Exemple #1
0
        public static ConfigInvokeItem FromXElement(XElement root)
        {
            var newConfigItem = new ConfigInvokeItem();

            if (root.Attribute("type").Value.Equals("customKeyboard"))
            {
                newConfigItem.Type         = ConfigInvokeItemType.CustomAction;
                newConfigItem.CustomAction = new InvokeItem();
                newConfigItem.CustomAction.invokeKeyPress = true;
                newConfigItem.CustomAction.keysHold       = new List <VirtualKeyCode>();
                foreach (var key in root.Element("holdKeys").Elements())
                {
                    newConfigItem.CustomAction.keysHold.Add((VirtualKeyCode)Enum.Parse(typeof(VirtualKeyCode), key.Value, true));
                }
                newConfigItem.CustomAction.keyPress = (VirtualKeyCode)Enum.Parse(typeof(VirtualKeyCode), root.Element("key").Value, true);
                return(newConfigItem);
            }
            else if (root.Attribute("type").Value.Equals("customMouse"))
            {
                newConfigItem.Type         = ConfigInvokeItemType.CustomAction;
                newConfigItem.CustomAction = new InvokeItem();
                newConfigItem.CustomAction.invokeMousePress = true;
                newConfigItem.CustomAction.invokeKeyPress   = true;
                newConfigItem.CustomAction.mouseButtonsDown = new List <MouseKeyCode>();
                foreach (var key in root.Elements("mouse"))
                {
                    newConfigItem.CustomAction.mouseButtonsDown.Add((MouseKeyCode)Enum.Parse(typeof(MouseKeyCode), key.Value, true));
                }
                return(newConfigItem);
            }
            else if (root.Attribute("type").Value.Equals("empty"))
            {
                newConfigItem.Type = ConfigInvokeItemType.DoNothing;
                return(newConfigItem);
            }
            else if (root.Attribute("type").Value.Equals("default"))
            {
                newConfigItem.Type          = ConfigInvokeItemType.DefaultAction;
                newConfigItem.DefaultAction = (DefaultAction)Enum.Parse(typeof(DefaultAction), root.Value, true);
                return(newConfigItem);
            }
            return(null);
        }
Exemple #2
0
        public static Configuration Parse(XElement root)
        {
            var newConfig = Configuration.Default();

            var item = root.Element("MouseTapsLongMs");

            if (item != null)
            {
                Int32.TryParse(item.Value, out newConfig.MouseTapsLongMs);
            }

            item = root.Element("MouseTapsLongMovingArea");
            if (item != null)
            {
                Int32.TryParse(item.Value, out newConfig.MouseTapsLongMovingArea);
            }

            item = root.Element("SwipeBorderInsetX");
            if (item != null)
            {
                Int32.TryParse(item.Value, out newConfig.SwipeBorderInsetX);
            }

            item = root.Element("SwipeBorderInsetY");
            if (item != null)
            {
                Int32.TryParse(item.Value, out newConfig.SwipeBorderInsetY);
            }

            item = root.Element("SwipeBorderSpeedMs");
            if (item != null)
            {
                Int32.TryParse(item.Value, out newConfig.SwipeBorderSpeedMs);
            }

            item = root.Element("TapMaxMsBetween");
            if (item != null)
            {
                Int32.TryParse(item.Value, out newConfig.TapMaxMsBetween);
            }

            item = root.Element("TapMaxDistance");
            if (item != null)
            {
                Int32.TryParse(item.Value, out newConfig.TapMaxDistance);
            }

            item = root.Element("ScrollSpeed");
            if (item != null)
            {
                Int32.TryParse(item.Value, out newConfig.ScrollSpeed);
            }

            item = root.Element("ScrollAccelerationEnabled");
            if (item != null)
            {
                Boolean.TryParse(item.Value, out newConfig.ScrollAccelerationEnabled);
            }

            item = root.Element("ScrollAcceleration");
            if (item != null)
            {
                Int32.TryParse(item.Value, out newConfig.ScrollAcceleration);
            }

            item = root.Element("ScrollReverse");
            if (item != null)
            {
                Boolean.TryParse(item.Value, out newConfig.ScrollReverse);
            }

            item = root.Element("ScrollHorizontal");
            if (item != null)
            {
                Boolean.TryParse(item.Value, out newConfig.ScrollHorizontal);
            }

            item = root.Element("ScrollVertical");
            if (item != null)
            {
                Boolean.TryParse(item.Value, out newConfig.ScrollVertical);
            }

            item = root.Element("SwipeTwoMovementXDirection");
            if (item != null)
            {
                Int32.TryParse(item.Value, out newConfig.SwipeTwoMovementXDirection);
            }

            item = root.Element("SwipeTwoMovementXOrthogonal");
            if (item != null)
            {
                Int32.TryParse(item.Value, out newConfig.SwipeTwoMovementXOrthogonal);
            }

            item = root.Element("SwipeTwoMovementYDirection");
            if (item != null)
            {
                Int32.TryParse(item.Value, out newConfig.SwipeTwoMovementYDirection);
            }

            item = root.Element("SwipeTwoMovementYOrthogonal");
            if (item != null)
            {
                Int32.TryParse(item.Value, out newConfig.SwipeTwoMovementYOrthogonal);
            }

            item = root.Element("SwipeThreeMovementXDirection");
            if (item != null)
            {
                Int32.TryParse(item.Value, out newConfig.ScrollAcceleration);
            }

            item = root.Element("SwipeThreeMovementXOrthogonal");
            if (item != null)
            {
                Int32.TryParse(item.Value, out newConfig.ScrollAcceleration);
            }

            item = root.Element("SwipeThreeMovementYDirection");
            if (item != null)
            {
                Int32.TryParse(item.Value, out newConfig.ScrollAcceleration);
            }

            item = root.Element("SwipeThreeMovementYOrthogonal");
            if (item != null)
            {
                Int32.TryParse(item.Value, out newConfig.ScrollAcceleration);
            }

            foreach (var action in root.Descendants("action"))
            {
                var id   = action.Attribute("id");
                var type = action.Attribute("type");
                if (type == null || id == null)
                {
                    break;
                }
                var invokeItem = ConfigInvokeItem.FromXElement(action);
                if (id.Value.Equals("MouseTapOne"))
                {
                    newConfig.MouseTapOne = invokeItem;
                }
                if (id.Value.Equals("MouseTapOneLong"))
                {
                    newConfig.MouseTapOneLong = invokeItem;
                }
                if (id.Value.Equals("MouseTapTwo"))
                {
                    newConfig.MouseTapTwo = invokeItem;
                }
                if (id.Value.Equals("MouseTapTwoLong"))
                {
                    newConfig.MouseTapTwoLong = invokeItem;
                }
                if (id.Value.Equals("MouseTapThree"))
                {
                    newConfig.MouseTapThree = invokeItem;
                }
                if (id.Value.Equals("MouseTapThreeLong"))
                {
                    newConfig.MouseTapThreeLong = invokeItem;
                }
                if (id.Value.Equals("SwipeTwoLeft"))
                {
                    newConfig.SwipeTwoLeft = invokeItem;
                }
                if (id.Value.Equals("SwipeTwoRight"))
                {
                    newConfig.SwipeTwoRight = invokeItem;
                }
                if (id.Value.Equals("SwipeThreeUp"))
                {
                    newConfig.SwipeThreeUp = invokeItem;
                }
                if (id.Value.Equals("SwipeThreeRight"))
                {
                    newConfig.SwipeThreeRight = invokeItem;
                }
                if (id.Value.Equals("SwipeThreeDown"))
                {
                    newConfig.SwipeThreeDown = invokeItem;
                }
                if (id.Value.Equals("SwipeThreeLeft"))
                {
                    newConfig.SwipeThreeLeft = invokeItem;
                }
                if (id.Value.Equals("SwipeBorderTop"))
                {
                    newConfig.SwipeBorderTop = invokeItem;
                }
                if (id.Value.Equals("SwipeBorderRight"))
                {
                    newConfig.SwipeBorderRight = invokeItem;
                }
                if (id.Value.Equals("SwipeBorderBottom"))
                {
                    newConfig.SwipeBorderBottom = invokeItem;
                }
                if (id.Value.Equals("SwipeBorderLeft"))
                {
                    newConfig.SwipeBorderLeft = invokeItem;
                }
            }

            return(newConfig);
        }