Index: Core/Common/src/Core.Common.Gui/Forms/MainWindow/MainWindow.xaml.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rfbf0127601ef799db5ec78430746c6aa23eab218 --- Core/Common/src/Core.Common.Gui/Forms/MainWindow/MainWindow.xaml.cs (.../MainWindow.xaml.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Common/src/Core.Common.Gui/Forms/MainWindow/MainWindow.xaml.cs (.../MainWindow.xaml.cs) (revision fbf0127601ef799db5ec78430746c6aa23eab218) @@ -306,7 +306,7 @@ } else { - viewController.ViewHost.SetFocusToView(propertyGrid); + viewController.ViewHost.BringToFront(propertyGrid); } } @@ -410,7 +410,7 @@ } else { - viewController.ViewHost.SetFocusToView(messageWindow); + viewController.ViewHost.BringToFront(messageWindow); } } Index: Core/Common/src/Core.Common.Gui/Forms/ViewHost/AvalonDockViewHost.xaml.cs =================================================================== diff -u -r75f679b341a9a7b82f35a623e6409ed28c74632f -rfbf0127601ef799db5ec78430746c6aa23eab218 --- Core/Common/src/Core.Common.Gui/Forms/ViewHost/AvalonDockViewHost.xaml.cs (.../AvalonDockViewHost.xaml.cs) (revision 75f679b341a9a7b82f35a623e6409ed28c74632f) +++ Core/Common/src/Core.Common.Gui/Forms/ViewHost/AvalonDockViewHost.xaml.cs (.../AvalonDockViewHost.xaml.cs) (revision fbf0127601ef799db5ec78430746c6aa23eab218) @@ -42,7 +42,7 @@ private readonly List documentViews; private readonly List hostControls; - private IView focussedView; + private IView activeView; private IView activeDocumentView; private bool removingProgrammatically; @@ -114,11 +114,10 @@ return; } - // If the view was already added, just focus it + // If the view was already added, just bring it to front if (documentViews.Contains(view) || toolViews.Contains(view)) { - PerformWithoutChangingActiveContent(() => { SetFocusToView(view); }); - + BringToFront(view); return; } @@ -132,16 +131,15 @@ Content = hostControl }; - documentViews.Add(view); - hostControls.Add(hostControl); - PerformWithoutChangingActiveContent(() => { AddLayoutDocument(layoutDocument); - SetFocusToView(view); + layoutDocument.IsActive = true; }); - layoutDocument.Closing += OnLayoutDocumentClosing; + documentViews.Add(view); + hostControls.Add(hostControl); + layoutDocument.Closed += OnLayoutDocumentClosed; OnViewOpenedEvent(view); @@ -155,11 +153,10 @@ return; } - // If the view was already added, just focus it + // If the view was already added, just bring it to front if (documentViews.Contains(view) || toolViews.Contains(view)) { - PerformWithoutChangingActiveContent(() => { SetFocusToView(view); }); - + BringToFront(view); return; } @@ -176,13 +173,12 @@ PerformWithoutChangingActiveContent(() => { AddLayoutAnchorable(layoutAnchorable, toolViewLocation); - - toolViews.Add(view); - hostControls.Add(hostControl); - - SetFocusToView(view); + layoutAnchorable.IsActive = true; }); + toolViews.Add(view); + hostControls.Add(hostControl); + layoutAnchorable.Hiding += OnLayoutAnchorableHiding; layoutAnchorable.Closing += OnLayoutAnchorableClosing; @@ -195,14 +191,6 @@ if (documentViews.Contains(view)) { - if (ActiveDocumentView == view) - { - // Note: When removing the active document view programmatically, always set focus to this - // view in order to make the view host behave as expected (in this case AvalonDock will help - // us selecting the previous active document view based on active content changes). - SetFocusToView(view); - } - var layoutDocument = GetLayoutContent(view); layoutDocument.Close(); UpdateDockingManager(); @@ -217,26 +205,23 @@ removingProgrammatically = false; } - public void SetFocusToView(IView view) + public void BringToFront(IView view) { - if (documentViews.Contains(view)) + PerformWithoutChangingActiveContent(() => { - var layoutDocument = GetLayoutContent(view); - if (!layoutDocument.IsActive) + LayoutContent layoutContent = documentViews.Contains(view) + ? (LayoutContent) GetLayoutContent(view) + : toolViews.Contains(view) + ? GetLayoutContent(view) + : null; + + if (layoutContent != null && !layoutContent.IsActive) { - DockingManager.Layout.ActiveContent = layoutDocument; + layoutContent.IsActive = true; } - } - else if (toolViews.Contains(view)) - { - var layoutAnchorable = GetLayoutContent(view); - if (!layoutAnchorable.IsActive) - { - DockingManager.Layout.ActiveContent = layoutAnchorable; - } - } - UpdateDockingManager(); + UpdateDockingManager(); + }); } public void SetImage(IView view, Image image) @@ -258,24 +243,15 @@ private void OnLostFocus(object sender, RoutedEventArgs routedEventArgs) { - var userControl = focussedView as UserControl; + var userControl = activeView as UserControl; if (userControl != null) { // Note: Raise (un)focus related events manually as changing focus from one WindowsFormsHost to another does not raise them // (see https://msdn.microsoft.com/en-us/library/ms751797(v=vs.100).aspx#Windows_Presentation_Foundation_Application_Hosting). // While doing so: // - prevent unfocus actions when removing views programmatically (not necessary and might interfere with AvalonDock's active content change behavior); // - prevent circular active content changes (which explains the code structure below). - DockingManager.ActiveContentChanged -= OnActiveContentChanged; - object activeContent = DockingManager.ActiveContent; - - userControl.ValidateChildren(); - - if (!ReferenceEquals(activeContent, DockingManager.ActiveContent)) - { - DockingManager.ActiveContent = activeContent; - } - DockingManager.ActiveContentChanged += OnActiveContentChanged; + PerformWithoutChangingActiveContent(() => userControl.ValidateChildren()); } } @@ -311,51 +287,29 @@ // While doing so: // - prevent unfocus actions when removing views programmatically (not necessary and might interfere with AvalonDock's active content change behavior); // - prevent circular active content changes (which explains the code structure below). - if (focussedView != null && !removingProgrammatically) + if (activeView != null && !removingProgrammatically) { - DockingManager.ActiveContentChanged -= OnActiveContentChanged; - object activeContent = DockingManager.ActiveContent; - NativeMethods.UnfocusActiveControl(focussedView as IContainerControl); - DockingManager.ActiveContent = activeContent; - DockingManager.ActiveContentChanged += OnActiveContentChanged; + PerformWithoutChangingActiveContent(() => NativeMethods.UnfocusActiveControl(activeView as IContainerControl)); } - focussedView = GetView(DockingManager.ActiveContent); + activeView = GetView(DockingManager.ActiveContent); - if (documentViews.Contains(focussedView)) + if (documentViews.Contains(activeView)) { - ActiveDocumentView = focussedView; - OnActiveViewChangedEvent(); + ActiveDocumentView = activeView; } - else if (toolViews.Contains(focussedView)) - { - OnActiveViewChangedEvent(); - } else if (DockingManager.ActiveContent == null) { ActiveDocumentView = null; } - } - private void OnLayoutDocumentClosing(object sender, CancelEventArgs e) - { - var layoutDocument = (LayoutDocument) sender; - IView view = GetView(layoutDocument.Content); - - if (ActiveDocumentView == view) - { - // Note: When removing the active document view via AvalonDock, always set focus to this - // view in order to make the view host behave as expected (in this case AvalonDock will help - // us selecting the previous active document view based on active content changes). - SetFocusToView(view); - } + OnActiveViewChangedEvent(); } private void OnLayoutDocumentClosed(object sender, EventArgs e) { var layoutDocument = (LayoutDocument) sender; - layoutDocument.Closing -= OnLayoutDocumentClosing; layoutDocument.Closed -= OnLayoutDocumentClosed; OnViewClosed(GetView(layoutDocument.Content)); Index: Core/Common/src/Core.Common.Gui/Forms/ViewHost/DocumentViewController.cs =================================================================== diff -u -rcbf0d02e860c096fd24d07fb4655e59206929827 -rfbf0127601ef799db5ec78430746c6aa23eab218 --- Core/Common/src/Core.Common.Gui/Forms/ViewHost/DocumentViewController.cs (.../DocumentViewController.cs) (revision cbf0d02e860c096fd24d07fb4655e59206929827) +++ Core/Common/src/Core.Common.Gui/Forms/ViewHost/DocumentViewController.cs (.../DocumentViewController.cs) (revision fbf0127601ef799db5ec78430746c6aa23eab218) @@ -159,7 +159,7 @@ if (view != null) { - viewHost.SetFocusToView(view); + viewHost.BringToFront(view); return; } Index: Core/Common/src/Core.Common.Gui/Forms/ViewHost/IViewHost.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rfbf0127601ef799db5ec78430746c6aa23eab218 --- Core/Common/src/Core.Common.Gui/Forms/ViewHost/IViewHost.cs (.../IViewHost.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Common/src/Core.Common.Gui/Forms/ViewHost/IViewHost.cs (.../IViewHost.cs) (revision fbf0127601ef799db5ec78430746c6aa23eab218) @@ -92,10 +92,10 @@ void Remove(IView view); /// - /// Sets focus to a document view or tool view and makes it visible. + /// Brings a document view or tool view to the front. /// - /// The view to set focus to. - void SetFocusToView(IView view); + /// The view to bring to front. + void BringToFront(IView view); /// /// Sets the image for a document view or tool view. Index: Core/Common/src/Core.Common.Gui/GuiCore.cs =================================================================== diff -u -r67e77262b9f0f183db81f8c95d7b12aa5fcdb8e9 -rfbf0127601ef799db5ec78430746c6aa23eab218 --- Core/Common/src/Core.Common.Gui/GuiCore.cs (.../GuiCore.cs) (revision 67e77262b9f0f183db81f8c95d7b12aa5fcdb8e9) +++ Core/Common/src/Core.Common.Gui/GuiCore.cs (.../GuiCore.cs) (revision fbf0127601ef799db5ec78430746c6aa23eab218) @@ -433,20 +433,20 @@ { mainWindow.Loaded += delegate { - // make sure these windows come on top + // Make sure these windows come on top if (ViewHost.ToolViews.Contains(mainWindow.PropertyGrid)) { - ViewHost.SetFocusToView(mainWindow.PropertyGrid); + ViewHost.BringToFront(mainWindow.PropertyGrid); } if (ViewHost.ToolViews.Contains(mainWindow.MessageWindow)) { - ViewHost.SetFocusToView(mainWindow.MessageWindow); + ViewHost.BringToFront(mainWindow.MessageWindow); } if (ViewHost.ToolViews.Contains(ProjectExplorer)) { - ViewHost.SetFocusToView(ProjectExplorer); + ViewHost.BringToFront(ProjectExplorer); } mainWindow.ValidateItems(); Index: Core/Common/test/Core.Common.Gui.Test/Forms/ViewHost/AvalonDockViewHostTest.cs =================================================================== diff -u -r75f679b341a9a7b82f35a623e6409ed28c74632f -rfbf0127601ef799db5ec78430746c6aa23eab218 --- Core/Common/test/Core.Common.Gui.Test/Forms/ViewHost/AvalonDockViewHostTest.cs (.../AvalonDockViewHostTest.cs) (revision 75f679b341a9a7b82f35a623e6409ed28c74632f) +++ Core/Common/test/Core.Common.Gui.Test/Forms/ViewHost/AvalonDockViewHostTest.cs (.../AvalonDockViewHostTest.cs) (revision fbf0127601ef799db5ec78430746c6aa23eab218) @@ -34,7 +34,6 @@ using Core.Common.Utils.Reflection; using NUnit.Framework; using Rhino.Mocks; -using Xceed.Wpf.AvalonDock; using Xceed.Wpf.AvalonDock.Layout; namespace Core.Common.Gui.Test.Forms.ViewHost @@ -54,12 +53,12 @@ CollectionAssert.IsEmpty(avalonDockViewHost.DocumentViews); CollectionAssert.IsEmpty(avalonDockViewHost.ToolViews); Assert.IsNull(avalonDockViewHost.ActiveDocumentView); - Assert.IsFalse(IsAnyViewFocussed(avalonDockViewHost)); + Assert.IsFalse(IsAnyViewActive(avalonDockViewHost)); } } [Test] - public void Dispose_ViewHostWithMultipleViews_ViewsClearedActiveDocumentViewSetToNullAndActiveDocumentEventsFired() + public void Dispose_ViewHostWithMultipleViews_ViewsClearedActiveDocumentViewSetToNullAndActiveViewEventsFired() { // Setup var testView1 = new TestView(); @@ -68,13 +67,17 @@ var testView4 = new TestView(); var activeDocumentViewChangingCounter = 0; var activeDocumentViewChangedCounter = 0; + var activeViewChangedCounter = 0; + var avalonDockViewHost = new AvalonDockViewHost(); avalonDockViewHost.AddDocumentView(testView1); avalonDockViewHost.AddDocumentView(testView2); avalonDockViewHost.AddToolView(testView3, ToolViewLocation.Left); avalonDockViewHost.AddToolView(testView4, ToolViewLocation.Left); + SetActiveView(avalonDockViewHost, testView1); + CollectionAssert.AreEqual( new[] { @@ -83,14 +86,21 @@ }, avalonDockViewHost.ToolViews); + avalonDockViewHost.ActiveDocumentViewChanging += (sender, args) => { activeDocumentViewChangingCounter++; }; + avalonDockViewHost.ActiveDocumentViewChanged += (sender, args) => { activeDocumentViewChangedCounter++; }; + avalonDockViewHost.ActiveViewChanged += (sender, args) => { activeViewChangedCounter++; }; + // Call avalonDockViewHost.Dispose(); // Assert CollectionAssert.IsEmpty(avalonDockViewHost.DocumentViews); CollectionAssert.IsEmpty(avalonDockViewHost.ToolViews); + Assert.AreNotEqual(0, activeDocumentViewChangingCounter); + Assert.AreNotEqual(0, activeDocumentViewChangedCounter); + Assert.AreNotEqual(0, activeViewChangedCounter); Assert.IsNull(avalonDockViewHost.ActiveDocumentView); - Assert.IsFalse(IsAnyViewFocussed(avalonDockViewHost)); + Assert.IsFalse(IsAnyViewActive(avalonDockViewHost)); } [Test] @@ -119,7 +129,7 @@ using (var avalonDockViewHost = new AvalonDockViewHost()) { avalonDockViewHost.AddDocumentView(testView); - avalonDockViewHost.SetFocusToView(testView); + SetActiveView(avalonDockViewHost, testView); // When avalonDockViewHost.RaiseEvent(new RoutedEventArgs(UIElement.LostFocusEvent)); @@ -299,36 +309,42 @@ } [Test] - public void Remove_ActiveDocumentViewInViewHostWithNoOtherDocumentViews_ActiveDocumentViewSetToNullAndActiveDocumentEventsFired() + public void Remove_ActiveDocumentViewInViewHostWithNoOtherDocumentViews_ActiveDocumentViewSetToNullAndActiveViewEventsFired() { // Setup var testView1 = new TestView(); var testView2 = new TestView(); var activeDocumentViewChangingCounter = 0; var activeDocumentViewChangedCounter = 0; + var activeViewChangedCounter = 0; using (var avalonDockViewHost = new AvalonDockViewHost()) { avalonDockViewHost.AddDocumentView(testView1); avalonDockViewHost.AddToolView(testView2, ToolViewLocation.Left); - avalonDockViewHost.SetFocusToView(testView1); + SetActiveView(avalonDockViewHost, testView1); - avalonDockViewHost.ActiveDocumentViewChanging += (sender, args) => { activeDocumentViewChangingCounter++; }; + avalonDockViewHost.ActiveDocumentViewChanging += (sender, args) => + { + activeDocumentViewChangingCounter++; + }; avalonDockViewHost.ActiveDocumentViewChanged += (sender, args) => { activeDocumentViewChangedCounter++; }; + avalonDockViewHost.ActiveViewChanged += (sender, args) => { activeViewChangedCounter++; }; // Call avalonDockViewHost.Remove(testView1); // Assert Assert.AreEqual(1, activeDocumentViewChangingCounter); Assert.AreEqual(1, activeDocumentViewChangedCounter); + Assert.AreEqual(1, activeViewChangedCounter); Assert.IsNull(avalonDockViewHost.ActiveDocumentView); - Assert.IsFalse(IsAnyViewFocussed(avalonDockViewHost)); + Assert.IsFalse(IsAnyViewActive(avalonDockViewHost)); } } [Test] - public void Remove_ActiveDocumentViewInViewHostWithMultipleOtherViews_ActiveDocumentViewSetToOtherViewAndActiveDocumentEventsFired() + public void Remove_ActiveDocumentViewInViewHostWithMultipleOtherViews_ActiveDocumentViewSetToOtherViewAndActiveViewEventsFired() { // Setup var testView1 = new TestView(); @@ -338,6 +354,7 @@ var testView5 = new TestView(); var activeDocumentViewChangingCounter = 0; var activeDocumentViewChangedCounter = 0; + var activeViewChangedCounter = 0; using (var avalonDockViewHost = new AvalonDockViewHost()) { @@ -347,29 +364,31 @@ avalonDockViewHost.AddDocumentView(testView4); avalonDockViewHost.AddToolView(testView5, ToolViewLocation.Left); - avalonDockViewHost.SetFocusToView(testView1); + SetActiveView(avalonDockViewHost, testView1); // Precondition Assert.AreSame(testView1, avalonDockViewHost.ActiveDocumentView); - Assert.IsTrue(IsFocussedView(avalonDockViewHost, testView1)); + Assert.IsTrue(IsActiveView(avalonDockViewHost, testView1)); avalonDockViewHost.ActiveDocumentViewChanging += (sender, args) => { activeDocumentViewChangingCounter++; }; avalonDockViewHost.ActiveDocumentViewChanged += (sender, args) => { activeDocumentViewChangedCounter++; }; + avalonDockViewHost.ActiveViewChanged += (sender, args) => { activeViewChangedCounter++; }; // Call avalonDockViewHost.Remove(testView1); // Assert Assert.AreEqual(1, activeDocumentViewChangingCounter); Assert.AreEqual(1, activeDocumentViewChangedCounter); + Assert.AreEqual(1, activeViewChangedCounter); Assert.IsNotNull(avalonDockViewHost.ActiveDocumentView); Assert.AreNotSame(testView1, avalonDockViewHost.ActiveDocumentView); - Assert.IsTrue(IsFocussedView(avalonDockViewHost, avalonDockViewHost.ActiveDocumentView)); + Assert.IsTrue(IsActiveView(avalonDockViewHost, avalonDockViewHost.ActiveDocumentView)); } } [Test] - public void Remove_NotActiveDocumentViewInViewHostWithMultipleOtherViews_ActiveDocumentViewNotAffectedAndNoActiveDocumentEventsFired() + public void Remove_NotActiveDocumentViewInViewHostWithMultipleOtherViews_ActiveDocumentViewNotAffectedAndNoActiveViewEventsFired() { // Setup var testView1 = new TestView(); @@ -379,6 +398,7 @@ var testView5 = new TestView(); var activeDocumentViewChangingCounter = 0; var activeDocumentViewChangedCounter = 0; + var activeViewChangedCounter = 0; using (var avalonDockViewHost = new AvalonDockViewHost()) { @@ -388,79 +408,89 @@ avalonDockViewHost.AddDocumentView(testView4); avalonDockViewHost.AddToolView(testView5, ToolViewLocation.Left); - avalonDockViewHost.SetFocusToView(testView3); + SetActiveView(avalonDockViewHost, testView3); // Precondition Assert.AreSame(testView3, avalonDockViewHost.ActiveDocumentView); - Assert.IsTrue(IsFocussedView(avalonDockViewHost, testView3)); + Assert.IsTrue(IsActiveView(avalonDockViewHost, testView3)); avalonDockViewHost.ActiveDocumentViewChanging += (sender, args) => { activeDocumentViewChangingCounter++; }; avalonDockViewHost.ActiveDocumentViewChanged += (sender, args) => { activeDocumentViewChangedCounter++; }; + avalonDockViewHost.ActiveViewChanged += (sender, args) => { activeViewChangedCounter++; }; // Call avalonDockViewHost.Remove(testView1); // Assert Assert.AreEqual(0, activeDocumentViewChangingCounter); Assert.AreEqual(0, activeDocumentViewChangedCounter); + Assert.AreEqual(0, activeViewChangedCounter); Assert.AreSame(testView3, avalonDockViewHost.ActiveDocumentView); - Assert.IsTrue(IsFocussedView(avalonDockViewHost, testView3)); + Assert.IsTrue(IsActiveView(avalonDockViewHost, testView3)); } } [Test] - public void SetFocusToView_ActiveDocumentView_ActiveDocumentViewNotAffectedAndNoActiveDocumentEventsFired() + public void BringToFront_ActiveDocumentView_ActiveViewNotAffectedAndNoActiveViewEventsFired() { // Setup - var testView = new TestView(); + var testView1 = new TestView(); + var testView2 = new TestView(); var activeDocumentViewChangingCounter = 0; var activeDocumentViewChangedCounter = 0; + var activeViewChangedCounter = 0; using (var avalonDockViewHost = new AvalonDockViewHost()) { - avalonDockViewHost.AddDocumentView(testView); - avalonDockViewHost.SetFocusToView(testView); + avalonDockViewHost.AddDocumentView(testView1); + avalonDockViewHost.AddDocumentView(testView2); + SetActiveView(avalonDockViewHost, testView1); avalonDockViewHost.ActiveDocumentViewChanging += (sender, args) => { activeDocumentViewChangingCounter++; }; avalonDockViewHost.ActiveDocumentViewChanged += (sender, args) => { activeDocumentViewChangedCounter++; }; + avalonDockViewHost.ActiveViewChanged += (sender, args) => { activeViewChangedCounter++; }; // Call - avalonDockViewHost.SetFocusToView(testView); + avalonDockViewHost.BringToFront(testView1); // Assert Assert.AreEqual(0, activeDocumentViewChangingCounter); Assert.AreEqual(0, activeDocumentViewChangedCounter); - Assert.AreSame(testView, avalonDockViewHost.ActiveDocumentView); - Assert.IsTrue(IsFocussedView(avalonDockViewHost, testView)); + Assert.AreEqual(0, activeViewChangedCounter); + Assert.AreSame(testView1, avalonDockViewHost.ActiveDocumentView); + Assert.IsTrue(IsActiveView(avalonDockViewHost, testView1)); } } [Test] - public void SetFocusToView_NonActiveDocumentView_ActiveDocumentViewSetAndActiveDocumentEventsFired() + public void BringToFront_NonActiveDocumentView_ActiveViewNotAffectedAndNoActiveViewEventsFired() { // Setup var testView1 = new TestView(); var testView2 = new TestView(); var activeDocumentViewChangingCounter = 0; var activeDocumentViewChangedCounter = 0; + var activeViewChangedCounter = 0; using (var avalonDockViewHost = new AvalonDockViewHost()) { avalonDockViewHost.AddDocumentView(testView1); avalonDockViewHost.AddDocumentView(testView2); - avalonDockViewHost.SetFocusToView(testView2); + SetActiveView(avalonDockViewHost, testView2); avalonDockViewHost.ActiveDocumentViewChanging += (sender, args) => { activeDocumentViewChangingCounter++; }; avalonDockViewHost.ActiveDocumentViewChanged += (sender, args) => { activeDocumentViewChangedCounter++; }; + avalonDockViewHost.ActiveViewChanged += (sender, args) => { activeViewChangedCounter++; }; // Call - avalonDockViewHost.SetFocusToView(testView1); + avalonDockViewHost.BringToFront(testView1); // Assert - Assert.AreEqual(1, activeDocumentViewChangingCounter); - Assert.AreEqual(1, activeDocumentViewChangedCounter); - Assert.AreSame(testView1, avalonDockViewHost.ActiveDocumentView); - Assert.IsTrue(IsFocussedView(avalonDockViewHost, testView1)); + Assert.AreEqual(0, activeDocumentViewChangingCounter); + Assert.AreEqual(0, activeDocumentViewChangedCounter); + Assert.AreEqual(0, activeViewChangedCounter); + Assert.AreSame(testView2, avalonDockViewHost.ActiveDocumentView); + Assert.IsTrue(IsActiveView(avalonDockViewHost, testView2)); } } @@ -577,7 +607,7 @@ } [Test] - public void AddToolView_DocumentViewFocussed_FocussedDocumentViewNotAffected() + public void AddToolView_DocumentViewSetAsActiveView_ActiveDocumentViewNotAffected() { // Setup var testToolView = new TestView(); @@ -586,19 +616,19 @@ using (var avalonDockViewHost = new AvalonDockViewHost()) { avalonDockViewHost.AddDocumentView(testDocumentView); - avalonDockViewHost.SetFocusToView(testDocumentView); + SetActiveView(avalonDockViewHost, testDocumentView); // Call avalonDockViewHost.AddToolView(testToolView, ToolViewLocation.Left); // Assert Assert.AreSame(testDocumentView, avalonDockViewHost.ActiveDocumentView); - Assert.IsTrue(IsFocussedView(avalonDockViewHost, testDocumentView)); + Assert.IsTrue(IsActiveView(avalonDockViewHost, testDocumentView)); } } [Test] - public void AddToolView_ToolViewWasAlreadyAdded_NoDuplicationNoViewOpenedEventFiredAndViewFocussed() + public void AddToolView_ToolViewWasAlreadyAdded_NoDuplicationNoViewOpenedEventFired() { // Setup var testView1 = new TestView(); @@ -688,7 +718,7 @@ } [Test] - public void Remove_ToolViewInViewHostWithMultipleOtherViews_ActiveDocumentViewNotAffectedAndNoActiveDocumentEventsFired() + public void Remove_ToolViewInViewHostWithMultipleOtherViews_ActiveDocumentViewNotAffectedAndNoActiveViewEventsFired() { // Setup var testView1 = new TestView(); @@ -698,6 +728,7 @@ var testView5 = new TestView(); var activeDocumentViewChangingCounter = 0; var activeDocumentViewChangedCounter = 0; + var activeViewChangedCounter = 0; using (var avalonDockViewHost = new AvalonDockViewHost()) { @@ -707,45 +738,87 @@ avalonDockViewHost.AddDocumentView(testView4); avalonDockViewHost.AddToolView(testView5, ToolViewLocation.Left); - avalonDockViewHost.SetFocusToView(testView3); + SetActiveView(avalonDockViewHost, testView3); avalonDockViewHost.ActiveDocumentViewChanging += (sender, args) => { activeDocumentViewChangingCounter++; }; avalonDockViewHost.ActiveDocumentViewChanged += (sender, args) => { activeDocumentViewChangedCounter++; }; + avalonDockViewHost.ActiveViewChanged += (sender, args) => { activeViewChangedCounter++; }; // Call avalonDockViewHost.Remove(testView5); // Assert Assert.AreEqual(0, activeDocumentViewChangingCounter); Assert.AreEqual(0, activeDocumentViewChangedCounter); + Assert.AreEqual(0, activeViewChangedCounter); Assert.AreSame(testView3, avalonDockViewHost.ActiveDocumentView); - Assert.IsTrue(IsFocussedView(avalonDockViewHost, testView3)); + Assert.IsTrue(IsActiveView(avalonDockViewHost, testView3)); } } [Test] - public void SetFocusToView_NonFocussedToolView_ToolViewFocussed() + public void BringToFront_ActiveToolView_ActiveViewNotAffectedAndNoActiveViewEventsFired() { // Setup var testView1 = new TestView(); var testView2 = new TestView(); + var activeDocumentViewChangingCounter = 0; + var activeDocumentViewChangedCounter = 0; + var activeViewChangedCounter = 0; using (var avalonDockViewHost = new AvalonDockViewHost()) { avalonDockViewHost.AddToolView(testView1, ToolViewLocation.Left); - avalonDockViewHost.AddToolView(testView2, ToolViewLocation.Right); + avalonDockViewHost.AddToolView(testView2, ToolViewLocation.Bottom); + SetActiveView(avalonDockViewHost, testView1); - avalonDockViewHost.SetFocusToView(testView2); + avalonDockViewHost.ActiveDocumentViewChanging += (sender, args) => { activeDocumentViewChangingCounter++; }; + avalonDockViewHost.ActiveDocumentViewChanged += (sender, args) => { activeDocumentViewChangedCounter++; }; + avalonDockViewHost.ActiveViewChanged += (sender, args) => { activeViewChangedCounter++; }; // Call - avalonDockViewHost.SetFocusToView(testView1); + avalonDockViewHost.BringToFront(testView1); // Assert - Assert.IsTrue(IsFocussedView(avalonDockViewHost, testView1)); + Assert.AreEqual(0, activeDocumentViewChangingCounter); + Assert.AreEqual(0, activeDocumentViewChangedCounter); + Assert.AreEqual(0, activeViewChangedCounter); + Assert.IsTrue(IsActiveView(avalonDockViewHost, testView1)); } } [Test] + public void BringToFront_NonActiveToolView_ActiveViewNotAffectedAndNoActiveViewEventsFired() + { + // Setup + var testView1 = new TestView(); + var testView2 = new TestView(); + var activeDocumentViewChangingCounter = 0; + var activeDocumentViewChangedCounter = 0; + var activeViewChangedCounter = 0; + + using (var avalonDockViewHost = new AvalonDockViewHost()) + { + avalonDockViewHost.AddToolView(testView1, ToolViewLocation.Left); + avalonDockViewHost.AddToolView(testView2, ToolViewLocation.Bottom); + SetActiveView(avalonDockViewHost, testView2); + + avalonDockViewHost.ActiveDocumentViewChanging += (sender, args) => { activeDocumentViewChangingCounter++; }; + avalonDockViewHost.ActiveDocumentViewChanged += (sender, args) => { activeDocumentViewChangedCounter++; }; + avalonDockViewHost.ActiveViewChanged += (sender, args) => { activeViewChangedCounter++; }; + + // Call + avalonDockViewHost.BringToFront(testView1); + + // Assert + Assert.AreEqual(0, activeDocumentViewChangingCounter); + Assert.AreEqual(0, activeDocumentViewChangedCounter); + Assert.AreEqual(0, activeViewChangedCounter); + Assert.IsTrue(IsActiveView(avalonDockViewHost, testView2)); + } + } + + [Test] public void SetImage_ToolView_ImageSet() { // Setup @@ -810,12 +883,12 @@ .Any(c => ((WindowsFormsHost) c.Content).Child == toolView); } - private static bool IsFocussedView(AvalonDockViewHost avalonDockViewHost, IView view) + private static bool IsActiveView(AvalonDockViewHost avalonDockViewHost, IView view) { return ((WindowsFormsHost) avalonDockViewHost.DockingManager.ActiveContent).Child == view; } - private static bool IsAnyViewFocussed(AvalonDockViewHost avalonDockViewHost) + private static bool IsAnyViewActive(AvalonDockViewHost avalonDockViewHost) { return avalonDockViewHost.DockingManager.ActiveContent != null; } @@ -829,6 +902,14 @@ .First(lc => ((WindowsFormsHost) lc.Content).Child == view).IconSource != null; } + private static void SetActiveView(AvalonDockViewHost avalonDockViewHost, IView view) + { + avalonDockViewHost.DockingManager.Layout.Descendents() + .OfType() + .First(d => ((WindowsFormsHost) d.Content).Child == view) + .IsActive = true; + } + #endregion } } \ No newline at end of file Index: Core/Common/test/Core.Common.Gui.Test/Forms/ViewHost/DocumentViewControllerTest.cs =================================================================== diff -u -r081badaad87a6e2a6d5c861de9ee95fa1ca6dea3 -rfbf0127601ef799db5ec78430746c6aa23eab218 --- Core/Common/test/Core.Common.Gui.Test/Forms/ViewHost/DocumentViewControllerTest.cs (.../DocumentViewControllerTest.cs) (revision 081badaad87a6e2a6d5c861de9ee95fa1ca6dea3) +++ Core/Common/test/Core.Common.Gui.Test/Forms/ViewHost/DocumentViewControllerTest.cs (.../DocumentViewControllerTest.cs) (revision fbf0127601ef799db5ec78430746c6aa23eab218) @@ -581,7 +581,7 @@ viewHost.Stub(vh => vh.DocumentViews).Return(viewList); viewHost.Expect(vm => vm.AddDocumentView(Arg.Is.NotNull)).WhenCalled(invocation => { viewList.Add(invocation.Arguments[0] as TestView); }); viewHost.Expect(vh => vh.SetImage(null, null)).IgnoreArguments(); - viewHost.Expect(vh => vh.SetFocusToView(Arg.Matches(c => c == viewList.First()))); + viewHost.Expect(vh => vh.BringToFront(Arg.Matches(c => c == viewList.First()))); mocks.ReplayAll(); Index: Core/Common/test/Core.Common.Gui.Test/GuiCoreTest.cs =================================================================== diff -u -r67e77262b9f0f183db81f8c95d7b12aa5fcdb8e9 -rfbf0127601ef799db5ec78430746c6aa23eab218 --- Core/Common/test/Core.Common.Gui.Test/GuiCoreTest.cs (.../GuiCoreTest.cs) (revision 67e77262b9f0f183db81f8c95d7b12aa5fcdb8e9) +++ Core/Common/test/Core.Common.Gui.Test/GuiCoreTest.cs (.../GuiCoreTest.cs) (revision fbf0127601ef799db5ec78430746c6aa23eab218) @@ -25,6 +25,7 @@ using System.Linq; using System.Threading; using System.Windows.Forms; +using System.Windows.Forms.Integration; using System.Windows.Forms.VisualStyles; using System.Windows.Threading; using Core.Common.Base.Data; @@ -46,6 +47,7 @@ using log4net.Repository.Hierarchy; using NUnit.Framework; using Rhino.Mocks; +using Xceed.Wpf.AvalonDock.Layout; namespace Core.Common.Gui.Test { @@ -1218,7 +1220,7 @@ [Test] [Apartment(ApartmentState.STA)] - public void GivenGuiWithoutSelection_WhenSelectionProviderAddedAndFocussed_ThenSelectionSynced() + public void GivenGuiWithoutSelection_WhenSelectionProviderSetAsActiveView_ThenSelectionSynced() { // Given var mocks = new MockRepository(); @@ -1232,13 +1234,13 @@ using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { gui.Run(); + gui.ViewHost.AddDocumentView(selectionProvider); // Precondition Assert.IsNull(gui.Selection); // When - gui.ViewHost.AddDocumentView(selectionProvider); - gui.ViewHost.SetFocusToView(selectionProvider); + SetActiveView((AvalonDockViewHost) gui.ViewHost, selectionProvider); // Then Assert.AreSame(selectionProvider.Selection, gui.Selection); @@ -1248,7 +1250,7 @@ [Test] [Apartment(ApartmentState.STA)] - public void GivenGuiWithRandomSelection_WhenSelectionProviderAddedAndFocussed_ThenSelectionSynced() + public void GivenGuiWithRandomSelection_WhenSelectionProviderSetAsActiveView_ThenSelectionSynced() { // Given var mocks = new MockRepository(); @@ -1262,12 +1264,12 @@ using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { gui.Run(); + gui.ViewHost.AddDocumentView(selectionProvider); gui.Selection = new object(); // When - gui.ViewHost.AddDocumentView(selectionProvider); - gui.ViewHost.SetFocusToView(selectionProvider); + SetActiveView((AvalonDockViewHost) gui.ViewHost, selectionProvider); // Then Assert.AreSame(selectionProvider.Selection, gui.Selection); @@ -1277,7 +1279,7 @@ [Test] [Apartment(ApartmentState.STA)] - public void GivenGuiWithRandomSelection_WhenNonSelectionProviderAdded_ThenSelectionPreserved() + public void GivenGuiWithRandomSelection_WhenSelectionChangedOnActiveSelectionProvider_ThenSelectionSynced() { // Given var mocks = new MockRepository(); @@ -1286,41 +1288,13 @@ IProjectFactory projectFactory = CreateProjectFactory(mocks); mocks.ReplayAll(); - var selection = new object(); - - using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) - { - gui.Run(); - - gui.Selection = selection; - - // When - gui.ViewHost.AddDocumentView(new TestView()); - - // Then - Assert.AreSame(selection, gui.Selection); - } - mocks.VerifyAll(); - } - - [Test] - [Apartment(ApartmentState.STA)] - public void GivenGuiWithRandomSelection_WhenSelectionChangedOnAddedAndFocussedSelectionProvider_ThenSelectionSynced() - { - // Given - var mocks = new MockRepository(); - var projectStore = mocks.Stub(); - var projectMigrator = mocks.Stub(); - IProjectFactory projectFactory = CreateProjectFactory(mocks); - mocks.ReplayAll(); - var selectionProvider = new TestSelectionProvider(); using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) { gui.Run(); gui.ViewHost.AddDocumentView(selectionProvider); - gui.ViewHost.SetFocusToView(selectionProvider); + SetActiveView((AvalonDockViewHost) gui.ViewHost, selectionProvider); gui.Selection = new object(); @@ -1351,6 +1325,8 @@ { gui.Run(); gui.ViewHost.AddDocumentView(selectionProvider); + SetActiveView((AvalonDockViewHost) gui.ViewHost, selectionProvider); + gui.ViewHost.Remove(selectionProvider); gui.Selection = selection; @@ -1366,7 +1342,7 @@ [Test] [Apartment(ApartmentState.STA)] - public void GivenGuiWithRandomSelection_WhenSelectionProviderBecomesActiveView_ThenSelectionSynced() + public void GivenGuiWithRandomSelection_WhenNonSelectionProviderSetAsActiveView_ThenSelectionPreserved() { // Given var mocks = new MockRepository(); @@ -1375,36 +1351,6 @@ IProjectFactory projectFactory = CreateProjectFactory(mocks); mocks.ReplayAll(); - var selectionProvider = new TestSelectionProvider(); - - using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings())) - { - gui.Run(); - gui.ViewHost.AddDocumentView(selectionProvider); - gui.ViewHost.AddDocumentView(new TestView()); - - gui.Selection = new object(); - - // When - gui.ViewHost.SetFocusToView(selectionProvider); - - // Then - Assert.AreSame(selectionProvider.Selection, gui.Selection); - } - mocks.VerifyAll(); - } - - [Test] - [Apartment(ApartmentState.STA)] - public void GivenGuiWithRandomSelection_WhenNonSelectionProviderBecomesActiveView_ThenSelectionPreserved() - { - // Given - var mocks = new MockRepository(); - var projectStore = mocks.Stub(); - var projectMigrator = mocks.Stub(); - IProjectFactory projectFactory = CreateProjectFactory(mocks); - mocks.ReplayAll(); - var testView = new TestView(); var selection = new object(); @@ -1416,7 +1362,7 @@ gui.Selection = selection; // When - gui.ViewHost.SetFocusToView(testView); + SetActiveView((AvalonDockViewHost) gui.ViewHost, testView); // Then Assert.AreSame(selection, gui.Selection); @@ -1471,7 +1417,7 @@ { gui.Run(); gui.ViewHost.AddDocumentView(selectionProvider); - gui.ViewHost.SetFocusToView(selectionProvider); + SetActiveView((AvalonDockViewHost) gui.ViewHost, selectionProvider); // Precondition Assert.AreSame(selectionProvider.Selection, gui.Selection); @@ -1502,6 +1448,7 @@ { gui.Run(); gui.ViewHost.AddDocumentView(selectionProvider); + SetActiveView((AvalonDockViewHost) gui.ViewHost, selectionProvider); gui.Dispose(); @@ -1517,6 +1464,14 @@ mocks.VerifyAll(); } + private static void SetActiveView(AvalonDockViewHost avalonDockViewHost, IView view) + { + avalonDockViewHost.DockingManager.Layout.Descendents() + .OfType() + .First(d => ((WindowsFormsHost) d.Content).Child == view) + .IsActive = true; + } + private static IProjectFactory CreateProjectFactory(MockRepository mocks) { var projectFactory = mocks.Stub(); @@ -1534,10 +1489,10 @@ Selection = new object(); } - public object Data { get; set; } - public object Selection { get; private set; } + public object Data { get; set; } + public void ChangeSelection() { Selection = new object();