Index: Core/Gui/src/Core.Gui/Forms/MainWindow/MainWindow.xaml.cs =================================================================== diff -u -r76fb7e42934ada3ec6ec79f986ff5fe3e026433b -r8579bcc787ce677afba506cc6b701885bae20e78 --- Core/Gui/src/Core.Gui/Forms/MainWindow/MainWindow.xaml.cs (.../MainWindow.xaml.cs) (revision 76fb7e42934ada3ec6ec79f986ff5fe3e026433b) +++ Core/Gui/src/Core.Gui/Forms/MainWindow/MainWindow.xaml.cs (.../MainWindow.xaml.cs) (revision 8579bcc787ce677afba506cc6b701885bae20e78) @@ -30,6 +30,7 @@ using System.Windows.Media.Imaging; using Core.Common.Controls.Views; using Core.Common.Util.Settings; +using Core.Components.Gis.Forms; using Core.Gui.Commands; using Core.Gui.Forms.Map; using Core.Gui.Forms.MessageWindow; @@ -58,6 +59,7 @@ private IGui gui; private PropertyGridView.PropertyGridView propertyGrid; + private IMapView currentMapView; /// /// Initializes a new instance of the class. @@ -120,12 +122,6 @@ } } - public IView PropertyGrid => propertyGrid; - - public IntPtr Handle => windowInteropHelper.Handle; - - public bool InvokeRequired => !Dispatcher.CheckAccess(); - /// /// Gets the . /// @@ -136,6 +132,12 @@ /// public MapLegendView MapLegendView { get; private set; } + public IView PropertyGrid => propertyGrid; + + public IntPtr Handle => windowInteropHelper.Handle; + + public bool InvokeRequired => !Dispatcher.CheckAccess(); + /// /// Sets the and dependencies. /// @@ -156,7 +158,10 @@ { if (viewController?.ViewHost != null) { + viewController.ViewHost.ViewOpened += OnViewOpened; + viewController.ViewHost.ViewBroughtToFront += OnViewBroughtToFront; viewController.ViewHost.ViewClosed += OnViewClosed; + viewController.ViewHost.ActiveDocumentViewChanged += OnActiveDocumentViewChanged; } } @@ -167,7 +172,10 @@ { if (viewController?.ViewHost != null) { + viewController.ViewHost.ViewOpened -= OnViewOpened; + viewController.ViewHost.ViewBroughtToFront -= OnViewBroughtToFront; viewController.ViewHost.ViewClosed -= OnViewClosed; + viewController.ViewHost.ActiveDocumentViewChanged -= OnActiveDocumentViewChanged; } } @@ -180,9 +188,9 @@ public void InitializeToolWindows() { InitProjectExplorerWindowOrBringToFront(); + InitMapLegendWindowOrBringToFront(); InitMessagesWindowOrBringToFront(); InitPropertiesWindowOrBringToFront(); - InitMapLegendWindowOrBringToFront(); } public void ValidateItems() @@ -195,43 +203,7 @@ UpdateToolWindowButtonState(); } - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - /// - /// Initializes and shows the property grid tool window. - /// - /// - /// When a hasn't been set with . - /// - public void InitPropertiesWindowOrBringToFront() - { - if (gui == null) - { - throw new InvalidOperationException("Must call 'SetGui(IGui)' before calling 'InitPropertiesWindowAndActivate'."); - } - - if (propertyGrid == null) - { - propertyGrid = new PropertyGridView.PropertyGridView(gui.PropertyResolver) - { - Text = Properties.Resources.Properties_Title, - Data = applicationSelection.Selection - }; - - viewController.ViewHost.AddToolView(propertyGrid, ToolViewLocation.Right); - viewController.ViewHost.SetImage(propertyGrid, Properties.Resources.PropertiesPanelIcon); - } - else - { - viewController.ViewHost.BringToFront(propertyGrid); - } - } - - /// /// Updates the data of the . /// public void UpdateProjectExplorer() @@ -242,6 +214,12 @@ } } + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + protected virtual void Dispose(bool disposing) { if (IsWindowDisposed || !disposing) @@ -256,104 +234,8 @@ SetGui(null); } - private void OnViewClosed(object sender, ViewChangeEventArgs e) - { - if (ReferenceEquals(e.View, propertyGrid)) - { - propertyGrid = null; - } + #region OnClick events - if (ReferenceEquals(e.View, MessageWindow)) - { - MessageWindow = null; - } - - if (ReferenceEquals(e.View, ProjectExplorer)) - { - ProjectExplorer = null; - } - - if (ReferenceEquals(e.View, MapLegendView)) - { - MapLegendView = null; - } - } - - private void UpdateToolWindowButtonState() - { - if (viewController.ViewHost != null) - { - ButtonShowProjectExplorer.IsChecked = viewController.ViewHost.ToolViews.Contains(ProjectExplorer); - ButtonShowMessages.IsChecked = viewController.ViewHost.ToolViews.Contains(MessageWindow); - ButtonShowProperties.IsChecked = viewController.ViewHost.ToolViews.Contains(PropertyGrid); - ButtonShowMapLegendView.IsChecked = viewController.ViewHost.ToolViews.Contains(MapLegendView); - } - } - - private void InitProjectExplorerWindowOrBringToFront() - { - if (gui == null) - { - throw new InvalidOperationException("Must call 'SetGui(IGui)' before calling 'InitMessagesWindowOrActivate'."); - } - - if (ProjectExplorer == null) - { - ProjectExplorer = new ProjectExplorer.ProjectExplorer(gui.ViewCommands, gui.GetTreeNodeInfos()) - { - Data = gui.Project - }; - viewController.ViewHost.AddToolView(ProjectExplorer, ToolViewLocation.Left); - viewController.ViewHost.SetImage(ProjectExplorer, Properties.Resources.ProjectExplorerIcon); - } - else - { - viewController.ViewHost.BringToFront(ProjectExplorer); - } - } - - private void InitMessagesWindowOrBringToFront() - { - if (gui == null) - { - throw new InvalidOperationException("Must call 'SetGui(IGui)' before calling 'InitMessagesWindowOrActivate'."); - } - - if (MessageWindow == null) - { - MessageWindow = new MessageWindow.MessageWindow(this) - { - Text = Properties.Resources.Messages - }; - viewController.ViewHost.AddToolView(MessageWindow, ToolViewLocation.Bottom); - viewController.ViewHost.SetImage(MessageWindow, Properties.Resources.application_view_list); - } - else - { - viewController.ViewHost.BringToFront(MessageWindow); - } - } - - private void InitMapLegendWindowOrBringToFront() - { - if (gui == null) - { - throw new InvalidOperationException("Must call 'SetGui(IGui)' before calling 'InitMessagesWindowOrActivate'."); - } - - if (MapLegendView == null) - { - MapLegendView = new MapLegendView(gui); - - viewController.ViewHost.AddToolView(MapLegendView, ToolViewLocation.Left); - viewController.ViewHost.SetImage(MapLegendView, Properties.Resources.application_view_list); - } - else - { - viewController.ViewHost.BringToFront(MapLegendView); - } - } - private void OnFileSaveClicked(object sender, RoutedEventArgs e) { commands.StorageCommands.SaveProject(); @@ -440,7 +322,7 @@ ButtonShowMessages.IsChecked = !active; } - + private void ButtonShowMapLegendView_Click(object sender, RoutedEventArgs e) { bool active = viewController.ViewHost.ToolViews.Contains(MapLegendView); @@ -513,6 +395,180 @@ aboutDialog.ShowDialog(); } + #endregion + + #region ToolWindows + + /// + /// Initializes and shows the property grid tool window. + /// + /// + /// When a hasn't been set with . + /// + public void InitPropertiesWindowOrBringToFront() + { + if (gui == null) + { + throw new InvalidOperationException("Must call 'SetGui(IGui)' before calling 'InitPropertiesWindowAndActivate'."); + } + + if (propertyGrid == null) + { + propertyGrid = new PropertyGridView.PropertyGridView(gui.PropertyResolver) + { + Text = Properties.Resources.Properties_Title, + Data = applicationSelection.Selection + }; + + viewController.ViewHost.AddToolView(propertyGrid, ToolViewLocation.Right); + viewController.ViewHost.SetImage(propertyGrid, Properties.Resources.PropertiesPanelIcon); + } + else + { + viewController.ViewHost.BringToFront(propertyGrid); + } + } + + private void UpdateToolWindowButtonState() + { + if (viewController.ViewHost != null) + { + ButtonShowProjectExplorer.IsChecked = viewController.ViewHost.ToolViews.Contains(ProjectExplorer); + ButtonShowMessages.IsChecked = viewController.ViewHost.ToolViews.Contains(MessageWindow); + ButtonShowProperties.IsChecked = viewController.ViewHost.ToolViews.Contains(PropertyGrid); + ButtonShowMapLegendView.IsChecked = viewController.ViewHost.ToolViews.Contains(MapLegendView); + } + } + + private void InitProjectExplorerWindowOrBringToFront() + { + if (gui == null) + { + throw new InvalidOperationException("Must call 'SetGui(IGui)' before calling 'InitMessagesWindowOrActivate'."); + } + + if (ProjectExplorer == null) + { + ProjectExplorer = new ProjectExplorer.ProjectExplorer(gui.ViewCommands, gui.GetTreeNodeInfos()) + { + Data = gui.Project + }; + viewController.ViewHost.AddToolView(ProjectExplorer, ToolViewLocation.Left); + viewController.ViewHost.SetImage(ProjectExplorer, Properties.Resources.ProjectExplorerIcon); + } + else + { + viewController.ViewHost.BringToFront(ProjectExplorer); + } + } + + private void InitMessagesWindowOrBringToFront() + { + if (gui == null) + { + throw new InvalidOperationException("Must call 'SetGui(IGui)' before calling 'InitMessagesWindowOrActivate'."); + } + + if (MessageWindow == null) + { + MessageWindow = new MessageWindow.MessageWindow(this) + { + Text = Properties.Resources.Messages + }; + viewController.ViewHost.AddToolView(MessageWindow, ToolViewLocation.Bottom); + viewController.ViewHost.SetImage(MessageWindow, Properties.Resources.application_view_list); + } + else + { + viewController.ViewHost.BringToFront(MessageWindow); + } + } + + private void InitMapLegendWindowOrBringToFront() + { + if (gui == null) + { + throw new InvalidOperationException("Must call 'SetGui(IGui)' before calling 'InitMessagesWindowOrActivate'."); + } + + if (MapLegendView == null) + { + MapLegendView = new MapLegendView(gui); + + viewController.ViewHost.AddToolView(MapLegendView, ToolViewLocation.Left); + viewController.ViewHost.SetImage(MapLegendView, Properties.Resources.application_view_list); + } + else + { + viewController.ViewHost.BringToFront(MapLegendView); + } + } + + #endregion + + #region Events + + private void OnViewOpened(object sender, ViewChangeEventArgs e) + { + if (e.View is IMapView mapView) + { + mapView.Map.ZoomToAllVisibleLayers(); + UpdateComponentsForMapView(mapView); + } + } + + private void OnViewBroughtToFront(object sender, ViewChangeEventArgs e) + { + UpdateComponentsForMapView(e.View as IMapView); + } + + private void OnActiveDocumentViewChanged(object sender, EventArgs e) + { + UpdateComponentsForMapView(viewController.ViewHost.ActiveDocumentView as IMapView); + } + + private void OnViewClosed(object sender, ViewChangeEventArgs e) + { + if (ReferenceEquals(e.View, propertyGrid)) + { + propertyGrid = null; + } + + if (ReferenceEquals(e.View, MessageWindow)) + { + MessageWindow = null; + } + + if (ReferenceEquals(e.View, ProjectExplorer)) + { + ProjectExplorer = null; + } + + if (ReferenceEquals(e.View, MapLegendView)) + { + MapLegendView = null; + } + + if (ReferenceEquals(e.View, currentMapView)) + { + UpdateComponentsForMapView(null); + } + } + + private void UpdateComponentsForMapView(IMapView mapView) + { + if (ReferenceEquals(currentMapView, mapView)) + { + return; + } + + currentMapView = mapView; + + MapLegendView.MapControl = mapView?.Map; + } + + #endregion + #region Implementation: ISynchronizeInvoke public IAsyncResult BeginInvoke(Delegate method, object[] args)