From 3ae960d275e82c88f5aabe57ad9405f028e8ceb4 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 24 Nov 2024 16:11:53 +0800 Subject: [PATCH 01/19] Replace System.Windows.Message with MessageBoxEx --- Flow.Launcher.Core/Configuration/Portable.cs | 13 +++++++------ .../MessageBoxEx.xaml | 4 ++-- .../MessageBoxEx.xaml.cs | 15 +-------------- .../Resource/Internationalization.cs | 3 ++- Flow.Launcher.Core/Resource/Theme.cs | 4 ++-- Flow.Launcher.Core/Updater.cs | 7 ++++--- Flow.Launcher/ActionKeywords.xaml.cs | 3 ++- Flow.Launcher/CustomQueryHotkeySetting.xaml.cs | 4 ++-- Flow.Launcher/CustomShortcutSetting.xaml.cs | 5 +++-- Flow.Launcher/Helper/HotKeyMapper.cs | 4 ++-- Flow.Launcher/PriorityChangeWindow.xaml.cs | 5 +++-- .../ViewModels/SettingsPaneAboutViewModel.cs | 2 +- .../ViewModels/SettingsPaneHotkeyViewModel.cs | 18 ++++++++++-------- .../ViewModels/SettingsPaneProxyViewModel.cs | 3 +-- .../ViewModels/SettingsPaneThemeViewModel.cs | 4 ++-- 15 files changed, 44 insertions(+), 50 deletions(-) rename {Flow.Launcher => Flow.Launcher.Core}/MessageBoxEx.xaml (98%) rename {Flow.Launcher => Flow.Launcher.Core}/MessageBoxEx.xaml.cs (93%) diff --git a/Flow.Launcher.Core/Configuration/Portable.cs b/Flow.Launcher.Core/Configuration/Portable.cs index b58154dcb23..544cf25094e 100644 --- a/Flow.Launcher.Core/Configuration/Portable.cs +++ b/Flow.Launcher.Core/Configuration/Portable.cs @@ -9,6 +9,7 @@ using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin.SharedCommands; using System.Linq; +using static Flow.Launcher.Core.MessageBoxEx; namespace Flow.Launcher.Core.Configuration { @@ -40,7 +41,7 @@ public void DisablePortableMode() #endif IndicateDeletion(DataLocation.PortableDataPath); - MessageBox.Show("Flow Launcher needs to restart to finish disabling portable mode, " + + MessageBoxEx.Show("Flow Launcher needs to restart to finish disabling portable mode, " + "after the restart your portable data profile will be deleted and roaming data profile kept"); UpdateManager.RestartApp(Constant.ApplicationFileName); @@ -64,7 +65,7 @@ public void EnablePortableMode() #endif IndicateDeletion(DataLocation.RoamingDataPath); - MessageBox.Show("Flow Launcher needs to restart to finish enabling portable mode, " + + MessageBoxEx.Show("Flow Launcher needs to restart to finish enabling portable mode, " + "after the restart your roaming data profile will be deleted and portable data profile kept"); UpdateManager.RestartApp(Constant.ApplicationFileName); @@ -159,9 +160,9 @@ public void PreStartCleanUpAfterPortabilityUpdate() { FilesFolders.RemoveFolderIfExists(roamingDataDir); - if (MessageBox.Show("Flow Launcher has detected you enabled portable mode, " + + if (MessageBoxEx.Show("Flow Launcher has detected you enabled portable mode, " + "would you like to move it to a different location?", string.Empty, - MessageBoxButton.YesNo) == MessageBoxResult.Yes) + MessageBoxType.YesNo) == MessageBoxResult.Yes) { FilesFolders.OpenPath(Constant.RootDirectory); @@ -174,7 +175,7 @@ public void PreStartCleanUpAfterPortabilityUpdate() { FilesFolders.RemoveFolderIfExists(portableDataDir); - MessageBox.Show("Flow Launcher has detected you disabled portable mode, " + + MessageBoxEx.Show("Flow Launcher has detected you disabled portable mode, " + "the relevant shortcuts and uninstaller entry have been created"); } } @@ -186,7 +187,7 @@ public bool CanUpdatePortability() if (roamingLocationExists && portableLocationExists) { - MessageBox.Show(string.Format("Flow Launcher detected your user data exists both in {0} and " + + MessageBoxEx.Show(string.Format("Flow Launcher detected your user data exists both in {0} and " + "{1}. {2}{2}Please delete {1} in order to proceed. No changes have occurred.", DataLocation.PortableDataPath, DataLocation.RoamingDataPath, Environment.NewLine)); diff --git a/Flow.Launcher/MessageBoxEx.xaml b/Flow.Launcher.Core/MessageBoxEx.xaml similarity index 98% rename from Flow.Launcher/MessageBoxEx.xaml rename to Flow.Launcher.Core/MessageBoxEx.xaml index f466a640e28..ca543271bc8 100644 --- a/Flow.Launcher/MessageBoxEx.xaml +++ b/Flow.Launcher.Core/MessageBoxEx.xaml @@ -1,9 +1,9 @@  path can't be found"); if (theme != defaultTheme) { - MessageBox.Show(string.Format(InternationalizationManager.Instance.GetTranslation("theme_load_failure_path_not_exists"), theme)); + MessageBoxEx.Show(string.Format(InternationalizationManager.Instance.GetTranslation("theme_load_failure_path_not_exists"), theme)); ChangeTheme(defaultTheme); } return false; @@ -120,7 +120,7 @@ public bool ChangeTheme(string theme) Log.Error($"|Theme.ChangeTheme|Theme <{theme}> fail to parse"); if (theme != defaultTheme) { - MessageBox.Show(string.Format(InternationalizationManager.Instance.GetTranslation("theme_load_failure_parse_error"), theme)); + MessageBoxEx.Show(string.Format(InternationalizationManager.Instance.GetTranslation("theme_load_failure_parse_error"), theme)); ChangeTheme(defaultTheme); } return false; diff --git a/Flow.Launcher.Core/Updater.cs b/Flow.Launcher.Core/Updater.cs index 3f64b273e4c..34545c771da 100644 --- a/Flow.Launcher.Core/Updater.cs +++ b/Flow.Launcher.Core/Updater.cs @@ -17,6 +17,7 @@ using Flow.Launcher.Plugin; using System.Text.Json.Serialization; using System.Threading; +using static Flow.Launcher.Core.MessageBoxEx; namespace Flow.Launcher.Core { @@ -53,7 +54,7 @@ public async Task UpdateAppAsync(IPublicAPI api, bool silentUpdate = true) if (newReleaseVersion <= currentVersion) { if (!silentUpdate) - MessageBox.Show(api.GetTranslation("update_flowlauncher_already_on_latest")); + MessageBoxEx.Show(api.GetTranslation("update_flowlauncher_already_on_latest")); return; } @@ -70,7 +71,7 @@ public async Task UpdateAppAsync(IPublicAPI api, bool silentUpdate = true) var targetDestination = updateManager.RootAppDirectory + $"\\app-{newReleaseVersion.ToString()}\\{DataLocation.PortableFolderName}"; FilesFolders.CopyAll(DataLocation.PortableDataPath, targetDestination); if (!FilesFolders.VerifyBothFolderFilesEqual(DataLocation.PortableDataPath, targetDestination)) - MessageBox.Show(string.Format(api.GetTranslation("update_flowlauncher_fail_moving_portable_user_profile_data"), + MessageBoxEx.Show(string.Format(api.GetTranslation("update_flowlauncher_fail_moving_portable_user_profile_data"), DataLocation.PortableDataPath, targetDestination)); } @@ -83,7 +84,7 @@ public async Task UpdateAppAsync(IPublicAPI api, bool silentUpdate = true) Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}"); - if (MessageBox.Show(newVersionTips, api.GetTranslation("update_flowlauncher_new_update"), MessageBoxButton.YesNo) == MessageBoxResult.Yes) + if (MessageBoxEx.Show(newVersionTips, api.GetTranslation("update_flowlauncher_new_update"), MessageBoxType.YesNo) == MessageBoxResult.Yes) { UpdateManager.RestartApp(Constant.ApplicationFileName); } diff --git a/Flow.Launcher/ActionKeywords.xaml.cs b/Flow.Launcher/ActionKeywords.xaml.cs index 371b2dd07c9..ba47a4ded22 100644 --- a/Flow.Launcher/ActionKeywords.xaml.cs +++ b/Flow.Launcher/ActionKeywords.xaml.cs @@ -2,6 +2,7 @@ using Flow.Launcher.Core.Resource; using Flow.Launcher.Plugin; using Flow.Launcher.ViewModel; +using Flow.Launcher.Core; namespace Flow.Launcher { @@ -43,7 +44,7 @@ private void btnDone_OnClick(object sender, RoutedEventArgs _) else { string msg = translater.GetTranslation("newActionKeywordsHasBeenAssigned"); - MessageBox.Show(msg); + MessageBoxEx.Show(msg); } } } diff --git a/Flow.Launcher/CustomQueryHotkeySetting.xaml.cs b/Flow.Launcher/CustomQueryHotkeySetting.xaml.cs index 5db6115ade1..81e7600b8fa 100644 --- a/Flow.Launcher/CustomQueryHotkeySetting.xaml.cs +++ b/Flow.Launcher/CustomQueryHotkeySetting.xaml.cs @@ -6,7 +6,7 @@ using System.Windows; using System.Windows.Input; using System.Windows.Controls; -using Flow.Launcher.ViewModel; +using Flow.Launcher.Core; namespace Flow.Launcher { @@ -63,7 +63,7 @@ public void UpdateItem(CustomPluginHotkey item) o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey); if (updateCustomHotkey == null) { - MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidPluginHotkey")); + MessageBoxEx.Show(InternationalizationManager.Instance.GetTranslation("invalidPluginHotkey")); Close(); return; } diff --git a/Flow.Launcher/CustomShortcutSetting.xaml.cs b/Flow.Launcher/CustomShortcutSetting.xaml.cs index 531b29d50b6..dec3506eb35 100644 --- a/Flow.Launcher/CustomShortcutSetting.xaml.cs +++ b/Flow.Launcher/CustomShortcutSetting.xaml.cs @@ -3,6 +3,7 @@ using System.Windows; using System.Windows.Input; using Flow.Launcher.SettingPages.ViewModels; +using Flow.Launcher.Core; namespace Flow.Launcher { @@ -42,13 +43,13 @@ private void BtnAdd_OnClick(object sender, RoutedEventArgs e) { if (String.IsNullOrEmpty(Key) || String.IsNullOrEmpty(Value)) { - MessageBox.Show(InternationalizationManager.Instance.GetTranslation("emptyShortcut")); + MessageBoxEx.Show(InternationalizationManager.Instance.GetTranslation("emptyShortcut")); return; } // Check if key is modified or adding a new one if (((update && originalKey != Key) || !update) && _hotkeyVm.DoesShortcutExist(Key)) { - MessageBox.Show(InternationalizationManager.Instance.GetTranslation("duplicateShortcut")); + MessageBoxEx.Show(InternationalizationManager.Instance.GetTranslation("duplicateShortcut")); return; } DialogResult = !update || originalKey != Key || originalValue != Value; diff --git a/Flow.Launcher/Helper/HotKeyMapper.cs b/Flow.Launcher/Helper/HotKeyMapper.cs index 21ddf276ad3..8b30b8be1f5 100644 --- a/Flow.Launcher/Helper/HotKeyMapper.cs +++ b/Flow.Launcher/Helper/HotKeyMapper.cs @@ -4,8 +4,8 @@ using NHotkey; using NHotkey.Wpf; using Flow.Launcher.Core.Resource; -using System.Windows; using Flow.Launcher.ViewModel; +using Flow.Launcher.Core; namespace Flow.Launcher.Helper; @@ -46,7 +46,7 @@ internal static void SetHotkey(HotkeyModel hotkey, EventHandler { string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr); string errorMsgTitle = InternationalizationManager.Instance.GetTranslation("MessageBoxTitle"); - MessageBox.Show(errorMsg,errorMsgTitle); + MessageBoxEx.Show(errorMsg, errorMsgTitle); } } diff --git a/Flow.Launcher/PriorityChangeWindow.xaml.cs b/Flow.Launcher/PriorityChangeWindow.xaml.cs index 2d0966de4d2..2154b058d1c 100644 --- a/Flow.Launcher/PriorityChangeWindow.xaml.cs +++ b/Flow.Launcher/PriorityChangeWindow.xaml.cs @@ -5,6 +5,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using Flow.Launcher.Core; namespace Flow.Launcher { @@ -23,7 +24,7 @@ public PriorityChangeWindow(string pluginId, PluginViewModel pluginViewModel) this.pluginViewModel = pluginViewModel; if (plugin == null) { - MessageBox.Show(translater.GetTranslation("cannotFindSpecifiedPlugin")); + MessageBoxEx.Show(translater.GetTranslation("cannotFindSpecifiedPlugin")); Close(); } } @@ -43,7 +44,7 @@ private void btnDone_OnClick(object sender, RoutedEventArgs e) else { string msg = translater.GetTranslation("invalidPriority"); - MessageBox.Show(msg); + MessageBoxEx.Show(msg); } } diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs index c314b42ee68..6e6cbce4d7b 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs @@ -11,7 +11,7 @@ using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; -using static Flow.Launcher.MessageBoxEx; +using static Flow.Launcher.Core.MessageBoxEx; namespace Flow.Launcher.SettingPages.ViewModels; diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs index a4488a0377a..669cd078433 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs @@ -7,6 +7,8 @@ using Flow.Launcher.Infrastructure.Hotkey; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; +using Flow.Launcher.Core; +using static Flow.Launcher.Core.MessageBoxEx; namespace Flow.Launcher.SettingPages.ViewModels; @@ -41,16 +43,16 @@ private void CustomHotkeyDelete() var item = SelectedCustomPluginHotkey; if (item is null) { - MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem")); + MessageBoxEx.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem")); return; } - var result = MessageBox.Show( + var result = MessageBoxEx.Show( string.Format( InternationalizationManager.Instance.GetTranslation("deleteCustomHotkeyWarning"), item.Hotkey ), InternationalizationManager.Instance.GetTranslation("delete"), - MessageBoxButton.YesNo + MessageBoxType.YesNo ); if (result is MessageBoxResult.Yes) @@ -66,7 +68,7 @@ private void CustomHotkeyEdit() var item = SelectedCustomPluginHotkey; if (item is null) { - MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem")); + MessageBoxEx.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem")); return; } @@ -87,16 +89,16 @@ private void CustomShortcutDelete() var item = SelectedCustomShortcut; if (item is null) { - MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem")); + MessageBoxEx.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem")); return; } - var result = MessageBox.Show( + var result = MessageBoxEx.Show( string.Format( InternationalizationManager.Instance.GetTranslation("deleteCustomShortcutWarning"), item.Key, item.Value ), InternationalizationManager.Instance.GetTranslation("delete"), - MessageBoxButton.YesNo + MessageBoxType.YesNo ); if (result is MessageBoxResult.Yes) @@ -111,7 +113,7 @@ private void CustomShortcutEdit() var item = SelectedCustomShortcut; if (item is null) { - MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem")); + MessageBoxEx.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem")); return; } diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneProxyViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneProxyViewModel.cs index 2dd57809db2..1c840fb2703 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneProxyViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneProxyViewModel.cs @@ -1,5 +1,4 @@ using System.Net; -using System.Windows; using CommunityToolkit.Mvvm.Input; using Flow.Launcher.Core; using Flow.Launcher.Core.Resource; @@ -23,7 +22,7 @@ public SettingsPaneProxyViewModel(Settings settings, Updater updater) private void OnTestProxyClicked() { var message = TestProxy(); - MessageBox.Show(InternationalizationManager.Instance.GetTranslation(message)); + MessageBoxEx.Show(InternationalizationManager.Instance.GetTranslation(message)); } private string TestProxy() diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index f2e52dbaed9..8a835ba7cbb 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Windows; -using System.Windows.Controls; using System.Globalization; using System.IO; using System.Linq; @@ -15,6 +14,7 @@ using Flow.Launcher.Plugin; using Flow.Launcher.ViewModel; using ModernWpf; +using Flow.Launcher.Core; using ThemeManager = Flow.Launcher.Core.Resource.ThemeManager; using ThemeManagerForColorSchemeSwitch = ModernWpf.ThemeManager; @@ -49,7 +49,7 @@ public bool DropShadowEffect { if (ThemeManager.Instance.BlurEnabled && value) { - MessageBox.Show(InternationalizationManager.Instance.GetTranslation("shadowEffectNotAllowed")); + MessageBoxEx.Show(InternationalizationManager.Instance.GetTranslation("shadowEffectNotAllowed")); return; } From 6feca10bdbc3dbce3f4b8cc48fe9f3aebe23b3ad Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 24 Nov 2024 16:30:35 +0800 Subject: [PATCH 02/19] Improve MessageBoxEx paramters as System.Windows.MessageBox for readability --- Flow.Launcher.Core/MessageBoxEx.xaml.cs | 30 ++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Flow.Launcher.Core/MessageBoxEx.xaml.cs b/Flow.Launcher.Core/MessageBoxEx.xaml.cs index 18b1ae07f9c..3e04657dc45 100644 --- a/Flow.Launcher.Core/MessageBoxEx.xaml.cs +++ b/Flow.Launcher.Core/MessageBoxEx.xaml.cs @@ -37,39 +37,39 @@ public enum MessageBoxImage /// 1 parameter - public static MessageBoxResult Show(string msg) + public static MessageBoxResult Show(string messageBoxText) { - return Show(string.Empty, msg, MessageBoxButton.OK, MessageBoxImage.None); + return Show(string.Empty, messageBoxText, MessageBoxButton.OK, MessageBoxImage.None); } // 2 parameter - public static MessageBoxResult Show(string caption, string text) + public static MessageBoxResult Show(string messageBoxText, string title) { - return Show(caption, text, MessageBoxButton.OK, MessageBoxImage.None); + return Show(messageBoxText, title, MessageBoxButton.OK, MessageBoxImage.None); } /// 3 parameter - public static MessageBoxResult Show(string caption, string msg, MessageBoxType type) + public static MessageBoxResult Show(string messageBoxText, string title, MessageBoxType type) { switch (type) { case MessageBoxType.ConfirmationWithYesNo: - return Show(caption, msg, MessageBoxButton.YesNo, + return Show(messageBoxText, title, MessageBoxButton.YesNo, MessageBoxImage.Question); case MessageBoxType.YesNo: - return Show(caption, msg, MessageBoxButton.YesNo, + return Show(messageBoxText, title, MessageBoxButton.YesNo, MessageBoxImage.Question); case MessageBoxType.ConfirmationWithYesNoCancel: - return Show(caption, msg, MessageBoxButton.YesNoCancel, + return Show(messageBoxText, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question); case MessageBoxType.Information: - return Show(caption, msg, MessageBoxButton.OK, + return Show(messageBoxText, title, MessageBoxButton.OK, MessageBoxImage.Information); case MessageBoxType.Error: - return Show(caption, msg, MessageBoxButton.OK, + return Show(messageBoxText, title, MessageBoxButton.OK, MessageBoxImage.Error); case MessageBoxType.Warning: - return Show(caption, msg, MessageBoxButton.OK, + return Show(messageBoxText, title, MessageBoxButton.OK, MessageBoxImage.Warning); default: return MessageBoxResult.No; @@ -77,12 +77,12 @@ public static MessageBoxResult Show(string caption, string msg, MessageBoxType t } // 4 parameter, Final Display Message. - public static MessageBoxResult Show(string caption, string text, MessageBoxButton button, MessageBoxImage image) + public static MessageBoxResult Show(string messageBoxText, string title, MessageBoxButton button, MessageBoxImage image) { msgBox = new MessageBoxEx(); - msgBox.TitleTextBlock.Text = text; - msgBox.DescTextBlock.Text = caption; - msgBox.Title = text; + msgBox.TitleTextBlock.Text = title; + msgBox.DescTextBlock.Text = messageBoxText; + msgBox.Title = title; SetVisibilityOfButtons(button); SetImageOfMessageBox(image); msgBox.ShowDialog(); From ab087bd927c8e4c75db90115151ce1b11cefe6c7 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 24 Nov 2024 22:08:50 +0800 Subject: [PATCH 03/19] Remove useless columns --- Flow.Launcher.Core/MessageBoxEx.xaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Flow.Launcher.Core/MessageBoxEx.xaml b/Flow.Launcher.Core/MessageBoxEx.xaml index ca543271bc8..2788a76489a 100644 --- a/Flow.Launcher.Core/MessageBoxEx.xaml +++ b/Flow.Launcher.Core/MessageBoxEx.xaml @@ -33,14 +33,11 @@ - - -