Repository navigation
Expand file tree
/
Copy pathMainWindowViewModel.cs
More file actions
241 lines (220 loc) · 8.55 KB
/
Copy pathMainWindowViewModel.cs
File metadata and controls
241 lines (220 loc) · 8.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
using System.Windows.Input;
using ControlzEx.Theming;
using DevExpress.Mvvm;
using QuickNoteWidget.Theme;
namespace QuickNoteWidget
{
public class MainWindowViewModel : ViewModelBase
{
#region Constants
private const string WHITE = "#FFFFFF";
private const string BLACK = "#252525"; // Based on Theme colord "Dark"
private const string GRAY = "#616161"; // slightly lighter than BLACK
private const string LIGHT_GRAY = "#EAEAEA"; // slightly darker than "WhiteSmoke"
#endregion Constants
#region MVVM Properties
private string _multiLine;
private string _multiLineTextForegroundColor;
private string _characterCount;
private string _dragAreaColor;
private string _statusBarBackground;
private double _transparencyValue;
private int _transparencyInPercent;
private ObservableCollection<string> _fonts;
private ObservableCollection<string> _themes;
private ObservableCollection<string> _accents;
private string _selectedTheme;
private string _selectedAccent;
private bool _ontop;
private bool _showintaskbar;
private bool _displaydetails;
private string _currentfont;
private bool _isWindowResizeBarVisible;
public bool IsWindowResizeBarVisible
{
get { return _isWindowResizeBarVisible; }
set { SetProperty(ref _isWindowResizeBarVisible, value, () => IsWindowResizeBarVisible); }
}
public string CurrentFont
{
get { return _currentfont; }
set { SetProperty(ref _currentfont, value, () => CurrentFont); }
}
public bool OnTop
{
get { return _ontop; }
set { SetProperty(ref _ontop, value, () => OnTop); }
}
public bool DisplayDetails
{
get { return _displaydetails; }
set { SetProperty(ref _displaydetails, value, () => DisplayDetails); }
}
public bool ShowInTaskbar
{
get { return _showintaskbar; }
set { SetProperty(ref _showintaskbar, value, () => ShowInTaskbar); }
}
public string SelectedAccent
{
get => _selectedAccent;
set
{
SetProperty(ref _selectedAccent, value, () => SelectedAccent);
ThemeChanger.ChangeTheme(this.SelectedAccent, this.SelectedTheme);
}
}
public string SelectedTheme
{
get => _selectedTheme;
set
{
SetProperty(ref _selectedTheme, value, () => SelectedTheme);
StatusBarBackground = this.SelectedTheme == ThemeManager.BaseColorLight ? WHITE : BLACK;
DragAreaColor = this.SelectedTheme == ThemeManager.BaseColorLight ? LIGHT_GRAY : GRAY;
ThemeChanger.ChangeTheme(this.SelectedAccent, this.SelectedTheme);
UpdateFontColorOnThemeSelectionChanged();
}
}
public ObservableCollection<string> Accents
{
get => _accents;
set => SetProperty(ref _accents, value, () => Accents);
}
public ObservableCollection<string> Themes
{
get => _themes;
set => SetProperty(ref _themes, value, () => Themes);
}
public ObservableCollection<string> Fonts
{
get { return _fonts; }
set { SetProperty(ref _fonts, value, () => Fonts); }
}
public int TransparencyInPercent
{
get { return _transparencyInPercent; }
set { SetProperty(ref _transparencyInPercent, value, () => TransparencyInPercent); }
}
public double TransparencyValue
{
get { return _transparencyValue; }
set
{
SetProperty(ref _transparencyValue, value, () => TransparencyValue);
TransparencyInPercent = (Int32)(TransparencyValue * 100);
}
}
public string StatusBarBackground
{
get => _statusBarBackground;
set => SetProperty(ref _statusBarBackground, value, () => StatusBarBackground);
}
public string DragAreaColor
{
get => _dragAreaColor;
set => SetProperty(ref _dragAreaColor, value, () => DragAreaColor);
}
public string CharacterCount
{
get => _characterCount;
set => SetProperty(ref _characterCount, value, () => CharacterCount);
}
public string MultiLineTextForegroundColor
{
get => _multiLineTextForegroundColor;
set => SetProperty(ref _multiLineTextForegroundColor, value, () => MultiLineTextForegroundColor);
}
public string MultiLine
{
get => _multiLine;
set => SetProperty(ref _multiLine, value, () => MultiLine);
}
#endregion MVVM Properties
public Settings Settings { get; set; }
public ICommand ResetViewCommand { get; set; }
// Callback Action to the view, with loose coupling
public Action ResetWindowSizeAction;
public MainWindowViewModel()
{
LoadAvailableThemesAndAccents();
LoadSettings(SettingsLoadLocations.FromFile);
InitViewModel();
}
private void LoadAvailableThemesAndAccents()
{
Themes = new ObservableCollection<string>() { ThemeManager.BaseColorLight, ThemeManager.BaseColorDark };
Accents = new ObservableCollection<string>(ThemeManager.Current.ColorSchemes);
}
private void LoadSettings(SettingsLoadLocations location)
{
InitSettingsBeforePropertiesUpdate(location);
UpdateProperties();
}
private void InitSettingsBeforePropertiesUpdate(SettingsLoadLocations location)
{
switch (location)
{
case SettingsLoadLocations.FromFile:
Settings = SettingsLogic.GetSettings();
break;
case SettingsLoadLocations.Default:
Settings = SettingsLogic.GetDefaultSettings();
break;
}
}
private void UpdateProperties()
{
this.SelectedTheme = Themes.FirstOrDefault(f => f == this.Settings.SelectedThemeName);
this.SelectedAccent = Accents.FirstOrDefault(f => f == this.Settings.SelectedAccentName);
this.TransparencyValue = Settings.TransparencyValue;
this.OnTop = Settings.OnTop;
this.CurrentFont = Settings.CurrentFont;
this.DisplayDetails = Settings.DisplayDetails;
this.ShowInTaskbar = Settings.ShowInTaskbar;
this.IsWindowResizeBarVisible = Settings.WindowResizeBarVisible;
}
public void SaveSettingsOnClose()
{
Settings.SelectedAccentName = this.SelectedAccent;
Settings.SelectedThemeName = this.SelectedTheme;
Settings.TransparencyValue = this.TransparencyValue;
Settings.OnTop = this.OnTop;
Settings.CurrentFont = this.CurrentFont;
Settings.DisplayDetails = this.DisplayDetails;
Settings.ShowInTaskbar = this.ShowInTaskbar;
Settings.WindowResizeBarVisible = this.IsWindowResizeBarVisible;
SettingsLogic.SaveSettings(this.Settings);
}
private void InitViewModel()
{
Fonts = new ObservableCollection<string>(LoadInstalledFonts());
ResetViewCommand = new DelegateCommand(ResetView);
}
private IEnumerable<string> LoadInstalledFonts()
{
using (var fonts = new InstalledFontCollection())
foreach (FontFamily font in fonts.Families)
yield return font.Name;
}
private void ResetView()
{
Settings defaultSettings = SettingsLogic.GetDefaultSettings();
LoadSettings(SettingsLoadLocations.Default);
ResetWindowSizeAction.Invoke();
}
private void UpdateFontColorOnThemeSelectionChanged()
{
if (!String.IsNullOrEmpty(SelectedTheme))
MultiLineTextForegroundColor = SelectedTheme == ThemeManager.BaseColorLight ? BLACK : WHITE;
else
MultiLineTextForegroundColor = LIGHT_GRAY;
}
}
}