mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
Fixes race conditions with PointerEnter/Exit events conflicting with Selection and unselection. This change provides better encapsulation of the logic to enable a selected item for accelerator (hotkey) events, and allow mouse input on results where the pointer is over.
This commit is contained in:
@@ -12,6 +12,6 @@ namespace Wox.ViewModel
|
||||
public ICommand Command { get; set; }
|
||||
public string AcceleratorKey { get; set; }
|
||||
public string AcceleratorModifiers { get; set; }
|
||||
public bool IsEnabled { get; set; }
|
||||
public bool IsAcceleratorKeyEnabled { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -17,12 +17,24 @@ namespace Wox.ViewModel
|
||||
{
|
||||
public class ResultViewModel : BaseModel
|
||||
{
|
||||
public enum ActivationType
|
||||
{
|
||||
Selection,
|
||||
Hover
|
||||
};
|
||||
|
||||
public List<ContextMenuItemViewModel> ContextMenuItems { get; set; }
|
||||
|
||||
public ICommand LoadContextMenuCommand { get; set; }
|
||||
public ICommand ActivateContextButtonsHoverCommand { get; set; }
|
||||
public ICommand ActivateContextButtonsSelectionCommand { get; set; }
|
||||
public ICommand DeactivateContextButtonsHoverCommand { get; set; }
|
||||
|
||||
public ICommand DeactivateContextButtonsSelectionCommand { get; set; }
|
||||
|
||||
public bool IsSelected { get; set; }
|
||||
|
||||
public bool AreContextButtonsActive { get; set; }
|
||||
|
||||
public int ContextMenuSelectedIndex { get; set; }
|
||||
|
||||
const int NoSelectionIndex = -1;
|
||||
@@ -34,9 +46,62 @@ namespace Wox.ViewModel
|
||||
Result = result;
|
||||
}
|
||||
ContextMenuSelectedIndex = NoSelectionIndex;
|
||||
LoadContextMenuCommand = new RelayCommand(LoadContextMenu);
|
||||
ActivateContextButtonsHoverCommand = new RelayCommand(ActivateContextButtonsHoverAction);
|
||||
ActivateContextButtonsSelectionCommand = new RelayCommand(ActivateContextButtonsSelectionAction);
|
||||
DeactivateContextButtonsHoverCommand = new RelayCommand(DeactivateContextButtonsHoverAction);
|
||||
DeactivateContextButtonsSelectionCommand = new RelayCommand(DeactivateContextButtonsSelectionAction);
|
||||
}
|
||||
public void LoadContextMenu(object sender=null)
|
||||
|
||||
private void ActivateContextButtonsHoverAction(object sender)
|
||||
{
|
||||
ActivateContextButtons(ActivationType.Hover);
|
||||
}
|
||||
|
||||
private void ActivateContextButtonsSelectionAction(object sender)
|
||||
{
|
||||
ActivateContextButtons(ActivationType.Selection);
|
||||
}
|
||||
public void ActivateContextButtons(ActivationType activationType)
|
||||
{
|
||||
|
||||
if (ContextMenuItems == null)
|
||||
{
|
||||
LoadContextMenu();
|
||||
}
|
||||
|
||||
AreContextButtonsActive = true;
|
||||
|
||||
if (activationType == ActivationType.Selection)
|
||||
{
|
||||
IsSelected = true;
|
||||
EnableContextMenuAcceleratorKeys();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void DeactivateContextButtonsHoverAction(object sender)
|
||||
{
|
||||
DeactivateContextButtons(ActivationType.Hover);
|
||||
}
|
||||
|
||||
private void DeactivateContextButtonsSelectionAction(object sender)
|
||||
{
|
||||
DeactivateContextButtons(ActivationType.Selection);
|
||||
}
|
||||
|
||||
public void DeactivateContextButtons(ActivationType activationType)
|
||||
{
|
||||
AreContextButtonsActive = false;
|
||||
|
||||
if (activationType == ActivationType.Selection)
|
||||
{
|
||||
IsSelected = false;
|
||||
DisableContextMenuAcceleratorkeys();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void LoadContextMenu()
|
||||
{
|
||||
var results = PluginManager.GetContextMenusForPlugin(Result);
|
||||
var newItems = new List<ContextMenuItemViewModel>();
|
||||
@@ -68,19 +133,19 @@ namespace Wox.ViewModel
|
||||
ContextMenuItems = newItems;
|
||||
}
|
||||
|
||||
internal void EnableContextMenu()
|
||||
private void EnableContextMenuAcceleratorKeys()
|
||||
{
|
||||
foreach(var i in ContextMenuItems)
|
||||
{
|
||||
i.IsEnabled = true;
|
||||
i.IsAcceleratorKeyEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
internal void DisableContextMenu()
|
||||
private void DisableContextMenuAcceleratorkeys()
|
||||
{
|
||||
foreach (var i in ContextMenuItems)
|
||||
{
|
||||
i.IsEnabled = false;
|
||||
i.IsAcceleratorKeyEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,14 +59,11 @@ namespace Wox.ViewModel
|
||||
{
|
||||
if (_selectedItem != null)
|
||||
{
|
||||
_selectedItem.IsSelected = false;
|
||||
_selectedItem.DisableContextMenu();
|
||||
_selectedItem.DeactivateContextButtons(ResultViewModel.ActivationType.Selection);
|
||||
}
|
||||
|
||||
_selectedItem = value;
|
||||
_selectedItem.LoadContextMenu();
|
||||
_selectedItem.EnableContextMenu();
|
||||
_selectedItem.IsSelected = true;
|
||||
_selectedItem.ActivateContextButtons(ResultViewModel.ActivationType.Selection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user