using System;
using System.IO;
using System.Xml;
using SAGA.DotNetUtils;
using SAGA.RevitMenu.ShortKey;
using SAGA.RevitUtils;
namespace SAGA.RevitMenu
{
public class ScreenMenuKeyBoardShortCut
{
public static void SetKeyboardShortcuts(string versionName)
{
try
{
string path = Path.Combine(Path.Combine(Environment.ExpandEnvironmentVariables(@"%appdata%\Autodesk\Revit"), versionName), "KeyboardShortcuts.xml");
XmlDocument doc = new XmlDocument();
if (!File.Exists(path))
{
File.Copy(
Path.Combine(
Path.Combine(AppBaseInfo.DllRunPath, "ShortKey"),
"KeyboardShortcuts.xml"), path);
}
doc.Load(path);
SetSpaceShortcuts(doc);
doc.Save(path);
}
catch (Exception exception)
{
MessageShow.Show(exception, false, "");
}
}
///
/// 设置放置空调的快捷键
///
///
private static void SetSpaceShortcuts(XmlDocument doc)
{
string SpaceKey = "UKJ";
string ASpaceKey = "UAKJ";
ShortKeyHelper.AddShotKey(doc, "ID_OBJECTS_MEP_SPACE", SpaceKey);
ShortKeyHelper.AddShotKey(doc, "Dialog_RoomAreaPlan_RoomTagDlgBar:Control_RoomAreaPlan_FindAllSpaces", ASpaceKey);
string SaveKey = "SSS";
ShortKeyHelper.AddShotKey(doc, "ID_REVIT_FILE_SAVE", SaveKey);
}
private static void SetOneKeyboardShortcuts(XmlDocument doc, string commandName, string className, string shortcuts, string ribbonTabName, string ribbonPanelName)
{
XmlElement documentElement = doc.DocumentElement;
string str = "CustomCtrl_%CustomCtrl_%" + ribbonTabName + "%" + ribbonPanelName + "%" + className;
string str2 = ribbonTabName + ">" + ribbonPanelName;
string xpath = string.Format("Shortcuts/ShortcutItem[@CommandId='{0}']", str);
XmlNode node = doc.SelectSingleNode(xpath);
if (node == null)
{
XmlElement newChild = doc.CreateElement("ShortcutItem");
newChild.SetAttribute("CommandName", commandName);
newChild.SetAttribute("CommandId", str);
newChild.SetAttribute("Shortcuts", shortcuts);
newChild.SetAttribute("Paths", str2);
documentElement.AppendChild(newChild);
}
else
{
XmlElement element3 = node as XmlElement;
if (!element3.HasAttribute("Shortcuts"))
{
element3.SetAttribute("Shortcuts", shortcuts);
}
else if (element3.GetAttribute("Shortcuts").CompareTo(shortcuts) != 0)
{
element3.SetAttribute("Shortcuts", shortcuts);
}
if (!element3.HasAttribute("CommandName"))
{
element3.SetAttribute("CommandName", commandName);
}
else if (element3.GetAttribute("CommandName").CompareTo(commandName) != 0)
{
element3.SetAttribute("CommandName", commandName);
}
if (!element3.HasAttribute("Paths"))
{
element3.SetAttribute("Paths", str2);
}
else if (element3.GetAttribute("Paths").CompareTo(str2) != 0)
{
element3.SetAttribute("Paths", str2);
}
}
}
}
}