Exemplo n.º 1
0
        public void PopulateFixes(Gtk.Menu menu)
        {
            int mnemonic = 1;

            foreach (var fix_ in fixes.OrderByDescending(i => GetUsage(i.IdString)))
            {
                var fix          = fix_;
                var escapedLabel = fix.Title.Replace("_", "__");
                var label        = (mnemonic <= 10)
                        ? "_" + (mnemonic++ % 10).ToString() + " " + escapedLabel
                        : "  " + escapedLabel;
                var menuItem = new Gtk.MenuItem(label);
                menuItem.Activated += new ContextActionRunner(fix, document, loc).Run;
                menuItem.Activated += delegate
                {
                    ConfirmUsage(fix.IdString);
                    menu.Destroy();
                };
                menu.Add(menuItem);
            }
            var first           = true;
            var alreadyInserted = new HashSet <CodeIssueProvider> ();

            foreach (var analysisFix_ in fixes.OfType <AnalysisContextActionProvider.AnalysisCodeAction>().Where(f => f.Result is InspectorResults))
            {
                var analysisFix = analysisFix_;
                var ir          = analysisFix.Result as InspectorResults;
                if (ir == null)
                {
                    continue;
                }

                if (first)
                {
                    menu.Add(new Gtk.SeparatorMenuItem());
                    first = false;
                }
                if (alreadyInserted.Contains(ir.Inspector))
                {
                    continue;
                }
                alreadyInserted.Add(ir.Inspector);

                var label    = GettextCatalog.GetString("_Inspection options for \"{0}\"", ir.Inspector.Title);
                var menuItem = new Gtk.MenuItem(label);
                menuItem.Activated += analysisFix.ShowOptions;
                menuItem.Activated += delegate
                {
                    menu.Destroy();
                };
                menu.Add(menuItem);
            }
        }
Exemplo n.º 2
0
        void PopupQuickFixMenu(Gdk.EventButton evt)
        {
            Gtk.Menu menu = new Gtk.Menu();

            Dictionary <Gtk.MenuItem, ContextAction> fixTable = new Dictionary <Gtk.MenuItem, ContextAction> ();
            int mnemonic = 1;

            foreach (ContextAction fix in fixes)
            {
                var escapedLabel = fix.GetMenuText(document, loc).Replace("_", "__");
                var label        = (mnemonic <= 10)
                                                ? "_" + (mnemonic++ % 10).ToString() + " " + escapedLabel
                                                : "  " + escapedLabel;
                Gtk.MenuItem menuItem = new Gtk.MenuItem(label);
                fixTable [menuItem] = fix;
                menuItem.Activated += delegate(object sender, EventArgs e) {
                    // ensure that the Ast is recent.
                    document.UpdateParseDocument();
                    var runFix = fixTable [(Gtk.MenuItem)sender];
                    runFix.Run(document, loc);

                    document.Editor.Document.CommitUpdateAll();
                    menu.Destroy();
                };
                menu.Add(menuItem);
            }
            menu.ShowAll();
            menu.SelectFirst(true);
            menuPushed      = true;
            menu.Destroyed += delegate {
                menuPushed = false;
                QueueDraw();
            };
            GtkWorkarounds.ShowContextMenu(menu, this, evt, Allocation);
        }
Exemplo n.º 3
0
        internal void ShowDockPopupMenu(uint time)
        {
            Gtk.Menu menu = new Gtk.Menu();

            // Hide menuitem
            if ((Behavior & DockItemBehavior.CantClose) == 0)
            {
                Gtk.MenuItem mitem = new Gtk.MenuItem(Catalog.GetString("Hide"));
                mitem.Activated += delegate { Visible = false; };
                menu.Append(mitem);
            }

            Gtk.MenuItem citem;

            // Auto Hide menuitem
            if ((Behavior & DockItemBehavior.CantAutoHide) == 0 && Status != DockItemStatus.AutoHide)
            {
                citem            = new Gtk.MenuItem(Catalog.GetString("Minimize"));
                citem.Activated += delegate { Status = DockItemStatus.AutoHide; };
                menu.Append(citem);
            }

            if (Status != DockItemStatus.Dockable)
            {
                // Dockable menuitem
                citem            = new Gtk.MenuItem(Catalog.GetString("Dock"));
                citem.Activated += delegate { Status = DockItemStatus.Dockable; };
                menu.Append(citem);
            }

            // Floating menuitem
            if ((Behavior & DockItemBehavior.NeverFloating) == 0 && Status != DockItemStatus.Floating)
            {
                citem            = new Gtk.MenuItem(Catalog.GetString("Undock"));
                citem.Activated += delegate { Status = DockItemStatus.Floating; };
                menu.Append(citem);
            }

            if (menu.Children.Length == 0)
            {
                menu.Destroy();
                return;
            }

            ShowingContextMemu = true;

            menu.ShowAll();
            menu.Hidden += (o, e) => {
                ShowingContextMemu = false;
            };
            menu.Popup(null, null, null, 3, time);
        }
Exemplo n.º 4
0
        public void PopupQuickFixMenu()
        {
            Gtk.Menu menu = new Gtk.Menu();

            Dictionary <Gtk.MenuItem, ContextAction> fixTable = new Dictionary <Gtk.MenuItem, ContextAction> ();
            int mnemonic = 1;

            foreach (ContextAction fix in fixes)
            {
                var escapedLabel = fix.GetMenuText(document, loc).Replace("_", "__");
                var label        = (mnemonic <= 10)
                                                ? "_" + (mnemonic++ % 10).ToString() + " " + escapedLabel
                                                : "  " + escapedLabel;
                Gtk.MenuItem menuItem = new Gtk.MenuItem(label);
                fixTable [menuItem] = fix;
                menuItem.Activated += delegate(object sender, EventArgs e) {
                    // ensure that the Ast is recent.
                    document.UpdateParseDocument();
                    var runFix = fixTable [(Gtk.MenuItem)sender];
                    runFix.Run(document, loc);

                    document.Editor.Document.CommitUpdateAll();
                    menu.Destroy();
                };
                menu.Add(menuItem);
            }
            menu.ShowAll();
            int dx, dy;

            this.ParentWindow.GetOrigin(out dx, out dy);
            dx += ((TextEditorContainer.EditorContainerChild)(this.document.Editor.Parent.Parent as TextEditorContainer) [this]).X;
            dy += ((TextEditorContainer.EditorContainerChild)(this.document.Editor.Parent.Parent as TextEditorContainer) [this]).Y - (int)document.Editor.VAdjustment.Value;

            menu.Popup(null, null, delegate(Gtk.Menu menu2, out int x, out int y, out bool pushIn) {
                x          = dx;
                y          = dy + Allocation.Height;
                pushIn     = false;
                menuPushed = true;
                QueueDraw();
            }, 0, Gtk.Global.CurrentEventTime);
            menu.SelectFirst(true);
            menu.Destroyed += delegate {
                menuPushed = false;
                QueueDraw();
            };
        }
Exemplo n.º 5
0
        void PopupQuickFixMenu(Gdk.EventButton evt, Action <Gtk.Menu> menuAction)
        {
            var menu = new Gtk.Menu();

            menu.Events |= Gdk.EventMask.AllEventsMask;
            Gtk.Menu      fixMenu = menu;
            ResolveResult resolveResult;

            ICSharpCode.NRefactory.CSharp.AstNode node;
            int items = 0;

            if (ResolveCommandHandler.ResolveAt(document, out resolveResult, out node))
            {
                var possibleNamespaces = MonoDevelop.Refactoring.ResolveCommandHandler.GetPossibleNamespaces(
                    document,
                    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    menuItem  = new Gtk.MenuItem(string.Format("using {0};", ns));
                        menuItem.Activated += delegate {
                            new ResolveCommandHandler.AddImport(document, resolveResult, ns, reference, true, node).Run();
                            if (reference != null)
                            {
                                document.Project.Items.Add(reference);
                            }
                            menu.Destroy();
                        };
                        menu.Add(menuItem);
                        items++;
                    }
                }

                bool resolveDirect = !(resolveResult is UnknownMemberResolveResult);
                if (resolveDirect)
                {
                    foreach (var t in possibleNamespaces)
                    {
                        string ns        = t.Namespace;
                        var    reference = t.Reference;
                        var    menuItem  = new Gtk.MenuItem(GettextCatalog.GetString("{0}", ns + "." + document.Editor.GetTextBetween(node.StartLocation, node.EndLocation)));
                        menuItem.Activated += delegate {
                            new ResolveCommandHandler.AddImport(document, resolveResult, ns, reference, false, node).Run();
                            menu.Destroy();
                        };
                        menu.Add(menuItem);
                        items++;
                    }
                }
                if (menu.Children.Any() && fixes.Any())
                {
                    fixMenu = new Gtk.Menu();
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("Quick Fixes"));
                    menuItem.Submenu = fixMenu;
                    menu.Add(menuItem);
                    items++;
                }
            }

            PopulateFixes(fixMenu, ref items);
            if (items == 0)
            {
                menu.Destroy();
                return;
            }
            document.Editor.SuppressTooltips = true;
            document.Editor.Parent.HideTooltip();
            if (menuAction != null)
            {
                menuAction(menu);
            }
            menu.ShowAll();
            menu.SelectFirst(true);
            menuPushed   = true;
            menu.Hidden += delegate {
                document.Editor.SuppressTooltips = false;
            };
            menu.Destroyed += delegate {
                menuPushed = false;
                Hide();
            };
            var container = document.Editor.Parent;
            var child     = (TextEditor.EditorContainerChild)container [this];

            Gdk.Rectangle rect;

/*			if (child != null) {
 *                              rect = new Gdk.Rectangle (child.X, child.Y + Allocation.Height - (int)document.Editor.VAdjustment.Value, 0, 0);
 *                      } else {*/
            var p = container.LocationToPoint(loc);

            rect = new Gdk.Rectangle(p.X + container.Allocation.X, p.Y + (int)document.Editor.LineHeight + container.Allocation.Y, 0, 0);
            //}
            GtkWorkarounds.ShowContextMenu(menu, document.Editor.Parent, null, rect);
        }
Exemplo n.º 6
0
        public void PopulateFixes(Gtk.Menu menu, ref int items)
        {
            int mnemonic = 1;

            foreach (var fix_ in fixes.OrderByDescending(i => GetUsage(i.IdString)))
            {
                var fix          = fix_;
                var escapedLabel = fix.Title.Replace("_", "__");
                var label        = (mnemonic <= 10)
                                        ? "_" + (mnemonic++ % 10).ToString() + " " + escapedLabel
                                                : "  " + escapedLabel;
                var menuItem = new Gtk.MenuItem(label);
                menuItem.Activated += new ContextActionRunner(fix, document, loc).Run;
                menuItem.Activated += delegate {
                    ConfirmUsage(fix.IdString);
                    menu.Destroy();
                };
                menu.Add(menuItem);
                items++;
            }
            var first           = true;
            var alreadyInserted = new HashSet <CodeIssueProvider> ();

            foreach (var analysisFix_ in fixes.OfType <AnalysisContextActionProvider.AnalysisCodeAction>().Where(f => f.Result is InspectorResults))
            {
                var analysisFix = analysisFix_;
                var ir          = analysisFix.Result as InspectorResults;
                if (ir == null)
                {
                    continue;
                }

                if (first)
                {
                    menu.Add(new Gtk.SeparatorMenuItem());
                    first = false;
                }
                if (alreadyInserted.Contains(ir.Inspector))
                {
                    continue;
                }
                alreadyInserted.Add(ir.Inspector);

                var label    = GettextCatalog.GetString("_Inspection options for \"{0}\"", ir.Inspector.Title);
                var menuItem = new Gtk.MenuItem(label);
                menuItem.Activated += analysisFix.ShowOptions;
                menuItem.Activated += delegate {
                    menu.Destroy();
                };
                menu.Add(menuItem);
                items++;
            }

            foreach (var fix_ in fixes.Where(f => f.BoundToIssue != null))
            {
                var fix = fix_;
                foreach (var inspector_ in RefactoringService.GetInspectors(document.Editor.MimeType).Where(i => i.GetSeverity() != ICSharpCode.NRefactory.CSharp.Severity.None))
                {
                    var inspector = inspector_;

                    if (inspector.IdString.IndexOf(fix.BoundToIssue.FullName, StringComparison.Ordinal) < 0)
                    {
                        continue;
                    }
                    if (first)
                    {
                        menu.Add(new Gtk.SeparatorMenuItem());
                        first = false;
                    }
                    if (alreadyInserted.Contains(inspector))
                    {
                        continue;
                    }
                    alreadyInserted.Add(inspector);

                    var label    = GettextCatalog.GetString("_Inspection options for \"{0}\"", inspector.Title);
                    var menuItem = new Gtk.MenuItem(label);
                    menuItem.Activated += delegate {
                        MessageService.RunCustomDialog(new CodeIssueOptionsDialog(inspector), MessageService.RootWindow);
                        menu.Destroy();
                    };
                    menu.Add(menuItem);
                    break;
                }

                items++;
            }
        }
Exemplo n.º 7
0
		internal void ShowDockPopupMenu (uint time)
		{
			Gtk.Menu menu = new Gtk.Menu ();
			
			// Hide menuitem
			if ((Behavior & DockItemBehavior.CantClose) == 0) {
				Gtk.MenuItem mitem = new Gtk.MenuItem (Catalog.GetString("Hide"));
				mitem.Activated += delegate { Visible = false; };
				menu.Append (mitem);
			}

			Gtk.MenuItem citem;

			// Auto Hide menuitem
			if ((Behavior & DockItemBehavior.CantAutoHide) == 0 && Status != DockItemStatus.AutoHide) {
				citem = new Gtk.MenuItem (Catalog.GetString("Minimize"));
				citem.Activated += delegate { Status = DockItemStatus.AutoHide; };
				menu.Append (citem);
			}

			if (Status != DockItemStatus.Dockable) {
				// Dockable menuitem
				citem = new Gtk.MenuItem (Catalog.GetString("Dock"));
				citem.Activated += delegate { Status = DockItemStatus.Dockable; };
				menu.Append (citem);
			}

			// Floating menuitem
			if ((Behavior & DockItemBehavior.NeverFloating) == 0 && Status != DockItemStatus.Floating) {
				citem = new Gtk.MenuItem (Catalog.GetString("Undock"));
				citem.Activated += delegate { Status = DockItemStatus.Floating; };
				menu.Append (citem);
			}

			if (menu.Children.Length == 0) {
				menu.Destroy ();
				return;
			}

			ShowingContextMemu = true;

			menu.ShowAll ();
			menu.Hidden += (o,e) => {
				ShowingContextMemu = false;
			};
			menu.Popup (null, null, null, 3, time);
		}
Exemplo n.º 8
0
	void PopupQuickFixMenu (Gdk.EventButton evt)
		{
			var menu = new Gtk.Menu ();

			Gtk.Menu fixMenu = menu;
			ResolveResult resolveResult;
			ICSharpCode.NRefactory.CSharp.AstNode node;
			int items = 0;
			if (ResolveCommandHandler.ResolveAt (document, out resolveResult, out node)) {
				var possibleNamespaces = MonoDevelop.Refactoring.ResolveCommandHandler.GetPossibleNamespaces (
					document,
					node,
					ref resolveResult
				);
	
				bool addUsing = !(resolveResult is AmbiguousTypeResolveResult);
				if (addUsing) {
					foreach (var t in possibleNamespaces.Where (tp => tp.Item2)) {
						string ns = t.Item1;
						var menuItem = new Gtk.MenuItem (string.Format ("using {0};", ns));
						menuItem.Activated += delegate {
							new MonoDevelop.Refactoring.ResolveCommandHandler.AddImport (document, resolveResult, ns, true, node).Run ();
							menu.Destroy ();
						};
						menu.Add (menuItem);
						items++;
					}
				}
				
				bool resolveDirect = !(resolveResult is UnknownMemberResolveResult);
				if (resolveDirect) {
					foreach (var t in possibleNamespaces) {
						string ns = t.Item1;
						var menuItem = new Gtk.MenuItem (GettextCatalog.GetString ("{0}", ns + "." + document.Editor.GetTextBetween (node.StartLocation, node.EndLocation)));
						menuItem.Activated += delegate {
							new MonoDevelop.Refactoring.ResolveCommandHandler.AddImport (document, resolveResult, ns, false, node).Run ();
							menu.Destroy ();
						};
						menu.Add (menuItem);
						items++;
					}
				}
				if (menu.Children.Any () && fixes.Any ()) {
					fixMenu = new Gtk.Menu ();
					var menuItem = new Gtk.MenuItem (GettextCatalog.GetString ("Quick Fixes"));
					menuItem.Submenu = fixMenu;
					menu.Add (menuItem);
					items++;
				}
			}
			
			PopulateFixes (fixMenu, ref items);
			if (items == 0) {
				menu.Destroy ();
				return;
			}
			document.Editor.SuppressTooltips = true;
			document.Editor.Parent.HideTooltip ();
			menu.ShowAll ();
			menu.SelectFirst (true);
			menuPushed = true;
			menu.Hidden += delegate {
				document.Editor.SuppressTooltips = false;
			};
			menu.Destroyed += delegate {
				menuPushed = false;
				Hide ();
			};
			var container = document.Editor.Parent;
			var child = (TextEditor.EditorContainerChild)container [this];

			Gdk.Rectangle rect;
/*			if (child != null) {
				rect = new Gdk.Rectangle (child.X, child.Y + Allocation.Height - (int)document.Editor.VAdjustment.Value, 0, 0);
			} else {*/
				var p = container.LocationToPoint (loc);
				rect = new Gdk.Rectangle (p.X + container.Allocation.X , p.Y + (int)document.Editor.LineHeight + container.Allocation.Y, 0, 0);
			//}
			GtkWorkarounds.ShowContextMenu (menu, document.Editor.Parent, null, rect);
		}
Exemplo n.º 9
0
        void PopupQuickFixMenu(Gdk.EventButton evt)
        {
            var menu = new Gtk.Menu();

            Gtk.Menu      fixMenu = menu;
            ResolveResult resolveResult;

            ICSharpCode.NRefactory.CSharp.AstNode node;
            if (ResolveCommandHandler.ResolveAt(document, out resolveResult, out node))
            {
                var possibleNamespaces = MonoDevelop.Refactoring.ResolveCommandHandler.GetPossibleNamespaces(
                    document,
                    node,
                    resolveResult
                    );

                bool addUsing = !(resolveResult is AmbiguousTypeResolveResult);
                if (addUsing)
                {
                    foreach (string ns_ in possibleNamespaces)
                    {
                        string ns       = ns_;
                        var    menuItem = new Gtk.MenuItem(string.Format("using {0};", ns));
                        menuItem.Activated += delegate {
                            new MonoDevelop.Refactoring.ResolveCommandHandler.AddImport(document, resolveResult, ns, true, node).Run();
                            menu.Destroy();
                        };
                        menu.Add(menuItem);
                    }
                }

                bool resolveDirect = !(resolveResult is UnknownMemberResolveResult);
                if (resolveDirect)
                {
                    foreach (string ns in possibleNamespaces)
                    {
                        var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("{0}", ns + "." + document.Editor.GetTextBetween(node.StartLocation, node.EndLocation)));
                        menuItem.Activated += delegate {
                            new MonoDevelop.Refactoring.ResolveCommandHandler.AddImport(document, resolveResult, ns, false, node).Run();
                            menu.Destroy();
                        };
                        menu.Add(menuItem);
                    }
                }
                if (menu.Children.Any() && fixes.Any())
                {
                    fixMenu = new Gtk.Menu();
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("Quick Fixes"));
                    menuItem.Submenu = fixMenu;
                    menu.Add(menuItem);
                }
            }

            PopulateFixes(fixMenu);

            menu.ShowAll();
            menu.SelectFirst(true);
            menuPushed      = true;
            menu.Destroyed += delegate {
                menuPushed = false;
                Hide();
            };
            var container = (TextEditorContainer)document.Editor.Parent.Parent;
            var child     = (TextEditorContainer.EditorContainerChild)container [this];

            GtkWorkarounds.ShowContextMenu(menu, document.Editor.Parent, null, new Gdk.Rectangle(child.X, child.Y + Allocation.Height - (int)document.Editor.VAdjustment.Value, 0, 0));
        }
Exemplo n.º 10
0
        public void PopulateFixes(Gtk.Menu menu, ref int items)
        {
            int mnemonic = 1;

            foreach (var fix_ in fixes.OrderByDescending(i => GetUsage(i.IdString)))
            {
                var fix          = fix_;
                var escapedLabel = fix.Title.Replace("_", "__");
                var label        = (mnemonic <= 10)
                                        ? "_" + (mnemonic++ % 10).ToString() + " " + escapedLabel
                                                : "  " + escapedLabel;
                var thisInstanceMenuItem = new Gtk.MenuItem(label);
                thisInstanceMenuItem.Activated += new ContextActionRunner(fix, document, loc).Run;
                thisInstanceMenuItem.Activated += delegate {
                    ConfirmUsage(fix.IdString);
                    menu.Destroy();
                };
                menu.Add(thisInstanceMenuItem);
                items++;
            }
            var first           = true;
            var alreadyInserted = new HashSet <BaseCodeIssueProvider> ();

            foreach (var analysisFix_ in fixes.OfType <AnalysisContextActionProvider.AnalysisCodeAction>().Where(f => f.Result is InspectorResults))
            {
                var analysisFix = analysisFix_;
                var ir          = analysisFix.Result as InspectorResults;
                if (ir == null)
                {
                    continue;
                }

                if (first)
                {
                    menu.Add(new Gtk.SeparatorMenuItem());
                    first = false;
                }
                if (alreadyInserted.Contains(ir.Inspector))
                {
                    continue;
                }
                alreadyInserted.Add(ir.Inspector);

                var subMenu = new Gtk.Menu();
                if (analysisFix.SupportsBatchRunning)
                {
                    var batchRunMenuItem = new Gtk.MenuItem(GettextCatalog.GetString("Fix all in this file"));
                    batchRunMenuItem.Activated += delegate {
                        ConfirmUsage(analysisFix.IdString);
                        menu.Destroy();
                    };
                    batchRunMenuItem.Activated += new ContextActionRunner(analysisFix, document, loc).BatchRun;
                    subMenu.Add(batchRunMenuItem);
                    subMenu.Add(new Gtk.SeparatorMenuItem());
                }

                var inspector = ir.Inspector;
                if (inspector.CanDisableWithPragma)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Suppress with #pragma"));
                    menuItem.Activated += delegate {
                        inspector.DisableWithPragma(document, loc);
                    };
                    subMenu.Add(menuItem);
                }

                if (inspector.CanDisableOnce)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Disable once with comment"));
                    menuItem.Activated += delegate {
                        inspector.DisableOnce(document, loc);
                    };
                    subMenu.Add(menuItem);
                }

                if (inspector.CanDisableAndRestore)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("Disable _and restore with comments"));
                    menuItem.Activated += delegate {
                        inspector.DisableAndRestore(document, loc);
                    };
                    subMenu.Add(menuItem);
                }
                var label       = GettextCatalog.GetString("_Options for \"{0}\"", InspectorResults.GetTitle(ir.Inspector));
                var subMenuItem = new Gtk.MenuItem(label);

                var optionsMenuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Configure inspection severity"));
                optionsMenuItem.Activated += analysisFix.ShowOptions;
                optionsMenuItem.Activated += delegate {
                    menu.Destroy();
                };
                subMenu.Add(optionsMenuItem);
                subMenuItem.Submenu = subMenu;
                menu.Add(subMenuItem);
                items++;
            }

            foreach (var fix_ in fixes.Where(f => f.BoundToIssue != null))
            {
                var fix = fix_;
                foreach (var inspector_ in RefactoringService.GetInspectors(document.Editor.MimeType).Where(i => i.GetSeverity() != Severity.None))
                {
                    var inspector = inspector_;

                    if (inspector.IdString.IndexOf(fix.BoundToIssue.FullName, StringComparison.Ordinal) < 0)
                    {
                        continue;
                    }
                    if (first)
                    {
                        menu.Add(new Gtk.SeparatorMenuItem());
                        first = false;
                    }
                    if (alreadyInserted.Contains(inspector))
                    {
                        continue;
                    }
                    alreadyInserted.Add(inspector);

                    var      label       = GettextCatalog.GetString("_Options for \"{0}\"", InspectorResults.GetTitle(inspector));
                    var      subMenuItem = new Gtk.MenuItem(label);
                    Gtk.Menu subMenu     = new Gtk.Menu();
                    if (inspector.CanSuppressWithAttribute)
                    {
                        var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Suppress with attribute"));
                        menuItem.Activated += delegate {
                            inspector.SuppressWithAttribute(document, loc);
                        };
                        subMenu.Add(menuItem);
                    }

                    if (inspector.CanDisableWithPragma)
                    {
                        var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Suppress with #pragma"));
                        menuItem.Activated += delegate {
                            inspector.DisableWithPragma(document, loc);
                        };
                        subMenu.Add(menuItem);
                    }

                    if (inspector.CanDisableOnce)
                    {
                        var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Disable once with comment"));
                        menuItem.Activated += delegate {
                            inspector.DisableOnce(document, loc);
                        };
                        subMenu.Add(menuItem);
                    }

                    if (inspector.CanDisableAndRestore)
                    {
                        var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("Disable _and restore with comments"));
                        menuItem.Activated += delegate {
                            inspector.DisableAndRestore(document, loc);
                        };
                        subMenu.Add(menuItem);
                    }

                    var confItem = new Gtk.MenuItem(GettextCatalog.GetString("_Configure inspection severity"));
                    confItem.Activated += delegate {
                        MessageService.RunCustomDialog(new CodeIssueOptionsDialog(inspector), MessageService.RootWindow);
                        menu.Destroy();
                    };
                    subMenu.Add(confItem);

                    subMenuItem.Submenu = subMenu;
                    subMenu.ShowAll();
                    menu.Add(subMenuItem);
                    break;
                }

                items++;
            }
        }
Exemplo n.º 11
0
        public void PopulateFixes(Gtk.Menu menu, ref int items)
        {
            int  mnemonic = 1;
            bool gotImportantFix = false, addedSeparator = false;
            var  fixesAdded = new List <string> ();

            foreach (var fix_ in fixes.OrderByDescending(i => Tuple.Create(IsAnalysisOrErrorFix(i), (int)i.Severity, GetUsage(i.IdString))))
            {
                // filter out code actions that are already resolutions of a code issue
                if (fixesAdded.Any(f => fix_.IdString.IndexOf(f, StringComparison.Ordinal) >= 0))
                {
                    continue;
                }
                fixesAdded.Add(fix_.IdString);
                if (IsAnalysisOrErrorFix(fix_))
                {
                    gotImportantFix = true;
                }
                if (!addedSeparator && gotImportantFix && !IsAnalysisOrErrorFix(fix_))
                {
                    menu.Add(new Gtk.SeparatorMenuItem());
                    addedSeparator = true;
                }

                var fix          = fix_;
                var escapedLabel = fix.Title.Replace("_", "__");
                var label        = (mnemonic <= 10)
                                        ? "_" + (mnemonic++ % 10).ToString() + " " + escapedLabel
                                                : "  " + escapedLabel;
                var thisInstanceMenuItem = new Gtk.MenuItem(label);
                thisInstanceMenuItem.Activated += new ContextActionRunner(fix, document, loc).Run;
                thisInstanceMenuItem.Activated += delegate {
                    ConfirmUsage(fix.IdString);
                    menu.Destroy();
                };
                menu.Add(thisInstanceMenuItem);
                items++;
            }

            bool first             = true;
            var  settingsMenuFixes = fixes
                                     .OfType <AnalysisContextActionProvider.AnalysisCodeAction> ()
                                     .Where(f => f.Result is InspectorResults)
                                     .GroupBy(f => ((InspectorResults)f.Result).Inspector);

            foreach (var analysisFixGroup_ in settingsMenuFixes)
            {
                var analysisFixGroup    = analysisFixGroup_;
                var arbitraryFixInGroup = analysisFixGroup.First();
                var ir = (InspectorResults)arbitraryFixInGroup.Result;

                if (first)
                {
                    menu.Add(new Gtk.SeparatorMenuItem());
                    first = false;
                }

                var subMenu = new Gtk.Menu();
                foreach (var analysisFix_ in analysisFixGroup)
                {
                    var analysisFix = analysisFix_;
                    if (analysisFix.SupportsBatchRunning)
                    {
                        var batchRunMenuItem = new Gtk.MenuItem(string.Format(GettextCatalog.GetString("Apply in file: {0}"), analysisFix.Title));
                        batchRunMenuItem.Activated += delegate {
                            ConfirmUsage(analysisFix.IdString);
                            menu.Destroy();
                        };
                        batchRunMenuItem.Activated += new ContextActionRunner(analysisFix, document, loc).BatchRun;
                        subMenu.Add(batchRunMenuItem);
                        subMenu.Add(new Gtk.SeparatorMenuItem());
                    }
                }

                var inspector = ir.Inspector;
                if (inspector.CanSuppressWithAttribute)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Suppress with attribute"));
                    menuItem.Activated += delegate {
                        inspector.SuppressWithAttribute(document, arbitraryFixInGroup.DocumentRegion);
                    };
                    subMenu.Add(menuItem);
                }

                if (inspector.CanDisableWithPragma)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Suppress with #pragma"));
                    menuItem.Activated += delegate {
                        inspector.DisableWithPragma(document, arbitraryFixInGroup.DocumentRegion);
                    };
                    subMenu.Add(menuItem);
                }

                if (inspector.CanDisableOnce)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Disable once with comment"));
                    menuItem.Activated += delegate {
                        inspector.DisableOnce(document, arbitraryFixInGroup.DocumentRegion);
                    };
                    subMenu.Add(menuItem);
                }

                if (inspector.CanDisableAndRestore)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("Disable _and restore with comments"));
                    menuItem.Activated += delegate {
                        inspector.DisableAndRestore(document, arbitraryFixInGroup.DocumentRegion);
                    };
                    subMenu.Add(menuItem);
                }
                var label       = GettextCatalog.GetString("_Options for \"{0}\"", InspectorResults.GetTitle(ir.Inspector));
                var subMenuItem = new Gtk.MenuItem(label);

                var optionsMenuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Configure inspection"));
                optionsMenuItem.Activated += arbitraryFixInGroup.ShowOptions;

                optionsMenuItem.Activated += delegate {
                    menu.Destroy();
                };
                subMenu.Add(optionsMenuItem);
                subMenuItem.Submenu = subMenu;
                menu.Add(subMenuItem);
                items++;
            }
        }
Exemplo n.º 12
0
        public void PopulateFixes(Gtk.Menu menu, ref int items)
        {
            int  mnemonic = 1;
            bool gotImportantFix = false, addedSeparator = false;

            foreach (var fix_ in fixes.OrderByDescending(i => Tuple.Create(IsAnalysisOrErrorFix(i), (int)i.Severity, GetUsage(i.IdString))))
            {
                if (IsAnalysisOrErrorFix(fix_))
                {
                    gotImportantFix = true;
                }
                if (!addedSeparator && gotImportantFix && !IsAnalysisOrErrorFix(fix_))
                {
                    menu.Add(new Gtk.SeparatorMenuItem());
                    addedSeparator = true;
                }

                var fix          = fix_;
                var escapedLabel = fix.Title.Replace("_", "__");
                var label        = (mnemonic <= 10)
                                        ? "_" + (mnemonic++ % 10).ToString() + " " + escapedLabel
                                                : "  " + escapedLabel;
                var thisInstanceMenuItem = new Gtk.MenuItem(label);
                thisInstanceMenuItem.Activated += new ContextActionRunner(fix, document, loc).Run;
                thisInstanceMenuItem.Activated += delegate {
                    ConfirmUsage(fix.IdString);
                    menu.Destroy();
                };
                menu.Add(thisInstanceMenuItem);
                items++;
            }

            bool first           = true;
            var  alreadyInserted = new HashSet <BaseCodeIssueProvider> ();

            foreach (var analysisFix_ in fixes.OfType <AnalysisContextActionProvider.AnalysisCodeAction>().Where(f => f.Result is InspectorResults))
            {
                var analysisFix = analysisFix_;
                var ir          = analysisFix.Result as InspectorResults;
                if (ir == null)
                {
                    continue;
                }

                if (first)
                {
                    menu.Add(new Gtk.SeparatorMenuItem());
                    first = false;
                }
                if (alreadyInserted.Contains(ir.Inspector))
                {
                    continue;
                }
                alreadyInserted.Add(ir.Inspector);

                var subMenu = new Gtk.Menu();
                if (analysisFix.SupportsBatchRunning)
                {
                    var batchRunMenuItem = new Gtk.MenuItem(GettextCatalog.GetString("Fix all in this file"));
                    batchRunMenuItem.Activated += delegate {
                        ConfirmUsage(analysisFix.IdString);
                        menu.Destroy();
                    };
                    batchRunMenuItem.Activated += new ContextActionRunner(analysisFix, document, loc).BatchRun;
                    subMenu.Add(batchRunMenuItem);
                    subMenu.Add(new Gtk.SeparatorMenuItem());
                }

                var inspector = ir.Inspector;
                if (inspector.CanSuppressWithAttribute)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Suppress with attribute"));
                    menuItem.Activated += delegate {
                        inspector.SuppressWithAttribute(document, analysisFix.DocumentRegion);
                    };
                    subMenu.Add(menuItem);
                }

                if (inspector.CanDisableWithPragma)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Suppress with #pragma"));
                    menuItem.Activated += delegate {
                        inspector.DisableWithPragma(document, analysisFix.DocumentRegion);
                    };
                    subMenu.Add(menuItem);
                }

                if (inspector.CanDisableOnce)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Disable once with comment"));
                    menuItem.Activated += delegate {
                        inspector.DisableOnce(document, analysisFix.DocumentRegion);
                    };
                    subMenu.Add(menuItem);
                }

                if (inspector.CanDisableAndRestore)
                {
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("Disable _and restore with comments"));
                    menuItem.Activated += delegate {
                        inspector.DisableAndRestore(document, analysisFix.DocumentRegion);
                    };
                    subMenu.Add(menuItem);
                }
                var label       = GettextCatalog.GetString("_Options for \"{0}\"", InspectorResults.GetTitle(ir.Inspector));
                var subMenuItem = new Gtk.MenuItem(label);

                var optionsMenuItem = new Gtk.MenuItem(GettextCatalog.GetString("_Configure inspection"));
                optionsMenuItem.Activated += analysisFix.ShowOptions;
                optionsMenuItem.Activated += delegate {
                    menu.Destroy();
                };
                subMenu.Add(optionsMenuItem);
                subMenuItem.Submenu = subMenu;
                menu.Add(subMenuItem);
                items++;
            }
        }
Exemplo n.º 13
0
		void PopupQuickFixMenu (Gdk.EventButton evt)
		{
			var menu = new Gtk.Menu ();

			Gtk.Menu fixMenu = menu;
			ResolveResult resolveResult;
			ICSharpCode.NRefactory.CSharp.AstNode node;
			if (ResolveCommandHandler.ResolveAt (document, out resolveResult, out node)) {
				var possibleNamespaces = MonoDevelop.Refactoring.ResolveCommandHandler.GetPossibleNamespaces (
					document,
					node,
					resolveResult
				);
	
				bool addUsing = !(resolveResult is AmbiguousTypeResolveResult);
				if (addUsing) {
					foreach (string ns_ in possibleNamespaces) {
						string ns = ns_;
						var menuItem = new Gtk.MenuItem (string.Format ("using {0};", ns));
						menuItem.Activated += delegate {
							new MonoDevelop.Refactoring.ResolveCommandHandler.AddImport (document, resolveResult, ns, true).Run ();
							menu.Destroy ();
						};
						menu.Add (menuItem);
					}
				}
				
				bool resolveDirect = !(resolveResult is UnknownMemberResolveResult);
				if (resolveDirect) {
					foreach (string ns in possibleNamespaces) {
						var menuItem = new Gtk.MenuItem (GettextCatalog.GetString ("{0}", ns + "." + document.Editor.GetTextBetween (node.StartLocation, node.EndLocation)));
						menuItem.Activated += delegate {
							new MonoDevelop.Refactoring.ResolveCommandHandler.AddImport (document, resolveResult, ns, false).Run ();
							menu.Destroy ();
						};
						menu.Add (menuItem);
					}
				}
				if (menu.Children.Any () && fixes.Any ()) {
					fixMenu = new Gtk.Menu ();
					var menuItem = new Gtk.MenuItem (GettextCatalog.GetString ("Quick Fixes"));
					menuItem.Submenu = fixMenu;
					menu.Add (menuItem);
				}
			}
			
			PopulateFixes (fixMenu);
			
			menu.ShowAll ();
			menu.SelectFirst (true);
			menuPushed = true;
			menu.Destroyed += delegate {
				menuPushed = false;
				Hide ();
			};
			var container = (TextEditorContainer)document.Editor.Parent.Parent;
			var child = (TextEditorContainer.EditorContainerChild)container [this];
			GtkWorkarounds.ShowContextMenu (menu, document.Editor.Parent, null, new Gdk.Rectangle (child.X, child.Y + Allocation.Height - (int)document.Editor.VAdjustment.Value, 0, 0));
		}
Exemplo n.º 14
0
		public void PopupQuickFixMenu ()
		{
			Gtk.Menu menu = new Gtk.Menu ();
			
			Dictionary<Gtk.MenuItem, ContextAction> fixTable = new Dictionary<Gtk.MenuItem, ContextAction> ();
			int mnemonic = 1;
			foreach (ContextAction fix in fixes) {
				var escapedLabel = fix.GetMenuText (document, loc).Replace ("_", "__");
				var label = (mnemonic <= 10)
						? "_" + (mnemonic++ % 10).ToString () + " " + escapedLabel
						: "  " + escapedLabel;
				Gtk.MenuItem menuItem = new Gtk.MenuItem (label);
				fixTable [menuItem] = fix;
				menuItem.Activated += delegate(object sender, EventArgs e) {
					// ensure that the Ast is recent.
					document.UpdateParseDocument ();
					var runFix = fixTable [(Gtk.MenuItem)sender];
					runFix.Run (document, loc);
					
					document.Editor.Document.CommitUpdateAll ();
					menu.Destroy ();
				};
				menu.Add (menuItem);
			}
			menu.ShowAll ();
			int dx, dy;
			this.ParentWindow.GetOrigin (out dx, out dy);
			dx += ((TextEditorContainer.EditorContainerChild)(this.document.Editor.Parent.Parent as TextEditorContainer) [this]).X;
			dy += ((TextEditorContainer.EditorContainerChild)(this.document.Editor.Parent.Parent as TextEditorContainer) [this]).Y - (int)document.Editor.VAdjustment.Value;
					
			menu.Popup (null, null, delegate (Gtk.Menu menu2, out int x, out int y, out bool pushIn) {
				x = dx; 
				y = dy + Allocation.Height; 
				pushIn = false;
				menuPushed = true;
				QueueDraw ();
			}, 0, Gtk.Global.CurrentEventTime);
			menu.SelectFirst (true);
			menu.Destroyed += delegate {
				menuPushed = false;
				QueueDraw ();
			};
		}