Пример #1
0
        public static void Initialize(MouseImageViewerTool mouseTool)
        {
            object[] buttonAssignment = mouseTool.GetType().GetCustomAttributes(typeof(MouseToolButtonAttribute), true);
            if (buttonAssignment == null || buttonAssignment.Length == 0)
            {
                throw new InvalidOperationException(String.Format(SR.ExceptionMouseToolShouldHaveDefault, mouseTool.GetType().FullName));
            }
            else
            {
                MouseToolButtonAttribute attribute = buttonAssignment[0] as MouseToolButtonAttribute;

                if (attribute.MouseButton == XMouseButtons.None)
                {
                    throw new InvalidOperationException(String.Format(SR.ExceptionMouseToolShouldHaveDefault, mouseTool.GetType().FullName));
                }
                else
                {
                    mouseTool.MouseButton = attribute.MouseButton;
                    mouseTool.Active      = attribute.InitiallyActive;
                }
            }
        }
Пример #2
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;
        }