Skip to content

Commit

Permalink
fix: Fix saving font
Browse files Browse the repository at this point in the history
  • Loading branch information
Samir L. Boulema committed Sep 15, 2021
1 parent 038cd13 commit 5b269c3
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 18 deletions.
16 changes: 16 additions & 0 deletions CodeNav.Shared/Helpers/SettingsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.ObjectModel;
using System.Drawing;

namespace CodeNav.Helpers
{
Expand All @@ -21,6 +22,20 @@ public static bool UseXMLComments
set => _useXmlComments = value;
}

private static Font _font;
public static Font Font
{
get
{
if (_font == null)
{
_font = new Font(General.Instance.FontFamilyName, General.Instance.FontSize, General.Instance.FontStyle);
}
return _font;
}
set => _font = value;
}

private static ObservableCollection<FilterRule> _filterRules;
public static ObservableCollection<FilterRule> FilterRules
{
Expand All @@ -38,6 +53,7 @@ public static void Refresh()
{
_useXmlComments = null;
_filterRules = null;
_font = null;
}

private static ObservableCollection<FilterRule> LoadFilterRules()
Expand Down
11 changes: 6 additions & 5 deletions CodeNav.Shared/Mappers/BaseMapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CodeNav.Models;
using CodeNav.Helpers;
using CodeNav.Models;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
Expand Down Expand Up @@ -50,10 +51,10 @@ private static T MapBase<T>(SyntaxNode source, string name, SyntaxTokenList modi
element.Span = source.Span;
element.ForegroundColor = Colors.Black;
element.Access = MapAccess(modifiers, source);
element.FontSize = General.Instance.Font.SizeInPoints;
element.ParameterFontSize = General.Instance.Font.SizeInPoints - 1;
element.FontFamily = new FontFamily(General.Instance.Font.FontFamily.Name);
element.FontStyle = FontStyleMapper.Map(General.Instance.Font.Style);
element.FontSize = SettingsHelper.Font.SizeInPoints;
element.ParameterFontSize = SettingsHelper.Font.SizeInPoints - 1;
element.FontFamily = new FontFamily(SettingsHelper.Font.FontFamily.Name);
element.FontStyle = FontStyleMapper.Map(SettingsHelper.Font.Style);
element.Control = control;

return element;
Expand Down
2 changes: 1 addition & 1 deletion CodeNav.Shared/Mappers/ClassMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private static void MapMembersFromBaseClass(ClassDeclarationSyntax member,
Tooltip = baseType.Name,
ForegroundColor = Colors.Black,
BorderColor = Colors.DarkGray,
FontSize = General.Instance.Font.SizeInPoints - 2,
FontSize = SettingsHelper.Font.SizeInPoints - 2,
Kind = CodeItemKindEnum.BaseClass,
Control = control
};
Expand Down
2 changes: 1 addition & 1 deletion CodeNav.Shared/Mappers/InterfaceMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static CodeImplementedInterfaceItem MapImplementedInterface(string name,
Id = name,
ForegroundColor = Colors.Black,
BorderColor = Colors.DarkGray,
FontSize = General.Instance.Font.SizeInPoints - 2,
FontSize = SettingsHelper.Font.SizeInPoints - 2,
Kind = CodeItemKindEnum.ImplementedInterface,
IsExpanded = true,
Control = control
Expand Down
11 changes: 6 additions & 5 deletions CodeNav.Shared/Mappers/JavaScript/BaseMapperJS.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CodeNav.Models;
using CodeNav.Helpers;
using CodeNav.Models;
using Microsoft.CodeAnalysis.Text;
using System;
using System.Linq;
Expand Down Expand Up @@ -27,10 +28,10 @@ public static T MapBase<T>(Node member, string id, ICodeViewUserControl control)
element.Span = new TextSpan(member.NodeStart, member.End.GetValueOrDefault() - member.NodeStart);
element.ForegroundColor = Colors.Black;
element.Access = CodeItemAccessEnum.Public;
element.FontSize = General.Instance.Font.SizeInPoints;
element.ParameterFontSize = General.Instance.Font.SizeInPoints - 1;
element.FontFamily = new FontFamily(General.Instance.Font.FontFamily.Name);
element.FontStyle = FontStyleMapper.Map(General.Instance.Font.Style);
element.FontSize = SettingsHelper.Font.SizeInPoints;
element.ParameterFontSize = SettingsHelper.Font.SizeInPoints - 1;
element.FontFamily = new FontFamily(SettingsHelper.Font.FontFamily.Name);
element.FontStyle = FontStyleMapper.Map(SettingsHelper.Font.Style);
element.Control = control;

return element;
Expand Down
2 changes: 1 addition & 1 deletion CodeNav.Shared/Mappers/RegionMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private static CodeRegionItem MapRegion(SyntaxTrivia source, ICodeViewUserContro
StartLinePosition = GetStartLinePosition(source),
ForegroundColor = Colors.Black,
BorderColor = Colors.DarkGray,
FontSize = General.Instance.Font.SizeInPoints - 2,
FontSize = SettingsHelper.Font.SizeInPoints - 2,
Kind = CodeItemKindEnum.Region,
Span = source.Span,
Control = control
Expand Down
6 changes: 5 additions & 1 deletion CodeNav.Shared/Options/General.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ public class General : BaseOptionModel<General>

public int AutoLoadLineThreshold { get; set; } = 0;

public Font Font { get; set; } = new Font("Segoe UI", 11.25f);
public string FontFamilyName { get; set; } = "Segoe UI";

public float FontSize { get; set; } = 11.25f;

public FontStyle FontStyle { get; set; } = FontStyle.Regular;

public Color HighlightColor { get; set; } = ColorHelper.Transparent();

Expand Down
14 changes: 10 additions & 4 deletions CodeNav.Shared/Windows/OptionsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using CodeNav.Models;
using CodeNav.Shared.ViewModels;
using Microsoft.VisualStudio.PlatformUI;
using System.Drawing;
using System.Windows;
using System.Windows.Forms;

Expand All @@ -27,7 +26,7 @@ private void OptionsWindow_Loaded(object sender, RoutedEventArgs e)
ShowHistoryIndicators = General.Instance.ShowHistoryIndicators,
DisableHighlight = General.Instance.DisableHighlight,
AutoLoadLineThreshold = General.Instance.AutoLoadLineThreshold,
Font = General.Instance.Font,
Font = SettingsHelper.Font,
BackgroundColor = General.Instance.BackgroundColor,
HighlightColor = General.Instance.HighlightColor
};
Expand All @@ -38,6 +37,9 @@ private void OptionsWindow_Loaded(object sender, RoutedEventArgs e)
private void ShowFontDialog(object sender, RoutedEventArgs e)
{
var fontDialog = new FontDialog();

fontDialog.Font = ViewModel.Font;

if (fontDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
ViewModel.Font = fontDialog.Font;
Expand Down Expand Up @@ -65,7 +67,9 @@ private void ShowBackgroundColorDialog(object sender, RoutedEventArgs e)
private void OkClick(object sender, RoutedEventArgs e)
{
General.Instance.MarginSide = (int)ViewModel.MarginSide;
General.Instance.Font = ViewModel.Font;
General.Instance.FontFamilyName = ViewModel.Font.FontFamily.Name;
General.Instance.FontSize = ViewModel.Font.Size;
General.Instance.FontStyle = ViewModel.Font.Style;
General.Instance.ShowFilterToolbar = ViewModel.ShowFilterToolbar;
General.Instance.UseXMLComments = ViewModel.UseXMLComments;
General.Instance.ShowHistoryIndicators = ViewModel.ShowHistoryIndicators;
Expand All @@ -90,7 +94,9 @@ private void ResetClick(object sender, RoutedEventArgs e)
{
General.Instance.Width = 200;
General.Instance.MarginSide = (int)MarginSideEnum.Left;
General.Instance.Font = new Font("Segoe UI", (float)11.25);
General.Instance.FontFamilyName = "Segoe UI";
General.Instance.FontSize = 11.25f;
General.Instance.FontStyle = System.Drawing.FontStyle.Regular;
General.Instance.ShowFilterToolbar = true;
General.Instance.ShowMargin = true;
General.Instance.FilterRules = string.Empty;
Expand Down

0 comments on commit 5b269c3

Please sign in to comment.