ContextMenuItemViewModel.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.Windows.Input; 6 7 using Microsoft.PowerLauncher.Telemetry; 8 using Microsoft.PowerToys.Telemetry; 9 using Wox.Plugin; 10 11 namespace PowerLauncher.ViewModel 12 { 13 public class ContextMenuItemViewModel : BaseModel 14 { 15 private ICommand _command; 16 17 public string PluginName { get; } 18 19 public string Title { get; } 20 21 public string Glyph { get; } 22 23 public string FontFamily { get; } 24 25 public ICommand Command 26 { 27 get 28 { 29 return _command; 30 } 31 32 set 33 { 34 // ICommand does not implement the INotifyPropertyChanged interface and must call OnPropertyChanged() to prevent memory leaks 35 if (value != _command) 36 { 37 _command = value; 38 OnPropertyChanged(); 39 } 40 } 41 } 42 43 public Key AcceleratorKey { get; } 44 45 public ModifierKeys AcceleratorModifiers { get; } 46 47 public bool IsAcceleratorKeyEnabled { get; set; } 48 49 public ContextMenuItemViewModel(string pluginName, string title, string glyph, string fontFamily, Key acceleratorKey, ModifierKeys acceleratorModifiers, ICommand command) 50 { 51 PluginName = pluginName; 52 Title = title; 53 Glyph = glyph; 54 FontFamily = fontFamily; 55 Command = command; 56 AcceleratorKey = acceleratorKey; 57 AcceleratorModifiers = acceleratorModifiers; 58 } 59 60 public void SendTelemetryEvent(LauncherResultActionEvent.TriggerType triggerType) 61 { 62 var eventData = new LauncherResultActionEvent() 63 { 64 PluginName = PluginName, 65 Trigger = triggerType.ToString(), 66 ActionName = Title, 67 }; 68 PowerToysTelemetry.Log.WriteEvent(eventData); 69 } 70 71 public override string ToString() 72 { 73 return Title; 74 } 75 } 76 }