Esempio n. 1
0
        private void RegisterHotKey(XElement settings, string methodName, Action action)
        {
            if (typeof(AddIn).GetMethod(methodName)
                .GetCustomAttributes(typeof(CommandAttribute), false)
                .FirstOrDefault() is CommandAttribute cmd)
            {
                var hotkey = new Hotkey(cmd.DefaultKeys);

                var setting = settings?.Elements("command")
                              .FirstOrDefault(e => e.Attribute("command")?.Value == methodName);

                if (setting != null)
                {
                    if (Enum.TryParse <Keys>(setting.Attribute("keys")?.Value, true, out var keys))
                    {
                        // has user deliberately cleared command binding (?HasFlag doesn't work?)
                        if ((keys & Keys.KeyCode) == Keys.Back)
                        {
                            hotkey = null;
                        }
                        // has user overridden default binding
                        else if ((hotkey.Keys & hotkey.Modifiers) != keys)
                        {
                            hotkey = new Hotkey(keys);
                        }
                    }
                }

                if (hotkey != null)
                {
                    HotkeyManager.RegisterHotKey(action, hotkey);
                }
            }
        }
Esempio n. 2
0
        private void RegisterHotkeys()
        {
            HotkeyManager.RegisterHotKey(Forms.Keys.F, Hotmods.ControlAlt);
            HotkeyManager.RegisterHotKey(Forms.Keys.F, Hotmods.ControlShift);
            HotkeyManager.RegisterHotKey(Forms.Keys.OemMinus, Hotmods.AltShift);
            HotkeyManager.RegisterHotKey(Forms.Keys.Oemplus, Hotmods.AltShift);
            HotkeyManager.RegisterHotKey(Forms.Keys.F4);
            HotkeyManager.RegisterHotKey(Forms.Keys.V, Hotmods.ControlAlt);
            HotkeyManager.RegisterHotKey(Forms.Keys.H, Hotmods.Control);
            HotkeyManager.RegisterHotKey(Forms.Keys.U, Hotmods.ControlShift);
            HotkeyManager.RegisterHotKey(Forms.Keys.U, Hotmods.ControlAltShift);
            HotkeyManager.RegisterHotKey(Forms.Keys.Oemplus, Hotmods.ControlAlt);
            HotkeyManager.RegisterHotKey(Forms.Keys.OemMinus, Hotmods.ControlAlt);
            HotkeyManager.RegisterHotKey(Forms.Keys.X, Hotmods.ControlAltShift);
            HotkeyManager.RegisterHotKey(Forms.Keys.F8);

            HotkeyManager.HotKeyPressed += HotkeyHandler;
        }
Esempio n. 3
0
        private void RegisterHotkeys()
        {
            logger.WriteLine("defining hotkeys");

            HotkeyManager.Initialize();

            HotkeyManager.RegisterHotKey(async() => await AddFootnoteCmd(null),
                                         Keys.F, Hotmods.ControlAlt);

            HotkeyManager.RegisterHotKey(async() => await AddFormulaCmd(null),
                                         Keys.F5);

            HotkeyManager.RegisterHotKey(async() => await DecreaseFontSizeCmd(null),
                                         Keys.OemMinus, Hotmods.ControlAlt);

            HotkeyManager.RegisterHotKey(async() => await HighlightCmd(null),
                                         Keys.H, Hotmods.ControlShift);

            HotkeyManager.RegisterHotKey(async() => await IncreaseFontSizeCmd(null),
                                         Keys.Oemplus, Hotmods.ControlAlt);

            HotkeyManager.RegisterHotKey(async() => await InsertCodeBlockCmd(null),
                                         Keys.F6);

            HotkeyManager.RegisterHotKey(async() => await InsertDateCmd(null),
                                         Keys.D, Hotmods.ControlShift);

            HotkeyManager.RegisterHotKey(async() => await InsertDoubleHorizontalLineCmd(null),
                                         Keys.F12, Hotmods.AltShift);

            HotkeyManager.RegisterHotKey(async() => await InsertHorizontalLineCmd(null),
                                         Keys.F11, Hotmods.AltShift);

            HotkeyManager.RegisterHotKey(async() => await NoSpellCheckCmd(null),
                                         Keys.F4);

            HotkeyManager.RegisterHotKey(async() => await PasteRtfCmd(null),
                                         Keys.V, Hotmods.ControlAlt);

            HotkeyManager.RegisterHotKey(async() => await RecalculateFormulaCmd(null),
                                         Keys.F5, Hotmods.Shift);

            HotkeyManager.RegisterHotKey(async() => await RemoveFootnoteCmd(null),
                                         Keys.F, Hotmods.ControlShift);

            HotkeyManager.RegisterHotKey(async() => await SearchCmd(null),
                                         Keys.F, Hotmods.Alt);

            HotkeyManager.RegisterHotKey(async() => await SearchAndReplaceCmd(null),
                                         Keys.H, Hotmods.Control);

            HotkeyManager.RegisterHotKey(async() => await TaggedCmd(null),
                                         Keys.T, Hotmods.ControlAlt);

            HotkeyManager.RegisterHotKey(async() => await TaggingCmd(null),
                                         Keys.T, Hotmods.Alt);

            HotkeyManager.RegisterHotKey(async() => await ToLowercaseCmd(null),
                                         Keys.U, Hotmods.ControlShift);

            HotkeyManager.RegisterHotKey(async() => await ToUppercaseCmd(null),
                                         Keys.U, Hotmods.ControlAltShift);

            // tools

            HotkeyManager.RegisterHotKey(async() => await ShowXmlCmd(null),
                                         Keys.X, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(async() => await factory.Run <DiagnosticsCommand>(),
                                         Keys.F8);

            HotkeyManager.RegisterHotKey(async() => await factory.Run <ClearLogCommand>(),
                                         Keys.F8, Hotmods.Control);

            // custom styles, CtrlAltShift+1..9

            HotkeyManager.RegisterHotKey(async() => await factory.Run <ApplyStyleCommand>(0),
                                         Keys.D1, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(async() => await factory.Run <ApplyStyleCommand>(1),
                                         Keys.D2, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(async() => await factory.Run <ApplyStyleCommand>(2),
                                         Keys.D3, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(async() => await factory.Run <ApplyStyleCommand>(3),
                                         Keys.D4, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(async() => await factory.Run <ApplyStyleCommand>(4),
                                         Keys.D5, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(async() => await factory.Run <ApplyStyleCommand>(5),
                                         Keys.D6, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(async() => await factory.Run <ApplyStyleCommand>(6),
                                         Keys.D7, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(async() => await factory.Run <ApplyStyleCommand>(7),
                                         Keys.D8, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(async() => await factory.Run <ApplyStyleCommand>(9),
                                         Keys.D9, Hotmods.ControlAltShift);
        }
Esempio n. 4
0
        private void RegisterHotkeys()
        {
            HotkeyManager.Initialize();

            HotkeyManager.RegisterHotKey(() =>
                                         AddFootnoteCmd(null),
                                         Keys.F, Hotmods.ControlAlt);

            HotkeyManager.RegisterHotKey(() =>
                                         RemoveFootnoteCmd(null),
                                         Keys.F, Hotmods.ControlShift);

            HotkeyManager.RegisterHotKey(() =>
                                         AddFormulaCmd(null),
                                         Keys.F5);

            HotkeyManager.RegisterHotKey(() =>
                                         RecalculateFormulaCmd(null),
                                         Keys.F5, Hotmods.Shift);

            HotkeyManager.RegisterHotKey(() =>
                                         InsertCodeBlockCmd(null),
                                         Keys.F6);

            HotkeyManager.RegisterHotKey(() =>
                                         InsertHorizontalLineCmd(null),
                                         Keys.OemMinus, Hotmods.AltShift);

            HotkeyManager.RegisterHotKey(() =>
                                         InsertDoubleHorizontalLineCmd(null),
                                         Keys.Oemplus, Hotmods.AltShift);

            HotkeyManager.RegisterHotKey(() =>
                                         NoSpellCheckCmd(null),
                                         Keys.F4);

            HotkeyManager.RegisterHotKey(() =>
                                         PasteRtfCmd(null),
                                         Keys.V, Hotmods.ControlAlt);

            HotkeyManager.RegisterHotKey(() =>
                                         SearchCmd(null),
                                         Keys.F, Hotmods.Alt);

            HotkeyManager.RegisterHotKey(() =>
                                         SearchAndReplaceCmd(null),
                                         Keys.H, Hotmods.Control);

            HotkeyManager.RegisterHotKey(() =>
                                         ToLowercaseCmd(null),
                                         Keys.U, Hotmods.ControlShift);

            HotkeyManager.RegisterHotKey(() =>
                                         ToUppercaseCmd(null),
                                         Keys.U, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(() =>
                                         IncreaseFontSizeCmd(null),
                                         Keys.Oemplus, Hotmods.ControlAlt);

            HotkeyManager.RegisterHotKey(() =>
                                         DecreaseFontSizeCmd(null),
                                         Keys.OemMinus, Hotmods.ControlAlt);

            HotkeyManager.RegisterHotKey(() =>
                                         ShowXmlCmd(null),
                                         Keys.X, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(() =>
                                         factory.Run <DiagnosticsCommand>(),
                                         Keys.F8);

            HotkeyManager.RegisterHotKey(() =>
                                         factory.Run <ClearLogCommand>(),
                                         Keys.F8, Hotmods.Control);

            // custom styles, CtrlAltShift+1..9

            HotkeyManager.RegisterHotKey(() =>
                                         factory.Run <ApplyStyleCommand>(0),
                                         Keys.D1, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(() =>
                                         factory.Run <ApplyStyleCommand>(1),
                                         Keys.D2, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(() =>
                                         factory.Run <ApplyStyleCommand>(2),
                                         Keys.D3, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(() =>
                                         factory.Run <ApplyStyleCommand>(3),
                                         Keys.D4, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(() =>
                                         factory.Run <ApplyStyleCommand>(4),
                                         Keys.D5, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(() =>
                                         factory.Run <ApplyStyleCommand>(5),
                                         Keys.D6, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(() =>
                                         factory.Run <ApplyStyleCommand>(6),
                                         Keys.D7, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(() =>
                                         factory.Run <ApplyStyleCommand>(7),
                                         Keys.D8, Hotmods.ControlAltShift);

            HotkeyManager.RegisterHotKey(() =>
                                         factory.Run <ApplyStyleCommand>(9),
                                         Keys.D9, Hotmods.ControlAltShift);
        }