Index: Core/Common/src/Core.Common.Gui/Forms/ViewHost/AvalonDockViewHost.xaml.cs =================================================================== diff -u -r569a286badd9b3494f5465cc2767a8cf6a77f618 -ra999c7ca7999cc5e15b938120496d19364b26cc8 --- Core/Common/src/Core.Common.Gui/Forms/ViewHost/AvalonDockViewHost.xaml.cs (.../AvalonDockViewHost.xaml.cs) (revision 569a286badd9b3494f5465cc2767a8cf6a77f618) +++ Core/Common/src/Core.Common.Gui/Forms/ViewHost/AvalonDockViewHost.xaml.cs (.../AvalonDockViewHost.xaml.cs) (revision a999c7ca7999cc5e15b938120496d19364b26cc8) @@ -48,6 +48,7 @@ public event EventHandler ActiveDocumentViewChanged; public event EventHandler ActiveViewChanged; public event EventHandler ViewOpened; + public event EventHandler ViewBroughtToFront; public event EventHandler ViewClosed; /// @@ -216,6 +217,8 @@ : null; BringToFront(layoutContent); + + OnViewBroughtToFront(view); } public void SetImage(IView view, Image image) @@ -270,6 +273,11 @@ ViewOpened?.Invoke(this, new ViewChangeEventArgs(view)); } + private void OnViewBroughtToFront(IView view) + { + ViewBroughtToFront?.Invoke(this, new ViewChangeEventArgs(view)); + } + private void OnViewClosed(IView view) { ViewClosed?.Invoke(this, new ViewChangeEventArgs(view)); Index: Core/Common/src/Core.Common.Gui/Forms/ViewHost/IViewHost.cs =================================================================== diff -u -rfbf0127601ef799db5ec78430746c6aa23eab218 -ra999c7ca7999cc5e15b938120496d19364b26cc8 --- Core/Common/src/Core.Common.Gui/Forms/ViewHost/IViewHost.cs (.../IViewHost.cs) (revision fbf0127601ef799db5ec78430746c6aa23eab218) +++ Core/Common/src/Core.Common.Gui/Forms/ViewHost/IViewHost.cs (.../IViewHost.cs) (revision a999c7ca7999cc5e15b938120496d19364b26cc8) @@ -52,6 +52,11 @@ event EventHandler ViewOpened; /// + /// Fired when an already opened document view or tool view is brought to front. + /// + event EventHandler ViewBroughtToFront; + + /// /// Fired when a document view or a tool view has been closed. /// event EventHandler ViewClosed; Index: Core/Common/test/Core.Common.Gui.Test/Forms/ViewHost/AvalonDockViewHostTest.cs =================================================================== diff -u -r2f093d7c5de7c58974002da72ed60c0358409480 -ra999c7ca7999cc5e15b938120496d19364b26cc8 --- Core/Common/test/Core.Common.Gui.Test/Forms/ViewHost/AvalonDockViewHostTest.cs (.../AvalonDockViewHostTest.cs) (revision 2f093d7c5de7c58974002da72ed60c0358409480) +++ Core/Common/test/Core.Common.Gui.Test/Forms/ViewHost/AvalonDockViewHostTest.cs (.../AvalonDockViewHostTest.cs) (revision a999c7ca7999cc5e15b938120496d19364b26cc8) @@ -380,11 +380,12 @@ } [Test] - public void BringToFront_ActiveDocumentView_ActiveViewNotAffectedAndNoActiveViewEventsFired() + public void BringToFront_ActiveDocumentView_ViewBroughtToFrontFiredButActiveViewNotAffectedAndNoActiveViewEventsFired() { // Setup var testView1 = new TestView(); var testView2 = new TestView(); + var viewBroughtToFrontCounter = 0; var activeDocumentViewChangingCounter = 0; var activeDocumentViewChangedCounter = 0; var activeViewChangedCounter = 0; @@ -395,6 +396,7 @@ avalonDockViewHost.AddDocumentView(testView2); SetActiveView(avalonDockViewHost, testView1); + avalonDockViewHost.ViewBroughtToFront += (sender, args) => viewBroughtToFrontCounter++; avalonDockViewHost.ActiveDocumentViewChanging += (sender, args) => activeDocumentViewChangingCounter++; avalonDockViewHost.ActiveDocumentViewChanged += (sender, args) => activeDocumentViewChangedCounter++; avalonDockViewHost.ActiveViewChanged += (sender, args) => activeViewChangedCounter++; @@ -403,6 +405,7 @@ avalonDockViewHost.BringToFront(testView1); // Assert + Assert.AreEqual(1, viewBroughtToFrontCounter); Assert.AreEqual(0, activeDocumentViewChangingCounter); Assert.AreEqual(0, activeDocumentViewChangedCounter); Assert.AreEqual(0, activeViewChangedCounter); @@ -412,11 +415,12 @@ } [Test] - public void BringToFront_NonActiveDocumentView_ActiveViewNotAffectedAndNoActiveViewEventsFired() + public void BringToFront_NonActiveDocumentView_ViewBroughtToFrontFiredButActiveViewNotAffectedAndNoActiveViewEventsFired() { // Setup var testView1 = new TestView(); var testView2 = new TestView(); + var viewBroughtToFrontCounter = 0; var activeDocumentViewChangingCounter = 0; var activeDocumentViewChangedCounter = 0; var activeViewChangedCounter = 0; @@ -427,6 +431,7 @@ avalonDockViewHost.AddDocumentView(testView2); SetActiveView(avalonDockViewHost, testView2); + avalonDockViewHost.ViewBroughtToFront += (sender, args) => viewBroughtToFrontCounter++; avalonDockViewHost.ActiveDocumentViewChanging += (sender, args) => activeDocumentViewChangingCounter++; avalonDockViewHost.ActiveDocumentViewChanged += (sender, args) => activeDocumentViewChangedCounter++; avalonDockViewHost.ActiveViewChanged += (sender, args) => activeViewChangedCounter++; @@ -435,6 +440,7 @@ avalonDockViewHost.BringToFront(testView1); // Assert + Assert.AreEqual(1, viewBroughtToFrontCounter); Assert.AreEqual(0, activeDocumentViewChangingCounter); Assert.AreEqual(0, activeDocumentViewChangedCounter); Assert.AreEqual(0, activeViewChangedCounter); @@ -709,11 +715,12 @@ } [Test] - public void BringToFront_ActiveToolView_ActiveViewNotAffectedAndNoActiveViewEventsFired() + public void BringToFront_ActiveToolView_ViewBroughtToFrontFiredButActiveViewNotAffectedAndNoActiveViewEventsFired() { // Setup var testView1 = new TestView(); var testView2 = new TestView(); + var viewBroughtToFrontCounter = 0; var activeDocumentViewChangingCounter = 0; var activeDocumentViewChangedCounter = 0; var activeViewChangedCounter = 0; @@ -724,6 +731,7 @@ avalonDockViewHost.AddToolView(testView2, ToolViewLocation.Bottom); SetActiveView(avalonDockViewHost, testView1); + avalonDockViewHost.ViewBroughtToFront += (sender, args) => viewBroughtToFrontCounter++; avalonDockViewHost.ActiveDocumentViewChanging += (sender, args) => activeDocumentViewChangingCounter++; avalonDockViewHost.ActiveDocumentViewChanged += (sender, args) => activeDocumentViewChangedCounter++; avalonDockViewHost.ActiveViewChanged += (sender, args) => activeViewChangedCounter++; @@ -732,6 +740,7 @@ avalonDockViewHost.BringToFront(testView1); // Assert + Assert.AreEqual(1, viewBroughtToFrontCounter); Assert.AreEqual(0, activeDocumentViewChangingCounter); Assert.AreEqual(0, activeDocumentViewChangedCounter); Assert.AreEqual(0, activeViewChangedCounter); @@ -740,11 +749,12 @@ } [Test] - public void BringToFront_NonActiveToolView_ActiveViewNotAffectedAndNoActiveViewEventsFired() + public void BringToFront_NonActiveToolView_ViewBroughtToFrontFiredButActiveViewNotAffectedAndNoActiveViewEventsFired() { // Setup var testView1 = new TestView(); var testView2 = new TestView(); + var viewBroughtToFrontCounter = 0; var activeDocumentViewChangingCounter = 0; var activeDocumentViewChangedCounter = 0; var activeViewChangedCounter = 0; @@ -755,6 +765,7 @@ avalonDockViewHost.AddToolView(testView2, ToolViewLocation.Bottom); SetActiveView(avalonDockViewHost, testView2); + avalonDockViewHost.ViewBroughtToFront += (sender, args) => viewBroughtToFrontCounter++; avalonDockViewHost.ActiveDocumentViewChanging += (sender, args) => activeDocumentViewChangingCounter++; avalonDockViewHost.ActiveDocumentViewChanged += (sender, args) => activeDocumentViewChangedCounter++; avalonDockViewHost.ActiveViewChanged += (sender, args) => activeViewChangedCounter++; @@ -763,6 +774,7 @@ avalonDockViewHost.BringToFront(testView1); // Assert + Assert.AreEqual(1, viewBroughtToFrontCounter); Assert.AreEqual(0, activeDocumentViewChangingCounter); Assert.AreEqual(0, activeDocumentViewChangedCounter); Assert.AreEqual(0, activeViewChangedCounter); Index: Core/Plugins/src/Core.Plugins.Chart/ChartPlugin.cs =================================================================== diff -u -r75f679b341a9a7b82f35a623e6409ed28c74632f -ra999c7ca7999cc5e15b938120496d19364b26cc8 --- Core/Plugins/src/Core.Plugins.Chart/ChartPlugin.cs (.../ChartPlugin.cs) (revision 75f679b341a9a7b82f35a623e6409ed28c74632f) +++ Core/Plugins/src/Core.Plugins.Chart/ChartPlugin.cs (.../ChartPlugin.cs) (revision a999c7ca7999cc5e15b938120496d19364b26cc8) @@ -58,6 +58,7 @@ chartLegendController.ToggleView(); Gui.ViewHost.ViewOpened += OnViewOpened; + Gui.ViewHost.ViewBroughtToFront += OnViewBroughtToFront; Gui.ViewHost.ViewClosed += OnViewClosed; Gui.ViewHost.ActiveDocumentViewChanged += OnActiveDocumentViewChanged; activated = true; @@ -78,6 +79,7 @@ if (activated) { Gui.ViewHost.ViewOpened -= OnViewOpened; + Gui.ViewHost.ViewBroughtToFront -= OnViewBroughtToFront; Gui.ViewHost.ViewClosed -= OnViewClosed; Gui.ViewHost.ActiveDocumentViewChanged -= OnActiveDocumentViewChanged; } @@ -112,6 +114,16 @@ }; } + private void OnViewOpened(object sender, ViewChangeEventArgs e) + { + UpdateComponentsForView(e.View as IChartView); + } + + private void OnViewBroughtToFront(object sender, ViewChangeEventArgs e) + { + UpdateComponentsForView(e.View as IChartView); + } + private void OnViewClosed(object sender, ViewChangeEventArgs e) { if (ReferenceEquals(currentChartView, e.View)) @@ -120,11 +132,6 @@ } } - private void OnViewOpened(object sender, ViewChangeEventArgs e) - { - UpdateComponentsForView(e.View as IChartView); - } - private void OnActiveDocumentViewChanged(object sender, EventArgs e) { UpdateComponentsForActiveDocumentView(); @@ -137,10 +144,14 @@ private void UpdateComponentsForView(IChartView chartView) { + if (ReferenceEquals(currentChartView, chartView)) + { + return; + } + currentChartView = chartView; IChartControl chartControl = chartView?.Chart; - chartLegendController.Update(chartControl); chartingRibbon.Chart = chartControl; } Index: Core/Plugins/src/Core.Plugins.Chart/ChartingRibbon.xaml.cs =================================================================== diff -u -r93036b575ee81b4517b29db51f1eadf81454fb93 -ra999c7ca7999cc5e15b938120496d19364b26cc8 --- Core/Plugins/src/Core.Plugins.Chart/ChartingRibbon.xaml.cs (.../ChartingRibbon.xaml.cs) (revision 93036b575ee81b4517b29db51f1eadf81454fb93) +++ Core/Plugins/src/Core.Plugins.Chart/ChartingRibbon.xaml.cs (.../ChartingRibbon.xaml.cs) (revision a999c7ca7999cc5e15b938120496d19364b26cc8) @@ -40,6 +40,8 @@ public ChartingRibbon() { InitializeComponent(); + + HideChartingTab(); } /// Index: Core/Plugins/src/Core.Plugins.Map/MapPlugin.cs =================================================================== diff -u -r2c5e077a0f546af6d6379eb93111fd8366fc2224 -ra999c7ca7999cc5e15b938120496d19364b26cc8 --- Core/Plugins/src/Core.Plugins.Map/MapPlugin.cs (.../MapPlugin.cs) (revision 2c5e077a0f546af6d6379eb93111fd8366fc2224) +++ Core/Plugins/src/Core.Plugins.Map/MapPlugin.cs (.../MapPlugin.cs) (revision a999c7ca7999cc5e15b938120496d19364b26cc8) @@ -61,6 +61,7 @@ mapLegendController.ToggleView(); Gui.ViewHost.ViewOpened += OnViewOpened; + Gui.ViewHost.ViewBroughtToFront += OnViewBroughtToFront; Gui.ViewHost.ViewClosed += OnViewClosed; Gui.ViewHost.ActiveDocumentViewChanged += OnActiveDocumentViewChanged; activated = true; @@ -94,6 +95,7 @@ if (activated) { Gui.ViewHost.ViewOpened -= OnViewOpened; + Gui.ViewHost.ViewBroughtToFront -= OnViewBroughtToFront; Gui.ViewHost.ViewClosed -= OnViewClosed; Gui.ViewHost.ActiveDocumentViewChanged -= OnActiveDocumentViewChanged; } @@ -131,6 +133,11 @@ UpdateComponentsForView(view); } + private void OnViewBroughtToFront(object sender, ViewChangeEventArgs e) + { + UpdateComponentsForView(e.View as IMapView); + } + private void OnViewClosed(object sender, ViewChangeEventArgs e) { if (ReferenceEquals(currentMapView, e.View)) @@ -151,6 +158,11 @@ private void UpdateComponentsForView(IMapView mapView) { + if (ReferenceEquals(currentMapView, mapView)) + { + return; + } + currentMapView = mapView; IMapControl mapControl = mapView?.Map; Index: Core/Plugins/src/Core.Plugins.Map/MapRibbon.xaml.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -ra999c7ca7999cc5e15b938120496d19364b26cc8 --- Core/Plugins/src/Core.Plugins.Map/MapRibbon.xaml.cs (.../MapRibbon.xaml.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Plugins/src/Core.Plugins.Map/MapRibbon.xaml.cs (.../MapRibbon.xaml.cs) (revision a999c7ca7999cc5e15b938120496d19364b26cc8) @@ -40,6 +40,8 @@ public MapRibbon() { InitializeComponent(); + + HideMapTab(); } /// Index: Core/Plugins/test/Core.Plugins.Chart.Test/ChartPluginTest.cs =================================================================== diff -u -r2c5e077a0f546af6d6379eb93111fd8366fc2224 -ra999c7ca7999cc5e15b938120496d19364b26cc8 --- Core/Plugins/test/Core.Plugins.Chart.Test/ChartPluginTest.cs (.../ChartPluginTest.cs) (revision 2c5e077a0f546af6d6379eb93111fd8366fc2224) +++ Core/Plugins/test/Core.Plugins.Chart.Test/ChartPluginTest.cs (.../ChartPluginTest.cs) (revision a999c7ca7999cc5e15b938120496d19364b26cc8) @@ -33,7 +33,9 @@ using Core.Common.Gui.Plugin; using Core.Common.Gui.Settings; using Core.Common.Gui.TestUtil; +using Core.Common.Utils.Reflection; using Core.Components.Chart.Data; +using Core.Components.Chart.Forms; using Core.Components.OxyPlot.Forms; using Core.Plugins.Chart.Legend; using Core.Plugins.Chart.PropertyClasses; @@ -85,14 +87,15 @@ var viewHost = mocks.Stub(); gui.Stub(g => g.ViewHost).Return(viewHost); - viewHost.Expect(vm => vm.ToolViews).Return(new IView[0]); viewHost.Expect(vm => vm.AddToolView(Arg.Is.NotNull, Arg.Matches(vl => vl == ToolViewLocation.Left))); viewHost.Expect(vm => vm.SetImage(null, null)).IgnoreArguments(); viewHost.Expect(vm => vm.ActiveDocumentView).Return(null); viewHost.Expect(vm => vm.ActiveDocumentViewChanged += null).IgnoreArguments(); viewHost.Expect(vm => vm.ActiveDocumentViewChanged -= null).IgnoreArguments(); viewHost.Expect(vm => vm.ViewOpened += null).IgnoreArguments(); viewHost.Expect(vm => vm.ViewOpened -= null).IgnoreArguments(); + viewHost.Expect(vm => vm.ViewBroughtToFront += null).IgnoreArguments(); + viewHost.Expect(vm => vm.ViewBroughtToFront -= null).IgnoreArguments(); viewHost.Expect(vm => vm.ViewClosed += null).IgnoreArguments(); viewHost.Expect(vm => vm.ViewClosed -= null).IgnoreArguments(); @@ -111,44 +114,6 @@ } [Test] - [TestCase(true)] - [TestCase(false)] - [Apartment(ApartmentState.STA)] - public void GivenConfiguredGui_WhenActiveDocumentViewChangesToViewWithChart_ThenRibbonSetVisibility(bool visible) - { - // Given - var mocks = new MockRepository(); - var projectStore = mocks.Stub(); - var projectMigrator = mocks.Stub(); - var projectFactory = mocks.Stub(); - projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); - mocks.ReplayAll(); - - using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) - { - var plugin = new ChartPlugin(); - var testChartView = new TestChartView(); - var chart = new ChartControl(); - IView view = visible ? (IView) testChartView : new TestView(); - - testChartView.Data = chart; - - gui.Plugins.Add(plugin); - plugin.Gui = gui; - gui.Run(); - - // When - gui.ViewHost.AddDocumentView(view); - - // Then - Assert.AreEqual(visible ? Visibility.Visible : Visibility.Collapsed, plugin.RibbonCommandHandler.GetRibbonControl().ContextualGroups[0].Visibility); - mocks.VerifyAll(); - } - - Dispatcher.CurrentDispatcher.InvokeShutdown(); - } - - [Test] public void GetPropertyInfos_ReturnsSupportedPropertyInfos() { // Setup @@ -191,5 +156,238 @@ typeof(ChartPointDataProperties)); } } + + [Test] + [TestCase(true)] + [TestCase(false)] + [Apartment(ApartmentState.STA)] + public void GivenConfiguredGui_WhenActiveDocumentViewChangesToViewWithChart_ThenRibbonSetVisibility(bool visible) + { + // Given + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + var plugin = new ChartPlugin + { + Gui = gui + }; + + gui.Plugins.Add(plugin); + gui.Run(); + + var testChartView = new TestChartView + { + Data = new ChartControl() + }; + IView view = visible ? (IView) testChartView : new TestView(); + + // When + gui.ViewHost.AddDocumentView(view); + + // Then + Assert.AreEqual(visible ? Visibility.Visible : Visibility.Collapsed, plugin.RibbonCommandHandler.GetRibbonControl().ContextualGroups[0].Visibility); + } + + Dispatcher.CurrentDispatcher.InvokeShutdown(); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenConfiguredGui_WhenChartViewAdded_ThenComponentsUpdated() + { + // Given + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + var plugin = new ChartPlugin + { + Gui = gui + }; + + gui.Plugins.Add(plugin); + gui.Run(); + + var view = new TestChartView(); + IViewHost guiViewHost = gui.ViewHost; + ChartLegendView chartLegendView = guiViewHost.ToolViews.OfType().First(); + var chartingRibbon = (ChartingRibbon) plugin.RibbonCommandHandler; + + // Precondition + Assert.IsNull(GetChartControl(chartLegendView)); + Assert.IsNull(GetChartControl(chartingRibbon)); + + // When + guiViewHost.AddDocumentView(view); + + // Then + Assert.AreSame(view.Chart, GetChartControl(chartLegendView)); + Assert.AreSame(view.Chart, GetChartControl(chartingRibbon)); + } + + Dispatcher.CurrentDispatcher.InvokeShutdown(); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenConfiguredGui_WhenChartViewBroughtToFront_ThenComponentsUpdated() + { + // Given + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + var plugin = new ChartPlugin + { + Gui = gui + }; + + gui.Plugins.Add(plugin); + gui.Run(); + + var view1 = new TestChartView(); + var view2 = new TestChartView(); + IViewHost guiViewHost = gui.ViewHost; + ChartLegendView chartLegendView = guiViewHost.ToolViews.OfType().First(); + var chartingRibbon = (ChartingRibbon) plugin.RibbonCommandHandler; + + guiViewHost.AddDocumentView(view1); + guiViewHost.AddDocumentView(view2); + + // Precondition + Assert.AreSame(view2.Chart, GetChartControl(chartLegendView)); + Assert.AreSame(view2.Chart, GetChartControl(chartingRibbon)); + + // When + guiViewHost.BringToFront(view1); + + // Then + Assert.AreSame(view1.Chart, GetChartControl(chartLegendView)); + Assert.AreSame(view1.Chart, GetChartControl(chartingRibbon)); + } + + Dispatcher.CurrentDispatcher.InvokeShutdown(); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenConfiguredGui_WhenChartViewRemoved_ThenComponentsUpdated() + { + // Given + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + var plugin = new ChartPlugin + { + Gui = gui + }; + + gui.Plugins.Add(plugin); + gui.Run(); + + var view = new TestChartView(); + IViewHost guiViewHost = gui.ViewHost; + ChartLegendView chartLegendView = guiViewHost.ToolViews.OfType().First(); + var chartingRibbon = (ChartingRibbon) plugin.RibbonCommandHandler; + + guiViewHost.AddDocumentView(view); + + // Precondition + Assert.AreSame(view.Chart, GetChartControl(chartLegendView)); + Assert.AreSame(view.Chart, GetChartControl(chartingRibbon)); + + // When + guiViewHost.Remove(view); + + // Then + Assert.IsNull(GetChartControl(chartLegendView)); + Assert.IsNull(GetChartControl(chartingRibbon)); + } + + Dispatcher.CurrentDispatcher.InvokeShutdown(); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenConfiguredGui_WhenOtherChartViewRemoved_ThenComponentsNotUpdated() + { + // Given + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + var plugin = new ChartPlugin + { + Gui = gui + }; + + gui.Plugins.Add(plugin); + gui.Run(); + + var view1 = new TestChartView(); + var view2 = new TestChartView(); + IViewHost guiViewHost = gui.ViewHost; + ChartLegendView chartLegendView = guiViewHost.ToolViews.OfType().First(); + var chartingRibbon = (ChartingRibbon) plugin.RibbonCommandHandler; + + guiViewHost.AddDocumentView(view1); + guiViewHost.AddDocumentView(view2); + + // Precondition + Assert.AreSame(view2.Chart, GetChartControl(chartLegendView)); + Assert.AreSame(view2.Chart, GetChartControl(chartingRibbon)); + + // When + guiViewHost.Remove(view1); + + // Then + Assert.AreSame(view2.Chart, GetChartControl(chartLegendView)); + Assert.AreSame(view2.Chart, GetChartControl(chartingRibbon)); + } + + Dispatcher.CurrentDispatcher.InvokeShutdown(); + mocks.VerifyAll(); + } + + private static IChartControl GetChartControl(ChartingRibbon chartRibbon) + { + return TypeUtils.GetProperty(chartRibbon, "Chart"); + } + + private static IChartControl GetChartControl(ChartLegendView chartLegendView) + { + return TypeUtils.GetProperty(chartLegendView, "ChartControl"); + } } } \ No newline at end of file Index: Core/Plugins/test/Core.Plugins.Chart.Test/ChartingRibbonTest.cs =================================================================== diff -u -r93036b575ee81b4517b29db51f1eadf81454fb93 -ra999c7ca7999cc5e15b938120496d19364b26cc8 --- Core/Plugins/test/Core.Plugins.Chart.Test/ChartingRibbonTest.cs (.../ChartingRibbonTest.cs) (revision 93036b575ee81b4517b29db51f1eadf81454fb93) +++ Core/Plugins/test/Core.Plugins.Chart.Test/ChartingRibbonTest.cs (.../ChartingRibbonTest.cs) (revision a999c7ca7999cc5e15b938120496d19364b26cc8) @@ -38,13 +38,18 @@ { [Test] [Apartment(ApartmentState.STA)] - public void DefaultConstructor_Always_CreatesControl() + public void DefaultConstructor_Always_CreatesControlWithContextualGroupCollapsed() { - // Setup + // Call var ribbon = new ChartingRibbon(); - // Call & Assert - Assert.IsInstanceOf(ribbon.GetRibbonControl()); + // Assert + Ribbon ribbonControl = ribbon.GetRibbonControl(); + Assert.IsInstanceOf(ribbonControl); + + var contextualGroup = ribbonControl.FindName("ChartingContextualGroup") as RibbonContextualTabGroup; + Assert.IsNotNull(contextualGroup); + Assert.AreEqual(Visibility.Collapsed, contextualGroup.Visibility); } [Test] Index: Core/Plugins/test/Core.Plugins.Map.Test/MapPluginTest.cs =================================================================== diff -u -r75f679b341a9a7b82f35a623e6409ed28c74632f -ra999c7ca7999cc5e15b938120496d19364b26cc8 --- Core/Plugins/test/Core.Plugins.Map.Test/MapPluginTest.cs (.../MapPluginTest.cs) (revision 75f679b341a9a7b82f35a623e6409ed28c74632f) +++ Core/Plugins/test/Core.Plugins.Map.Test/MapPluginTest.cs (.../MapPluginTest.cs) (revision a999c7ca7999cc5e15b938120496d19364b26cc8) @@ -33,8 +33,10 @@ using Core.Common.Gui.Plugin; using Core.Common.Gui.Settings; using Core.Common.Gui.TestUtil; +using Core.Common.Utils.Reflection; using Core.Components.DotSpatial.Forms; using Core.Components.Gis.Data; +using Core.Components.Gis.Forms; using Core.Plugins.Map.Legend; using Core.Plugins.Map.PropertyClasses; using DotSpatial.Data; @@ -87,14 +89,15 @@ var viewHost = mocks.Stub(); gui.Stub(g => g.ViewHost).Return(viewHost); - viewHost.Expect(vm => vm.ToolViews).Return(new IView[0]); viewHost.Expect(vm => vm.AddToolView(Arg.Is.NotNull, Arg.Matches(vl => vl == ToolViewLocation.Left))); viewHost.Expect(vm => vm.SetImage(null, null)).IgnoreArguments(); viewHost.Expect(vm => vm.ActiveDocumentView).Return(null); viewHost.Expect(vm => vm.ActiveDocumentViewChanged += null).IgnoreArguments(); viewHost.Expect(vm => vm.ActiveDocumentViewChanged -= null).IgnoreArguments(); viewHost.Expect(vm => vm.ViewOpened += null).IgnoreArguments(); viewHost.Expect(vm => vm.ViewOpened -= null).IgnoreArguments(); + viewHost.Expect(vm => vm.ViewBroughtToFront += null).IgnoreArguments(); + viewHost.Expect(vm => vm.ViewBroughtToFront -= null).IgnoreArguments(); viewHost.Expect(vm => vm.ViewClosed += null).IgnoreArguments(); viewHost.Expect(vm => vm.ViewClosed -= null).IgnoreArguments(); viewHost.Expect(vm => vm.Remove(Arg.Is.NotNull)); @@ -178,23 +181,25 @@ using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { - var plugin = new MapPlugin(); + var plugin = new MapPlugin + { + Gui = gui + }; - IView view = visible ? (IView) new TestMapView() : new TestView(); - gui.Plugins.Add(plugin); - plugin.Gui = gui; gui.Run(); + IView view = visible ? (IView) new TestMapView() : new TestView(); + // When gui.ViewHost.AddDocumentView(view); // Then Assert.AreEqual(visible ? Visibility.Visible : Visibility.Collapsed, plugin.RibbonCommandHandler.GetRibbonControl().ContextualGroups[0].Visibility); - mocks.VerifyAll(); } Dispatcher.CurrentDispatcher.InvokeShutdown(); + mocks.VerifyAll(); } [Test] @@ -211,13 +216,14 @@ using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { - var plugin = new MapPlugin(); - var testMapView = new TestMapView(); + gui.Plugins.Add(new MapPlugin + { + Gui = gui + }); - gui.Plugins.Add(plugin); - plugin.Gui = gui; gui.Run(); + var testMapView = new TestMapView(); var map = (DotSpatialMap) ((MapControl) testMapView.Map).Controls[0]; // Precondition @@ -228,10 +234,202 @@ // Then Assert.AreNotEqual(initialExtents, map.ViewExtents); - mocks.VerifyAll(); } Dispatcher.CurrentDispatcher.InvokeShutdown(); + mocks.VerifyAll(); } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenConfiguredGui_WhenMapViewAdded_ThenComponentsUpdated() + { + // Given + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + var plugin = new MapPlugin + { + Gui = gui + }; + + gui.Plugins.Add(plugin); + gui.Run(); + + var view = new TestMapView(); + IViewHost guiViewHost = gui.ViewHost; + MapLegendView mapLegendView = guiViewHost.ToolViews.OfType().First(); + var mapRibbon = (MapRibbon) plugin.RibbonCommandHandler; + + // Precondition + Assert.IsNull(GetMapControl(mapLegendView)); + Assert.IsNull(GetMapControl(mapRibbon)); + + // When + guiViewHost.AddDocumentView(view); + + // Then + Assert.AreSame(view.Map, GetMapControl(mapLegendView)); + Assert.AreSame(view.Map, GetMapControl(mapRibbon)); + } + + Dispatcher.CurrentDispatcher.InvokeShutdown(); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenConfiguredGui_WhenMapViewBroughtToFront_ThenComponentsUpdated() + { + // Given + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + var plugin = new MapPlugin + { + Gui = gui + }; + + gui.Plugins.Add(plugin); + gui.Run(); + + var view1 = new TestMapView(); + var view2 = new TestMapView(); + IViewHost guiViewHost = gui.ViewHost; + MapLegendView mapLegendView = guiViewHost.ToolViews.OfType().First(); + var mapRibbon = (MapRibbon) plugin.RibbonCommandHandler; + + guiViewHost.AddDocumentView(view1); + guiViewHost.AddDocumentView(view2); + + // Precondition + Assert.AreSame(view2.Map, GetMapControl(mapLegendView)); + Assert.AreSame(view2.Map, GetMapControl(mapRibbon)); + + // When + guiViewHost.BringToFront(view1); + + // Then + Assert.AreSame(view1.Map, GetMapControl(mapLegendView)); + Assert.AreSame(view1.Map, GetMapControl(mapRibbon)); + } + + Dispatcher.CurrentDispatcher.InvokeShutdown(); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenConfiguredGui_WhenMapViewRemoved_ThenComponentsUpdated() + { + // Given + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + var plugin = new MapPlugin + { + Gui = gui + }; + + gui.Plugins.Add(plugin); + gui.Run(); + + var view = new TestMapView(); + IViewHost guiViewHost = gui.ViewHost; + MapLegendView mapLegendView = guiViewHost.ToolViews.OfType().First(); + var mapRibbon = (MapRibbon) plugin.RibbonCommandHandler; + + guiViewHost.AddDocumentView(view); + + // Precondition + Assert.AreSame(view.Map, GetMapControl(mapLegendView)); + Assert.AreSame(view.Map, GetMapControl(mapRibbon)); + + // When + guiViewHost.Remove(view); + + // Then + Assert.IsNull(GetMapControl(mapLegendView)); + Assert.IsNull(GetMapControl(mapRibbon)); + } + + Dispatcher.CurrentDispatcher.InvokeShutdown(); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenConfiguredGui_WhenOtherMapViewRemoved_ThenComponentsNotUpdated() + { + // Given + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); + projectFactory.Stub(pf => pf.CreateNewProject()).Return(mocks.Stub()); + mocks.ReplayAll(); + + using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) + { + var plugin = new MapPlugin + { + Gui = gui + }; + + gui.Plugins.Add(plugin); + gui.Run(); + + var view1 = new TestMapView(); + var view2 = new TestMapView(); + IViewHost guiViewHost = gui.ViewHost; + MapLegendView mapLegendView = guiViewHost.ToolViews.OfType().First(); + var mapRibbon = (MapRibbon) plugin.RibbonCommandHandler; + + guiViewHost.AddDocumentView(view1); + guiViewHost.AddDocumentView(view2); + + // Precondition + Assert.AreSame(view2.Map, GetMapControl(mapLegendView)); + Assert.AreSame(view2.Map, GetMapControl(mapRibbon)); + + // When + guiViewHost.Remove(view1); + + // Then + Assert.AreSame(view2.Map, GetMapControl(mapLegendView)); + Assert.AreSame(view2.Map, GetMapControl(mapRibbon)); + } + + Dispatcher.CurrentDispatcher.InvokeShutdown(); + mocks.VerifyAll(); + } + + private static IMapControl GetMapControl(MapRibbon mapRibbon) + { + return TypeUtils.GetProperty(mapRibbon, "Map"); + } + + private static IMapControl GetMapControl(MapLegendView mapLegendView) + { + return TypeUtils.GetProperty(mapLegendView, "MapControl"); + } } } \ No newline at end of file Index: Core/Plugins/test/Core.Plugins.Map.Test/MapRibbonTest.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -ra999c7ca7999cc5e15b938120496d19364b26cc8 --- Core/Plugins/test/Core.Plugins.Map.Test/MapRibbonTest.cs (.../MapRibbonTest.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Plugins/test/Core.Plugins.Map.Test/MapRibbonTest.cs (.../MapRibbonTest.cs) (revision a999c7ca7999cc5e15b938120496d19364b26cc8) @@ -38,13 +38,18 @@ { [Test] [Apartment(ApartmentState.STA)] - public void DefaultContstructor_Always_CreatesControl() + public void DefaultConstructor_Always_CreatesControlWithContextualGroupCollapsed() { - // Setup + // Call var ribbon = new MapRibbon(); - // Call & Assert - Assert.IsInstanceOf(ribbon.GetRibbonControl()); + // Assert + Ribbon ribbonControl = ribbon.GetRibbonControl(); + Assert.IsInstanceOf(ribbonControl); + + var contextualGroup = ribbonControl.FindName("MapContextualGroup") as RibbonContextualTabGroup; + Assert.IsNotNull(contextualGroup); + Assert.AreEqual(Visibility.Collapsed, contextualGroup.Visibility); } [Test]