mirror of
https://github.com/lin-ycv/EverythingPowerToys.git
synced 2025-01-08 11:57:59 +08:00
Added option to expand Enviroment Variables
Resolves #70 Code refactoring
This commit is contained in:
parent
a84d81c278
commit
455d28fd04
@ -11,27 +11,21 @@ using Wox.Plugin.Logger;
|
||||
|
||||
namespace Community.PowerToys.Run.Plugin.Everything
|
||||
{
|
||||
internal sealed class ContextMenuLoader : IContextMenu
|
||||
internal sealed class ContextMenuLoader(PluginInitContext context, string options) : IContextMenu
|
||||
{
|
||||
private readonly PluginInitContext _context;
|
||||
private readonly PluginInitContext _context = context;
|
||||
|
||||
// Extensions for adding run as admin context menu item for applications
|
||||
private readonly string[] _appExtensions = { ".exe", ".bat", ".appref-ms", ".lnk" };
|
||||
private readonly string[] _appExtensions = [".exe", ".bat", ".appref-ms", ".lnk"];
|
||||
|
||||
private bool _swapCopy;
|
||||
private string _options;
|
||||
private string _options = options;
|
||||
internal void Update(Settings s)
|
||||
{
|
||||
_swapCopy = s.Copy;
|
||||
_options = s.Context;
|
||||
}
|
||||
|
||||
public ContextMenuLoader(PluginInitContext context, string options)
|
||||
{
|
||||
_context = context;
|
||||
_options = options;
|
||||
}
|
||||
|
||||
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
|
||||
{
|
||||
var contextMenus = new List<ContextMenuResult>();
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
@ -33,9 +34,14 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
Everything_SetMatchPath(true);
|
||||
}
|
||||
|
||||
if (setting.EnvVar && orgqry.Contains('%'))
|
||||
{
|
||||
query = Environment.ExpandEnvironmentVariables(query).Replace(';', '|');
|
||||
}
|
||||
|
||||
if (orgqry.Contains(':'))
|
||||
{
|
||||
string[] nqry = query.Split(':');
|
||||
string[] nqry = query.Split(':', 2);
|
||||
if (setting.Filters.TryGetValue(nqry[0].ToLowerInvariant(), out string value))
|
||||
query = nqry[1].Trim() + " ext:" + value;
|
||||
}
|
||||
@ -55,7 +61,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
|
||||
for (uint i = 0; i < resultCount; i++)
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder(260);
|
||||
StringBuilder buffer = new(260);
|
||||
Everything_GetResultFullPathName(i, buffer, 260);
|
||||
string fullPath = buffer.ToString();
|
||||
string name = Path.GetFileName(fullPath);
|
||||
@ -100,7 +106,6 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
};
|
||||
yield return r;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,4 +12,5 @@ using System.Diagnostics.CodeAnalysis;
|
||||
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1602:Enumeration items should be documented", Justification = "Reviewed")]
|
||||
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File should have header", Justification = "Reviewed")]
|
||||
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1636:FileHeaderCopyrightTextMustMatch", Justification = "Reviewed.")]
|
||||
[assembly: SuppressMessage("Performance", "CA1838:Avoid 'StringBuilder' parameters for P/Invokes", Justification = "breaks icon preview for some reason when using char[]", Scope = "member", Target = "~M:Community.PowerToys.Run.Plugin.Everything.NativeMethods.Everything_GetResultFullPathName(System.UInt32,System.Text.StringBuilder,System.UInt32)")]
|
||||
[assembly: SuppressMessage("Performance", "CA1838:Avoid 'StringBuilder' parameters for P/Invokes", Justification = "breaks icon preview for some reason when using char[]")]
|
||||
[assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1010:Opening square brackets should be spaced correctly", Justification = "Reviewed")]
|
||||
|
39
Main.cs
39
Main.cs
@ -27,15 +27,14 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
|
||||
private readonly Settings _setting;
|
||||
private readonly PluginJsonStorage<Settings> _storage;
|
||||
private readonly Everything _everything;
|
||||
|
||||
private IContextMenu _contextMenuLoader;
|
||||
private ContextMenuLoader _contextMenuLoader;
|
||||
private bool _disposed;
|
||||
|
||||
private Everything _everything;
|
||||
|
||||
public IEnumerable<PluginAdditionalOption> AdditionalOptions => new List<PluginAdditionalOption>()
|
||||
{
|
||||
new PluginAdditionalOption()
|
||||
new()
|
||||
{
|
||||
Key = nameof(Settings.Context),
|
||||
DisplayLabel = Resources.Context,
|
||||
@ -43,7 +42,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Textbox,
|
||||
TextValue = _setting.Context,
|
||||
},
|
||||
new PluginAdditionalOption()
|
||||
new()
|
||||
{
|
||||
Key = nameof(Settings.Sort),
|
||||
DisplayLabel = Resources.Sort,
|
||||
@ -52,7 +51,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
ComboBoxItems = Enum.GetValues(typeof(Sort)).Cast<int>().Select(v => new KeyValuePair<string, string>(((Sort)v).ToString(), v + string.Empty)).ToList(),
|
||||
ComboBoxValue = (int)_setting.Sort,
|
||||
},
|
||||
new PluginAdditionalOption()
|
||||
new()
|
||||
{
|
||||
Key = nameof(Settings.Max),
|
||||
DisplayLabel = Resources.Max,
|
||||
@ -60,42 +59,49 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Numberbox,
|
||||
NumberValue = _setting.Max,
|
||||
},
|
||||
new PluginAdditionalOption()
|
||||
new()
|
||||
{
|
||||
Key = nameof(Settings.Copy),
|
||||
DisplayLabel = Resources.SwapCopy,
|
||||
DisplayDescription = Resources.SwapCopy_Description,
|
||||
Value = _setting.Copy,
|
||||
},
|
||||
new PluginAdditionalOption()
|
||||
new()
|
||||
{
|
||||
Key = nameof(Settings.MatchPath),
|
||||
DisplayLabel = Resources.Match_path,
|
||||
DisplayDescription = Resources.Match_path_Description,
|
||||
Value = _setting.MatchPath,
|
||||
},
|
||||
new PluginAdditionalOption()
|
||||
new()
|
||||
{
|
||||
Key = nameof(Settings.Preview),
|
||||
DisplayLabel = Resources.Preview,
|
||||
DisplayDescription = Resources.Preview_Description,
|
||||
Value = _setting.Preview,
|
||||
},
|
||||
new PluginAdditionalOption()
|
||||
new()
|
||||
{
|
||||
Key = nameof(Settings.QueryText),
|
||||
DisplayLabel = Resources.QueryText,
|
||||
DisplayDescription = Resources.QueryText_Description,
|
||||
Value = _setting.QueryText,
|
||||
},
|
||||
new PluginAdditionalOption()
|
||||
new()
|
||||
{
|
||||
Key = nameof(Settings.RegEx),
|
||||
DisplayLabel = Resources.RegEx,
|
||||
DisplayDescription = Resources.RegEx_Description,
|
||||
Value = _setting.RegEx,
|
||||
},
|
||||
new PluginAdditionalOption()
|
||||
new()
|
||||
{
|
||||
Key = nameof(Settings.EnvVar),
|
||||
DisplayLabel = Resources.EnvVar,
|
||||
DisplayDescription = Resources.EnvVar_Description,
|
||||
Value = _setting.EnvVar,
|
||||
},
|
||||
new()
|
||||
{
|
||||
Key = nameof(Settings.Updates),
|
||||
DisplayLabel = Resources.Updates,
|
||||
@ -126,11 +132,12 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
_setting.MatchPath = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.MatchPath)).Value;
|
||||
_setting.Copy = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.Copy)).Value;
|
||||
_setting.QueryText = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.QueryText)).Value;
|
||||
_setting.EnvVar = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.EnvVar)).Value;
|
||||
_setting.Updates = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.Updates)).Value;
|
||||
|
||||
_everything.UpdateSettings(_setting);
|
||||
|
||||
if (_contextMenuLoader != null) ((ContextMenuLoader)_contextMenuLoader).Update(_setting);
|
||||
if (_contextMenuLoader != null) _contextMenuLoader.Update(_setting);
|
||||
|
||||
Save();
|
||||
}
|
||||
@ -139,18 +146,18 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
_contextMenuLoader = new ContextMenuLoader(context, _setting.Context);
|
||||
((ContextMenuLoader)_contextMenuLoader).Update(_setting);
|
||||
_contextMenuLoader.Update(_setting);
|
||||
}
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
List<Result> results = new List<Result>();
|
||||
List<Result> results = [];
|
||||
return results;
|
||||
}
|
||||
|
||||
public List<Result> Query(Query query, bool delayedExecution)
|
||||
{
|
||||
List<Result> results = new List<Result>();
|
||||
List<Result> results = [];
|
||||
if (!string.IsNullOrEmpty(query.Search))
|
||||
{
|
||||
var searchQuery = query.Search;
|
||||
|
18
Properties/Resources.Designer.cs
generated
18
Properties/Resources.Designer.cs
generated
@ -124,6 +124,24 @@ namespace Community.PowerToys.Run.Plugin.Everything.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Enviroment Variables.
|
||||
/// </summary>
|
||||
public static string EnvVar {
|
||||
get {
|
||||
return ResourceManager.GetString("EnvVar", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Expanded enviroment variables, such as %appdata%, so that they work properly at the cost of query time..
|
||||
/// </summary>
|
||||
public static string EnvVar_Description {
|
||||
get {
|
||||
return ResourceManager.GetString("EnvVar_Description", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Install Everything if not installed.
|
||||
/// </summary>
|
||||
|
@ -139,6 +139,12 @@
|
||||
<data name="copy_shortcutAlt" xml:space="preserve">
|
||||
<value>(Ctrl+Alt+C)</value>
|
||||
</data>
|
||||
<data name="EnvVar" xml:space="preserve">
|
||||
<value>Enviroment Variables</value>
|
||||
</data>
|
||||
<data name="EnvVar_Description" xml:space="preserve">
|
||||
<value>Expanded enviroment variables, such as %appdata%, so that they work properly at the cost of query time.</value>
|
||||
</data>
|
||||
<data name="Everything_ini" xml:space="preserve">
|
||||
<value>Install Everything if not installed</value>
|
||||
</data>
|
||||
|
@ -130,6 +130,9 @@
|
||||
<data name="copy_path" xml:space="preserve">
|
||||
<value>複製路徑</value>
|
||||
</data>
|
||||
<data name="EnvVar_Description" xml:space="preserve">
|
||||
<value>搜尋時可用環境變數,但會增加搜尋時間</value>
|
||||
</data>
|
||||
<data name="Everything_ini" xml:space="preserve">
|
||||
<value>是否有安裝 Everything?</value>
|
||||
</data>
|
||||
|
@ -12,7 +12,7 @@ Dev instructions are in the wiki.
|
||||
#### Install instructions
|
||||
1. Download the latest release from [here](https://github.com/lin-ycv/EverythingPowerToys/releases/latest).
|
||||
2. Unzip.
|
||||
3. Copy the `Everything` folder to `C:\Program Files\PowerToys\RunPlugins` or `%LOCALAPPDATA%\Microsoft\PowerToys\PowerToys Run\Plugins\`.
|
||||
3. Copy the `Everything` folder to `C:\Program Files\PowerToys\RunPlugins` or `%LOCALAPPDATA%\PowerToys\RunPlugins`.
|
||||
4. Restart PowerToys.
|
||||
|
||||
#### Requirements
|
||||
|
@ -6,6 +6,7 @@ namespace Community.PowerToys.Run.Plugin.Everything.SearchHelper
|
||||
{
|
||||
internal sealed class IconLoader
|
||||
{
|
||||
internal static readonly char[] Separator = ['\"', ','];
|
||||
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
|
||||
internal static string? Icon(string doctype)
|
||||
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
|
||||
@ -14,7 +15,7 @@ namespace Community.PowerToys.Run.Plugin.Everything.SearchHelper
|
||||
_ = AssocQueryString(AssocF.NONE, AssocStr.DEFAULTICON, doctype, null, null, ref pcchOut);
|
||||
char[] pszOut = new char[pcchOut];
|
||||
if (AssocQueryString(AssocF.NONE, AssocStr.DEFAULTICON, doctype, null, pszOut, ref pcchOut) != 0) return null;
|
||||
string doc = Environment.ExpandEnvironmentVariables(new string(pszOut).Split(new char[] { '\"', ',' }, StringSplitOptions.RemoveEmptyEntries)[0].Replace("\"", string.Empty, StringComparison.CurrentCulture).Trim());
|
||||
string doc = Environment.ExpandEnvironmentVariables(new string(pszOut).Split(Separator, StringSplitOptions.RemoveEmptyEntries)[0].Replace("\"", string.Empty, StringComparison.CurrentCulture).Trim());
|
||||
|
||||
return File.Exists(doc) ? doc : null;
|
||||
}
|
||||
|
@ -17,17 +17,17 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
public bool Preview { get; set; } = true;
|
||||
public bool QueryText { get; set; }
|
||||
public bool RegEx { get; set; }
|
||||
public bool EnvVar { get; set; }
|
||||
public bool Updates { get; set; } = true;
|
||||
public string Skip { get; set; }
|
||||
|
||||
// Get Filters from settings.toml
|
||||
public Dictionary<string, string> Filters { get; } = new Dictionary<string, string>();
|
||||
public Dictionary<string, string> Filters { get; } = [];
|
||||
internal void Getfilters()
|
||||
{
|
||||
string[] strArr;
|
||||
try { strArr = File.ReadAllLines(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "settings.toml")); }
|
||||
catch { return; }
|
||||
var culture = new System.Globalization.CultureInfo("en-US");
|
||||
foreach (string str in strArr)
|
||||
{
|
||||
if (str.Length == 0 || str[0] == '#') continue;
|
||||
|
@ -4,7 +4,7 @@
|
||||
"IsGlobal": true,
|
||||
"Name": "Everything",
|
||||
"Author": "Yu Chieh (Victor) Lin",
|
||||
"Version": "0.76.2",
|
||||
"Version": "0.77.0",
|
||||
"Language": "csharp",
|
||||
"Website": "https://github.com/Lin-ycv/EverythingPowerToys",
|
||||
"ExecuteFileName": "Community.PowerToys.Run.Plugin.Everything.dll",
|
||||
|
Loading…
Reference in New Issue
Block a user