mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 03:36:44 +02:00
Refactoring ContextMenu
1. Remove ItemDropEvent 2. Remove ShowContextMenus from API 3. Fix context menu item can't be opened ( #535 ), bug introduced from PR #494 (commit 45dbb50) 4. Move open result command and load context menu command back to MainViewModel 5. unify load context menu logic 6. other performance enhancement and potential bug fixed
This commit is contained in:
@@ -22,7 +22,6 @@ namespace Wox.Plugin.Folder
|
||||
{
|
||||
this.context = context;
|
||||
this.context.API.BackKeyDownEvent += ApiBackKeyDownEvent;
|
||||
this.context.API.ResultItemDropEvent += ResultDropEvent;
|
||||
InitialDriverList();
|
||||
if (FolderStorage.Instance.FolderLinks == null)
|
||||
{
|
||||
@@ -31,38 +30,6 @@ namespace Wox.Plugin.Folder
|
||||
}
|
||||
}
|
||||
|
||||
void ResultDropEvent(Result result, IDataObject dropObject, DragEventArgs e)
|
||||
{
|
||||
if (dropObject.GetDataPresent(DataFormats.FileDrop))
|
||||
{
|
||||
HanldeFilesDrop(result, dropObject);
|
||||
}
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void HanldeFilesDrop(Result targetResult, IDataObject dropObject)
|
||||
{
|
||||
List<string> files = ((string[])dropObject.GetData(DataFormats.FileDrop, false)).ToList();
|
||||
context.API.ShowContextMenu(context.CurrentPluginMetadata, GetContextMenusForFileDrop(targetResult, files));
|
||||
}
|
||||
|
||||
private static List<Result> GetContextMenusForFileDrop(Result targetResult, List<string> files)
|
||||
{
|
||||
List<Result> contextMenus = new List<Result>();
|
||||
string folderPath = ((FolderLink) targetResult.ContextData).Path;
|
||||
contextMenus.Add(new Result
|
||||
{
|
||||
Title = "Copy to this folder",
|
||||
IcoPath = "Images/copy.png",
|
||||
Action = _ =>
|
||||
{
|
||||
MessageBox.Show("Copy");
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return contextMenus;
|
||||
}
|
||||
|
||||
private void ApiBackKeyDownEvent(WoxKeyDownEventArgs e)
|
||||
{
|
||||
string query = e.Query;
|
||||
|
||||
@@ -61,7 +61,6 @@ namespace Wox.Plugin.Program
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
this.context = context;
|
||||
this.context.API.ResultItemDropEvent += ResultDropEvent;
|
||||
Stopwatch.Debug("Preload programs", () =>
|
||||
{
|
||||
programs = ProgramCacheStorage.Instance.Programs;
|
||||
@@ -70,12 +69,6 @@ namespace Wox.Plugin.Program
|
||||
Stopwatch.Debug("Program Index", IndexPrograms);
|
||||
}
|
||||
|
||||
void ResultDropEvent(Result result, IDataObject dropObject, DragEventArgs e)
|
||||
{
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
public static void IndexPrograms()
|
||||
{
|
||||
lock (lockObject)
|
||||
|
||||
Reference in New Issue
Block a user