private void RemoveMenuCommands()
        {
            // Add our command handlers for menu (commands must exist in the .vsct file)
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                mcs.RemoveCommand(_menuItem);
                mcs.RemoveCommand(_menuToolWin);
            }
        }
        private void RefreshReplCommands(object sender, EventArgs e)
        {
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (mcs == null)
            {
                return;
            }
            List <OpenReplCommand> replCommands = new List <OpenReplCommand>();

            lock (CommandsLock) {
                foreach (var keyValue in Commands)
                {
                    var             command  = keyValue.Key;
                    OpenReplCommand openRepl = command as OpenReplCommand;
                    if (openRepl != null)
                    {
                        replCommands.Add(openRepl);

                        mcs.RemoveCommand(keyValue.Value);
                    }
                }

                foreach (var command in replCommands)
                {
                    Commands.Remove(command);
                }

                RegisterCommands(GetReplCommands(), GuidList.guidPythonToolsCmdSet);
            }
        }
 private void RemoveCommand(MenuCommand commandItem)
 {
     if (commandService != null && commandItem != null && commandService.FindCommand(commandItem.CommandID) != null)
     {
         commandService.RemoveCommand(commandItem);
     }
 }
        /// <summary>
        /// Sets the visibility of the command and creates the dynamic list of commands
        /// </summary>
        /// <param name="sender">Sender of the event</param>
        /// <param name="e">Event arguments</param>
        private void SetVisibility(object sender, EventArgs e)
        {
            // gets the full path of the clicked file
            var path = SolutionHelpers.GetSourceFilePath();

            var myCommand = sender as OleMenuCommand;

            // if the currently selected file is a Gruntfile set the command to visible
            myCommand.Visible = this.IsGruntFile();


            if (!this.IsGruntFile() && !this.IsGulpFile())
            {
                this.lastFile = path;
            }

            if (!this.IsNewFile())
            {
                return;
            }



            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            // delete the old command list
            if (commands == null)
            {
                commands = new List <OleMenuCommand>();
            }

            foreach (var cmd in commands)
            {
                mcs.RemoveCommand(cmd);
            }

            if (myCommand.Visible)
            {
                this.lastFile = path;
                var list = GruntParser.ReadAllTasks(path);
                if (list.Contains("default"))
                {
                    list.Remove("default");
                }

                // creates the list of commands
                int j = 1;
                foreach (var ele in list)
                {
                    CommandID menuCommandID = new CommandID(GuidList.guidGruntLauncherCmdSet, (int)PkgCmdIDList.cmdidGruntLauncher + j);
                    j++;
                    OleMenuCommand command = new OleMenuCommand(this.MenuItemCallback, menuCommandID);
                    command.Text = "Grunt: " + ele;
                    command.BeforeQueryStatus += (x, y) => { (x as OleMenuCommand).Visible = true; };
                    commands.Add(command);
                    mcs.AddCommand(command);
                }
            }
        }
Beispiel #5
0
 public void Dispose()
 {
     if (commands.Count > 0)
     {
         foreach (var cmd in commands)
         {
             mcs.RemoveCommand(cmd);
         }
     }
 }
Beispiel #6
0
        public Task InitializeAsync()
        {
            OleMenuCommandService commandService = _serviceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (commandService == null)
            {
                _logger.WriteLine("OleMenuCommandService was not resolved");
                return(Task.CompletedTask);
            }

            var id = 1;

            foreach (var iconType in ExtensionCatalogue.IconTypes)
            {
                var names  = Enum.GetNames(iconType);
                var values = Enum.GetValues(iconType);

                for (var idx = 0; idx < names.Length; idx++)
                {
                    var cmdidMyDynamicStartCommand = id * 100;

                    var value = (int)values.GetValue(idx);
                    var icon  = new ExtensionMethodIcon(iconType, value);

                    CommandID dynamicItemRootId = new CommandID(guidDynamicCommandsSet.SetId, cmdidMyDynamicStartCommand);

                    var existing = commandService.FindCommand(dynamicItemRootId);
                    if (existing != null)
                    {
                        commandService.RemoveCommand(existing);
                    }

                    var matchingMethods = _extensionsCacheService.ExtensionsForIcon(icon);
                    if (matchingMethods.Any())
                    {
                        DynamicItemMenuCommand dynamicMenuCommand = new DynamicItemMenuCommand(
                            _extensionsCacheService,
                            _invocationService,
                            dynamicItemRootId,
                            cmdidMyDynamicStartCommand,
                            matchingMethods
                            )
                        {
                            Visible = false
                        };
                        commandService.AddCommand(dynamicMenuCommand);
                    }

                    id++;
                }
            }

            return(Task.CompletedTask);
        }
Beispiel #7
0
        /// <summary>
        /// create the list of tasks and replace the placeholder menu
        /// </summary>
        /// <param name="dir"></param>
        private void setupRakeTasksMenu(string dir)
        {
            try
            {
                List <RakeTask> tasks;
                //update if cache not exist
                if (!taskCache.ContainsKey(dir))
                {
                    updateCache(dir);
                }
                //get the tasks from the cache for the directory
                taskCache.TryGetValue(dir, out tasks);

                OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

                // Add our command handlers for menu (commands must exist in the .vsct file)
                if (null != mcs)
                {
                    //if there is any task in menu, remove them all.
                    foreach (var command in currentCommandsInMenu)
                    {
                        var cmdID = new CommandID(
                            GuidList.guidRakeRunnerCmdSet, command);
                        var menu = mcs.FindCommand(cmdID);
                        if (menu != null)
                        {
                            mcs.RemoveCommand(menu);
                        }
                    }
                    //clear the commands list
                    currentCommandsInMenu.Clear();

                    if (tasks != null)
                    {
                        //add the tasks
                        for (int i = 0; i < tasks.Count; i++)
                        {
                            int commandId = (int)PkgCmdIDList.icmdTasksList + i;
                            var cmdID     = new CommandID(
                                GuidList.guidRakeRunnerCmdSet, commandId);
                            var mc = new OleMenuCommand(RakeTaskSelected, cmdID);
                            mc.Text = tasks[i].Task;
                            mcs.AddCommand(mc);
                            //store the commandid so we can remove when re-creating the menu
                            currentCommandsInMenu.Add(commandId);
                        }
                    }
                    //var tasks = rakeService.GetRakeTasks()
                }
            }
            catch
            {
            }
        }
        private void InitializeCommands(OleMenuCommandService service)
        {
            if (service != null)
            {
                CommandID toolbarMenuCommandRefreshID = new CommandID(Guids.guidConfluenceToolbarMenu, Guids.COMMAND_REFRESH_ID);

                MenuCommand onToolbarMenuCommandRefreshClick = new MenuCommand(RefreshSpacesAsync, toolbarMenuCommandRefreshID);

                service.RemoveCommand(service.FindCommand(toolbarMenuCommandRefreshID));
                service.AddCommand(onToolbarMenuCommandRefreshClick);
            }
        }
Beispiel #9
0
 protected override void Close()
 {
     if (_menuService != null)
     {
         foreach (var command in _commands)
         {
             _menuService.RemoveCommand(command);
         }
         _menuService.Dispose();
     }
     _commands.Clear();
     base.Close();
 }
        public static void RemoveCommandHandler(IServiceProvider serviceProvider, uint id)
        {
            OleMenuCommandService mcs = serviceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (mcs != null)
            {
                MenuCommand command = mcs.FindCommand(new CommandID(CodeSweep.VSPackage.GuidList_Accessor.guidVSPackageCmdSet, (int)id));
                if (command != null)
                {
                    mcs.RemoveCommand(command);
                }
            }
        }
Beispiel #11
0
        //TODO: Is it correct implementation of destroy?
        private static bool CreateDestroyMenu(bool create)
        {
            OleMenuCommandService commandService = ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (commandService == null)
            {
                return(false);
            }

            // Save As .png
            var SaveAsPngCommandID = new CommandID(typeof(ContextMenuCommandSet).GUID, (int)ContextMenuCommandSet.SaveAsPng);
            var menuItemSaveAsPng  = new OleMenuCommand(SaveAsPng, SaveAsPngCommandID);

            menuItemSaveAsPng.BeforeQueryStatus += MenuItemSaveAsPng_BeforeQueryStatus;
            if (create)
            {
                commandService.AddCommand(menuItemSaveAsPng);
            }
            else
            {
                commandService.RemoveCommand(menuItemSaveAsPng);
            }

            // Save As .csv
            var SaveAsCsvCommandID = new CommandID(typeof(ContextMenuCommandSet).GUID, (int)ContextMenuCommandSet.SaveAsCsv);
            var menuItemSaveAsCsv  = new OleMenuCommand(SaveAsCsv, SaveAsCsvCommandID);

            menuItemSaveAsCsv.BeforeQueryStatus += MenuItemSaveAsCsv_BeforeQueryStatus;
            if (create)
            {
                commandService.AddCommand(menuItemSaveAsCsv);
            }
            else
            {
                commandService.RemoveCommand(menuItemSaveAsCsv);
            }

            return(true);
        }
        private void RegisterCommand(
            OleMenuCommandService commandService,
            Guid menuCommandGroupGuid,
            int commandIdNumber,
            EventHandler handler)
        {
            var commandId   = new CommandID(menuCommandGroupGuid, commandIdNumber);
            var menuCommand = new MenuCommand(handler, commandId);

            if (commandService.FindCommand(commandId) != null)
            {
                commandService.RemoveCommand(menuCommand); //Is this step needed?
            }

            commandService.AddCommand(menuCommand);

            Debug.WriteLine($"Registered command {nameof(commandService)}: {menuCommandGroupGuid} - {commandIdNumber}");
        }
Beispiel #13
0
        protected void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }
            _disposed = true;

            if (disposing)
            {
                if (_menuService != null)
                {
                    foreach (var command in _commands)
                    {
                        _menuService.RemoveCommand(command);
                    }
                }
                _commands.Clear();
            }
        }
        private void GulpBeforeQueryStatus(object sender, EventArgs e)
        {
            // gets the full path of the clicked file
            var path = SolutionHelpers.GetSourceFilePath();

            var myCommand = sender as OleMenuCommand;

            myCommand.Visible = this.IsGulpFile();


            if (!this.IsNewFile())
            {
                return;
            }

            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            // delete the old command list
            if (commands == null)
            {
                commands = new List <OleMenuCommand>();
            }

            foreach (var cmd in commands)
            {
                mcs.RemoveCommand(cmd);
            }

            if (myCommand.Visible)
            {
                this.lastFile = path;

                var list = GulpParser.ReadAllTasks(path);

                myCommand.Text    = "Gulp";
                myCommand.Enabled = true;

                if (list.Count == 0)
                {
                    myCommand.Enabled = false;
                    myCommand.Text    = "Gulpfile.js not found";
                }

                if (list.Contains("default"))
                {
                    list.Remove("default");
                }

                string n = exclusionRegex;

                Regex a = null;

                if (!string.IsNullOrEmpty(n))
                {
                    try
                    {
                        a = new Regex(n);
                    }
                    catch (Exception)
                    {
                        // invalid regex -> ignore
                    }
                }

                // creates the list of commands
                int j = 1;
                foreach (var ele in list)
                {
                    if (a != null)
                    {
                        if (a.Match(ele).Success)
                        {
                            continue;
                        }
                    }


                    CommandID menuCommandID = new CommandID(GuidList.guidGruntLauncherCmdSet, (int)PkgCmdIDList.cmdidGulpLauncher + j);
                    j++;
                    OleMenuCommand command = new OleMenuCommand(this.GulpCallback, menuCommandID);
                    command.Text = "Gulp: " + ele;
                    command.BeforeQueryStatus += (x, y) => { (x as OleMenuCommand).Visible = true; };
                    commands.Add(command);
                    mcs.AddCommand(command);
                }
            }
        }