Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 5 additions & 6 deletions Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,16 @@ public interface IPublicAPI
public MessageBoxResult ShowMsgBox(string messageBoxText, string caption = "", MessageBoxButton button = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.OK);

/// <summary>
/// Displays a standardised Flow message box.
/// If there is issue when showing the message box, it will return null.
/// Displays a standardised Flow progress box.
/// </summary>
/// <param name="caption">The caption of the message box.</param>
/// <param name="caption">The caption of the progress box.</param>
/// <param name="reportProgressAsync">
/// Time-consuming task function, whose input is the action to report progress.
/// The input of the action is the progress value which is a double value between 0 and 100.
/// If there are any exceptions, this action will be null.
/// </param>
/// <param name="forceClosed">When user closes the progress box manually by button or esc key, this action will be called.</param>
/// <returns>A progress box interface.</returns>
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action forceClosed = null);
/// <param name="cancelProgress">When user cancel the progress, this action will be called.</param>
/// <returns></returns>
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action cancelProgress = null);
}
}
1 change: 1 addition & 0 deletions Flow.Launcher/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@
<system:String x:Key="commonOK">OK</system:String>
<system:String x:Key="commonYes">Yes</system:String>
<system:String x:Key="commonNo">No</system:String>
<system:String x:Key="commonBackground">Background</system:String>

<!-- Crash Reporter -->
<system:String x:Key="reportWindow_version">Version</system:String>
Expand Down
32 changes: 31 additions & 1 deletion Flow.Launcher/ProgressBoxEx.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Foreground="{DynamicResource PopupTextColor}"
ResizeMode="NoResize"
SizeToContent="Height"
Topmost="True"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">
<WindowChrome.WindowChrome>
Expand All @@ -35,9 +36,32 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button
Grid.Column="1"
Click="Button_Minimize"
RenderOptions.EdgeMode="Aliased"
Style="{DynamicResource TitleBarButtonStyle}">
<Path
Width="46"
Height="32"
Data="M 18,15 H 28"
Stroke="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}"
StrokeThickness="1">
<Path.Style>
<Style TargetType="Path">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Value="False">
<Setter Property="Opacity" Value="0.5" />
</DataTrigger>
</Style.Triggers>
</Style>
</Path.Style>
</Path>
</Button>
<Button
Grid.Column="2"
Click="Button_Cancel"
Style="{StaticResource TitleBarCloseButtonStyle}">
<Path
Expand Down Expand Up @@ -94,11 +118,17 @@
HorizontalAlignment="Center"
VerticalAlignment="Center"
Orientation="Horizontal">
<Button
x:Name="btnBackground"
MinWidth="120"
Margin="5 0 5 0"
Click="Button_Background"
Content="{DynamicResource commonBackground}" />
<Button
x:Name="btnCancel"
MinWidth="120"
Margin="5 0 5 0"
Click="Button_Click"
Click="Button_Cancel"
Content="{DynamicResource commonCancel}" />
</WrapPanel>
</Border>
Expand Down
25 changes: 15 additions & 10 deletions Flow.Launcher/ProgressBoxEx.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ namespace Flow.Launcher
{
public partial class ProgressBoxEx : Window
{
private readonly Action _forceClosed;
private readonly Action _cancelProgress;

private ProgressBoxEx(Action forceClosed)
private ProgressBoxEx(Action cancelProgress)
{
_forceClosed = forceClosed;
_cancelProgress = cancelProgress;
InitializeComponent();
}

public static async Task ShowAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action forceClosed = null)
public static async Task ShowAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action cancelProgress = null)
{
ProgressBoxEx prgBox = null;
try
Expand All @@ -25,7 +25,7 @@ public static async Task ShowAsync(string caption, Func<Action<double>, Task> re
{
await Application.Current.Dispatcher.InvokeAsync(() =>
{
prgBox = new ProgressBoxEx(forceClosed)
prgBox = new ProgressBoxEx(cancelProgress)
{
Title = caption
};
Expand All @@ -35,7 +35,7 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
}
else
{
prgBox = new ProgressBoxEx(forceClosed)
prgBox = new ProgressBoxEx(cancelProgress)
{
Title = caption
};
Expand Down Expand Up @@ -95,20 +95,25 @@ private void KeyEsc_OnPress(object sender, ExecutedRoutedEventArgs e)
ForceClose();
}

private void Button_Click(object sender, RoutedEventArgs e)
private void Button_Cancel(object sender, RoutedEventArgs e)
{
ForceClose();
}

private void Button_Cancel(object sender, RoutedEventArgs e)
private void Button_Minimize(object sender, RoutedEventArgs e)
{
ForceClose();
WindowState = WindowState.Minimized;
}

private void Button_Background(object sender, RoutedEventArgs e)
{
Hide();
}

private void ForceClose()
{
Close();
_forceClosed?.Invoke();
_cancelProgress?.Invoke();
}
}
}
2 changes: 1 addition & 1 deletion Flow.Launcher/PublicAPIInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public bool IsGameModeOn()
public MessageBoxResult ShowMsgBox(string messageBoxText, string caption = "", MessageBoxButton button = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.OK) =>
MessageBoxEx.Show(messageBoxText, caption, button, icon, defaultResult);

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

#endregion

Expand Down
Loading