Skip to content

Commit e5d66f0

Browse files
committed
removed System.Web & System.WinForms references;
added ComboBox for FontSelection;
1 parent 831974f commit e5d66f0

File tree

4 files changed

+114
-69
lines changed

4 files changed

+114
-69
lines changed

QuickNoteWidget/MainWindow.xaml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
Title="MainWindow"
1515
Height="350"
1616
Topmost="{Binding Settings.OnTop}"
17-
ShowInTaskbar="{Binding Settings.ShowInTaskbar}" AllowsTransparency="True"
17+
ShowInTaskbar="{Binding Settings.ShowInTaskbar}"
18+
AllowsTransparency="True"
1819
Opacity="{Binding TransparencyValue, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
1920
ContextMenu="{DynamicResource contextMenu}"
20-
Width="550">
21+
Width="600">
2122
<Window.Resources>
2223
<converter:AccentToColorConverter x:Key="AccentToColorConverter" />
2324
<converter:StringToFontStyleConverter x:Key="fontStyle" />
@@ -83,47 +84,60 @@
8384
<CheckBox Content="Show in Taskbar"
8485
IsChecked="{Binding Settings.ShowInTaskbar}" />
8586
</MenuItem>
86-
<MenuItem Header="Reset Transperency"
87-
Command="{Binding ResetTransparencyCommand}" />
87+
<MenuItem Header="Reset Settings"
88+
Command="{Binding ResetViewCommand}" />
8889
<MenuItem Header="Info"
8990
Click="Info_Click" />
9091
</ContextMenu>
9192
</Window.Resources>
9293
<Grid Background="{Binding DragAreaColor, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
9394
<DockPanel LastChildFill="True">
94-
<StatusBar Height="23"
95+
<StatusBar Height="32"
9596
Style="{DynamicResource MahApps.Styles.StatusBar}"
9697
DockPanel.Dock="Bottom"
9798
Visibility="{Binding Settings.DisplayDetails, Converter={StaticResource BoolToVisibilityCollapsedConverter}}"
9899
VerticalAlignment="Bottom"
99100
Margin="12,6,12,10"
100101
Background="{Binding StatusBarBackground, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
101-
<StatusBarItem>
102+
<StatusBarItem VerticalAlignment="Center">
102103
<StackPanel Orientation="Horizontal">
103104
<TextBlock Text="Word Count: " />
104105
<TextBlock Text="{Binding WordCount, UpdateSourceTrigger=PropertyChanged}" />
105106
</StackPanel>
106107
</StatusBarItem>
107108
<Separator Margin="10,0,10,0"
108109
HorizontalAlignment="Left" />
109-
<StatusBarItem>
110+
<StatusBarItem VerticalAlignment="Center">
110111
<StackPanel Orientation="Horizontal">
111112
<TextBlock Text="Transparency"
113+
VerticalAlignment="Center"
112114
Margin="0,0,10,0" />
113115
<Slider Width="100"
116+
VerticalAlignment="Center"
114117
Minimum="0.3"
115118
Maximum="1"
116119
Value="{Binding TransparencyValue, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
117-
<TextBlock Margin="10,0,0,0">
120+
<TextBlock Margin="10,0,0,0"
121+
VerticalAlignment="Center">
118122
<TextBlock.Inlines>
119123
<Run Text="{Binding TransparencyInPercent, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
120124
<Run Text="%" />
121-
</TextBlock.Inlines>
122-
</TextBlock>
125+
</TextBlock.Inlines></TextBlock>
123126
</StackPanel>
124127
</StatusBarItem>
128+
<Separator Margin="10,0,10,0"
129+
HorizontalAlignment="Left" />
130+
<StatusBarItem VerticalAlignment="Center">
131+
<StackPanel Orientation="Horizontal">
132+
<TextBlock Text="Current Font: "
133+
VerticalAlignment="Center" />
134+
<ComboBox Width="140" VerticalAlignment="Center" Height="23"
135+
ItemsSource="{Binding Fonts, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
136+
SelectedItem="{Binding Settings.CurrentFont, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
137+
</StackPanel>
138+
</StatusBarItem>
139+
125140
</StatusBar>
126-
127141
<avalonedit:TextEditor x:Name="tbxMultiLine"
128142
DockPanel.Dock="Top"
129143
Margin="12,12,12,6"
@@ -136,9 +150,9 @@
136150
Foreground="{Binding MultiLineTextForegroundColor, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
137151
ShowLineNumbers="True"
138152
WordWrap="True"
153+
FontFamily="{Binding Settings.CurrentFont, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
139154
PreviewMouseWheel="tbxMultiLine_PreviewMouseWheel" />
140155
</DockPanel>
141-
142156
<tb:TaskbarIcon IconSource=".\Clipboard.ico"
143157
x:Name="TaskbarIcon"
144158
Grid.RowSpan="2"
Lines changed: 77 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Collections.ObjectModel;
4+
using System.Drawing;
5+
using System.Drawing.Text;
36
using System.Linq;
47
using System.Windows.Input;
8+
59
using ControlzEx.Theming;
610
using DevExpress.Mvvm;
711
using 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
}

QuickNoteWidget/QuickNoteWidget.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@
7676
<Reference Include="System.Data.SQLite, Version=1.0.116.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
7777
<HintPath>..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.116.0\lib\net451\System.Data.SQLite.dll</HintPath>
7878
</Reference>
79-
<Reference Include="System.Web" />
80-
<Reference Include="System.Web.Extensions" />
79+
<Reference Include="System.Drawing" />
8180
<Reference Include="System.Windows" />
82-
<Reference Include="System.Windows.Forms" />
8381
<Reference Include="System.Xml" />
8482
<Reference Include="Microsoft.CSharp" />
8583
<Reference Include="System.Core" />

QuickNoteWidget/Settings.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
using System;
22
using System.IO;
33
using System.Xml.Serialization;
4+
using DevExpress.Mvvm;
45

56
namespace QuickNoteWidget
67
{
7-
public class Settings
8+
public class Settings : BindableBase
89
{
910
public string SelectedThemeName { get; set; }
1011
public string SelectedAccentName { get; set; }
1112
public bool OnTop { get; set; }
1213
public bool DisplayDetails { get; set; }
1314
public bool ShowInTaskbar { get; set; }
1415
public double TransparencyValue { get; set; }
16+
17+
private string _currentFont;
18+
19+
public string CurrentFont
20+
{
21+
get { return _currentFont; }
22+
set { SetProperty(ref _currentFont, value, () => CurrentFont); }
23+
}
1524
}
1625

1726
public static class SettingsLogic

0 commit comments

Comments
 (0)