ShortKeyHelper.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* ==============================================================================
  2. * 功能描述:ShortKeyHelper
  3. * 创 建 者:Garrett
  4. * 创建日期:2017/11/30 16:25:19
  5. * ==============================================================================*/
  6. using System.IO;
  7. using System.Linq;
  8. using System.Xml;
  9. using SAGA.DotNetUtils;
  10. namespace SAGA.RevitMenu.ShortKey
  11. {
  12. /// <summary>
  13. /// ShortKeyHelper
  14. /// </summary>
  15. public class ShortKeyHelper
  16. {
  17. public static void AddShotKey(XmlDocument doc ,string commandId, string key)
  18. {
  19. XmlNode xn = doc.SelectSingleNode($"/Shortcuts/ShortcutItem[@CommandId='{commandId}']");
  20. string shortStr = "Shortcuts";
  21. if (xn.Attributes[shortStr] == null)
  22. {
  23. XmlAttribute shorcutAttr=doc.CreateAttribute(shortStr);
  24. shorcutAttr.Value = key;
  25. xn.Attributes.Append(shorcutAttr);
  26. }
  27. else
  28. {
  29. var shortValue = xn.Attributes[shortStr].Value;
  30. var shortArray = shortValue.Split('#');
  31. if (!shortArray.Contains(key))
  32. {
  33. shortValue += "#" + key;
  34. }
  35. xn.Attributes[shortStr].Value = shortValue;
  36. }
  37. }
  38. }
  39. }