diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs | 93 | ||||
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/MessageBox.xaml | 27 |
2 files changed, 105 insertions, 15 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs index dbaafa6bb..02e41e087 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs @@ -8,16 +8,37 @@ using System.Windows; using System.Windows.Media; using Tango.PPC.Common.Notifications; using Tango.Core; +using System.Collections.Concurrent; +using System.Windows.Media.Imaging; +using Tango.SharedUI.Helpers; namespace Tango.PPC.UI.Notifications { public class DefaultNotificationProvider : ExtendedObject, INotificationProvider { + private class PendingMessageBox + { + public MessageBoxVM VM { get; set; } + public TaskCompletionSource<bool> CompletionSource { get; set; } + } + + private ConcurrentQueue<PendingMessageBox> _pendingMessageBoxes; + + public DefaultNotificationProvider() + { + _pendingMessageBoxes = new ConcurrentQueue<PendingMessageBox>(); + } + private MessageBoxVM _currentMessageBox; public MessageBoxVM CurrentMessageBox { get { return _currentMessageBox; } - private set { _currentMessageBox = value; RaisePropertyChangedAuto(); } + private set + { + _currentMessageBox = value; + RaisePropertyChangedAuto(); + RaisePropertyChanged(nameof(HasMessageBox)); + } } public bool HasMessageBox @@ -30,22 +51,84 @@ namespace Tango.PPC.UI.Notifications public Task ShowError(string message) { - throw new NotImplementedException(); + return ShowMessageBox(new MessageBoxVM() + { + Message = message, + Icon = ResourceHelper.GetImageFromResources("Images/MessageBox Icons/information.png"), + Title = "Error", + Brush = Application.Current.Resources["TangoMessageBoxErrorBrush"] as Brush, + }); } public Task ShowInfo(string message) { - throw new NotImplementedException(); + return ShowMessageBox(new MessageBoxVM() + { + Message = message, + Icon = ResourceHelper.GetImageFromResources("Images/MessageBox Icons/information.png"), + Title = "Information", + Brush = Application.Current.Resources["TangoMessageBoxInfoBrush"] as Brush, + }); } public Task ShowWarning(string message) { - throw new NotImplementedException(); + return ShowMessageBox(new MessageBoxVM() + { + Message = message, + Icon = ResourceHelper.GetImageFromResources("Images/MessageBox Icons/information.png"), + Title = "Warning", + Brush = Application.Current.Resources["TangoMessageBoxWarningBrush"] as Brush, + }); } public Task<bool> ShowQuestion(string message) { - throw new NotImplementedException(); + return ShowMessageBox(new MessageBoxVM() + { + Message = message, + Icon = ResourceHelper.GetImageFromResources("Images/MessageBox Icons/information.png"), + Title = "Confirm", + HasCancel = true, + Brush = Application.Current.Resources["TangoMessageBoxQuestionBrush"] as Brush, + }); + } + + private Task<bool> ShowMessageBox(MessageBoxVM vm) + { + TaskCompletionSource<bool> source = new TaskCompletionSource<bool>(); + + vm.Accepted += () => { OnMessageBoxClosed(); source.SetResult(true); }; + vm.Canceled += () => { OnMessageBoxClosed(); source.SetResult(false); }; + + if (CurrentMessageBox == null) + { + CurrentMessageBox = vm; + } + else + { + _pendingMessageBoxes.Enqueue(new PendingMessageBox() + { + VM = vm, + CompletionSource = source, + }); + } + + return source.Task; + } + + private void OnMessageBoxClosed() + { + CurrentMessageBox = null; + + if (_pendingMessageBoxes.Count > 0) + { + PendingMessageBox p = null; + if (_pendingMessageBoxes.TryDequeue(out p)) + { + CurrentMessageBox = p.VM; + } + } } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/MessageBox.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/MessageBox.xaml index a699902b8..07d3b11ac 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/MessageBox.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/MessageBox.xaml @@ -8,30 +8,37 @@ xmlns:vm="clr-namespace:Tango.PPC.Common.Notifications;assembly=Tango.PPC.Common" xmlns:local="clr-namespace:Tango.PanelPC.UI.Notifications" mc:Ignorable="d" - d:DesignHeight="200" d:DesignWidth="500" d:DataContext="{d:DesignInstance vm:MessageBoxVM,IsDesignTimeCreatable=False}"> + d:DesignHeight="400" d:DesignWidth="800" d:DataContext="{d:DesignInstance vm:MessageBoxVM,IsDesignTimeCreatable=False}"> <Grid> - <Border Background="{StaticResource TangoPrimaryBackgroundBrush}" CornerRadius="10" Margin="10" Padding="10"> + <Border Background="{StaticResource TangoPrimaryBackgroundBrush}" CornerRadius="10" Margin="10"> <Border.Effect> <DropShadowEffect BlurRadius="10" /> </Border.Effect> <Grid> <Grid.ColumnDefinitions> - <ColumnDefinition Width="17*"/> + <ColumnDefinition Width="100"/> <ColumnDefinition Width="75*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> + <RowDefinition Height="100" /> <RowDefinition Height="1*" /> - <RowDefinition Height="Auto"/> + <RowDefinition Height="70"/> </Grid.RowDefinitions> - <Image Source="{Binding Icon,FallbackValue='/Images/MessageBox Icons/information.png'}" Margin="10" /> - <TextBlock x:Name="lbMessage" Grid.Column="1" TextWrapping="Wrap" VerticalAlignment="Center" Margin="10,50,10,55" Height="16"></TextBlock> + <Image Grid.Row="0" Source="{Binding Icon}" Margin="20" /> + <TextBlock Grid.Column="1" Text="{Binding Title,TargetNullValue=Confirm}" Foreground="{Binding Brush,TargetNullValue={StaticResource TangoPrimaryAccentBrush}}" VerticalAlignment="Center" Margin="10" Style="{StaticResource TangoMessageBoxTitle}"></TextBlock> - <UniformGrid Grid.Column="1" Grid.Row="1" HorizontalAlignment="Right" Rows="1" Width="220"> - <touch:TouchButton x:Name="btnCancel" Margin="2" Style="{StaticResource TangoFlatButtonTextOnly}">CANCEL</touch:TouchButton> - <touch:TouchButton x:Name="btnOK" Margin="2" Style="{StaticResource TangoFlatButtonTextOnly}">OK</touch:TouchButton> - </UniformGrid> + <Rectangle Stroke="{Binding Brush}" VerticalAlignment="Bottom" Grid.ColumnSpan="2" StrokeThickness="3" /> + + <TextBlock Grid.Row="1" FontSize="{StaticResource TangoMessageBoxMessageFontSize}" Text="{Binding Message}" VerticalAlignment="Top" Grid.Column="1" TextWrapping="Wrap" Margin="10 20 10 10"></TextBlock> + + <Rectangle Stroke="{StaticResource TangoDividerBrush}" VerticalAlignment="Bottom" Grid.Row="1" Grid.ColumnSpan="2" StrokeThickness="1"/> + + <StackPanel Grid.Column="1" Grid.Row="2" HorizontalAlignment="Right" Orientation="Horizontal"> + <touch:TouchButton x:Name="btnCancel" Width="180" Margin="2 0" Style="{StaticResource TangoMessageBoxButton}" Command="{Binding CloseCommand}" Visibility="{Binding HasCancel,Converter={StaticResource BooleanToVisibilityConverter}}">CANCEL</touch:TouchButton> + <touch:TouchButton x:Name="btnOK" Width="180" Margin="2 0" Style="{StaticResource TangoMessageBoxButton}" Command="{Binding OKCommand}">OK</touch:TouchButton> + </StackPanel> </Grid> </Border> </Grid> |
