Skip to content

Commit e37d976

Browse files
committed
add option for user to customise Explorer's Action Keywords
ui + backend logic
1 parent 9feb4d6 commit e37d976

File tree

6 files changed

+180
-25
lines changed

6 files changed

+180
-25
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/Flow.Launcher.Plugin.Explorer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
</ItemGroup>
105105

106106
<ItemGroup>
107+
<ProjectReference Include="..\..\Flow.Launcher.Core\Flow.Launcher.Core.csproj" />
107108
<ProjectReference Include="..\..\Flow.Launcher.Infrastructure\Flow.Launcher.Infrastructure.csproj" />
108109
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
109110
</ItemGroup>

Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:system="clr-namespace:System;assembly=mscorlib">
44

55
<!--Dialogues-->
6+
<system:String x:Key="plugin_explorer_make_selection_warning">Please make a selection first</system:String>
67
<system:String x:Key="plugin_explorer_select_folder_link_warning">Please select a folder link</system:String>
78
<system:String x:Key="plugin_explorer_delete_folder_link">Are you sure you want to delete {0}?</system:String>
89
<system:String x:Key="plugin_explorer_deletefilefolderconfirm">Are you sure you want to permanently delete this {0}?</system:String>
@@ -17,6 +18,8 @@
1718
<system:String x:Key="plugin_explorer_quickfolderaccess_header">Quick Folder Access Paths</system:String>
1819
<system:String x:Key="plugin_explorer_indexsearchexcludedpaths_header">Index Search Excluded Paths</system:String>
1920
<system:String x:Key="plugin_explorer_manageindexoptions">Indexing Options</system:String>
21+
<system:String x:Key="plugin_explorer_actionkeywordview_search">Search Activation:</system:String>
22+
<system:String x:Key="plugin_explorer_actionkeywordview_filecontentsearch">File Content Search:</system:String>
2023

2124
<!--Plugin Infos-->
2225
<system:String x:Key="plugin_explorer_plugin_name">Explorer</system:String>

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Flow.Launcher.Infrastructure.Storage;
1+
using Flow.Launcher.Core.Plugin;
2+
using Flow.Launcher.Infrastructure.Storage;
23
using Flow.Launcher.Plugin.Explorer.Search;
34
using Flow.Launcher.Plugin.Explorer.Search.FolderLinks;
45
using System.Diagnostics;
@@ -40,5 +41,18 @@ internal void OpenWindowsIndexingOptions()
4041

4142
Process.Start(psi);
4243
}
44+
45+
internal void UpdateActionKeyword(string newActionKeyword, string oldActionKeyword)
46+
{
47+
PluginManager.ReplaceActionKeyword(Context.CurrentPluginMetadata.ID, oldActionKeyword, newActionKeyword);
48+
49+
if (Settings.FileContentSearchActionKeyword == oldActionKeyword)
50+
Settings.FileContentSearchActionKeyword = newActionKeyword;
51+
52+
if (Settings.SearchActionKeyword == oldActionKeyword)
53+
Settings.SearchActionKeyword = newActionKeyword;
54+
}
55+
56+
internal bool IsActionKeywordAlreadyAssigned(string newActionKeyword) => PluginManager.ActionKeywordRegistered(newActionKeyword);
4357
}
4458
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<Window x:Class="Flow.Launcher.Plugin.Explorer.Views.ActionKeywordSetting"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:Flow.Launcher.Plugin.Explorer.Views"
7+
mc:Ignorable="d"
8+
ResizeMode="NoResize"
9+
WindowStartupLocation="CenterScreen"
10+
Title="Action Keyword Setting" Height="200" Width="500">
11+
<Grid>
12+
<Grid.RowDefinitions>
13+
<RowDefinition />
14+
<RowDefinition />
15+
</Grid.RowDefinitions>
16+
<Grid.ColumnDefinitions>
17+
<ColumnDefinition Width="180" />
18+
<ColumnDefinition />
19+
</Grid.ColumnDefinitions>
20+
<TextBlock Margin="20 10 10 10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center"
21+
HorizontalAlignment="Left" Text="Current Action Keyword:" />
22+
<TextBox Name="txtCurrentActionKeyword"
23+
Margin="10" Grid.Row="0" Width="105" Grid.Column="1"
24+
VerticalAlignment="Center"
25+
HorizontalAlignment="Left" />
26+
27+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="1" Grid.Column="1">
28+
<Button Click="OnConfirmButtonClick"
29+
Margin="10 0 10 0" Width="80" Height="35"
30+
Content="OK" />
31+
<Button Click="OnCancelButtonClick"
32+
Margin="10 0 10 0" Width="80" Height="35"
33+
Content="Cancel" />
34+
</StackPanel>
35+
</Grid>
36+
</Window>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using Flow.Launcher.Plugin.Explorer.ViewModels;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Shapes;
14+
15+
namespace Flow.Launcher.Plugin.Explorer.Views
16+
{
17+
/// <summary>
18+
/// Interaction logic for ActionKeywordSetting.xaml
19+
/// </summary>
20+
public partial class ActionKeywordSetting : Window
21+
{
22+
private SettingsViewModel settingsViewModel;
23+
24+
private ActionKeywordView currentActionKeyword;
25+
26+
private List<ActionKeywordView> actionKeywordListView;
27+
28+
public ActionKeywordSetting(SettingsViewModel settingsViewModel, List<ActionKeywordView> actionKeywordListView, ActionKeywordView selectedActionKeyword)
29+
{
30+
InitializeComponent();
31+
32+
this.settingsViewModel = settingsViewModel;
33+
34+
currentActionKeyword = selectedActionKeyword;
35+
36+
txtCurrentActionKeyword.Text = selectedActionKeyword.Keyword;
37+
38+
this.actionKeywordListView = actionKeywordListView;
39+
}
40+
41+
private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
42+
{
43+
var newActionKeyword = txtCurrentActionKeyword.Text;
44+
45+
if (string.IsNullOrEmpty(newActionKeyword))
46+
return;
47+
48+
if (newActionKeyword == currentActionKeyword.Keyword)
49+
{
50+
Close();
51+
52+
return;
53+
}
54+
55+
if(!settingsViewModel.IsActionKeywordAlreadyAssigned(newActionKeyword))
56+
{
57+
settingsViewModel.UpdateActionKeyword(newActionKeyword, currentActionKeyword.Keyword);
58+
59+
actionKeywordListView.Where(x => x.Description == currentActionKeyword.Description).FirstOrDefault().Keyword = newActionKeyword;
60+
61+
Close();
62+
63+
return;
64+
}
65+
66+
MessageBox.Show(settingsViewModel.Context.API.GetTranslation("newActionKeywordsHasBeenAssigned"));
67+
}
68+
69+
private void OnCancelButtonClick(object sender, RoutedEventArgs e)
70+
{
71+
Close();
72+
73+
return;
74+
}
75+
}
76+
}

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

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ namespace Flow.Launcher.Plugin.Explorer.Views
2020
public partial class ExplorerSettings
2121
{
2222
private readonly SettingsViewModel viewModel;
23+
24+
private List<ActionKeywordView> actionKeywordsListView;
25+
2326
public ExplorerSettings(SettingsViewModel viewModel)
2427
{
2528
InitializeComponent();
@@ -30,10 +33,19 @@ public ExplorerSettings(SettingsViewModel viewModel)
3033

3134
lbxExcludedPaths.ItemsSource = this.viewModel.Settings.IndexSearchExcludedSubdirectoryPaths;
3235

33-
var actionKeywordsListView = new List<ActionKeywordView>();
34-
35-
actionKeywordsListView.Add(new ActionKeywordView() { Description = "Search Activation:", Keyword = this.viewModel.Settings.SearchActionKeyword });
36-
actionKeywordsListView.Add(new ActionKeywordView() { Description = "File Content Search:", Keyword = this.viewModel.Settings.FileContentSearchActionKeyword });
36+
actionKeywordsListView = new List<ActionKeywordView>
37+
{
38+
new ActionKeywordView()
39+
{
40+
Description = viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_search"),
41+
Keyword = this.viewModel.Settings.SearchActionKeyword
42+
},
43+
new ActionKeywordView()
44+
{
45+
Description = viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_filecontentsearch"),
46+
Keyword = this.viewModel.Settings.FileContentSearchActionKeyword
47+
}
48+
};
3749

3850
lbxActionKeywords.ItemsSource = actionKeywordsListView;
3951

@@ -175,33 +187,46 @@ private void btnDelete_Click(object sender, RoutedEventArgs e)
175187

176188
private void btnEdit_Click(object sender, RoutedEventArgs e)
177189
{
178-
var selectedRow = lbxFolderLinks.SelectedItem as FolderLink ?? lbxExcludedPaths.SelectedItem as FolderLink;
179-
180-
if (selectedRow != null)
190+
if (lbxActionKeywords.SelectedItem is ActionKeywordView)
181191
{
182-
var folderBrowserDialog = new FolderBrowserDialog();
183-
folderBrowserDialog.SelectedPath = selectedRow.Path;
184-
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
185-
{
186-
if (expFolderLinks.IsExpanded)
187-
{
188-
var link = viewModel.Settings.QuickFolderAccessLinks.First(x => x.Path == selectedRow.Path);
189-
link.Path = folderBrowserDialog.SelectedPath;
190-
}
192+
var selectedActionKeyword = lbxActionKeywords.SelectedItem as ActionKeywordView;
191193

192-
if (expExcludedPaths.IsExpanded)
193-
{
194-
var link = viewModel.Settings.IndexSearchExcludedSubdirectoryPaths.First(x => x.Path == selectedRow.Path);
195-
link.Path = folderBrowserDialog.SelectedPath;
196-
}
197-
}
194+
var actionKeywordWindow = new ActionKeywordSetting(viewModel, actionKeywordsListView, selectedActionKeyword);
195+
196+
actionKeywordWindow.ShowDialog();
198197

199198
RefreshView();
200199
}
201200
else
202201
{
203-
string warning = viewModel.Context.API.GetTranslation("plugin_explorer_select_folder_link_warning");
204-
MessageBox.Show(warning);
202+
var selectedRow = lbxFolderLinks.SelectedItem as FolderLink ?? lbxExcludedPaths.SelectedItem as FolderLink;
203+
204+
if (selectedRow != null)
205+
{
206+
var folderBrowserDialog = new FolderBrowserDialog();
207+
folderBrowserDialog.SelectedPath = selectedRow.Path;
208+
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
209+
{
210+
if (expFolderLinks.IsExpanded)
211+
{
212+
var link = viewModel.Settings.QuickFolderAccessLinks.First(x => x.Path == selectedRow.Path);
213+
link.Path = folderBrowserDialog.SelectedPath;
214+
}
215+
216+
if (expExcludedPaths.IsExpanded)
217+
{
218+
var link = viewModel.Settings.IndexSearchExcludedSubdirectoryPaths.First(x => x.Path == selectedRow.Path);
219+
link.Path = folderBrowserDialog.SelectedPath;
220+
}
221+
}
222+
223+
RefreshView();
224+
}
225+
else
226+
{
227+
string warning = viewModel.Context.API.GetTranslation("plugin_explorer_make_selection_warning");
228+
MessageBox.Show(warning);
229+
}
205230
}
206231
}
207232

0 commit comments

Comments
 (0)