1
1
using Flow . Launcher . Plugin . Explorer . ViewModels ;
2
+ using ICSharpCode . SharpZipLib . Zip ;
3
+ using System ;
2
4
using System . Collections . Generic ;
3
5
using System . Linq ;
4
6
using System . Windows ;
7
+ using System . Windows . Input ;
5
8
6
9
namespace Flow . Launcher . Plugin . Explorer . Views
7
10
{
@@ -14,16 +17,28 @@ public partial class ActionKeywordSetting : Window
14
17
15
18
public ActionKeywordView CurrentActionKeyword { get ; set ; }
16
19
17
- private string oldActionKeyword ;
20
+ public string ActionKeyword
21
+ {
22
+ get => _actionKeyword ;
23
+ set
24
+ {
25
+ // Set Enable to be true if user change ActionKeyword
26
+ if ( Enabled is not null )
27
+ Enabled = true ;
28
+ _actionKeyword = value ;
29
+ }
30
+ }
31
+
32
+ public bool ? Enabled { get ; set ; }
18
33
19
- private List < ActionKeywordView > actionKeywordListView ;
20
34
21
35
private Settings settings ;
36
+ private string _actionKeyword ;
22
37
23
- public Visibility Visible => CurrentActionKeyword . Enabled is not null ? Visibility . Visible : Visibility . Collapsed ;
38
+ public Visibility Visible =>
39
+ CurrentActionKeyword . Enabled is not null ? Visibility . Visible : Visibility . Collapsed ;
24
40
25
41
public ActionKeywordSetting ( SettingsViewModel settingsViewModel ,
26
- List < ActionKeywordView > actionKeywordListView ,
27
42
ActionKeywordView selectedActionKeyword , Settings settings )
28
43
{
29
44
this . settingsViewModel = settingsViewModel ;
@@ -32,60 +47,78 @@ public ActionKeywordSetting(SettingsViewModel settingsViewModel,
32
47
33
48
CurrentActionKeyword = selectedActionKeyword ;
34
49
35
- oldActionKeyword = selectedActionKeyword . Keyword ;
50
+ ActionKeyword = selectedActionKeyword . Keyword ;
51
+ Enabled = selectedActionKeyword . Enabled ;
36
52
37
- this . actionKeywordListView = actionKeywordListView ;
38
-
39
53
InitializeComponent ( ) ;
40
54
55
+ TxtCurrentActionKeyword . Focus ( ) ;
41
56
}
42
57
43
58
private void OnDoneButtonClick ( object sender , RoutedEventArgs e )
44
59
{
45
- if ( string . IsNullOrEmpty ( CurrentActionKeyword . Keyword ) )
60
+ if ( string . IsNullOrEmpty ( ActionKeyword ) )
61
+ ActionKeyword = Query . GlobalPluginWildcardSign ;
62
+
63
+ if ( CurrentActionKeyword . Keyword == ActionKeyword && CurrentActionKeyword . Enabled == Enabled )
64
+ {
65
+ Close ( ) ;
46
66
return ;
67
+ }
47
68
48
- if ( settingsViewModel . IsNewActionKeywordGlobal ( CurrentActionKeyword . Keyword )
49
- && CurrentActionKeyword . KeywordProperty == Settings . ActionKeyword . FileContentSearchActionKeyword )
69
+
70
+ if ( CurrentActionKeyword is
71
+ {
72
+ Keyword : Query . GlobalPluginWildcardSign ,
73
+ KeywordProperty : Settings . ActionKeyword . FileContentSearchActionKeyword
74
+ } )
50
75
{
51
76
MessageBox . Show (
52
77
settingsViewModel . Context . API . GetTranslation ( "plugin_explorer_globalActionKeywordInvalid" ) ) ;
53
78
54
79
return ;
55
80
}
56
81
57
- if ( ! settingsViewModel . IsActionKeywordAlreadyAssigned ( CurrentActionKeyword . Keyword , oldActionKeyword ) )
58
- {
59
- settingsViewModel . UpdateActionKeyword ( CurrentActionKeyword . KeywordProperty , CurrentActionKeyword . Keyword , oldActionKeyword ) ;
60
-
61
- actionKeywordListView . FirstOrDefault ( x => x . Description == CurrentActionKeyword . Description ) . Keyword =
62
- CurrentActionKeyword . Keyword ;
63
-
64
- // automatically help users set this to enabled if an action keyword is set and currently disabled
65
- if ( CurrentActionKeyword . KeywordProperty == Settings . ActionKeyword . IndexSearchActionKeyword
66
- && ! settings . EnabledIndexOnlySearchKeyword )
67
- settings . EnabledIndexOnlySearchKeyword = true ;
82
+ var oldActionKeyword = CurrentActionKeyword . Keyword ;
68
83
69
- if ( CurrentActionKeyword . KeywordProperty == Settings . ActionKeyword . PathSearchActionKeyword
70
- && ! settings . EnabledPathSearchKeyword )
71
- settings . EnabledPathSearchKeyword = true ;
72
84
73
- if ( CurrentActionKeyword . KeywordProperty == Settings . ActionKeyword . SearchActionKeyword
74
- && ! settings . EnableSearchActionKeyword )
75
- settings . EnableSearchActionKeyword = true ;
85
+ // == because of nullable
86
+ if ( Enabled == false || ! settingsViewModel . IsActionKeywordAlreadyAssigned ( ActionKeyword ) )
87
+ {
88
+ // Update View Data
89
+ CurrentActionKeyword . Keyword = ActionKeyword ;
90
+ CurrentActionKeyword . Enabled = Enabled ;
91
+
92
+ switch ( Enabled )
93
+ {
94
+ // reset to global so it does not take up an action keyword when disabled
95
+ // not for null Enable plugin
96
+ case false when oldActionKeyword != Query . GlobalPluginWildcardSign :
97
+ settingsViewModel . UpdateActionKeyword ( CurrentActionKeyword . KeywordProperty ,
98
+ Query . GlobalPluginWildcardSign , oldActionKeyword ) ;
99
+ break ;
100
+ default :
101
+ settingsViewModel . UpdateActionKeyword ( CurrentActionKeyword . KeywordProperty ,
102
+ CurrentActionKeyword . Keyword , oldActionKeyword ) ;
103
+ break ;
104
+ }
76
105
77
106
Close ( ) ;
78
-
79
107
return ;
80
108
}
81
109
82
- // reset to global so it does not take up an action keyword when disabled
83
- if ( CurrentActionKeyword . Enabled is not null && CurrentActionKeyword . Enabled == false && CurrentActionKeyword . Keyword != Query . GlobalPluginWildcardSign )
84
- settingsViewModel . UpdateActionKeyword ( CurrentActionKeyword . KeywordProperty , Query . GlobalPluginWildcardSign , oldActionKeyword ) ;
85
-
86
- Close ( ) ;
110
+ // The keyword is not valid, so show message
111
+ MessageBox . Show ( settingsViewModel . Context . API . GetTranslation ( "newActionKeywordsHasBeenAssigned" ) ) ;
112
+ }
87
113
88
- return ;
114
+ private void TxtCurrentActionKeyword_OnKeyDown ( object sender , KeyEventArgs e )
115
+ {
116
+ if ( e . Key == Key . Enter )
117
+ {
118
+ DownButton . Focus ( ) ;
119
+ OnDoneButtonClick ( sender , e ) ;
120
+ e . Handled = true ;
121
+ }
89
122
}
90
123
}
91
124
}
0 commit comments