📄 menucreator.cs
字号:
// MenuCreator.cs
// Copyright (C) 2001 Mike Krueger
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using System.Xml;
using SharpDevelop.Gui;
using SharpDevelop.Gui.Components;
using SharpDevelop.Tool.Data;
using SharpDevelop.Tool.Text;
using SharpDevelop.Actions;
using SharpDevelop.Actions.Menu;
using SharpDevelop.Internal.Messages;
namespace SharpDevelop.Tool.Function {
public class MenuCreator {
public static MenuItem[] CreateMenu(MainWindow mainwindow, string eventnamespace, XmlElement xmlelement)
{
return CreateMenu(mainwindow, Assembly.GetCallingAssembly(), eventnamespace, xmlelement);
}
public static MenuItem[] CreateMenu(MainWindow mainwindow,Assembly assembly, string eventnamespace, XmlElement xmlelement)
{
XmlNodeList nodes = xmlelement.ChildNodes;
IconMenuItem[] item = new IconMenuItem[nodes.Count];
for (int i = 0; i < nodes.Count; ++i) {
XmlElement el = (XmlElement)nodes[i];
MenuAction action = null;
EventHandler handler1 = null;
EventHandler handler2 = null;
XmlAttribute attribute = el.Attributes["ATTRIBUTE"];
bool link = attribute == null ? false : attribute.InnerText.ToUpper() == "WEBLINK" || attribute.InnerText.ToUpper() == "LINK";
bool ischecked = false;
// set eventhandler
if (el.Attributes["EVENT"] != null) {
ISdPlugin ia = null;
if (link) {
if (attribute.InnerText.ToUpper() == "LINK")
ia = new SharpDevelop.Actions.Menu.GotoLink(el.Attributes["EVENT"].InnerText);
else
ia = new SharpDevelop.Actions.Menu.GotoWebSite(el.Attributes["EVENT"].InnerText);
} else {
string objname = eventnamespace + el.Attributes["EVENT"].InnerText;
ia = (ISdPlugin)assembly.CreateInstance(objname);
}
if (ia == null) {
MessageBox.Show("Can't create MenuAction " + el.Attributes["EVENT"].InnerText, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
} else {
if (ia.MessageHandler != null)
Messenger.AddMessageHandler(ia.MessageHandler);
ischecked = ia is ISdToggleablePlugin;
action = new MenuAction(mainwindow, ia);
handler1 = new EventHandler(action.Invoke);
if (ischecked)
handler2 = new EventHandler(action.Toggle);
}
}
// create MenuItem
string s1 = el.Attributes["NAME"] == null ? null : StringParser.Parse(el.Attributes["NAME"].InnerText, new string [,] {});
string s2 = el.Attributes["DESCRIPTION"] == null ? null : StringParser.Parse(el.Attributes["DESCRIPTION"].InnerText, new string [,] {});
item[i] = new IconMenuItem(mainwindow, s1, handler1, s2);
if (ischecked && action.Plugin != null) {
action.MenuItem = item[i];
SharpDevelopMain.InitComplete += new EventHandler(action.FirstInit);
item[i].Click += handler2;
}
// read attributes
if (attribute != null) {
item[i].ItemTag = (SpecialItemTag)Enum.Parse(typeof(SpecialItemTag), attribute.InnerText);
}
// read open status
XmlAttribute active = el.Attributes["ACTIVE"];
if (active != null) {
item[i].IconEnabled = (IconEnabledStatus)Enum.Parse(typeof(IconEnabledStatus), active.InnerText);
}
// set menuitem icon
XmlAttribute icon = el.Attributes["ICON"];
if (icon != null) {
item[i].Icon = FileUtility.GetBitmap(icon.InnerText);
}
// set menuitem shortcut
XmlAttribute shortcut = el.Attributes["SHORTCUT"];
if (shortcut != null) {
try {
item[i].Shortcut = (Shortcut)((Shortcut.F1.GetType()).InvokeMember(shortcut.InnerText, BindingFlags.GetField, null, Shortcut.F1, new object[0]));
} catch (Exception) {
item[i].Shortcut = Shortcut.None;
item[i].ShortcutText = shortcut.InnerText;
}
}
// add submenus
MenuItem[] submenus = CreateMenu(mainwindow, assembly, eventnamespace, el);
foreach (MenuItem menuitem in submenus)
item[i].MenuItems.Add(menuitem);
}
return item;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -