diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index 50e034f33..84fc9076f 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -391,49 +391,20 @@ namespace Flow.Launcher private void OnDeleteCustomShortCutClick(object sender, RoutedEventArgs e) { - var item = viewModel.SelectedCustomShortcut; - if (item == null) - { - MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem")); - return; - } - - string deleteWarning = - string.Format(InternationalizationManager.Instance.GetTranslation("deleteCustomShortcutWarning"), - item?.Key, item?.Value); - if ( - MessageBox.Show(deleteWarning, InternationalizationManager.Instance.GetTranslation("delete"), - MessageBoxButton.YesNo) == MessageBoxResult.Yes) - { - settings.CustomShortcuts.Remove(item); - } + viewModel.DeleteSelectedCustomShortcut(); } private void OnEditCustomShortCutClick(object sender, RoutedEventArgs e) { - var item = viewModel.SelectedCustomShortcut; - if (item == null) + if (viewModel.EditSelectedCustomShortcut()) { - MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem")); - return; - } - - var shortcutSettingWindow = new CustomShortcutSetting(item, settings); - if (shortcutSettingWindow.ShowDialog() == true) - { - item.Key = shortcutSettingWindow.Key; - item.Value = shortcutSettingWindow.Value; customShortcutView.Items.Refresh(); } } private void OnAddCustomShortCutClick(object sender, RoutedEventArgs e) { - var shortcutSettingWindow = new CustomShortcutSetting(settings); - if (shortcutSettingWindow.ShowDialog() == true) - { - settings.CustomShortcuts.Add(shortcutSettingWindow.ShortCut); - } + viewModel.AddCustomShortcut(); } #endregion diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index 389af9a45..2703aa70d 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -689,6 +689,58 @@ namespace Flow.Launcher.ViewModel #endregion + #region shortcut + + public void DeleteSelectedCustomShortcut() + { + var item = SelectedCustomShortcut; + if (item == null) + { + MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem")); + return; + } + + string deleteWarning = + string.Format(InternationalizationManager.Instance.GetTranslation("deleteCustomShortcutWarning"), + item?.Key, item?.Value); + if ( + MessageBox.Show(deleteWarning, InternationalizationManager.Instance.GetTranslation("delete"), + MessageBoxButton.YesNo) == MessageBoxResult.Yes) + { + Settings.CustomShortcuts.Remove(item); + } + } + + public bool EditSelectedCustomShortcut() + { + var item = SelectedCustomShortcut; + if (item == null) + { + MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem")); + return false; + } + + var shortcutSettingWindow = new CustomShortcutSetting(item, Settings); + if (shortcutSettingWindow.ShowDialog() == true) + { + item.Key = shortcutSettingWindow.Key; + item.Value = shortcutSettingWindow.Value; + return true; + } + return false; + } + + public void AddCustomShortcut() + { + var shortcutSettingWindow = new CustomShortcutSetting(Settings); + if (shortcutSettingWindow.ShowDialog() == true) + { + Settings.CustomShortcuts.Add(shortcutSettingWindow.ShortCut); + } + } + + #endregion + #region about public string Website => Constant.Website;