コード例 #1
0
        private bool AddRecursivelyAux(Gtk.MenuShell shell, List <MenuLayout> menus, BasicWidgetType type, ref Gtk.Widget widget, int level)
        {
            if (menus.Count <= 0)
            {
                return(false);
            }

            foreach (MenuLayout menu in menus)
            {
                Gtk.MenuItem menuitem = null;
                if (menu is MenuSeparator)
                {
                    menuitem = new Gtk.SeparatorMenuItem();
                    if (type == BasicWidgetType.ChildMenuSeparator)
                    {
                        widget = menuitem;
                    }
                }
                else
                {
                    menuitem = new Gtk.MenuItem(menu.Label);

                    Gtk.Menu menushell = new Gtk.Menu();
                    if (AddRecursivelyAux(menushell, menu.SubMenus, type, ref widget, level + 1))
                    {
                        menuitem.Submenu = menushell;
                        if ((widget == null) && (level == 0))
                        {
                            widget = menuitem;
                        }
                    }
                    else
                    {
                        if (widget == null && type == BasicWidgetType.ChildMenu)
                        {
                            widget = menuitem;
                        }
                    }
                }

                shell.Append(menuitem);
                menuitem.Show();
            }
            shell.ShowAll();
            return(true);
        }
コード例 #2
0
 ///
 MenuItemType ISolidIDE.GetMenuItem <MenuItemType>(params string[] names)
 {
     Gtk.MenuShell menu = (this as ISolidIDE).GetMainMenu();
     Gtk.MenuItem  item = null;
     for (int i = 0; i < names.Length; i++)
     {
         item = null;
         foreach (Gtk.Widget w in menu.Children)
         {
             if (w.Name == names[i] + "Action")
             {
                 item = w as Gtk.ImageMenuItem;
                 if (i < names.Length - 1)
                 {
                     if (item.Submenu == null)
                     {
                         item.Submenu = new Gtk.Menu();
                     }
                     menu = item.Submenu as Gtk.MenuShell;
                 }
                 break;
             }
         }
         if (item == null)
         {
             item = new MenuItemType();
             Gtk.AccelLabel accelLabel = new Gtk.AccelLabel("");
             accelLabel.TextWithMnemonic = names[i];
             accelLabel.SetAlignment(0f, 0.5f);
             item.Add(accelLabel);
             accelLabel.AccelWidget = item;
             item.Name = names[i] + "Action";
             menu.Append(item);
             if (i < names.Length - 1)
             {
                 item.Submenu = new Gtk.Menu();
             }
             menu = item.Submenu as Gtk.MenuShell;
         }
     }
     return(item as MenuItemType);
 }
コード例 #3
0
        /// <summary>
        /// Creates a menu item for command.
        /// </summary>
        /// <param name="command">The command for which a menu item is to be created.</param>
        /// <param name="parentMenu">The menu to put the menu item into.</param>
        /// <param name="parentCommand">Parent command for the given command.</param>
        /// <param name="stockItem">If non-Zero, defines the stock item to use for the command.</param>
        /// <param name="menuItemType">A specific type of menu item to use.</param>
        /// <param name="stateData">If not <c>null</c>, state data for the menu item being created.</param>
        /// <returns>The menu item for the command.</returns>
        public static OSMenuItem CreateMenuItem(this VisualRelayCommand command, Gtk.MenuShell parentMenu, VisualRelayCommand parentCommand, Gtk.StockItem stockItem, System.Type menuItemType = null, object stateData = null)
        {
            var useDefaultMenuHandler = true;

            Gtk.MenuItem menuItemVisual;

            if (command.UniqueId == RootCommandGroup.MenuSeparatorCommand.UniqueId)
            {
                menuItemVisual        = new Gtk.SeparatorMenuItem();
                useDefaultMenuHandler = false;
            }
            else if (menuItemType == typeof(Gtk.CheckMenuItem))
            {
                var checkMenuItem = new Gtk.CheckMenuItem(command.MenuItemName);
                checkMenuItem.Active  = (bool)stateData;
                menuItemVisual        = checkMenuItem;
                useDefaultMenuHandler = false;
            }
            else if ((command.SmallIcon != null) || (stockItem.StockId != Gtk.StockItem.Zero.StockId))
            {
                if (stockItem.StockId == Gtk.StockItem.Zero.StockId)
                {
                    menuItemVisual = new Gtk.ImageMenuItem(command.MenuItemName)
                    {
                        Image = new Gtk.Image(command.SmallIcon)
                    };
                    if (Properties.Settings.Default.EnableMenuIcons)
                    {
                        // NOTE: This causes some internal errors if we try to draw stock items. So don't do it.
                        menuItemVisual.ExposeEvent += ImageMenuItemHackExposeEvent;
                    }
                }
                else
                {
                    menuItemVisual = new Gtk.ImageMenuItem(stockItem.StockId, null);
                }
            }
            else
            {
                menuItemVisual = new Gtk.MenuItem(command.MenuItemName);
            }

            menuItemVisual.Name = command.UniqueId;
            menuItemVisual.SetValue(CommandGroup.AttachedCommandPropertyName, command);
            var submenu = command.Visual.AsType <Gtk.Menu>();

            if ((submenu == null) && (parentMenu is Gtk.MenuBar) && command.Visual.IsEmpty)
            {
                submenu = new Gtk.Menu()
                {
                    Name = parentCommand.UniqueId
                };
                command.Visual = submenu;
            }
            menuItemVisual.Submenu = submenu;

            var insertLocation = FindInsertLocation(parentCommand, command, true);

            if ((insertLocation < 0) || (insertLocation >= parentMenu.Children.Length))
            {
                parentMenu.Append(menuItemVisual);
            }
            else
            {
                parentMenu.Insert(menuItemVisual, insertLocation);
            }

            if (useDefaultMenuHandler && (menuItemVisual.Submenu == null))
            {
                menuItemVisual.Activated += HandleCommand;
            }
            if (!string.IsNullOrEmpty(command.KeyboardShortcutKey))
            {
                command.AddAccelerator(menuItemVisual, command.GetAcceleratorKey());
            }
            menuItemVisual.ShowAll(); // because programmatically created, need to show
            ////DebugOutputIf(requiresParentCommand && (parentCommand.MenuItem.IsEmpty) && (parentCommand.Visual.IsEmpty), "Failed to create parent menu item for command: " + command.Name + "(" + command.UniqueId + ")");

            ////DebugOutputIf(requiresParentCommand && (parentCommand == null) && (parentCommand.Visual.IsEmpty), "No parent menu item for command: " + command.Name + "(" + command.UniqueId + ")");
            if (menuItemVisual != null)
            {
                var group = command.GetCommandGroup() as CommandGroup;
                if (group != null)
                {
                    var context = group.GetCommandContext(command, null);
                    menuItemVisual.SetValue(IFakeDependencyObjectHelpers.DataContextPropertyName, context);
                    group.AttachCanExecuteChangeHandler(command);
                }
            }
            return(menuItemVisual);
        }