Skip to content

Commit

Permalink
- Added functionality to launch Everything with a search query for ex…
Browse files Browse the repository at this point in the history
…tended results.

- Modified default sort order to match Everything defaults
  • Loading branch information
lin-ycv committed Jul 4, 2024
1 parent 80d1d9d commit 07871a3
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 2 deletions.
41 changes: 41 additions & 0 deletions Everything.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
{
internal sealed class Everything
{
private string exe = string.Empty;
internal Everything(Settings setting)
{
Everything_SetRequestFlags(Request.FILE_NAME | Request.PATH);
Expand All @@ -24,6 +25,16 @@ internal void UpdateSettings(Settings setting)
Everything_SetMax(setting.Max);
Everything_SetMatchPath(setting.MatchPath);
Everything_SetRegex(setting.RegEx);
if (!string.IsNullOrEmpty(setting.EverythingPath))
{
if (setting.EverythingPath != exe && Path.Exists(setting.EverythingPath))
exe = setting.EverythingPath;
}
else if (string.IsNullOrEmpty(exe))
{
exe = Path.Exists("C:\\Program Files\\Everything 1.5a\\Everything64.exe") ? "C:\\Program Files\\Everything 1.5a\\Everything64.exe" :
(Path.Exists("C:\\Program Files\\Everything\\Everything64.exe") ? "C:\\Program Files\\Everything\\Everything64.exe" : string.Empty);
}
}

internal IEnumerable<Result> Query(string query, Settings setting)
Expand Down Expand Up @@ -76,6 +87,36 @@ internal IEnumerable<Result> Query(string query, Settings setting)
if (setting.Log > LogLevel.None)
Debugger.Write($"Results: {resultCount}");

bool showMore = !string.IsNullOrEmpty(exe) && resultCount == setting.Max;
if (showMore)
{
var more = new Result()
{
Title = Resources.more_results,
SubTitle = Resources.more_results_Subtitle,
IcoPath = "Images/Everything.light.png",
Action = e =>
{
using var process = new Process();
process.StartInfo.FileName = exe;
process.StartInfo.UseShellExecute = true;
process.StartInfo.Arguments = $@"-s {query}";
try
{
process.Start();
return true;
}
catch (Win32Exception)
{
return false;
}
},
Score = int.MinValue,
QueryTextDisplay = orgqry,
};
yield return more;
}

for (uint i = 0; i < resultCount; i++)
{
if (setting.Log > LogLevel.None)
Expand Down
9 changes: 9 additions & 0 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu,
TextValue = _setting.Prefix,
},
new()
{
Key = nameof(Settings.EverythingPath),
DisplayLabel = Resources.EverythingPath,
DisplayDescription = Resources.EverythingPath_Description,
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Textbox,
TextValue = _setting.EverythingPath,
},
new()
{
Key = nameof(Settings.Copy),
DisplayLabel = Resources.SwapCopy,
Expand Down Expand Up @@ -144,6 +152,7 @@ public void UpdateSettings(PowerLauncherPluginSettings settings)
_setting.Updates = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.Updates)).Value;
_setting.Log = (LogLevel)settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.Log)).ComboBoxValue;
_setting.Prefix = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.Prefix)).TextValue;
_setting.EverythingPath = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.EverythingPath)).TextValue;

_everything?.UpdateSettings(_setting);
_contextMenuLoader?.Update(_setting);
Expand Down
36 changes: 36 additions & 0 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@
<data name="EnvVar_Description" xml:space="preserve">
<value>Expand enviroment variables, such as %appdata%, so that they work properly at the cost of query time.</value>
</data>
<data name="EverythingPath" xml:space="preserve">
<value>Everything64.exe</value>
</data>
<data name="EverythingPath_Description" xml:space="preserve">
<value>Location of Everything64.exe if it's not installed in "Program Files"</value>
</data>
<data name="Everything_ini" xml:space="preserve">
<value>Install Everything if not installed</value>
</data>
Expand All @@ -166,6 +172,12 @@
<data name="Max_Description" xml:space="preserve">
<value>The maximum amount of results to display in the results.</value>
</data>
<data name="more_results" xml:space="preserve">
<value>See more...</value>
</data>
<data name="more_results_Subtitle" xml:space="preserve">
<value>Open Everything and see the remaining results</value>
</data>
<data name="open_containing_folder" xml:space="preserve">
<value>Open containing folder (Ctrl+Shift+E)</value>
</data>
Expand Down
13 changes: 13 additions & 0 deletions Properties/Resources.zh-cn.resx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@
<data name="EnvVar_Description" xml:space="preserve">
<value>搜索时可以使用环境变量,但会增加搜索时间</value>
</data>
<data name="EverythingPath_Description" xml:space="preserve">
<value>若Everything安装位置非预设的Program Files,请提供Everything64exe的位置</value>
</data>
<data name="Everything_ini" xml:space="preserve">
<value>是否安装了 Everything?</value>
</data>
Expand All @@ -148,6 +151,12 @@
<data name="Max_Description" xml:space="preserve">
<value>结果中显示的最大结果数</value>
</data>
<data name="more_results" xml:space="preserve">
<value>显示更多结果...</value>
</data>
<data name="more_results_Subtitle" xml:space="preserve">
<value>在Everything主视窗里查看更多结果</value>
</data>
<data name="open_containing_folder" xml:space="preserve">
<value>打开所在文件夹 (Ctrl+Shift+E)</value>
</data>
Expand All @@ -160,6 +169,10 @@
<data name="plugin_name" xml:space="preserve">
<value>Everything</value>
</data>
<data name="Prefix_Description" xml:space="preserve">
<value>为搜索词添加固定的前缀,搜索时无需再手动输入修饰词/筛选词
前缀与搜索词之间不会自动加入空格</value>
</data>
<data name="Preview_Description" xml:space="preserve">
<value>以图标形式预览文件内容,如果文件不是本地文件,可能会导致冻结</value>
</data>
Expand Down
9 changes: 9 additions & 0 deletions Properties/Resources.zh-tw.resx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@
<data name="EnvVar_Description" xml:space="preserve">
<value>搜尋時可用環境變數,但會增加搜尋時間</value>
</data>
<data name="EverythingPath_Description" xml:space="preserve">
<value>若Everything安裝位置非預設的Program Files,請提供Everything64.exe的位置</value>
</data>
<data name="Everything_ini" xml:space="preserve">
<value>是否有安裝 Everything?</value>
</data>
Expand All @@ -148,6 +151,12 @@
<data name="Max_Description" xml:space="preserve">
<value>結果中顯示的結果數上限</value>
</data>
<data name="more_results" xml:space="preserve">
<value>顯示更多結果...</value>
</data>
<data name="more_results_Subtitle" xml:space="preserve">
<value>在Everything主視窗裡查看更多結果</value>
</data>
<data name="open_containing_folder" xml:space="preserve">
<value>開啟檔案位置 (Ctrl+Shift+E)</value>
</data>
Expand Down
5 changes: 3 additions & 2 deletions Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace Community.PowerToys.Run.Plugin.Everything
public class Settings
{
// Settings from PTR settings
public Sort Sort { get; set; } = Sort.DATE_MODIFIED_DESCENDING;
public uint Max { get; set; } = 20;
public Sort Sort { get; set; } = Sort.NAME_ASCENDING;
public uint Max { get; set; } = 10;
public string Context { get; set; } = "012345";
public bool Copy { get; set; }
public bool MatchPath { get; set; }
Expand All @@ -22,6 +22,7 @@ public class Settings
public string Skip { get; set; }
public LogLevel Log { get; set; } = LogLevel.None;
public string Prefix { get; set; }
public string EverythingPath { get; set; }

// Get Filters from settings.toml
public Dictionary<string, string> Filters { get; } = [];
Expand Down

0 comments on commit 07871a3

Please sign in to comment.