[Run] Open in console functionality (#4739)

* Added open in console for indexer

* Added open in console fpr indexer and folder plugin

* Added open in console to program plugin

* Added string localization for program plugin

* Added test for win32 program

* Added test for win32 programs

* Added test for indexer plugin

* Localization for context menu title

* Added tests for folder plugin

* Added tests for indexer plugin

* Code cleanup

* Improved logging and nit fixes

* Updated tooltip for open in console

* Updates tests

* Removed subtitle property from contextmenuresult class

* Improved logging for context menu loaders
This commit is contained in:
Divyansh Srivastava
2020-07-08 09:56:26 -07:00
committed by GitHub
parent e3e6b23b7c
commit 638cd1dd48
32 changed files with 402 additions and 80 deletions

View File

@@ -10,6 +10,7 @@ using Wox.Plugin.SharedCommands;
using Wox.Plugin;
using System.Reflection;
using System.Windows.Input;
using Wox.Infrastructure;
namespace Microsoft.Plugin.Folder
{
@@ -33,14 +34,12 @@ namespace Microsoft.Plugin.Folder
}
var icoPath = (record.Type == ResultType.File) ? Main.FileImagePath : Main.FolderImagePath;
var fileOrFolder = (record.Type == ResultType.File) ? "file" : "folder";
contextMenus.Add(new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = _context.API.GetTranslation("Microsoft_plugin_folder_copy_path"),
Glyph = "\xE8C8",
FontFamily = "Segoe MDL2 Assets",
SubTitle = $"Copy the current {fileOrFolder} path to clipboard",
AcceleratorKey = Key.C,
AcceleratorModifiers = ModifierKeys.Control,
Action = (context) =>
@@ -59,6 +58,38 @@ namespace Microsoft.Plugin.Folder
}
}
});
contextMenus.Add(new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = _context.API.GetTranslation("Microsoft_plugin_folder_open_in_console"),
Glyph = "\xE756",
FontFamily = "Segoe MDL2 Assets",
AcceleratorKey = Key.C,
AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
Action = (context) =>
{
try
{
if (record.Type == ResultType.File)
{
Helper.OpenInConsole(Path.GetDirectoryName(record.FullPath));
}
else
{
Helper.OpenInConsole(record.FullPath);
}
return true;
}
catch (Exception e)
{
Log.Exception($"|Microsoft.Plugin.Folder.ContextMenuLoader.LoadContextMenus| Failed to open {record.FullPath} in console, {e.Message}", e);
return false;
}
}
});
}
return contextMenus;
@@ -69,7 +100,7 @@ namespace Microsoft.Plugin.Folder
return new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = "Open containing folder",
Title = _context.API.GetTranslation("Microsoft_plugin_folder_open_containing_folder"),
Glyph = "\xE838",
FontFamily = "Segoe MDL2 Assets",
AcceleratorKey = Key.E,

View File

@@ -12,5 +12,6 @@
<system:String x:Key="wox_plugin_folder_plugin_name">Ordner</system:String>
<system:String x:Key="wox_plugin_folder_plugin_description">Öffne deine Lieblingsordner direkt von Wox aus</system:String>
<system:String x:Key="Microsoft_plugin_folder_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
</ResourceDictionary>

View File

@@ -12,5 +12,6 @@
<system:String x:Key="wox_plugin_folder_plugin_name">Folder</system:String>
<system:String x:Key="wox_plugin_folder_plugin_description">Open favorite folder from Wox directly</system:String>
<system:String x:Key="Microsoft_plugin_folder_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
</ResourceDictionary>

View File

@@ -12,5 +12,6 @@
<system:String x:Key="wox_plugin_folder_plugin_name">Foldery</system:String>
<system:String x:Key="wox_plugin_folder_plugin_description">Otwórz ulubione foldery bezpośrednio z poziomu Woxa</system:String>
<system:String x:Key="Microsoft_plugin_folder_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
</ResourceDictionary>

View File

@@ -12,5 +12,6 @@
<system:String x:Key="wox_plugin_folder_plugin_name">Klasör</system:String>
<system:String x:Key="wox_plugin_folder_plugin_description">Favori klasörünüzü doğrudan Wox'tan açın</system:String>
<system:String x:Key="Microsoft_plugin_folder_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
</ResourceDictionary>

View File

@@ -12,5 +12,6 @@
<system:String x:Key="wox_plugin_folder_plugin_name">文件夹</system:String>
<system:String x:Key="wox_plugin_folder_plugin_description">在Wox中直接打开收藏的文件夹</system:String>
<system:String x:Key="Microsoft_plugin_folder_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
</ResourceDictionary>

View File

@@ -12,5 +12,6 @@
<system:String x:Key="wox_plugin_folder_plugin_name">資料夾</system:String>
<system:String x:Key="wox_plugin_folder_plugin_description">在 Wox 中直接開啟收藏的資料夾</system:String>
<system:String x:Key="Microsoft_plugin_folder_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_folder_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
</ResourceDictionary>

View File

@@ -42,6 +42,12 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Wox.Test</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
<ItemGroup>
<Page Include="FolderPluginSettings.xaml">

View File

@@ -8,6 +8,7 @@ using Wox.Plugin;
using Microsoft.Plugin.Indexer.SearchHelper;
using System.Windows.Input;
using System.Reflection;
using Wox.Infrastructure;
namespace Microsoft.Plugin.Indexer
{
@@ -38,14 +39,12 @@ namespace Microsoft.Plugin.Indexer
contextMenus.Add(CreateOpenContainingFolderResult(record));
}
var fileOrFolder = (type == ResultType.File) ? "file" : "folder";
contextMenus.Add(new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = _context.API.GetTranslation("Microsoft_plugin_indexer_copy_path"),
Glyph = "\xE8C8",
FontFamily = "Segoe MDL2 Assets",
SubTitle = $"Copy the current {fileOrFolder} path to clipboard",
AcceleratorKey = Key.C,
AcceleratorModifiers = ModifierKeys.Control,
@@ -65,6 +64,37 @@ namespace Microsoft.Plugin.Indexer
}
}
});
contextMenus.Add(new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = _context.API.GetTranslation("Microsoft_plugin_indexer_open_in_console"),
Glyph = "\xE756",
FontFamily = "Segoe MDL2 Assets",
AcceleratorKey = Key.C,
AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
Action = (context) =>
{
try
{
if (type == ResultType.File)
{
Helper.OpenInConsole(Path.GetDirectoryName(record.Path));
}
else
{
Helper.OpenInConsole(record.Path);
}
return true;
}
catch (Exception e)
{
Log.Exception($"|Microsoft.Plugin.Indexer.ContextMenuLoader.LoadContextMenus| Failed to open {record.Path} in console, {e.Message}", e);
return false;
}
}
});
}
return contextMenus;

View File

@@ -4,6 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>

View File

@@ -4,6 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>

View File

@@ -4,6 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>

View File

@@ -4,6 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>

View File

@@ -4,6 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>

View File

@@ -4,6 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>

View File

@@ -4,6 +4,7 @@
<system:String x:Key="Microsoft_plugin_indexer_copy_path">Copy path (Ctrl+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="Microsoft_plugin_indexer_name">Name</system:String>
<system:String x:Key="Microsoft_plugin_indexer_path">Path</system:String>

View File

@@ -58,6 +58,12 @@
</None>
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Wox.Test</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
<ItemGroup>
<Content Include="Languages\de.xaml">
<Generator>MSBuild:Compile</Generator>
@@ -95,6 +101,4 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

View File

@@ -30,6 +30,7 @@
<system:String x:Key="wox_plugin_program_run_as_administrator">Als Administrator ausführen (Ctrl+Shift+Enter)</system:String>
<system:String x:Key="wox_plugin_program_open_containing_folder">Enthaltenden Ordner öffnen (Ctrl+Shift+E)</system:String>
<system:String x:Key="wox_plugin_program_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="wox_plugin_program_plugin_name">Programm</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">Suche Programme mit Wox</system:String>

View File

@@ -35,6 +35,8 @@
<system:String x:Key="wox_plugin_program_run_as_administrator">Run As Administrator (Ctrl+Shift+Enter)</system:String>
<system:String x:Key="wox_plugin_program_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="wox_plugin_program_disable_program">Disable this program from displaying</system:String>
<system:String x:Key="wox_plugin_program_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="wox_plugin_program_plugin_name">Program</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">Search programs in Wox</system:String>

View File

@@ -31,6 +31,8 @@
<system:String x:Key="wox_plugin_program_run_as_administrator">Run As Administrator (Ctrl+Shift+Enter)</system:String>
<system:String x:Key="wox_plugin_program_open_containing_folder">Open containing folder (Ctrl+Shift+E)</system:String>
<system:String x:Key="wox_plugin_program_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="wox_plugin_program_plugin_name">Program</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">Search programs in Wox</system:String>

View File

@@ -33,6 +33,7 @@
<system:String x:Key="wox_plugin_program_plugin_name">Programy</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">Szukaj i uruchamiaj programy z poziomu Woxa</system:String>
<system:String x:Key="wox_plugin_program_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<!--Application subtitle-->
<system:String x:Key="powertoys_run_plugin_program_win32_application">Application</system:String>
@@ -43,4 +44,5 @@
<system:String x:Key="powertoys_run_plugin_program_file_name">Name</system:String>
<system:String x:Key="powertoys_run_plugin_program_file_path">Path</system:String>
</ResourceDictionary>

View File

@@ -30,6 +30,8 @@
<system:String x:Key="wox_plugin_program_run_as_administrator">Yönetici Olarak Çalıştır (Ctrl+Shift+Enter)</system:String>
<system:String x:Key="wox_plugin_program_open_containing_folder">İçeren Klasörü Aç (Ctrl+Shift+E)</system:String>
<system:String x:Key="wox_plugin_program_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="wox_plugin_program_plugin_name">Program</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">Programları Wox'tan arayın</system:String>

View File

@@ -30,6 +30,8 @@
<system:String x:Key="wox_plugin_program_run_as_administrator">以管理员身份运行 (Ctrl+Shift+Enter)</system:String>
<system:String x:Key="wox_plugin_program_open_containing_folder">打开所属文件夹 (Ctrl+Shift+E)</system:String>
<system:String x:Key="wox_plugin_program_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="wox_plugin_program_plugin_name">程序</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">在Wox中搜索程序</system:String>

View File

@@ -30,6 +30,8 @@
<system:String x:Key="wox_plugin_program_run_as_administrator">以系統管理員身分執行 (Ctrl+Shift+Enter)</system:String>
<system:String x:Key="wox_plugin_program_open_containing_folder">開啟檔案位置 (Ctrl+Shift+E)</system:String>
<system:String x:Key="wox_plugin_program_open_in_console">Open path in console (Ctrl+Shift+C)</system:String>
<system:String x:Key="wox_plugin_program_plugin_name">程式</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">在 Wox 中搜尋程式</system:String>

View File

@@ -22,6 +22,7 @@ using System.Runtime.InteropServices.ComTypes;
using Wox.Plugin.SharedCommands;
using System.Reflection;
using Wox.Infrastructure.Image;
using Wox.Infrastructure.Logger;
namespace Microsoft.Plugin.Program.Programs
{
@@ -356,7 +357,30 @@ namespace Microsoft.Plugin.Program.Programs
return true;
}
});
contextMenus.Add(new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = api.GetTranslation("wox_plugin_program_open_in_console"),
Glyph = "\xE756",
FontFamily = "Segoe MDL2 Assets",
AcceleratorKey = Key.C,
AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
Action = (context) =>
{
try
{
Helper.OpenInConsole(Package.Location);
return true;
}
catch (Exception e)
{
Log.Exception($"|Microsoft.Plugin.Program.UWP.ContextMenu| Failed to open {Name} in console, {e.Message}", e);
return false;
}
}
});
return contextMenus;
}

View File

@@ -14,6 +14,7 @@ using Wox.Plugin;
using System.Windows.Input;
using System.Reflection;
using System.Text.RegularExpressions;
using Wox.Infrastructure.Logger;
namespace Microsoft.Plugin.Program.Programs
{
@@ -202,32 +203,11 @@ namespace Microsoft.Plugin.Program.Programs
public List<ContextMenuResult> ContextMenus(IPublicAPI api)
{
// To add a context menu only to open file location as Internet shortcut applications do not have the functionality to run as admin
if(AppType == (uint)ApplicationTypes.INTERNET_SHORTCUT_APPLICATION)
var contextMenus = new List<ContextMenuResult>();
if (AppType != (uint)ApplicationTypes.INTERNET_SHORTCUT_APPLICATION)
{
var contextMenuItems = new List<ContextMenuResult>
{
new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = api.GetTranslation("wox_plugin_program_open_containing_folder"),
Glyph = "\xE838",
FontFamily = "Segoe MDL2 Assets",
AcceleratorKey = Key.E,
AcceleratorModifiers = (ModifierKeys.Control | ModifierKeys.Shift),
Action = _ =>
{
Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", ParentDirectory));
return true;
}
}
};
return contextMenuItems;
}
var contextMenus = new List<ContextMenuResult>
{
new ContextMenuResult
contextMenus.Add(new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = api.GetTranslation("wox_plugin_program_run_as_administrator"),
@@ -249,7 +229,10 @@ namespace Microsoft.Plugin.Program.Programs
return true;
}
},
});
}
contextMenus.Add(
new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
@@ -263,8 +246,32 @@ namespace Microsoft.Plugin.Program.Programs
Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", ParentDirectory));
return true;
}
}
};
});
contextMenus.Add(
new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = api.GetTranslation("wox_plugin_program_open_in_console"),
Glyph = "\xE756",
FontFamily = "Segoe MDL2 Assets",
AcceleratorKey = Key.C,
AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
Action = (context) =>
{
try
{
Helper.OpenInConsole(ParentDirectory);
return true;
}
catch (Exception e)
{
Log.Exception($"|Microsoft.Plugin.Program.Win32.ContextMenu| Failed to open {Name} in console, {e.Message}", e);
return false;
}
}
});
return contextMenus;
}