mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #449 from Flow-Launcher/ExplorerPathActionkeyword
Add specific keyword for path explore in explorer plugin
This commit is contained in:
commit
ad36f89345
15 changed files with 312 additions and 163 deletions
|
|
@ -252,6 +252,8 @@ namespace Flow.Launcher.Core.Plugin
|
|||
|
||||
public static bool ActionKeywordRegistered(string actionKeyword)
|
||||
{
|
||||
// this method is only checking for action keywords (defined as not '*') registration
|
||||
// hence the actionKeyword != Query.GlobalPluginWildcardSign logic
|
||||
return actionKeyword != Query.GlobalPluginWildcardSign
|
||||
&& NonGlobalPlugins.ContainsKey(actionKeyword);
|
||||
}
|
||||
|
|
@ -276,7 +278,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// used to add action keyword for multiple action keyword plugin
|
||||
/// used to remove action keyword for multiple action keyword plugin
|
||||
/// e.g. web search
|
||||
/// </summary>
|
||||
public static void RemoveActionKeyword(string id, string oldActionkeyword)
|
||||
|
|
|
|||
|
|
@ -16,11 +16,13 @@ namespace Flow.Launcher.Infrastructure.UserSettings
|
|||
{
|
||||
var settings = Plugins[metadata.ID];
|
||||
|
||||
// TODO: Remove. This is one off for 1.2.0 release.
|
||||
// Introduced a new action keyword in Explorer, so need to update plugin setting in the UserData folder.
|
||||
// This kind of plugin meta update should be handled by a dedicated method trigger by version bump.
|
||||
// TODO: Remove. This is backwards compatibility for 1.8.0 release.
|
||||
// Introduced two new action keywords in Explorer, so need to update plugin setting in the UserData folder.
|
||||
if (metadata.ID == "572be03c74c642baae319fc283e561a8" && metadata.ActionKeywords.Count != settings.ActionKeywords.Count)
|
||||
settings.ActionKeywords = metadata.ActionKeywords;
|
||||
{
|
||||
settings.ActionKeywords.Add(Query.GlobalPluginWildcardSign); // for index search
|
||||
settings.ActionKeywords.Add(Query.GlobalPluginWildcardSign); // for path search
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(settings.Version))
|
||||
settings.Version = metadata.Version;
|
||||
|
|
|
|||
|
|
@ -547,26 +547,9 @@ namespace Flow.Launcher.ViewModel
|
|||
|
||||
private void RemoveOldQueryResults(Query query)
|
||||
{
|
||||
string lastKeyword = _lastQuery.ActionKeyword;
|
||||
|
||||
string keyword = query.ActionKeyword;
|
||||
if (string.IsNullOrEmpty(lastKeyword))
|
||||
if (_lastQuery.ActionKeyword != query.ActionKeyword)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
Results.KeepResultsFor(PluginManager.NonGlobalPlugins[keyword].Metadata);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
Results.KeepResultsExcept(PluginManager.NonGlobalPlugins[lastKeyword].Metadata);
|
||||
}
|
||||
else if (lastKeyword != keyword)
|
||||
{
|
||||
Results.KeepResultsFor(PluginManager.NonGlobalPlugins[keyword].Metadata);
|
||||
}
|
||||
Results.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,8 +19,14 @@
|
|||
<system:String x:Key="plugin_explorer_quickaccesslinks_header">Quick Access Links</system:String>
|
||||
<system:String x:Key="plugin_explorer_indexsearchexcludedpaths_header">Index Search Excluded Paths</system:String>
|
||||
<system:String x:Key="plugin_explorer_manageindexoptions">Indexing Options</system:String>
|
||||
<system:String x:Key="plugin_explorer_actionkeywordview_search">Search Activation:</system:String>
|
||||
<system:String x:Key="plugin_explorer_actionkeywordview_search">Search:</system:String>
|
||||
<system:String x:Key="plugin_explorer_actionkeywordview_pathsearch">Path Search:</system:String>
|
||||
<system:String x:Key="plugin_explorer_actionkeywordview_filecontentsearch">File Content Search:</system:String>
|
||||
<system:String x:Key="plugin_explorer_actionkeywordview_indexsearch">Index Search:</system:String>
|
||||
<system:String x:Key="plugin_explorer_actionkeyword_current">Current Action Keyword:</system:String>
|
||||
<system:String x:Key="plugin_explorer_actionkeyword_done">Done</system:String>
|
||||
<system:String x:Key="plugin_explorer_actionkeyword_enabled">Enabled</system:String>
|
||||
<system:String x:Key="plugin_explorer_actionkeyword_enabled_tooltip">When disabled Flow will not execute this search option, and will additionally revert back to '*' to free up the action keyword</system:String>
|
||||
|
||||
<!--Plugin Infos-->
|
||||
<system:String x:Key="plugin_explorer_plugin_name">Explorer</system:String>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
<system:String x:Key="plugin_explorer_indexsearchexcludedpaths_header">索引搜索排除的路径</system:String>
|
||||
<system:String x:Key="plugin_explorer_manageindexoptions">索引选项</system:String>
|
||||
<system:String x:Key="plugin_explorer_actionkeywordview_search">搜索激活:</system:String>
|
||||
<system:String x:Key="plugin_explorer_actionkeywordview_pathsearch">路径搜索激活:</system:String>
|
||||
<system:String x:Key="plugin_explorer_actionkeywordview_filecontentsearch">文件内容搜索:</system:String>
|
||||
|
||||
<!--Plugin Infos-->
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace Flow.Launcher.Plugin.Explorer
|
|||
return new ExplorerSettings(viewModel);
|
||||
}
|
||||
|
||||
public async Task InitAsync(PluginInitContext context)
|
||||
public Task InitAsync(PluginInitContext context)
|
||||
{
|
||||
Context = context;
|
||||
|
||||
|
|
@ -47,6 +47,8 @@ namespace Flow.Launcher.Plugin.Explorer
|
|||
contextMenu = new ContextMenu(Context, Settings, viewModel);
|
||||
searchManager = new SearchManager(Settings, Context);
|
||||
ResultManager.Init(Context);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public List<Result> LoadContextMenus(Result selectedResult)
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
{
|
||||
internal static bool IsEnvironmentVariableSearch(string search)
|
||||
{
|
||||
return LoadEnvironmentStringPaths().Count > 0
|
||||
&& search.StartsWith("%")
|
||||
return search.StartsWith("%")
|
||||
&& search != "%%"
|
||||
&& !search.Contains("\\");
|
||||
&& !search.Contains("\\") &&
|
||||
LoadEnvironmentStringPaths().Count > 0;
|
||||
}
|
||||
|
||||
internal static Dictionary<string, string> LoadEnvironmentStringPaths()
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
{
|
||||
private static PathEqualityComparator instance;
|
||||
public static PathEqualityComparator Instance => instance ??= new PathEqualityComparator();
|
||||
|
||||
public bool Equals(Result x, Result y)
|
||||
{
|
||||
return x.SubTitle == y.SubTitle;
|
||||
|
|
@ -39,21 +40,61 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
|
||||
internal async Task<List<Result>> SearchAsync(Query query, CancellationToken token)
|
||||
{
|
||||
var results = new HashSet<Result>(PathEqualityComparator.Instance);
|
||||
|
||||
var querySearch = query.Search;
|
||||
|
||||
if (IsFileContentSearch(query.ActionKeyword))
|
||||
return await WindowsIndexFileContentSearchAsync(query, querySearch, token).ConfigureAwait(false);
|
||||
|
||||
var result = new HashSet<Result>(PathEqualityComparator.Instance);
|
||||
|
||||
if (ActionKeywordMatch(query, Settings.ActionKeyword.PathSearchActionKeyword) ||
|
||||
ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword))
|
||||
{
|
||||
result.UnionWith(await PathSearchAsync(query, token).ConfigureAwait(false));
|
||||
}
|
||||
|
||||
if ((ActionKeywordMatch(query, Settings.ActionKeyword.IndexSearchActionKeyword) ||
|
||||
ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword)) &&
|
||||
querySearch.Length > 0 &&
|
||||
!querySearch.IsLocationPathString())
|
||||
{
|
||||
result.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token)
|
||||
.ConfigureAwait(false));
|
||||
}
|
||||
|
||||
return result.ToList();
|
||||
}
|
||||
|
||||
private bool ActionKeywordMatch(Query query, Settings.ActionKeyword allowedActionKeyword)
|
||||
{
|
||||
var keyword = query.ActionKeyword.Length == 0 ? Query.GlobalPluginWildcardSign : query.ActionKeyword;
|
||||
|
||||
return allowedActionKeyword switch
|
||||
{
|
||||
Settings.ActionKeyword.SearchActionKeyword => settings.EnableSearchActionKeyword &&
|
||||
keyword == settings.SearchActionKeyword,
|
||||
Settings.ActionKeyword.PathSearchActionKeyword => settings.EnabledPathSearchKeyword &&
|
||||
keyword == settings.PathSearchActionKeyword,
|
||||
Settings.ActionKeyword.FileContentSearchActionKeyword => keyword ==
|
||||
settings.FileContentSearchActionKeyword,
|
||||
Settings.ActionKeyword.IndexSearchActionKeyword => settings.EnabledIndexOnlySearchKeyword &&
|
||||
keyword == settings.IndexSearchActionKeyword
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<List<Result>> PathSearchAsync(Query query, CancellationToken token = default)
|
||||
{
|
||||
var querySearch = query.Search;
|
||||
|
||||
// This allows the user to type the assigned action keyword and only see the list of quick folder links
|
||||
if (string.IsNullOrEmpty(query.Search))
|
||||
return QuickAccess.AccessLinkListAll(query, settings.QuickAccessLinks);
|
||||
|
||||
var results = new HashSet<Result>(PathEqualityComparator.Instance);
|
||||
|
||||
var quickaccessLinks = QuickAccess.AccessLinkListMatched(query, settings.QuickAccessLinks);
|
||||
|
||||
if (quickaccessLinks.Count > 0)
|
||||
results.UnionWith(quickaccessLinks);
|
||||
results.UnionWith(quickaccessLinks);
|
||||
|
||||
var isEnvironmentVariable = EnvironmentVariables.IsEnvironmentVariableSearch(querySearch);
|
||||
|
||||
|
|
@ -63,13 +104,6 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
// Query is a location path with a full environment variable, eg. %appdata%\somefolder\
|
||||
var isEnvironmentVariablePath = querySearch[1..].Contains("%\\");
|
||||
|
||||
if (!querySearch.IsLocationPathString() && !isEnvironmentVariablePath)
|
||||
{
|
||||
results.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false));
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
|
||||
var locationPath = querySearch;
|
||||
|
||||
if (isEnvironmentVariablePath)
|
||||
|
|
@ -99,7 +133,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
return results.ToList();
|
||||
}
|
||||
|
||||
private async Task<List<Result>> WindowsIndexFileContentSearchAsync(Query query, string querySearchString, CancellationToken token)
|
||||
private async Task<List<Result>> WindowsIndexFileContentSearchAsync(Query query, string querySearchString,
|
||||
CancellationToken token)
|
||||
{
|
||||
var queryConstructor = new QueryConstructor(settings);
|
||||
|
||||
|
|
@ -107,11 +142,11 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
return new List<Result>();
|
||||
|
||||
return await IndexSearch.WindowsIndexSearchAsync(querySearchString,
|
||||
queryConstructor.CreateQueryHelper().ConnectionString,
|
||||
queryConstructor.QueryForFileContentSearch,
|
||||
settings.IndexSearchExcludedSubdirectoryPaths,
|
||||
query,
|
||||
token).ConfigureAwait(false);
|
||||
queryConstructor.CreateQueryHelper().ConnectionString,
|
||||
queryConstructor.QueryForFileContentSearch,
|
||||
settings.IndexSearchExcludedSubdirectoryPaths,
|
||||
query,
|
||||
token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public bool IsFileContentSearch(string actionKeyword)
|
||||
|
|
@ -138,28 +173,30 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
return await windowsIndexSearch(query, querySearchString, token);
|
||||
}
|
||||
|
||||
private async Task<List<Result>> WindowsIndexFilesAndFoldersSearchAsync(Query query, string querySearchString, CancellationToken token)
|
||||
private async Task<List<Result>> WindowsIndexFilesAndFoldersSearchAsync(Query query, string querySearchString,
|
||||
CancellationToken token)
|
||||
{
|
||||
var queryConstructor = new QueryConstructor(settings);
|
||||
|
||||
return await IndexSearch.WindowsIndexSearchAsync(querySearchString,
|
||||
queryConstructor.CreateQueryHelper().ConnectionString,
|
||||
queryConstructor.QueryForAllFilesAndFolders,
|
||||
settings.IndexSearchExcludedSubdirectoryPaths,
|
||||
query,
|
||||
token).ConfigureAwait(false);
|
||||
queryConstructor.CreateQueryHelper().ConnectionString,
|
||||
queryConstructor.QueryForAllFilesAndFolders,
|
||||
settings.IndexSearchExcludedSubdirectoryPaths,
|
||||
query,
|
||||
token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task<List<Result>> WindowsIndexTopLevelFolderSearchAsync(Query query, string path, CancellationToken token)
|
||||
private async Task<List<Result>> WindowsIndexTopLevelFolderSearchAsync(Query query, string path,
|
||||
CancellationToken token)
|
||||
{
|
||||
var queryConstructor = new QueryConstructor(settings);
|
||||
|
||||
return await IndexSearch.WindowsIndexSearchAsync(path,
|
||||
queryConstructor.CreateQueryHelper().ConnectionString,
|
||||
queryConstructor.QueryForTopLevelDirectorySearch,
|
||||
settings.IndexSearchExcludedSubdirectoryPaths,
|
||||
query,
|
||||
token).ConfigureAwait(false);
|
||||
queryConstructor.CreateQueryHelper().ConnectionString,
|
||||
queryConstructor.QueryForTopLevelDirectorySearch,
|
||||
settings.IndexSearchExcludedSubdirectoryPaths,
|
||||
query,
|
||||
token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private bool UseWindowsIndexForDirectorySearch(string locationPath)
|
||||
|
|
@ -170,11 +207,11 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
return false;
|
||||
|
||||
if (settings.IndexSearchExcludedSubdirectoryPaths
|
||||
.Any(x => FilesFolders.ReturnPreviousDirectoryIfIncompleteString(pathToDirectory)
|
||||
.StartsWith(x.Path, StringComparison.OrdinalIgnoreCase)))
|
||||
.Any(x => FilesFolders.ReturnPreviousDirectoryIfIncompleteString(pathToDirectory)
|
||||
.StartsWith(x.Path, StringComparison.OrdinalIgnoreCase)))
|
||||
return false;
|
||||
|
||||
return IndexSearch.PathIsIndexed(pathToDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
using Flow.Launcher.Plugin.Explorer.Search;
|
||||
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
|
||||
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Flow.Launcher.Plugin.Explorer
|
||||
{
|
||||
|
|
@ -18,7 +21,57 @@ namespace Flow.Launcher.Plugin.Explorer
|
|||
public List<AccessLink> IndexSearchExcludedSubdirectoryPaths { get; set; } = new List<AccessLink>();
|
||||
|
||||
public string SearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
|
||||
public bool EnableSearchActionKeyword { get; set; } = true;
|
||||
|
||||
public string FileContentSearchActionKeyword { get; set; } = Constants.DefaultContentSearchActionKeyword;
|
||||
|
||||
public string PathSearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
|
||||
|
||||
public bool EnabledPathSearchKeyword { get; set; }
|
||||
|
||||
public string IndexSearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
|
||||
|
||||
public bool EnabledIndexOnlySearchKeyword { get; set; }
|
||||
|
||||
internal enum ActionKeyword
|
||||
{
|
||||
SearchActionKeyword,
|
||||
PathSearchActionKeyword,
|
||||
FileContentSearchActionKeyword,
|
||||
IndexSearchActionKeyword
|
||||
}
|
||||
|
||||
internal string GetActionKeyword(ActionKeyword actionKeyword) => actionKeyword switch
|
||||
{
|
||||
ActionKeyword.SearchActionKeyword => SearchActionKeyword,
|
||||
ActionKeyword.PathSearchActionKeyword => PathSearchActionKeyword,
|
||||
ActionKeyword.FileContentSearchActionKeyword => FileContentSearchActionKeyword,
|
||||
ActionKeyword.IndexSearchActionKeyword => IndexSearchActionKeyword
|
||||
};
|
||||
|
||||
internal void SetActionKeyword(ActionKeyword actionKeyword, string keyword) => _ = actionKeyword switch
|
||||
{
|
||||
ActionKeyword.SearchActionKeyword => SearchActionKeyword = keyword,
|
||||
ActionKeyword.PathSearchActionKeyword => PathSearchActionKeyword = keyword,
|
||||
ActionKeyword.FileContentSearchActionKeyword => FileContentSearchActionKeyword = keyword,
|
||||
ActionKeyword.IndexSearchActionKeyword => IndexSearchActionKeyword = keyword,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "Unexpected property")
|
||||
};
|
||||
|
||||
internal bool? GetActionKeywordEnable(ActionKeyword actionKeyword) => actionKeyword switch
|
||||
{
|
||||
ActionKeyword.SearchActionKeyword => EnableSearchActionKeyword,
|
||||
ActionKeyword.PathSearchActionKeyword => EnabledPathSearchKeyword,
|
||||
ActionKeyword.IndexSearchActionKeyword => EnabledIndexOnlySearchKeyword,
|
||||
_ => null
|
||||
};
|
||||
|
||||
internal void SetActionKeywordEnable(ActionKeyword actionKeyword, bool enable) => _ = actionKeyword switch
|
||||
{
|
||||
ActionKeyword.SearchActionKeyword => EnableSearchActionKeyword = enable,
|
||||
ActionKeyword.PathSearchActionKeyword => EnabledPathSearchKeyword = enable,
|
||||
ActionKeyword.IndexSearchActionKeyword => EnabledIndexOnlySearchKeyword = enable,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "Unexpected property")
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -41,18 +41,15 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
|
|||
Process.Start(psi);
|
||||
}
|
||||
|
||||
internal void UpdateActionKeyword(string newActionKeyword, string oldActionKeyword)
|
||||
internal void UpdateActionKeyword(Settings.ActionKeyword modifiedActionKeyword, string newActionKeyword, string oldActionKeyword)
|
||||
{
|
||||
PluginManager.ReplaceActionKeyword(Context.CurrentPluginMetadata.ID, oldActionKeyword, newActionKeyword);
|
||||
|
||||
if (Settings.FileContentSearchActionKeyword == oldActionKeyword)
|
||||
Settings.FileContentSearchActionKeyword = newActionKeyword;
|
||||
|
||||
if (Settings.SearchActionKeyword == oldActionKeyword)
|
||||
Settings.SearchActionKeyword = newActionKeyword;
|
||||
}
|
||||
|
||||
internal bool IsActionKeywordAlreadyAssigned(string newActionKeyword) => PluginManager.ActionKeywordRegistered(newActionKeyword);
|
||||
internal bool IsActionKeywordAlreadyAssigned(string newActionKeyword)
|
||||
{
|
||||
return PluginManager.ActionKeywordRegistered(newActionKeyword);
|
||||
}
|
||||
|
||||
internal bool IsNewActionKeywordGlobal(string newActionKeyword) => newActionKeyword == Query.GlobalPluginWildcardSign;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
mc:Ignorable="d"
|
||||
ResizeMode="NoResize"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
DataContext="{Binding RelativeSource={RelativeSource Self}}"
|
||||
Title="Action Keyword Setting" Height="200" Width="500">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
|
|
@ -16,21 +17,24 @@
|
|||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="180" />
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Margin="20 10 10 10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center"
|
||||
HorizontalAlignment="Left" Text="Current Action Keyword:" />
|
||||
<TextBox Name="txtCurrentActionKeyword"
|
||||
HorizontalAlignment="Left" Text="{DynamicResource plugin_explorer_actionkeyword_current}" />
|
||||
<TextBox Name="TxtCurrentActionKeyword"
|
||||
Margin="10" Grid.Row="0" Width="105" Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Left" />
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="1" Grid.Column="1">
|
||||
<Button Click="OnConfirmButtonClick"
|
||||
Margin="10 0 10 0" Width="80" Height="35"
|
||||
Content="OK" />
|
||||
<Button Click="OnCancelButtonClick"
|
||||
Margin="10 0 10 0" Width="80" Height="35"
|
||||
Content="Cancel" />
|
||||
</StackPanel>
|
||||
HorizontalAlignment="Left"
|
||||
Text="{Binding ActionKeyword}"
|
||||
PreviewKeyDown="TxtCurrentActionKeyword_OnKeyDown"/>
|
||||
<CheckBox Name="ChkActionKeywordEnabled" ToolTip="{DynamicResource plugin_explorer_actionkeyword_enabled_tooltip}"
|
||||
Margin="10" Grid.Row="0" Grid.Column="2" Content="{DynamicResource plugin_explorer_actionkeyword_enabled}"
|
||||
Width="auto"
|
||||
VerticalAlignment="Center" IsChecked="{Binding Enabled}"
|
||||
Visibility="{Binding Visible}"/>
|
||||
<Button Name="DownButton"
|
||||
Click="OnDoneButtonClick" Grid.Row="1" Grid.Column="2"
|
||||
Margin="10 0 10 0" Width="80" Height="35"
|
||||
Content="{DynamicResource plugin_explorer_actionkeyword_done}" />
|
||||
</Grid>
|
||||
</Window>
|
||||
</Window>
|
||||
|
|
@ -1,16 +1,10 @@
|
|||
using Flow.Launcher.Plugin.Explorer.ViewModels;
|
||||
using Flow.Launcher.Plugin.Explorer.ViewModels;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Flow.Launcher.Plugin.Explorer.Views
|
||||
{
|
||||
|
|
@ -21,65 +15,102 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
{
|
||||
private SettingsViewModel settingsViewModel;
|
||||
|
||||
private ActionKeywordView currentActionKeyword;
|
||||
public ActionKeywordView CurrentActionKeyword { get; set; }
|
||||
|
||||
private List<ActionKeywordView> actionKeywordListView;
|
||||
|
||||
public ActionKeywordSetting(SettingsViewModel settingsViewModel, List<ActionKeywordView> actionKeywordListView, ActionKeywordView selectedActionKeyword)
|
||||
public string ActionKeyword
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.settingsViewModel = settingsViewModel;
|
||||
|
||||
currentActionKeyword = selectedActionKeyword;
|
||||
|
||||
txtCurrentActionKeyword.Text = selectedActionKeyword.Keyword;
|
||||
|
||||
this.actionKeywordListView = actionKeywordListView;
|
||||
get => _actionKeyword;
|
||||
set
|
||||
{
|
||||
// Set Enable to be true if user change ActionKeyword
|
||||
if (Enabled is not null)
|
||||
Enabled = true;
|
||||
_actionKeyword = value;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
|
||||
public bool? Enabled { get; set; }
|
||||
|
||||
private string _actionKeyword;
|
||||
|
||||
public Visibility Visible =>
|
||||
CurrentActionKeyword.Enabled is not null ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
public ActionKeywordSetting(SettingsViewModel settingsViewModel,
|
||||
ActionKeywordView selectedActionKeyword)
|
||||
{
|
||||
var newActionKeyword = txtCurrentActionKeyword.Text;
|
||||
this.settingsViewModel = settingsViewModel;
|
||||
|
||||
if (string.IsNullOrEmpty(newActionKeyword))
|
||||
return;
|
||||
CurrentActionKeyword = selectedActionKeyword;
|
||||
|
||||
if (newActionKeyword == currentActionKeyword.Keyword)
|
||||
ActionKeyword = selectedActionKeyword.Keyword;
|
||||
Enabled = selectedActionKeyword.Enabled;
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
TxtCurrentActionKeyword.Focus();
|
||||
}
|
||||
|
||||
private void OnDoneButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ActionKeyword))
|
||||
ActionKeyword = Query.GlobalPluginWildcardSign;
|
||||
|
||||
if (CurrentActionKeyword.Keyword == ActionKeyword && CurrentActionKeyword.Enabled == Enabled)
|
||||
{
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (CurrentActionKeyword.KeywordProperty == Settings.ActionKeyword.FileContentSearchActionKeyword
|
||||
&& ActionKeyword == Query.GlobalPluginWildcardSign)
|
||||
{
|
||||
MessageBox.Show(
|
||||
settingsViewModel.Context.API.GetTranslation("plugin_explorer_globalActionKeywordInvalid"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (settingsViewModel.IsNewActionKeywordGlobal(newActionKeyword)
|
||||
&& currentActionKeyword.Description
|
||||
== settingsViewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_filecontentsearch"))
|
||||
{
|
||||
MessageBox.Show(settingsViewModel.Context.API.GetTranslation("plugin_explorer_globalActionKeywordInvalid"));
|
||||
var oldActionKeyword = CurrentActionKeyword.Keyword;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!settingsViewModel.IsActionKeywordAlreadyAssigned(newActionKeyword))
|
||||
// == because of nullable
|
||||
if (Enabled == false || !settingsViewModel.IsActionKeywordAlreadyAssigned(ActionKeyword))
|
||||
{
|
||||
settingsViewModel.UpdateActionKeyword(newActionKeyword, currentActionKeyword.Keyword);
|
||||
// Update View Data
|
||||
CurrentActionKeyword.Keyword = Enabled == true ? ActionKeyword : Query.GlobalPluginWildcardSign;
|
||||
CurrentActionKeyword.Enabled = Enabled;
|
||||
|
||||
actionKeywordListView.Where(x => x.Description == currentActionKeyword.Description).FirstOrDefault().Keyword = newActionKeyword;
|
||||
switch (Enabled)
|
||||
{
|
||||
// reset to global so it does not take up an action keyword when disabled
|
||||
// not for null Enable plugin
|
||||
case false when oldActionKeyword != Query.GlobalPluginWildcardSign:
|
||||
settingsViewModel.UpdateActionKeyword(CurrentActionKeyword.KeywordProperty,
|
||||
Query.GlobalPluginWildcardSign, oldActionKeyword);
|
||||
break;
|
||||
default:
|
||||
settingsViewModel.UpdateActionKeyword(CurrentActionKeyword.KeywordProperty,
|
||||
CurrentActionKeyword.Keyword, oldActionKeyword);
|
||||
break;
|
||||
}
|
||||
|
||||
Close();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// The keyword is not valid, so show message
|
||||
MessageBox.Show(settingsViewModel.Context.API.GetTranslation("newActionKeywordsHasBeenAssigned"));
|
||||
}
|
||||
|
||||
private void OnCancelButtonClick(object sender, RoutedEventArgs e)
|
||||
private void TxtCurrentActionKeyword_OnKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
Close();
|
||||
|
||||
return;
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
DownButton.Focus();
|
||||
OnDoneButtonClick(sender, e);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:viewModels="clr-namespace:Flow.Launcher.Plugin.Explorer.ViewModels"
|
||||
xmlns:views="clr-namespace:Flow.Launcher.Plugin.Explorer.Views"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<UserControl.Resources>
|
||||
|
|
@ -17,14 +18,17 @@
|
|||
Text="{Binding Path, Mode=OneTime}"
|
||||
Margin="0,5,0,5" />
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="ListViewActionKeywords">
|
||||
<DataTemplate x:Key="ListViewActionKeywords"
|
||||
DataType="views:ActionKeywordView">
|
||||
<Grid>
|
||||
<TextBlock
|
||||
Text="{Binding Description, Mode=OneTime}"
|
||||
Foreground="{Binding Color, Mode=OneWay}"
|
||||
Margin="0,5,0,0" />
|
||||
<TextBlock
|
||||
Text="{Binding Keyword, Mode=OneTime}"
|
||||
Margin="150,5,0,0" />
|
||||
Foreground="{Binding Color, Mode=OneWay}"
|
||||
Margin="250,5,0,0" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</UserControl.Resources>
|
||||
|
|
|
|||
|
|
@ -35,20 +35,20 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
|
||||
actionKeywordsListView = new List<ActionKeywordView>
|
||||
{
|
||||
new ActionKeywordView()
|
||||
{
|
||||
Description = viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_search"),
|
||||
Keyword = this.viewModel.Settings.SearchActionKeyword
|
||||
},
|
||||
new ActionKeywordView()
|
||||
{
|
||||
Description = viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_filecontentsearch"),
|
||||
Keyword = this.viewModel.Settings.FileContentSearchActionKeyword
|
||||
}
|
||||
new(Settings.ActionKeyword.SearchActionKeyword,
|
||||
viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_search")),
|
||||
new(Settings.ActionKeyword.FileContentSearchActionKeyword,
|
||||
viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_filecontentsearch")),
|
||||
new(Settings.ActionKeyword.PathSearchActionKeyword,
|
||||
viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_pathsearch")),
|
||||
new(Settings.ActionKeyword.IndexSearchActionKeyword,
|
||||
viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_indexsearch"))
|
||||
};
|
||||
|
||||
lbxActionKeywords.ItemsSource = actionKeywordsListView;
|
||||
|
||||
ActionKeywordView.Init(viewModel.Settings);
|
||||
|
||||
RefreshView();
|
||||
}
|
||||
|
||||
|
|
@ -71,9 +71,9 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
&& btnEdit.Visibility == Visibility.Hidden)
|
||||
btnEdit.Visibility = Visibility.Visible;
|
||||
|
||||
if ((lbxAccessLinks.Items.Count == 0 && lbxExcludedPaths.Items.Count == 0)
|
||||
&& btnDelete.Visibility == Visibility.Visible
|
||||
&& btnEdit.Visibility == Visibility.Visible)
|
||||
if (lbxAccessLinks.Items.Count == 0 && lbxExcludedPaths.Items.Count == 0
|
||||
&& btnDelete.Visibility == Visibility.Visible
|
||||
&& btnEdit.Visibility == Visibility.Visible)
|
||||
{
|
||||
btnDelete.Visibility = Visibility.Hidden;
|
||||
btnEdit.Visibility = Visibility.Hidden;
|
||||
|
|
@ -122,7 +122,7 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
private void expActionKeywords_Collapsed(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!expActionKeywords.IsExpanded)
|
||||
expActionKeywords.Height = Double.NaN;
|
||||
expActionKeywords.Height = double.NaN;
|
||||
}
|
||||
|
||||
private void expAccessLinks_Click(object sender, RoutedEventArgs e)
|
||||
|
|
@ -135,20 +135,20 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
|
||||
if (expActionKeywords.IsExpanded)
|
||||
expActionKeywords.IsExpanded = false;
|
||||
|
||||
|
||||
RefreshView();
|
||||
}
|
||||
|
||||
private void expAccessLinks_Collapsed(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!expAccessLinks.IsExpanded)
|
||||
expAccessLinks.Height = Double.NaN;
|
||||
expAccessLinks.Height = double.NaN;
|
||||
}
|
||||
|
||||
private void expExcludedPaths_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (expExcludedPaths.IsExpanded)
|
||||
expAccessLinks.Height = Double.NaN;
|
||||
expAccessLinks.Height = double.NaN;
|
||||
|
||||
if (expAccessLinks.IsExpanded)
|
||||
expAccessLinks.IsExpanded = false;
|
||||
|
|
@ -161,11 +161,12 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
|
||||
private void btnDelete_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var selectedRow = lbxAccessLinks.SelectedItem as AccessLink?? lbxExcludedPaths.SelectedItem as AccessLink;
|
||||
var selectedRow = lbxAccessLinks.SelectedItem as AccessLink ?? lbxExcludedPaths.SelectedItem as AccessLink;
|
||||
|
||||
if (selectedRow != null)
|
||||
{
|
||||
string msg = string.Format(viewModel.Context.API.GetTranslation("plugin_explorer_delete_folder_link"), selectedRow.Path);
|
||||
string msg = string.Format(viewModel.Context.API.GetTranslation("plugin_explorer_delete_folder_link"),
|
||||
selectedRow.Path);
|
||||
|
||||
if (MessageBox.Show(msg, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||
{
|
||||
|
|
@ -191,7 +192,8 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
{
|
||||
var selectedActionKeyword = lbxActionKeywords.SelectedItem as ActionKeywordView;
|
||||
|
||||
var actionKeywordWindow = new ActionKeywordSetting(viewModel, actionKeywordsListView, selectedActionKeyword);
|
||||
var actionKeywordWindow = new ActionKeywordSetting(viewModel,
|
||||
selectedActionKeyword);
|
||||
|
||||
actionKeywordWindow.ShowDialog();
|
||||
|
||||
|
|
@ -199,7 +201,8 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
}
|
||||
else
|
||||
{
|
||||
var selectedRow = lbxAccessLinks.SelectedItem as AccessLink ?? lbxExcludedPaths.SelectedItem as AccessLink;
|
||||
var selectedRow = lbxAccessLinks.SelectedItem as AccessLink ??
|
||||
lbxExcludedPaths.SelectedItem as AccessLink;
|
||||
|
||||
if (selectedRow != null)
|
||||
{
|
||||
|
|
@ -215,7 +218,8 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
|
||||
if (expExcludedPaths.IsExpanded)
|
||||
{
|
||||
var link = viewModel.Settings.IndexSearchExcludedSubdirectoryPaths.First(x => x.Path == selectedRow.Path);
|
||||
var link = viewModel.Settings.IndexSearchExcludedSubdirectoryPaths.First(x =>
|
||||
x.Path == selectedRow.Path);
|
||||
link.Path = folderBrowserDialog.SelectedPath;
|
||||
}
|
||||
}
|
||||
|
|
@ -235,10 +239,7 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
var folderBrowserDialog = new FolderBrowserDialog();
|
||||
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
var newAccessLink = new AccessLink
|
||||
{
|
||||
Path = folderBrowserDialog.SelectedPath
|
||||
};
|
||||
var newAccessLink = new AccessLink {Path = folderBrowserDialog.SelectedPath};
|
||||
|
||||
AddAccessLink(newAccessLink);
|
||||
}
|
||||
|
|
@ -259,10 +260,7 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
{
|
||||
if (Directory.Exists(s))
|
||||
{
|
||||
var newFolderLink = new AccessLink
|
||||
{
|
||||
Path = s
|
||||
};
|
||||
var newFolderLink = new AccessLink {Path = s};
|
||||
|
||||
AddAccessLink(newFolderLink);
|
||||
}
|
||||
|
|
@ -275,7 +273,7 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
private void AddAccessLink(AccessLink newAccessLink)
|
||||
{
|
||||
if (expAccessLinks.IsExpanded
|
||||
&& !viewModel.Settings.QuickAccessLinks.Any(x => x.Path == newAccessLink.Path))
|
||||
&& !viewModel.Settings.QuickAccessLinks.Any(x => x.Path == newAccessLink.Path))
|
||||
{
|
||||
if (viewModel.Settings.QuickAccessLinks == null)
|
||||
viewModel.Settings.QuickAccessLinks = new List<AccessLink>();
|
||||
|
|
@ -313,8 +311,35 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
|
||||
public class ActionKeywordView
|
||||
{
|
||||
public string Description { get; set; }
|
||||
private static Settings _settings;
|
||||
|
||||
public string Keyword { get; set; }
|
||||
public static void Init(Settings settings)
|
||||
{
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
internal ActionKeywordView(Settings.ActionKeyword actionKeyword, string description)
|
||||
{
|
||||
KeywordProperty = actionKeyword;
|
||||
Description = description;
|
||||
}
|
||||
|
||||
public string Description { get; private init; }
|
||||
public string Color => Enabled ?? true ? "Black" : "Gray";
|
||||
|
||||
internal Settings.ActionKeyword KeywordProperty { get; }
|
||||
|
||||
public string Keyword
|
||||
{
|
||||
get => _settings.GetActionKeyword(KeywordProperty);
|
||||
set => _settings.SetActionKeyword(KeywordProperty, value);
|
||||
}
|
||||
|
||||
public bool? Enabled
|
||||
{
|
||||
get => _settings.GetActionKeywordEnable(KeywordProperty);
|
||||
set => _settings.SetActionKeywordEnable(KeywordProperty,
|
||||
value ?? throw new ArgumentException("Unexpected null value"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
{
|
||||
"ID": "572be03c74c642baae319fc283e561a8",
|
||||
"ActionKeywords": [
|
||||
"*",
|
||||
"doc:"
|
||||
"*",
|
||||
"doc:",
|
||||
"*",
|
||||
"*"
|
||||
],
|
||||
"Name": "Explorer",
|
||||
"Description": "Search and manage files and folders. Explorer utilises Windows Index Search",
|
||||
|
|
|
|||
Loading…
Reference in a new issue