Skip to content

Commit 977ec33

Browse files
Move logic to viewmodel
1 parent 7fe81b4 commit 977ec33

File tree

2 files changed

+55
-32
lines changed

2 files changed

+55
-32
lines changed

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -391,49 +391,20 @@ private void Window_StateChanged(object sender, EventArgs e)
391391

392392
private void OnDeleteCustomShortCutClick(object sender, RoutedEventArgs e)
393393
{
394-
var item = viewModel.SelectedCustomShortcut;
395-
if (item == null)
396-
{
397-
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
398-
return;
399-
}
400-
401-
string deleteWarning =
402-
string.Format(InternationalizationManager.Instance.GetTranslation("deleteCustomShortcutWarning"),
403-
item?.Key, item?.Value);
404-
if (
405-
MessageBox.Show(deleteWarning, InternationalizationManager.Instance.GetTranslation("delete"),
406-
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
407-
{
408-
settings.CustomShortcuts.Remove(item);
409-
}
394+
viewModel.DeleteSelectedCustomShortcut();
410395
}
411396

412397
private void OnEditCustomShortCutClick(object sender, RoutedEventArgs e)
413398
{
414-
var item = viewModel.SelectedCustomShortcut;
415-
if (item == null)
416-
{
417-
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
418-
return;
419-
}
420-
421-
var shortcutSettingWindow = new CustomShortcutSetting(item, settings);
422-
if (shortcutSettingWindow.ShowDialog() == true)
399+
if (viewModel.EditSelectedCustomShortcut())
423400
{
424-
item.Key = shortcutSettingWindow.Key;
425-
item.Value = shortcutSettingWindow.Value;
426401
customShortcutView.Items.Refresh();
427402
}
428403
}
429404

430405
private void OnAddCustomShortCutClick(object sender, RoutedEventArgs e)
431406
{
432-
var shortcutSettingWindow = new CustomShortcutSetting(settings);
433-
if (shortcutSettingWindow.ShowDialog() == true)
434-
{
435-
settings.CustomShortcuts.Add(shortcutSettingWindow.ShortCut);
436-
}
407+
viewModel.AddCustomShortcut();
437408
}
438409

439410
#endregion

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,58 @@ public FamilyTypeface SelectedResultFontFaces
689689

690690
#endregion
691691

692+
#region shortcut
693+
694+
public void DeleteSelectedCustomShortcut()
695+
{
696+
var item = SelectedCustomShortcut;
697+
if (item == null)
698+
{
699+
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
700+
return;
701+
}
702+
703+
string deleteWarning =
704+
string.Format(InternationalizationManager.Instance.GetTranslation("deleteCustomShortcutWarning"),
705+
item?.Key, item?.Value);
706+
if (
707+
MessageBox.Show(deleteWarning, InternationalizationManager.Instance.GetTranslation("delete"),
708+
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
709+
{
710+
Settings.CustomShortcuts.Remove(item);
711+
}
712+
}
713+
714+
public bool EditSelectedCustomShortcut()
715+
{
716+
var item = SelectedCustomShortcut;
717+
if (item == null)
718+
{
719+
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
720+
return false;
721+
}
722+
723+
var shortcutSettingWindow = new CustomShortcutSetting(item, Settings);
724+
if (shortcutSettingWindow.ShowDialog() == true)
725+
{
726+
item.Key = shortcutSettingWindow.Key;
727+
item.Value = shortcutSettingWindow.Value;
728+
return true;
729+
}
730+
return false;
731+
}
732+
733+
public void AddCustomShortcut()
734+
{
735+
var shortcutSettingWindow = new CustomShortcutSetting(Settings);
736+
if (shortcutSettingWindow.ShowDialog() == true)
737+
{
738+
Settings.CustomShortcuts.Add(shortcutSettingWindow.ShortCut);
739+
}
740+
}
741+
742+
#endregion
743+
692744
#region about
693745

694746
public string Website => Constant.Website;

0 commit comments

Comments
 (0)