Skip to content

Commit 5b269c3

Browse files
author
Samir L. Boulema
committed
fix: Fix saving font
1 parent 038cd13 commit 5b269c3

File tree

8 files changed

+46
-18
lines changed

8 files changed

+46
-18
lines changed

CodeNav.Shared/Helpers/SettingsHelper.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Newtonsoft.Json;
33
using System;
44
using System.Collections.ObjectModel;
5+
using System.Drawing;
56

67
namespace CodeNav.Helpers
78
{
@@ -21,6 +22,20 @@ public static bool UseXMLComments
2122
set => _useXmlComments = value;
2223
}
2324

25+
private static Font _font;
26+
public static Font Font
27+
{
28+
get
29+
{
30+
if (_font == null)
31+
{
32+
_font = new Font(General.Instance.FontFamilyName, General.Instance.FontSize, General.Instance.FontStyle);
33+
}
34+
return _font;
35+
}
36+
set => _font = value;
37+
}
38+
2439
private static ObservableCollection<FilterRule> _filterRules;
2540
public static ObservableCollection<FilterRule> FilterRules
2641
{
@@ -38,6 +53,7 @@ public static void Refresh()
3853
{
3954
_useXmlComments = null;
4055
_filterRules = null;
56+
_font = null;
4157
}
4258

4359
private static ObservableCollection<FilterRule> LoadFilterRules()

CodeNav.Shared/Mappers/BaseMapper.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CodeNav.Models;
1+
using CodeNav.Helpers;
2+
using CodeNav.Models;
23
using Microsoft.CodeAnalysis;
34
using Microsoft.CodeAnalysis.CSharp;
45
using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -50,10 +51,10 @@ private static T MapBase<T>(SyntaxNode source, string name, SyntaxTokenList modi
5051
element.Span = source.Span;
5152
element.ForegroundColor = Colors.Black;
5253
element.Access = MapAccess(modifiers, source);
53-
element.FontSize = General.Instance.Font.SizeInPoints;
54-
element.ParameterFontSize = General.Instance.Font.SizeInPoints - 1;
55-
element.FontFamily = new FontFamily(General.Instance.Font.FontFamily.Name);
56-
element.FontStyle = FontStyleMapper.Map(General.Instance.Font.Style);
54+
element.FontSize = SettingsHelper.Font.SizeInPoints;
55+
element.ParameterFontSize = SettingsHelper.Font.SizeInPoints - 1;
56+
element.FontFamily = new FontFamily(SettingsHelper.Font.FontFamily.Name);
57+
element.FontStyle = FontStyleMapper.Map(SettingsHelper.Font.Style);
5758
element.Control = control;
5859

5960
return element;

CodeNav.Shared/Mappers/ClassMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private static void MapMembersFromBaseClass(ClassDeclarationSyntax member,
184184
Tooltip = baseType.Name,
185185
ForegroundColor = Colors.Black,
186186
BorderColor = Colors.DarkGray,
187-
FontSize = General.Instance.Font.SizeInPoints - 2,
187+
FontSize = SettingsHelper.Font.SizeInPoints - 2,
188188
Kind = CodeItemKindEnum.BaseClass,
189189
Control = control
190190
};

CodeNav.Shared/Mappers/InterfaceMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static CodeImplementedInterfaceItem MapImplementedInterface(string name,
7474
Id = name,
7575
ForegroundColor = Colors.Black,
7676
BorderColor = Colors.DarkGray,
77-
FontSize = General.Instance.Font.SizeInPoints - 2,
77+
FontSize = SettingsHelper.Font.SizeInPoints - 2,
7878
Kind = CodeItemKindEnum.ImplementedInterface,
7979
IsExpanded = true,
8080
Control = control

CodeNav.Shared/Mappers/JavaScript/BaseMapperJS.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CodeNav.Models;
1+
using CodeNav.Helpers;
2+
using CodeNav.Models;
23
using Microsoft.CodeAnalysis.Text;
34
using System;
45
using System.Linq;
@@ -27,10 +28,10 @@ public static T MapBase<T>(Node member, string id, ICodeViewUserControl control)
2728
element.Span = new TextSpan(member.NodeStart, member.End.GetValueOrDefault() - member.NodeStart);
2829
element.ForegroundColor = Colors.Black;
2930
element.Access = CodeItemAccessEnum.Public;
30-
element.FontSize = General.Instance.Font.SizeInPoints;
31-
element.ParameterFontSize = General.Instance.Font.SizeInPoints - 1;
32-
element.FontFamily = new FontFamily(General.Instance.Font.FontFamily.Name);
33-
element.FontStyle = FontStyleMapper.Map(General.Instance.Font.Style);
31+
element.FontSize = SettingsHelper.Font.SizeInPoints;
32+
element.ParameterFontSize = SettingsHelper.Font.SizeInPoints - 1;
33+
element.FontFamily = new FontFamily(SettingsHelper.Font.FontFamily.Name);
34+
element.FontStyle = FontStyleMapper.Map(SettingsHelper.Font.Style);
3435
element.Control = control;
3536

3637
return element;

CodeNav.Shared/Mappers/RegionMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private static CodeRegionItem MapRegion(SyntaxTrivia source, ICodeViewUserContro
114114
StartLinePosition = GetStartLinePosition(source),
115115
ForegroundColor = Colors.Black,
116116
BorderColor = Colors.DarkGray,
117-
FontSize = General.Instance.Font.SizeInPoints - 2,
117+
FontSize = SettingsHelper.Font.SizeInPoints - 2,
118118
Kind = CodeItemKindEnum.Region,
119119
Span = source.Span,
120120
Control = control

CodeNav.Shared/Options/General.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ public class General : BaseOptionModel<General>
2121

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

24-
public Font Font { get; set; } = new Font("Segoe UI", 11.25f);
24+
public string FontFamilyName { get; set; } = "Segoe UI";
25+
26+
public float FontSize { get; set; } = 11.25f;
27+
28+
public FontStyle FontStyle { get; set; } = FontStyle.Regular;
2529

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

CodeNav.Shared/Windows/OptionsWindow.xaml.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using CodeNav.Models;
33
using CodeNav.Shared.ViewModels;
44
using Microsoft.VisualStudio.PlatformUI;
5-
using System.Drawing;
65
using System.Windows;
76
using System.Windows.Forms;
87

@@ -27,7 +26,7 @@ private void OptionsWindow_Loaded(object sender, RoutedEventArgs e)
2726
ShowHistoryIndicators = General.Instance.ShowHistoryIndicators,
2827
DisableHighlight = General.Instance.DisableHighlight,
2928
AutoLoadLineThreshold = General.Instance.AutoLoadLineThreshold,
30-
Font = General.Instance.Font,
29+
Font = SettingsHelper.Font,
3130
BackgroundColor = General.Instance.BackgroundColor,
3231
HighlightColor = General.Instance.HighlightColor
3332
};
@@ -38,6 +37,9 @@ private void OptionsWindow_Loaded(object sender, RoutedEventArgs e)
3837
private void ShowFontDialog(object sender, RoutedEventArgs e)
3938
{
4039
var fontDialog = new FontDialog();
40+
41+
fontDialog.Font = ViewModel.Font;
42+
4143
if (fontDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
4244
{
4345
ViewModel.Font = fontDialog.Font;
@@ -65,7 +67,9 @@ private void ShowBackgroundColorDialog(object sender, RoutedEventArgs e)
6567
private void OkClick(object sender, RoutedEventArgs e)
6668
{
6769
General.Instance.MarginSide = (int)ViewModel.MarginSide;
68-
General.Instance.Font = ViewModel.Font;
70+
General.Instance.FontFamilyName = ViewModel.Font.FontFamily.Name;
71+
General.Instance.FontSize = ViewModel.Font.Size;
72+
General.Instance.FontStyle = ViewModel.Font.Style;
6973
General.Instance.ShowFilterToolbar = ViewModel.ShowFilterToolbar;
7074
General.Instance.UseXMLComments = ViewModel.UseXMLComments;
7175
General.Instance.ShowHistoryIndicators = ViewModel.ShowHistoryIndicators;
@@ -90,7 +94,9 @@ private void ResetClick(object sender, RoutedEventArgs e)
9094
{
9195
General.Instance.Width = 200;
9296
General.Instance.MarginSide = (int)MarginSideEnum.Left;
93-
General.Instance.Font = new Font("Segoe UI", (float)11.25);
97+
General.Instance.FontFamilyName = "Segoe UI";
98+
General.Instance.FontSize = 11.25f;
99+
General.Instance.FontStyle = System.Drawing.FontStyle.Regular;
94100
General.Instance.ShowFilterToolbar = true;
95101
General.Instance.ShowMargin = true;
96102
General.Instance.FilterRules = string.Empty;

0 commit comments

Comments
 (0)