private CommandBarControl InitializeChildControl(ICommandMenuItem item) { if (item == null) { return(null); } var child = (CommandBarButton)Item.Controls.Add(MsoControlType.msoControlButton, Temporary: true); SetButtonImage(child, item.Image, item.Mask); child.BeginGroup = item.BeginGroup; child.Tag = item.GetType().FullName; child.Caption = item.Caption.Invoke(); var command = item.Command as CommandBase; // todo: add 'ShortcutText' to a new 'interface ICommand : System.Windows.Input.ICommand' child.ShortcutText = command != null ? command.ShortcutText : string.Empty; Debug.WriteLine("Menu item '{0}' created; hash code: {1} (command hash code {2})", child.Caption, child.GetHashCode(), item.Command.GetHashCode()); child.Click += child_Click; return(child); }
private ICommandBarControl InitializeChildControl(ICommandMenuItem item) { if (item == null) { return(null); } ICommandBarButton child; using (var controls = Item.Controls) { child = CommandBarButtonFactory.Create(controls); } child.Picture = item.Image; child.Mask = item.Mask; child.ApplyIcon(); child.BeginsGroup = item.BeginGroup; using (var itemParent = Item.Parent) { child.Tag = $"{itemParent.Name}::{Item.Tag}::{item.GetType().Name}"; } child.Caption = item.Caption.Invoke(); var command = item.Command; // todo: add 'ShortcutText' to a new 'interface CommandBase : System.Windows.Input.CommandBase' child.ShortcutText = command != null ? command.ShortcutText : string.Empty; child.Click += child_Click; return(child); }
private ICommandBarControl InitializeChildControl(ICommandMenuItem item) { if (item == null) { return(null); } ICommandBarButton child; using (var controls = Item.Controls) { child = CommandBarButtonFactory.Create(controls); } child.Style = item.ButtonStyle; child.Picture = item.Image; child.Mask = item.Mask; child.ApplyIcon(); child.IsVisible = item.IsVisible; child.BeginsGroup = item.BeginGroup; child.Tag = item.GetType().FullName; child.Caption = item.Caption.Invoke(); child.TooltipText = item.ToolTipText.Invoke(); if (item.Command != null) { child.Click += child_Click; } return(child); }
protected override void AddUserContextMenu(ContextMenuHelper contextMenu) { try { RegisterCommands(); if (contextMenu != null) { contextMenu.AddContextMenuItem(MaximusCommands.NewDestination, OnNewDestination); // can register callback only ONCE contextMenu.AddContextMenuItem(MaximusCommands.EditDestination, OnEditDestination, OnSingleRowSelectedStatus); // can register callback only ONCE contextMenu.AddContextMenuItem(MaximusCommands.DeleteDestination, OnDeleteDestination, OnDeleteDestinationStatus); // can register callback only ONCE contextMenu.AddContextMenuSeparator(); ICommandMenuItem subMenu = contextMenu.AddContextMenuItem(MaximusCommands.AddTestDropDown, null); if (TestClassesInitialized) { foreach (KeyValuePair <Guid, ManagementPackClass> commandAndClass in TestClassesAddCommands) { contextMenu.AddContextMenuItem(new CommandID(commandAndClass.Key, TestClassCommandId), OnAddNewTest, OnSingleRowSelectedStatus, subMenu); // can register callback only ONCE } } contextMenu.AddContextMenuSeparator(); contextMenu.AddContextMenuItem(MaximusCommands.MaintenanceModeStart, OnMaintenanceModeStart, OnMaintenanceModeStartStatus); // can register callback only ONCE contextMenu.AddContextMenuItem(MaximusCommands.MaintenanceModeEdit, OnMaintenanceModeEdit, OnMaintenanceModeEditStatus); // can register callback only ONCE contextMenu.AddContextMenuItem(MaximusCommands.MaintenanceModeEnd, OnMaintenanceModeEnd, OnMaintenanceModeEditStatus); // can register callback only ONCE contextMenu.AddContextMenuSeparator(); } } catch (Exception e) { MessageBox.Show($"In {System.Reflection.MethodBase.GetCurrentMethod().Name} it said {e.Message}"); } }
private CommandBarControl InitializeChildControl(ICommandMenuItem item) { if (item == null) { return null; } var child = (CommandBarButton)Item.Controls.Add(MsoControlType.msoControlButton, Temporary: true); SetButtonImage(child, item.Image, item.Mask); child.BeginGroup = item.BeginGroup; child.Tag = item.GetType().FullName; child.Caption = item.Caption.Invoke(); var command = item.Command as CommandBase; // todo: add 'ShortcutText' to a new 'interface CommandBase : System.Windows.Input.CommandBase' child.ShortcutText = command != null ? command.ShortcutText : string.Empty; child.Click += child_Click; return child; }
void Update(CommandInfo cmdInfo) { if (lastCmdInfo != null) { lastCmdInfo.CancelAsyncUpdate(); lastCmdInfo.Changed -= CommandInfoChanged; } lastCmdInfo = cmdInfo; lastCmdInfo.Changed += CommandInfoChanged; if (isArray && !isArrayItem) { this.Visible = false; Gtk.Menu menu = (Gtk.Menu)Parent; if (itemArray != null) { foreach (Gtk.MenuItem item in itemArray) { menu.Remove(item); } } itemArray = new ArrayList(); int i = Array.IndexOf(menu.Children, this); if (cmdInfo.ArrayInfo != null) { foreach (CommandInfo info in cmdInfo.ArrayInfo) { Gtk.MenuItem item; if (info.IsArraySeparator) { item = new Gtk.SeparatorMenuItem(); item.Show(); } else { item = CommandEntry.CreateMenuItem(commandManager, commandId, false); ICommandMenuItem mi = (ICommandMenuItem)item; mi.SetUpdateInfo(info, initialTarget); } menu.Insert(item, ++i); itemArray.Add(item); } } } else { Gtk.Widget child = Child; if (child == null) { return; } Gtk.Label accel_label = null; Gtk.Label label = null; if (!(child is Gtk.HBox)) { child = new Gtk.HBox(false, 0); accel_label = new Gtk.Label(""); accel_label.UseUnderline = false; accel_label.Xalign = 1.0f; accel_label.Show(); label = new Gtk.Label(""); label.UseUnderline = true; label.Xalign = 0.0f; label.Show(); ((Gtk.Box)child).PackStart(label); ((Gtk.Box)child).PackStart(accel_label); child.Show(); this.Remove(Child); this.Add(child); } else { accel_label = (Gtk.Label)((Gtk.Box)child).Children[1]; label = (Gtk.Label)((Gtk.Box)child).Children[0]; } if (cmdInfo.AccelKey != null) { accel_label.Text = " " + KeyBindingManager.BindingToDisplayLabel(cmdInfo.AccelKey, true); } else { accel_label.Text = String.Empty; } if (cmdInfo.UseMarkup) { label.Markup = overrideLabel ?? cmdInfo.Text; label.UseMarkup = true; } else { label.Text = overrideLabel ?? cmdInfo.Text; label.UseMarkup = false; } if (!string.IsNullOrEmpty(cmdInfo.Description) && label.TooltipText != cmdInfo.Description) { label.TooltipText = cmdInfo.Description; } label.UseUnderline = true; this.Sensitive = cmdInfo.Enabled; this.Visible = cmdInfo.Visible && (disabledVisible || cmdInfo.Enabled); if (!cmdInfo.Icon.IsNull && cmdInfo.Icon != lastIcon) { Image = new ImageView(cmdInfo.Icon, Gtk.IconSize.Menu); lastIcon = cmdInfo.Icon; } if (cmdInfo is CommandInfoSet) { CommandInfoSet ciset = (CommandInfoSet)cmdInfo; Gtk.Menu smenu = new Gtk.Menu(); Submenu = smenu; foreach (CommandInfo info in ciset.CommandInfos) { Gtk.MenuItem item; if (info.IsArraySeparator) { item = new Gtk.SeparatorMenuItem(); item.Show(); } else { item = CommandEntry.CreateMenuItem(commandManager, commandId, false); ICommandMenuItem mi = (ICommandMenuItem)item; mi.SetUpdateInfo(info, initialTarget); } smenu.Add(item); } } } }