mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 06:29:44 +08:00
Added the inotifyPropertyChanged to all the properties and that stops the memory for shooting up
This commit is contained in:
parent
0dd17cc175
commit
25015df212
@ -10,10 +10,72 @@ namespace Wox.ViewModel
|
||||
public class ContextMenuItemViewModel : BaseModel
|
||||
{
|
||||
public string PluginName { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Glyph { get; set; }
|
||||
public string FontFamily { get; set; }
|
||||
public ICommand Command { get; set; }
|
||||
|
||||
private string title;
|
||||
private string glyph;
|
||||
private string fontfamily;
|
||||
private ICommand command;
|
||||
|
||||
public string Title {
|
||||
get
|
||||
{
|
||||
return this.title;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != this.title)
|
||||
{
|
||||
this.title = value;
|
||||
OnPropertyChanged("Title");
|
||||
}
|
||||
}
|
||||
}
|
||||
public string Glyph {
|
||||
get
|
||||
{
|
||||
return this.glyph;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != this.glyph)
|
||||
{
|
||||
this.glyph = value;
|
||||
OnPropertyChanged("Glyph");
|
||||
}
|
||||
}
|
||||
}
|
||||
public string FontFamily {
|
||||
get
|
||||
{
|
||||
return this.fontfamily;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != this.fontfamily)
|
||||
{
|
||||
this.fontfamily = value;
|
||||
OnPropertyChanged("FontFamily");
|
||||
}
|
||||
}
|
||||
}
|
||||
public ICommand Command {
|
||||
get
|
||||
{
|
||||
return this.command;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != this.command)
|
||||
{
|
||||
this.command = value;
|
||||
OnPropertyChanged("Command");
|
||||
}
|
||||
}
|
||||
}
|
||||
public Key AcceleratorKey { get; set; }
|
||||
public ModifierKeys AcceleratorModifiers { get; set; }
|
||||
public bool IsAcceleratorKeyEnabled { get; set; }
|
||||
|
@ -22,7 +22,24 @@ namespace Wox.ViewModel
|
||||
Hover
|
||||
};
|
||||
|
||||
public List<ContextMenuItemViewModel> ContextMenuItems { get; set; }
|
||||
private List<ContextMenuItemViewModel> _items = new List<ContextMenuItemViewModel>();
|
||||
|
||||
public List<ContextMenuItemViewModel> ContextMenuItems
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._items;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != this._items)
|
||||
{
|
||||
this._items = value;
|
||||
OnPropertyChanged("ContextMenuItems");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand ActivateContextButtonsHoverCommand { get; set; }
|
||||
public ICommand ActivateContextButtonsSelectionCommand { get; set; }
|
||||
@ -34,9 +51,41 @@ namespace Wox.ViewModel
|
||||
|
||||
public bool IsHovered { get; set; }
|
||||
|
||||
public bool AreContextButtonsActive { get; set; }
|
||||
private bool areContextButtonsActive;
|
||||
public bool AreContextButtonsActive
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.areContextButtonsActive;
|
||||
}
|
||||
|
||||
public int ContextMenuSelectedIndex { get; set; }
|
||||
set
|
||||
{
|
||||
if (value != this.areContextButtonsActive)
|
||||
{
|
||||
this.areContextButtonsActive = value;
|
||||
OnPropertyChanged("AreContextButtonsActive");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int contextMenuSelectedIndex;
|
||||
|
||||
public int ContextMenuSelectedIndex {
|
||||
get
|
||||
{
|
||||
return this.contextMenuSelectedIndex;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != this.contextMenuSelectedIndex)
|
||||
{
|
||||
this.contextMenuSelectedIndex = value;
|
||||
OnPropertyChanged("ContextMenuSelectedIndex");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const int NoSelectionIndex = -1;
|
||||
|
||||
@ -46,7 +95,11 @@ namespace Wox.ViewModel
|
||||
{
|
||||
Result = result;
|
||||
}
|
||||
|
||||
ContextMenuSelectedIndex = NoSelectionIndex;
|
||||
ContextMenuItems = LoadContextMenu();
|
||||
AreContextButtonsActive = false;
|
||||
|
||||
ActivateContextButtonsHoverCommand = new RelayCommand(ActivateContextButtonsHoverAction);
|
||||
ActivateContextButtonsSelectionCommand = new RelayCommand(ActivateContextButtonsSelectionAction);
|
||||
DeactivateContextButtonsHoverCommand = new RelayCommand(DeactivateContextButtonsHoverAction);
|
||||
@ -64,10 +117,7 @@ namespace Wox.ViewModel
|
||||
}
|
||||
public void ActivateContextButtons(ActivationType activationType)
|
||||
{
|
||||
if (ContextMenuItems == null)
|
||||
{
|
||||
LoadContextMenu();
|
||||
}
|
||||
|
||||
|
||||
// Result does not contain any context menu items - we don't need to show the context menu ListView at all.
|
||||
if (ContextMenuItems.Count > 0)
|
||||
@ -78,14 +128,14 @@ namespace Wox.ViewModel
|
||||
{
|
||||
AreContextButtonsActive = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (activationType == ActivationType.Selection)
|
||||
{
|
||||
IsSelected = true;
|
||||
EnableContextMenuAcceleratorKeys();
|
||||
}
|
||||
else if(activationType == ActivationType.Hover)
|
||||
else if (activationType == ActivationType.Hover)
|
||||
{
|
||||
IsHovered = true;
|
||||
}
|
||||
@ -122,11 +172,11 @@ namespace Wox.ViewModel
|
||||
else
|
||||
{
|
||||
AreContextButtonsActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void LoadContextMenu()
|
||||
public List<ContextMenuItemViewModel> LoadContextMenu()
|
||||
{
|
||||
var results = PluginManager.GetContextMenusForPlugin(Result);
|
||||
var newItems = new List<ContextMenuItemViewModel>();
|
||||
@ -156,12 +206,12 @@ namespace Wox.ViewModel
|
||||
});
|
||||
}
|
||||
|
||||
ContextMenuItems = newItems;
|
||||
return newItems;
|
||||
}
|
||||
|
||||
private void EnableContextMenuAcceleratorKeys()
|
||||
{
|
||||
foreach(var i in ContextMenuItems)
|
||||
foreach (var i in ContextMenuItems)
|
||||
{
|
||||
i.IsAcceleratorKeyEnabled = true;
|
||||
}
|
||||
@ -192,7 +242,7 @@ namespace Wox.ViewModel
|
||||
imagePath = ImageLoader.ErrorIconPath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// will get here either when icoPath has value\icon delegate is null\when had exception in delegate
|
||||
return ImageLoader.Load(imagePath);
|
||||
}
|
||||
@ -201,10 +251,10 @@ namespace Wox.ViewModel
|
||||
//Returns false if we've already reached the last item.
|
||||
public bool SelectNextContextButton()
|
||||
{
|
||||
if(ContextMenuSelectedIndex == (ContextMenuItems.Count -1))
|
||||
if (ContextMenuSelectedIndex == (ContextMenuItems.Count - 1))
|
||||
{
|
||||
ContextMenuSelectedIndex = NoSelectionIndex;
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
ContextMenuSelectedIndex++;
|
||||
|
Loading…
Reference in New Issue
Block a user