2021-07-15 16:34:27 +02:00
|
|
|
// Copyright (c) Microsoft Corporation
|
2020-08-05 14:06:55 -07:00
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
2020-07-20 11:22:03 -07:00
|
|
|
using System.Windows.Input;
|
2020-08-05 14:06:55 -07:00
|
|
|
using Microsoft.PowerLauncher.Telemetry;
|
|
|
|
|
using Microsoft.PowerToys.Telemetry;
|
2020-07-20 11:22:03 -07:00
|
|
|
using Wox.Plugin;
|
|
|
|
|
|
|
|
|
|
namespace PowerLauncher.ViewModel
|
|
|
|
|
{
|
|
|
|
|
public class ContextMenuItemViewModel : BaseModel
|
|
|
|
|
{
|
|
|
|
|
private ICommand _command;
|
|
|
|
|
|
2021-07-15 16:34:27 +02:00
|
|
|
public string PluginName { get; }
|
2020-08-05 14:06:55 -07:00
|
|
|
|
2021-07-15 16:34:27 +02:00
|
|
|
public string Title { get; }
|
2020-08-05 14:06:55 -07:00
|
|
|
|
2021-07-15 16:34:27 +02:00
|
|
|
public string Glyph { get; }
|
2021-01-20 11:23:56 +02:00
|
|
|
|
2021-07-15 16:34:27 +02:00
|
|
|
public string FontFamily { get; }
|
2020-08-05 14:06:55 -07:00
|
|
|
|
2020-07-22 13:27:17 -07:00
|
|
|
public ICommand Command
|
|
|
|
|
{
|
2020-07-20 11:22:03 -07:00
|
|
|
get
|
|
|
|
|
{
|
2020-08-14 09:22:24 -07:00
|
|
|
return _command;
|
2020-07-20 11:22:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
// ICommand does not implement the INotifyPropertyChanged interface and must call OnPropertyChanged() to prevent memory leaks
|
2020-08-14 09:22:24 -07:00
|
|
|
if (value != _command)
|
2020-07-20 11:22:03 -07:00
|
|
|
{
|
2020-08-14 09:22:24 -07:00
|
|
|
_command = value;
|
2020-07-20 11:22:03 -07:00
|
|
|
OnPropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-15 16:34:27 +02:00
|
|
|
public Key AcceleratorKey { get; }
|
2020-08-05 14:06:55 -07:00
|
|
|
|
2021-07-15 16:34:27 +02:00
|
|
|
public ModifierKeys AcceleratorModifiers { get; }
|
2020-08-05 14:06:55 -07:00
|
|
|
|
2020-07-20 11:22:03 -07:00
|
|
|
public bool IsAcceleratorKeyEnabled { get; set; }
|
|
|
|
|
|
2021-07-15 16:34:27 +02:00
|
|
|
public ContextMenuItemViewModel(string pluginName, string title, string glyph, string fontFamily, Key acceleratorKey, ModifierKeys acceleratorModifiers, ICommand command)
|
|
|
|
|
{
|
|
|
|
|
PluginName = pluginName;
|
|
|
|
|
Title = title;
|
|
|
|
|
Glyph = glyph;
|
|
|
|
|
FontFamily = fontFamily;
|
|
|
|
|
Command = command;
|
|
|
|
|
AcceleratorKey = acceleratorKey;
|
|
|
|
|
AcceleratorModifiers = acceleratorModifiers;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-20 11:22:03 -07:00
|
|
|
public void SendTelemetryEvent(LauncherResultActionEvent.TriggerType triggerType)
|
|
|
|
|
{
|
|
|
|
|
var eventData = new LauncherResultActionEvent()
|
|
|
|
|
{
|
|
|
|
|
PluginName = PluginName,
|
|
|
|
|
Trigger = triggerType.ToString(),
|
2020-08-13 15:32:12 -07:00
|
|
|
ActionName = Title,
|
2020-07-20 11:22:03 -07:00
|
|
|
};
|
|
|
|
|
PowerToysTelemetry.Log.WriteEvent(eventData);
|
|
|
|
|
}
|
2020-09-02 13:34:07 -07:00
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return Title;
|
|
|
|
|
}
|
2020-07-20 11:22:03 -07:00
|
|
|
}
|
2020-08-05 14:06:55 -07:00
|
|
|
}
|