Move logic to viewmodel

This commit is contained in:
Vic 2022-11-06 13:20:30 +08:00
parent 7fe81b4438
commit 977ec33283
2 changed files with 55 additions and 32 deletions

View file

@ -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

View file

@ -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;