1234567891011121314151617181920212223242526272829303132333435363738394041 |
- /* ==============================================================================
- * 功能描述:ShortKeyHelper
- * 创 建 者:Garrett
- * 创建日期:2017/11/30 16:25:19
- * ==============================================================================*/
- using System.IO;
- using System.Linq;
- using System.Xml;
- using SAGA.DotNetUtils;
- namespace SAGA.RevitMenu.ShortKey
- {
- /// <summary>
- /// ShortKeyHelper
- /// </summary>
- public class ShortKeyHelper
- {
- public static void AddShotKey(XmlDocument doc ,string commandId, string key)
- {
- XmlNode xn = doc.SelectSingleNode($"/Shortcuts/ShortcutItem[@CommandId='{commandId}']");
- string shortStr = "Shortcuts";
- if (xn.Attributes[shortStr] == null)
- {
- XmlAttribute shorcutAttr=doc.CreateAttribute(shortStr);
- shorcutAttr.Value = key;
- xn.Attributes.Append(shorcutAttr);
- }
- else
- {
- var shortValue = xn.Attributes[shortStr].Value;
- var shortArray = shortValue.Split('#');
- if (!shortArray.Contains(key))
- {
- shortValue += "#" + key;
- }
- xn.Attributes[shortStr].Value = shortValue;
- }
- }
- }
- }
|