Skip to content

Commit 67f4f94

Browse files
authored
Merge branch 'dev' into explorer-plugin-add-context-menu-hotkey
2 parents 2519422 + 188068d commit 67f4f94

File tree

8 files changed

+340
-2
lines changed

8 files changed

+340
-2
lines changed

Flow.Launcher/Images/Error.png

4.91 KB
Loading

Flow.Launcher/Images/Exclamation.png

3.3 KB
Loading

Flow.Launcher/Images/Information.png

4.68 KB
Loading

Flow.Launcher/Images/Question.png

5.07 KB
Loading

Flow.Launcher/Languages/en.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@
349349
<system:String x:Key="commonCancel">Cancel</system:String>
350350
<system:String x:Key="commonReset">Reset</system:String>
351351
<system:String x:Key="commonDelete">Delete</system:String>
352+
<system:String x:Key="commonOK">OK</system:String>
353+
<system:String x:Key="commonYes">Yes</system:String>
354+
<system:String x:Key="commonNo">No</system:String>
352355

353356
<!-- Crash Reporter -->
354357
<system:String x:Key="reportWindow_version">Version</system:String>

Flow.Launcher/MessageBoxEx.xaml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<Window
2+
x:Class="Flow.Launcher.MessageBoxEx"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:Flow.Launcher"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
x:Name="MessageBoxWindow"
9+
Width="420"
10+
Height="Auto"
11+
Background="{DynamicResource PopuBGColor}"
12+
Foreground="{DynamicResource PopupTextColor}"
13+
ResizeMode="NoResize"
14+
SizeToContent="Height"
15+
WindowStartupLocation="CenterScreen"
16+
mc:Ignorable="d">
17+
<WindowChrome.WindowChrome>
18+
<WindowChrome CaptionHeight="32" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
19+
</WindowChrome.WindowChrome>
20+
<Window.InputBindings>
21+
<KeyBinding Key="Escape" Command="Close" />
22+
</Window.InputBindings>
23+
<Window.CommandBindings>
24+
<CommandBinding Command="Close" Executed="cmdEsc_OnPress" />
25+
</Window.CommandBindings>
26+
<Grid>
27+
<Grid.RowDefinitions>
28+
<RowDefinition Height="Auto" />
29+
<RowDefinition />
30+
<RowDefinition MinHeight="68" />
31+
</Grid.RowDefinitions>
32+
<StackPanel Grid.Row="0">
33+
<StackPanel>
34+
<Grid>
35+
<Grid.ColumnDefinitions>
36+
<ColumnDefinition Width="Auto" />
37+
<ColumnDefinition Width="*" />
38+
<ColumnDefinition Width="Auto" />
39+
<ColumnDefinition Width="Auto" />
40+
<ColumnDefinition Width="Auto" />
41+
</Grid.ColumnDefinitions>
42+
<Button
43+
Grid.Column="4"
44+
Click="Button_Cancel"
45+
Style="{StaticResource TitleBarCloseButtonStyle}">
46+
<Path
47+
Width="46"
48+
Height="32"
49+
Data="M 18,11 27,20 M 18,20 27,11"
50+
Stroke="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}"
51+
StrokeThickness="1">
52+
<Path.Style>
53+
<Style TargetType="Path">
54+
<Style.Triggers>
55+
<DataTrigger Binding="{Binding Path=IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Value="False">
56+
<Setter Property="Opacity" Value="0.5" />
57+
</DataTrigger>
58+
</Style.Triggers>
59+
</Style>
60+
</Path.Style>
61+
</Path>
62+
</Button>
63+
</Grid>
64+
</StackPanel>
65+
</StackPanel>
66+
<StackPanel Grid.Row="1" Margin="30 0 30 24">
67+
<Grid Grid.Column="0" Margin="0 0 0 12">
68+
<Grid.ColumnDefinitions>
69+
<ColumnDefinition Width="Auto" />
70+
<ColumnDefinition Width="*" />
71+
</Grid.ColumnDefinitions>
72+
<Image
73+
Name="Img"
74+
Grid.Column="0"
75+
Width="18"
76+
Height="18"
77+
Margin="0 0 0 0"
78+
HorizontalAlignment="Left"
79+
VerticalAlignment="Center"
80+
RenderOptions.BitmapScalingMode="Fant"
81+
Stretch="UniformToFill"
82+
Visibility="Collapsed" />
83+
<TextBlock
84+
x:Name="TitleTextBlock"
85+
Grid.Column="1"
86+
MaxWidth="400"
87+
Margin="10 0 26 0"
88+
VerticalAlignment="Center"
89+
FontFamily="Segoe UI"
90+
FontSize="20"
91+
FontWeight="SemiBold"
92+
TextAlignment="Left"
93+
TextWrapping="Wrap" />
94+
</Grid>
95+
<TextBlock
96+
x:Name="DescTextBlock"
97+
Grid.Column="1"
98+
MaxWidth="400"
99+
Margin="0 0 26 0"
100+
HorizontalAlignment="Stretch"
101+
FontSize="14"
102+
TextAlignment="Left"
103+
TextWrapping="Wrap" />
104+
</StackPanel>
105+
<Border
106+
Grid.Row="2"
107+
Margin="0 0 0 0"
108+
Background="{DynamicResource PopupButtonAreaBGColor}"
109+
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}"
110+
BorderThickness="0 1 0 0">
111+
<WrapPanel
112+
HorizontalAlignment="Center"
113+
VerticalAlignment="Center"
114+
Orientation="Horizontal">
115+
<Button
116+
x:Name="btnCancel"
117+
MinWidth="140"
118+
Margin="5 0 5 0"
119+
Click="Button_Click"
120+
Content="{DynamicResource commonCancel}" />
121+
<Button
122+
x:Name="btnNo"
123+
MinWidth="140"
124+
Margin="5 0 5 0"
125+
Click="Button_Click"
126+
Content="{DynamicResource commonNo}" />
127+
<Button
128+
x:Name="btnOk"
129+
MinWidth="140"
130+
Margin="5 0 5 0"
131+
Click="Button_Click"
132+
Content="{DynamicResource commonOK}" />
133+
<Button
134+
x:Name="btnYes"
135+
MinWidth="140"
136+
Margin="5 0 5 0"
137+
Click="Button_Click"
138+
Content="{DynamicResource commonYes}" />
139+
</WrapPanel>
140+
</Border>
141+
</Grid>
142+
</Window>

Flow.Launcher/MessageBoxEx.xaml.cs

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Forms;
11+
using System.Windows.Input;
12+
using System.Windows.Media;
13+
using System.Windows.Media.Imaging;
14+
using System.Windows.Shapes;
15+
using Flow.Launcher.Core.Resource;
16+
using Flow.Launcher.Infrastructure;
17+
using Flow.Launcher.Infrastructure.Image;
18+
using YamlDotNet.Core.Tokens;
19+
20+
namespace Flow.Launcher
21+
{
22+
public partial class MessageBoxEx : Window
23+
{
24+
public MessageBoxEx()
25+
{
26+
InitializeComponent();
27+
}
28+
29+
public enum MessageBoxType
30+
{
31+
ConfirmationWithYesNo = 0,
32+
ConfirmationWithYesNoCancel,
33+
YesNo,
34+
Information,
35+
Error,
36+
Warning
37+
}
38+
39+
public enum MessageBoxImage
40+
{
41+
Warning = 0,
42+
Question,
43+
Information,
44+
Error,
45+
None
46+
}
47+
48+
static MessageBoxEx msgBox;
49+
static MessageBoxResult _result = MessageBoxResult.No;
50+
51+
52+
/// 1 parameter
53+
public static MessageBoxResult Show(string msg)
54+
{
55+
return Show(string.Empty, msg, MessageBoxButton.OK, MessageBoxImage.None);
56+
}
57+
58+
// 2 parameter
59+
public static MessageBoxResult Show(string caption, string text)
60+
{
61+
return Show(caption, text, MessageBoxButton.OK, MessageBoxImage.None);
62+
}
63+
64+
/// 3 parameter
65+
public static MessageBoxResult Show(string caption, string msg, MessageBoxType type)
66+
{
67+
switch (type)
68+
{
69+
case MessageBoxType.ConfirmationWithYesNo:
70+
return Show(caption, msg, MessageBoxButton.YesNo,
71+
MessageBoxImage.Question);
72+
case MessageBoxType.YesNo:
73+
return Show(caption, msg, MessageBoxButton.YesNo,
74+
MessageBoxImage.Question);
75+
case MessageBoxType.ConfirmationWithYesNoCancel:
76+
return Show(caption, msg, MessageBoxButton.YesNoCancel,
77+
MessageBoxImage.Question);
78+
case MessageBoxType.Information:
79+
return Show(caption, msg, MessageBoxButton.OK,
80+
MessageBoxImage.Information);
81+
case MessageBoxType.Error:
82+
return Show(caption, msg, MessageBoxButton.OK,
83+
MessageBoxImage.Error);
84+
case MessageBoxType.Warning:
85+
return Show(caption, msg, MessageBoxButton.OK,
86+
MessageBoxImage.Warning);
87+
default:
88+
return MessageBoxResult.No;
89+
}
90+
}
91+
92+
// 4 parameter, Final Display Message.
93+
public static MessageBoxResult Show(string caption, string text, MessageBoxButton button, MessageBoxImage image)
94+
{
95+
msgBox = new MessageBoxEx();
96+
msgBox.TitleTextBlock.Text = text;
97+
msgBox.DescTextBlock.Text = caption;
98+
msgBox.Title = text;
99+
SetVisibilityOfButtons(button);
100+
SetImageOfMessageBox(image);
101+
msgBox.ShowDialog();
102+
return _result;
103+
}
104+
private void Button_Click(object sender, RoutedEventArgs e)
105+
{
106+
if (sender == btnOk)
107+
_result = MessageBoxResult.OK;
108+
else if (sender == btnYes)
109+
_result = MessageBoxResult.Yes;
110+
else if (sender == btnNo)
111+
_result = MessageBoxResult.No;
112+
else if (sender == btnCancel)
113+
_result = MessageBoxResult.Cancel;
114+
else
115+
_result = MessageBoxResult.None;
116+
msgBox.Close();
117+
msgBox = null;
118+
}
119+
120+
private static void SetVisibilityOfButtons(MessageBoxButton button)
121+
{
122+
switch (button)
123+
{
124+
case MessageBoxButton.OK:
125+
msgBox.btnCancel.Visibility = Visibility.Collapsed;
126+
msgBox.btnNo.Visibility = Visibility.Collapsed;
127+
msgBox.btnYes.Visibility = Visibility.Collapsed;
128+
msgBox.btnOk.Focus();
129+
break;
130+
case MessageBoxButton.OKCancel:
131+
msgBox.btnNo.Visibility = Visibility.Collapsed;
132+
msgBox.btnYes.Visibility = Visibility.Collapsed;
133+
msgBox.btnCancel.Focus();
134+
break;
135+
case MessageBoxButton.YesNo:
136+
msgBox.btnOk.Visibility = Visibility.Collapsed;
137+
msgBox.btnCancel.Visibility = Visibility.Collapsed;
138+
msgBox.btnNo.Focus();
139+
break;
140+
case MessageBoxButton.YesNoCancel:
141+
msgBox.btnOk.Visibility = Visibility.Collapsed;
142+
msgBox.btnCancel.Focus();
143+
break;
144+
default:
145+
break;
146+
}
147+
}
148+
private static void SetImageOfMessageBox(MessageBoxImage image)
149+
{
150+
switch (image)
151+
{
152+
case MessageBoxImage.Warning:
153+
msgBox.SetImage("Warning.png");
154+
msgBox.Img.Visibility = Visibility.Visible;
155+
break;
156+
case MessageBoxImage.Question:
157+
msgBox.SetImage("Question.png");
158+
msgBox.Img.Visibility = Visibility.Visible;
159+
break;
160+
case MessageBoxImage.Information:
161+
msgBox.SetImage("Information.png");
162+
msgBox.Img.Visibility = Visibility.Visible;
163+
break;
164+
case MessageBoxImage.Error:
165+
msgBox.SetImage("Error.png");
166+
msgBox.Img.Visibility = Visibility.Visible;
167+
break;
168+
default:
169+
msgBox.Img.Visibility = Visibility.Collapsed;
170+
break;
171+
}
172+
}
173+
private void SetImage(string imageName)
174+
{
175+
string uri = Constant.ProgramDirectory + "/Images/" + imageName;
176+
var uriSource = new Uri(uri, UriKind.RelativeOrAbsolute);
177+
Img.Source = new BitmapImage(uriSource);
178+
}
179+
private void cmdEsc_OnPress(object sender, ExecutedRoutedEventArgs e)
180+
{
181+
DialogResult = false;
182+
Close();
183+
}
184+
185+
private void Button_Cancel(object sender, RoutedEventArgs e)
186+
{
187+
msgBox.Close();
188+
msgBox = null;
189+
}
190+
191+
}
192+
}

Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Flow.Launcher.Infrastructure;
1212
using Flow.Launcher.Infrastructure.UserSettings;
1313
using Flow.Launcher.Plugin;
14+
using static Flow.Launcher.MessageBoxEx;
1415

1516
namespace Flow.Launcher.SettingPages.ViewModels;
1617

@@ -62,10 +63,10 @@ private void OpenWelcomeWindow()
6263
[RelayCommand]
6364
private void AskClearLogFolderConfirmation()
6465
{
65-
var confirmResult = MessageBox.Show(
66+
var confirmResult = MessageBoxEx.Show(
6667
InternationalizationManager.Instance.GetTranslation("clearlogfolderMessage"),
6768
InternationalizationManager.Instance.GetTranslation("clearlogfolder"),
68-
MessageBoxButton.YesNo
69+
MessageBoxType.YesNo
6970
);
7071

7172
if (confirmResult == MessageBoxResult.Yes)

0 commit comments

Comments
 (0)