Skip to content

Commit 50702d8

Browse files
committed
Refactor Clcok/Date code to viewmodel
1 parent f97fdaf commit 50702d8

File tree

4 files changed

+156
-172
lines changed

4 files changed

+156
-172
lines changed

Flow.Launcher/Helper/HotKeyMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal static class HotKeyMapper
1717
internal static void Initialize(MainViewModel mainVM)
1818
{
1919
mainViewModel = mainVM;
20-
settings = mainViewModel._settings;
20+
settings = mainViewModel.Settings;
2121

2222
SetHotkey(settings.Hotkey, OnToggleHotkey);
2323
LoadCustomPluginHotkey();

Flow.Launcher/MainWindow.xaml

Lines changed: 114 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<Window
2-
x:Class="Flow.Launcher.MainWindow"
1+
<Window x:Class="Flow.Launcher.MainWindow"
32
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
43
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
54
xmlns:converters="clr-namespace:Flow.Launcher.Converters"
@@ -36,144 +35,129 @@
3635
<Window.Resources>
3736
<converters:QuerySuggestionBoxConverter x:Key="QuerySuggestionBoxConverter" />
3837
<converters:BorderClipConverter x:Key="BorderClipConverter" />
38+
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
3939
</Window.Resources>
4040
<Window.InputBindings>
41-
<KeyBinding Key="Escape" Command="{Binding EscCommand}" />
42-
<KeyBinding Key="F1" Command="{Binding StartHelpCommand}" />
43-
<KeyBinding Key="F5" Command="{Binding ReloadPluginDataCommand}" />
44-
<KeyBinding Key="Tab" Command="{Binding AutocompleteQueryCommand}" />
45-
<KeyBinding
46-
Key="Tab"
41+
<KeyBinding Key="Escape"
42+
Command="{Binding EscCommand}" />
43+
<KeyBinding Key="F1"
44+
Command="{Binding StartHelpCommand}" />
45+
<KeyBinding Key="F5"
46+
Command="{Binding ReloadPluginDataCommand}" />
47+
<KeyBinding Key="Tab"
48+
Command="{Binding AutocompleteQueryCommand}" />
49+
<KeyBinding Key="Tab"
4750
Command="{Binding AutocompleteQueryCommand}"
4851
Modifiers="Shift" />
49-
<KeyBinding
50-
Key="I"
52+
<KeyBinding Key="I"
5153
Command="{Binding OpenSettingCommand}"
5254
Modifiers="Ctrl" />
53-
<KeyBinding
54-
Key="N"
55+
<KeyBinding Key="N"
5556
Command="{Binding SelectNextItemCommand}"
5657
Modifiers="Ctrl" />
57-
<KeyBinding
58-
Key="J"
58+
<KeyBinding Key="J"
5959
Command="{Binding SelectNextItemCommand}"
6060
Modifiers="Ctrl" />
61-
<KeyBinding
62-
Key="D"
61+
<KeyBinding Key="D"
6362
Command="{Binding SelectNextPageCommand}"
6463
Modifiers="Ctrl" />
65-
<KeyBinding
66-
Key="P"
64+
<KeyBinding Key="P"
6765
Command="{Binding SelectPrevItemCommand}"
6866
Modifiers="Ctrl" />
69-
<KeyBinding
70-
Key="K"
67+
<KeyBinding Key="K"
7168
Command="{Binding SelectPrevItemCommand}"
7269
Modifiers="Ctrl" />
73-
<KeyBinding
74-
Key="U"
70+
<KeyBinding Key="U"
7571
Command="{Binding SelectPrevPageCommand}"
7672
Modifiers="Ctrl" />
77-
<KeyBinding
78-
Key="Home"
73+
<KeyBinding Key="Home"
7974
Command="{Binding SelectFirstResultCommand}"
8075
Modifiers="Alt" />
81-
<KeyBinding
82-
Key="O"
76+
<KeyBinding Key="O"
8377
Command="{Binding LoadContextMenuCommand}"
8478
Modifiers="Ctrl" />
85-
<KeyBinding Key="Right" Command="{Binding LoadContextMenuCommand}" />
86-
<KeyBinding Key="Left" Command="{Binding EscCommand}" />
87-
<KeyBinding
88-
Key="H"
79+
<KeyBinding Key="Right"
80+
Command="{Binding LoadContextMenuCommand}" />
81+
<KeyBinding Key="Left"
82+
Command="{Binding EscCommand}" />
83+
<KeyBinding Key="H"
8984
Command="{Binding LoadHistoryCommand}"
9085
Modifiers="Ctrl" />
91-
<KeyBinding
92-
Key="Enter"
86+
<KeyBinding Key="Enter"
9387
Command="{Binding OpenResultCommand}"
9488
Modifiers="Ctrl+Shift" />
95-
<KeyBinding
96-
Key="Enter"
89+
<KeyBinding Key="Enter"
9790
Command="{Binding LoadContextMenuCommand}"
9891
Modifiers="Shift" />
99-
<KeyBinding Key="Enter" Command="{Binding OpenResultCommand}" />
100-
<KeyBinding
101-
Key="Enter"
92+
<KeyBinding Key="Enter"
93+
Command="{Binding OpenResultCommand}" />
94+
<KeyBinding Key="Enter"
10295
Command="{Binding OpenResultCommand}"
10396
Modifiers="Ctrl" />
104-
<KeyBinding
105-
Key="Enter"
97+
<KeyBinding Key="Enter"
10698
Command="{Binding OpenResultCommand}"
10799
Modifiers="Alt" />
108-
<KeyBinding
109-
Key="D1"
100+
<KeyBinding Key="D1"
110101
Command="{Binding OpenResultCommand}"
111102
CommandParameter="0"
112103
Modifiers="{Binding OpenResultCommandModifiers}" />
113-
<KeyBinding
114-
Key="D2"
104+
<KeyBinding Key="D2"
115105
Command="{Binding OpenResultCommand}"
116106
CommandParameter="1"
117107
Modifiers="{Binding OpenResultCommandModifiers}" />
118-
<KeyBinding
119-
Key="D3"
108+
<KeyBinding Key="D3"
120109
Command="{Binding OpenResultCommand}"
121110
CommandParameter="2"
122111
Modifiers="{Binding OpenResultCommandModifiers}" />
123-
<KeyBinding
124-
Key="D4"
112+
<KeyBinding Key="D4"
125113
Command="{Binding OpenResultCommand}"
126114
CommandParameter="3"
127115
Modifiers="{Binding OpenResultCommandModifiers}" />
128-
<KeyBinding
129-
Key="D5"
116+
<KeyBinding Key="D5"
130117
Command="{Binding OpenResultCommand}"
131118
CommandParameter="4"
132119
Modifiers="{Binding OpenResultCommandModifiers}" />
133-
<KeyBinding
134-
Key="D6"
120+
<KeyBinding Key="D6"
135121
Command="{Binding OpenResultCommand}"
136122
CommandParameter="5"
137123
Modifiers="{Binding OpenResultCommandModifiers}" />
138-
<KeyBinding
139-
Key="D7"
124+
<KeyBinding Key="D7"
140125
Command="{Binding OpenResultCommand}"
141126
CommandParameter="6"
142127
Modifiers="{Binding OpenResultCommandModifiers}" />
143-
<KeyBinding
144-
Key="D8"
128+
<KeyBinding Key="D8"
145129
Command="{Binding OpenResultCommand}"
146130
CommandParameter="7"
147131
Modifiers="{Binding OpenResultCommandModifiers}" />
148-
<KeyBinding
149-
Key="D9"
132+
<KeyBinding Key="D9"
150133
Command="{Binding OpenResultCommand}"
151134
CommandParameter="8"
152135
Modifiers="{Binding OpenResultCommandModifiers}" />
153-
<KeyBinding
154-
Key="D0"
136+
<KeyBinding Key="D0"
155137
Command="{Binding OpenResultCommand}"
156138
CommandParameter="9"
157139
Modifiers="{Binding OpenResultCommandModifiers}" />
158140
</Window.InputBindings>
159141
<Grid>
160-
<Border MouseDown="OnMouseDown" Style="{DynamicResource WindowBorderStyle}">
142+
<Border MouseDown="OnMouseDown"
143+
Style="{DynamicResource WindowBorderStyle}">
161144
<StackPanel Orientation="Vertical">
162145
<Grid>
163-
<TextBox
164-
x:Name="QueryTextSuggestionBox"
146+
<TextBox x:Name="QueryTextSuggestionBox"
165147
IsEnabled="False"
166148
Style="{DynamicResource QuerySuggestionBoxStyle}">
167149
<TextBox.Text>
168150
<MultiBinding Converter="{StaticResource QuerySuggestionBoxConverter}">
169-
<Binding ElementName="QueryTextBox" Mode="OneTime" />
170-
<Binding ElementName="ResultListBox" Path="SelectedItem" />
171-
<Binding ElementName="QueryTextBox" Path="Text" />
151+
<Binding ElementName="QueryTextBox"
152+
Mode="OneTime" />
153+
<Binding ElementName="ResultListBox"
154+
Path="SelectedItem" />
155+
<Binding ElementName="QueryTextBox"
156+
Path="Text" />
172157
</MultiBinding>
173158
</TextBox.Text>
174159
</TextBox>
175-
<TextBox
176-
x:Name="QueryTextBox"
160+
<TextBox x:Name="QueryTextBox"
177161
AllowDrop="True"
178162
Background="Transparent"
179163
PreviewDragOver="OnPreviewDragOver"
@@ -182,31 +166,42 @@
182166
PreviewKeyUp="QueryTextBox_KeyUp"
183167
Visibility="Visible">
184168
<TextBox.CommandBindings>
185-
<CommandBinding Command="ApplicationCommands.Copy" Executed="OnCopy" />
169+
<CommandBinding Command="ApplicationCommands.Copy"
170+
Executed="OnCopy" />
186171
</TextBox.CommandBindings>
187172
<TextBox.ContextMenu>
188173
<ContextMenu>
189-
<MenuItem Command="ApplicationCommands.Cut" Header="{DynamicResource cut}" />
190-
<MenuItem Command="ApplicationCommands.Copy" Header="{DynamicResource copy}" />
191-
<MenuItem Command="ApplicationCommands.Paste" Header="{DynamicResource paste}" />
192-
<Separator
193-
Margin="0"
174+
<MenuItem Command="ApplicationCommands.Cut"
175+
Header="{DynamicResource cut}" />
176+
<MenuItem Command="ApplicationCommands.Copy"
177+
Header="{DynamicResource copy}" />
178+
<MenuItem Command="ApplicationCommands.Paste"
179+
Header="{DynamicResource paste}" />
180+
<Separator Margin="0"
194181
Padding="0,4,0,4"
195182
Background="{DynamicResource ContextSeparator}" />
196-
<MenuItem Click="OnContextMenusForSettingsClick" Header="{DynamicResource flowlauncher_settings}" />
197-
<MenuItem Command="{Binding EscCommand}" Header="{DynamicResource closeWindow}" />
183+
<MenuItem Click="OnContextMenusForSettingsClick"
184+
Header="{DynamicResource flowlauncher_settings}" />
185+
<MenuItem Command="{Binding EscCommand}"
186+
Header="{DynamicResource closeWindow}" />
198187
</ContextMenu>
199188
</TextBox.ContextMenu>
200189
</TextBox>
201190

202-
<StackPanel x:Name="ClockPanel" Style="{DynamicResource ClockPanel}" IsHitTestVisible="False">
203-
<TextBlock x:Name="DateBox" Style="{DynamicResource DateBox}" />
204-
<TextBlock x:Name="ClockBox" Style="{DynamicResource ClockBox}" />
191+
<StackPanel x:Name="ClockPanel"
192+
Style="{DynamicResource ClockPanel}"
193+
IsHitTestVisible="False">
194+
<TextBlock
195+
Visibility="{Binding Settings.UseDate, Converter={StaticResource BooleanToVisibilityConverter}}"
196+
Style="{DynamicResource DateBox}"
197+
Text="{Binding DateText}" />
198+
<TextBlock Style="{DynamicResource ClockBox}"
199+
Visibility="{Binding Settings.UseClock, Converter={StaticResource BooleanToVisibilityConverter}}"
200+
Text="{Binding ClockText}"/>
205201
</StackPanel>
206202

207203
<Canvas Style="{DynamicResource SearchIconPosition}">
208-
<Image
209-
x:Name="PluginActivationIcon"
204+
<Image x:Name="PluginActivationIcon"
210205
Width="32"
211206
Height="32"
212207
Margin="0,0,0,0"
@@ -217,8 +212,7 @@
217212
Source="{Binding PluginIconPath}"
218213
Stretch="Uniform"
219214
Style="{DynamicResource PluginActivationIcon}" />
220-
<Path
221-
Name="SearchIcon"
215+
<Path Name="SearchIcon"
222216
Margin="0"
223217
Data="{DynamicResource SearchIconImg}"
224218
Stretch="Fill"
@@ -231,27 +225,32 @@
231225
<ContentControl>
232226
<ContentControl.Style>
233227
<Style TargetType="ContentControl">
234-
<Setter Property="Visibility" Value="Collapsed" />
228+
<Setter Property="Visibility"
229+
Value="Collapsed" />
235230
<Style.Triggers>
236-
<DataTrigger Binding="{Binding ElementName=ResultListBox, Path=Visibility}" Value="Visible">
237-
<Setter Property="Visibility" Value="Visible" />
231+
<DataTrigger Binding="{Binding ElementName=ResultListBox, Path=Visibility}"
232+
Value="Visible">
233+
<Setter Property="Visibility"
234+
Value="Visible" />
238235
</DataTrigger>
239-
<DataTrigger Binding="{Binding ElementName=ContextMenu, Path=Visibility}" Value="Visible">
240-
<Setter Property="Visibility" Value="Visible" />
236+
<DataTrigger Binding="{Binding ElementName=ContextMenu, Path=Visibility}"
237+
Value="Visible">
238+
<Setter Property="Visibility"
239+
Value="Visible" />
241240
</DataTrigger>
242-
<DataTrigger Binding="{Binding ElementName=History, Path=Visibility}" Value="Visible">
243-
<Setter Property="Visibility" Value="Visible" />
241+
<DataTrigger Binding="{Binding ElementName=History, Path=Visibility}"
242+
Value="Visible">
243+
<Setter Property="Visibility"
244+
Value="Visible" />
244245
</DataTrigger>
245246
</Style.Triggers>
246247
</Style>
247248
</ContentControl.Style>
248-
<Rectangle
249-
Width="Auto"
249+
<Rectangle Width="Auto"
250250
HorizontalAlignment="Stretch"
251251
Style="{DynamicResource SeparatorStyle}" />
252252
</ContentControl>
253-
<Line
254-
x:Name="ProgressBar"
253+
<Line x:Name="ProgressBar"
255254
Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=ActualWidth}"
256255
Height="2"
257256
HorizontalAlignment="Right"
@@ -267,49 +266,55 @@
267266
<Border Style="{DynamicResource WindowRadius}">
268267
<Border.Clip>
269268
<MultiBinding Converter="{StaticResource BorderClipConverter}">
270-
<Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}" />
271-
<Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}" />
272-
<Binding Path="CornerRadius" RelativeSource="{RelativeSource Self}" />
269+
<Binding Path="ActualWidth"
270+
RelativeSource="{RelativeSource Self}" />
271+
<Binding Path="ActualHeight"
272+
RelativeSource="{RelativeSource Self}" />
273+
<Binding Path="CornerRadius"
274+
RelativeSource="{RelativeSource Self}" />
273275
</MultiBinding>
274276
</Border.Clip>
275277
<ContentControl>
276-
<flowlauncher:ResultListBox
277-
x:Name="ResultListBox"
278+
<flowlauncher:ResultListBox x:Name="ResultListBox"
278279
DataContext="{Binding Results}"
279280
PreviewMouseDown="OnPreviewMouseButtonDown" />
280281
</ContentControl>
281282
</Border>
282283
<Border Style="{DynamicResource WindowRadius}">
283284
<Border.Clip>
284285
<MultiBinding Converter="{StaticResource BorderClipConverter}">
285-
<Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}" />
286-
<Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}" />
287-
<Binding Path="CornerRadius" RelativeSource="{RelativeSource Self}" />
286+
<Binding Path="ActualWidth"
287+
RelativeSource="{RelativeSource Self}" />
288+
<Binding Path="ActualHeight"
289+
RelativeSource="{RelativeSource Self}" />
290+
<Binding Path="CornerRadius"
291+
RelativeSource="{RelativeSource Self}" />
288292
</MultiBinding>
289293
</Border.Clip>
290294
<ContentControl>
291-
<flowlauncher:ResultListBox
292-
x:Name="ContextMenu"
295+
<flowlauncher:ResultListBox x:Name="ContextMenu"
293296
DataContext="{Binding ContextMenu}"
294297
PreviewMouseDown="OnPreviewMouseButtonDown" />
295298
</ContentControl>
296299
</Border>
297300
<Border Style="{DynamicResource WindowRadius}">
298301
<Border.Clip>
299302
<MultiBinding Converter="{StaticResource BorderClipConverter}">
300-
<Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}" />
301-
<Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}" />
302-
<Binding Path="CornerRadius" RelativeSource="{RelativeSource Self}" />
303+
<Binding Path="ActualWidth"
304+
RelativeSource="{RelativeSource Self}" />
305+
<Binding Path="ActualHeight"
306+
RelativeSource="{RelativeSource Self}" />
307+
<Binding Path="CornerRadius"
308+
RelativeSource="{RelativeSource Self}" />
303309
</MultiBinding>
304310
</Border.Clip>
305311
<ContentControl>
306-
<flowlauncher:ResultListBox
307-
x:Name="History"
312+
<flowlauncher:ResultListBox x:Name="History"
308313
DataContext="{Binding History}"
309314
PreviewMouseDown="OnPreviewMouseButtonDown" />
310315
</ContentControl>
311316
</Border>
312317
</StackPanel>
313318
</Border>
314319
</Grid>
315-
</Window>
320+
</Window>

0 commit comments

Comments
 (0)