From 73590c3ea924d1ce353694f301c54717260d3d63 Mon Sep 17 00:00:00 2001 From: Floris Westerman Date: Sun, 11 Sep 2022 22:25:29 +0200 Subject: [PATCH] [PTRun] Windows Terminal plugin: Add option to open profiles in quake window (#19960) * Run/Windows Terminal: Add option to open profiles in quake window * Typo * Incorporate review feedback --- .../TerminalHelperTests.cs | 10 ++++++---- .../Helpers/TerminalHelper.cs | 18 +++++++++++++++-- .../Main.cs | 17 ++++++++++++++-- .../Properties/Resources.Designer.cs | 20 ++++++++++++++++++- .../Properties/Resources.resx | 10 +++++++++- 5 files changed, 65 insertions(+), 10 deletions(-) diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal.UnitTests/TerminalHelperTests.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal.UnitTests/TerminalHelperTests.cs index efd61c3043..06f0f31d56 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal.UnitTests/TerminalHelperTests.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal.UnitTests/TerminalHelperTests.cs @@ -15,11 +15,13 @@ namespace Microsoft.Plugin.WindowsTerminal.UnitTests public class TerminalHelperTests { [DataTestMethod] - [DataRow("Windows PowerShell", true, "--window 0 nt --profile \"Windows PowerShell\"")] - [DataRow("Windows PowerShell", false, "--profile \"Windows PowerShell\"")] - public void ArgumentsTest(string profile, bool openNewTab, string expectedArguments) + [DataRow("Windows PowerShell", true, true, "--window _quake --profile \"Windows PowerShell\"")] + [DataRow("Windows PowerShell", false, true, "--window _quake --profile \"Windows PowerShell\"")] + [DataRow("Windows PowerShell", true, false, "--window 0 nt --profile \"Windows PowerShell\"")] + [DataRow("Windows PowerShell", false, false, " --profile \"Windows PowerShell\"")] + public void ArgumentsTest(string profile, bool openNewTab, bool openQuake, string expectedArguments) { - var arguments = TerminalHelper.GetArguments(profile, openNewTab); + var arguments = TerminalHelper.GetArguments(profile, openNewTab, openQuake); Assert.AreEqual(arguments, expectedArguments); } diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Helpers/TerminalHelper.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Helpers/TerminalHelper.cs index 2b39ad38e7..02e7716436 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Helpers/TerminalHelper.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Helpers/TerminalHelper.cs @@ -15,9 +15,23 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal.Helpers /// /// Name of the Terminal profile /// Whether to launch the profile in a new tab - public static string GetArguments(string profileName, bool openNewTab) + /// Whether to launch the profile in the quake window + public static string GetArguments(string profileName, bool openNewTab, bool openQuake) { - return openNewTab ? $"--window 0 nt --profile \"{profileName}\"" : $"--profile \"{profileName}\""; + var argsPrefix = string.Empty; + if (openQuake) + { + // It does not matter whether we add the "nt" argument here; when specifying the + // _quake window explicitly, Windows Terminal will always open a new tab when the + // window exists, or open a new window when it does not yet. + argsPrefix = "--window _quake"; + } + else if (openNewTab) + { + argsPrefix = "--window 0 nt"; + } + + return $"{argsPrefix} --profile \"{profileName}\""; } /// diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Main.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Main.cs index 0ae54a4fa8..e575ad99cf 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Main.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Main.cs @@ -21,10 +21,12 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal public class Main : IPlugin, IContextMenu, IPluginI18n, ISettingProvider { private const string OpenNewTab = nameof(OpenNewTab); + private const string OpenQuake = nameof(OpenQuake); private const string ShowHiddenProfiles = nameof(ShowHiddenProfiles); private readonly ITerminalQuery _terminalQuery = new TerminalQuery(); private PluginInitContext _context; private bool _openNewTab; + private bool _openQuake; private bool _showHiddenProfiles; private Dictionary _logoCache = new Dictionary(); @@ -41,6 +43,14 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal Value = false, }, + new PluginAdditionalOption() + { + Key = OpenQuake, + DisplayLabel = Resources.open_quake, + DisplayDescription = Resources.open_quake_description, + Value = false, + }, + new PluginAdditionalOption() { Key = ShowHiddenProfiles, @@ -134,7 +144,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal { var appManager = new ApplicationActivationManager(); const ActivateOptions noFlags = ActivateOptions.None; - var queryArguments = TerminalHelper.GetArguments(profile, _openNewTab); + var queryArguments = TerminalHelper.GetArguments(profile, _openNewTab, _openQuake); try { appManager.ActivateApplication(id, queryArguments, noFlags, out var unusedPid); @@ -153,7 +163,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal try { string path = "shell:AppsFolder\\" + id; - Helper.OpenInShell(path, TerminalHelper.GetArguments(profile, _openNewTab), runAs: Helper.ShellRunAsType.Administrator); + Helper.OpenInShell(path, TerminalHelper.GetArguments(profile, _openNewTab, _openQuake), runAs: Helper.ShellRunAsType.Administrator); } catch (Exception ex) { @@ -172,15 +182,18 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal public void UpdateSettings(PowerLauncherPluginSettings settings) { var openNewTab = false; + var openQuake = false; var showHiddenProfiles = false; if (settings != null && settings.AdditionalOptions != null) { openNewTab = settings.AdditionalOptions.FirstOrDefault(x => x.Key == OpenNewTab)?.Value ?? false; + openQuake = settings.AdditionalOptions.FirstOrDefault(x => x.Key == OpenQuake)?.Value ?? false; showHiddenProfiles = settings.AdditionalOptions.FirstOrDefault(x => x.Key == ShowHiddenProfiles)?.Value ?? false; } _openNewTab = openNewTab; + _openQuake = openQuake; _showHiddenProfiles = showHiddenProfiles; } diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Properties/Resources.Designer.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Properties/Resources.Designer.cs index 054ff6c02f..ba2a902906 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Properties/Resources.Designer.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -69,6 +69,24 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal.Properties { } } + /// + /// Looks up a localized string similar to Open profiles in the quake window. + /// + internal static string open_quake { + get { + return ResourceManager.GetString("open_quake", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Windows Terminal supports a "quake" feature where a terminal window is accessible using a global hotkey. Enable this option to open profiles in this window.. + /// + internal static string open_quake_description { + get { + return ResourceManager.GetString("open_quake_description", resourceCulture); + } + } + /// /// Looks up a localized string similar to Open Windows Terminal profiles.. /// diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Properties/Resources.resx b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Properties/Resources.resx index c134b127e1..09acd59b45 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Properties/Resources.resx +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Properties/Resources.resx @@ -120,6 +120,14 @@ Open profiles in a new tab + + Open profiles in the quake window + Quake is a well-known computer game. Don't localize. See https://en.wikipedia.org/wiki/Quake_(video_game) + + + Windows Terminal supports a "quake" feature where a terminal window is accessible using a global hotkey. Enable this option to open profiles in a new tab in this window. + Quake is a well-known computer game. Don't localize. See https://en.wikipedia.org/wiki/Quake_(video_game) + Open Windows Terminal profiles. @@ -135,4 +143,4 @@ Show hidden profiles - \ No newline at end of file +