Added the inotifyPropertyChanged to all the properties and that stops the memory for shooting up

This commit is contained in:
Alekhya Reddy 2020-06-29 19:36:13 -07:00
parent 0dd17cc175
commit 25015df212
2 changed files with 132 additions and 20 deletions

View File

@ -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; }

View File

@ -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++;