Beispiel #1
0
        /// <summary>
        /// 基于通用库封装的RibbonCommandItem设置其快捷键.
        /// </summary>
        /// <param name="commandItem">RibbonCommandItem.</param>
        /// <param name="key">快捷键字符串.</param>
        /// <returns></returns>
        public static bool SetShortCut(this Autodesk.Windows.RibbonItem commandItem, string key)
        {
            if (commandItem == null || string.IsNullOrEmpty(key))
            {
                return(false);
            }

            var parentTab   = default(Autodesk.Windows.RibbonTab);
            var parentPanel = default(Autodesk.Windows.RibbonPanel);

            Autodesk.Windows.ComponentManager.Ribbon.FindItem(commandItem.Id, false, out parentPanel, out parentTab, true);

            if (parentTab == null || parentPanel == null)
            {
                return(false);
            }

            var path  = string.Format("{0}>{1}", parentTab.Id, parentPanel.Source.Id);
            var cmdId = ControlHelper.GetCommandId(commandItem);

            if (string.IsNullOrEmpty(cmdId))
            {
                cmdId = Guid.NewGuid().ToString();
                ControlHelper.SetCommandId(commandItem, cmdId);
            }

            var shortcutItem = new ShortcutItem(commandItem.Text, cmdId, key, path);

            shortcutItem.ShortcutType = StType.RevitAPI;
            KeyboardShortcutService.applyShortcutChanges(new Dictionary <string, ShortcutItem>()
            {
                {
                    cmdId, shortcutItem
                }
            });
            return(true);
        }
 protected override bool CanExecute(Autodesk.Windows.RibbonItem parameter)
 {
     return(true);
 }
Beispiel #3
0
 /// <summary>
 /// 此命令是否能执行.
 /// </summary>
 /// <param name="parameter"></param>
 /// <returns></returns>
 protected abstract bool CanExecute(Autodesk.Windows.RibbonItem parameter);