From cca10ca5a015c6d7aebd747474a99a518230e3e7 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Tue, 6 Dec 2022 22:54:12 +0800 Subject: [PATCH] Move show msgbox to view --- .../AddProgramSource.xaml.cs | 14 +++++------ .../ViewModels/AddProgramSourceViewModel.cs | 23 ++++++++----------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs index ae6c5197e..c41e9f688 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs @@ -30,15 +30,15 @@ namespace Flow.Launcher.Plugin.Program private void BtnAdd_OnClick(object sender, RoutedEventArgs e) { var status = ViewModel.AddOrUpdate(); - if (status == null) + bool modified = status.Item1; + string msg = status.Item2; + if (modified == false && msg != null) { - return; // Invalid - } - else - { - DialogResult = status ?? false; - Close(); + MessageBox.Show(msg); // Invalid + return; } + DialogResult = modified; + Close(); } } } diff --git a/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs b/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs index 92981b1fd..c47525fde 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs @@ -80,42 +80,37 @@ namespace Flow.Launcher.Plugin.Program.ViewModels } } - public bool? AddProgramSource() + public (bool, string) AddProgramSource() { if (!Directory.Exists(Location)) { - System.Windows.MessageBox.Show(API.GetTranslation("flowlauncher_plugin_program_invalid_path")); - return null; + return (false, API.GetTranslation("flowlauncher_plugin_program_invalid_path")); } else if (DuplicateSource(Location)) { - System.Windows.MessageBox.Show(API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source")); - return null; + return (false, API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source")); } else { var source = new ProgramSource(Location, Enabled); Settings.ProgramSources.Insert(0, source); ProgramSetting.ProgramSettingDisplayList.Add(source); - return true; + return (true, null); } } - public bool? UpdateProgramSource() + public (bool, string) UpdateProgramSource() { // Separate checks to avoid changing UniqueIdentifier of UWP when changing Enabled if (LocationModified) { if (!Directory.Exists(Location)) { - System.Windows.MessageBox.Show(API.GetTranslation("flowlauncher_plugin_program_invalid_path")); - return null; + return (false, API.GetTranslation("flowlauncher_plugin_program_invalid_path")); } else if (DuplicateSource(Location)) { - // No need to check win32 or uwp, just override them - System.Windows.MessageBox.Show(API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source")); - return null; + return (false, API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source")); } else { @@ -126,10 +121,10 @@ namespace Flow.Launcher.Plugin.Program.ViewModels { Source.Enabled = Enabled; } - return StatusModified || LocationModified; + return (StatusModified || LocationModified, null); } - public bool? AddOrUpdate() + public (bool, string) AddOrUpdate() { if (Source == null) {