Refactor Code

1. Moving Property match to Settings.cs
2. Use Binding to avoid explicit Function Assign
3. Simplify ActionKeywordMatch
This commit is contained in:
弘韬 张 2021-06-01 18:10:24 -07:00
parent 995cf568ff
commit 5966ddc4d9
7 changed files with 178 additions and 164 deletions

View file

@ -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;
@ -46,16 +47,19 @@ namespace Flow.Launcher.Plugin.Explorer.Search
var result = new HashSet<Result>(PathEqualityComparator.Instance);
if (ActionKeywordMatch(query, Settings.ActionKeyword.PathSearchActionKeyword) || ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword))
if (ActionKeywordMatch(query, Settings.ActionKeyword.PathSearchActionKeyword) ||
ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword))
{
result.UnionWith(await PathSearchAsync(query, token).ConfigureAwait(false));
}
if ((ActionKeywordMatch(query, Settings.ActionKeyword.IndexOnlySearchActionKeyword) || ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword)) &&
querySearch.Length > 0 &&
!querySearch.IsLocationPathString())
if ((ActionKeywordMatch(query, Settings.ActionKeyword.IndexOnlySearchActionKeyword) ||
ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword)) &&
querySearch.Length > 0 &&
!querySearch.IsLocationPathString())
{
result.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false));
result.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token)
.ConfigureAwait(false));
}
return result.ToList();
@ -63,19 +67,19 @@ namespace Flow.Launcher.Plugin.Explorer.Search
private bool ActionKeywordMatch(Query query, Settings.ActionKeyword allowedActionKeyword)
{
if (query.ActionKeyword == settings.IndexOnlySearchActionKeyword)
return Settings.ActionKeyword.IndexOnlySearchActionKeyword == allowedActionKeyword && settings.EnabledIndexOnlySearchKeyword;
var keyword = query.ActionKeyword.Length == 0 ? "*" : query.ActionKeyword;
if (query.ActionKeyword == settings.PathSearchActionKeyword)
return Settings.ActionKeyword.PathSearchActionKeyword == allowedActionKeyword && settings.EnabledPathSearchKeyword;
if (query.ActionKeyword == settings.SearchActionKeyword)
return Settings.ActionKeyword.SearchActionKeyword == allowedActionKeyword;
return (Settings.ActionKeyword.IndexOnlySearchActionKeyword == allowedActionKeyword && settings.EnabledIndexOnlySearchKeyword)
|| (Settings.ActionKeyword.PathSearchActionKeyword == allowedActionKeyword && settings.EnabledPathSearchKeyword)
|| settings.SearchActionKeyword == Query.GlobalPluginWildcardSign;
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.IndexOnlySearchActionKeyword => settings.EnabledIndexOnlySearchKeyword &&
keyword == settings.IndexOnlySearchActionKeyword
};
}
public async Task<List<Result>> PathSearchAsync(Query query, CancellationToken token = default)
@ -129,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);
@ -137,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)
@ -168,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)
@ -200,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);
}
}
}
}

View file

@ -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,6 +21,7 @@ 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;
@ -36,5 +40,38 @@ namespace Flow.Launcher.Plugin.Explorer
FileContentSearchActionKeyword,
IndexOnlySearchActionKeyword
}
internal string GetActionKeyword(ActionKeyword actionKeyword) => actionKeyword switch
{
ActionKeyword.SearchActionKeyword => SearchActionKeyword,
ActionKeyword.PathSearchActionKeyword => PathSearchActionKeyword,
ActionKeyword.FileContentSearchActionKeyword => FileContentSearchActionKeyword,
ActionKeyword.IndexOnlySearchActionKeyword => IndexOnlySearchActionKeyword
};
internal void SetActionKeyword(ActionKeyword actionKeyword, string keyword) => _ = actionKeyword switch
{
ActionKeyword.SearchActionKeyword => SearchActionKeyword = keyword,
ActionKeyword.PathSearchActionKeyword => PathSearchActionKeyword = keyword,
ActionKeyword.FileContentSearchActionKeyword => FileContentSearchActionKeyword = keyword,
ActionKeyword.IndexOnlySearchActionKeyword => IndexOnlySearchActionKeyword = keyword,
_ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "Unexpected property")
};
internal bool? GetActionKeywordEnable(ActionKeyword actionKeyword) => actionKeyword switch
{
ActionKeyword.SearchActionKeyword => EnableSearchActionKeyword,
ActionKeyword.PathSearchActionKeyword => EnabledPathSearchKeyword,
ActionKeyword.IndexOnlySearchActionKeyword => EnabledIndexOnlySearchKeyword,
_ => null
};
internal void SetActionKeywordEnable(ActionKeyword actionKeyword, bool enable) => _ = actionKeyword switch
{
ActionKeyword.SearchActionKeyword => EnableSearchActionKeyword = enable,
ActionKeyword.PathSearchActionKeyword => EnabledPathSearchKeyword = enable,
ActionKeyword.IndexOnlySearchActionKeyword => EnabledIndexOnlySearchKeyword = enable,
_ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "Unexpected property")
};
}
}

View file

@ -41,22 +41,22 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
Process.Start(psi);
}
internal void UpdateActionKeyword(ActionKeywordProperty modifiedActionKeyword, string newActionKeyword, string oldActionKeyword)
internal void UpdateActionKeyword(Settings.ActionKeyword modifiedActionKeyword, string newActionKeyword, string oldActionKeyword)
{
PluginManager.ReplaceActionKeyword(Context.CurrentPluginMetadata.ID, oldActionKeyword, newActionKeyword);
switch (modifiedActionKeyword)
{
case ActionKeywordProperty.SearchActionKeyword:
case Settings.ActionKeyword.SearchActionKeyword:
Settings.SearchActionKeyword = newActionKeyword;
break;
case ActionKeywordProperty.PathSearchActionKeyword:
case Settings.ActionKeyword.PathSearchActionKeyword:
Settings.PathSearchActionKeyword = newActionKeyword;
break;
case ActionKeywordProperty.FileContentSearchActionKeyword:
case Settings.ActionKeyword.FileContentSearchActionKeyword:
Settings.FileContentSearchActionKeyword = newActionKeyword;
break;
case ActionKeywordProperty.IndexOnlySearchActionKeyword:
case Settings.ActionKeyword.IndexOnlySearchActionKeyword:
Settings.IndexOnlySearchActionKeyword = newActionKeyword;
break;
}
@ -66,12 +66,4 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
internal bool IsNewActionKeywordGlobal(string newActionKeyword) => newActionKeyword == Query.GlobalPluginWildcardSign;
}
public enum ActionKeywordProperty
{
SearchActionKeyword,
PathSearchActionKeyword,
FileContentSearchActionKeyword,
IndexOnlySearchActionKeyword
}
}

View file

@ -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>
@ -20,12 +21,15 @@
</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"
<TextBox Name="TxtCurrentActionKeyword"
Margin="10" Grid.Row="0" Width="105" Grid.Column="1"
VerticalAlignment="Center"
HorizontalAlignment="Left" />
<CheckBox Name="chkActionKeywordEnabled" Margin="10" Grid.Row="0" Grid.Column="2" Content="Enabled" Width="auto"
VerticalAlignment="Center" Checked="OnActionKeywordEnabledChecked" Unchecked="OnActionKeywordEnabledUnChecked"/>
HorizontalAlignment="Left"
Text="{Binding CurrentActionKeyword.Keyword}" />
<CheckBox Name="ChkActionKeywordEnabled" Margin="10" Grid.Row="0" Grid.Column="2" Content="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"
@ -35,4 +39,4 @@
Content="Cancel" />
</StackPanel>
</Grid>
</Window>
</Window>

View file

@ -12,66 +12,43 @@ namespace Flow.Launcher.Plugin.Explorer.Views
{
private SettingsViewModel settingsViewModel;
private ActionKeywordView currentActionKeyword;
public ActionKeywordView CurrentActionKeyword { get; set; }
private List<ActionKeywordView> actionKeywordListView;
private Settings settings;
public ActionKeywordSetting(SettingsViewModel settingsViewModel,
List<ActionKeywordView> actionKeywordListView,
public Visibility Visible => CurrentActionKeyword.Enabled is not null ? Visibility.Visible : Visibility.Collapsed;
public ActionKeywordSetting(SettingsViewModel settingsViewModel,
List<ActionKeywordView> actionKeywordListView,
ActionKeywordView selectedActionKeyword, Settings settings)
{
InitializeComponent();
this.settingsViewModel = settingsViewModel;
this.settings = settings;
currentActionKeyword = selectedActionKeyword;
txtCurrentActionKeyword.Text = selectedActionKeyword.Keyword;
CurrentActionKeyword = selectedActionKeyword;
this.actionKeywordListView = actionKeywordListView;
InitializeComponent();
// Search and File Content action keyword are not allowed to be disabled, they are the default search keywords.
if (currentActionKeyword.KeywordProperty == ActionKeywordProperty.SearchActionKeyword
|| currentActionKeyword.KeywordProperty == ActionKeywordProperty.FileContentSearchActionKeyword)
chkActionKeywordEnabled.Visibility = Visibility.Collapsed;
if (currentActionKeyword.KeywordProperty == ActionKeywordProperty.IndexOnlySearchActionKeyword)
chkActionKeywordEnabled.IsChecked = this.settings.EnabledIndexOnlySearchKeyword;
if (currentActionKeyword.KeywordProperty == ActionKeywordProperty.PathSearchActionKeyword)
chkActionKeywordEnabled.IsChecked = this.settings.EnabledPathSearchKeyword;
}
private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
{
var newActionKeyword = txtCurrentActionKeyword.Text;
var newActionKeyword = TxtCurrentActionKeyword.Text;
if (string.IsNullOrEmpty(newActionKeyword))
return;
if (currentActionKeyword.KeywordProperty == ActionKeywordProperty.IndexOnlySearchActionKeyword)
{
// reset to global so it does not take up an action keyword when disabled
if (!currentActionKeyword.Enabled && newActionKeyword != Query.GlobalPluginWildcardSign)
settingsViewModel.UpdateActionKeyword(currentActionKeyword.KeywordProperty, Query.GlobalPluginWildcardSign, currentActionKeyword.Keyword);
// 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);
settings.EnabledIndexOnlySearchKeyword = currentActionKeyword.Enabled;
}
if (currentActionKeyword.KeywordProperty == ActionKeywordProperty.PathSearchActionKeyword)
{
// reset to global so it does not take up an action keyword when disabled
if (!currentActionKeyword.Enabled && newActionKeyword != Query.GlobalPluginWildcardSign)
settingsViewModel.UpdateActionKeyword(currentActionKeyword.KeywordProperty, Query.GlobalPluginWildcardSign, currentActionKeyword.Keyword);
settings.EnabledPathSearchKeyword = currentActionKeyword.Enabled;
}
if (newActionKeyword == currentActionKeyword.Keyword)
if (newActionKeyword == CurrentActionKeyword.Keyword)
{
Close();
@ -79,25 +56,28 @@ namespace Flow.Launcher.Plugin.Explorer.Views
}
if (settingsViewModel.IsNewActionKeywordGlobal(newActionKeyword)
&& currentActionKeyword.KeywordProperty == ActionKeywordProperty.FileContentSearchActionKeyword)
&& CurrentActionKeyword.KeywordProperty == Settings.ActionKeyword.FileContentSearchActionKeyword)
{
MessageBox.Show(settingsViewModel.Context.API.GetTranslation("plugin_explorer_globalActionKeywordInvalid"));
MessageBox.Show(
settingsViewModel.Context.API.GetTranslation("plugin_explorer_globalActionKeywordInvalid"));
return;
}
if (!settingsViewModel.IsActionKeywordAlreadyAssigned(newActionKeyword))
{
settingsViewModel.UpdateActionKeyword(currentActionKeyword.KeywordProperty, newActionKeyword, currentActionKeyword.Keyword);
settingsViewModel.UpdateActionKeyword(CurrentActionKeyword.KeywordProperty, newActionKeyword,
CurrentActionKeyword.Keyword);
actionKeywordListView.FirstOrDefault(x => x.Description == currentActionKeyword.Description).Keyword = newActionKeyword;
actionKeywordListView.FirstOrDefault(x => x.Description == CurrentActionKeyword.Description).Keyword =
newActionKeyword;
// automatically help users set this to enabled if an action keyword is set and currently disabled
if (currentActionKeyword.KeywordProperty == ActionKeywordProperty.IndexOnlySearchActionKeyword
if (CurrentActionKeyword.KeywordProperty == Settings.ActionKeyword.IndexOnlySearchActionKeyword
&& !settings.EnabledIndexOnlySearchKeyword)
settings.EnabledIndexOnlySearchKeyword = true;
if (currentActionKeyword.KeywordProperty == ActionKeywordProperty.PathSearchActionKeyword
if (CurrentActionKeyword.KeywordProperty == Settings.ActionKeyword.PathSearchActionKeyword
&& !settings.EnabledPathSearchKeyword)
settings.EnabledPathSearchKeyword = true;
@ -115,14 +95,5 @@ namespace Flow.Launcher.Plugin.Explorer.Views
return;
}
private void OnActionKeywordEnabledChecked(object sender, RoutedEventArgs e)
{
currentActionKeyword.Enabled = true;
}
private void OnActionKeywordEnabledUnChecked(object sender, RoutedEventArgs e)
{
currentActionKeyword.Enabled = false;
}
}
}
}

View file

@ -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,13 +18,16 @@
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}"
Foreground="{Binding Color, Mode=OneWay}"
Margin="250,5,0,0" />
</Grid>
</DataTemplate>

View file

@ -35,44 +35,20 @@ namespace Flow.Launcher.Plugin.Explorer.Views
actionKeywordsListView = new List<ActionKeywordView>
{
new ()
{
Description = viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_search"),
Keyword = viewModel.Settings.SearchActionKeyword,
KeywordProperty = ActionKeywordProperty.SearchActionKeyword,
Enabled = true
},
new ()
{
Description = viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_filecontentsearch"),
Keyword = viewModel.Settings.FileContentSearchActionKeyword,
KeywordProperty = ActionKeywordProperty.FileContentSearchActionKeyword,
Enabled = true
},
new ()
{
Description = viewModel.Settings.EnabledPathSearchKeyword
? viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_path")
: viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_path")
+ " " + viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_brackets_disabled"),
Keyword = viewModel.Settings.PathSearchActionKeyword,
KeywordProperty = ActionKeywordProperty.PathSearchActionKeyword,
Enabled = viewModel.Settings.EnabledPathSearchKeyword
},
new ()
{
Description = viewModel.Settings.EnabledIndexOnlySearchKeyword
? viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_indexonlysearch")
: viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_indexonlysearch")
+ " " + viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_brackets_disabled"),
Keyword = viewModel.Settings.IndexOnlySearchActionKeyword,
KeywordProperty = ActionKeywordProperty.IndexOnlySearchActionKeyword,
Enabled = viewModel.Settings.EnabledIndexOnlySearchKeyword
}
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_path")),
new(Settings.ActionKeyword.IndexOnlySearchActionKeyword,
viewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_indexonlysearch"))
};
lbxActionKeywords.ItemsSource = actionKeywordsListView;
ActionKeywordView.Init(viewModel.Settings, viewModel.Context.API);
RefreshView();
}
@ -96,8 +72,8 @@ namespace Flow.Launcher.Plugin.Explorer.Views
btnEdit.Visibility = Visibility.Visible;
if (lbxAccessLinks.Items.Count == 0 && lbxExcludedPaths.Items.Count == 0
&& btnDelete.Visibility == Visibility.Visible
&& btnEdit.Visibility == Visibility.Visible)
&& btnDelete.Visibility == Visibility.Visible
&& btnEdit.Visibility == Visibility.Visible)
{
btnDelete.Visibility = Visibility.Hidden;
btnEdit.Visibility = Visibility.Hidden;
@ -189,7 +165,8 @@ namespace Flow.Launcher.Plugin.Explorer.Views
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)
{
@ -215,7 +192,8 @@ namespace Flow.Launcher.Plugin.Explorer.Views
{
var selectedActionKeyword = lbxActionKeywords.SelectedItem as ActionKeywordView;
var actionKeywordWindow = new ActionKeywordSetting(viewModel, actionKeywordsListView, selectedActionKeyword, viewModel.Settings);
var actionKeywordWindow = new ActionKeywordSetting(viewModel, actionKeywordsListView,
selectedActionKeyword, viewModel.Settings);
actionKeywordWindow.ShowDialog();
@ -223,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)
{
@ -239,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;
}
}
@ -259,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);
}
@ -283,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);
}
@ -299,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>();
@ -337,12 +311,37 @@ namespace Flow.Launcher.Plugin.Explorer.Views
public class ActionKeywordView
{
public string Description { get; set; }
private static Settings _settings;
private static IPublicAPI _api;
public ActionKeywordProperty KeywordProperty { get; init; }
public static void Init(Settings settings, IPublicAPI api)
{
_settings = settings;
_api = api;
}
public string Keyword { get; set; }
internal ActionKeywordView(Settings.ActionKeyword actionKeyword, string description)
{
KeywordProperty = actionKeyword;
Description = description;
}
public bool Enabled { get; set; }
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"));
}
}
}
}