mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
update ActionKeywordSetting view logic
This commit is contained in:
parent
f13e24bd07
commit
ff404c5c5b
6 changed files with 39 additions and 38 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,10 @@
|
|||
<system:String x:Key="plugin_explorer_actionkeywordview_path">Path Search:</system:String>
|
||||
<system:String x:Key="plugin_explorer_actionkeywordview_filecontentsearch">File Content Search:</system:String>
|
||||
<system:String x:Key="plugin_explorer_actionkeywordview_indexonlysearch">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>
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
|
||||
private bool ActionKeywordMatch(Query query, Settings.ActionKeyword allowedActionKeyword)
|
||||
{
|
||||
var keyword = query.ActionKeyword.Length == 0 ? "*" : query.ActionKeyword;
|
||||
var keyword = query.ActionKeyword.Length == 0 ? Query.GlobalPluginWildcardSign : query.ActionKeyword;
|
||||
|
||||
return allowedActionKeyword switch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -62,7 +62,14 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
internal bool IsActionKeywordAlreadyAssigned(string newActionKeyword) => PluginManager.ActionKeywordRegistered(newActionKeyword);
|
||||
internal bool IsActionKeywordAlreadyAssigned(string newActionKeyword, string oldActionKeyword)
|
||||
{
|
||||
// PluginManager.ActionKeywordRegistered does not check global action keyword ('*'), so use this logic instead
|
||||
if (newActionKeyword == Query.GlobalPluginWildcardSign)
|
||||
return newActionKeyword == oldActionKeyword;
|
||||
|
||||
return PluginManager.ActionKeywordRegistered(newActionKeyword);
|
||||
}
|
||||
|
||||
internal bool IsNewActionKeywordGlobal(string newActionKeyword) => newActionKeyword == Query.GlobalPluginWildcardSign;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,23 +20,19 @@
|
|||
<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:" />
|
||||
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"
|
||||
Text="{Binding CurrentActionKeyword.Keyword}" />
|
||||
<CheckBox Name="ChkActionKeywordEnabled" Margin="10" Grid.Row="0" Grid.Column="2" Content="Enabled"
|
||||
<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 CurrentActionKeyword.Enabled}"
|
||||
Visibility="{Binding Visible}"/>
|
||||
<StackPanel Orientation="Horizontal" Grid.Column="1" Grid.ColumnSpan="2" Margin="100 92 0 0" Grid.RowSpan="2">
|
||||
<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>
|
||||
<Button 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>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
using Flow.Launcher.Plugin.Explorer.ViewModels;
|
||||
using Flow.Launcher.Plugin.Explorer.ViewModels;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
|
|
@ -14,6 +14,8 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
|
||||
public ActionKeywordView CurrentActionKeyword { get; set; }
|
||||
|
||||
private string oldActionKeyword;
|
||||
|
||||
private List<ActionKeywordView> actionKeywordListView;
|
||||
|
||||
private Settings settings;
|
||||
|
|
@ -30,32 +32,20 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
|
||||
CurrentActionKeyword = selectedActionKeyword;
|
||||
|
||||
oldActionKeyword = selectedActionKeyword.Keyword;
|
||||
|
||||
this.actionKeywordListView = actionKeywordListView;
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
}
|
||||
|
||||
private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
|
||||
private void OnDoneButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var newActionKeyword = TxtCurrentActionKeyword.Text;
|
||||
|
||||
if (string.IsNullOrEmpty(newActionKeyword))
|
||||
if (string.IsNullOrEmpty(CurrentActionKeyword.Keyword))
|
||||
return;
|
||||
|
||||
// reset to global so it does not take up an action keyword when disabled
|
||||
if (!CurrentActionKeyword.Enabled is not null && newActionKeyword != Query.GlobalPluginWildcardSign)
|
||||
settingsViewModel.UpdateActionKeyword(CurrentActionKeyword.KeywordProperty,
|
||||
Query.GlobalPluginWildcardSign, CurrentActionKeyword.Keyword);
|
||||
|
||||
if (newActionKeyword == CurrentActionKeyword.Keyword)
|
||||
{
|
||||
Close();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (settingsViewModel.IsNewActionKeywordGlobal(newActionKeyword)
|
||||
if (settingsViewModel.IsNewActionKeywordGlobal(CurrentActionKeyword.Keyword)
|
||||
&& CurrentActionKeyword.KeywordProperty == Settings.ActionKeyword.FileContentSearchActionKeyword)
|
||||
{
|
||||
MessageBox.Show(
|
||||
|
|
@ -64,13 +54,12 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
return;
|
||||
}
|
||||
|
||||
if (!settingsViewModel.IsActionKeywordAlreadyAssigned(newActionKeyword))
|
||||
if (!settingsViewModel.IsActionKeywordAlreadyAssigned(CurrentActionKeyword.Keyword, oldActionKeyword))
|
||||
{
|
||||
settingsViewModel.UpdateActionKeyword(CurrentActionKeyword.KeywordProperty, newActionKeyword,
|
||||
CurrentActionKeyword.Keyword);
|
||||
settingsViewModel.UpdateActionKeyword(CurrentActionKeyword.KeywordProperty, CurrentActionKeyword.Keyword, oldActionKeyword);
|
||||
|
||||
actionKeywordListView.FirstOrDefault(x => x.Description == CurrentActionKeyword.Description).Keyword =
|
||||
newActionKeyword;
|
||||
CurrentActionKeyword.Keyword;
|
||||
|
||||
// automatically help users set this to enabled if an action keyword is set and currently disabled
|
||||
if (CurrentActionKeyword.KeywordProperty == Settings.ActionKeyword.IndexSearchActionKeyword
|
||||
|
|
@ -81,16 +70,19 @@ namespace Flow.Launcher.Plugin.Explorer.Views
|
|||
&& !settings.EnabledPathSearchKeyword)
|
||||
settings.EnabledPathSearchKeyword = true;
|
||||
|
||||
if (CurrentActionKeyword.KeywordProperty == Settings.ActionKeyword.SearchActionKeyword
|
||||
&& !settings.EnableSearchActionKeyword)
|
||||
settings.EnableSearchActionKeyword = true;
|
||||
|
||||
Close();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
MessageBox.Show(settingsViewModel.Context.API.GetTranslation("newActionKeywordsHasBeenAssigned"));
|
||||
}
|
||||
// reset to global so it does not take up an action keyword when disabled
|
||||
if (CurrentActionKeyword.Enabled is not null && CurrentActionKeyword.Enabled == false && CurrentActionKeyword.Keyword != Query.GlobalPluginWildcardSign)
|
||||
settingsViewModel.UpdateActionKeyword(CurrentActionKeyword.KeywordProperty, Query.GlobalPluginWildcardSign, oldActionKeyword);
|
||||
|
||||
private void OnCancelButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in a new issue