Beispiel #1
0
        protected override async Task UpdateAsync(CommandArrayInfo info, CancellationToken cancelToken)
        {
            var editor = IdeApp.Workbench.ActiveDocument?.Editor;
            var ext    = editor?.GetContent <CodeActionEditorExtension> ();

            if (ext == null)
            {
                return;
            }
            try {
                info.Add(new CommandInfo(GettextCatalog.GetString("Loading..."), false, false), null);
                var currentFixes = await ext.GetCurrentFixesAsync(cancelToken);

                var menu = await CodeFixMenuService.CreateFixMenu(editor, currentFixes, cancelToken);

                info.Clear();
                foreach (var item in menu.Items)
                {
                    AddItem(info, item);
                }
                if (menu.Items.Count == 0)
                {
                    info.Add(new CommandInfo(GettextCatalog.GetString("No code fixes available"), false, false), null);
                }
                info.NotifyChanged();
            } catch (OperationCanceledException) {
            } catch (Exception e) {
                LoggingService.LogError("Error while creating quick fix menu.", e);
                info.Clear();
                info.Add(new CommandInfo(GettextCatalog.GetString("No code fixes available"), false, false), null);
                info.NotifyChanged();
            }
        }
Beispiel #2
0
		public void OnSetBuildActionUpdate (CommandArrayInfo info)
		{
			Set<string> toggledActions = new Set<string> ();
			Project proj = null;
			foreach (ITreeNavigator node in CurrentNodes) {
				ProjectFile finfo = (ProjectFile) node.DataItem;
				
				//disallow multi-slect on more than one project, since available build actions may differ
				if (proj == null && finfo.Project != null) {
					proj = finfo.Project;
				} else if (proj == null || proj != finfo.Project) {
					info.Clear ();
					return;
				}
				toggledActions.Add (finfo.BuildAction);
			}
			
			foreach (string action in proj.GetBuildActions ()) {
				if (action == "--") {
					info.AddSeparator ();
				} else {
					CommandInfo ci = info.Add (action, action);
					ci.Checked = toggledActions.Contains (action);
					if (ci.Checked)
						ci.CheckedInconsistent = toggledActions.Count > 1;
				}
			}
		}
        void AddCommands(CommandArrayInfo info, LanguageClientCodeAction[] actions)
        {
            info.Clear();

            if (actions == null || actions.Length == 0)
            {
                AddNoFixesAvailableCommand(info);
                return;
            }

            foreach (var action in actions)
            {
                AddCommand(info, action.Title, enabled: true, dataItem: action);
            }
        }
        protected override async Task UpdateAsync(CommandArrayInfo info, CancellationToken cancelToken)
        {
            var languageClient = GetLanguageClientExtension();

            if (languageClient == null)
            {
                return;
            }

            try {
                await AddQuickFixCommands(info, languageClient, cancelToken);
            } catch (OperationCanceledException) {
                // Ignore.
            } catch (Exception ex) {
                LoggingService.LogError("Error creating quick fix menu.", ex);
                info.Clear();
                AddNoFixesAvailableCommand(info);
            }
        }
        // If multiple nodes are selected and the method does not have the AllowMultiSelectionAttribute
        // attribute, disable the command.

        protected override void CommandUpdate(object target, CommandArrayInfo cinfo)
        {
            NodeCommandHandler nc = (NodeCommandHandler)target;

            base.CommandUpdate(target, cinfo);
            if (nc.MultipleSelectedNodes)
            {
                bool allowMultiArray         = false;
                ICommandArrayUpdateHandler h = ((ICommandArrayUpdateHandler)this).Next;
                while (h != null)
                {
                    if (h is AllowMultiSelectionAttribute)
                    {
                        allowMultiArray = true;
                        break;
                    }
                    h = h.Next;
                }
                if (!allowMultiArray)
                {
                    cinfo.Clear();
                }
            }
        }