Skip to content

Commit 65f85cf

Browse files
authored
Merge pull request #3267 from Jack251970/improve_progress_box
Improve Progress Box Design
2 parents 9329575 + ed5e0bb commit 65f85cf

File tree

5 files changed

+53
-18
lines changed

5 files changed

+53
-18
lines changed

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

+5-6
Original file line numberDiff line numberDiff line change
@@ -323,17 +323,16 @@ public interface IPublicAPI
323323
public MessageBoxResult ShowMsgBox(string messageBoxText, string caption = "", MessageBoxButton button = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.OK);
324324

325325
/// <summary>
326-
/// Displays a standardised Flow message box.
327-
/// If there is issue when showing the message box, it will return null.
326+
/// Displays a standardised Flow progress box.
328327
/// </summary>
329-
/// <param name="caption">The caption of the message box.</param>
328+
/// <param name="caption">The caption of the progress box.</param>
330329
/// <param name="reportProgressAsync">
331330
/// Time-consuming task function, whose input is the action to report progress.
332331
/// The input of the action is the progress value which is a double value between 0 and 100.
333332
/// If there are any exceptions, this action will be null.
334333
/// </param>
335-
/// <param name="forceClosed">When user closes the progress box manually by button or esc key, this action will be called.</param>
336-
/// <returns>A progress box interface.</returns>
337-
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action forceClosed = null);
334+
/// <param name="cancelProgress">When user cancel the progress, this action will be called.</param>
335+
/// <returns></returns>
336+
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action cancelProgress = null);
338337
}
339338
}

Flow.Launcher/Languages/en.xaml

+1
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@
368368
<system:String x:Key="commonOK">OK</system:String>
369369
<system:String x:Key="commonYes">Yes</system:String>
370370
<system:String x:Key="commonNo">No</system:String>
371+
<system:String x:Key="commonBackground">Background</system:String>
371372

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

Flow.Launcher/ProgressBoxEx.xaml

+31-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Foreground="{DynamicResource PopupTextColor}"
1313
ResizeMode="NoResize"
1414
SizeToContent="Height"
15+
Topmost="True"
1516
WindowStartupLocation="CenterScreen"
1617
mc:Ignorable="d">
1718
<WindowChrome.WindowChrome>
@@ -35,9 +36,32 @@
3536
<Grid.ColumnDefinitions>
3637
<ColumnDefinition Width="*" />
3738
<ColumnDefinition Width="Auto" />
39+
<ColumnDefinition Width="Auto" />
3840
</Grid.ColumnDefinitions>
3941
<Button
4042
Grid.Column="1"
43+
Click="Button_Minimize"
44+
RenderOptions.EdgeMode="Aliased"
45+
Style="{DynamicResource TitleBarButtonStyle}">
46+
<Path
47+
Width="46"
48+
Height="32"
49+
Data="M 18,15 H 28"
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+
<Button
64+
Grid.Column="2"
4165
Click="Button_Cancel"
4266
Style="{StaticResource TitleBarCloseButtonStyle}">
4367
<Path
@@ -94,11 +118,17 @@
94118
HorizontalAlignment="Center"
95119
VerticalAlignment="Center"
96120
Orientation="Horizontal">
121+
<Button
122+
x:Name="btnBackground"
123+
MinWidth="120"
124+
Margin="5 0 5 0"
125+
Click="Button_Background"
126+
Content="{DynamicResource commonBackground}" />
97127
<Button
98128
x:Name="btnCancel"
99129
MinWidth="120"
100130
Margin="5 0 5 0"
101-
Click="Button_Click"
131+
Click="Button_Cancel"
102132
Content="{DynamicResource commonCancel}" />
103133
</WrapPanel>
104134
</Border>

Flow.Launcher/ProgressBoxEx.xaml.cs

+15-10
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ namespace Flow.Launcher
88
{
99
public partial class ProgressBoxEx : Window
1010
{
11-
private readonly Action _forceClosed;
11+
private readonly Action _cancelProgress;
1212

13-
private ProgressBoxEx(Action forceClosed)
13+
private ProgressBoxEx(Action cancelProgress)
1414
{
15-
_forceClosed = forceClosed;
15+
_cancelProgress = cancelProgress;
1616
InitializeComponent();
1717
}
1818

19-
public static async Task ShowAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action forceClosed = null)
19+
public static async Task ShowAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action cancelProgress = null)
2020
{
2121
ProgressBoxEx prgBox = null;
2222
try
@@ -25,7 +25,7 @@ public static async Task ShowAsync(string caption, Func<Action<double>, Task> re
2525
{
2626
await Application.Current.Dispatcher.InvokeAsync(() =>
2727
{
28-
prgBox = new ProgressBoxEx(forceClosed)
28+
prgBox = new ProgressBoxEx(cancelProgress)
2929
{
3030
Title = caption
3131
};
@@ -35,7 +35,7 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
3535
}
3636
else
3737
{
38-
prgBox = new ProgressBoxEx(forceClosed)
38+
prgBox = new ProgressBoxEx(cancelProgress)
3939
{
4040
Title = caption
4141
};
@@ -95,20 +95,25 @@ private void KeyEsc_OnPress(object sender, ExecutedRoutedEventArgs e)
9595
ForceClose();
9696
}
9797

98-
private void Button_Click(object sender, RoutedEventArgs e)
98+
private void Button_Cancel(object sender, RoutedEventArgs e)
9999
{
100100
ForceClose();
101101
}
102102

103-
private void Button_Cancel(object sender, RoutedEventArgs e)
103+
private void Button_Minimize(object sender, RoutedEventArgs e)
104104
{
105-
ForceClose();
105+
WindowState = WindowState.Minimized;
106+
}
107+
108+
private void Button_Background(object sender, RoutedEventArgs e)
109+
{
110+
Hide();
106111
}
107112

108113
private void ForceClose()
109114
{
110115
Close();
111-
_forceClosed?.Invoke();
116+
_cancelProgress?.Invoke();
112117
}
113118
}
114119
}

Flow.Launcher/PublicAPIInstance.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public bool IsGameModeOn()
342342
public MessageBoxResult ShowMsgBox(string messageBoxText, string caption = "", MessageBoxButton button = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.OK) =>
343343
MessageBoxEx.Show(messageBoxText, caption, button, icon, defaultResult);
344344

345-
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action forceClosed = null) => ProgressBoxEx.ShowAsync(caption, reportProgressAsync, forceClosed);
345+
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action cancelProgress = null) => ProgressBoxEx.ShowAsync(caption, reportProgressAsync, cancelProgress);
346346

347347
#endregion
348348

0 commit comments

Comments
 (0)