Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace original MessageBox with MessageBoxEx & Improve MessageBoxEx display style & Add new public api for using MessageBoxEx #3093

Merged
merged 20 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3ae960d
Replace System.Windows.Message with MessageBoxEx
Jack251970 Nov 24, 2024
6feca10
Improve MessageBoxEx paramters as System.Windows.MessageBox for reada…
Jack251970 Nov 24, 2024
ab087bd
Remove useless columns
Jack251970 Nov 24, 2024
fd78972
Improve OK MessageBoxEx display style
Jack251970 Nov 24, 2024
c103244
Merge branch 'dev4' of https://github.com/Jack251970/Flow.Launcher in…
Jack251970 Nov 24, 2024
b30cc4f
Replace System.Windows.MessageBox with MessageBoxEx
Jack251970 Nov 25, 2024
4bc9e86
Improve MessageBoxEx style as System.Windows.MessageBox
Jack251970 Nov 25, 2024
dcea54a
Fix parameter bug under release mode
Jack251970 Nov 26, 2024
897fd7a
Replace Flow.Launcher.Core.MessageBoxType & MessageBoxImage with Syst…
Jack251970 Nov 26, 2024
32c138b
Improve MessageBoxEx show function, making experience like System.Win…
Jack251970 Nov 26, 2024
7cb17ab
Improve title display experience & Fix three button dialog display is…
Jack251970 Nov 26, 2024
7ba8d58
Improve result handle & Improve exception support
Jack251970 Nov 27, 2024
9b75acd
Add ShowMsgBox functions in public api
Jack251970 Nov 27, 2024
534a111
Use public api to call ShowMsgBox functions & remove useless Core pro…
Jack251970 Nov 27, 2024
5d8f277
Use image loader to load image
Jack251970 Nov 27, 2024
5312505
Improve code quality
Jack251970 Nov 27, 2024
0d362b3
Add default messageboxShow parameter for functions in FilesFolders
Jack251970 Dec 1, 2024
b568d2d
Combine ShowMsgBox into one function.
Jack251970 Dec 1, 2024
57cbe10
Fix parameter bug
Jack251970 Dec 1, 2024
676a5b1
add defaults to MessageBoxEx Show & update WebSearch to use api call
jjw24 Dec 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions Flow.Launcher.Core/Configuration/Portable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -95,13 +96,13 @@ public void RemoveUninstallerEntry()

public void MoveUserDataFolder(string fromLocation, string toLocation)
{
FilesFolders.CopyAll(fromLocation, toLocation);
FilesFolders.CopyAll(fromLocation, toLocation, MessageBoxEx.Show);
VerifyUserDataAfterMove(fromLocation, toLocation);
}

public void VerifyUserDataAfterMove(string fromLocation, string toLocation)
{
FilesFolders.VerifyBothFolderFilesEqual(fromLocation, toLocation);
FilesFolders.VerifyBothFolderFilesEqual(fromLocation, toLocation, MessageBoxEx.Show);
}

public void CreateShortcuts()
Expand Down Expand Up @@ -157,13 +158,13 @@ public void PreStartCleanUpAfterPortabilityUpdate()
// delete it and prompt the user to pick the portable data location
if (File.Exists(roamingDataDeleteFilePath))
{
FilesFolders.RemoveFolderIfExists(roamingDataDir);
FilesFolders.RemoveFolderIfExists(roamingDataDir, MessageBoxEx.Show);

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);
FilesFolders.OpenPath(Constant.RootDirectory, MessageBoxEx.Show);

Environment.Exit(0);
}
Expand All @@ -172,9 +173,9 @@ public void PreStartCleanUpAfterPortabilityUpdate()
// delete it and notify the user about it.
else if (File.Exists(portableDataDeleteFilePath))
{
FilesFolders.RemoveFolderIfExists(portableDataDir);
FilesFolders.RemoveFolderIfExists(portableDataDir, MessageBoxEx.Show);

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");
}
}
Expand All @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Forms;
using Flow.Launcher.Core.Resource;
using static Flow.Launcher.Core.MessageBoxEx;

namespace Flow.Launcher.Core.ExternalPlugins.Environments
{
Expand Down Expand Up @@ -57,7 +59,7 @@ internal IEnumerable<PluginPair> Setup()
EnvName,
Environment.NewLine
);
if (MessageBox.Show(noRuntimeMessage, string.Empty, MessageBoxButtons.YesNo) == DialogResult.No)
if (MessageBoxEx.Show(noRuntimeMessage, string.Empty, MessageBoxType.YesNo) == MessageBoxResult.No)
{
var msg = string.Format(InternationalizationManager.Instance.GetTranslation("runtimePluginChooseRuntimeExecutable"), EnvName);
string selectedFile;
Expand All @@ -82,7 +84,7 @@ internal IEnumerable<PluginPair> Setup()
}
else
{
MessageBox.Show(string.Format(InternationalizationManager.Instance.GetTranslation("runtimePluginUnableToSetExecutablePath"), Language));
MessageBoxEx.Show(string.Format(InternationalizationManager.Instance.GetTranslation("runtimePluginUnableToSetExecutablePath"), Language));
Jack251970 marked this conversation as resolved.
Show resolved Hide resolved
Log.Error("PluginsLoader",
$"Not able to successfully set {EnvName} path, setting's plugin executable path variable is still an empty string.",
$"{Language}Environment");
Expand All @@ -98,7 +100,7 @@ private void EnsureLatestInstalled(string expectedPath, string currentPath, stri
if (expectedPath == currentPath)
return;

FilesFolders.RemoveFolderIfExists(installedDirPath);
FilesFolders.RemoveFolderIfExists(installedDirPath, MessageBoxEx.Show);

InstallEnvironment();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal PythonEnvironment(List<PluginMetadata> pluginMetadataList, PluginsSetti

internal override void InstallEnvironment()
{
FilesFolders.RemoveFolderIfExists(InstallPath);
FilesFolders.RemoveFolderIfExists(InstallPath, MessageBoxEx.Show);

// Python 3.11.4 is no longer Windows 7 compatible. If user is on Win 7 and
// uses Python plugin they need to custom install and use v3.8.9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal TypeScriptEnvironment(List<PluginMetadata> pluginMetadataList, PluginsS

internal override void InstallEnvironment()
{
FilesFolders.RemoveFolderIfExists(InstallPath);
FilesFolders.RemoveFolderIfExists(InstallPath, MessageBoxEx.Show);

DroplexPackage.Drop(App.nodejs_16_18_0, InstallPath).Wait();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal TypeScriptV2Environment(List<PluginMetadata> pluginMetadataList, Plugin

internal override void InstallEnvironment()
{
FilesFolders.RemoveFolderIfExists(InstallPath);
FilesFolders.RemoveFolderIfExists(InstallPath, MessageBoxEx.Show);
Jack251970 marked this conversation as resolved.
Show resolved Hide resolved

DroplexPackage.Drop(App.nodejs_16_18_0, InstallPath).Wait();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Window
x:Class="Flow.Launcher.MessageBoxEx"
x:Class="Flow.Launcher.Core.MessageBoxEx"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Flow.Launcher"
xmlns:local="clr-namespace:Flow.Launcher.Core"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="MessageBoxWindow"
Width="420"
Expand Down Expand Up @@ -33,14 +33,11 @@
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button
Grid.Column="4"
Grid.Column="1"
Click="Button_Cancel"
Style="{StaticResource TitleBarCloseButtonStyle}">
<Path
Expand All @@ -63,8 +60,12 @@
</Grid>
</StackPanel>
</StackPanel>
<StackPanel Grid.Row="1" Margin="30 0 30 24">
<Grid Grid.Column="0" Margin="0 0 0 12">
<Grid Grid.Row="1" Margin="30 0 30 24">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Margin="0 0 0 12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
Expand Down Expand Up @@ -94,14 +95,25 @@
</Grid>
<TextBlock
x:Name="DescTextBlock"
Grid.Column="1"
Grid.Row="1"
MaxWidth="400"
Margin="0 0 26 0"
HorizontalAlignment="Stretch"
FontSize="14"
TextAlignment="Left"
TextWrapping="Wrap" />
</StackPanel>
<TextBlock
x:Name="DescOnlyTextBlock"
Grid.Row="0"
Grid.RowSpan="2"
MaxWidth="400"
Margin="0 0 26 0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
FontSize="14"
TextAlignment="Left"
TextWrapping="Wrap" />
</Grid>
<Border
Grid.Row="2"
Margin="0 0 0 0"
Expand All @@ -113,29 +125,29 @@
VerticalAlignment="Center"
Orientation="Horizontal">
<Button
x:Name="btnCancel"
x:Name="btnOk"
MinWidth="140"
Margin="5 0 5 0"
Click="Button_Click"
Content="{DynamicResource commonCancel}" />
Content="{DynamicResource commonOK}" />
<Button
x:Name="btnNo"
x:Name="btnYes"
MinWidth="140"
Margin="5 0 5 0"
Click="Button_Click"
Content="{DynamicResource commonNo}" />
Content="{DynamicResource commonYes}" />
<Button
x:Name="btnOk"
x:Name="btnNo"
MinWidth="140"
Margin="5 0 5 0"
Click="Button_Click"
Content="{DynamicResource commonOK}" />
Content="{DynamicResource commonNo}" />
<Button
x:Name="btnYes"
x:Name="btnCancel"
MinWidth="140"
Margin="5 0 5 0"
Click="Button_Click"
Content="{DynamicResource commonYes}" />
Content="{DynamicResource commonCancel}" />
</WrapPanel>
</Border>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Flow.Launcher.Core.Resource;
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.Image;
using YamlDotNet.Core.Tokens;

namespace Flow.Launcher
namespace Flow.Launcher.Core
{
public partial class MessageBoxEx : Window
{
Expand Down Expand Up @@ -50,54 +37,62 @@ 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(messageBoxText, string.Empty, 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;
}
}

// 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();
Jack251970 marked this conversation as resolved.
Show resolved Hide resolved
msgBox.TitleTextBlock.Text = text;
msgBox.DescTextBlock.Text = caption;
msgBox.Title = text;
if (title == string.Empty && button == MessageBoxButton.OK && image == MessageBoxImage.None)
{
msgBox.DescOnlyTextBlock.Text = messageBoxText;
msgBox.Title = messageBoxText;
}
else
{
msgBox.TitleTextBlock.Text = title;
msgBox.DescTextBlock.Text = messageBoxText;
msgBox.Title = title;
SetImageOfMessageBox(image);
}
SetVisibilityOfButtons(button);
SetImageOfMessageBox(image);
msgBox.ShowDialog();
return _result;
}
Expand Down Expand Up @@ -130,16 +125,16 @@ private static void SetVisibilityOfButtons(MessageBoxButton button)
case MessageBoxButton.OKCancel:
msgBox.btnNo.Visibility = Visibility.Collapsed;
msgBox.btnYes.Visibility = Visibility.Collapsed;
msgBox.btnCancel.Focus();
msgBox.btnOk.Focus();
break;
case MessageBoxButton.YesNo:
msgBox.btnOk.Visibility = Visibility.Collapsed;
msgBox.btnCancel.Visibility = Visibility.Collapsed;
msgBox.btnNo.Focus();
msgBox.btnYes.Focus();
break;
case MessageBoxButton.YesNoCancel:
msgBox.btnOk.Visibility = Visibility.Collapsed;
msgBox.btnCancel.Focus();
msgBox.btnYes.Focus();
break;
default:
break;
Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool c

var newPluginPath = Path.Combine(installDirectory, folderName);

FilesFolders.CopyAll(pluginFolderPath, newPluginPath);
FilesFolders.CopyAll(pluginFolderPath, newPluginPath, MessageBoxEx.Show);

Directory.Delete(tempFolderPluginPath, true);

Expand Down
Loading
Loading