示例#1
0
        public static GenericMenu AddSep(this GenericMenu menu, string text) {
    #if UNITY_EDITOR_WIN
            menu.AddSeparator(text);
    #else
            if (string.IsNullOrEmpty(text) || (text.IndexOf("/") == -1)){
			    menu.AddSeparator(text);
		    } else {
                menu.AddSeparator((text ?? "") + "--------------------");
		    }
    #endif
            return menu;
        }
示例#2
0
        public static void NewKeybind(this Menu menu, string identifier, string displayName, bool defaultValue, KeyBind.BindTypes bindType, char key, bool separatorBefore = false)
        {
            if (separatorBefore) menu.AddSeparator();

            menu.Add(identifier, new KeyBind(displayName, defaultValue, bindType, key));

            Menus[menu.Parent.DisplayName][menu.DisplayName][menu].Add(identifier, Values.KeyBind);
        }
示例#3
0
        public static void NewSlider(this Menu menu, string identifier, string displayName, int defaultValue, int minValue, int maxValue, bool separatorBefore = false)
        {
            if (separatorBefore) menu.AddSeparator();

            menu.Add(identifier, new Slider(displayName, defaultValue, minValue, maxValue));

            Menus[menu.Parent.DisplayName][menu.DisplayName][menu].Add(identifier, Values.Slider);
        }
示例#4
0
        public static void NewCheckbox(this Menu menu, string identifier, string displayName, bool defaultValue = true, bool separatorBefore = false)
        {
            if (separatorBefore) menu.AddSeparator();
            
            menu.Add(identifier, new CheckBox(displayName, defaultValue));

            Menus[menu.Parent.DisplayName][menu.DisplayName][menu].Add(identifier, Values.Checkbox);
        }
        public static ToolStripSeparator BindSeparator(this ToolStripDropDown dropDown, CommandManager commandManager, string commandId)
        {
            Lifetime<ICommand> command = commandManager.FindCommand(commandId);
            if (command == null)
                throw new ArgumentException();

            ToolStripSeparator item = dropDown.AddSeparator();
            item.Tag = new ToolStripItemCommandBinding(dropDown, item, command, (object)null);

            return item;
        }
示例#6
0
        public static ContextMenu AddTextBoxItems(this ContextMenu menu) {
            if (!menu.Items.IsEmpty) {
                menu.AddSeparator();
            }

            return menu
                .AddItem(ApplicationCommands.Undo)
                .AddSeparator()
                .AddItem(ApplicationCommands.Cut)
                .AddItem(ApplicationCommands.Copy)
                .AddItem(ApplicationCommands.Paste)
                .AddItem(ApplicationCommands.Delete)
                .AddSeparator()
                .AddItem(ApplicationCommands.SelectAll);
        }
 public static void AddAction(this Menu.MenuItemCollection items, MenuAction action)
 {
     MenuItem item;
     if (action.IsSeparator)
     {
         items.AddSeparator();
     }
     else
     {
         item = new MenuItem
         {
             Name = action.Name,
             Text = action.Caption,
             Enabled = action.Enabled,
             // TODO: see if MenuItem supports this: Image = action.Image,
         };
         // TODO: execute safely (i.e. catch exceptions to report errors) and maybe asynchronously
         item.Click += (clickSender, eventArgs) =>
         {
             var result = action.Execute();
             if (result)
             {
                 var menuItem = (MenuItem) clickSender;
                 var parentMenu = menuItem.GetContextMenu();
                 Debug.Assert(parentMenu != null);
                 var parentControl = parentMenu.SourceControl;
                 while (parentControl != null && !(parentControl is IHistoryContainer))
                 {
                     parentControl = parentControl.Parent;
                 }
                 if (parentControl != null)
                 {
                     var historyContainer = (IHistoryContainer) parentControl;
                     var currentHistoryItem = historyContainer.Current;
                     currentHistoryItem.Reload();
                 }
             }
         };
         items.Add(item);
     }
 }