mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add specific keyword for path explore in explorer plugin
This commit is contained in:
parent
d813a4732d
commit
acba2dd1a3
12 changed files with 106 additions and 47 deletions
4
.editorconfig
Normal file
4
.editorconfig
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
[*.cs]
|
||||
|
||||
# IDE0011: 添加大括号
|
||||
csharp_prefer_braces = when_multiline
|
||||
|
|
@ -38,6 +38,10 @@
|
|||
<Compile Include="..\SolutionAssemblyInfo.cs" Link="Properties\SolutionAssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\.editorconfig" Link=".editorconfig" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Plugins\Flow.Launcher.Plugin.Explorer\Flow.Launcher.Plugin.Explorer.csproj" />
|
||||
<ProjectReference Include="..\Plugins\Flow.Launcher.Plugin.Program\Flow.Launcher.Plugin.Program.csproj" />
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flow.Launcher.Plugin.Url",
|
|||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FFD651C7-0546-441F-BC8C-D4EE8FD01EA7}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.editorconfig = .editorconfig
|
||||
.gitattributes = .gitattributes
|
||||
.gitignore = .gitignore
|
||||
appveyor.yml = appveyor.yml
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@
|
|||
<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">Index Search Activation:</system:String>
|
||||
<system:String x:Key="plugin_explorer_actionkeywordview_path">Path Explore Activation:</system:String>
|
||||
<system:String x:Key="plugin_explorer_actionkeywordview_filecontentsearch">File Content Search:</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()
|
||||
|
|
|
|||
|
|
@ -39,21 +39,47 @@ 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.PathSearchActionKeyword))
|
||||
{
|
||||
result.UnionWith(await PathSearchAsync(query, token).ConfigureAwait(false));
|
||||
}
|
||||
|
||||
if (ActionKeywordMatch(query, settings.SearchActionKeyword) &&
|
||||
querySearch.Length > 0 &&
|
||||
!querySearch.IsLocationPathString())
|
||||
{
|
||||
result.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false));
|
||||
}
|
||||
|
||||
return result.ToList();
|
||||
}
|
||||
|
||||
private bool ActionKeywordMatch(Query query, string actionKeyword)
|
||||
{
|
||||
return query.ActionKeyword == actionKeyword ||
|
||||
query.ActionKeyword.Length == 0 && actionKeyword == Query.GlobalPluginWildcardSign;
|
||||
}
|
||||
|
||||
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 +89,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)
|
||||
|
|
|
|||
|
|
@ -20,5 +20,7 @@ namespace Flow.Launcher.Plugin.Explorer
|
|||
public string SearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
|
||||
|
||||
public string FileContentSearchActionKeyword { get; set; } = Constants.DefaultContentSearchActionKeyword;
|
||||
|
||||
public string PathSearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
|
||||
}
|
||||
}
|
||||
|
|
@ -41,19 +41,36 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
|
|||
Process.Start(psi);
|
||||
}
|
||||
|
||||
internal void UpdateActionKeyword(string newActionKeyword, string oldActionKeyword)
|
||||
internal void UpdateActionKeyword(ActionKeywordProperty modifiedActionKeyword, string newActionKeyword, string oldActionKeyword)
|
||||
{
|
||||
PluginManager.ReplaceActionKeyword(Context.CurrentPluginMetadata.ID, oldActionKeyword, newActionKeyword);
|
||||
if (Settings.SearchActionKeyword == Settings.PathSearchActionKeyword)
|
||||
PluginManager.AddActionKeyword(Context.CurrentPluginMetadata.ID, newActionKeyword);
|
||||
else
|
||||
PluginManager.ReplaceActionKeyword(Context.CurrentPluginMetadata.ID, oldActionKeyword, newActionKeyword);
|
||||
|
||||
if (Settings.FileContentSearchActionKeyword == oldActionKeyword)
|
||||
Settings.FileContentSearchActionKeyword = newActionKeyword;
|
||||
|
||||
if (Settings.SearchActionKeyword == oldActionKeyword)
|
||||
Settings.SearchActionKeyword = newActionKeyword;
|
||||
switch (modifiedActionKeyword)
|
||||
{
|
||||
case ActionKeywordProperty.SearchActionKeyword:
|
||||
Settings.SearchActionKeyword = newActionKeyword;
|
||||
break;
|
||||
case ActionKeywordProperty.PathSearchActionKeyword:
|
||||
Settings.PathSearchActionKeyword = newActionKeyword;
|
||||
break;
|
||||
case ActionKeywordProperty.FileContentSearchActionKeyword:
|
||||
Settings.FileContentSearchActionKeyword = newActionKeyword;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool IsActionKeywordAlreadyAssigned(string newActionKeyword) => PluginManager.ActionKeywordRegistered(newActionKeyword);
|
||||
|
||||
internal bool IsNewActionKeywordGlobal(string newActionKeyword) => newActionKeyword == Query.GlobalPluginWildcardSign;
|
||||
}
|
||||
|
||||
public enum ActionKeywordProperty
|
||||
{
|
||||
SearchActionKeyword,
|
||||
PathSearchActionKeyword,
|
||||
FileContentSearchActionKeyword
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
|
||||
private ActionKeywordView currentActionKeyword;
|
||||
|
||||
|
||||
private List<ActionKeywordView> actionKeywordListView;
|
||||
|
||||
public ActionKeywordSetting(SettingsViewModel settingsViewModel, List<ActionKeywordView> actionKeywordListView, ActionKeywordView selectedActionKeyword)
|
||||
|
|
@ -35,7 +36,7 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
|
||||
txtCurrentActionKeyword.Text = selectedActionKeyword.Keyword;
|
||||
|
||||
this.actionKeywordListView = actionKeywordListView;
|
||||
this.actionKeywordListView = actionKeywordListView;
|
||||
}
|
||||
|
||||
private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
|
||||
|
|
@ -52,20 +53,19 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
return;
|
||||
}
|
||||
|
||||
if (settingsViewModel.IsNewActionKeywordGlobal(newActionKeyword)
|
||||
&& currentActionKeyword.Description
|
||||
== settingsViewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_filecontentsearch"))
|
||||
if (settingsViewModel.IsNewActionKeywordGlobal(newActionKeyword)
|
||||
&& currentActionKeyword.KeywordProperty == ActionKeywordProperty.FileContentSearchActionKeyword)
|
||||
{
|
||||
MessageBox.Show(settingsViewModel.Context.API.GetTranslation("plugin_explorer_globalActionKeywordInvalid"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!settingsViewModel.IsActionKeywordAlreadyAssigned(newActionKeyword))
|
||||
{
|
||||
settingsViewModel.UpdateActionKeyword(newActionKeyword, currentActionKeyword.Keyword);
|
||||
settingsViewModel.UpdateActionKeyword(currentActionKeyword.KeywordProperty, newActionKeyword, currentActionKeyword.Keyword);
|
||||
|
||||
actionKeywordListView.Where(x => x.Description == currentActionKeyword.Description).FirstOrDefault().Keyword = newActionKeyword;
|
||||
actionKeywordListView.FirstOrDefault(x => x.Description == currentActionKeyword.Description).Keyword = newActionKeyword;
|
||||
|
||||
Close();
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
Margin="0,5,0,0" />
|
||||
<TextBlock
|
||||
Text="{Binding Keyword, Mode=OneTime}"
|
||||
Margin="150,5,0,0" />
|
||||
Margin="250,5,0,0" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</UserControl.Resources>
|
||||
|
|
|
|||
|
|
@ -35,16 +35,24 @@ 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 ()
|
||||
{
|
||||
Description = viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_search"),
|
||||
Keyword = this.viewModel.Settings.SearchActionKeyword,
|
||||
KeywordProperty = ActionKeywordProperty.SearchActionKeyword
|
||||
},
|
||||
new ()
|
||||
{
|
||||
Description = viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_filecontentsearch"),
|
||||
Keyword = this.viewModel.Settings.FileContentSearchActionKeyword,
|
||||
KeywordProperty = ActionKeywordProperty.FileContentSearchActionKeyword
|
||||
},
|
||||
new ()
|
||||
{
|
||||
Description = viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_path"),
|
||||
Keyword = this.viewModel.Settings.PathSearchActionKeyword,
|
||||
KeywordProperty = ActionKeywordProperty.PathSearchActionKeyword
|
||||
}
|
||||
};
|
||||
|
||||
lbxActionKeywords.ItemsSource = actionKeywordsListView;
|
||||
|
|
@ -71,7 +79,7 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
&& btnEdit.Visibility == Visibility.Hidden)
|
||||
btnEdit.Visibility = Visibility.Visible;
|
||||
|
||||
if ((lbxAccessLinks.Items.Count == 0 && lbxExcludedPaths.Items.Count == 0)
|
||||
if (lbxAccessLinks.Items.Count == 0 && lbxExcludedPaths.Items.Count == 0
|
||||
&& btnDelete.Visibility == Visibility.Visible
|
||||
&& btnEdit.Visibility == Visibility.Visible)
|
||||
{
|
||||
|
|
@ -122,7 +130,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 +143,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,7 +169,7 @@ 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)
|
||||
{
|
||||
|
|
@ -315,6 +323,7 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
{
|
||||
public string Description { get; set; }
|
||||
|
||||
public ActionKeywordProperty KeywordProperty { get; init; }
|
||||
public string Keyword { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue