@@ -36,6 +36,7 @@ namespace Flow.Launcher
36
36
public partial class MainWindow
37
37
{
38
38
#region Private Fields
39
+
39
40
private Settings _settings ;
40
41
private NotifyIcon _notifyIcon ;
41
42
private ContextMenu contextMenu ;
@@ -50,7 +51,7 @@ public MainWindow(Settings settings, MainViewModel mainVM)
50
51
DataContext = mainVM ;
51
52
_viewModel = mainVM ;
52
53
_settings = settings ;
53
-
54
+
54
55
InitializeComponent ( ) ;
55
56
InitializePosition ( ) ;
56
57
animationSound . Open ( new Uri ( AppDomain . CurrentDomain . BaseDirectory + "Resources\\ open.wav" ) ) ;
@@ -60,7 +61,7 @@ public MainWindow()
60
61
{
61
62
InitializeComponent ( ) ;
62
63
}
63
-
64
+
64
65
private void OnCopy ( object sender , ExecutedRoutedEventArgs e )
65
66
{
66
67
if ( QueryTextBox . SelectionLength == 0 )
@@ -108,29 +109,29 @@ private void OnLoaded(object sender, RoutedEventArgs _)
108
109
switch ( e . PropertyName )
109
110
{
110
111
case nameof ( MainViewModel . MainWindowVisibilityStatus ) :
112
+ {
113
+ if ( _viewModel . MainWindowVisibilityStatus )
111
114
{
112
- if ( _viewModel . MainWindowVisibilityStatus )
115
+ if ( _settings . UseSound )
113
116
{
114
- if ( _settings . UseSound )
115
- {
116
- animationSound . Position = TimeSpan . Zero ;
117
- animationSound . Play ( ) ;
118
- }
119
- UpdatePosition ( ) ;
120
- Activate ( ) ;
121
- QueryTextBox . Focus ( ) ;
122
- _settings . ActivateTimes ++ ;
123
- if ( ! _viewModel . LastQuerySelected )
124
- {
125
- QueryTextBox . SelectAll ( ) ;
126
- _viewModel . LastQuerySelected = true ;
127
- }
128
-
129
- if ( _settings . UseAnimation )
130
- WindowAnimator ( ) ;
117
+ animationSound . Position = TimeSpan . Zero ;
118
+ animationSound . Play ( ) ;
131
119
}
132
- break ;
120
+ UpdatePosition ( ) ;
121
+ Activate ( ) ;
122
+ QueryTextBox . Focus ( ) ;
123
+ _settings . ActivateTimes ++ ;
124
+ if ( ! _viewModel . LastQuerySelected )
125
+ {
126
+ QueryTextBox . SelectAll ( ) ;
127
+ _viewModel . LastQuerySelected = true ;
128
+ }
129
+
130
+ if ( _settings . UseAnimation )
131
+ WindowAnimator ( ) ;
133
132
}
133
+ break ;
134
+ }
134
135
case nameof ( MainViewModel . QueryTextCursorMovedToEnd ) :
135
136
if ( _viewModel . QueryTextCursorMovedToEnd )
136
137
{
@@ -211,35 +212,45 @@ private void InitializeNotifyIcon()
211
212
Visible = ! _settings . HideNotifyIcon
212
213
} ;
213
214
contextMenu = new ContextMenu ( ) ;
214
- var openIcon = new FontIcon { Glyph = "\ue71e " } ;
215
+ var openIcon = new FontIcon
216
+ {
217
+ Glyph = "\ue71e "
218
+ } ;
215
219
var open = new MenuItem
216
220
{
217
- Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayOpen" ) + " (" + _settings . Hotkey + ")" ,
218
- Icon = openIcon
221
+ Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayOpen" ) + " (" + _settings . Hotkey + ")" , Icon = openIcon
222
+ } ;
223
+ var gamemodeIcon = new FontIcon
224
+ {
225
+ Glyph = "\ue7fc "
219
226
} ;
220
- var gamemodeIcon = new FontIcon { Glyph = "\ue7fc " } ;
221
227
var gamemode = new MenuItem
222
228
{
223
- Header = InternationalizationManager . Instance . GetTranslation ( "GameMode" ) ,
224
- Icon = gamemodeIcon
229
+ Header = InternationalizationManager . Instance . GetTranslation ( "GameMode" ) , Icon = gamemodeIcon
230
+ } ;
231
+ var positionresetIcon = new FontIcon
232
+ {
233
+ Glyph = "\ue73f "
225
234
} ;
226
- var positionresetIcon = new FontIcon { Glyph = "\ue73f " } ;
227
235
var positionreset = new MenuItem
228
236
{
229
- Header = InternationalizationManager . Instance . GetTranslation ( "PositionReset" ) ,
230
- Icon = positionresetIcon
237
+ Header = InternationalizationManager . Instance . GetTranslation ( "PositionReset" ) , Icon = positionresetIcon
238
+ } ;
239
+ var settingsIcon = new FontIcon
240
+ {
241
+ Glyph = "\ue713 "
231
242
} ;
232
- var settingsIcon = new FontIcon { Glyph = "\ue713 " } ;
233
243
var settings = new MenuItem
234
244
{
235
- Header = InternationalizationManager . Instance . GetTranslation ( "iconTraySettings" ) ,
236
- Icon = settingsIcon
245
+ Header = InternationalizationManager . Instance . GetTranslation ( "iconTraySettings" ) , Icon = settingsIcon
246
+ } ;
247
+ var exitIcon = new FontIcon
248
+ {
249
+ Glyph = "\ue7e8 "
237
250
} ;
238
- var exitIcon = new FontIcon { Glyph = "\ue7e8 " } ;
239
251
var exit = new MenuItem
240
252
{
241
- Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayExit" ) ,
242
- Icon = exitIcon
253
+ Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayExit" ) , Icon = exitIcon
243
254
} ;
244
255
245
256
open . Click += ( o , e ) => _viewModel . ToggleFlowLauncher ( ) ;
@@ -300,10 +311,10 @@ private void ToggleGameMode()
300
311
}
301
312
private async void PositionReset ( )
302
313
{
303
- _viewModel . Show ( ) ;
304
- await Task . Delay ( 300 ) ; // If don't give a time, Positioning will be weird.
305
- Left = HorizonCenter ( ) ;
306
- Top = VerticalCenter ( ) ;
314
+ _viewModel . Show ( ) ;
315
+ await Task . Delay ( 300 ) ; // If don't give a time, Positioning will be weird.
316
+ Left = HorizonCenter ( ) ;
317
+ Top = VerticalCenter ( ) ;
307
318
}
308
319
private void InitProgressbarAnimation ( )
309
320
{
@@ -320,14 +331,30 @@ private void InitProgressbarAnimation()
320
331
da . Freeze ( ) ;
321
332
da1 . Freeze ( ) ;
322
333
323
- var beginStoryboard = new BeginStoryboard ( ) ;
324
- beginStoryboard . Storyboard = progressBarStoryBoard ;
334
+ const string progressBarAnimationName = "ProgressBarAnimation" ;
335
+ var beginStoryboard = new BeginStoryboard
336
+ {
337
+ Name = progressBarAnimationName , Storyboard = progressBarStoryBoard
338
+ } ;
339
+
340
+ var stopStoryboard = new StopStoryboard ( )
341
+ {
342
+ BeginStoryboardName = progressBarAnimationName
343
+ } ;
325
344
326
- var trigger = new Trigger { Property = System . Windows . Shapes . Line . VisibilityProperty , Value = Visibility . Visible } ;
345
+ var trigger = new Trigger
346
+ {
347
+ Property = VisibilityProperty , Value = Visibility . Visible
348
+ } ;
327
349
trigger . EnterActions . Add ( beginStoryboard ) ;
350
+ trigger . ExitActions . Add ( stopStoryboard ) ;
351
+
328
352
329
- var progressStyle = new Style ( typeof ( System . Windows . Shapes . Line ) ) ;
330
- progressStyle . BasedOn = FindResource ( "PendingLineStyle" ) as Style ;
353
+ var progressStyle = new Style ( typeof ( System . Windows . Shapes . Line ) )
354
+ {
355
+ BasedOn = FindResource ( "PendingLineStyle" ) as Style
356
+ } ;
357
+ progressStyle . RegisterName ( progressBarAnimationName , beginStoryboard ) ;
331
358
progressStyle . Triggers . Add ( trigger ) ;
332
359
333
360
ProgressBar . Style = progressStyle ;
@@ -343,7 +370,7 @@ public void WindowAnimator()
343
370
UpdatePosition ( ) ;
344
371
Storyboard sb = new Storyboard ( ) ;
345
372
Storyboard iconsb = new Storyboard ( ) ;
346
- CircleEase easing = new CircleEase ( ) ; // or whatever easing class you want
373
+ CircleEase easing = new CircleEase ( ) ; // or whatever easing class you want
347
374
easing . EasingMode = EasingMode . EaseInOut ;
348
375
var da = new DoubleAnimation
349
376
{
@@ -360,14 +387,14 @@ public void WindowAnimator()
360
387
Duration = TimeSpan . FromSeconds ( 0.25 ) ,
361
388
FillBehavior = FillBehavior . Stop
362
389
} ;
363
- var da3 = new DoubleAnimation
364
- {
365
- From = 12 ,
366
- To = 0 ,
367
- EasingFunction = easing ,
368
- Duration = TimeSpan . FromSeconds ( 0.36 ) ,
369
- FillBehavior = FillBehavior . Stop
370
- } ;
390
+ var da3 = new DoubleAnimation
391
+ {
392
+ From = 12 ,
393
+ To = 0 ,
394
+ EasingFunction = easing ,
395
+ Duration = TimeSpan . FromSeconds ( 0.36 ) ,
396
+ FillBehavior = FillBehavior . Stop
397
+ } ;
371
398
Storyboard . SetTarget ( da , this ) ;
372
399
Storyboard . SetTargetProperty ( da , new PropertyPath ( Window . OpacityProperty ) ) ;
373
400
Storyboard . SetTargetProperty ( da2 , new PropertyPath ( Window . TopProperty ) ) ;
@@ -395,10 +422,10 @@ private void OnPreviewDragOver(object sender, DragEventArgs e)
395
422
private async void OnContextMenusForSettingsClick ( object sender , RoutedEventArgs e )
396
423
{
397
424
_viewModel . Hide ( ) ;
398
-
399
- if ( _settings . UseAnimation )
425
+
426
+ if ( _settings . UseAnimation )
400
427
await Task . Delay ( 100 ) ;
401
-
428
+
402
429
App . API . OpenSettingDialog ( ) ;
403
430
}
404
431
@@ -416,7 +443,7 @@ private async void OnDeactivated(object sender, EventArgs e)
416
443
// and always after Settings window is closed.
417
444
if ( _settings . UseAnimation )
418
445
await Task . Delay ( 100 ) ;
419
-
446
+
420
447
if ( _settings . HideWhenDeactive )
421
448
{
422
449
_viewModel . Hide ( ) ;
@@ -454,7 +481,7 @@ public void HideStartup()
454
481
_viewModel . Show ( ) ;
455
482
}
456
483
}
457
-
484
+
458
485
public double HorizonCenter ( )
459
486
{
460
487
var screen = Screen . FromPoint ( System . Windows . Forms . Cursor . Position ) ;
@@ -536,9 +563,9 @@ private void OnKeyDown(object sender, KeyEventArgs e)
536
563
&& QueryTextBox . Text . Length > 0
537
564
&& QueryTextBox . CaretIndex == QueryTextBox . Text . Length )
538
565
{
539
- var queryWithoutActionKeyword =
566
+ var queryWithoutActionKeyword =
540
567
QueryBuilder . Build ( QueryTextBox . Text . Trim ( ) , PluginManager . NonGlobalPlugins ) . Search ;
541
-
568
+
542
569
if ( FilesFolders . IsLocationPathString ( queryWithoutActionKeyword ) )
543
570
{
544
571
_viewModel . BackspaceCommand . Execute ( null ) ;
@@ -574,7 +601,7 @@ public void InitializeColorScheme()
574
601
575
602
private void QueryTextBox_KeyUp ( object sender , KeyEventArgs e )
576
603
{
577
- if ( _viewModel . QueryText != QueryTextBox . Text )
604
+ if ( _viewModel . QueryText != QueryTextBox . Text )
578
605
{
579
606
BindingExpression be = QueryTextBox . GetBindingExpression ( System . Windows . Controls . TextBox . TextProperty ) ;
580
607
be . UpdateSource ( ) ;
0 commit comments