Example #1
0
        private void btnAdd_OnClick(object sender, RoutedEventArgs e)
        {
            if (!update)
            {
                if (!ctlHotkey.CurrentHotkeyAvailable)
                {
                    MessageBox.Show(InternationalizationManager.Instance.GetTranslation("hotkeyIsNotUnavailable"));
                    return;
                }

                if (UserSettingStorage.Instance.CustomPluginHotkeys == null)
                {
                    UserSettingStorage.Instance.CustomPluginHotkeys = new List <CustomPluginHotkey>();
                }

                var pluginHotkey = new CustomPluginHotkey
                {
                    Hotkey        = ctlHotkey.CurrentHotkey.ToString(),
                    ActionKeyword = tbAction.Text
                };
                UserSettingStorage.Instance.CustomPluginHotkeys.Add(pluginHotkey);

                SetHotkey(ctlHotkey.CurrentHotkey, delegate
                {
                    App.API.ChangeQuery(pluginHotkey.ActionKeyword);
                    App.API.ShowApp();
                });
                MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
            }
            else
            {
                if (updateCustomHotkey.Hotkey != ctlHotkey.CurrentHotkey.ToString() && !ctlHotkey.CurrentHotkeyAvailable)
                {
                    MessageBox.Show(InternationalizationManager.Instance.GetTranslation("hotkeyIsNotUnavailable"));
                    return;
                }
                var oldHotkey = updateCustomHotkey.Hotkey;
                updateCustomHotkey.ActionKeyword = tbAction.Text;
                updateCustomHotkey.Hotkey        = ctlHotkey.CurrentHotkey.ToString();
                //remove origin hotkey
                RemoveHotkey(oldHotkey);
                SetHotkey(new HotkeyModel(updateCustomHotkey.Hotkey), delegate
                {
                    App.API.ShowApp();
                    App.API.ChangeQuery(updateCustomHotkey.ActionKeyword);
                });
                MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
            }

            UserSettingStorage.Instance.Save();
            settingWidow.ReloadCustomPluginHotkeyView();
            Close();
        }
        private void btnAdd_OnClick(object sender, RoutedEventArgs e)
        {
            if (!update)
            {
                if (!ctlHotkey.CurrentHotkeyAvailable)
                {
                    MessageBox.Show("Hotkey is unavailable, please select a new hotkey");
                    return;
                }

                if (UserSettingStorage.Instance.CustomPluginHotkeys == null)
                {
                    UserSettingStorage.Instance.CustomPluginHotkeys = new List <CustomPluginHotkey>();
                }

                var pluginHotkey = new CustomPluginHotkey()
                {
                    Hotkey        = ctlHotkey.CurrentHotkey.ToString(),
                    ActionKeyword = tbAction.Text
                };
                UserSettingStorage.Instance.CustomPluginHotkeys.Add(pluginHotkey);
                settingWidow.MainWindow.SetHotkey(ctlHotkey.CurrentHotkey.ToString(), delegate
                {
                    settingWidow.MainWindow.ChangeQuery(pluginHotkey.ActionKeyword);
                    settingWidow.MainWindow.ShowApp();
                });
                MessageBox.Show("Add hotkey successfully!");
            }
            else
            {
                if (updateCustomHotkey.Hotkey != ctlHotkey.CurrentHotkey.ToString() && !ctlHotkey.CurrentHotkeyAvailable)
                {
                    MessageBox.Show("Hotkey is unavailable, please select a new hotkey");
                    return;
                }
                var oldHotkey = updateCustomHotkey.Hotkey;
                updateCustomHotkey.ActionKeyword = tbAction.Text;
                updateCustomHotkey.Hotkey        = ctlHotkey.CurrentHotkey.ToString();
                //remove origin hotkey
                settingWidow.MainWindow.RemoveHotkey(oldHotkey);
                settingWidow.MainWindow.SetHotkey(updateCustomHotkey.Hotkey, delegate
                {
                    settingWidow.MainWindow.ShowApp();
                    settingWidow.MainWindow.ChangeQuery(updateCustomHotkey.ActionKeyword);
                });
                MessageBox.Show("Update successfully!");
            }

            UserSettingStorage.Instance.Save();
            settingWidow.ReloadCustomPluginHotkeyView();
            Close();
        }