Skip to content

Commit 7854cf3

Browse files
committed
Finishing editing logic, and add a few interactive for ActionKeywordSetting.xaml
1. It will automatically focus on the textbox 2. Enter will trigger the done button
1 parent e589785 commit 7854cf3

File tree

4 files changed

+74
-59
lines changed

4 files changed

+74
-59
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,10 @@ internal void OpenWindowsIndexingOptions()
4444
internal void UpdateActionKeyword(Settings.ActionKeyword modifiedActionKeyword, string newActionKeyword, string oldActionKeyword)
4545
{
4646
PluginManager.ReplaceActionKeyword(Context.CurrentPluginMetadata.ID, oldActionKeyword, newActionKeyword);
47-
48-
switch (modifiedActionKeyword)
49-
{
50-
case Settings.ActionKeyword.SearchActionKeyword:
51-
Settings.SearchActionKeyword = newActionKeyword;
52-
break;
53-
case Settings.ActionKeyword.PathSearchActionKeyword:
54-
Settings.PathSearchActionKeyword = newActionKeyword;
55-
break;
56-
case Settings.ActionKeyword.FileContentSearchActionKeyword:
57-
Settings.FileContentSearchActionKeyword = newActionKeyword;
58-
break;
59-
case Settings.ActionKeyword.IndexSearchActionKeyword:
60-
Settings.IndexSearchActionKeyword = newActionKeyword;
61-
break;
62-
}
6347
}
6448

65-
internal bool IsActionKeywordAlreadyAssigned(string newActionKeyword, string oldActionKeyword)
49+
internal bool IsActionKeywordAlreadyAssigned(string newActionKeyword)
6650
{
67-
// PluginManager.ActionKeywordRegistered does not check global action keyword ('*'), so use this logic instead
68-
if (newActionKeyword == Query.GlobalPluginWildcardSign)
69-
return newActionKeyword == oldActionKeyword;
70-
7151
return PluginManager.ActionKeywordRegistered(newActionKeyword);
7252
}
7353

Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
Margin="10" Grid.Row="0" Width="105" Grid.Column="1"
2626
VerticalAlignment="Center"
2727
HorizontalAlignment="Left"
28-
Text="{Binding CurrentActionKeyword.Keyword}" />
28+
Text="{Binding ActionKeyword}"
29+
PreviewKeyDown="TxtCurrentActionKeyword_OnKeyDown"/>
2930
<CheckBox Name="ChkActionKeywordEnabled" ToolTip="{DynamicResource plugin_explorer_actionkeyword_enabled_tooltip}"
3031
Margin="10" Grid.Row="0" Grid.Column="2" Content="{DynamicResource plugin_explorer_actionkeyword_enabled}"
3132
Width="auto"
32-
VerticalAlignment="Center" IsChecked="{Binding CurrentActionKeyword.Enabled}"
33+
VerticalAlignment="Center" IsChecked="{Binding Enabled}"
3334
Visibility="{Binding Visible}"/>
34-
<Button Click="OnDoneButtonClick" Grid.Row="1" Grid.Column="2"
35+
<Button Name="DownButton"
36+
Click="OnDoneButtonClick" Grid.Row="1" Grid.Column="2"
3537
Margin="10 0 10 0" Width="80" Height="35"
3638
Content="{DynamicResource plugin_explorer_actionkeyword_done}" />
3739
</Grid>
Lines changed: 67 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using Flow.Launcher.Plugin.Explorer.ViewModels;
2+
using ICSharpCode.SharpZipLib.Zip;
3+
using System;
24
using System.Collections.Generic;
35
using System.Linq;
46
using System.Windows;
7+
using System.Windows.Input;
58

69
namespace Flow.Launcher.Plugin.Explorer.Views
710
{
@@ -14,16 +17,28 @@ public partial class ActionKeywordSetting : Window
1417

1518
public ActionKeywordView CurrentActionKeyword { get; set; }
1619

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; }
1833

19-
private List<ActionKeywordView> actionKeywordListView;
2034

2135
private Settings settings;
36+
private string _actionKeyword;
2237

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;
2440

2541
public ActionKeywordSetting(SettingsViewModel settingsViewModel,
26-
List<ActionKeywordView> actionKeywordListView,
2742
ActionKeywordView selectedActionKeyword, Settings settings)
2843
{
2944
this.settingsViewModel = settingsViewModel;
@@ -32,60 +47,78 @@ public ActionKeywordSetting(SettingsViewModel settingsViewModel,
3247

3348
CurrentActionKeyword = selectedActionKeyword;
3449

35-
oldActionKeyword = selectedActionKeyword.Keyword;
50+
ActionKeyword = selectedActionKeyword.Keyword;
51+
Enabled = selectedActionKeyword.Enabled;
3652

37-
this.actionKeywordListView = actionKeywordListView;
38-
3953
InitializeComponent();
4054

55+
TxtCurrentActionKeyword.Focus();
4156
}
4257

4358
private void OnDoneButtonClick(object sender, RoutedEventArgs e)
4459
{
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();
4666
return;
67+
}
4768

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+
})
5075
{
5176
MessageBox.Show(
5277
settingsViewModel.Context.API.GetTranslation("plugin_explorer_globalActionKeywordInvalid"));
5378

5479
return;
5580
}
5681

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;
6883

69-
if (CurrentActionKeyword.KeywordProperty == Settings.ActionKeyword.PathSearchActionKeyword
70-
&& !settings.EnabledPathSearchKeyword)
71-
settings.EnabledPathSearchKeyword = true;
7284

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+
}
76105

77106
Close();
78-
79107
return;
80108
}
81109

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+
}
87113

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+
}
89122
}
90123
}
91124
}

Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private void btnEdit_Click(object sender, RoutedEventArgs e)
192192
{
193193
var selectedActionKeyword = lbxActionKeywords.SelectedItem as ActionKeywordView;
194194

195-
var actionKeywordWindow = new ActionKeywordSetting(viewModel, actionKeywordsListView,
195+
var actionKeywordWindow = new ActionKeywordSetting(viewModel,
196196
selectedActionKeyword, viewModel.Settings);
197197

198198
actionKeywordWindow.ShowDialog();

0 commit comments

Comments
 (0)