private void UpdateClickActionKeyStroke(AbstractActionModelTreeLeafClickAction node, XKeys keys) { if (_updatingKeyStrokes) { return; } _updatingKeyStrokes = true; try { // find the old keys to which this action was assigned var oldKeys = _keyStrokeMap.FindAssignment(node.ActionId, XKeys.None); // check if updating this value actually causes a change if (oldKeys == keys) { return; } // unassign the key stroke from the old actions if it has previously been assigned to something else if (keys != XKeys.None && _keyStrokeMap.IsAssignedToOther(keys, node.ActionId)) { foreach (AbstractActionModelTreeLeafAction action in _actionMap[_keyStrokeMap[keys]]) { if (action is AbstractActionModelTreeLeafClickAction) { ((AbstractActionModelTreeLeafClickAction)action).KeyStroke = XKeys.None; } } } // assign the key stroke to the new actions foreach (AbstractActionModelTreeLeafAction action in _actionMap[node.ActionId]) { if (action is AbstractActionModelTreeLeafClickAction) { ((AbstractActionModelTreeLeafClickAction)action).KeyStroke = keys; } } // clear the old assignment if (oldKeys != XKeys.None) { _keyStrokeMap[oldKeys] = string.Empty; } // update the key stroke map if (keys != XKeys.None) { _keyStrokeMap[keys] = node.ActionId; } } finally { _updatingKeyStrokes = false; } }
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); }
public ImageViewerActionModelConfigurationComponent(string @namespace, string site, CustomizeViewerActionModelsComponent owner) : base(@namespace, site, owner._imageViewer.ExportedActions, owner._imageViewer.DesktopWindow, site == _globalToolbarActionSite) { _owner = owner; // just keep a single copy of it for a consistent startup state - we don't store the unsaved changes in here _toolProfile = MouseToolSettingsProfile.Current.Clone(); this.ValidationPolicy = _owner._validationPolicy; // update the keystroke and action maps foreach (AbstractActionModelTreeLeafAction node in base.ActionNodeMap.ActionNodes) { if (node is AbstractActionModelTreeLeafClickAction) { AbstractActionModelTreeLeafClickAction clickActionNode = (AbstractActionModelTreeLeafClickAction)node; if (clickActionNode.KeyStroke != XKeys.None) { if (_owner._keyStrokeMap.IsAssignedToOther(clickActionNode.KeyStroke, clickActionNode.ActionId)) { clickActionNode.KeyStroke = XKeys.None; } else { _owner._keyStrokeMap[clickActionNode.KeyStroke] = clickActionNode.ActionId; } } } if (_toolProfile.HasEntryByActivationActionId(node.ActionId)) { var mouseToolSetting = _toolProfile.GetEntryByActivationActionId(node.ActionId); var mouseButtonValue = mouseToolSetting.MouseButton.GetValueOrDefault(XMouseButtons.Left); if (mouseButtonValue != XMouseButtons.None) { if (mouseToolSetting.InitiallyActive.GetValueOrDefault(false)) { if (!_owner._initialMouseToolsMap.IsAssignedToOther(mouseButtonValue, node.ActionId)) { _owner._initialMouseToolsMap[mouseButtonValue] = node.ActionId; } } if (!_owner._mouseButtonMap[mouseButtonValue].Contains(node.ActionId)) { _owner._mouseButtonMap.Add(mouseButtonValue, node.ActionId); } } var defaultMouseButtonValue = mouseToolSetting.DefaultMouseButton.GetValueOrDefault(XMouseButtons.None); var defaultMouseButtonModifiers = mouseToolSetting.DefaultMouseButtonModifiers.GetValueOrDefault(ModifierFlags.None); if (defaultMouseButtonValue != XMouseButtons.None) { var defaultMouseButton = new XMouseButtonCombo(defaultMouseButtonValue, defaultMouseButtonModifiers); if (!_owner._defaultMouseToolsMap.IsAssignedToOther(defaultMouseButton, node.ActionId)) { _owner._defaultMouseToolsMap[defaultMouseButton] = node.ActionId; } } } } foreach (string actionId in base.ActionNodeMap.ActionIds) { _owner._actionMap.AddRange(actionId, base.ActionNodeMap[actionId]); } }