static void AddMenuItem(NSLocationAwareMenu menu, ContextMenuItem item) { if (item.IsSeparator) { menu.AddItem(NSMenuItem.SeparatorItem); return; } var menuItem = new NSContextMenuItem(item.Label.Replace("_", ""), item); menuItem.Hidden = !item.Visible; menuItem.Enabled = item.Sensitive; menuItem.Image = item.Image.ToNSImage(); if (item is RadioButtonContextMenuItem) { var radioItem = (RadioButtonContextMenuItem)item; menuItem.State = radioItem.Checked ? NSCellStateValue.On : NSCellStateValue.Off; } else if (item is CheckBoxContextMenuItem) { var checkItem = (CheckBoxContextMenuItem)item; menuItem.State = checkItem.Checked ? NSCellStateValue.On : NSCellStateValue.Off; } if (item.SubMenu != null && item.SubMenu.Items.Count > 0) { var subMenu = FromMenu(item.SubMenu, null, menu); menuItem.Submenu = subMenu; } menu.AddItem(menuItem); }
void MenuWillHighlightItem(NSMenu menu, NSMenuItem willHighlightItem) { if (oldItem != null) { oldItem.FireDeselectedEvent(); oldItem = null; } if (willHighlightItem == null) { return; } int index = (int)menu.IndexOf(willHighlightItem); if (index < 0) { return; } oldItem = this.menu.Items [index]; nfloat x = 0, y = 0; var locationAwareMenu = menu as NSLocationAwareMenu; if (locationAwareMenu != null) { while (locationAwareMenu.Parent != null && locationAwareMenu.Parent.TryGetTarget(out var other)) { locationAwareMenu = other; } x = locationAwareMenu.Location.X; y = locationAwareMenu.Location.Y; menu = locationAwareMenu; } oldItem.FireSelectedEvent(new Xwt.Rectangle(x, y, menu.Size.Width, menu.Size.Height)); }
static NSMenuItem CreateMenuItem(ContextMenuItem item) { if (item.IsSeparator) { return(NSMenuItem.SeparatorItem); } var menuItem = new NSMenuItem(item.Label, (s, e) => item.Click()); menuItem.Hidden = !item.Visible; menuItem.Enabled = item.Sensitive; menuItem.Image = item.Image.ToNSImage(); if (item is RadioButtonContextMenuItem) { var radioItem = (RadioButtonContextMenuItem)item; menuItem.State = radioItem.Checked ? NSCellStateValue.On : NSCellStateValue.Off; } else if (item is CheckBoxContextMenuItem) { var checkItem = (CheckBoxContextMenuItem)item; menuItem.State = checkItem.Checked ? NSCellStateValue.On : NSCellStateValue.Off; } if (item.SubMenu != null && item.SubMenu.Items.Count > 0) { menuItem.Submenu = FromMenu(item.SubMenu); } return(menuItem); }
public NSContextMenuItem(string label, ContextMenuItem item) : base(label) { contextMenu = new WeakReference <ContextMenuItem> (item); if (item.SubMenu == null || item.SubMenu.Items.Count == 0) { this.Activated += OnActivated; } }
static void ShowNativeContextMenu(this Gtk.Entry entry, Gdk.EventButton evt) { var context_menu = new ContextMenu(); var cut = new ContextMenuItem { Label = GettextCatalog.GetString("Cut"), Context = entry }; cut.Clicked += CutClicked; context_menu.Items.Add(cut); var copy = new ContextMenuItem { Label = GettextCatalog.GetString("Copy"), Context = entry }; copy.Clicked += CopyClicked; context_menu.Items.Add(copy); var paste = new ContextMenuItem { Label = GettextCatalog.GetString("Paste"), Context = entry }; paste.Clicked += PasteClicked; context_menu.Items.Add(paste); context_menu.Items.Add(new SeparatorContextMenuItem()); var delete = new ContextMenuItem { Label = GettextCatalog.GetString("Delete"), Context = entry }; delete.Clicked += DeleteClicked; context_menu.Items.Add(delete); context_menu.Items.Add(new SeparatorContextMenuItem()); var select_all = new ContextMenuItem { Label = GettextCatalog.GetString("Select All"), Context = entry }; select_all.Clicked += SelectAllClicked; context_menu.Items.Add(select_all); /* Update the menu items' sensitivities */ copy.Sensitive = select_all.Sensitive = (entry.Text.Length > 0); cut.Sensitive = delete.Sensitive = (entry.Text.Length > 0 && entry.IsEditable); paste.Sensitive = entry.IsEditable; context_menu.Show(entry, evt); }
static Gtk.MenuItem CreateMenuItem (ContextMenuItem item) { if (!item.Visible) return null; if (item.IsSeparator) { return new Gtk.SeparatorMenuItem (); } Gtk.MenuItem menuItem; if (item is RadioButtonContextMenuItem) { var radioItem = (RadioButtonContextMenuItem)item; menuItem = new Gtk.CheckMenuItem (item.Label) { Active = radioItem.Checked, DrawAsRadio = true }; } else if (item is CheckBoxContextMenuItem) { var checkItem = (CheckBoxContextMenuItem)item; menuItem = new Gtk.CheckMenuItem (item.Label) { Active = checkItem.Checked }; } else { menuItem = new Gtk.ImageMenuItem (item.Label); } if (item.SubMenu != null && item.SubMenu.Items.Count > 0) { menuItem.Submenu = FromMenu (item.SubMenu); } else { menuItem.Activated += (sender, e) => item.Click (); } menuItem.Sensitive = item.Sensitive; var label = (Gtk.Label) menuItem.Child; label.UseUnderline = item.UseMnemonic; if (item.UseMnemonic) label.TextWithMnemonic = item.Label; if (item.Image != null) { Gtk.ImageMenuItem imageItem = menuItem as Gtk.ImageMenuItem; if (imageItem != null) { var img = new ImageView (item.Image); img.ShowAll (); imageItem.Image = img; GtkWorkarounds.ForceImageOnMenuItem (imageItem); } } return menuItem; }
void MenuWillHighlightItem(NSMenu menu, NSMenuItem willHighlightItem) { if (oldItem != null) { oldItem.FireDeselectedEvent(); oldItem = null; } if (willHighlightItem == null) { return; } int index = (int)menu.IndexOf(willHighlightItem); if (index < 0) { return; } oldItem = this.menu.Items [index]; oldItem.FireSelectedEvent(new Xwt.Rectangle(lastOpenPositon.X, lastOpenPositon.Y, menu.Size.Width, menu.Size.Height)); }
void ShowPopup (Gdk.EventButton evt) { var context_menu = new ContextMenu (); context_menu.Items.Add (new SeparatorContextMenuItem ()); var selectAllItem = new ContextMenuItem (GettextCatalog.GetString ("Select All")); selectAllItem.Clicked += delegate { OnSelectAll (); }; context_menu.Items.Add (selectAllItem); var copyItem = new ContextMenuItem (GettextCatalog.GetString ("Copy")); copyItem.Clicked += delegate { OnCopy (); }; context_menu.Items.Add (copyItem); context_menu.Items.Add (new SeparatorContextMenuItem ()); var assemblyCheckbox = new CheckBoxContextMenuItem (GettextCatalog.GetString ("Show Module Name")); assemblyCheckbox.Clicked += delegate { assemblyCheckbox.Checked = ShowModuleName = !ShowModuleName; StoreSettings (); UpdateDisplay (); }; assemblyCheckbox.Checked = ShowModuleName; context_menu.Items.Add (assemblyCheckbox); var typeCheckbox = new CheckBoxContextMenuItem (GettextCatalog.GetString ("Show Parameter Type")); typeCheckbox.Clicked += delegate { typeCheckbox.Checked = ShowParameterType = !ShowParameterType; StoreSettings (); UpdateDisplay (); }; typeCheckbox.Checked = ShowParameterType; context_menu.Items.Add (typeCheckbox); var nameCheckbox = new CheckBoxContextMenuItem (GettextCatalog.GetString ("Show Parameter Name")); nameCheckbox.Clicked += delegate { nameCheckbox.Checked = ShowParameterName = !ShowParameterName; StoreSettings (); UpdateDisplay (); }; nameCheckbox.Checked = ShowParameterName; context_menu.Items.Add (nameCheckbox); var valueCheckbox = new CheckBoxContextMenuItem (GettextCatalog.GetString ("Show Parameter Value")); valueCheckbox.Clicked += delegate { valueCheckbox.Checked = ShowParameterValue = !ShowParameterValue; StoreSettings (); UpdateDisplay (); }; valueCheckbox.Checked = ShowParameterValue; context_menu.Items.Add (valueCheckbox); var lineCheckbox = new CheckBoxContextMenuItem (GettextCatalog.GetString ("Show Line Number")); lineCheckbox.Clicked += delegate { lineCheckbox.Checked = ShowLineNumber = !ShowLineNumber; StoreSettings (); UpdateDisplay (); }; lineCheckbox.Checked = ShowLineNumber; context_menu.Items.Add (lineCheckbox); context_menu.Items.Add (new SeparatorContextMenuItem ()); var columnsVisibilitySubMenu = new ContextMenu (); var nameColumnVisibilityCheckbox = new CheckBoxContextMenuItem (GettextCatalog.GetString ("Name")); nameColumnVisibilityCheckbox.Clicked += delegate { nameColumnVisibilityCheckbox.Checked = tree.Columns [MethodColumn].Visible = !tree.Columns [MethodColumn].Visible; StoreColumnsVisibility (); }; nameColumnVisibilityCheckbox.Checked = tree.Columns [MethodColumn].Visible; columnsVisibilitySubMenu.Items.Add (nameColumnVisibilityCheckbox); var fileColumnVisibilityCheckbox = new CheckBoxContextMenuItem (GettextCatalog.GetString ("File")); fileColumnVisibilityCheckbox.Clicked += delegate { fileColumnVisibilityCheckbox.Checked = tree.Columns [FileColumn].Visible = !tree.Columns [FileColumn].Visible; StoreColumnsVisibility (); }; fileColumnVisibilityCheckbox.Checked = tree.Columns [FileColumn].Visible; columnsVisibilitySubMenu.Items.Add (fileColumnVisibilityCheckbox); var languageColumnVisibilityCheckbox = new CheckBoxContextMenuItem (GettextCatalog.GetString ("Language")); languageColumnVisibilityCheckbox.Clicked += delegate { languageColumnVisibilityCheckbox.Checked = tree.Columns [LangColumn].Visible = !tree.Columns [LangColumn].Visible; StoreColumnsVisibility (); }; languageColumnVisibilityCheckbox.Checked = tree.Columns [LangColumn].Visible; columnsVisibilitySubMenu.Items.Add (languageColumnVisibilityCheckbox); var addressColumnVisibilityCheckbox = new CheckBoxContextMenuItem (GettextCatalog.GetString ("Address")); addressColumnVisibilityCheckbox.Clicked += delegate { addressColumnVisibilityCheckbox.Checked = tree.Columns [AddrColumn].Visible = !tree.Columns [AddrColumn].Visible; StoreColumnsVisibility (); }; addressColumnVisibilityCheckbox.Checked = tree.Columns [AddrColumn].Visible; columnsVisibilitySubMenu.Items.Add (addressColumnVisibilityCheckbox); context_menu.Items.Add (new ContextMenuItem (GettextCatalog.GetString ("Columns")){ SubMenu = columnsVisibilitySubMenu }); context_menu.Show (this, evt); }
void UpdateGlobalWarningLabel () { KeyBindingConflict[] conflicts = currentBindings.CheckKeyBindingConflicts (IdeApp.CommandService.GetCommands ()); if (conflicts.Length == 0) { globalWarningBox.Hide (); return; } globalWarningBox.Show (); conflicButton.ContextMenuRequested = delegate { ContextMenu menu = new ContextMenu (); bool first = true; foreach (KeyBindingConflict conf in conflicts) { if (first == false) { ContextMenuItem item = new SeparatorContextMenuItem (); menu.Items.Add (item); } foreach (Command cmd in conf.Commands) { string txt = currentBindings.GetBinding (cmd) + " - " + cmd.Text; ContextMenuItem item = new ContextMenuItem (txt); Command localCmd = cmd; item.Clicked += (sender, e) => SelectCommand (localCmd); menu.Items.Add (item); first = false; } } return menu; }; }
public void Add (ContextMenuItem menuItem) { items.Add (menuItem); }
static Gtk.MenuItem CreateMenuItem (ContextMenuItem item) { if (!item.Visible) return null; if (item.IsSeparator) { return new Gtk.SeparatorMenuItem (); } Gtk.MenuItem menuItem; if (item is RadioButtonContextMenuItem) { var radioItem = (RadioButtonContextMenuItem)item; menuItem = new Gtk.CheckMenuItem (item.Label) { Active = radioItem.Checked, DrawAsRadio = true }; } else if (item is CheckBoxContextMenuItem) { var checkItem = (CheckBoxContextMenuItem)item; menuItem = new Gtk.CheckMenuItem (item.Label) { Active = checkItem.Checked }; } else { menuItem = new Gtk.ImageMenuItem (item.Label); } menuItem.Selected += delegate (object sender, EventArgs e) { var si = sender as Gtk.MenuItem; if (si == null || si.GdkWindow == null) return; int x, y; si.GdkWindow.GetOrigin (out x, out y); int rx, ry; IdeApp.Workbench.RootWindow.GdkWindow.GetOrigin (out rx, out ry); item.FireSelectedEvent (new Xwt.Rectangle (x - rx, y - ry, si.Allocation.Width, si.Allocation.Height)); }; menuItem.Deselected += delegate { item.FireDeselectedEvent (); }; if (item.SubMenu != null && item.SubMenu.Items.Count > 0) { menuItem.Submenu = FromMenu (item.SubMenu, null); } else { menuItem.Activated += (sender, e) => item.Click (); } menuItem.Sensitive = item.Sensitive; var label = (Gtk.Label) menuItem.Child; label.UseUnderline = item.UseMnemonic; if (item.UseMnemonic) label.TextWithMnemonic = item.Label; if (item.Image != null) { Gtk.ImageMenuItem imageItem = menuItem as Gtk.ImageMenuItem; if (imageItem != null) { var img = new ImageView (item.Image); img.ShowAll (); imageItem.Image = img; Xwt.GtkBackend.GtkWorkarounds.ForceImageOnMenuItem (imageItem); } } return menuItem; }
ContextMenu CreateContextMenu (FixMenuDescriptor entrySet) { var menu = new ContextMenu (); foreach (var item in entrySet.Items) { if (item == FixMenuEntry.Separator) { menu.Items.Add (new SeparatorContextMenuItem ()); continue; } var menuItem = new ContextMenuItem (item.Label); menuItem.Context = item.Action; var subMenu = item as FixMenuDescriptor; if (subMenu != null) { menuItem.SubMenu = CreateContextMenu (subMenu); } else { menuItem.Clicked += (object sender, ContextMenuItemClickedEventArgs e) => ((System.Action)((ContextMenuItem)sender).Context) (); } menu.Items.Add (menuItem); } return menu; }
void UpdateConflictsWarning () { duplicates = new Dictionary<string, HashSet<Command>> (); foreach (var conflict in currentBindings.CheckKeyBindingConflicts (IdeApp.CommandService.GetCommands ())) { HashSet<Command> cmds = null; if (!duplicates.TryGetValue (conflict.Key, out cmds)) duplicates [conflict.Key] = cmds = new HashSet<Command> (); foreach (var cmd in conflict.Commands) cmds.Add (cmd); } conflicts = new Dictionary<string, HashSet<Command>> (); foreach (var dup in duplicates) { foreach (var cmd in dup.Value) { HashSet<Command> cmdDuplicates; if (IdeApp.CommandService.Conflicts.TryGetValue (cmd, out cmdDuplicates)) { cmdDuplicates = new HashSet<Command> (cmdDuplicates.Intersect (dup.Value)); if (cmdDuplicates.Count > 0) { HashSet<Command> cmdConflicts; if (!conflicts.TryGetValue (dup.Key, out cmdConflicts)) conflicts [dup.Key] = cmdConflicts = new HashSet<Command> (); conflicts [dup.Key].UnionWith (cmdDuplicates); } } } } if (conflicts.Count == 0) { globalWarningBox.Hide (); return; } globalWarningBox.Show (); conflicButton.ContextMenuRequested = delegate { ContextMenu menu = new ContextMenu (); bool first = true; foreach (var conf in conflicts) { if (first == false) { ContextMenuItem item = new SeparatorContextMenuItem (); menu.Items.Add (item); } foreach (Command cmd in conf.Value.OrderBy (cmd => cmd.DisplayName)) { string txt = conf.Key + " \u2013 " + cmd.DisplayName; ContextMenuItem item = new ContextMenuItem (txt); Command localCmd = cmd; item.Clicked += (sender, e) => SelectCommand (localCmd); menu.Items.Add (item); first = false; } } return menu; }; }
static Gtk.MenuItem CreateMenuItem(ContextMenuItem item) { if (!item.Visible) { return(null); } if (item.IsSeparator) { return(new Gtk.SeparatorMenuItem()); } Gtk.MenuItem menuItem; if (item is RadioButtonContextMenuItem) { var radioItem = (RadioButtonContextMenuItem)item; menuItem = new Gtk.CheckMenuItem(item.Label) { Active = radioItem.Checked, DrawAsRadio = true }; } else if (item is CheckBoxContextMenuItem) { var checkItem = (CheckBoxContextMenuItem)item; menuItem = new Gtk.CheckMenuItem(item.Label) { Active = checkItem.Checked }; } else { menuItem = new Gtk.ImageMenuItem(item.Label); } if (item.SubMenu != null && item.SubMenu.Items.Count > 0) { menuItem.Submenu = FromMenu(item.SubMenu, null); } else { menuItem.Activated += (sender, e) => item.Click(); } menuItem.Sensitive = item.Sensitive; var label = (Gtk.Label)menuItem.Child; label.UseUnderline = item.UseMnemonic; if (item.UseMnemonic) { label.TextWithMnemonic = item.Label; } if (item.Image != null) { Gtk.ImageMenuItem imageItem = menuItem as Gtk.ImageMenuItem; if (imageItem != null) { var img = new ImageView(item.Image); img.ShowAll(); imageItem.Image = img; Xwt.GtkBackend.GtkWorkarounds.ForceImageOnMenuItem(imageItem); } } return(menuItem); }
public DefaultPolicyOptionsDialog (Gtk.Window parentWindow) : base (parentWindow, new PolicySet (), "/MonoDevelop/ProjectModel/Gui/DefaultPolicyPanels") { this.Title = GettextCatalog.GetString ("Custom Policies"); editingSet = (PolicySet) DataObject; HBox topBar = new HBox (); topBar.Spacing = 3; topBar.PackStart (new Label (GettextCatalog.GetString ("Editing Policy:")), false, false, 0); policiesCombo = ComboBox.NewText (); topBar.PackStart (policiesCombo, false, false, 0); deleteButton = new Button (GettextCatalog.GetString ("Delete Policy")); topBar.PackEnd (deleteButton, false, false, 0); exportButton = new MenuButton (); exportButton.Label = GettextCatalog.GetString ("Export"); exportButton.ContextMenuRequested = delegate { ContextMenu menu = new ContextMenu (); ContextMenuItem item = new ContextMenuItem (GettextCatalog.GetString ("To file...")); item.Clicked += HandleToFile; menu.Items.Add (item); item = new ContextMenuItem (GettextCatalog.GetString ("To project or solution...")); item.Clicked += HandleToProject; if (!IdeApp.Workspace.IsOpen) { item.Sensitive = false; } menu.Items.Add (item); return menu; }; topBar.PackEnd (exportButton, false, false, 0); newButton = new MenuButton (); newButton.Label = GettextCatalog.GetString ("Add Policy"); newButton.ContextMenuRequested = delegate { ContextMenu menu = new ContextMenu (); ContextMenuItem item = new ContextMenuItem (GettextCatalog.GetString ("New policy...")); item.Clicked += HandleNewButtonClicked; menu.Items.Add (item); item = new ContextMenuItem (GettextCatalog.GetString ("From file...")); item.Clicked += HandleFromFile; menu.Items.Add (item); item = new ContextMenuItem (GettextCatalog.GetString ("From project or solution...")); item.Clicked += HandleFromProject; if (!IdeApp.Workspace.IsOpen) { item.Sensitive = false; } menu.Items.Add (item); return menu; }; topBar.PackEnd (newButton, false, false, 0); Alignment align = new Alignment (0f, 0f, 1f, 1f); align.LeftPadding = 9; align.TopPadding = 9; align.RightPadding = 9; align.BottomPadding = 9; align.Add (topBar); HeaderBox ebox = new HeaderBox (); ebox.GradientBackground = true; ebox.SetMargins (0, 1, 0, 0); ebox.Add (align); ebox.ShowAll (); VBox.PackStart (ebox, false, false, 0); VBox.BorderWidth = 0; Box.BoxChild c = (Box.BoxChild) VBox [ebox]; c.Position = 0; foreach (PolicySet ps in PolicyService.GetUserPolicySets ()) { PolicySet copy = ps.Clone (); originalSets [copy] = ps; sets.Add (copy); } FillPolicySets (); policiesCombo.Changed += HandlePoliciesComboChanged; deleteButton.Clicked += HandleDeleteButtonClicked; }
void ShowPopup (Gdk.EventButton evt) { TreeIter selected; if (!tree.Selection.GetSelected (out selected)) return; var process = store.GetValue (selected, (int)Columns.Object) as ProcessInfo; if (process == null) return;//User right-clicked on thread and not process var session = store.GetValue (selected, (int)Columns.Session) as DebuggerSession; var context_menu = new ContextMenu (); var continueExecution = new ContextMenuItem (GettextCatalog.GetString ("Resume")); continueExecution.Sensitive = !session.IsRunning; continueExecution.Clicked += delegate { session.Continue (); }; context_menu.Items.Add (continueExecution); var pauseExecution = new ContextMenuItem (GettextCatalog.GetString ("Pause")); pauseExecution.Sensitive = session.IsRunning; pauseExecution.Clicked += delegate { session.Stop (); }; context_menu.Items.Add (pauseExecution); context_menu.Show (this, evt); }
void MenuWillHighlightItem (NSMenu menu, NSMenuItem willHighlightItem) { if (oldItem != null) { oldItem.FireDeselectedEvent (); oldItem = null; } if (willHighlightItem == null) return; int index = (int)menu.IndexOf (willHighlightItem); if (index < 0) return; oldItem = this.menu.Items [index]; oldItem.FireSelectedEvent (new Xwt.Rectangle (lastOpenPositon.X, lastOpenPositon.Y, menu.Size.Width, menu.Size.Height)); }
public NSContextMenuItem(string label, ContextMenuItem item) : base(label) { contextMenu = new WeakReference <ContextMenuItem> (item); this.Activated += OnActivated; }
ContextMenu CreateContextMenu (FixMenuDescriptor entrySet) { var menu = new ContextMenu (); foreach (var item in entrySet.Items) { if (item == FixMenuEntry.Separator) { menu.Items.Add (new SeparatorContextMenuItem ()); continue; } var menuItem = new ContextMenuItem (item.Label); menuItem.Context = item.Action; var subMenu = item as FixMenuDescriptor; if (subMenu != null) { menuItem.SubMenu = CreateContextMenu (subMenu); menuItem.Selected += delegate (object sender, Xwt.Rectangle e) { HidePreviewTooltip (); }; menuItem.Deselected += delegate { HidePreviewTooltip (); }; } else { menuItem.Clicked += (object sender, ContextMenuItemClickedEventArgs e) => ((System.Action)((ContextMenuItem)sender).Context) (); menuItem.Selected += delegate (object sender, Xwt.Rectangle e) { HidePreviewTooltip (); if (item.ShowPreviewTooltip != null) { item.ShowPreviewTooltip (e); } }; menuItem.Deselected += delegate { HidePreviewTooltip (); }; } menu.Items.Add (menuItem); } menu.Closed += delegate { HidePreviewTooltip (); }; return menu; }
static Gtk.MenuItem CreateMenuItem(ContextMenuItem item) { if (!item.Visible) { return(null); } if (item.IsSeparator) { return(new Gtk.SeparatorMenuItem()); } Gtk.MenuItem menuItem; if (item is RadioButtonContextMenuItem) { var radioItem = (RadioButtonContextMenuItem)item; menuItem = new Gtk.CheckMenuItem(item.Label) { Active = radioItem.Checked, DrawAsRadio = true }; } else if (item is CheckBoxContextMenuItem) { var checkItem = (CheckBoxContextMenuItem)item; menuItem = new Gtk.CheckMenuItem(item.Label) { Active = checkItem.Checked }; } else { menuItem = new Gtk.ImageMenuItem(item.Label); } menuItem.Selected += delegate(object sender, EventArgs e) { var si = sender as Gtk.MenuItem; if (si == null || si.GdkWindow == null) { return; } int x, y; si.GdkWindow.GetOrigin(out x, out y); int rx, ry; IdeApp.Workbench.RootWindow.GdkWindow.GetOrigin(out rx, out ry); item.FireSelectedEvent(new Xwt.Rectangle(x - rx, y - ry, si.Allocation.Width, si.Allocation.Height)); }; menuItem.Deselected += delegate { item.FireDeselectedEvent(); }; if (item.SubMenu != null && item.SubMenu.Items.Count > 0) { menuItem.Submenu = FromMenu(item.SubMenu, null); } else { menuItem.Activated += (sender, e) => item.Click(); } menuItem.Sensitive = item.Sensitive; var label = (Gtk.Label)menuItem.Child; label.UseUnderline = item.UseMnemonic; if (item.UseMnemonic) { label.TextWithMnemonic = item.Label; } if (item.Image != null) { Gtk.ImageMenuItem imageItem = menuItem as Gtk.ImageMenuItem; if (imageItem != null) { var img = new ImageView(item.Image); img.ShowAll(); imageItem.Image = img; Xwt.GtkBackend.GtkWorkarounds.ForceImageOnMenuItem(imageItem); } } return(menuItem); }
public void Add(ContextMenuItem menuItem) { items.Add(menuItem); }
public override void PopupContextMenu (UnitTestLocation unitTest, int x, int y) { var debugModeSet = Runtime.ProcessService.GetDebugExecutionMode (); var project = ext?.DocumentContext?.Project; if (project == null) return; var menu = new ContextMenu (); if (unitTest.IsFixture) { var menuItem = new ContextMenuItem ("_Run All"); menuItem.Clicked += new TestRunner (unitTest.UnitTestIdentifier, project, false).Run; menu.Add (menuItem); if (debugModeSet != null) { menuItem = new ContextMenuItem ("_Debug All"); menuItem.Clicked += new TestRunner (unitTest.UnitTestIdentifier, project, true).Run; menu.Add (menuItem); } menuItem = new ContextMenuItem ("_Select in Test Pad"); menuItem.Clicked += new TestRunner (unitTest.UnitTestIdentifier, project, true).Select; menu.Add (menuItem); } else { if (unitTest.TestCases.Count == 0) { var menuItem = new ContextMenuItem ("_Run"); menuItem.Clicked += new TestRunner (unitTest.UnitTestIdentifier, project, false).Run; menu.Add (menuItem); if (debugModeSet != null) { menuItem = new ContextMenuItem ("_Debug"); menuItem.Clicked += new TestRunner (unitTest.UnitTestIdentifier, project, true).Run; menu.Add (menuItem); } menuItem = new ContextMenuItem ("_Select in Test Pad"); menuItem.Clicked += new TestRunner (unitTest.UnitTestIdentifier, project, true).Select; menu.Add (menuItem); } else { var menuItem = new ContextMenuItem ("_Run All"); menuItem.Clicked += new TestRunner (unitTest.UnitTestIdentifier, project, false).Run; menu.Add (menuItem); if (debugModeSet != null) { menuItem = new ContextMenuItem ("_Debug All"); menuItem.Clicked += new TestRunner (unitTest.UnitTestIdentifier, project, true).Run; menu.Add (menuItem); } menu.Add (new SeparatorContextMenuItem ()); foreach (var id in unitTest.TestCases) { var submenu = new ContextMenu (); menuItem = new ContextMenuItem ("_Run"); menuItem.Clicked += new TestRunner (unitTest.UnitTestIdentifier + id, project, false).Run; submenu.Add (menuItem); if (debugModeSet != null) { menuItem = new ContextMenuItem ("_Debug"); menuItem.Clicked += new TestRunner (unitTest.UnitTestIdentifier + id, project, true).Run; submenu.Add (menuItem); } var label = "Test" + id; string tooltip = null; var test = UnitTestService.SearchTestById (unitTest.UnitTestIdentifier + id); if (test != null) { var result = test.GetLastResult (); if (result != null && result.IsFailure) { tooltip = result.Message; label += "!"; } } menuItem = new ContextMenuItem ("_Select in Test Pad"); menuItem.Clicked += new TestRunner (unitTest.UnitTestIdentifier + id, project, true).Select; submenu.Add (menuItem); var subMenuItem = new ContextMenuItem (label); // if (!string.IsNullOrEmpty (tooltip)) // subMenuItem.TooltipText = tooltip; subMenuItem.SubMenu = submenu; menu.Add (subMenuItem); } } } menu.Show (ext.Editor, x, y); }
static NSMenuItem CreateMenuItem (ContextMenuItem item) { if (item.IsSeparator) { return NSMenuItem.SeparatorItem; } var menuItem = new NSMenuItem (item.Label.Replace ("_",""), (s, e) => item.Click ()); menuItem.Hidden = !item.Visible; menuItem.Enabled = item.Sensitive; menuItem.Image = item.Image.ToNSImage (); if (item is RadioButtonContextMenuItem) { var radioItem = (RadioButtonContextMenuItem)item; menuItem.State = radioItem.Checked ? NSCellStateValue.On : NSCellStateValue.Off; } else if (item is CheckBoxContextMenuItem) { var checkItem = (CheckBoxContextMenuItem)item; menuItem.State = checkItem.Checked ? NSCellStateValue.On : NSCellStateValue.Off; } if (item.SubMenu != null && item.SubMenu.Items.Count > 0) { menuItem.Submenu = FromMenu (item.SubMenu, null); } return menuItem; }
public override void InformMousePress (TextEditor editor, Margin margin, MarginMouseEventArgs args) { if (!(margin is ActionMargin)) return; var debugModeSet = Runtime.ProcessService.GetDebugExecutionMode (); var menu = new ContextMenu (); if (unitTest.IsFixture) { var menuItem = new ContextMenuItem ("_Run All"); menuItem.Clicked += new TestRunner (doc, unitTest.UnitTestIdentifier, false).Run; menu.Items.Add (menuItem); if (debugModeSet != null) { menuItem = new ContextMenuItem ("_Debug All"); menuItem.Clicked += new TestRunner (doc, unitTest.UnitTestIdentifier, true).Run; menu.Items.Add (menuItem); } menuItem = new ContextMenuItem ("_Select in Test Pad"); menuItem.Clicked += new TestRunner (doc, unitTest.UnitTestIdentifier, true).Select; menu.Items.Add (menuItem); } else { if (unitTest.TestCases.Count == 0) { var menuItem = new ContextMenuItem ("_Run"); menuItem.Clicked += new TestRunner (doc, unitTest.UnitTestIdentifier, false).Run; menu.Items.Add (menuItem); if (debugModeSet != null) { menuItem = new ContextMenuItem ("_Debug"); menuItem.Clicked += new TestRunner (doc, unitTest.UnitTestIdentifier, true).Run; menu.Items.Add (menuItem); } menuItem = new ContextMenuItem ("_Select in Test Pad"); menuItem.Clicked += new TestRunner (doc, unitTest.UnitTestIdentifier, true).Select; menu.Items.Add (menuItem); } else { var menuItem = new ContextMenuItem ("_Run All"); menuItem.Clicked += new TestRunner (doc, unitTest.UnitTestIdentifier, false).Run; menu.Items.Add (menuItem); if (debugModeSet != null) { menuItem = new ContextMenuItem ("_Debug All"); menuItem.Clicked += new TestRunner (doc, unitTest.UnitTestIdentifier, true).Run; menu.Items.Add (menuItem); } menu.Items.Add (new SeparatorContextMenuItem ()); foreach (var id in unitTest.TestCases) { var submenu = new ContextMenu (); menuItem = new ContextMenuItem ("_Run"); menuItem.Clicked += new TestRunner (doc, unitTest.UnitTestIdentifier + id, false).Run; submenu.Items.Add (menuItem); if (debugModeSet != null) { menuItem = new ContextMenuItem ("_Debug"); menuItem.Clicked += new TestRunner (doc, unitTest.UnitTestIdentifier + id, true).Run; submenu.Items.Add (menuItem); } var label = "Test" + id; string tooltip = null; var test = NUnitService.Instance.SearchTestById (unitTest.UnitTestIdentifier + id); if (test != null) { var result = test.GetLastResult (); if (result != null && result.IsFailure) { tooltip = result.Message; label += "!"; } } menuItem = new ContextMenuItem ("_Select in Test Pad"); menuItem.Clicked += new TestRunner (doc, unitTest.UnitTestIdentifier + id, true).Select; submenu.Items.Add (menuItem); var subMenuItem = new ContextMenuItem (label); //if (!string.IsNullOrEmpty (tooltip)) // subMenuItem.TooltipText = tooltip; subMenuItem.SubMenu = submenu; menu.Items.Add (subMenuItem); } } } menu.Show (editor, (int)(args.X + margin.XOffset), (int)args.Y); }