[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
This commit is contained in:
Floris Westerman 2022-09-11 22:25:29 +02:00 committed by GitHub
parent 922d21f9f1
commit 73590c3ea9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 10 deletions

View File

@ -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);
}

View File

@ -15,9 +15,23 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal.Helpers
/// </summary>
/// <param name="profileName">Name of the Terminal profile</param>
/// <param name="openNewTab">Whether to launch the profile in a new tab</param>
public static string GetArguments(string profileName, bool openNewTab)
/// <param name="openQuake">Whether to launch the profile in the quake window</param>
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}\"";
}
/// <summary>

View File

@ -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<string, BitmapImage> _logoCache = new Dictionary<string, BitmapImage>();
@ -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;
}

View File

@ -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 {
}
}
/// <summary>
/// Looks up a localized string similar to Open profiles in the quake window.
/// </summary>
internal static string open_quake {
get {
return ResourceManager.GetString("open_quake", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Windows Terminal supports a &quot;quake&quot; feature where a terminal window is accessible using a global hotkey. Enable this option to open profiles in this window..
/// </summary>
internal static string open_quake_description {
get {
return ResourceManager.GetString("open_quake_description", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Open Windows Terminal profiles..
/// </summary>

View File

@ -120,6 +120,14 @@
<data name="open_new_tab" xml:space="preserve">
<value>Open profiles in a new tab</value>
</data>
<data name="open_quake" xml:space="preserve">
<value>Open profiles in the quake window</value>
<comment>Quake is a well-known computer game. Don't localize. See https://en.wikipedia.org/wiki/Quake_(video_game)</comment>
</data>
<data name="open_quake_description" xml:space="preserve">
<value>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.</value>
<comment>Quake is a well-known computer game. Don't localize. See https://en.wikipedia.org/wiki/Quake_(video_game)</comment>
</data>
<data name="plugin_description" xml:space="preserve">
<value>Open Windows Terminal profiles.</value>
</data>
@ -135,4 +143,4 @@
<data name="show_hidden_profiles" xml:space="preserve">
<value>Show hidden profiles</value>
</data>
</root>
</root>