Index: Core/Gui/src/Core.Gui/Commands/MainWindowCommands.cs
===================================================================
diff -u
--- Core/Gui/src/Core.Gui/Commands/MainWindowCommands.cs (revision 0)
+++ Core/Gui/src/Core.Gui/Commands/MainWindowCommands.cs (revision 577bf2384ad70fef1d46fe46c399fee1a3401718)
@@ -0,0 +1,67 @@
+// Copyright (C) Stichting Deltares 2021. All rights reserved.
+//
+// This file is part of Riskeer.
+//
+// Riskeer is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System.Windows.Input;
+using Core.Gui.Forms.MainWindow;
+
+namespace Core.Gui.Commands
+{
+ ///
+ /// This class defines members for the custom commands of .
+ ///
+ public static class MainWindowCommands
+ {
+ ///
+ /// The command for creating a new project.
+ ///
+ public static readonly ICommand NewProjectCommand = new RoutedCommand();
+
+ ///
+ /// The command for saving the project.
+ ///
+ public static readonly ICommand SaveProjectCommand = new RoutedCommand();
+
+ ///
+ /// The command for saving the project as.
+ ///
+ public static readonly ICommand SaveProjectAsCommand = new RoutedCommand();
+
+ ///
+ /// The command for opening a project.
+ ///
+ public static readonly ICommand OpenProjectCommand = new RoutedCommand();
+
+ ///
+ /// The command for closing the application.
+ ///
+ public static readonly ICommand CloseApplicationCommand = new RoutedCommand();
+
+ ///
+ /// The command for closing the current active view.
+ ///
+ public static readonly ICommand CloseViewTabCommand = new RoutedCommand();
+
+ ///
+ /// The command for toggling the backstage.
+ ///
+ public static readonly ICommand ToggleBackstageCommand = new RoutedCommand();
+ }
+}
\ No newline at end of file
Index: Core/Gui/src/Core.Gui/Commands/RelayCommand.cs
===================================================================
diff -u
--- Core/Gui/src/Core.Gui/Commands/RelayCommand.cs (revision 0)
+++ Core/Gui/src/Core.Gui/Commands/RelayCommand.cs (revision 577bf2384ad70fef1d46fe46c399fee1a3401718)
@@ -0,0 +1,55 @@
+using System;
+using System.Windows.Input;
+
+namespace Core.Gui.Commands
+{
+ ///
+ /// Defines a simple command that executes an .
+ ///
+ public class RelayCommand : ICommand
+ {
+ private readonly Action action;
+ private readonly Func canExecute;
+
+ public event EventHandler CanExecuteChanged;
+
+ ///
+ /// Creates a new instance of .
+ ///
+ /// The action to execute.
+ /// Thrown when is null .
+ public RelayCommand(Action action) : this(action, o => true) {}
+
+ ///
+ /// Creates a new instance of .
+ ///
+ /// The action to execute.
+ /// The function that determines whether command can execute.
+ /// Thrown when is null .
+ public RelayCommand(Action action, Func canExecute)
+ {
+ if (action == null)
+ {
+ throw new ArgumentNullException(nameof(action));
+ }
+
+ if (canExecute == null)
+ {
+ throw new ArgumentNullException(nameof(canExecute));
+ }
+
+ this.action = action;
+ this.canExecute = canExecute;
+ }
+
+ public bool CanExecute(object parameter)
+ {
+ return canExecute(parameter);
+ }
+
+ public void Execute(object parameter)
+ {
+ action(parameter);
+ }
+ }
+}
\ No newline at end of file
Index: Core/Gui/src/Core.Gui/Commands/RoutedCommandHandler.cs
===================================================================
diff -u
--- Core/Gui/src/Core.Gui/Commands/RoutedCommandHandler.cs (revision 0)
+++ Core/Gui/src/Core.Gui/Commands/RoutedCommandHandler.cs (revision 577bf2384ad70fef1d46fe46c399fee1a3401718)
@@ -0,0 +1,75 @@
+using System.Windows;
+using System.Windows.Input;
+
+namespace Core.Gui.Commands
+{
+ ///
+ /// Allows for binding of to the execution of a .
+ ///
+ public class RoutedCommandHandler : Freezable
+ {
+ ///
+ /// Identifies the dependency property.
+ ///
+ public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
+ nameof(Command),
+ typeof(ICommand),
+ typeof(RoutedCommandHandler),
+ new PropertyMetadata(default(ICommand)));
+
+ ///
+ /// Gets or sets the command that should be executed when the RoutedCommand fires.
+ ///
+ public ICommand Command
+ {
+ get => (ICommand) GetValue(CommandProperty);
+ set => SetValue(CommandProperty, value);
+ }
+
+ ///
+ /// The command that triggers the .
+ ///
+ public ICommand RoutedCommand { get; set; }
+
+ protected override Freezable CreateInstanceCore()
+ {
+ return new RoutedCommandHandler();
+ }
+
+ ///
+ /// Registers this handler to respond to the registered RoutedCommand for the
+ /// given element.
+ ///
+ /// The element for which we should register the command
+ /// binding for the current routed command.
+ internal void Register(FrameworkElement owner)
+ {
+ var binding = new CommandBinding(RoutedCommand, HandleExecute, HandleCanExecute);
+ owner.CommandBindings.Add(binding);
+ }
+
+ ///
+ /// Executes with the
+ /// from .
+ ///
+ /// The owner of the routed command.
+ /// The event arguments given by the routed event.
+ private void HandleCanExecute(object sender, CanExecuteRoutedEventArgs e)
+ {
+ e.CanExecute = Command?.CanExecute(e.Parameter) == true;
+ e.Handled = true;
+ }
+
+ ///
+ /// Executes with the
+ /// from .
+ ///
+ /// The owner of the routed command.
+ /// The event arguments given by the routed event.
+ private void HandleExecute(object sender, ExecutedRoutedEventArgs e)
+ {
+ Command?.Execute(e.Parameter);
+ e.Handled = true;
+ }
+ }
+}
\ No newline at end of file
Index: Core/Gui/src/Core.Gui/Commands/RoutedCommandHandlers.cs
===================================================================
diff -u
--- Core/Gui/src/Core.Gui/Commands/RoutedCommandHandlers.cs (revision 0)
+++ Core/Gui/src/Core.Gui/Commands/RoutedCommandHandlers.cs (revision 577bf2384ad70fef1d46fe46c399fee1a3401718)
@@ -0,0 +1,73 @@
+using System.Collections;
+using System.Collections.Specialized;
+using System.Windows;
+
+namespace Core.Gui.Commands
+{
+ ///
+ /// Holds a collection of that should be
+ /// turned into CommandBindings.
+ ///
+ public class RoutedCommandHandlers : FreezableCollection
+ {
+ private static readonly DependencyProperty commandsProperty = DependencyProperty.RegisterAttached(
+ "CommandsPrivate",
+ typeof(RoutedCommandHandlers),
+ typeof(RoutedCommandHandlers),
+ new PropertyMetadata(default(RoutedCommandHandlers)));
+
+ private readonly FrameworkElement owner;
+
+ ///
+ /// Creates a new instance of .
+ ///
+ /// The element for which this collection is created.
+ private RoutedCommandHandlers(FrameworkElement owner)
+ {
+ this.owner = owner;
+
+ ((INotifyCollectionChanged) this).CollectionChanged += OnCollectionChanged;
+ }
+
+ ///
+ /// Gets the collection of RoutedCommandHandler for a given element, creating
+ /// it if it doesn't already exist.
+ ///
+ /// The element to which
+ /// was added.
+ public static RoutedCommandHandlers GetCommands(FrameworkElement element)
+ {
+ var handlers = (RoutedCommandHandlers) element.GetValue(commandsProperty);
+ if (handlers == null)
+ {
+ handlers = new RoutedCommandHandlers(element);
+ element.SetValue(commandsProperty, handlers);
+ }
+
+ return handlers;
+ }
+
+ protected override Freezable CreateInstanceCore()
+ {
+ return new RoutedCommandHandlers(owner);
+ }
+
+ private static void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
+ {
+ ((RoutedCommandHandlers) sender).OnAdd(args.NewItems);
+ }
+
+ private void OnAdd(IEnumerable newItems)
+ {
+ if (newItems == null)
+ {
+ return;
+ }
+
+ foreach (RoutedCommandHandler routedHandler in newItems)
+ {
+ routedHandler.Register(owner);
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Core/Gui/src/Core.Gui/Forms/Backstage/BackstageControl.xaml
===================================================================
diff -u -r25b3196f83ff6455104b5b61d996982beaf9a116 -r577bf2384ad70fef1d46fe46c399fee1a3401718
--- Core/Gui/src/Core.Gui/Forms/Backstage/BackstageControl.xaml (.../BackstageControl.xaml) (revision 25b3196f83ff6455104b5b61d996982beaf9a116)
+++ Core/Gui/src/Core.Gui/Forms/Backstage/BackstageControl.xaml (.../BackstageControl.xaml) (revision 577bf2384ad70fef1d46fe46c399fee1a3401718)
@@ -25,7 +25,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:commands="clr-namespace:Core.Gui.Forms.MainWindow"
+ xmlns:commands="clr-namespace:Core.Gui.Commands"
mc:Ignorable="d">
@@ -43,14 +43,14 @@
INFO
OPENEN
- Opslaan
- Opslaan Als
+ Opslaan
+ Opslaan Als
OVER
Toon log
Handleiding
- Afsluiten
+ Afsluiten
Index: Core/Gui/src/Core.Gui/Forms/MainWindow/MainWindow.xaml
===================================================================
diff -u -r7d6dbf16901f397773a04a2beacf3c07589ce73f -r577bf2384ad70fef1d46fe46c399fee1a3401718
--- Core/Gui/src/Core.Gui/Forms/MainWindow/MainWindow.xaml (.../MainWindow.xaml) (revision 7d6dbf16901f397773a04a2beacf3c07589ce73f)
+++ Core/Gui/src/Core.Gui/Forms/MainWindow/MainWindow.xaml (.../MainWindow.xaml) (revision 577bf2384ad70fef1d46fe46c399fee1a3401718)
@@ -26,35 +26,41 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:metro="http://metro.mahapps.com/winfx/xaml/controls"
- xmlns:commands="clr-namespace:Core.Gui.Forms.MainWindow"
xmlns:properties="clr-namespace:Core.Gui.Properties"
xmlns:viewHost="clr-namespace:Core.Gui.Forms.ViewHost"
xmlns:backstage="clr-namespace:Core.Gui.Forms.Backstage"
+ xmlns:commands="clr-namespace:Core.Gui.Commands"
mc:Ignorable="d"
Title="MainWindow" Height="768" Width="1024"
x:Name="Window"
Icon="/Core.Gui;component\Resources/Riskeer.ico"
ResizeMode="CanResizeWithGrip"
FlowDirection="LeftToRight"
Loaded="MainWindow_OnLoaded">
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
@@ -81,26 +87,26 @@
-
+ Command="{x:Static commands:MainWindowCommands.NewProjectCommand}"
+ AutomationProperties.AutomationId="WindowCommandsNewProject">
+
+ Command="{x:Static commands:MainWindowCommands.SaveProjectCommand}"
+ AutomationProperties.AutomationId="WindowCommandsSaveProject">
+ Command="{x:Static commands:MainWindowCommands.SaveProjectAsCommand}"
+ AutomationProperties.AutomationId="WindowCommandsSaveProjectAs">
+ Command="{x:Static commands:MainWindowCommands.OpenProjectCommand}"
+ AutomationProperties.AutomationId= "WindowCommandsOpenProject">
@@ -190,7 +196,7 @@
Index: Core/Gui/src/Core.Gui/Forms/MainWindow/MainWindow.xaml.cs
===================================================================
diff -u -r7d6dbf16901f397773a04a2beacf3c07589ce73f -r577bf2384ad70fef1d46fe46c399fee1a3401718
--- Core/Gui/src/Core.Gui/Forms/MainWindow/MainWindow.xaml.cs (.../MainWindow.xaml.cs) (revision 7d6dbf16901f397773a04a2beacf3c07589ce73f)
+++ Core/Gui/src/Core.Gui/Forms/MainWindow/MainWindow.xaml.cs (.../MainWindow.xaml.cs) (revision 577bf2384ad70fef1d46fe46c399fee1a3401718)
@@ -69,6 +69,14 @@
private PropertyGridView.PropertyGridView propertyGrid;
private IMapView currentMapView;
private IChartView currentChartView;
+
+ public ICommand NewProjectCommand { get; }
+ public ICommand SaveProjectCommand { get; }
+ public ICommand SaveProjectAsCommand { get; }
+ public ICommand OpenProjectCommand { get; }
+ public ICommand CloseApplicationCommand { get; }
+ public ICommand CloseViewTabCommand { get; }
+ public ICommand ToggleBackStageCommand { get; }
///
/// Initializes a new instance of the class.
@@ -79,6 +87,15 @@
windowInteropHelper = new WindowInteropHelper(this);
Name = "RiskeerMainWindow";
+
+ NewProjectCommand = new RelayCommand(OnNewProject);
+ SaveProjectCommand = new RelayCommand(OnSaveProject);
+ SaveProjectAsCommand = new RelayCommand(OnSaveProjectAs);
+ OpenProjectCommand = new RelayCommand(OnOpenProject);
+ CloseApplicationCommand = new RelayCommand(OnCloseApplication);
+ CloseViewTabCommand = new RelayCommand(OnCloseViewTab, CanCloseViewTab);
+
+ ToggleBackStageCommand = new RelayCommand(OnToggleBackstage);
}
///
@@ -315,17 +332,23 @@
#region OnClick events
- private void OnFileSaveClicked(object sender, RoutedEventArgs e)
+ private void OnNewProject(object obj)
{
+ commands.StorageCommands.CreateNewProject();
+ ValidateItems();
+ }
+
+ private void OnSaveProject(object obj)
+ {
commands.StorageCommands.SaveProject();
}
-
- private void OnFileSaveAsClicked(object sender, RoutedEventArgs e)
+
+ private void OnSaveProjectAs(object obj)
{
commands.StorageCommands.SaveProjectAs();
}
-
- private void OnFileOpenClicked(object sender, RoutedEventArgs e)
+
+ private void OnOpenProject(object obj)
{
string projectPath = commands.StorageCommands.GetExistingProjectFilePath();
if (!string.IsNullOrEmpty(projectPath))
@@ -334,24 +357,33 @@
}
}
- private void OnFileNewClicked(object sender, RoutedEventArgs e)
+ private void OnCloseApplication(object obj)
{
- commands.StorageCommands.CreateNewProject();
- ValidateItems();
+ gui.ExitApplication();
}
-
- private void OnFileExitClicked(object sender, RoutedEventArgs e)
+
+ private bool CanCloseViewTab(object arg)
{
- gui.ExitApplication();
+ return viewController.ViewHost.DocumentViews.Any();
}
- private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
+ private void OnCloseViewTab(object obj)
{
- WindowState = WindowState.Maximized;
+ viewController.ViewHost.Remove(viewController.ViewHost.ActiveDocumentView);
+ }
- FileManualButton.IsEnabled = File.Exists(settings.FixedSettings.ManualFilePath);
-
- ValidateItems();
+ private void OnToggleBackstage(object obj)
+ {
+ if (MainDockPanel.Visibility == Visibility.Visible)
+ {
+ MainDockPanel.Visibility = Visibility.Collapsed;
+ BackstageDockPanel.Visibility = Visibility.Visible;
+ }
+ else
+ {
+ MainDockPanel.Visibility = Visibility.Visible;
+ BackstageDockPanel.Visibility = Visibility.Collapsed;
+ }
}
private void ButtonShowProjectExplorer_Click(object sender, RoutedEventArgs e)
@@ -410,16 +442,6 @@
}
}
- private void CloseDocumentTab(object sender, ExecutedRoutedEventArgs e)
- {
- viewController.ViewHost.Remove(viewController.ViewHost.ActiveDocumentView);
- }
-
- private void CanCloseDocumentTab(object sender, CanExecuteRoutedEventArgs e)
- {
- e.CanExecute = viewController.ViewHost.DocumentViews.Any();
- }
-
private void OnAboutDialog_Clicked(object sender, RoutedEventArgs e)
{
var aboutDialog = new SplashScreen.SplashScreen
@@ -532,6 +554,15 @@
#region Events
+ private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
+ {
+ WindowState = WindowState.Maximized;
+
+ FileManualButton.IsEnabled = File.Exists(settings.FixedSettings.ManualFilePath);
+
+ ValidateItems();
+ }
+
private void OnViewOpened(object sender, ViewChangeEventArgs e)
{
var mapView = e.View as IMapView;
@@ -655,19 +686,5 @@
}
#endregion
-
- private void CommandBinding_OnExecuted(object sender, ExecutedRoutedEventArgs e)
- {
- if (MainDockPanel.Visibility == Visibility.Visible)
- {
- MainDockPanel.Visibility = Visibility.Collapsed;
- BackstageDockPanel.Visibility = Visibility.Visible;
- }
- else
- {
- MainDockPanel.Visibility = Visibility.Visible;
- BackstageDockPanel.Visibility = Visibility.Collapsed;
- }
- }
}
}
\ No newline at end of file
Fisheye: Tag 577bf2384ad70fef1d46fe46c399fee1a3401718 refers to a dead (removed) revision in file `Core/Gui/src/Core.Gui/Forms/MainWindow/MainWindowCommands.cs'.
Fisheye: No comparison available. Pass `N' to diff?