11using System ;
2+ using System . Collections . Generic ;
23using System . Collections . ObjectModel ;
4+ using System . Drawing ;
5+ using System . Drawing . Text ;
36using System . Linq ;
47using System . Windows . Input ;
8+
59using ControlzEx . Theming ;
610using DevExpress . Mvvm ;
711using QuickNoteWidget . Theme ;
@@ -18,8 +22,11 @@ public class MainWindowViewModel : ViewModelBase
1822 private const string NORMAL = "Normal" ;
1923 private const string ITALIC = "Italic" ;
2024 private const string STRIKETHROUGH = "Strikethrough" ;
21- #endregion
25+ private const string DEFAULT_FONT = "Arial" ;
26+ private const string CYAN = "Cyan" ;
27+ #endregion Constants
2228
29+ #region MVVM Properties
2330 private string _multiLine ;
2431 private string _multiLineTextForegroundColor ;
2532 private string _wordCount ;
@@ -28,7 +35,47 @@ public class MainWindowViewModel : ViewModelBase
2835 private double _transparencyValue ;
2936 private int _transparencyInPercent ;
3037 private Settings _settings ;
31-
38+ private ObservableCollection < string > _fonts ;
39+ private ObservableCollection < string > _themes ;
40+ private ObservableCollection < string > _accents ;
41+ private string _selectedTheme ;
42+ private string _selectedAccent ;
43+ public string SelectedAccent
44+ {
45+ get => _selectedAccent ;
46+ set
47+ {
48+ SetProperty ( ref _selectedAccent , value , ( ) => SelectedAccent ) ;
49+ ThemeChanger . ChangeTheme ( this . SelectedAccent , this . SelectedTheme ) ;
50+ }
51+ }
52+ public string SelectedTheme
53+ {
54+ get => _selectedTheme ;
55+ set
56+ {
57+ SetProperty ( ref _selectedTheme , value , ( ) => SelectedTheme ) ;
58+ StatusBarBackground = this . SelectedTheme == ThemeManager . BaseColorLight ? WHITE : BLACK ;
59+ DragAreaColor = this . SelectedTheme == ThemeManager . BaseColorLight ? LIGHT_GRAY : GRAY ;
60+ ThemeChanger . ChangeTheme ( this . SelectedAccent , this . SelectedTheme ) ;
61+ ThemeSelectionChanged ( ) ;
62+ }
63+ }
64+ public ObservableCollection < string > Accents
65+ {
66+ get => _accents ;
67+ set => SetProperty ( ref _accents , value , ( ) => Accents ) ;
68+ }
69+ public ObservableCollection < string > Themes
70+ {
71+ get => _themes ;
72+ set => SetProperty ( ref _themes , value , ( ) => Themes ) ;
73+ }
74+ public ObservableCollection < string > Fonts
75+ {
76+ get { return _fonts ; }
77+ set { SetProperty ( ref _fonts , value , ( ) => Fonts ) ; }
78+ }
3279 public Settings Settings
3380 {
3481 get { return _settings ; }
@@ -74,9 +121,10 @@ public string MultiLine
74121 set => SetProperty ( ref _multiLine , value , ( ) => MultiLine ) ;
75122 }
76123
124+ #endregion MVVM Properties
77125
78126 public ICommand ClearMultiLineCommand { get ; set ; }
79- public ICommand ResetTransparencyCommand { get ; set ; }
127+ public ICommand ResetViewCommand { get ; set ; }
80128
81129
82130 public MainWindowViewModel ( )
@@ -88,71 +136,55 @@ public MainWindowViewModel()
88136
89137 private void Init ( )
90138 {
91- ResetTransparencyCommand = new DelegateCommand ( ResetTransparency ) ;
139+ ResetViewCommand = new DelegateCommand ( ResetView ) ;
92140 ClearMultiLineCommand = new DelegateCommand ( ClearMultiLine ) ;
141+
93142 ClearMultiLine ( ) ;
143+ Fonts = new ObservableCollection < string > ( LoadInstalledFonts ( ) ) ;
94144 }
95145
96- private void ClearMultiLine ( ) => this . MultiLine = String . Empty ;
97- private void ResetTransparency ( ) => this . TransparencyValue = 1 ;
98-
99-
100- #region Settings
101-
102-
103-
104- private ObservableCollection < string > _themes ;
105- private ObservableCollection < string > _accents ;
106- private string _selectedTheme ;
107- private string _selectedAccent ;
108- public string SelectedAccent
146+ private IEnumerable < string > LoadInstalledFonts ( )
109147 {
110- get => _selectedAccent ;
111- set
112- {
113- SetProperty ( ref _selectedAccent , value , ( ) => SelectedAccent ) ;
114- ThemeChanger . ChangeTheme ( this . SelectedAccent , this . SelectedTheme ) ;
115- }
116- }
117- public string SelectedTheme
118- {
119- get => _selectedTheme ;
120- set
121- {
122- SetProperty ( ref _selectedTheme , value , ( ) => SelectedTheme ) ;
123- StatusBarBackground = this . SelectedTheme == ThemeManager . BaseColorLight ? WHITE : BLACK ;
124- DragAreaColor = this . SelectedTheme == ThemeManager . BaseColorLight ? LIGHT_GRAY : GRAY ;
125- ThemeChanger . ChangeTheme ( this . SelectedAccent , this . SelectedTheme ) ;
126- ThemeSelectionChanged ( ) ;
127- }
128- }
129- public ObservableCollection < string > Accents
130- {
131- get => _accents ;
132- set => SetProperty ( ref _accents , value , ( ) => Accents ) ;
148+ using ( var fonts = new InstalledFontCollection ( ) )
149+ foreach ( FontFamily font in fonts . Families )
150+ yield return font . Name ;
133151 }
134- public ObservableCollection < string > Themes
152+
153+ private void ClearMultiLine ( ) => this . MultiLine = String . Empty ;
154+
155+ private void ResetView ( )
135156 {
136- get => _themes ;
137- set => SetProperty ( ref _themes , value , ( ) => Themes ) ;
157+ this . TransparencyValue = 1 ;
158+ this . SelectedTheme = Themes . First ( ) ;
159+ this . SelectedAccent = Accents . First ( f => f == CYAN ) ;
160+ this . Settings . CurrentFont = Fonts . First ( f => f == DEFAULT_FONT ) ;
138161 }
139162
140163
164+ #region Themes
141165 private void LoadAvailableThemes ( )
142166 {
143167 Themes = new ObservableCollection < string > ( ) { ThemeManager . BaseColorLight , ThemeManager . BaseColorDark } ;
144168 Accents = new ObservableCollection < string > ( ThemeManager . Current . ColorSchemes ) ;
145169 }
170+ private void ThemeSelectionChanged ( )
171+ {
172+ if ( ! String . IsNullOrEmpty ( SelectedTheme ) )
173+ MultiLineTextForegroundColor = SelectedTheme == ThemeManager . BaseColorLight ? BLACK : WHITE ;
174+ else
175+ MultiLineTextForegroundColor = LIGHT_GRAY ;
176+ }
177+ #endregion Themes
146178
179+
180+ #region Settings
147181 private void LoadSettings ( )
148182 {
149183 this . Settings = SettingsLogic . GetSettings ( ) ;
150184 SelectedTheme = Themes . FirstOrDefault ( f => f == this . Settings . SelectedThemeName ) ;
151185 SelectedAccent = Accents . FirstOrDefault ( f => f == this . Settings . SelectedAccentName ) ;
152186 TransparencyValue = Settings . TransparencyValue ;
153187 }
154-
155-
156188 public void SaveSettings ( )
157189 {
158190 Settings . SelectedAccentName = this . SelectedAccent ;
@@ -161,14 +193,6 @@ public void SaveSettings()
161193 SettingsLogic . SaveSettings ( this . Settings ) ;
162194 }
163195
164- private void ThemeSelectionChanged ( )
165- {
166- if ( ! String . IsNullOrEmpty ( SelectedTheme ) )
167- MultiLineTextForegroundColor = SelectedTheme == ThemeManager . BaseColorLight ? BLACK : WHITE ;
168- else
169- MultiLineTextForegroundColor = LIGHT_GRAY ;
170- }
171-
172196 #endregion Settings
173197 }
174198}
0 commit comments