상속: System.Windows.Forms.Layout.ArrangedElementCollection, IList, ICollection, IEnumerable
예제 #1
0
        public DynamicMenu(ToolStripItemCollection tsicHost)
        {
            Debug.Assert(tsicHost != null);
            if(tsicHost == null) throw new ArgumentNullException("tsicHost");

            m_tsicHost = tsicHost;
        }
예제 #2
0
    /// <summary>
    /// Recherche une suite de séparateurs consécutifs
    /// </summary>
    /// <param name="items">collection d'éléments de menus où s'effectue la recherche</param>
    /// <param name="from">index du premier élément à considérer</param>
    /// <param name="start">index du premier séparateur de la suite</param>
    /// <param name="end">index du dernier séparateur de la suite</param>
    /// <returns>true si au moins un séparateur a été trouvé</returns>
    private static bool DoHasSeparators( ToolStripItemCollection items, int from, ref int start, ref int end ) {
      start = from;
      end = start - 1;
      bool found = false;

      // rechercher le premier séparateur
      for (int ix = from ; ix < items.Count ; ix++) {
        if (!(items[ ix ] is ToolStripSeparator)) continue;
        start = ix;
        found = true;
        break;
      }

      // pas de séparateur trouvé
      if (!found) return false;

      // rechercher le dernier séparateur de la suite
      end = start;
      for (int ix = start + 1 ; ix < items.Count ; ix++) {
        if (!(items[ ix ] is ToolStripSeparator)) break;
        end = ix;
      }

      return true;
    }
 public void Initialize(IMyGenerationMDI mdi, ToolStripItemCollection menuItems)
 {
     this.scintilla.AddShortcuts(menuItems);
     this._fileId = Guid.NewGuid().ToString();
     _mdi = mdi;
     RefreshConnectionInfo();
 }
예제 #4
0
        // Constructor required by plugins
        public DynamicMenu(ToolStripDropDownItem tsmiHost)
        {
            Debug.Assert(tsmiHost != null);
            if(tsmiHost == null) throw new ArgumentNullException("tsmiHost");

            m_tsicHost = tsmiHost.DropDownItems;
        }
예제 #5
0
		/// <summary>
		/// Assert that the strip has no menu item with the specified text.
		/// </summary>
		/// <param name="items"></param>
		/// <param name="text"></param>
		/// <returns></returns>
		private static void AssertHasNoMenuWithText(ToolStripItemCollection items, string text)
		{
			if (items.Cast<ToolStripItem>().Any(item => item is ToolStripMenuItem && (item as ToolStripMenuItem).Text == text))
			{
				Assert.Fail("item " + text + " was unexpectedly found in a context menu");
			}
		}
예제 #6
0
        private static void PopulateItems(ToolStripItemCollection items, IEnumerable<CommandMenuGroup> groups, CommandRegistry registry)
        {
            List<CommandMenuGroup> groupList = groups as List<CommandMenuGroup>;
            if (groupList == null)
                groupList = new List<CommandMenuGroup>(groups);

            foreach (CommandMenuGroup group in groupList) {
                if (group != groupList[0])
                    items.Add(new ToolStripSeparator());

                foreach (CommandMenuEntry entry in group) {
                    if (entry.SubMenu != null)
                        items.Add(BuildToolStripMenu(entry.SubMenu, registry));
                    else {
                        CommandRecord record = registry.Lookup(entry.Key);
                        if (record != null) {
                            ToolStripMenuItem menuItem = new ToolStripMenuItem() {
                                Tag = new CommandMenuTag(entry.Key, entry.Param),
                                Text = record.DisplayName,
                                Image = record.Image,
                                ShortcutKeys = record.Shortcut,
                                ShortcutKeyDisplayString = record.ShortcutDisplay,
                                ToolTipText = record.Description,
                            };

                            if (entry.Default)
                                menuItem.Font = new Font(menuItem.Font, menuItem.Font.Style | FontStyle.Bold);

                            items.Add(menuItem);
                        }
                    }
                }
            }
        }
        //////////////////////////////////////////////////////////////////////////
        public void SetToolStripState(ToolStripItemCollection Items)
        {
            foreach(ToolStripItem Item in Items)
            {
                string ActName = Item.Tag as string;
                if (ActName != null)
                {
                    Action.State St = ActContext.GetState(ActName);

                    Item.Enabled = ((St & Action.State.Disabled) != Action.State.Disabled);
                    Item.Visible = ((St & Action.State.Hidden) != Action.State.Hidden);

                    if (Item is ToolStripButton)
                        ((ToolStripButton)Item).Checked = ((St & Action.State.Checked) == Action.State.Checked);
                    else if (Item is ToolStripMenuItem)
                        ((ToolStripMenuItem)Item).Checked = ((St & Action.State.Checked) == Action.State.Checked);

                }

                if(Item is ToolStripDropDownItem)
                {
                    SetToolStripState(((ToolStripDropDownItem)Item).DropDownItems);
                }
            }
        }
 private static void FillMenuItems(List<MySQL.Base.MenuItem> itemsBE, ToolStripItemCollection itemsFE)
 {
     foreach (MySQL.Base.MenuItem itemBE in itemsBE)
       {
     switch (itemBE.get_type())
     {
       case MySQL.Base.MenuItemType.MenuSeparator:
     {
       itemsFE.Add(new ToolStripSeparator());
     }
     break;
       default:
     {
       ToolStripMenuItem itemFE = new ToolStripMenuItem();
       itemFE.Tag = itemBE.get_name();
       itemFE.Text = itemBE.get_caption();
       itemFE.Enabled = itemBE.get_enabled();
       if (MySQL.Base.MenuItemType.MenuCascade == itemBE.get_type())
       {
         FillMenuItems(itemBE.get_subitems(), itemFE.DropDownItems);
       }
       else
       {
         itemFE.Click += new EventHandler(OnMenuItemClick);
       }
       itemsFE.Add(itemFE);
     }
     break;
     }
       }
 }
예제 #9
0
        /// <summary>
        /// Read a streams file adding submenus and items to a context menu.
        /// </summary>
        /// <param name="filepath">Path to the streams file to read lines from.</param>
        /// <param name="menu">Target context menu.</param>
        /// <param name="onClick">Click event to attach to menu items.</param>
        public void Read(String filepath, ContextMenuStrip menu, EventHandler onClick)
        {
            this.filepath = filepath;
            this.menu = menu;
            this.onClick = onClick;

            try
            {
                // start at the menu root:
                currentMenuItemCollection = menu.Items;

                foreach (String line in File.ReadLines(filepath))
                {
                    currentLineNumber++;
                    currentLine = line;
                    ReadLine(line);
                }

                // add pending items for the last submenu:
                AddCurrentMenuItems();
            }
            finally
            {
                ResetState();
            }
        }
예제 #10
0
 public ToolController(ToolStripItemCollection collection, Viewport viewport, Project project)
 {
     Tools = collection;
     Viewport = viewport;
     Viewport.Input.MouseClick += ViewportClick;
     Project = project;
 }
예제 #11
0
 public static void BuildMenu(ToolStripItemCollection items, IEnumerable<IEditorScript> scripts, Action<IEditorScript> callback)
 {
   foreach (var script in scripts)
   {
     if (script.Name.StartsWith("----"))
     {
       items.Add(new ToolStripSeparator());
     }
     else if (script.Children.Any())
     {
       var item = new ToolStripMenuItem(script.Name);
       BuildMenu(item.DropDownItems, script.Children, callback);
       items.Add(item);
     }
     else
     {
       items.Add(new ToolStripMenuItem(script.Name, null, (s, ev) =>
       {
         var query = script.Script; // Trigger execution
         if (!string.IsNullOrEmpty(query))
         {
           callback(script);
         }
       }));
     }
   }
 }
예제 #12
0
        private static int BuildMenuContentsForGroup(int index, ICommandTarget target, ToolStripItemCollection children, IPoderosaMenuGroup grp) {
            int count = 0;
            foreach (IPoderosaMenu m in grp.ChildMenus) {
                ToolStripMenuItem mi = new ToolStripMenuItem();
                children.Insert(index++, mi); //途中挿入のことも
                mi.DropDownOpening += new EventHandler(OnPopupMenu);
                mi.Enabled = m.IsEnabled(target);
                mi.Checked = mi.Enabled ? m.IsChecked(target) : false;
                mi.Text = m.Text; //Enabledを先に
                mi.Tag = new MenuItemTag(grp, m, target);

                IPoderosaMenuFolder folder;
                IPoderosaMenuItem leaf;
                if ((folder = m as IPoderosaMenuFolder) != null) {
                    BuildMenuContents(mi, folder);
                }
                else if ((leaf = m as IPoderosaMenuItem) != null) {
                    mi.Click += new EventHandler(OnClickMenu);
                    IGeneralCommand gc = leaf.AssociatedCommand as IGeneralCommand;
                    if (gc != null)
                        mi.ShortcutKeyDisplayString = WinFormsUtil.FormatShortcut(CommandManagerPlugin.Instance.CurrentKeyBinds.GetKey(gc));
                }

                count++;
            }

            return count;
        }
예제 #13
0
 public static void BuildMenu(ToolStripItemCollection items, IEnumerable<IEditorScript> scripts, Func<IEditorScript, Task> callback)
 {
   foreach (var script in scripts)
   {
     if (script.Name.StartsWith("----"))
     {
       items.Add(new ToolStripSeparator());
     }
     else if (script.Children.Any())
     {
       var item = new ToolStripMenuItem(script.Name);
       BuildMenu(item.DropDownItems, script.Children, callback);
       items.Add(item);
     }
     else
     {
       items.Add(new ToolStripMenuItem(script.Name, null, async (s, ev) =>
       {
         var text = await script.GetScript(); // Trigger execution
         if (!string.IsNullOrEmpty(text))
         {
           await callback(script);
         }
       }));
     }
   }
 }
예제 #14
0
 public void AddMenuItem(ToolStripItemCollection collection, int index, String fileName, EventHandler handler)
 {
     ToolStripMenuItem item = new ToolStripMenuItem ();
     item.Text = fileName;
     item.Click += new EventHandler (handler);
     collection.Insert (index, item);
 }
예제 #15
0
        public void GetPluginMenuItems(System.Windows.Forms.ToolStripItemCollection menu)
        {
            ICollection <System.Windows.Forms.ToolStripItem> _items = new List <System.Windows.Forms.ToolStripItem>();

            Server.GetPluginMenuItems(_items);
            menu.AddRange(_items.ToArray <ToolStripItem>());
        }
예제 #16
0
 private static void CreateButton(ToolStripItemCollection items, string title, EventHandler handler,
     Workitem item)
 {
     var button = new ToolStripMenuItem(title, null, handler);
     items.Add(button);
     button.Tag = item;
 }
예제 #17
0
 internal void WireItems(ToolStripItemCollection collection)
 {
     foreach (System.Windows.Forms.ToolStripItem item in collection)
     {
         ItemAdded(null, new ToolStripItemEventArgs(item));
     }
 }
예제 #18
0
 internal static void UpdateControlsForLanguage(ToolStripItemCollection toolStripItems)
 {
     foreach (ToolStripItem i in toolStripItems)
     {
         if (!String.IsNullOrEmpty(Lang.ResourceManager.GetString(i.Name, Lang.Culture)))
             i.Text = Lang.ResourceManager.GetString(i.Name, Lang.Culture);
     }
 }
예제 #19
0
        protected ToolStripDropDownItem()
            : base()
        {
            _dropDownItems = new ToolStripItemCollection(Parent, null);

            ArrowColor = Color.Black;
            ArrowImage = ApplicationBehaviour.Resources.Images.DropDownRightArrow;
        }
예제 #20
0
 private void AssignPayPalMenuItems(ToolStripItemCollection dropDownItems)
 {
     dropDownItems.AddRange(new ToolStripItem[]
     {
         donateInUSDollarsToolStripMenuItem,
         donateInEuroToolStripMenuItem,
         donateInGBPToolStripMenuItem
     });
 }
 public static void ApplyResources(this ComponentResourceManager rm, ToolStripItemCollection items)
 {
     foreach (ToolStripItem item in items)
     {
         rm.ApplyResources(item, item.Name);
         if (item is ToolStripMenuItem)
             ApplyResources(rm, (item as ToolStripMenuItem).DropDownItems);
     }
 }
        public static void Sort(ToolStripItemCollection collection, IComparer comparer)
        {
            ArrayList items = new ArrayList(collection);
            items.Sort(comparer);

            collection.Clear();
            foreach (object itm in items)
                collection.Add(itm as ToolStripItem);
        }
예제 #23
0
		public void ApplyTo(ToolStripItemCollection tsic)
		{
			if(tsic == null) throw new ArgumentNullException("tsic");

			Dictionary<string, string> dict = this.ToDictionary();
			if(dict.Count == 0) return;

			this.ApplyTo(tsic, dict);
		}
예제 #24
0
 public HistoryMenu(TSItems root, string text)
 {
     this.root = root;
     root.AddRange(new TSItem[] {
         index     = new TSLabel(text),
         clearMenu = new TSMenuItem(Language.ClearHistory, null, HandleClearClick)
         {
             Enabled = false,
         },
     });
 }
예제 #25
0
        public ToolStrip()
        {
            _items = new ToolStripItemCollection(this, null);
            p_args = new PaintEventArgs();

            BackColor = Color.FromArgb(246, 246, 246);
            BorderColor = Color.FromArgb(204, 206, 219);
            Orientation = Forms.Orientation.Vertical;

            Owner.UpClick += Application_UpClick;
        }
예제 #26
0
        public ToolStrip(ToolStripItem[] items)
        {
            _items = new ToolStripItemCollection(this, items);
            _items.AddRange(items);

            BackColor = Color.FromArgb(246, 246, 246);
            BorderColor = Color.FromArgb(204, 206, 219);
            Orientation = Forms.Orientation.Vertical;

            Owner.UpClick += Application_UpClick;
        }
예제 #27
0
 private bool findItem(ToolStripMenuItem item, ToolStripItemCollection items)
 {
     foreach (ToolStripItem i in items)
         if (i == item) return true;
         else if (i is ToolStripMenuItem)
         {
             ToolStripMenuItem mi = i as ToolStripMenuItem;
             if (mi.DropDown.Items.Count > 0 && findItem(item, mi.DropDown.Items)) return true;
         }
     return false;
 }
예제 #28
0
		ToolStripMenuItem GetNamedChild(ToolStripItemCollection container, string name)
		{
			foreach (ToolStripMenuItem item in container)
				if (name == item.Text)
					return item as ToolStripMenuItem;

			ToolStripMenuItem newItem = new ToolStripMenuItem(name);
			container.Add(newItem);

			return newItem;
		}
 //////////////////////////////////////////////////////////////////////////
 public void AddToolStrip(ActionStripItem Root, ToolStripItemCollection Items, bool AsMenu)
 {
     foreach(ManagedToolStrip Strip in ManagedStrips)
     {
         if(Strip.Items==Items)
         {
             ManagedStrips.Remove(Strip);
             break;
         }
     }
     ManagedStrips.Add(new ManagedToolStrip(Root, Items, AsMenu));
 }
예제 #30
0
        /// <summary>
        /// Builds ands returns a context menu for branches
        /// </summary>
        public ToolStripItemCollection GetContextMenu(ToolStrip owner)
        {
            ToolStripMenuItem mNew = new ToolStripMenuItem("New...", null, MenuNewRepoClick);
            ToolStripMenuItem mScan = new ToolStripMenuItem("Scan...", null, MenuScanRepoClick);
            ToolStripMenuItem mEdit = new ToolStripMenuItem("Edit...", null, MenuRepoEditClick);
            ToolStripMenuItem mDelete = new ToolStripMenuItem("Delete...", null, MenuDeleteRepoClick);
            ToolStripMenuItem mClone = new ToolStripMenuItem("Clone...", null, MenuNewRepoClick);
            ToolStripMenuItem mSwitchTo = new ToolStripMenuItem("Switch to...", null, ListReposDoubleClick);
            ToolStripMenuItem mSetDefault = new ToolStripMenuItem("Set Default to...", null, MenuSetDefaultRepoToClick);
            ToolStripMenuItem mCommand = new ToolStripMenuItem("Command Prompt...", null, MenuViewCommandClick);
            ToolStripMenuItem mRefresh = new ToolStripMenuItem("Refresh", null, MenuRefreshClick, Keys.F5);

            ToolStripItemCollection menu = new ToolStripItemCollection(owner, new ToolStripItem[] {
                mNew, mScan, mEdit, mDelete, mClone,
                new ToolStripSeparator(),
                mSwitchTo, mSetDefault, mCommand,
                new ToolStripSeparator(),
                mRefresh
            });

            // Disable some menus depending on few rules
            ClassRepo repo = GetSelectedRepo();

            if (repo == null)
                mEdit.Enabled = mDelete.Enabled = mClone.Enabled = mSwitchTo.Enabled = mSetDefault.Enabled = mCommand.Enabled = false;
            else
            {
                mNew.Tag = String.Empty;
                if (repo == App.Repos.Current)
                    mSwitchTo.Enabled = false;

                if (repo == App.Repos.Default)
                    mSetDefault.Enabled = false;
            }
            // We can delete a number of repos
            if (listRepos.SelectedIndices.Count > 1)
            {
                mDelete.Enabled = true;
                mCommand.Enabled = false;
                mClone.Enabled = false;
            }

            // Add the specific singular repo name
            if (listRepos.SelectedIndices.Count == 1)
            {
                string repoName = listRepos.SelectedItems[0].Text.Replace('\\', '/').Split('/').Last();
                mSwitchTo.Text = "Switch to " + repoName;
                mSetDefault.Text = "Set Default to " + repoName;
                mClone.Tag = App.Repos.Repos[listRepos.SelectedIndices[0]];
            }

            return menu;
        }
예제 #31
0
 /// <summary>
 /// Fills items to the specified tool strip item collection
 /// </summary>
 public static void FillToolItems(ToolStripItemCollection items, XmlNode node)
 {
     switch (node.Name)
     {
         case "separator":
             items.Add(GetSeparator(node));
             break;
         case "button":
             items.Add(GetButtonItem(node));
             break;
     }
 }
예제 #32
0
		/// <summary>
		/// Assert that the strip has a menu item with the specified text, and return the menu item.
		/// </summary>
		/// <param name="items">Collection of menu items</param>
		/// <param name="text">Menu item under test</param>
		/// <param name="cSubMenuItems">Number of submenu items under the item under test</param>
		/// <returns></returns>
		private static ToolStripMenuItem AssertHasMenuWithText(ToolStripItemCollection items, string text, int cSubMenuItems)
		{
			foreach (ToolStripItem item1 in items)
			{
				var item = item1 as ToolStripMenuItem;
				if (item == null || item.Text != text)
					continue;
				Assert.AreEqual(cSubMenuItems, item.DropDownItems.Count, "item " + text + " has wrong number of items");
				return item;
			}
			Assert.Fail("menu should contain item " + text);
			return null;
		}
 public static void Update(System.Windows.Forms.ToolStripItemCollection toolStripItemCollection,
                           ToolStripItemCodonCollection codonCollection)
 {
     if (codonCollection == null || toolStripItemCollection == null)
     {
         Debug.Assert(false, "ToolStripItemCollection 或 CodonCollection为null");
         return;
     }
     toolStripItemCollection.Clear();
     foreach (IToolStripItemCodon codon in codonCollection)
     {
         toolStripItemCollection.Add((ToolStripItem)codon.View);
     }
 }
예제 #34
0
 private void ResizeMenuStripItems(System.Windows.Forms.ToolStripItemCollection ctrl, double multiplyer)
 {
     if (ctrl.Count > 0)
     {
         foreach (ToolStripMenuItem control in ctrl)
         {
             control.AutoSize = false;
             if (control.DropDownItems.Count > 0)
             {
                 ResizeMenuStripItems(control.DropDownItems, multiplyer);
             }
             control.Height = (int)(control.Height * multiplyer);
         }
     }
 }
예제 #35
0
 public override void InitializeBackend(object frontend, ApplicationContext context)
 {
     base.InitializeBackend(frontend, context);
     Menu                      = new SWF.MenuStrip();
     ItemsCollection           = Menu.Items;
     _items.CollectionChanged += (sender, args) => {
         var backend = args.NewItems.Cast <MenuItemBackend> ().FirstOrDefault();
         if (args.Action == NotifyCollectionChangedAction.Add)
         {
             ItemsCollection.Insert(args.NewStartingIndex, backend.MenuItem);
         }
         if (args.Action == NotifyCollectionChangedAction.Remove)
         {
             ItemsCollection.Remove(backend.MenuItem);
         }
     };
 }
예제 #36
0
            internal AccessibleObject?GetChildFragment(int fragmentIndex, UiaCore.NavigateDirection direction, bool getOverflowItem = false)
            {
                if (fragmentIndex < 0)
                {
                    return(null);
                }

                ToolStripItemCollection items = getOverflowItem
                    ? _owningToolStrip.OverflowItems
                    : _owningToolStrip.DisplayedItems;

                if (!getOverflowItem &&
                    _owningToolStrip.CanOverflow &&
                    _owningToolStrip.OverflowButton.Visible &&
                    fragmentIndex == items.Count - 1)
                {
                    return(_owningToolStrip.OverflowButton.AccessibilityObject);
                }

                if (fragmentIndex < items.Count)
                {
                    ToolStripItem item = items[fragmentIndex];
                    if (item.Available && item.Alignment == ToolStripItemAlignment.Left)
                    {
                        return(GetItemAccessibleObject(item));
                    }
                }

                List <ToolStripItem> orderedItems = new();

                for (int i = 0, current = 0; i < _owningToolStrip.Items.Count; i++)
                {
                    ToolStripItem item = _owningToolStrip.Items[i];
                    orderedItems.Insert(current, item);
                    if (item.Alignment == ToolStripItemAlignment.Left)
                    {
                        current++;
                    }
                }

                if (fragmentIndex < orderedItems.Count)
                {
                    ToolStripItem item = orderedItems[fragmentIndex];
                    if (item.Available && item.Alignment == ToolStripItemAlignment.Right)
                    {
                        return(GetItemAccessibleObject(item));
                    }
                }

                return(null);

                AccessibleObject?GetItemAccessibleObject(ToolStripItem item)
                {
                    if (item is ToolStripControlHost controlHostItem)
                    {
                        if (ShouldItemBeSkipped(controlHostItem.Control))
                        {
                            return(GetFollowingChildFragment(fragmentIndex, items, direction));
                        }

                        return(controlHostItem.ControlAccessibilityObject);
                    }

                    return(item.AccessibilityObject);
                }
            }
예제 #37
0
        public ClipboardApplication()
        {
            clipboardNotifier.ClipboardChanged += HandleClipboard;

            if (settings.autoCleanInterval > 0)
            {
                cleanupTimer.Interval = settings.autoCleanInterval * 1000;
            }
            cleanupTimer.Tick += HandleCleanUpClicked;

            notifyIcon.DoubleClick += HandleCleanUpClicked;

            NumericUpDown intervalItemBox = new NumericUpDown {
                Minimum = 0,
                Maximum = int.MaxValue,
                Value   = settings.autoCleanInterval,
            };

            intervalItemBox.ValueChanged += HandleIntervalChange;
            NumericUpDown historyCountBox = new NumericUpDown {
                Minimum = 0,
                Maximum = int.MaxValue,
                Value   = settings.maxHistoryObjects,
            };

            historyCountBox.ValueChanged += HandleHistoryCountChange;

            TSItems children = notifyIcon.ContextMenuStrip.Items;

            children.AddRange(new TSItem[] {
                new TSLabel(string.Format(Language.Caption, Application.ProductName, Application.ProductVersion)),

                new TSSeparator(),

                new TSLabel(Language.ExistsDataCaption),
                dataDisplay,
                imageDataDisplay,
                new TSMenuItem(Language.ClearNow, null, HandleCleanUpClicked),
                new TSMenuItem(Language.Pin, null, HandlePinClick),

                new TSSeparator(),
            });

            pinned = new HistoryMenu(children, Language.PinnedMenu);

            children.Add(new TSSeparator());

            history = new HistoryMenu(children, Language.HistoryMenu)
            {
                removeOnUse = true
            };

            children.AddRange(new TSItem[] {
                new TSSeparator(),

                new TSLabel(Language.AutoCleanAt),
                new ToolStripControlHost(intervalItemBox),
                new TSLabel(Language.EnableHistory),
                new ToolStripControlHost(historyCountBox),
                new TSMenuItem(Language.NotifyChanges, null, HandleNotifyToggle)
                {
                    Checked = settings.notifyEnabled,
                },
                new TSMenuItem(Language.RunAtStartup, null, RunAtStartupClick)
                {
                    Checked = RunAtStartup
                },

                new TSSeparator(),

                new TSMenuItem(Language.Exit, null, HandleExitClick),
            });

            HandleClipboard(false, Clipboard.GetDataObject());
            Application.ApplicationExit += HandleApplicationExit;
        }