예제 #1
0
        /// <summary>
        /// Loads keybindings from the configuration file and registers them with Windows.
        /// </summary>
        private void AssignHotkeys(HotkeyManager hotkeyManager)
        {
            try
            {
                foreach (var hotkey in ConfigManager.Config.Hotkeys ?? new HotkeyConfig[] {})
                {
                    var          keys = KeyCombination.Parse(hotkey.Hotkey);
                    HotkeyAction action;
                    try
                    {
                        // Reading the Action variable will cause it to be parsed from hotkey.ActionString.
                        // If this fails, an ArgumentException is thrown.
                        action = hotkey.Action;
                    }
                    catch (ArgumentException)
                    {
                        RaiseNotification($"Invalid hotkey configuration in config.yaml.\nThe action \"{hotkey.ActionString}\" is not known.", ToolTipIcon.Error);
                        continue;
                    }
                    switch (action)
                    {
                    case HotkeyAction.DecryptPassword:
                        hotkeyManager.AddHotKey(keys, () => DecryptPassword(hotkey.Options.CopyToClipboard, hotkey.Options.TypeUsername, hotkey.Options.TypePassword));
                        break;

                    case HotkeyAction.AddPassword:
                        hotkeyManager.AddHotKey(keys, AddPassword);
                        break;

                    case HotkeyAction.EditPassword:
                        hotkeyManager.AddHotKey(keys, EditPassword);
                        break;

                    case HotkeyAction.GitPull:
                        hotkeyManager.AddHotKey(keys, UpdatePasswordStore);
                        break;

                    case HotkeyAction.GitPush:
                        hotkeyManager.AddHotKey(keys, CommitChanges);
                        break;

                    case HotkeyAction.OpenShell:
                        hotkeyManager.AddHotKey(keys, OpenPasswordShell);
                        break;

                    case HotkeyAction.ShowDebugInfo:
                        hotkeyManager.AddHotKey(keys, ShowDebugInfo);
                        break;
                    }
                }
            }
            catch (Exception e) when(e is ArgumentException || e is HotkeyException)
            {
                RaiseNotification(e.Message, ToolTipIcon.Error);
                Exit();
            }
        }
        protected bool IsPressed(HotkeyConfig hotkey)
        {
            var combination = KeyCombination.Parse(hotkey.Hotkey);

            if (combination.Key != Key.None)
            {
                if (!Keyboard.IsKeyDown(combination.Key))
                {
                    return(false);
                }
            }
            return(Keyboard.Modifiers == combination.ModifierKeys);
        }
예제 #3
0
        public static TableTile FromXElement(XElement xElement, ref List <ExceptionPsHandler> exceptions, string exceptionHeader)
        {
            var tableTile = new TableTile();

            try
            {
                tableTile.Name = xElement.Element("Name").Value;
            }
            catch (Exception e)
            {
                exceptions.Add(new ExceptionPsHandler(e, exceptionHeader + " TableTile.FromXElement() xElement:" + Environment.NewLine + xElement));
                return(null);
            }
            try
            {
                tableTile.IsEnabled = bool.Parse(xElement.Element("IsEnabled").Value);
            }
            catch
            {
            }
            try
            {
                tableTile.KeyCombination = KeyCombination.Parse(xElement.Element("Hotkey").Value);
            }
            catch
            {
            }
            try
            {
                tableTile.SortByStartingHand = bool.Parse(xElement.Element("SortByStartingHand").Value);
            }
            catch
            {
            }
            try
            {
                tableTile.BringToFront = bool.Parse(xElement.Element("BringToFront").Value);
            }
            catch
            {
            }
            try
            {
                tableTile.AutoTile = bool.Parse(xElement.Element("AutoTile").Value);
            }
            catch
            {
            }
            try
            {
                tableTile.AutoTileMethod = ParseAutoTileMethod(xElement.Element("AutoTileMethod").Value);
            }
            catch
            {
            }
            try
            {
                tableTile.RegexWindowTitle = new Regex(xElement.Element("RegexWindowTitle").Value);
            }
            catch
            {
            }
            try
            {
                tableTile.RegexWindowClass = new Regex(xElement.Element("RegexWindowClass").Value);
            }
            catch
            {
            }
            try
            {
                tableTile.XYWHs = xElement.Element("XYWHs") == null ? new Rectangle[0] : xElement.Element("XYWHs").Elements().Select(o =>
                {
                    string[] s = o.Value.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    return(new Rectangle(int.Parse(s[0]), int.Parse(s[1]), int.Parse(s[2]), int.Parse(s[3])));
                }).ToArray();
            }
            catch
            {
            }
            try
            {
                tableTile.TableCountEqualOrGreaterThan = int.Parse(xElement.Element("TableCountEqualOrGreaterThan").Value);
            }
            catch
            {
            }
            try
            {
                tableTile.TableCountEqualOrLessThan = int.Parse(xElement.Element("TableCountEqualOrLessThan").Value);
            }
            catch
            {
            }

            return(tableTile);
        }