mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +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:
@@ -1,4 +1,5 @@
|
||||
using Wox.Core.Plugin;
|
||||
using System;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Hotkey;
|
||||
@@ -22,41 +23,6 @@ namespace Wox.ViewModel
|
||||
if (result != null)
|
||||
{
|
||||
RawResult = result;
|
||||
|
||||
OpenResultListBoxItemCommand = new RelayCommand(_ =>
|
||||
{
|
||||
|
||||
bool hideWindow = result.Action(new ActionContext
|
||||
{
|
||||
SpecialKeyState = GlobalHotkey.Instance.CheckModifiers()
|
||||
});
|
||||
|
||||
if (hideWindow)
|
||||
{
|
||||
App.API.HideApp();
|
||||
UserSelectedRecordStorage.Instance.Add(RawResult);
|
||||
QueryHistoryStorage.Instance.Add(RawResult.OriginQuery.RawQuery);
|
||||
}
|
||||
});
|
||||
|
||||
OpenContextMenuItemCommand = new RelayCommand(_ =>
|
||||
{
|
||||
|
||||
var actions = PluginManager.GetContextMenusForPlugin(result);
|
||||
|
||||
var pluginMetaData = PluginManager.GetPluginForId(result.PluginID).Metadata;
|
||||
actions.ForEach(o =>
|
||||
{
|
||||
o.PluginDirectory = pluginMetaData.PluginDirectory;
|
||||
o.PluginID = result.PluginID;
|
||||
o.OriginQuery = result.OriginQuery;
|
||||
});
|
||||
|
||||
actions.Add(GetTopMostContextMenu(result));
|
||||
|
||||
App.API.ShowContextMenu(pluginMetaData, actions);
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,51 +47,12 @@ namespace Wox.ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
public RelayCommand OpenResultListBoxItemCommand { get; set; }
|
||||
|
||||
public RelayCommand OpenContextMenuItemCommand { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public Result RawResult { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private Result GetTopMostContextMenu(Result result)
|
||||
{
|
||||
if (TopMostRecordStorage.Instance.IsTopMost(result))
|
||||
{
|
||||
return new Result(InternationalizationManager.Instance.GetTranslation("cancelTopMostInThisQuery"), "Images\\down.png")
|
||||
{
|
||||
PluginDirectory = WoxDirectroy.Executable,
|
||||
Action = _ =>
|
||||
{
|
||||
TopMostRecordStorage.Instance.Remove(result);
|
||||
App.API.ShowMsg("Succeed");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Result(InternationalizationManager.Instance.GetTranslation("setAsTopMostInThisQuery"), "Images\\up.png")
|
||||
{
|
||||
PluginDirectory = WoxDirectroy.Executable,
|
||||
Action = _ =>
|
||||
{
|
||||
TopMostRecordStorage.Instance.AddOrUpdate(result);
|
||||
App.API.ShowMsg("Succeed");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
public override bool Equals(object obj)
|
||||
|
||||
Reference in New Issue
Block a user