Skip to content

Commit 2fd5ad8

Browse files
committed
code clean ups
1 parent 0f0ac7b commit 2fd5ad8

File tree

2 files changed

+42
-43
lines changed

2 files changed

+42
-43
lines changed

QuickNoteWidget/MainWindow.xaml.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
7272
protected override void OnClosed(EventArgs e)
7373
{
7474
base.OnClosed(e);
75-
_mainWindowViewModel.SaveSettings();
75+
_mainWindowViewModel.SaveSettingsOnClose();
7676
}
7777

7878
private void Info_Click(object sender, RoutedEventArgs e)
@@ -81,20 +81,21 @@ private void Info_Click(object sender, RoutedEventArgs e)
8181
_infoWindow.Show();
8282
}
8383

84-
// React to ctrl + mouse wheel
84+
8585
private void tbxMultiLine_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
8686
{
87-
bool ctrl = (Keyboard.Modifiers == ModifierKeys.Control);
88-
if (ctrl)
87+
// React to ctrl + mouse wheel
88+
bool ctrlButtonPressed = (Keyboard.Modifiers == ModifierKeys.Control);
89+
if (ctrlButtonPressed)
8990
{
90-
this.UpdateFontSize(e.Delta > 0);
91+
bool increase = e.Delta > 0;
92+
this.UpdateFontSize(increase);
9193
e.Handled = true;
9294
}
9395
}
9496

95-
// max and min font size values
96-
private const double FONT_MAX_SIZE = 60d;
9797
private const double FONT_MIN_SIZE = 5d;
98+
private const double FONT_MAX_SIZE = 60d;
9899

99100
private void UpdateFontSize(bool increase)
100101
{

QuickNoteWidget/MainWindowViewModel.cs

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -148,47 +148,14 @@ public MainWindowViewModel()
148148
{
149149
LoadAvailableThemesAndAccents();
150150
LoadSettings(SettingsLoadLocations.FromFile);
151-
Init();
151+
InitViewModel();
152152
}
153-
154-
private void Init()
155-
{
156-
ResetViewCommand = new DelegateCommand(ResetView);
157-
Fonts = new ObservableCollection<string>(LoadInstalledFonts());
158-
}
159-
160-
private IEnumerable<string> LoadInstalledFonts()
161-
{
162-
using (var fonts = new InstalledFontCollection())
163-
foreach (FontFamily font in fonts.Families)
164-
yield return font.Name;
165-
}
166-
167-
private void ResetView()
168-
{
169-
Settings defaultSettings = SettingsLogic.GetDefaultSettings();
170-
LoadSettings(SettingsLoadLocations.Default);
171-
}
172-
173-
174-
#region Themes
175153
private void LoadAvailableThemesAndAccents()
176154
{
177155
Themes = new ObservableCollection<string>() { ThemeManager.BaseColorLight, ThemeManager.BaseColorDark };
178156
Accents = new ObservableCollection<string>(ThemeManager.Current.ColorSchemes);
179157
}
180158

181-
private void UpdateFontColorOnThemeSelectionChanged()
182-
{
183-
if (!String.IsNullOrEmpty(SelectedTheme))
184-
MultiLineTextForegroundColor = SelectedTheme == ThemeManager.BaseColorLight ? BLACK : WHITE;
185-
else
186-
MultiLineTextForegroundColor = LIGHT_GRAY;
187-
}
188-
#endregion Themes
189-
190-
191-
#region Settings
192159
private void LoadSettings(SettingsLoadLocations location)
193160
{
194161
InitSettingsBeforePropertiesUpdate(location);
@@ -219,8 +186,40 @@ private void UpdateProperties()
219186
this.ShowInTaskbar = Settings.ShowInTaskbar;
220187
}
221188

189+
private void InitViewModel()
190+
{
191+
Fonts = new ObservableCollection<string>(LoadInstalledFonts());
192+
ResetViewCommand = new DelegateCommand(ResetView);
193+
}
194+
195+
private IEnumerable<string> LoadInstalledFonts()
196+
{
197+
using (var fonts = new InstalledFontCollection())
198+
foreach (FontFamily font in fonts.Families)
199+
yield return font.Name;
200+
}
201+
202+
private void ResetView()
203+
{
204+
Settings defaultSettings = SettingsLogic.GetDefaultSettings();
205+
LoadSettings(SettingsLoadLocations.Default);
206+
}
207+
208+
209+
210+
211+
private void UpdateFontColorOnThemeSelectionChanged()
212+
{
213+
if (!String.IsNullOrEmpty(SelectedTheme))
214+
MultiLineTextForegroundColor = SelectedTheme == ThemeManager.BaseColorLight ? BLACK : WHITE;
215+
else
216+
MultiLineTextForegroundColor = LIGHT_GRAY;
217+
}
218+
219+
220+
222221

223-
public void SaveSettings()
222+
public void SaveSettingsOnClose()
224223
{
225224
Settings.SelectedAccentName = this.SelectedAccent;
226225
Settings.SelectedThemeName = this.SelectedTheme;
@@ -231,6 +230,5 @@ public void SaveSettings()
231230
Settings.ShowInTaskbar = this.ShowInTaskbar;
232231
SettingsLogic.SaveSettings(this.Settings);
233232
}
234-
#endregion Settings
235233
}
236234
}

0 commit comments

Comments
 (0)