Example #1
0
        /// <summary>
        /// Called when the mouse tool settings entry for this tool has changed.
        /// </summary>
        /// <remarks>
        /// The default implementation reloads all mouse button and shortcut assignments from the setting.
        /// Override this method to provide custom behaviour for attempting to change assignments on a live tool.
        /// </remarks>
        protected virtual void OnMouseToolSettingsChanged(MouseToolSettingsProfile.Setting setting)
        {
            if (setting == null || setting.IsEmpty)
            {
                return;
            }

            this.MouseButton = setting.MouseButton.GetValueOrDefault(this.MouseButton);

            var oldDefaultMouseButtonShortcut = this.DefaultMouseButtonShortcut ?? new MouseButtonShortcut(XMouseButtons.None, ModifierFlags.None);
            var defaultMouseButton            = setting.DefaultMouseButton.GetValueOrDefault(oldDefaultMouseButtonShortcut.MouseButton);

            if (defaultMouseButton == XMouseButtons.None && this.DefaultMouseButtonShortcut != null)
            {
                this.DefaultMouseButtonShortcut = null;
            }
            else if (defaultMouseButton != XMouseButtons.None)
            {
                var defaultMouseButtonModifiers = setting.DefaultMouseButtonModifiers.GetValueOrDefault(oldDefaultMouseButtonShortcut.Modifiers.ModifierFlags);
                if (oldDefaultMouseButtonShortcut.MouseButton != defaultMouseButton || oldDefaultMouseButtonShortcut.Modifiers.ModifierFlags != defaultMouseButtonModifiers)
                {
                    this.DefaultMouseButtonShortcut = new MouseButtonShortcut(defaultMouseButton, defaultMouseButtonModifiers);
                }
            }

            //We DO change the initially active property of the tool because
            //it essentially identifies the default mouse tool for each mouse button.
            if (setting.InitiallyActive.HasValue)
            {
                InitiallyActive = setting.InitiallyActive.Value;
            }
        }
Example #2
0
        private static void InitializeModifiedMouseToolButton(MouseImageViewerTool mouseTool)
        {
            MouseButtonShortcut defaultMouseButtonShortcut = null;

            // check for hardcoded assembly default settings
            object[] defaultButtonAssignments = mouseTool.GetType().GetCustomAttributes(typeof(DefaultMouseToolButtonAttribute), true);
            if (defaultButtonAssignments != null && defaultButtonAssignments.Length > 0)
            {
                DefaultMouseToolButtonAttribute attribute = (DefaultMouseToolButtonAttribute)defaultButtonAssignments[0];
                defaultMouseButtonShortcut = attribute.Shortcut;
            }

            // check settings profile for an override specific to this tool
            Type mouseToolType = mouseTool.GetType();

            if (MouseToolSettingsProfile.Current.HasEntry(mouseToolType))
            {
                MouseToolSettingsProfile.Setting value = MouseToolSettingsProfile.Current[mouseToolType];
                if (value.DefaultMouseButton.HasValue)
                {
                    defaultMouseButtonShortcut = null;
                    if (value.DefaultMouseButton.Value != XMouseButtons.None)
                    {
                        defaultMouseButtonShortcut = new MouseButtonShortcut(value.DefaultMouseButton.Value, value.DefaultMouseButtonModifiers.GetValueOrDefault(ModifierFlags.None));
                    }
                }
            }

            // apply the selected value to the tool (don't write back to the profile! - that's not for us to decide)
            try
            {
                mouseTool.DefaultMouseButtonShortcut = defaultMouseButtonShortcut;
            }
            catch (Exception e)
            {
                // JY: what exactly are we catching here?
                Platform.Log(LogLevel.Warn, e);
            }

            MouseToolSettingsProfile.Current[mouseToolType].DefaultMouseButton          = defaultMouseButtonShortcut != null ? defaultMouseButtonShortcut.MouseButton : XMouseButtons.None;
            MouseToolSettingsProfile.Current[mouseToolType].DefaultMouseButtonModifiers = defaultMouseButtonShortcut != null ? defaultMouseButtonShortcut.Modifiers.ModifierFlags : ModifierFlags.None;
        }
Example #3
0
        private static void InitializeMouseToolButton(MouseImageViewerTool mouseTool)
        {
            XMouseButtons mouseButton = XMouseButtons.Left;

            // check for hardcoded assembly default settings
            object[] buttonAssignment = mouseTool.GetType().GetCustomAttributes(typeof(MouseToolButtonAttribute), true);
            if (buttonAssignment != null && buttonAssignment.Length > 0)
            {
                MouseToolButtonAttribute attribute = (MouseToolButtonAttribute)buttonAssignment[0];
                if (attribute.MouseButton == XMouseButtons.None)
                {
                    Platform.Log(LogLevel.Warn, String.Format(SR.FormatMouseToolInvalidAssignment, mouseTool.GetType().FullName));
                }
                mouseButton = attribute.MouseButton;
                mouseTool.InitiallyActive = attribute.InitiallyActive;
            }

            // check settings profile for an override specific to this tool
            Type mouseToolType = mouseTool.GetType();

            if (MouseToolSettingsProfile.Current.HasEntry(mouseToolType))
            {
                MouseToolSettingsProfile.Setting value = MouseToolSettingsProfile.Current[mouseToolType];
                mouseButton = value.MouseButton.GetValueOrDefault(mouseButton);
                if (value.InitiallyActive.HasValue)
                {
                    mouseTool.InitiallyActive = value.InitiallyActive.Value;
                }
            }

            mouseTool.MouseButton = mouseButton;
            mouseTool.Active      = mouseTool.InitiallyActive;

            MouseToolSettingsProfile.Current[mouseToolType].MouseButton     = mouseButton;
            MouseToolSettingsProfile.Current[mouseToolType].InitiallyActive = mouseTool.InitiallyActive;
        }