mirror of
https://github.com/microsoft/PowerToys
synced 2025-08-31 06:25:20 +00:00
[Pt Run] Show context menu for first folder plugin result (#6301)
* Added context menu to first folder result * Added context menu to first folder result * Add localization for string in folder plugin * Fixed issue with context menu not showing on first selected item * Add exception logging
This commit is contained in:
committed by
GitHub
parent
726f94e2a2
commit
a0eaf077de
@@ -11,8 +11,12 @@ using System.Linq;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Media;
|
||||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||||
|
using Microsoft.VisualBasic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
|
using Wox.Infrastructure.Logger;
|
||||||
using Wox.Infrastructure.Storage;
|
using Wox.Infrastructure.Storage;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
|
|
||||||
@@ -106,6 +110,23 @@ namespace Microsoft.Plugin.Folder
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alive and instead inform the user of the error")]
|
||||||
|
private static bool OpenFileOrFolder(string program, string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Process.Start(program, path);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
string messageBoxTitle = string.Format(CultureInfo.InvariantCulture, "{0} {1}", Properties.Resources.wox_plugin_folder_select_folder_OpenFileOrFolder_error_message, path);
|
||||||
|
Log.Exception($"|Microsoft.Plugin.Folder.Main.OpenFileOrFolder| Failed to open {path} in explorer, {e.Message}", e);
|
||||||
|
_context.API.ShowMsg(messageBoxTitle, e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private static bool IsDriveOrSharedFolder(string search)
|
private static bool IsDriveOrSharedFolder(string search)
|
||||||
{
|
{
|
||||||
if (search == null)
|
if (search == null)
|
||||||
@@ -137,14 +158,13 @@ namespace Microsoft.Plugin.Folder
|
|||||||
{
|
{
|
||||||
Title = title,
|
Title = title,
|
||||||
IcoPath = path,
|
IcoPath = path,
|
||||||
SubTitle = "Folder: " + subtitle,
|
SubTitle = string.Format(CultureInfo.InvariantCulture, "{0}: {1}", Properties.Resources.wox_plugin_folder_plugin_name, subtitle),
|
||||||
QueryTextDisplay = path,
|
QueryTextDisplay = path,
|
||||||
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData,
|
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData,
|
||||||
ContextData = new SearchResult { Type = ResultType.Folder, FullPath = path },
|
ContextData = new SearchResult { Type = ResultType.Folder, FullPath = path },
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
Process.Start(_fileExplorerProgramName, path);
|
return OpenFileOrFolder(_fileExplorerProgramName, path);
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -297,37 +317,26 @@ namespace Microsoft.Plugin.Folder
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alve and instead inform the user of the error")]
|
|
||||||
private static Result CreateFileResult(string filePath, Query query)
|
private static Result CreateFileResult(string filePath, Query query)
|
||||||
{
|
{
|
||||||
var result = new Result
|
var result = new Result
|
||||||
{
|
{
|
||||||
Title = Path.GetFileName(filePath),
|
Title = Path.GetFileName(filePath),
|
||||||
SubTitle = "Folder: " + filePath,
|
SubTitle = string.Format(CultureInfo.InvariantCulture, "{0}: {1}", Properties.Resources.wox_plugin_folder_plugin_name, filePath),
|
||||||
IcoPath = filePath,
|
IcoPath = filePath,
|
||||||
|
ContextData = new SearchResult { Type = ResultType.File, FullPath = filePath },
|
||||||
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, Path.GetFileName(filePath)).MatchData,
|
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, Path.GetFileName(filePath)).MatchData,
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
try
|
return OpenFileOrFolder(_fileExplorerProgramName, filePath);
|
||||||
{
|
|
||||||
Process.Start(_fileExplorerProgramName, filePath);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Could not start " + filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
ContextData = new SearchResult { Type = ResultType.File, FullPath = filePath },
|
|
||||||
};
|
};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Result CreateOpenCurrentFolderResult(string search)
|
private static Result CreateOpenCurrentFolderResult(string search)
|
||||||
{
|
{
|
||||||
var firstResult = "Open " + search;
|
var firstResult = string.Format(CultureInfo.InvariantCulture, "{0} {1}", Properties.Resources.wox_plugin_folder_select_folder_first_result_title, search);
|
||||||
|
|
||||||
var folderName = search.TrimEnd('\\').Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None).Last();
|
var folderName = search.TrimEnd('\\').Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None).Last();
|
||||||
var sanitizedPath = Regex.Replace(search, @"[\/\\]+", "\\");
|
var sanitizedPath = Regex.Replace(search, @"[\/\\]+", "\\");
|
||||||
|
|
||||||
@@ -341,13 +350,13 @@ namespace Microsoft.Plugin.Folder
|
|||||||
{
|
{
|
||||||
Title = firstResult,
|
Title = firstResult,
|
||||||
QueryTextDisplay = search,
|
QueryTextDisplay = search,
|
||||||
SubTitle = $"Folder: Use > to search within the directory. Use * to search for file extensions. Or use both >*.",
|
SubTitle = string.Format(CultureInfo.InvariantCulture, "{0}: {1}", Properties.Resources.wox_plugin_folder_plugin_name, Properties.Resources.wox_plugin_folder_select_folder_first_result_subtitle),
|
||||||
IcoPath = search,
|
IcoPath = search,
|
||||||
Score = 500,
|
Score = 500,
|
||||||
|
ContextData = new SearchResult { Type = ResultType.Folder, FullPath = search },
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
Process.Start(_fileExplorerProgramName, sanitizedPath);
|
return OpenFileOrFolder(_fileExplorerProgramName, search);
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -177,6 +177,24 @@ namespace Microsoft.Plugin.Folder.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Use > to search within the directory. Use * to search for file extensions. Or use both >*.
|
||||||
|
/// </summary>
|
||||||
|
public static string wox_plugin_folder_select_folder_first_result_subtitle {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("wox_plugin_folder_select_folder_first_result_subtitle", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Open.
|
||||||
|
/// </summary>
|
||||||
|
public static string wox_plugin_folder_select_folder_first_result_title {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("wox_plugin_folder_select_folder_first_result_title", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Please select a folder link.
|
/// Looks up a localized string similar to Please select a folder link.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -185,5 +203,14 @@ namespace Microsoft.Plugin.Folder.Properties {
|
|||||||
return ResourceManager.GetString("wox_plugin_folder_select_folder_link_warning", resourceCulture);
|
return ResourceManager.GetString("wox_plugin_folder_select_folder_link_warning", resourceCulture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Could not start.
|
||||||
|
/// </summary>
|
||||||
|
public static string wox_plugin_folder_select_folder_OpenFileOrFolder_error_message {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("wox_plugin_folder_select_folder_OpenFileOrFolder_error_message", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -159,4 +159,13 @@
|
|||||||
<data name="Microsoft_plugin_folder_clipboard_failed" xml:space="preserve">
|
<data name="Microsoft_plugin_folder_clipboard_failed" xml:space="preserve">
|
||||||
<value>Fail to set text in clipboard</value>
|
<value>Fail to set text in clipboard</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="wox_plugin_folder_select_folder_first_result_subtitle" xml:space="preserve">
|
||||||
|
<value>Use > to search within the directory. Use * to search for file extensions. Or use both >*</value>
|
||||||
|
</data>
|
||||||
|
<data name="wox_plugin_folder_select_folder_first_result_title" xml:space="preserve">
|
||||||
|
<value>Open</value>
|
||||||
|
</data>
|
||||||
|
<data name="wox_plugin_folder_select_folder_OpenFileOrFolder_error_message" xml:space="preserve">
|
||||||
|
<value>Could not start</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
@@ -75,6 +75,10 @@ namespace Wox
|
|||||||
|
|
||||||
public void ShowMsg(string title, string subTitle = "", string iconPath = "", bool useMainWindowAsOwner = true)
|
public void ShowMsg(string title, string subTitle = "", string iconPath = "", bool useMainWindowAsOwner = true)
|
||||||
{
|
{
|
||||||
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
|
{
|
||||||
|
MessageBox.Show(subTitle, title);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InstallPlugin(string path)
|
public void InstallPlugin(string path)
|
||||||
|
@@ -599,6 +599,7 @@ namespace PowerLauncher.ViewModel
|
|||||||
if (!isDelayedInvoke)
|
if (!isDelayedInvoke)
|
||||||
{
|
{
|
||||||
Results.SelectedIndex = 0;
|
Results.SelectedIndex = 0;
|
||||||
|
Results.SelectedItem = Results.Results[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user