Esempio n. 1
0
        /// <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();
        }
Esempio n. 2
0
		public void TestFixtureSetUp()
		{
			if (_dummyCulture == null)
				throw new Exception("Error setting up test - dummyCulture should not be NULL");
			if (CultureInfo.InvariantCulture.Equals(_dummyCulture))
				throw new Exception("Error setting up test - dummyCulture should not be invariant");
			if (_dummyCulture2 == null)
				throw new Exception("Error setting up test - dummyCulture2 should not be NULL");
			if (CultureInfo.InvariantCulture.Equals(_dummyCulture2))
				throw new Exception("Error setting up test - dummyCulture2 should not be invariant");
			if (_dummyCulture2.Equals(_dummyCulture))
				throw new Exception("Error setting up test - dummyCulture2 should not be the same as dummyCulture");

			// for testing purposes, set up the converter for a specific culture to have the Enum.ToString() mapping
			// normally, you would use TypeDescriptor.GetConverter, but we want to keep the test appdomain clean of these testing mods
			XKeysConverter converter = new XKeysConverter(_dummyCulture);
			IDictionary<XKeys, string> relocalizedKeyNames = new Dictionary<XKeys, string>();
			foreach (KeyValuePair<XKeys, string> pair in converter.LocalizedKeyNames)
				relocalizedKeyNames.Add(pair.Key, Enum.GetName(typeof (XKeys), pair.Key));
			relocalizedKeyNames[XKeys.Control] = "Control"; // Enum.ToString() treats this as Control+None
			relocalizedKeyNames[XKeys.Shift] = "Shift"; // Enum.ToString() treats this as Shift+None
			relocalizedKeyNames[XKeys.Alt] = "Alt"; // Enum.ToString() treats this as Alt+None
			relocalizedKeyNames[XKeys.OemPlus] = XKeysConverter.KeySeparator.ToString(); // for special case test
			converter.LocalizedKeyNames = relocalizedKeyNames;

			_converter = converter;
		}
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        /// <remarks>
        /// A reference implementation for ToString taken originally from GetTooltipTest(IClickAction) of
        /// ClearCanvas.Desktop.View.WinForms/ActiveToolbarButton.cs/r12907.
        /// This method now uses XKeysConverter, which is why we compare our results
        /// against this reference implementation.
        /// </remarks>
        private static string ReferenceToStringImplementation(XKeys keyStroke)
        {
            bool  ctrl    = (keyStroke & XKeys.Control) == XKeys.Control;
            bool  alt     = (keyStroke & XKeys.Alt) == XKeys.Alt;
            bool  shift   = (keyStroke & XKeys.Shift) == XKeys.Shift;
            XKeys keyCode = keyStroke & XKeys.KeyCode;

            StringBuilder builder = new StringBuilder();

            if (keyCode != XKeys.None)
            {
                if (ctrl)
                {
                    builder.Append("Ctrl");
                }

                if (alt)
                {
                    if (ctrl)
                    {
                        builder.Append("+");
                    }

                    builder.Append("Alt");
                }

                if (shift)
                {
                    if (ctrl || alt)
                    {
                        builder.Append("+");
                    }

                    builder.Append("Shift");
                }

                if (ctrl || alt || shift)
                {
                    builder.Append("+");
                }

                builder.Append(XKeysConverter.FormatInvariant(keyCode));
            }

            return(builder.ToString());
        }
Esempio n. 5
0
        public void TestFixtureSetUp()
        {
            if (_dummyCulture == null)
            {
                throw new Exception("Error setting up test - dummyCulture should not be NULL");
            }
            if (CultureInfo.InvariantCulture.Equals(_dummyCulture))
            {
                throw new Exception("Error setting up test - dummyCulture should not be invariant");
            }
            if (_dummyCulture2 == null)
            {
                throw new Exception("Error setting up test - dummyCulture2 should not be NULL");
            }
            if (CultureInfo.InvariantCulture.Equals(_dummyCulture2))
            {
                throw new Exception("Error setting up test - dummyCulture2 should not be invariant");
            }
            if (_dummyCulture2.Equals(_dummyCulture))
            {
                throw new Exception("Error setting up test - dummyCulture2 should not be the same as dummyCulture");
            }

            // for testing purposes, set up the converter for a specific culture to have the Enum.ToString() mapping
            // normally, you would use TypeDescriptor.GetConverter, but we want to keep the test appdomain clean of these testing mods
            XKeysConverter converter = new XKeysConverter(_dummyCulture);
            IDictionary <XKeys, string> relocalizedKeyNames = new Dictionary <XKeys, string>();

            foreach (KeyValuePair <XKeys, string> pair in converter.LocalizedKeyNames)
            {
                relocalizedKeyNames.Add(pair.Key, Enum.GetName(typeof(XKeys), pair.Key));
            }
            relocalizedKeyNames[XKeys.Control] = "Control";                              // Enum.ToString() treats this as Control+None
            relocalizedKeyNames[XKeys.Shift]   = "Shift";                                // Enum.ToString() treats this as Shift+None
            relocalizedKeyNames[XKeys.Alt]     = "Alt";                                  // Enum.ToString() treats this as Alt+None
            relocalizedKeyNames[XKeys.OemPlus] = XKeysConverter.KeySeparator.ToString(); // for special case test
            converter.LocalizedKeyNames        = relocalizedKeyNames;

            _converter = converter;
        }
Esempio n. 6
0
        /// <summary>
        /// Processes an <paramref name="xmlAction"/> element in the XML model, deserializing the persisted values into the provided <paramref name="action"/>.
        /// </summary>
        private static void ProcessXmlAction(XmlElement xmlAction, IAction action)
        {
            string path = xmlAction.GetAttribute("path");

            action.Path = new ActionPath(path, action.ResourceResolver);
            //The group hint from the xml never overrides the action's group hint!!!  Otherwise, we can't change
            //the group hint of an action for the purpose of placing a new one near it.
            //string grouphint = xmlAction.GetAttribute("group-hint");
            //action.GroupHint = new GroupHint(grouphint);

            bool   available      = true;
            string availableValue = xmlAction.GetAttribute("available");

            if (!string.IsNullOrEmpty(availableValue))
            {
                if (!bool.TryParse(availableValue, out available))
                {
                    available = true;
                }
            }
            action.Available = available;

            if (action is IClickAction)
            {
                IClickAction clickAction = (IClickAction)action;

                XKeys  keyStroke      = XKeys.None;
                string keystrokeValue = xmlAction.GetAttribute("keystroke");
                if (!string.IsNullOrEmpty(keystrokeValue))
                {
                    if (!XKeysConverter.TryParseInvariant(keystrokeValue, out keyStroke))
                    {
                        Platform.Log(LogLevel.Debug, "Invalid value for attribute keystroke for action {0}", action.ActionID);
                    }
                }
                clickAction.KeyStroke = keyStroke;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Sets all the relevant attributes on the <paramref name="xmlAction"/> from the <paramref name="action"/>.
        /// </summary>
        private static void SynchronizeAction(XmlElement xmlAction, IAction action)
        {
            xmlAction.SetAttribute("id", action.ActionID);
            xmlAction.SetAttribute("path", action.Path.ToString());
            xmlAction.SetAttribute("group-hint", action.GroupHint.Hint);

            if (!action.Available)
            {
                xmlAction.SetAttribute("available", action.Available.ToString(System.Globalization.CultureInfo.InvariantCulture));
            }

            var clickAction = action as IClickAction;

            if (clickAction == null)
            {
                return;
            }

            if (clickAction.KeyStroke != XKeys.None)
            {
                xmlAction.SetAttribute("keystroke", XKeysConverter.FormatInvariant(clickAction.KeyStroke));
            }
        }