private void CleanupDynamicallyAddedItems() { DropDownItems .OfType <CopyToClipboardToolStripMenuItem>() .ToArray() .ForEach(i => DropDownItems.Remove(i)); }
private void RemoveDropDownItem(string str) { var item = DropDownItems.FirstOrDefault(i => (string)i.Model == str); if (item == null) { return; } item.Clicked -= HandleDropDownItemClicked; Destroy(item.gameObject); DropDownItems.Remove(item); }
private void RemoveDropDownItem(IBoundsProvider provider) { var item = DropDownItems.FirstOrDefault(i => i.Model == provider); if (item == null) { return; } item.Clicked -= HandleDropDownItemClicked; Destroy(item.gameObject); DropDownItems.Remove(item); }
private void PopulateMenuSync(ToolStripItem[] items) { DropDownItems.AddRange(items); var menuItems = AllMenuItems.Except(new[] { _dummyItem }).ToArray(); if (!menuItems.Any()) { DropDownItems.Add(_noDiscItem); } // We need to always keep at least 1 menu item in the dropdown list // to prevent the list from being positioned in the upper-left corner // of the screen. DropDownItems.Remove(_dummyItem); }
protected void moveEntryForward(string entry) { ToolStripMenuItem entryItem = null; for (int i = 0; i < DropDownItems.Count && entryItem == null; i++) { if (DropDownItems[i].Text == entry) { entryItem = (ToolStripMenuItem)DropDownItems[i]; } } if (entryItem != null) { DropDownItems.Remove(entryItem); DropDownItems.Add(entryItem); } }
private void ClearMenu() { // We need to always keep at least 1 menu item in the dropdown list // to prevent the list from being positioned in the upper-left corner // of the screen. DropDownItems.Add(_dummyItem); // Special menu items that should NOT be destroyed var specialItems = new ToolStripItem[] { _noDiscItem, _scanningItem, _dividerItem }; // Disc Drive menu items var destroyableItems = AllMenuItems.Except(specialItems).Except(new[] { _dummyItem }).ToArray(); foreach (var menuItem in destroyableItems) { DestroyMenuItem(menuItem); DropDownItems.Remove(menuItem); } foreach (var menuItem in specialItems) { DropDownItems.Remove(menuItem); } }
void param_PersistentChanged(object sender, EventArgs e) { var param = sender as QueryParam; if (param.IsPersistent) { //添加 var item = DropDownItems.OfType <ToolStripMenuItem>().FirstOrDefault(s => s.Tag == param); if (item == null) { item = new ToolStripMenuItem(param.Name.DefaultForEmpty("<未命名>")) { Tag = param }; item.Click += (x, y) => { var p = ((x as ToolStripMenuItem).Tag as QueryParam); p.IsLoaded = true; Session.UserProfile.QueryParams.SelectedQuery = p; MainForm.Instance.SelectedSession = Session; }; DropDownItems.Add(item); } _emptyItem.Visible = false; } else { //删除 var item = DropDownItems.OfType <ToolStripMenuItem>().FirstOrDefault(s => s.Tag == param); if (item != null) { DropDownItems.Remove(item); } _emptyItem.Visible = DropDownItems.OfType <ToolStripMenuItem>().All(s => s.Tag == null); } }
public FileMenuStripItem(Type[] documentTypes) : base("&File".Localize()) { Name = "MenuFile"; // Construct Menu Items ToolStripMenuItem mNew = new ToolStripMenuItem("&New".Localize()); ToolStripMenuItem mOpen = new ToolStripMenuItem("&Open".Localize()); ToolStripMenuItem mClose = new ToolStripMenuItem("Close".Localize()); ToolStripMenuItem mSave = new ToolStripMenuItem("&Save".Localize()); ToolStripMenuItem mSaveAs = new ToolStripMenuItem("Save As".Localize()); ToolStripMenuItem mExit = new ToolStripMenuItem("E&xit".Localize()); // Add to Menu DropDownItems.Add(mNew); DropDownItems.Add(mOpen); DropDownItems.Add(mClose); DropDownItems.Add("-"); DropDownItems.Add(mSave); DropDownItems.Add(mSaveAs); DropDownItems.Add("-"); DropDownItems.Add(mExit); // Connect Event Handlers mClose.Click += mClose_Click; mSave.Click += mSave_Click; mSaveAs.Click += mSaveAs_Click; mExit.Click += mExit_Click; // Fill the New/Open menus based on documents if (documentTypes.Length == 1) { Documents.DocumentMeta meta = DocumentManager.GetInst().Meta.Get(documentTypes[0]); if (meta.NewFactoryData != null) { mNew.Tag = documentTypes[0]; mNew.Click += (sender, args) => { IDocument doc = meta.NewFactory.Invoke(null, null) as IDocument; if (doc != null) { DocumentManager.GetInst().Activate(doc); } }; } else { DropDownItems.Remove(mNew); // No NewDocumentFactory, application can only open files } mOpen.Tag = documentTypes[0]; mOpen.Click += (sender, args) => { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = meta.Filter.Filter; if (dlg.ShowDialog() == DialogResult.OK) { IDocument doc = meta.OpenFactory.Invoke(null, new object[] { dlg.FileName }) as IDocument; if (doc != null) { DocumentManager.GetInst().Activate(doc); } } }; } else { foreach (Type docType in documentTypes) { Documents.DocumentMeta meta = DocumentManager.GetInst().Meta.Get(docType); if (meta.NewFactory != null) { ToolStripMenuItem newSubItem = new ToolStripMenuItem(meta.Filter.Name); newSubItem.Click += (sender, args) => { IDocument doc = meta.NewFactory.Invoke(null, null) as IDocument; if (doc != null) { DocumentManager.GetInst().Activate(doc); } }; mNew.DropDownItems.Add(newSubItem); } if (meta.OpenFactory != null) { ToolStripMenuItem openSubItem = new ToolStripMenuItem(meta.Filter.Name); openSubItem.Click += (sender, args) => { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = meta.Filter.Filter; if (dlg.ShowDialog() == DialogResult.OK) { IDocument doc = meta.OpenFactory.Invoke(null, new object[] { dlg.FileName }) as IDocument; if (doc != null) { DocumentManager.GetInst().Activate(doc); } } }; mOpen.DropDownItems.Add(openSubItem); } } } }
private void This_DropDownClosed(object sender, EventArgs e) { Text = toolText.Text; DropDownItems.Remove(DropDownItems["toolText"]); }