/* public Gtk.Toolbar CreateToolbar (CommandEntrySet entrySet) { return CreateToolbar ("", entrySet); } */ /// <summary> /// Appends commands to a menu /// </summary> /// <returns> /// The menu. /// </returns> /// <param name='entrySet'> /// Entry set with the command definitions /// </param> /// <param name='menu'> /// The menu where to add the commands /// </param> public Gtk.Menu CreateMenu (CommandEntrySet entrySet, CommandMenu menu) { foreach (CommandEntry entry in entrySet) { Gtk.MenuItem mi = entry.CreateMenuItem (this); CustomItem ci = mi.Child as CustomItem; if (ci != null) ci.SetMenuStyle (menu); menu.Append (mi); } return menu; }
internal void Update() { CommandTargetRoute targetRoute = new CommandTargetRoute(initialCommandTarget); foreach (Gtk.Widget item in Children) { if (item is ICommandUserItem) { ((ICommandUserItem)item).Update(targetRoute); } else if (item is Gtk.MenuItem) { Gtk.MenuItem mitem = (Gtk.MenuItem)item; CommandMenu men = mitem.Submenu as CommandMenu; if (men != null) { men.InitialCommandTarget = initialCommandTarget; } item.Show(); if (item is AutoHideMenuItem) { men.Update(); if (!((AutoHideMenuItem)item).HasVisibleChildren) { item.Hide(); } } } else { item.Show(); } } // After updating the menu, hide the separators which don't actually // separate items. bool prevWasItem = false; Gtk.Widget lastSeparator = null; foreach (Gtk.Widget item in Children) { if (item is Gtk.SeparatorMenuItem) { if (!prevWasItem) { item.Hide(); } else { prevWasItem = false; lastSeparator = item; } } else if (item.Visible) { prevWasItem = true; } } if (!prevWasItem && lastSeparator != null) { lastSeparator.Hide(); } }
internal virtual Gtk.ToolItem CreateToolItem (CommandManager manager) { if (cmdId == CommandManager.ToCommandId (Command.Separator)) return new Gtk.SeparatorToolItem (); Command cmd = GetCommand (manager); if (cmd == null) return new Gtk.ToolItem (); if (cmd is CustomCommand) { Gtk.Widget child = (Gtk.Widget) Activator.CreateInstance (((CustomCommand)cmd).WidgetType); Gtk.ToolItem ti; if (child is Gtk.ToolItem) ti = (Gtk.ToolItem) child; else { ti = new Gtk.ToolItem (); ti.Child = child; } if (cmd.Text != null && cmd.Text.Length > 0) { //strip "_" accelerators from tooltips string text = cmd.Text; while (true) { int underscoreIndex = text.IndexOf ('_'); if (underscoreIndex > -1) text = text.Remove (underscoreIndex, 1); else break; } ti.TooltipText = text; } return ti; } ActionCommand acmd = cmd as ActionCommand; if (acmd == null) throw new InvalidOperationException ("Unknown cmd type."); if (acmd.CommandArray) { CommandMenu menu = new CommandMenu (manager); menu.Append (CreateMenuItem (manager)); return new MenuToolButton (menu, acmd.Icon); } else if (acmd.ActionType == ActionType.Normal) return new CommandToolButton (cmdId, manager); else return new CommandToggleToolButton (cmdId, manager); }
internal protected virtual Gtk.ToolItem CreateToolItem(CommandManager manager) { if (cmdId == CommandManager.ToCommandId(Command.Separator)) { return(new Gtk.SeparatorToolItem()); } Command cmd = GetCommand(manager); if (cmd == null) { return(new Gtk.ToolItem()); } if (cmd is CustomCommand) { Gtk.Widget child = (Gtk.Widget)Activator.CreateInstance(((CustomCommand)cmd).WidgetType); Gtk.ToolItem ti; if (child is Gtk.ToolItem) { ti = (Gtk.ToolItem)child; } else { ti = new Gtk.ToolItem(); ti.Child = child; } if (cmd.Text != null && cmd.Text.Length > 0) { //strip "_" accelerators from tooltips string text = cmd.Text; while (true) { int underscoreIndex = text.IndexOf('_'); if (underscoreIndex > -1) { text = text.Remove(underscoreIndex, 1); } else { break; } } ti.TooltipText = text; } return(ti); } ActionCommand acmd = cmd as ActionCommand; if (acmd == null) { throw new InvalidOperationException("Unknown cmd type."); } if (acmd.CommandArray) { CommandMenu menu = new CommandMenu(manager); menu.Append(CreateMenuItem(manager)); return(new MenuToolButton(menu, acmd.Icon)); } else if (acmd.ActionType == ActionType.Normal) { return(new CommandToolButton(cmdId, manager)); } else { return(new CommandToggleToolButton(cmdId, manager)); } }