📄 commandbaritemcollection.cs
字号:
// ---------------------------------------------------------
// Windows Forms CommandBar Control
// Copyright (C) 2001-2003 Lutz Roeder. All rights reserved.
// http://www.aisto.com/roeder
// roeder@aisto.com
// ---------------------------------------------------------
namespace Reflector.UserInterface
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
public class CommandBarItemCollection : ICollection
{
private CommandBar commandBar;
private ArrayList items;
internal CommandBarItemCollection()
{
this.commandBar = null;
this.items = new ArrayList();
}
internal CommandBarItemCollection(CommandBar commandBar)
{
this.commandBar = commandBar;
this.items = new ArrayList();
}
public IEnumerator GetEnumerator()
{
return this.items.GetEnumerator();
}
public int Count
{
get { return this.items.Count; }
}
public void Clear()
{
while (this.Count > 0)
{
this.RemoveAt(0);
}
//// Alex: clear also items array
if (items!=null) items.Clear();
//// clear hashes
keyItems.Clear();
}
public void Add(CommandBarItem item)
{
this.items.Add(item);
if (this.commandBar != null)
{
this.commandBar.AddItem(item);
}
//// clear hashes
keyItems.Clear();
}
public void AddSeparator()
{
this.Add(new CommandBarSeparator());
}
public CommandBarMenu AddMenu(string text)
{
CommandBarMenu menu = new CommandBarMenu(text);
this.Add(menu);
//// clear hashes
keyItems.Clear();
return menu;
}
public CommandBarMenu AddMenu(Image image, string text)
{
CommandBarMenu menu = this.AddMenu(text);
menu.Image = image;
//// clear hashes
keyItems.Clear();
return menu;
}
public CommandBarMenu AddMenu(string text, EventHandler dropDownHandler)
{
CommandBarMenu menu = this.AddMenu(text);
menu.DropDown += dropDownHandler;
//// clear hashes
keyItems.Clear();
return menu;
}
public CommandBarMenu AddMenu(Image image, string text, EventHandler dropDownHandler)
{
CommandBarMenu menu = this.AddMenu(text);
menu.Image = image;
menu.DropDown += dropDownHandler;
//// clear hashes
keyItems.Clear();
return menu;
}
public CommandBarButton AddButton(string text, EventHandler clickHandler)
{
CommandBarButton button = new CommandBarButton(text);
button.Click += clickHandler;
this.Add(button);
//// clear hashes
keyItems.Clear();
return button;
}
public CommandBarButton AddButton(string text, EventHandler clickHandler, Keys shortcut)
{
CommandBarButton button = this.AddButton(text, clickHandler);
button.Shortcut = shortcut;
//// clear hashes
keyItems.Clear();
return button;
}
public CommandBarButton AddButton(Image image, string text, EventHandler clickHandler)
{
CommandBarButton button = this.AddButton(text, clickHandler);
button.Image = image;
//// clear hashes
keyItems.Clear();
return button;
}
public CommandBarButton AddButton(Image image, string text, EventHandler clickHandler, Keys shortcut)
{
CommandBarButton button = this.AddButton(text, clickHandler, shortcut);
button.Image = image;
//// clear hashes
keyItems.Clear();
return button;
}
public CommandBarCheckBox AddCheckBox(string text)
{
CommandBarCheckBox checkBox = new CommandBarCheckBox(text);
this.Add(checkBox);
//// clear hashes
keyItems.Clear();
return checkBox;
}
public CommandBarCheckBox AddCheckBox(string text, Keys shortcut)
{
CommandBarCheckBox checkBox = this.AddCheckBox(text);
checkBox.Shortcut = shortcut;
//// clear hashes
keyItems.Clear();
return checkBox;
}
public CommandBarCheckBox AddCheckBox(Image image, string text, Keys shortcut)
{
CommandBarCheckBox checkBox = this.AddCheckBox(text, shortcut);
checkBox.Image = image;
//// clear hashes
keyItems.Clear();
return checkBox;
}
public CommandBarCheckBox AddCheckBox(Image image, string text)
{
CommandBarCheckBox checkBox = this.AddCheckBox(text);
checkBox.Image = image;
//// clear hashes
keyItems.Clear();
return checkBox;
}
public CommandBarComboBox AddComboBox(string text, ComboBox comboBox)
{
CommandBarComboBox item = new CommandBarComboBox(text, comboBox);
this.Add(item);
//// clear hashes
keyItems.Clear();
return item;
}
public void AddRange(ICollection items)
{
foreach (CommandBarItem item in items)
{
this.items.Add(item);
if (this.commandBar != null)
{
this.commandBar.AddItem(item);
}
}
//// clear hashes
keyItems.Clear();
}
public void Insert(int index, CommandBarItem item)
{
items.Insert(index, item);
if (this.commandBar != null)
{
this.commandBar.AddItem(item);
}
//// clear hashes
keyItems.Clear();
}
public void RemoveAt(int index)
{
CommandBarItem item = (CommandBarItem) this.items[index];
items.RemoveAt(index);
if (this.commandBar != null)
{
this.commandBar.RemoveItem(item);
}
//// clear hash table of shortcut items
keyItems.Clear();
}
public void Remove(CommandBarItem item)
{
if (this.items.Contains(item))
{
this.items.Remove(item);
if (this.commandBar != null)
{
this.commandBar.RemoveItem(item);
}
//// clear our hashes to simplify things - they will be reconstructed
keyItems.Clear();
}
}
public bool Contains(CommandBarItem item)
{
return this.items.Contains(item);
}
public int IndexOf(CommandBarItem item)
{
return this.items.IndexOf(item);
}
public CommandBarItem this[int index]
{
get { return (CommandBarItem)items[index]; }
}
public object SyncRoot
{
get { throw new NotSupportedException(); }
}
public bool IsSynchronized
{
get { return false; }
}
public void CopyTo(Array array, int index)
{
this.items.CopyTo(array, index);
}
public void CopyTo(CommandBarItem[] array, int index)
{
this.items.CopyTo(array, index);
}
// TODO
//// this one is causing a lot of call - could it be done as hashtable? Called very frequently form PreProcessMessage
internal Hashtable keyItems = new Hashtable();
internal CommandBarItem[] this[Keys shortcut]
{
get
{
//// try to get result immediately
if (keyItems[shortcut] == null) {
ArrayList list = new ArrayList();
foreach (CommandBarItem item in items)
{
CommandBarButtonBase buttonBase = item as CommandBarButtonBase;
if (buttonBase != null)
{
if ((buttonBase.Shortcut == shortcut) && (buttonBase.IsEnabled) && (buttonBase.IsVisible))
{
list.Add(buttonBase);
}
}
//// combine array lookup - better to make hashtable to speed up lookup - now it is too long
CommandBarMenu menu = item as CommandBarMenu;
if (menu != null)
{
list.AddRange(menu.Items[shortcut]);
}
}
//// too many calls - for every possible message in underlying windows
/*
foreach (CommandBarItem item in items)
{
CommandBarMenu menu = item as CommandBarMenu;
if (menu != null)
{
list.AddRange(menu.Items[shortcut]);
}
}
*/
CommandBarItem[] array = new CommandBarItem[list.Count];
list.CopyTo(array, 0);
//// add new array to list
keyItems.Add(shortcut, array);
}
return (CommandBarItem[])keyItems[shortcut];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -