示例#1
0
        private void AddMenuItem()
        {
            IAIMPMenuItem menuItem   = null;
            IAIMPAction   action     = null;
            IAIMPString   actionName = null;
            IAIMPString   id         = null;
            IAIMPString   groupName  = null;
            IAIMPMenuItem parentMenu = null;

            try
            {
                menuItem = Core.CreateObject <IAIMPMenuItem>();
                action   = Core.CreateObject <IAIMPAction>();

                actionName = Core.CreateString("Lyrics");
                action.SetProperty(AIMPActionPropId.Name, actionName);

                id = Core.CreateString("aimp.lyrics.open.window");
                action.SetProperty(AIMPActionPropId.Id, id);

                groupName = Core.CreateString("Lyrics Plugin");
                action.SetProperty(AIMPActionPropId.GroupName, groupName);

                var actionManager = Core.GetService <IAIMPServiceActionManager>();

                int hotkey = actionManager.MakeHotkey(AIMPActionHotKeyModifiers.Shift, (ushort)Keys.L);
                action.SetValueAsInt32((int)AIMPActionPropId.DefaultLocalHotKey, hotkey);

                int globalHotkey = actionManager.MakeHotkey(AIMPActionHotKeyModifiers.Ctrl | AIMPActionHotKeyModifiers.Alt, (ushort)Keys.L);
                action.SetValueAsInt32((int)AIMPActionPropId.DefaultGlobalHotKey, globalHotkey);

                var actionEvent = new AimpActionEvent();
                actionEvent.Execute += (data) => ShowLyricsWindow();
                action.SetProperty(AIMPActionPropId.Event, actionEvent);

                menuItem.SetValueAsObject(AIMPMenuItemPropId.Action, action);

                var menuManager = Core.GetService <IAIMPServiceMenuManager>();
                parentMenu = menuManager.GetBuiltIn(AIMPBuildInMenu.CommonUtilities);
                menuItem.SetValueAsObject(AIMPMenuItemPropId.Parent, parentMenu);

                menuItem.SetValueAsInt32(AIMPMenuItemPropId.Shortcut, hotkey);

                Core.RegisterExtension <IAIMPServiceActionManager>(action);
                Core.RegisterExtension <IAIMPServiceMenuManager>(menuItem);
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"Cannot create menu item: {ex}");
                throw;
            }
            finally
            {
                menuItem?.ReleaseComObject();
                action?.ReleaseComObject();
                actionName?.ReleaseComObject();
                id?.ReleaseComObject();
                groupName?.ReleaseComObject();
                parentMenu?.ReleaseComObject();
            }
        }
示例#2
0
 public static void SetProperty(this IAIMPAction action, AIMPActionPropId propId, object value)
 {
     action.SetValueAsObject((int)propId, value);
 }