Ejemplo n.º 1
0
        private static string ConvertHotkey(HotkeySettings hotkey)
        {
            Key         key   = KeyInterop.KeyFromVirtualKey(hotkey.Code);
            HotkeyModel model = new HotkeyModel(hotkey.Alt, hotkey.Shift, hotkey.Win, hotkey.Ctrl, key);

            return(model.ToString());
        }
Ejemplo n.º 2
0
        public HotkeySettingsControl()
        {
            InitializeComponent();
            internalSettings = new HotkeySettings();

            HotkeyTextBox.PreviewKeyDown += HotkeyTextBox_KeyDown;
            HotkeyTextBox.LostFocus      += HotkeyTextBox_LosingFocus;
        }
Ejemplo n.º 3
0
 public void AssertHotkeySettings(HotkeySettings setting, bool win, bool ctrl, bool alt, bool shift, int code)
 {
     Assert.AreEqual(win, setting.Win);
     Assert.AreEqual(ctrl, setting.Ctrl);
     Assert.AreEqual(alt, setting.Alt);
     Assert.AreEqual(shift, setting.Shift);
     Assert.AreEqual(code, setting.Code);
 }
Ejemplo n.º 4
0
        public void Hotkeys_ShouldUpdateHotkeys()
        {
            var openPowerLauncher = new HotkeySettings();

            openPowerLauncher.Win  = true;
            openPowerLauncher.Code = (int)Windows.System.VirtualKey.S;

            var openFileLocation = new HotkeySettings();

            openFileLocation.Ctrl = true;
            openFileLocation.Code = (int)Windows.System.VirtualKey.A;

            var openConsole = new HotkeySettings();

            openConsole.Alt  = true;
            openConsole.Code = (int)Windows.System.VirtualKey.D;

            var copyFileLocation = new HotkeySettings();

            copyFileLocation.Shift = true;
            copyFileLocation.Code  = (int)Windows.System.VirtualKey.F;

            viewModel.OpenPowerLauncher = openPowerLauncher;
            viewModel.OpenFileLocation  = openFileLocation;
            viewModel.OpenConsole       = openConsole;
            viewModel.CopyPathLocation  = copyFileLocation;

            Assert.AreEqual(4, sendCallbackMock.TimesSent);

            AssertHotkeySettings(
                mockSettings.Properties.OpenPowerLauncher,
                true,
                false,
                false,
                false,
                (int)Windows.System.VirtualKey.S);
            AssertHotkeySettings(
                mockSettings.Properties.OpenFileLocation,
                false,
                true,
                false,
                false,
                (int)Windows.System.VirtualKey.A);
            AssertHotkeySettings(
                mockSettings.Properties.OpenConsole,
                false,
                false,
                true,
                false,
                (int)Windows.System.VirtualKey.D);
            AssertHotkeySettings(
                mockSettings.Properties.CopyPathLocation,
                false,
                false,
                false,
                true,
                (int)Windows.System.VirtualKey.F);
        }
Ejemplo n.º 5
0
        private void HotkeyTextBox_LosingFocus(object sender, RoutedEventArgs e)
        {
            if (internalSettings.IsValid() || internalSettings.IsEmpty())
            {
                HotkeySettings = internalSettings;
            }

            HotkeyTextBox.Text = hotkeySettings.ToString();
        }
 public PowerLauncherProperties()
 {
     open_powerlauncher       = new HotkeySettings();
     open_file_location       = new HotkeySettings();
     copy_path_location       = new HotkeySettings();
     open_console             = new HotkeySettings();
     search_result_preference = "most_recently_used";
     search_type_preference   = "application_name";
 }
        public HotkeySelectionControl(HotkeySettings hotkeySetting)
        {
            InitializeComponent();

            HotkeySetting = hotkeySetting;

            UpdateDescription();
            UpdateHotkeyText();
        }
Ejemplo n.º 8
0
        public HotkeySettingsControl()
        {
            InitializeComponent();
            internalSettings = new HotkeySettings();

            HotkeyTextBox.GettingFocus += HotkeyTextBox_GettingFocus;
            HotkeyTextBox.LosingFocus  += HotkeyTextBox_LosingFocus;
            hook = new HotkeySettingsControlHook(Hotkey_KeyDown, Hotkey_KeyUp, Hotkey_IsActive);
        }
Ejemplo n.º 9
0
        private void AddHotkeySelectionControl(HotkeySettings hotkeySetting)
        {
            HKSControl control = _factory.CreateHKControl(hotkeySetting);

            control.Margin = new Padding(25, 0, 0, 2);
            control.HotkeyChanged += control_HotkeyChanged;

            _flpHotkeys.Controls.Add(control);
        }
        private void HotkeyTextBox_LosingFocus(object sender, RoutedEventArgs e)
        {
            if (lastValidSettings != null && (lastValidSettings.IsValid() || lastValidSettings.IsEmpty()))
            {
                HotkeySettings = lastValidSettings.Clone();
            }

            HotkeyTextBox.Text = hotkeySettings.ToString();
            _isActive          = false;
        }
        public HotkeySettingsControl()
        {
            InitializeComponent();
            internalSettings = new HotkeySettings();

            HotkeyTextBox.GettingFocus += HotkeyTextBox_GettingFocus;
            HotkeyTextBox.LosingFocus  += HotkeyTextBox_LosingFocus;
            HotkeyTextBox.Unloaded     += HotkeyTextBox_Unloaded;
            hook = new HotkeySettingsControlHook(Hotkey_KeyDown, Hotkey_KeyUp, Hotkey_IsActive, FilterAccessibleKeyboardEvents);
        }
Ejemplo n.º 12
0
 public PowerLauncherProperties()
 {
     open_powerlauncher           = new HotkeySettings();
     open_file_location           = new HotkeySettings();
     copy_path_location           = new HotkeySettings();
     open_console                 = new HotkeySettings();
     search_result_preference     = "most_recently_used";
     search_type_preference       = "application_name";
     ignore_hotkeys_in_fullscreen = false;
     clear_input_on_launch        = false;
 }
Ejemplo n.º 13
0
 private static bool ComboIsValid(HotkeySettings settings)
 {
     if (settings != null && (settings.IsValid() || settings.IsEmpty()))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 14
0
 private async void Hotkey_KeyDown(int key)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         KeyEventHandler(key, true, key, Lib.Utilities.Helper.GetKeyName((uint)key));
         if (internalSettings.Code > 0)
         {
             lastValidSettings  = internalSettings.Clone();
             HotkeyTextBox.Text = lastValidSettings.ToString();
         }
     });
 }
Ejemplo n.º 15
0
#pragma warning disable CA1801 // Review unused parameters
        private void ShortcutDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
#pragma warning restore CA1801 // Review unused parameters
        {
            if (ComboIsValid(lastValidSettings))
            {
                HotkeySettings = lastValidSettings.Clone();
            }

            PreviewKeysControl.ItemsSource = hotkeySettings.GetKeysList();
            AutomationProperties.SetHelpText(EditButton, HotkeySettings.ToString());
            shortcutDialog.Hide();
        }
Ejemplo n.º 16
0
        public void InvalidSettingKeyWontAdd()
        {
            var settings = new HotkeySettings();
            var expected = settings.Settings;

            settings.Settings = new[] { new HotkeySetting {
                                            Name = "ParseAll", IsEnabled = false, Key1 = "Foobar"
                                        } };

            var actual = settings.Settings;

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
Ejemplo n.º 17
0
        public void DefaultsSetInCtor()
        {
            var expected = new[]
            {
                new HotkeySetting {
                    Name = RubberduckHotkey.ParseAll.ToString(), IsEnabled = true, HasCtrlModifier = true, Key1 = "`"
                },
                new HotkeySetting {
                    Name = RubberduckHotkey.IndentProcedure.ToString(), IsEnabled = true, HasCtrlModifier = true, Key1 = "P"
                },
                new HotkeySetting {
                    Name = RubberduckHotkey.IndentModule.ToString(), IsEnabled = true, HasCtrlModifier = true, Key1 = "M"
                },
                new HotkeySetting {
                    Name = RubberduckHotkey.CodeExplorer.ToString(), IsEnabled = true, HasCtrlModifier = true, Key1 = "R"
                },
                new HotkeySetting {
                    Name = RubberduckHotkey.FindSymbol.ToString(), IsEnabled = true, HasCtrlModifier = true, Key1 = "T"
                },
                new HotkeySetting {
                    Name = RubberduckHotkey.InspectionResults.ToString(), IsEnabled = true, HasCtrlModifier = true, HasShiftModifier = true, Key1 = "I"
                },
                new HotkeySetting {
                    Name = RubberduckHotkey.TestExplorer.ToString(), IsEnabled = true, HasCtrlModifier = true, HasShiftModifier = true, Key1 = "T"
                },
                new HotkeySetting {
                    Name = RubberduckHotkey.RefactorMoveCloserToUsage.ToString(), IsEnabled = true, HasCtrlModifier = true, HasShiftModifier = true, Key1 = "C"
                },
                new HotkeySetting {
                    Name = RubberduckHotkey.RefactorRename.ToString(), IsEnabled = true, HasCtrlModifier = true, HasShiftModifier = true, Key1 = "R"
                },
                new HotkeySetting {
                    Name = RubberduckHotkey.RefactorExtractMethod.ToString(), IsEnabled = true, HasCtrlModifier = true, HasShiftModifier = true, Key1 = "M"
                },
                new HotkeySetting {
                    Name = RubberduckHotkey.SourceControl.ToString(), IsEnabled = true, HasCtrlModifier = true, HasShiftModifier = true, Key1 = "D6"
                },
                new HotkeySetting {
                    Name = RubberduckHotkey.RefactorEncapsulateField.ToString(), IsEnabled = true, HasCtrlModifier = true, HasShiftModifier = true, Key1 = "F"
                },
                new HotkeySetting {
                    Name = RubberduckHotkey.ExportActiveProject.ToString(), IsEnabled = true, HasCtrlModifier = true, HasShiftModifier = true, Key1 = "E"
                }
            };

            var settings = new HotkeySettings();
            var actual   = settings.Settings;

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
Ejemplo n.º 18
0
        private void HotkeyTextBox_KeyDown(object sender, KeyRoutedEventArgs e)
        {
            e.Handled = true;
            if (
                e.Key == Windows.System.VirtualKey.LeftWindows ||
                e.Key == Windows.System.VirtualKey.RightWindows ||
                e.Key == Windows.System.VirtualKey.Control ||
                e.Key == Windows.System.VirtualKey.Menu ||
                e.Key == Windows.System.VirtualKey.Shift)
            {
                return;
            }

            if (e.Key == Windows.System.VirtualKey.Escape)
            {
                internalSettings = new HotkeySettings();
                HotkeySettings   = new HotkeySettings();
                return;
            }

            var settings = new HotkeySettings();

            // Display HotKey value
            if (IsDown(Windows.System.VirtualKey.LeftWindows) ||
                IsDown(Windows.System.VirtualKey.RightWindows))
            {
                settings.Win = true;
            }

            if (IsDown(Windows.System.VirtualKey.Control))
            {
                settings.Ctrl = true;
            }

            if (IsDown(Windows.System.VirtualKey.Menu))
            {
                settings.Alt = true;
            }

            if (IsDown(Windows.System.VirtualKey.Shift))
            {
                settings.Shift = true;
            }

            settings.Key = Lib.Utilities.Helper.GetKeyName((uint)e.Key);

            settings.Code      = (int)e.OriginalKey;
            internalSettings   = settings;
            HotkeyTextBox.Text = internalSettings.ToString();
        }
Ejemplo n.º 19
0
        public void RegisterHotkey(HotkeySettings hotkeySetting)
        {
            UnregisterHotkey(hotkeySetting, false);

            if (hotkeySetting.HotkeyInfo.Status != HotkeyStatus.Registered && hotkeySetting.HotkeyInfo.IsValidHotkey)
            {
                _hotkey.RegisterHotkey(hotkeySetting.HotkeyInfo);
            }

            if (!Hotkeys.Contains(hotkeySetting))
            {
                Hotkeys.Add(hotkeySetting);
            }
        }
Ejemplo n.º 20
0
        public void Hotkeys_ShouldUpdateHotkeys()
        {
            var openPowerLauncher = new HotkeySettings();

            openPowerLauncher.Win  = true;
            openPowerLauncher.Code = 83;

            var openFileLocation = new HotkeySettings();

            openFileLocation.Ctrl = true;
            openFileLocation.Code = 65;

            var openConsole = new HotkeySettings();

            openConsole.Alt  = true;
            openConsole.Code = 68;

            var copyFileLocation = new HotkeySettings();

            copyFileLocation.Shift = true;
            copyFileLocation.Code  = 70;

            viewModel.OpenPowerLauncher = openPowerLauncher;
            viewModel.OpenFileLocation  = openFileLocation;
            viewModel.CopyPathLocation  = copyFileLocation;

            Assert.AreEqual(3, sendCallbackMock.TimesSent);

            AssertHotkeySettings(
                mockSettings.Properties.OpenPowerLauncher,
                true,
                false,
                false,
                false,
                83);
            AssertHotkeySettings(
                mockSettings.Properties.OpenFileLocation,
                false,
                true,
                false,
                false,
                65);
            AssertHotkeySettings(
                mockSettings.Properties.CopyPathLocation,
                false,
                false,
                false,
                true,
                70);
        }
        private async void Hotkey_KeyDown(int key)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                KeyEventHandler(key, true, key, Library.Utilities.Helper.GetKeyName((uint)key));

                // Tab and Shift+Tab are accessible keys and should not be displayed in the hotkey control.
                if (internalSettings.Code > 0 && !internalSettings.IsAccessibleShortcut())
                {
                    HotkeyTextBox.Text = internalSettings.ToString();
                    lastValidSettings  = internalSettings.Clone();
                }
            });
        }
Ejemplo n.º 22
0
 public static void AssertHotkeySettings(HotkeySettings setting, bool win, bool ctrl, bool alt, bool shift, int code)
 {
     if (setting != null)
     {
         Assert.AreEqual(win, setting.Win);
         Assert.AreEqual(ctrl, setting.Ctrl);
         Assert.AreEqual(alt, setting.Alt);
         Assert.AreEqual(shift, setting.Shift);
         Assert.AreEqual(code, setting.Code);
     }
     else
     {
         Assert.Fail("setting parameter is null");
     }
 }
Ejemplo n.º 23
0
        public void DidDefaultSettingsChangeTest2()
        {
            // arrange
            var defaultHotkeySettingsArray = new HotkeySettings[2] {
                new HotkeySettings("settings1", new HotkeyCommand(1, "C1")),
                new HotkeySettings("settings2", new HotkeyCommand(3, "C3"), new HotkeyCommand(2, "C2"), new HotkeyCommand(4, "C4"))
            };

            var loadedHotkeySettingsArray = new HotkeySettings[2] {
                new HotkeySettings("settings1", new HotkeyCommand(1, "C1"), new HotkeyCommand(4, "C4")),
                new HotkeySettings("settings2", new HotkeyCommand(3, "C3"), new HotkeyCommand(2, "C2"))
            };

            // act, assert
            HotkeySettingsManager.DidDefaultSettingsChange(defaultHotkeySettingsArray, loadedHotkeySettingsArray).Should().BeTrue();
        }
        public void DuplicateNamesAreIgnored()
        {
            var expected = new HotkeySetting {
                CommandTypeName = "FooCommand", IsEnabled = true, Key1 = "X"
            };
            var duplicate = new HotkeySetting {
                CommandTypeName = "FooCommand", IsEnabled = true, Key1 = "Y"
            };

            var settings = new HotkeySettings
            {
                Settings = new[] { expected, duplicate }
            };

            Assert.IsFalse(settings.Settings.Contains(duplicate));
        }
        public void DuplicateKeysAreDeactivated()
        {
            var duplicate1 = new HotkeySetting {
                CommandTypeName = "FooCommand", IsEnabled = true, Key1 = "X"
            };
            var duplicate2 = new HotkeySetting {
                CommandTypeName = "BarCommand", IsEnabled = true, Key1 = "X"
            };

            // ReSharper disable once UnusedVariable
            var settings = new HotkeySettings
            {
                Settings = new[] { duplicate1, duplicate2 }
            };

            Assert.IsFalse(duplicate1.IsEnabled == duplicate2.IsEnabled);
        }
        private async void Hotkey_KeyDown(int key)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                KeyEventHandler(key, true, key);

                c.Keys = internalSettings.GetKeysList();

                if (internalSettings.GetKeysList().Count == 0)
                {
                    // Empty, disable save button
                    shortcutDialog.IsPrimaryButtonEnabled = false;
                }
                else if (internalSettings.GetKeysList().Count == 1)
                {
                    // 1 key, disable save button
                    shortcutDialog.IsPrimaryButtonEnabled = false;

                    // Check if the one key is a hotkey
                    if (internalSettings.Shift || internalSettings.Win || internalSettings.Alt || internalSettings.Ctrl)
                    {
                        c.IsError = false;
                    }
                    else
                    {
                        c.IsError = true;
                    }
                }

                // Tab and Shift+Tab are accessible keys and should not be displayed in the hotkey control.
                if (internalSettings.Code > 0 && !internalSettings.IsAccessibleShortcut())
                {
                    lastValidSettings = internalSettings.Clone();

                    if (!ComboIsValid(lastValidSettings))
                    {
                        DisableKeys();
                    }
                    else
                    {
                        EnableKeys();
                    }
                }
            });
        }
Ejemplo n.º 27
0
        private void UpdateListViewItems(HotkeySettings setting)
        {
            this.SelectedHotkeyCommand = null;

            this.listMappings.Items.Clear();
            if (setting != null)
            {
                foreach (var cmd in setting.Commands)
                {
                    if (cmd != null)
                    {
                        var item = new ListViewItem(new[] { cmd.Name, cmd.KeyData.ToText() ?? _hotkeyNotSet.Text });
                        item.Tag = cmd;
                        this.listMappings.Items.Add(item);
                    }
                }
            }
        }
        public void InvalidSettingNameWontAdd()
        {
            var settings = new HotkeySettings(new[]
            {
                new HotkeySetting {
                    CommandTypeName = "FooCommand", Key1 = "F"
                }
            });

            var expected = settings.Settings;

            settings.Settings = new[]
            { new HotkeySetting {
                  CommandTypeName = "BarCommand", IsEnabled = false, Key1 = "CTRL-C"
              } };

            var actual = settings.Settings;

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
Ejemplo n.º 29
0
        private void UpdateListViewItems(HotkeySettings setting)
        {
            SelectedHotkeyCommand = null;

            listMappings.Items.Clear();
            if (setting is not null)
            {
                foreach (var cmd in setting.Commands)
                {
                    if (cmd is not null)
                    {
                        listMappings.Items.Add(
                            new ListViewItem(new[] { cmd.Name, cmd.KeyData.ToText() })
                        {
                            Tag = cmd
                        });
                    }
                }
            }
        }
Ejemplo n.º 30
0
        private void KeyEventHandler(int key, bool matchValue, int matchValueCode)
        {
            switch ((VirtualKey)key)
            {
            case VirtualKey.LeftWindows:
            case VirtualKey.RightWindows:
                internalSettings.Win = matchValue;
                break;

            case VirtualKey.Control:
            case VirtualKey.LeftControl:
            case VirtualKey.RightControl:
                internalSettings.Ctrl = matchValue;
                break;

            case VirtualKey.Menu:
            case VirtualKey.LeftMenu:
            case VirtualKey.RightMenu:
                internalSettings.Alt = matchValue;
                break;

            case VirtualKey.Shift:
            case VirtualKey.LeftShift:
            case VirtualKey.RightShift:
                _shiftToggled          = true;
                internalSettings.Shift = matchValue;
                break;

            case VirtualKey.Escape:
                internalSettings = new HotkeySettings();
                shortcutDialog.IsPrimaryButtonEnabled = false;
                return;

            default:
                internalSettings.Code = matchValueCode;
                break;
            }
        }
        private void KeyEventHandler(int key, bool matchValue, int matchValueCode, string matchValueText)
        {
            switch ((Windows.System.VirtualKey)key)
            {
            case Windows.System.VirtualKey.LeftWindows:
            case Windows.System.VirtualKey.RightWindows:
                internalSettings.Win = matchValue;
                break;

            case Windows.System.VirtualKey.Control:
            case Windows.System.VirtualKey.LeftControl:
            case Windows.System.VirtualKey.RightControl:
                internalSettings.Ctrl = matchValue;
                break;

            case Windows.System.VirtualKey.Menu:
            case Windows.System.VirtualKey.LeftMenu:
            case Windows.System.VirtualKey.RightMenu:
                internalSettings.Alt = matchValue;
                break;

            case Windows.System.VirtualKey.Shift:
            case Windows.System.VirtualKey.LeftShift:
            case Windows.System.VirtualKey.RightShift:
                _shiftToggled          = true;
                internalSettings.Shift = matchValue;
                break;

            case Windows.System.VirtualKey.Escape:
                internalSettings = new HotkeySettings();
                HotkeySettings   = new HotkeySettings();
                return;

            default:
                internalSettings.Code = matchValueCode;
                break;
            }
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HotkeyService"/> class.
        /// </summary>
        public HotkeyService()
        {
            this._settings = new HotkeySettings();
            if (!File.Exists(this.FilePath))
            {
                using (var file = File.Create(this.FilePath))
                {
                }

                this.Save();
            }
            else
            {
                try
                {
                    this._settings.ReadJsonFile(this.FilePath);
                }
                catch
                {
                    File.Delete(this.FilePath);
                }
            }
        }
Ejemplo n.º 33
0
        public ShortcutControl()
        {
            InitializeComponent();
            internalSettings = new HotkeySettings();

            this.Unloaded += ShortcutControl_Unloaded;
            hook           = new HotkeySettingsControlHook(Hotkey_KeyDown, Hotkey_KeyUp, Hotkey_IsActive, FilterAccessibleKeyboardEvents);
            ResourceLoader resourceLoader = ResourceLoader.GetForViewIndependentUse();

            // We create the Dialog in C# because doing it in XAML is giving WinUI/XAML Island bugs when using dark theme.
            shortcutDialog = new ContentDialog
            {
                XamlRoot          = this.XamlRoot,
                Title             = resourceLoader.GetString("Activation_Shortcut_Title"),
                Content           = c,
                PrimaryButtonText = resourceLoader.GetString("Activation_Shortcut_Save"),
                CloseButtonText   = resourceLoader.GetString("Activation_Shortcut_Cancel"),
                DefaultButton     = ContentDialogButton.Primary,
            };
            shortcutDialog.PrimaryButtonClick += ShortcutDialog_PrimaryButtonClick;
            shortcutDialog.Opened             += ShortcutDialog_Opened;
            shortcutDialog.Closing            += ShortcutDialog_Closing;
        }
Ejemplo n.º 34
0
        public void UnregisterHotkey(HotkeySettings hotkeySetting, bool removeFromList = true)
        {
            if (hotkeySetting.HotkeyInfo.Status == HotkeyStatus.Registered)
            {
                _hotkey.UnregisterHotkey(hotkeySetting.HotkeyInfo);
            }

            if (removeFromList)
            {
                Hotkeys.Remove(hotkeySetting);
            }
        }
Ejemplo n.º 35
0
 private void OnHotkeyTrigger(HotkeySettings hotkeySetting)
 {
     if (HotkeyTrigger != null)
     {
         HotkeyTrigger(hotkeySetting);
     }
 }
Ejemplo n.º 36
0
 public HKSControl CreateHKControl(HotkeySettings arg)
 {
     return new HotkeySelectionControl(arg);
 }