mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
Add option to open in tab for WebSearch plugin
This commit is contained in:
@@ -74,7 +74,14 @@ namespace Wox.Plugin.WebSearch
|
|||||||
IcoPath = searchSource.IconPath,
|
IcoPath = searchSource.IconPath,
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)).NewBrowserWindow("");
|
if (_settings.OpenInNewBrowser)
|
||||||
|
{
|
||||||
|
searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)).NewBrowserWindow("");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)).NewTabInBrowser("");
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -132,7 +139,15 @@ namespace Wox.Plugin.WebSearch
|
|||||||
IcoPath = searchSource.IconPath,
|
IcoPath = searchSource.IconPath,
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)).NewBrowserWindow("");
|
if (_settings.OpenInNewBrowser)
|
||||||
|
{
|
||||||
|
searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)).NewBrowserWindow("");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)).NewTabInBrowser("");
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -219,5 +219,7 @@ namespace Wox.Plugin.WebSearch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool OpenInNewBrowser { get; set; } = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,8 @@ namespace Wox.Plugin.SharedCommands
|
|||||||
{
|
{
|
||||||
public static class SearchWeb
|
public static class SearchWeb
|
||||||
{
|
{
|
||||||
/// <summary> Opens search in a new browser. If no browser path is passed in then Chrome is used.
|
/// <summary>
|
||||||
|
/// Opens search in a new browser. If no browser path is passed in then Chrome is used.
|
||||||
/// Leave browser path blank to use Chrome.
|
/// Leave browser path blank to use Chrome.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void NewBrowserWindow(this string url, string browserPath)
|
public static void NewBrowserWindow(this string url, string browserPath)
|
||||||
@@ -19,11 +20,30 @@ namespace Wox.Plugin.SharedCommands
|
|||||||
var browser = string.IsNullOrEmpty(browserExecutableName) ? "chrome" : browserPath;
|
var browser = string.IsNullOrEmpty(browserExecutableName) ? "chrome" : browserPath;
|
||||||
|
|
||||||
// Internet Explorer will open url in new browser window, and does not take the --new-window parameter
|
// Internet Explorer will open url in new browser window, and does not take the --new-window parameter
|
||||||
var browserArguements = browserExecutableName == "iexplore.exe" ? url : "--new-window " + url;
|
var browserArguements = browserExecutableName == "iexplore.exe" ? "" : "--new-window ";
|
||||||
|
|
||||||
|
OpenWebSearch(browser, browserArguements, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens search as a tab in the default browser chosen in Windows settings.
|
||||||
|
/// </summary>
|
||||||
|
public static void NewTabInBrowser(this string url, string browserPath)
|
||||||
|
{
|
||||||
|
var browserExecutableName = browserPath?
|
||||||
|
.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None)
|
||||||
|
.Last();
|
||||||
|
|
||||||
|
var browser = string.IsNullOrEmpty(browserExecutableName) ? "" : browserPath;
|
||||||
|
|
||||||
|
OpenWebSearch(browser, "", url);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OpenWebSearch(string chosenBrowser, string browserArguements, string url)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Process.Start(browser, browserArguements);
|
Process.Start(chosenBrowser, browserArguements + url);
|
||||||
}
|
}
|
||||||
catch (System.ComponentModel.Win32Exception)
|
catch (System.ComponentModel.Win32Exception)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user