Flow.Launcher/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs

245 lines
11 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
2022-03-28 20:28:18 +00:00
using System.Text.Json.Serialization;
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search.Everything;
using Flow.Launcher.Plugin.Explorer.Search.IProvider;
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
using Flow.Launcher.Plugin.Explorer.Search.WindowsIndex;
namespace Flow.Launcher.Plugin.Explorer
{
public class Settings
{
2020-05-24 22:14:21 +00:00
public int MaxResult { get; set; } = 100;
public ObservableCollection<AccessLink> QuickAccessLinks { get; set; } = [];
public ObservableCollection<AccessLink> IndexSearchExcludedSubdirectoryPaths { get; set; } = [];
public string EditorPath { get; set; } = "";
2022-12-19 20:07:07 +00:00
public string FolderEditorPath { get; set; } = "";
2022-08-17 00:52:53 +00:00
public string ShellPath { get; set; } = "cmd";
2024-07-16 22:44:18 +00:00
public string ExcludedFileTypes { get; set; } = "";
public bool UseLocationAsWorkingDir { get; set; } = false;
public bool ShowInlinedWindowsContextMenu { get; set; } = false;
public string WindowsContextMenuIncludedItems { get; set; } = string.Empty;
public string WindowsContextMenuExcludedItems { get; set; } = string.Empty;
2023-03-29 07:19:55 +00:00
public bool DefaultOpenFolderInFileManager { get; set; } = false;
2020-07-14 19:50:48 +00:00
2025-06-04 09:01:15 +00:00
public bool DisplayMoreInformationInToolTip { get; set; } = false;
2020-07-14 19:50:48 +00:00
public string SearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
2021-07-30 10:44:29 +00:00
2021-07-03 04:45:00 +00:00
public bool SearchActionKeywordEnabled { get; set; } = true;
2020-07-14 19:50:48 +00:00
public string FileContentSearchActionKeyword { get; set; } = Constants.DefaultContentSearchActionKeyword;
public bool FileContentSearchKeywordEnabled { get; set; } = true;
public string PathSearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
2021-07-03 04:45:00 +00:00
public bool PathSearchKeywordEnabled { get; set; }
public string IndexSearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
public bool IndexSearchKeywordEnabled { get; set; }
2021-07-30 10:44:29 +00:00
public string QuickAccessActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
public bool QuickAccessKeywordEnabled { get; set; }
public string FolderSearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
public bool FolderSearchKeywordEnabled { get; set; }
public string FileSearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
public bool FileSearchKeywordEnabled { get; set; }
public bool WarnWindowsSearchServiceOff { get; set; } = true;
public bool ShowFileSizeInPreviewPanel { get; set; } = true;
public bool ShowCreatedDateInPreviewPanel { get; set; } = true;
public bool ShowModifiedDateInPreviewPanel { get; set; } = true;
2025-05-24 03:12:56 +00:00
public bool ShowFileAgeInPreviewPanel { get; set; } = false;
2025-05-24 03:12:56 +00:00
public string PreviewPanelDateFormat { get; set; } = "yyyy-MM-dd";
public string PreviewPanelTimeFormat { get; set; } = "HH:mm";
private EverythingSearchManager _everythingManagerInstance;
private WindowsIndexSearchManager _windowsIndexSearchManager;
#region SearchEngine
private EverythingSearchManager EverythingManagerInstance => _everythingManagerInstance ??= new EverythingSearchManager(this);
private WindowsIndexSearchManager WindowsIndexSearchManager => _windowsIndexSearchManager ??= new WindowsIndexSearchManager(this);
public IndexSearchEngineOption IndexSearchEngine { get; set; } = IndexSearchEngineOption.WindowsIndex;
2022-03-28 20:28:18 +00:00
[JsonIgnore]
public IIndexProvider IndexProvider => IndexSearchEngine switch
{
IndexSearchEngineOption.Everything => EverythingManagerInstance,
IndexSearchEngineOption.WindowsIndex => WindowsIndexSearchManager,
_ => throw new ArgumentOutOfRangeException(nameof(IndexSearchEngine))
};
public PathEnumerationEngineOption PathEnumerationEngine { get; set; } = PathEnumerationEngineOption.WindowsIndex;
2022-03-28 20:28:18 +00:00
[JsonIgnore]
public IPathIndexProvider PathEnumerator => PathEnumerationEngine switch
{
PathEnumerationEngineOption.Everything => EverythingManagerInstance,
PathEnumerationEngineOption.WindowsIndex => WindowsIndexSearchManager,
_ => throw new ArgumentOutOfRangeException(nameof(PathEnumerationEngine))
};
public ContentIndexSearchEngineOption ContentSearchEngine { get; set; } = ContentIndexSearchEngineOption.WindowsIndex;
2022-03-28 20:28:18 +00:00
[JsonIgnore]
public IContentIndexProvider ContentIndexProvider => ContentSearchEngine switch
{
ContentIndexSearchEngineOption.Everything => EverythingManagerInstance,
ContentIndexSearchEngineOption.WindowsIndex => WindowsIndexSearchManager,
_ => throw new ArgumentOutOfRangeException(nameof(ContentSearchEngine))
};
public enum PathEnumerationEngineOption
{
[Description("plugin_explorer_engine_windows_index")]
WindowsIndex,
[Description("plugin_explorer_engine_everything")]
Everything,
[Description("plugin_explorer_path_enumeration_engine_none")]
DirectEnumeration
}
public enum IndexSearchEngineOption
{
[Description("plugin_explorer_engine_windows_index")]
WindowsIndex,
[Description("plugin_explorer_engine_everything")]
Everything,
}
2022-03-28 20:28:18 +00:00
public enum ContentIndexSearchEngineOption
{
[Description("plugin_explorer_engine_windows_index")]
WindowsIndex,
[Description("plugin_explorer_engine_everything")]
2022-03-28 20:28:18 +00:00
Everything,
}
#endregion
2022-03-28 20:28:18 +00:00
#region Everything Settings
public string EverythingInstalledPath { get; set; }
2025-07-16 13:28:17 +00:00
public EverythingSortOption SortOption { get; set; } = EverythingSortOption.NAME_ASCENDING;
public bool EnableEverythingContentSearch { get; set; } = false;
public bool EverythingEnabled => IndexSearchEngine == IndexSearchEngineOption.Everything ||
2022-08-17 01:32:49 +00:00
PathEnumerationEngine == PathEnumerationEngineOption.Everything ||
ContentSearchEngine == ContentIndexSearchEngineOption.Everything;
2023-02-20 20:04:50 +00:00
public bool EverythingSearchFullPath { get; set; } = false;
public bool EverythingEnableRunCount { get; set; } = true;
#endregion
internal enum ActionKeyword
{
SearchActionKeyword,
PathSearchActionKeyword,
FileContentSearchActionKeyword,
2021-07-30 10:44:29 +00:00
IndexSearchActionKeyword,
QuickAccessActionKeyword,
FolderSearchActionKeyword,
FileSearchActionKeyword,
}
internal string GetActionKeyword(ActionKeyword actionKeyword) => actionKeyword switch
{
ActionKeyword.SearchActionKeyword => SearchActionKeyword,
ActionKeyword.PathSearchActionKeyword => PathSearchActionKeyword,
ActionKeyword.FileContentSearchActionKeyword => FileContentSearchActionKeyword,
2021-07-30 10:44:29 +00:00
ActionKeyword.IndexSearchActionKeyword => IndexSearchActionKeyword,
ActionKeyword.QuickAccessActionKeyword => QuickAccessActionKeyword,
ActionKeyword.FolderSearchActionKeyword => FolderSearchActionKeyword,
ActionKeyword.FileSearchActionKeyword => FileSearchActionKeyword,
_ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "ActionKeyWord property not found")
};
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,
2021-07-30 10:44:29 +00:00
ActionKeyword.QuickAccessActionKeyword => QuickAccessActionKeyword = keyword,
ActionKeyword.FolderSearchActionKeyword => FolderSearchActionKeyword = keyword,
ActionKeyword.FileSearchActionKeyword => FileSearchActionKeyword = keyword,
_ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "ActionKeyWord property not found")
};
internal bool GetActionKeywordEnabled(ActionKeyword actionKeyword) => actionKeyword switch
{
2021-07-03 04:45:00 +00:00
ActionKeyword.SearchActionKeyword => SearchActionKeywordEnabled,
ActionKeyword.PathSearchActionKeyword => PathSearchKeywordEnabled,
ActionKeyword.IndexSearchActionKeyword => IndexSearchKeywordEnabled,
ActionKeyword.FileContentSearchActionKeyword => FileContentSearchKeywordEnabled,
2021-07-30 10:44:29 +00:00
ActionKeyword.QuickAccessActionKeyword => QuickAccessKeywordEnabled,
ActionKeyword.FolderSearchActionKeyword => FolderSearchKeywordEnabled,
ActionKeyword.FileSearchActionKeyword => FileSearchKeywordEnabled,
_ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "ActionKeyword enabled status not defined")
};
2021-07-03 06:33:29 +00:00
internal void SetActionKeywordEnabled(ActionKeyword actionKeyword, bool enable) => _ = actionKeyword switch
{
2021-07-03 04:45:00 +00:00
ActionKeyword.SearchActionKeyword => SearchActionKeywordEnabled = enable,
ActionKeyword.PathSearchActionKeyword => PathSearchKeywordEnabled = enable,
ActionKeyword.IndexSearchActionKeyword => IndexSearchKeywordEnabled = enable,
ActionKeyword.FileContentSearchActionKeyword => FileContentSearchKeywordEnabled = enable,
2021-07-30 10:44:29 +00:00
ActionKeyword.QuickAccessActionKeyword => QuickAccessKeywordEnabled = enable,
ActionKeyword.FolderSearchActionKeyword => FolderSearchKeywordEnabled = enable,
ActionKeyword.FileSearchActionKeyword => FileSearchKeywordEnabled = enable,
_ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "ActionKeyword enabled status not defined")
};
// Returns a dictionary because some ActionKeywords may use wildcards (*),
// which means multiple ActionKeywords can be considered active at the same time.
// Using a dictionary ensures O(1) lookup time when checking which actions
// are enabled.
internal Dictionary<ActionKeyword, string> GetActiveActionKeywords(string actionKeywordStr)
{
var result = new Dictionary<ActionKeyword, string>();
if (string.IsNullOrEmpty(actionKeywordStr)) return result;
foreach (var action in Enum.GetValues<ActionKeyword>())
{
var keywordStr = GetActionKeyword(action);
if (string.IsNullOrEmpty(keywordStr)) continue;
var isEnabled = GetActionKeywordEnabled(action);
if (keywordStr == actionKeywordStr && isEnabled) result.Add(action, keywordStr);
}
return result;
}
}
}