Skip to content

Commit 1560991

Browse files
committed
Merge Old MessageBox PR
2 parents 44ad866 + 9f364d7 commit 1560991

File tree

6 files changed

+328
-0
lines changed

6 files changed

+328
-0
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/MessageBoxEx.xaml

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

Flow.Launcher/MessageBoxEx.xaml.cs

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

0 commit comments

Comments
 (0)