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);
        }
Exemple #2
0
        protected override void Run(RefactoringOptions options)
        {
            Gtk.Menu menu = new Gtk.Menu();

            bool          resolveDirect;
            List <string> namespaces = GetResolveableNamespaces(options, out resolveDirect);

            foreach (string ns in namespaces)
            {
                // remove used namespaces for conflict resolving.
                if (options.Document.CompilationUnit.IsNamespaceUsedAt(ns, options.ResolveResult.ResolvedExpression.Region.Start))
                {
                    continue;
                }
                Gtk.MenuItem menuItem = new Gtk.MenuItem(string.Format(GettextCatalog.GetString("Add using '{0}'"), ns));
                CurrentRefactoryOperationsHandler.ResolveNameOperation resolveNameOperation = new CurrentRefactoryOperationsHandler.ResolveNameOperation(options.Dom, options.Document, options.ResolveResult, ns);
                menuItem.Activated += delegate
                {
                    resolveNameOperation.AddImport();
                };
                menu.Add(menuItem);
            }
            if (resolveDirect)
            {
                foreach (string ns in namespaces)
                {
                    Gtk.MenuItem menuItem = new Gtk.MenuItem(string.Format(GettextCatalog.GetString("Add '{0}'"), ns));
                    CurrentRefactoryOperationsHandler.ResolveNameOperation resolveNameOperation = new CurrentRefactoryOperationsHandler.ResolveNameOperation(options.Dom, options.Document, options.ResolveResult, ns);
                    menuItem.Activated += delegate
                    {
                        resolveNameOperation.ResolveName();
                    };
                    menu.Add(menuItem);
                }
            }

            if (menu.Children != null && menu.Children.Length > 0)
            {
                menu.ShowAll();

                ICompletionWidget     widget = options.Document.GetContent <ICompletionWidget> ();
                CodeCompletionContext codeCompletionContext = widget.CreateCodeCompletionContext(options.GetTextEditorData().Caret.Offset);

                menu.Popup(null, null, delegate(Gtk.Menu menu2, out int x, out int y, out bool pushIn)
                {
                    x      = codeCompletionContext.TriggerXCoord;
                    y      = codeCompletionContext.TriggerYCoord;
                    pushIn = false;
                }, 0, Gtk.Global.CurrentEventTime);
                menu.SelectFirst(true);
            }
        }
Exemple #3
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();
            };
        }
		protected override void Run (RefactoringOptions options)
		{
			Gtk.Menu menu = new Gtk.Menu ();
			
			bool resolveDirect;
			List<string> namespaces = GetResolveableNamespaces (options, out resolveDirect);
			
			foreach (string ns in namespaces) {
				// remove used namespaces for conflict resolving.
				if (options.Document.CompilationUnit.IsNamespaceUsedAt (ns, options.ResolveResult.ResolvedExpression.Region.Start))
					continue;
				Gtk.MenuItem menuItem = new Gtk.MenuItem (string.Format (GettextCatalog.GetString ("Add using '{0}'"), ns));
				CurrentRefactoryOperationsHandler.ResolveNameOperation resolveNameOperation = new CurrentRefactoryOperationsHandler.ResolveNameOperation (options.Dom, options.Document, options.ResolveResult, ns);
				menuItem.Activated += delegate {
					resolveNameOperation.AddImport ();
				};
				menu.Add (menuItem);
			}
			if (resolveDirect) {
				foreach (string ns in namespaces) {
					Gtk.MenuItem menuItem = new Gtk.MenuItem (string.Format (GettextCatalog.GetString ("Add '{0}'"), ns));
					CurrentRefactoryOperationsHandler.ResolveNameOperation resolveNameOperation = new CurrentRefactoryOperationsHandler.ResolveNameOperation (options.Dom, options.Document, options.ResolveResult, ns);
					menuItem.Activated += delegate {
						resolveNameOperation.ResolveName ();
					};
					menu.Add (menuItem);
				}
			}
			
			if (menu.Children != null && menu.Children.Length > 0) {
				menu.ShowAll ();
				
				ICompletionWidget widget = options.Document.GetContent<ICompletionWidget> ();
				CodeCompletionContext codeCompletionContext = widget.CreateCodeCompletionContext (options.GetTextEditorData ().Caret.Offset);

				menu.Popup (null, null, delegate (Gtk.Menu menu2, out int x, out int y, out bool pushIn) {
					x = codeCompletionContext.TriggerXCoord; 
					y = codeCompletionContext.TriggerYCoord; 
					pushIn = false;
				}, 0, Gtk.Global.CurrentEventTime);
				menu.SelectFirst (true);
			}
		}
        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);
        }
		void PopupQuickFixMenu (Gdk.EventButton evt)
		{
			var menu = new Gtk.Menu ();

			var caretOffset = document.Editor.Caret.Offset;
			Gtk.Menu fixMenu = menu;
			DomRegion region;
			var resolveResult = document.GetLanguageItem (caretOffset, out region);
			if (resolveResult != null) {
				var possibleNamespaces = MonoDevelop.Refactoring.ResolveCommandHandler.GetPossibleNamespaces (document, resolveResult);
	
				bool addUsing = !(resolveResult is AmbiguousTypeResolveResult);
				if (addUsing) {
					foreach (string ns_ in possibleNamespaces) {
						string ns = ns_;
						var menuItem = new Gtk.MenuItem (GettextCatalog.GetString ("Import Namespace {0}", ns));
						menuItem.Activated += delegate {
							new MonoDevelop.Refactoring.ResolveCommandHandler.AddImport (document, resolveResult, ns, true).Run ();
						};
						menu.Add (menuItem);
					}
				}
				
				bool resolveDirect = !(resolveResult is UnknownMemberResolveResult);
				if (resolveDirect) {
					foreach (string ns in possibleNamespaces) {
						var menuItem = new Gtk.MenuItem (GettextCatalog.GetString ("Use {0}", ns + "." + document.Editor.GetTextBetween (region.Begin, region.End)));
						menuItem.Activated += delegate {
							new MonoDevelop.Refactoring.ResolveCommandHandler.AddImport (document, resolveResult, ns, false).Run ();
						};
						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;
			};
			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));
		}
	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);
		}
Exemple #8
0
 protected override void OnClicked()
 {
     menu.SelectFirst(true);
     GuiUtils.PopupMenu(menu, null);
 }
Exemple #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));
        }
		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));
		}
		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 ();
			};
		}