/// <summary> /// Sets the tooltip text on the specified item, from the specified action. /// </summary> /// <param name="item"></param> /// <param name="action"></param> internal static void SetTooltipText(ToolStripItem item, IAction action) { var actionTooltip = action.Tooltip; if (string.IsNullOrEmpty(actionTooltip)) { actionTooltip = (action.Label ?? string.Empty).Replace("&", ""); } var clickAction = action as IClickAction; if (clickAction == null || clickAction.KeyStroke == XKeys.None) { item.ToolTipText = actionTooltip; return; } var keyCode = clickAction.KeyStroke & XKeys.KeyCode; var builder = new StringBuilder(); builder.Append(actionTooltip); if (keyCode != XKeys.None) { if (builder.Length > 0) { builder.AppendLine(); } builder.AppendFormat("{0}: ", SR.LabelKeyboardShortcut); builder.Append(XKeysConverter.Format(clickAction.KeyStroke)); } item.ToolTipText = builder.ToString(); }
private bool ValidateClickActionKeyStroke(AbstractActionModelTreeLeafClickAction node, XKeys keys) { // if we're just synchronizing key strokes due to another key stroke set action, short the validation request if (_updatingKeyStrokes) { return(true); } // if the key stroke is the empty value, it is always allowed if (keys == XKeys.None) { return(true); } // if the key stroke contains only modifiers and no key, it is never allowed if ((keys & XKeys.Modifiers) != 0 && (keys & XKeys.KeyCode) == 0) { return(false); } // if the action is not part of the viewer component then it is handled by the desktop and must be modified if (GetActionsById(_imageViewer.ExportedActions, node.ActionId).Count == 0 && (keys & XKeys.Modifiers) == 0) { return(false); } // if the key stroke is a value reserved by built-in viewer operations, then it cannot be allowed if (_reservedKeystrokes.Contains(keys)) { var message = string.Format(SR.MessageKeyStrokeReserved, XKeysConverter.Format(keys)); Host.DesktopWindow.ShowMessageBox(message, MessageBoxActions.Ok); return(false); } // check for other assignments to the same key stroke and confirm the action if there are pre-existing assignments if (_keyStrokeMap.IsAssignedToOther(keys, node.ActionId)) { IList <AbstractActionModelTreeLeafAction> actions = _actionMap[_keyStrokeMap[keys]]; if (actions.Count > 0) { string message = string.Format(SR.MessageKeyStrokeAlreadyAssigned, XKeysConverter.Format(keys), actions[0].Label); DialogBoxAction result = base.Host.DesktopWindow.ShowMessageBox(message, MessageBoxActions.YesNo); if (result != DialogBoxAction.Yes) { return(false); } } } return(true); }