aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs128
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DialogWindow.xaml32
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DialogWindow.xaml.cs42
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/MessageBoxWindow.xaml2
4 files changed, 130 insertions, 74 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs
index b1ba03109..d4d053eaf 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs
@@ -15,6 +15,8 @@ namespace Tango.MachineStudio.UI.Notifications
{
public class DefaultNotificationProvider : ExtendedObject, INotificationProvider
{
+ private static List<Type> viewTypes;
+
public ObservableCollection<TaskItem> TaskItems { get; private set; }
public bool HasTaskItems
@@ -35,48 +37,126 @@ namespace Tango.MachineStudio.UI.Notifications
TaskItems = new ObservableCollection<TaskItem>();
}
- public bool ShowModalWindow<T>(PackIconKind icon, string title, object context) where T : FrameworkElement
- {
- return ShowModalWindow(icon, title, Activator.CreateInstance<T>(), context);
- }
-
- public bool? ShowModalWindow(Window window)
+ public bool? ShowDialog(PackIconKind icon, Brush iconColor, string message, bool hasCancel)
{
- window.Owner = Application.Current.MainWindow;
MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible;
- bool result = window.ShowDialog().Value;
+
+ var result = new MessageBoxWindow()
+ {
+ Owner = Application.Current.MainWindow,
+ Message = message,
+ IconKind = icon,
+ IconColor = iconColor,
+ HasCancel = hasCancel
+
+ }.ShowDialog();
+
MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden;
return result;
}
- public bool ShowModalWindow(PackIconKind icon, string title, FrameworkElement content, object context)
+ public void ShowModalDialog<View, VM>(Action<VM> onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM
{
- DialogWindow dialog = new DialogWindow(content);
- dialog.DataContext = context;
- dialog.InnerTitle = title;
+ var view = Activator.CreateInstance<View>();
+ DialogWindow dialog = new DialogWindow();
dialog.Owner = Application.Current.MainWindow;
+ dialog.InnerContent = view;
MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible;
- bool result = dialog.ShowDialog().Value;
+ view.Loaded += (x, y) =>
+ {
+ VM context = view.DataContext as VM;
+ dialog.DataContext = context;
+
+ Action onAcceptAction = null;
+ onAcceptAction = new Action(() =>
+ {
+ dialog.Close();
+ onAccept(context);
+ context.Accepted -= onAcceptAction;
+ });
+
+ Action onCancelAction = null;
+ onCancelAction = new Action(() =>
+ {
+ dialog.Close();
+
+ if (onCancel != null)
+ {
+ onCancel();
+ }
+
+ context.Canceled -= onCancelAction;
+ });
+
+ context.Accepted += onAcceptAction;
+ context.Canceled += onCancelAction;
+
+ context.OnShow();
+ };
+ dialog.ShowDialog();
MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden;
- return result;
}
- public bool? ShowDialog(PackIconKind icon, Brush iconColor, string message, bool hasCancel)
+ public void ShowModalDialog<VM>(Action<VM> onAccept, Action onCancel) where VM : DialogViewVM
{
- MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible;
+ String viewName = typeof(VM).Name.Replace("VM", "");
- var result = new MessageBoxWindow()
+ if (viewTypes == null)
{
- Owner = Application.Current.MainWindow,
- Message = message,
- IconKind = icon,
- IconColor = iconColor,
- HasCancel = hasCancel
+ viewTypes = AppDomain.CurrentDomain.GetAssemblies().Where(x => x.FullName.Contains("MachineStudio")).SelectMany(x => x.GetTypes()).ToList();
+ }
- }.ShowDialog();
+ var viewType = viewTypes.SingleOrDefault(x => x.Name == viewName);
+
+ if (viewType == null)
+ {
+ throw new NullReferenceException("Could not locate view " + viewName);
+ }
+ var view = Activator.CreateInstance(viewType) as FrameworkElement;
+ DialogWindow dialog = new DialogWindow();
+ dialog.Owner = Application.Current.MainWindow;
+ dialog.InnerContent = view;
+ MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible;
+ view.Loaded += (x, y) =>
+ {
+ VM context = view.DataContext as VM;
+ dialog.DataContext = context;
+
+ Action onAcceptAction = null;
+ onAcceptAction = new Action(() =>
+ {
+ dialog.Close();
+ onAccept(context);
+ context.Accepted -= onAcceptAction;
+ });
+
+ Action onCancelAction = null;
+ onCancelAction = new Action(() =>
+ {
+ dialog.Close();
+
+ if (onCancel != null)
+ {
+ onCancel();
+ }
+
+ context.Canceled -= onCancelAction;
+ });
+
+ context.Accepted += onAcceptAction;
+ context.Canceled += onCancelAction;
+
+ context.OnShow();
+ };
+
+ dialog.ShowDialog();
MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden;
- return result;
+ }
+
+ public void ShowModalDialog<VM>(Action<VM> onAccept) where VM : DialogViewVM
+ {
+ ShowModalDialog<VM>(onAccept, null);
}
public void ShowError(string message)
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DialogWindow.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DialogWindow.xaml
index 2a8dd9f28..c11e2e11b 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DialogWindow.xaml
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DialogWindow.xaml
@@ -1,4 +1,4 @@
-<mahapps:MetroWindow x:Class="Tango.MachineStudio.UI.Windows.DialogWindow"
+<Window x:Class="Tango.MachineStudio.UI.Windows.DialogWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@@ -7,18 +7,22 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Tango.MachineStudio.UI.Windows"
mc:Ignorable="d"
- Title="Machine Studio" Height="450" Width="650" EnableDWMDropShadow="True" ShowCloseButton="False" WindowTransitionsEnabled="False" ShowMaxRestoreButton="False" ShowMinButton="False" TitleCaps="False" BorderThickness="1" WindowStartupLocation="CenterOwner">
+ Title="Machine Studio" MinHeight="220" SizeToContent="WidthAndHeight" MinWidth="600" AllowsTransparency="True" WindowStyle="None" WindowStartupLocation="CenterOwner" Background="Transparent">
<Grid>
- <Border Margin="16">
- <DockPanel LastChildFill="True">
- <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" VerticalAlignment="Top">
- <materialDesign:PackIcon Kind="{Binding RelativeSource={RelativeSource AncestorType=Window},Path=IconKind}" VerticalAlignment="Center" Width="32" Height="32" Foreground="{StaticResource AccentColorBrush}" />
- <TextBlock Margin="10 0 0 0" Foreground="{StaticResource AccentColorBrush}" FontSize="16" Text="{Binding RelativeSource={RelativeSource AncestorType=Window},Path=InnerTitle}"></TextBlock>
- </StackPanel>
- <ScrollViewer Margin="0 10 0 10" VerticalScrollBarVisibility="Auto" Padding="5">
- <ContentPresenter x:Name="presenter"></ContentPresenter>
- </ScrollViewer>
- </DockPanel>
- </Border>
+ <Grid>
+ <Border Background="White" CornerRadius="10" Padding="10" Margin="20">
+ <Border.Effect>
+ <DropShadowEffect ShadowDepth="0" BlurRadius="10"></DropShadowEffect>
+ </Border.Effect>
+
+ <Grid>
+ <ContentPresenter x:Name="presenter" Content="{Binding RelativeSource={RelativeSource AncestorType=Window},Path=InnerContent}"></ContentPresenter>
+
+ <Button Command="{Binding CloseCommand}" HorizontalAlignment="Right" VerticalAlignment="Top" Width="20" Height="20" Margin="0 -6 -4 0" Padding="0" Style="{StaticResource MaterialDesignFlatButton}" Foreground="Black">
+ <materialDesign:PackIcon Kind="Close" Width="16" Height="16"></materialDesign:PackIcon>
+ </Button>
+ </Grid>
+ </Border>
+ </Grid>
</Grid>
-</mahapps:MetroWindow>
+</Window>
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DialogWindow.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DialogWindow.xaml.cs
index 31dd3d644..d1bc0564b 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DialogWindow.xaml.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DialogWindow.xaml.cs
@@ -20,51 +20,23 @@ namespace Tango.MachineStudio.UI.Windows
/// <summary>
/// Interaction logic for DialogWindow.xaml
/// </summary>
- public partial class DialogWindow : MetroWindow
+ public partial class DialogWindow : Window
{
public DialogWindow()
{
InitializeComponent();
}
-
-
- public String InnerTitle
- {
- get { return (String)GetValue(InnerTitleProperty); }
- set { SetValue(InnerTitleProperty, value); }
- }
- public static readonly DependencyProperty InnerTitleProperty =
- DependencyProperty.Register("InnerTitle", typeof(String), typeof(DialogWindow), new PropertyMetadata(null));
-
-
-
- public PackIconKind IconKind
+ public FrameworkElement InnerContent
{
- get { return (PackIconKind)GetValue(IconKindProperty); }
- set { SetValue(IconKindProperty, value); }
+ get { return (FrameworkElement)GetValue(InnerContentProperty); }
+ set { SetValue(InnerContentProperty, value); }
}
- public static readonly DependencyProperty IconKindProperty =
- DependencyProperty.Register("IconKind", typeof(PackIconKind), typeof(DialogWindow), new PropertyMetadata(PackIconKind.Information));
-
+ // Using a DependencyProperty as the backing store for InnerContent. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty InnerContentProperty =
+ DependencyProperty.Register("InnerContent", typeof(FrameworkElement), typeof(DialogWindow), new PropertyMetadata(null));
- public DialogWindow(FrameworkElement content) : this()
- {
- presenter.Content = content;
- }
-
- private void OnOKClicked(object sender, RoutedEventArgs e)
- {
- DialogResult = true;
- Close();
- }
-
- private void OnCancelClicked(object sender, RoutedEventArgs e)
- {
- DialogResult = false;
- Close();
- }
}
}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/MessageBoxWindow.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/MessageBoxWindow.xaml
index 4f3b826fe..a89f8eeca 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/MessageBoxWindow.xaml
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/MessageBoxWindow.xaml
@@ -24,7 +24,7 @@
<Button Style="{StaticResource MaterialDesignFlatButton}" IsDefault="True" Margin="0 8 8 0" Click="OnOKClicked">
ACCEPT
</Button>
- <Button Visibility="{Binding RelativeSource={RelativeSource AncestorType=Window},Path=HasCancel,Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource MaterialDesignFlatButton}" IsCancel="True" Margin="0 8 8 0" Click="OnCancelClicked">
+ <Button Visibility="{Binding RelativeSource={RelativeSource AncestorType=Window},Path=HasCancel,Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource MaterialDesignFlatButton}" IsCancel="False" Margin="0 8 8 0" Click="OnCancelClicked">
CANCEL
</Button>
</StackPanel>