Esempio n. 1
0
        protected override void Update(CommandArrayInfo info)
        {
            for (int i = 0; i < IdeApp.Workbench.Pads.Count; i++)
            {
                Pad pad = IdeApp.Workbench.Pads[i];

                CommandInfo ci = new CommandInfo(pad.Title);
                ci.Icon        = pad.Icon;
                ci.UseMarkup   = true;
                ci.Description = GettextCatalog.GetString("Show {0}", pad.Title);
                ci.Checked     = pad.Visible;

                ActionCommand cmd = IdeApp.CommandService.GetActionCommand("Pad|" + pad.Id);
                if (cmd != null)
                {
                    ci.AccelKey = cmd.AccelKey;
                }

                CommandArrayInfo list = info;
                if (pad.Categories != null)
                {
                    for (int j = 0; j < pad.Categories.Length; j++)
                    {
                        bool found = false;
                        for (int k = list.Count - 1; k >= 0; k--)
                        {
                            if (list[k].Text == pad.Categories[j] && list[k] is CommandInfoSet)
                            {
                                list  = ((CommandInfoSet)list[k]).CommandInfos;
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            CommandInfoSet set = new CommandInfoSet();
                            set.Text        = pad.Categories[j];
                            set.Description = GettextCatalog.GetString("Show {0}", set.Text);
                            list.Add(set);
                            list = set.CommandInfos;
                        }
                    }
                }
                for (int j = list.Count - 1; j >= 0; j--)
                {
                    if (!(list[j] is CommandInfoSet))
                    {
                        list.Insert(j + 1, ci, pad);
                        pad = null;
                        break;
                    }
                }
                if (pad != null)
                {
                    list.Insert(0, ci, pad);
                }
            }
        }
        protected override void Update(CommandArrayInfo ainfo)
        {
            var doc = IdeApp.Workbench.ActiveDocument;

            if (doc == null || doc.FileName == FilePath.Null || doc.ParsedDocument == null)
            {
                return;
            }

            ResolveResult resolveResult;
            AstNode       node;

            if (!ResolveAt(doc, out resolveResult, out node))
            {
                return;
            }

            var resolveMenu = new CommandInfoSet();

            resolveMenu.Text = GettextCatalog.GetString("Resolve");

            var possibleNamespaces = GetPossibleNamespaces(doc, node, resolveResult);

            bool addUsing = !(resolveResult is AmbiguousTypeResolveResult);

            if (addUsing)
            {
                foreach (string ns in possibleNamespaces)
                {
                    var info = resolveMenu.CommandInfos.Add(
                        string.Format("using {0};", ns),
                        new System.Action(new AddImport(doc, resolveResult, ns, true).Run)
                        );
                    info.Icon = MonoDevelop.Ide.Gui.Stock.AddNamespace;
                }
            }

            bool resolveDirect = !(resolveResult is UnknownMemberResolveResult);

            if (resolveDirect)
            {
                if (resolveMenu.CommandInfos.Count > 0)
                {
                    resolveMenu.CommandInfos.AddSeparator();
                }
                if (node is ObjectCreateExpression)
                {
                    node = ((ObjectCreateExpression)node).Type;
                }
                foreach (string ns in possibleNamespaces)
                {
                    resolveMenu.CommandInfos.Add(string.Format("{0}", ns + "." + doc.Editor.GetTextBetween(node.StartLocation, node.EndLocation)), new System.Action(new AddImport(doc, resolveResult, ns, false).Run));
                }
            }

            if (resolveMenu.CommandInfos.Count > 0)
            {
                ainfo.Insert(0, resolveMenu);
            }
        }
Esempio n. 3
0
        protected override void Update(CommandArrayInfo info)
        {
            string group;
            var    lastListGroup = new Dictionary <CommandArrayInfo, string>();
            var    descFormat    = GettextCatalog.GetString("Show {0}");

            foreach (Pad pad in IdeApp.Workbench.Pads.OrderBy(p => p.Group, StringComparer.InvariantCultureIgnoreCase))
            {
                CommandInfo ci = new CommandInfo(pad.Title);
                ci.Icon        = pad.Icon;
                ci.UseMarkup   = true;
                ci.Description = string.Format(descFormat, pad.Title);
                // We only want these commands enabled if the main window is visible
                ci.Enabled = IdeApp.Workbench.RootWindow.Visible;

                ActionCommand cmd = IdeApp.CommandService.GetActionCommand("Pad|" + pad.Id);
                if (cmd != null)
                {
                    ci.AccelKey = cmd.AccelKey;
                }

                CommandArrayInfo list = info;
                if (pad.Categories != null)
                {
                    for (int j = 0; j < pad.Categories.Length; j++)
                    {
                        bool found = false;
                        for (int k = list.Count - 1; k >= 0; k--)
                        {
                            if (list[k].Text == pad.Categories[j] && list[k] is CommandInfoSet)
                            {
                                list  = ((CommandInfoSet)list[k]).CommandInfos;
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            CommandInfoSet set = new CommandInfoSet();
                            set.Text        = pad.Categories[j];
                            set.Description = string.Format(descFormat, set.Text);
                            list.Add(set);
                            list = set.CommandInfos;
                        }
                    }
                }

                int atIndex = 0;
                for (int j = list.Count - 1; j >= 0; j--)
                {
                    if (!(list [j] is CommandInfoSet))
                    {
                        atIndex = j + 1;
                        break;
                    }
                }

                list.Insert(atIndex, ci, pad);
                lastListGroup.TryGetValue(list, out group);
                if (group != pad.Group)
                {
                    lastListGroup [list] = pad.Group;
                    if (atIndex > 0)
                    {
                        CommandInfo sep = new CommandInfo("-");
                        sep.IsArraySeparator = true;
                        list.Insert(atIndex, sep, null);
                    }
                }
            }
        }
        protected override void Update(CommandArrayInfo ainfo)
        {
            var doc = IdeApp.Workbench.ActiveDocument;

            if (doc == null || doc.FileName == FilePath.Null || doc.ParsedDocument == null)
            {
                return;
            }

            ResolveResult resolveResult;
            AstNode       node;

            if (!ResolveAt(doc, out resolveResult, out node))
            {
                var location = RefactoringService.GetCorrectResolveLocation(doc, doc.Editor.Caret.Location);
                resolveResult = GetHeuristicResult(doc, location, ref node);
                if (resolveResult == null)
                {
                    return;
                }
            }
            var resolveMenu = new CommandInfoSet();

            resolveMenu.Text = GettextCatalog.GetString("Resolve");

            var possibleNamespaces = GetPossibleNamespaces(doc, node, ref resolveResult);

            bool addUsing = !(resolveResult is AmbiguousTypeResolveResult);

            if (addUsing)
            {
                foreach (var t in possibleNamespaces.Where(tp => tp.IsAccessibleWithGlobalUsing))
                {
                    string ns        = t.Namespace;
                    var    reference = t.Reference;
                    var    info      = resolveMenu.CommandInfos.Add(
                        t.GetImportText(),
                        new System.Action(new AddImport(doc, resolveResult, ns, reference, true, node).Run)
                        );
                    info.Icon = MonoDevelop.Ide.Gui.Stock.AddNamespace;
                }
            }

            bool resolveDirect = !(resolveResult is UnknownMemberResolveResult);

            if (resolveDirect)
            {
                if (resolveMenu.CommandInfos.Count > 0)
                {
                    resolveMenu.CommandInfos.AddSeparator();
                }
                if (node is ObjectCreateExpression)
                {
                    node = ((ObjectCreateExpression)node).Type;
                }
                foreach (var t in possibleNamespaces)
                {
                    string ns        = t.Namespace;
                    var    reference = t.Reference;
                    resolveMenu.CommandInfos.Add(t.GetInsertNamespaceText(doc.Editor.GetTextBetween(node.StartLocation, node.EndLocation)), new System.Action(new AddImport(doc, resolveResult, ns, reference, false, node).Run));
                }
            }

            if (resolveMenu.CommandInfos.Count > 0)
            {
                ainfo.Insert(0, resolveMenu);
            }
        }