Index: Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj =================================================================== diff -u -r6fefc4422dcc5076f0ff430f73d829a6670f0285 -r5a856571ad752251b382db7c2b018a7e0cd1cca1 --- Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj (.../Core.Common.Gui.csproj) (revision 6fefc4422dcc5076f0ff430f73d829a6670f0285) +++ Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj (.../Core.Common.Gui.csproj) (revision 5a856571ad752251b382db7c2b018a7e0cd1cca1) @@ -83,7 +83,6 @@ 3.5 - @@ -143,15 +142,15 @@ MessageWindowDialog.cs - - - - - + + AvalonDockViewHost.xaml + + + + - @@ -173,8 +172,6 @@ - - @@ -239,18 +236,8 @@ SplashScreen.xaml - - - - - - - UserControl - - - ViewSelectionContextMenuController.cs - - + + Settings.settings @@ -342,10 +329,6 @@ SelectViewDialog.cs Designer - - ViewSelectionContextMenuController.cs - Designer - PublicResXFileCodeGenerator Designer @@ -373,6 +356,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + Index: Core/Common/src/Core.Common.Gui/GuiCore.cs =================================================================== diff -u -r6fefc4422dcc5076f0ff430f73d829a6670f0285 -r5a856571ad752251b382db7c2b018a7e0cd1cca1 --- Core/Common/src/Core.Common.Gui/GuiCore.cs (.../GuiCore.cs) (revision 6fefc4422dcc5076f0ff430f73d829a6670f0285) +++ Core/Common/src/Core.Common.Gui/GuiCore.cs (.../GuiCore.cs) (revision 5a856571ad752251b382db7c2b018a7e0cd1cca1) @@ -33,19 +33,17 @@ using Core.Common.Base.Plugin; using Core.Common.Base.Storage; using Core.Common.Controls.TreeView; -using Core.Common.Controls.Views; using Core.Common.Gui.Commands; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms; using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.Forms.MessageWindow; using Core.Common.Gui.Forms.PropertyGridView; -using Core.Common.Gui.Forms.ViewManager; +using Core.Common.Gui.Forms.ViewHost; using Core.Common.Gui.Plugin; using Core.Common.Gui.Properties; using Core.Common.Gui.Selection; using Core.Common.Gui.Settings; -using Core.Common.Utils.Events; using Core.Common.Utils.Extensions; using Core.Common.Utils.Reflection; using log4net; @@ -66,8 +64,6 @@ private static bool isAlreadyRunningInstanceOfIGui; private static string instanceCreationStackTrace; - private AvalonDockDockingManager toolWindowViewsDockingManager; - private SplashScreen splashScreen; private bool runFinished; @@ -120,8 +116,8 @@ UserSettings = Properties.Settings.Default; - viewCommandHandler = new ViewCommandHandler(this, this, this, this); - storageCommandHandler = new StorageCommandHandler(projectStore, this, this, this, this, viewCommandHandler); + viewCommandHandler = new ViewCommandHandler(this, this, this); + storageCommandHandler = new StorageCommandHandler(projectStore, this, this, this, viewCommandHandler); exportImportCommandHandler = new ExportImportCommandHandler(MainWindow, Plugins.SelectMany(p => p.GetFileImporters()), Plugins.SelectMany(p => p.GetFileExporters())); @@ -157,12 +153,8 @@ ShowSplashScreen(); - log.Info(Resources.GuiCore_Run_Starting_application); - InitializeProjectFromPath(projectPath); - log.Info(Resources.GuiCore_Run_Initializing_graphical_user_interface); - Initialize(); log.InfoFormat(Resources.GuiCore_Run_Started_in_0_f2_sec, (DateTime.Now - startTime).TotalSeconds); @@ -192,10 +184,6 @@ CopyDefaultViewsToUserSettings(); - mainWindow.ClearDocumentTabs(); - - mainWindow.SaveLayout(); // save before ApplicationCore.Exit - if (userSettingsDirty) { UserSettings.Save(); @@ -248,12 +236,10 @@ Project = null; - if (ToolWindowViews != null) + if (ViewHost != null) { - ToolWindowViews.CollectionChanged -= ToolWindowViewsOnCollectionChanged; - ToolWindowViews.Clear(); - ToolWindowViews.Dispose(); - ToolWindowViews = null; + ViewHost.Dispose(); + ViewHost.ActiveDocumentViewChanged -= OnActiveDocumentViewChanged; } if (storageCommandHandler != null) @@ -262,31 +248,14 @@ storageCommandHandler = null; } - if (DocumentViews != null) - { - DocumentViews.ActiveViewChanging -= ActiveViewChanging; - DocumentViews.ActiveViewChanged -= OnActiveViewChanged; - DocumentViews.CollectionChanged -= DocumentViewsCollectionChanged; - - DocumentViews.Clear(); - DocumentViews.Dispose(); - DocumentViews = null; - } - - if (toolWindowViewsDockingManager != null) - { - toolWindowViewsDockingManager.Dispose(); - toolWindowViewsDockingManager = null; - } - // Dispose managed resources. TODO: double check if we need to dispose managed resources? if (mainWindow != null && !mainWindow.IsWindowDisposed) { mainWindow.Dispose(); mainWindow = null; } - DocumentViewsResolver = null; + DocumentViewController = null; splashScreen = null; @@ -378,7 +347,7 @@ { get { - return ToolWindowViews.OfType().FirstOrDefault(); + return ViewHost.ToolViews.OfType().FirstOrDefault(); } } @@ -425,17 +394,6 @@ ResumeUI(); } - // Sets the tooltip for given view, assuming that ProjectExplorer is not null. - private void SetToolTipForView(IView view) - { - if (mainWindow == null || ProjectExplorer == null) - { - return; - } - - DocumentViews.SetTooltip(view, ProjectExplorer.TreeViewControl.TryGetPathForData(view.Data)); - } - private void ConfigureLogging() { // configure logging @@ -466,10 +424,6 @@ CopyDefaultViewsFromUserSettings(); - //enable activation AFTER initialization - DocumentViews.IgnoreActivation = false; - ToolWindowViews.IgnoreActivation = false; - if (Properties.Settings.Default.SettingsKey.Contains("mruList")) { if (Properties.Settings.Default["mruList"] == null) @@ -485,7 +439,7 @@ { VersionText = SettingsHelper.ApplicationVersion, CopyrightText = FixedSettings.Copyright, - LicenseText = FixedSettings.LicenseDescription, + LicenseText = FixedSettings.LicenseDescription }; splashScreen.IsVisibleChanged += delegate @@ -518,25 +472,20 @@ { mainWindow.Loaded += delegate { - mainWindow.LoadLayout(); - - // bug in Fluent ribbon (views removed during load layout are not cleared - no events), synchronize them manually - ToolWindowViews.RemoveAllExcept(toolWindowViewsDockingManager.Views.ToArray()); - // make sure these windows come on top - if (ToolWindowViews.Contains(mainWindow.PropertyGrid)) + if (ViewHost.ToolViews.Contains(mainWindow.PropertyGrid)) { - ToolWindowViews.ActiveView = mainWindow.PropertyGrid; + ViewHost.SetFocusToView(mainWindow.PropertyGrid); } - if (ToolWindowViews.Contains(mainWindow.MessageWindow)) + if (ViewHost.ToolViews.Contains(mainWindow.MessageWindow)) { - ToolWindowViews.ActiveView = mainWindow.MessageWindow; + ViewHost.SetFocusToView(mainWindow.MessageWindow); } - if (ToolWindowViews.Contains(ProjectExplorer)) + if (ViewHost.ToolViews.Contains(ProjectExplorer)) { - ToolWindowViews.ActiveView = ProjectExplorer; + ViewHost.SetFocusToView(ProjectExplorer); } mainWindow.ValidateItems(); @@ -558,144 +507,34 @@ private void InitializeWindows() { - log.Info(Resources.GuiCore_InitializeWindows_Initializing_windows); - InitializeMainWindow(); - log.Info(Resources.GuiCore_InitializeWindows_Creating_default_tool_windows); - InitializeToolWindows(); + ViewHost = mainWindow.ViewHost; + ViewHost.ViewClosed += OnActiveDocumentViewChanged; + ViewHost.ActiveDocumentViewChanged += OnActiveDocumentViewChanged; - UpdateTitle(); + DocumentViewController = new DocumentViewController(ViewHost, Plugins.SelectMany(p => p.GetViewInfos()), mainWindow); - log.Info(Resources.GuiCore_InitializeWindows_All_windows_are_created); - } - - private void ActiveViewChanging(object sender, ActiveViewChangeEventArgs e) - { - if (e.View == null || mainWindow == null || mainWindow.IsWindowDisposed) - { - return; - } - - if (ProjectExplorer != null) - { - SetToolTipForView(e.View); - } - } - - private void InitializeToolWindows() - { - log.Info(Resources.GuiCore_InitToolWindows_Creating_document_window_manager); - - InitializeDocumentViewController(); - PropertyResolver = new PropertyResolver(Plugins.SelectMany(p => p.GetPropertyInfos())); applicationFeatureCommands = new ApplicationFeatureCommandHandler(PropertyResolver, mainWindow, this); - InitializeToolViewController(); - - log.Info(Resources.GuiCore_InitToolWindows_Creating_tool_window_manager); - mainWindow.InitializeToolWindows(); - log.Debug(Resources.GuiCore_InitToolWindows_Finished_InitToolWindows); - mainWindow.SubscribeToGui(); - } - private void InitializeDocumentViewController() - { - var allowedDocumentWindowLocations = new[] - { - ViewLocation.Document, - ViewLocation.Floating - }; - - var documentDockingManager = new AvalonDockDockingManager(mainWindow.DockingManager, allowedDocumentWindowLocations); - - var documentViewManager = new ViewList(documentDockingManager, ViewLocation.Document) - { - IgnoreActivation = true, - UpdateViewNameAction = v => UpdateViewName(v) - }; - - documentViewManager.EnableTabContextMenus(); - - documentViewManager.ActiveViewChanging += ActiveViewChanging; - documentViewManager.ActiveViewChanged += OnActiveViewChanged; - documentViewManager.CollectionChanged += DocumentViewsCollectionChanged; - - DocumentViews = documentViewManager; - - DocumentViewsResolver = new ViewResolver(documentViewManager, Plugins.SelectMany(p => p.GetViewInfos()), mainWindow); + UpdateTitle(); } - private void InitializeToolViewController() + private void OnActiveDocumentViewChanged(object sender, EventArgs e) { - var allowedToolWindowLocations = new[] - { - ViewLocation.Left, - ViewLocation.Right, - ViewLocation.Top, - ViewLocation.Bottom, - ViewLocation.Floating - }; - - toolWindowViewsDockingManager = new AvalonDockDockingManager(mainWindow.DockingManager, allowedToolWindowLocations); - - ToolWindowViews = new ViewList(toolWindowViewsDockingManager, ViewLocation.Left) - { - IgnoreActivation = true - }; - - ToolWindowViews.CollectionChanged += ToolWindowViewsOnCollectionChanged; - } - - private void OnActiveViewChanged(object sender, ActiveViewChangeEventArgs e) - { if (mainWindow == null || mainWindow.IsWindowDisposed) { return; } mainWindow.ValidateItems(); - FireActiveViewChanged(e); } - private void FireActiveViewChanged(ActiveViewChangeEventArgs e) - { - if (ActiveViewChanged != null) - { - ActiveViewChanged(null, e); - } - } - - private void UpdateViewName(IView view) - { - view.Text = DocumentViewsResolver.GetViewName(view); - SetToolTipForView(view); - } - - private void ToolWindowViewsOnCollectionChanged(object sender, NotifyCollectionChangeEventArgs notifyCollectionChangeEventArgs) - { - if (isExiting) - { - return; - } - mainWindow.ValidateItems(); - } - - private void DocumentViewsCollectionChanged(object sender, NotifyCollectionChangeEventArgs e) - { - if (isExiting || DocumentViews.Count != 0) - { - return; - } - - // if no new active view is set update toolbars - mainWindow.ValidateItems(); - } - private void InitializeGuiPlugins() { Plugins.ForEachElementDo(p => p.Gui = this); @@ -740,7 +579,7 @@ Type viewDataType = AssemblyUtils.GetTypeByName(viewDataTypeName); if (viewDataType != null) { - DocumentViewsResolver.DefaultViewTypes.Add(viewDataType, AssemblyUtils.GetTypeByName(viewTypeName)); + DocumentViewController.DefaultViewTypes.Add(viewDataType, AssemblyUtils.GetTypeByName(viewTypeName)); } } } @@ -750,13 +589,13 @@ StringCollection defaultViews = new StringCollection(); StringCollection defaultViewDataTypes = new StringCollection(); - foreach (Type objectType in DocumentViewsResolver.DefaultViewTypes.Keys) + foreach (Type objectType in DocumentViewController.DefaultViewTypes.Keys) { - if (DocumentViewsResolver.DefaultViewTypes[objectType] == null) + if (DocumentViewController.DefaultViewTypes[objectType] == null) { continue; } - defaultViews.Add(DocumentViewsResolver.DefaultViewTypes[objectType].ToString()); + defaultViews.Add(DocumentViewController.DefaultViewTypes[objectType].ToString()); defaultViewDataTypes.Add(objectType.ToString()); } @@ -829,11 +668,6 @@ return; } - if (null != DocumentViews) - { - DocumentViews.IgnoreActivation = true; - } - selection = value; settingSelection = true; @@ -854,11 +688,6 @@ { mainWindow.ValidateItems(); } - - if (null != DocumentViews) - { - DocumentViews.IgnoreActivation = false; - } } } @@ -906,32 +735,12 @@ #endregion - #region Implementation: IDocumentViewController + #region Implementation: IViewController - public event EventHandler ActiveViewChanged; + public IViewHost ViewHost { get; private set; } - public IView ActiveView - { - get - { - return DocumentViews != null ? - DocumentViews.ActiveView : - null; - } - } + public IDocumentViewController DocumentViewController { get; private set; } - public IViewList DocumentViews { get; private set; } - - public IViewResolver DocumentViewsResolver { get; private set; } - - public void UpdateToolTips() - { - foreach (var view in DocumentViews.AllViews) - { - SetToolTipForView(view); - } - } - #endregion #region Implementation: ISettingsOwner @@ -1027,7 +836,7 @@ UpdateTitle(); } - public void UpdateTitle() + private void UpdateTitle() { if (mainWindow != null) { @@ -1039,27 +848,5 @@ } #endregion - - #region Implementation: IToolViewController - - public IViewList ToolWindowViews { get; private set; } - - public void CloseToolView(IView toolView) - { - ToolWindowViews.Remove(toolView); - } - - public bool IsToolWindowOpen() - { - return ToolWindowViews.Any(t => t.GetType() == typeof(T)); - } - - public void OpenToolView(IView toolView) - { - ToolWindowViews.Add(toolView); - ToolWindowViews.ActiveView = toolView; - } - - #endregion } } \ No newline at end of file Index: Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj =================================================================== diff -u -r6fefc4422dcc5076f0ff430f73d829a6670f0285 -r5a856571ad752251b382db7c2b018a7e0cd1cca1 --- Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision 6fefc4422dcc5076f0ff430f73d829a6670f0285) +++ Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision 5a856571ad752251b382db7c2b018a7e0cd1cca1) @@ -68,6 +68,7 @@ + ..\..\..\..\packages\AvalonDock.2.0.2000\lib\net40\Xceed.Wpf.AvalonDock.dll True @@ -124,23 +125,14 @@ - - - - + + UserControl - + TestView.cs - - UserControl - - - ToolWindowTestControl.cs - - - + @@ -158,9 +150,6 @@ - - - @@ -201,13 +190,9 @@ - + TestView.cs - - ToolWindowTestControl.cs - Designer - ResXFileCodeGenerator Resources.Designer.cs Index: Core/Common/test/Core.Common.Gui.Test/Forms/MainWindow/MainWindowTest.cs =================================================================== diff -u -r6fefc4422dcc5076f0ff430f73d829a6670f0285 -r5a856571ad752251b382db7c2b018a7e0cd1cca1 --- Core/Common/test/Core.Common.Gui.Test/Forms/MainWindow/MainWindowTest.cs (.../MainWindowTest.cs) (revision 6fefc4422dcc5076f0ff430f73d829a6670f0285) +++ Core/Common/test/Core.Common.Gui.Test/Forms/MainWindow/MainWindowTest.cs (.../MainWindowTest.cs) (revision 5a856571ad752251b382db7c2b018a7e0cd1cca1) @@ -26,27 +26,20 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; -using System.Windows.Threading; +using Core.Common.Controls.Views; using Core.Common.Gui.Commands; -using Core.Common.Gui.Forms; using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.Forms.MessageWindow; using Core.Common.Gui.Forms.PropertyGridView; -using Core.Common.Gui.Forms.ViewManager; +using Core.Common.Gui.Forms.ViewHost; using Core.Common.Gui.Plugin; using Core.Common.Gui.PropertyBag; using Core.Common.Gui.Settings; -using Core.Common.Gui.Theme; using Core.Common.Utils; -using Core.Common.Utils.Events; using Core.Common.Utils.Reflection; - using NUnit.Framework; - using Rhino.Mocks; -using FlowDirection = System.Windows.FlowDirection; - namespace Core.Common.Gui.Test.Forms.MainWindow { [TestFixture] @@ -65,7 +58,6 @@ public void TearDown() { MessageWindowLogAppender.Instance = originalValue; - Dispatcher.CurrentDispatcher.InvokeShutdown(); } [Test] @@ -82,7 +74,6 @@ Assert.IsFalse(mainWindow.IsWindowDisposed); Assert.IsFalse(mainWindow.Visible); - Assert.IsTrue(mainWindow.DockingManager.AllowMixedOrientation); Assert.IsNull(mainWindow.MessageWindow); Assert.IsNull(mainWindow.PropertyGrid); @@ -91,7 +82,7 @@ Assert.IsNotNull(mainWindow.Handle); Assert.IsFalse(mainWindow.InvokeRequired, - "'mainWindow' instance on same thread as test, therefore invocation not required."); + "'mainWindow' instance on same thread as test, therefore invocation not required."); Assert.AreEqual("MainWindow", mainWindow.Title); Assert.AreEqual(ResizeMode.CanResizeWithGrip, mainWindow.ResizeMode); @@ -138,19 +129,15 @@ // Setup var mocks = new MockRepository(); var settings = mocks.Stub(); - settings["colorTheme"] = ColorTheme.Generic; - var toolViewsList = mocks.Stub(); - toolViewsList.Stub(l => l.Contains(Arg.Is.Anything)) - .Return(false); - toolViewsList.Stub(l => l.Contains(Arg.Is.Anything)) - .Return(false); + var viewHost = mocks.Stub(); + viewHost.Stub(vm => vm.ToolViews).Return(new IView[0]); var gui = mocks.Stub(); gui.Stub(g => g.UserSettings).Return(settings); gui.Stub(g => g.FixedSettings).Return(new GuiCoreSettings()); gui.Stub(g => g.Plugins).Return(Enumerable.Empty().ToList()); - gui.Stub(g => g.ToolWindowViews).Return(toolViewsList); + gui.Stub(g => g.ViewHost).Return(viewHost); mocks.ReplayAll(); using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) @@ -175,19 +162,15 @@ // Setup var mocks = new MockRepository(); var settings = mocks.Stub(); - settings["colorTheme"] = ColorTheme.Generic; - var toolViewsList = mocks.Stub(); - toolViewsList.Stub(l => l.Contains(Arg.Is.Anything)) - .Return(false); - toolViewsList.Stub(l => l.Contains(Arg.Is.Anything)) - .Return(false); + var viewHost = mocks.Stub(); + viewHost.Stub(vm => vm.ToolViews).Return(new IView[0]); var gui = mocks.Stub(); gui.Stub(g => g.UserSettings).Return(settings); gui.Stub(g => g.FixedSettings).Return(new GuiCoreSettings()); gui.Stub(g => g.Plugins).Return(Enumerable.Empty().ToList()); - gui.Stub(g => g.ToolWindowViews).Return(toolViewsList); + gui.Stub(g => g.ViewHost).Return(viewHost); mocks.ReplayAll(); using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) @@ -244,16 +227,12 @@ { // Setup var mocks = new MockRepository(); - var toolWindowsList = mocks.Stub(); - toolWindowsList.Expect(l => l.CollectionChanged += null).IgnoreArguments(); + var viewHost = mocks.Stub(); + viewHost.Expect(vm => vm.ActiveDocumentViewChanged += null).IgnoreArguments(); + viewHost.Expect(vm => vm.ActiveDocumentViewChanging += null).IgnoreArguments(); // Should happen during dispose - var documentViewsList = mocks.Stub(); - documentViewsList.Expect(l => l.ActiveViewChanged += null).IgnoreArguments(); - documentViewsList.Expect(l => l.ActiveViewChanging += null).IgnoreArguments(); // Should happen during dispose - var gui = mocks.Stub(); - gui.Stub(g => g.ToolWindowViews).Return(toolWindowsList); - gui.Stub(g => g.DocumentViews).Return(documentViewsList); + gui.Stub(g => g.ViewHost).Return(viewHost); mocks.ReplayAll(); using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) @@ -269,98 +248,6 @@ [Test] [STAThread] - public void GivenSubscribedToGui_WhenPropertyGridRemovedEvent_ThenPropertyGridCleared() - { - // Setup - var mocks = new MockRepository(); - var toolWindowsList = mocks.Stub(); - toolWindowsList.Expect(l => l.CollectionChanged += null).IgnoreArguments(); - toolWindowsList.Stub(l => l.Contains(null)).IgnoreArguments() - .Return(false); - toolWindowsList.Stub(l => l.Add(null, ViewLocation.Right)).IgnoreArguments(); - - var documentViewsList = mocks.Stub(); - documentViewsList.Expect(l => l.ActiveViewChanged += null).IgnoreArguments(); - documentViewsList.Expect(l => l.ActiveViewChanging += null).IgnoreArguments(); // Should happen during dispose - - var propertyResolver = mocks.Stub(); - propertyResolver.Stub(r => r.GetObjectProperties(null)).IgnoreArguments().Return(null); - - var gui = mocks.Stub(); - gui.Stub(g => g.ToolWindowViews).Return(toolWindowsList); - gui.Stub(g => g.DocumentViews).Return(documentViewsList); - gui.Stub(g => g.PropertyResolver).Return(propertyResolver); - gui.Stub(g => g.SelectionChanged += null).IgnoreArguments(); - gui.Stub(g => g.SelectionChanged -= null).IgnoreArguments(); - mocks.ReplayAll(); - - using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) - { - mainWindow.SetGui(gui); - mainWindow.InitializeToolWindows(); - - // Precondition: - Assert.IsNotNull(mainWindow.PropertyGrid); - - // Call - mainWindow.SubscribeToGui(); - toolWindowsList.Raise(l => l.CollectionChanged += null, - toolWindowsList, - new NotifyCollectionChangeEventArgs(NotifyCollectionChangeAction.Remove, mainWindow.PropertyGrid, -1, 0)); - // Assert - Assert.IsNull(mainWindow.PropertyGrid); - } - mocks.VerifyAll(); - } - - [Test] - [STAThread] - public void GivenSubscribedToGui_WhenMessageWindowRemovedEvent_ThenMessageWindowCleared() - { - // Setup - var mocks = new MockRepository(); - var toolWindowsList = mocks.Stub(); - toolWindowsList.Expect(l => l.CollectionChanged += null).IgnoreArguments(); - toolWindowsList.Stub(l => l.Contains(null)).IgnoreArguments() - .Return(false); - toolWindowsList.Stub(l => l.Add(null, ViewLocation.Right)).IgnoreArguments(); - - var documentViewsList = mocks.Stub(); - documentViewsList.Expect(l => l.ActiveViewChanged += null).IgnoreArguments(); - documentViewsList.Expect(l => l.ActiveViewChanging += null).IgnoreArguments(); // Should happen during dispose - - var propertyResolver = mocks.Stub(); - propertyResolver.Stub(r => r.GetObjectProperties(null)).IgnoreArguments().Return(null); - - var gui = mocks.Stub(); - gui.Stub(g => g.ToolWindowViews).Return(toolWindowsList); - gui.Stub(g => g.DocumentViews).Return(documentViewsList); - gui.Stub(g => g.PropertyResolver).Return(propertyResolver); - gui.Stub(g => g.SelectionChanged += null).IgnoreArguments(); - gui.Stub(g => g.SelectionChanged -= null).IgnoreArguments(); - mocks.ReplayAll(); - - using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) - { - mainWindow.SetGui(gui); - mainWindow.InitializeToolWindows(); - - // Precondition: - Assert.IsNotNull(mainWindow.MessageWindow); - - // Call - mainWindow.SubscribeToGui(); - toolWindowsList.Raise(l => l.CollectionChanged += null, - toolWindowsList, - new NotifyCollectionChangeEventArgs(NotifyCollectionChangeAction.Remove, mainWindow.MessageWindow, -1, 0)); - // Assert - Assert.IsNull(mainWindow.MessageWindow); - } - mocks.VerifyAll(); - } - - [Test] - [STAThread] public void UnsubscribeFromGui_NoGuiSet_DoNothing() { // Setup @@ -380,19 +267,14 @@ { // Setup var mocks = new MockRepository(); - var toolWindowsList = mocks.Stub(); - toolWindowsList.Expect(l => l.CollectionChanged += null).IgnoreArguments(); - toolWindowsList.Expect(l => l.CollectionChanged -= null).IgnoreArguments(); + var viewHost = mocks.Stub(); + viewHost.Expect(l => l.ActiveDocumentViewChanged += null).IgnoreArguments(); + viewHost.Expect(l => l.ActiveDocumentViewChanging += null).IgnoreArguments(); + viewHost.Expect(l => l.ActiveDocumentViewChanged -= null).IgnoreArguments(); + viewHost.Expect(l => l.ActiveDocumentViewChanging -= null).IgnoreArguments(); - var documentViewsList = mocks.Stub(); - documentViewsList.Expect(l => l.ActiveViewChanged += null).IgnoreArguments(); - documentViewsList.Expect(l => l.ActiveViewChanging += null).IgnoreArguments(); - documentViewsList.Expect(l => l.ActiveViewChanged -= null).IgnoreArguments(); - documentViewsList.Expect(l => l.ActiveViewChanging -= null).IgnoreArguments(); - var gui = mocks.Stub(); - gui.Stub(g => g.ToolWindowViews).Return(toolWindowsList); - gui.Stub(g => g.DocumentViews).Return(documentViewsList); + gui.Stub(g => g.ViewHost).Return(viewHost); mocks.ReplayAll(); using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) @@ -424,26 +306,22 @@ [Test] [STAThread] - public void InitPropertiesWindowAndActivate_GuiSet_InitializePropertyGridAndMakeActive() + public void InitPropertiesWindowAndActivate_GuiSet_InitializePropertyGrid() { // Setup var selectedObject = new object(); var mocks = new MockRepository(); var selectedObjectProperties = mocks.Stub(); - var toolWindowList = mocks.Stub(); - toolWindowList.Expect(l => l.Add(Arg.Matches(grid => - grid.Text == "Eigenschappen" && - grid.Data == selectedObjectProperties), - Arg.Is.Equal(ViewLocation.Right | ViewLocation.Bottom))); + var viewHost = new AvalonDockViewHost(); var propertyResolver = mocks.Stub(); propertyResolver.Expect(r => r.GetObjectProperties(selectedObject)) .Return(selectedObjectProperties); var gui = mocks.Stub(); - gui.Stub(g => g.ToolWindowViews).Return(toolWindowList); + gui.Stub(g => g.ViewHost).Return(viewHost); gui.Selection = selectedObject; gui.Stub(g => g.PropertyResolver).Return(propertyResolver); gui.Stub(g => g.SelectionChanged += null).IgnoreArguments(); @@ -458,12 +336,10 @@ mainWindow.InitPropertiesWindowAndActivate(); // Assert - Assert.IsInstanceOf(toolWindowList.ActiveView); - Assert.AreEqual("Eigenschappen", toolWindowList.ActiveView.Text); - Assert.AreEqual(selectedObjectProperties, toolWindowList.ActiveView.Data); - - Assert.AreSame(toolWindowList.ActiveView, mainWindow.PropertyGrid, - "PropertyGrid should now be initialized."); + Assert.IsNull(viewHost.ActiveDocumentView); + Assert.AreSame(viewHost.ToolViews.ElementAt(0), mainWindow.PropertyGrid, "PropertyGrid instance should remain the same."); + Assert.AreEqual("Eigenschappen", mainWindow.PropertyGrid.Text); + Assert.AreEqual(selectedObjectProperties, mainWindow.PropertyGrid.Data); } mocks.VerifyAll(); } @@ -477,20 +353,14 @@ var mocks = new MockRepository(); var selectedObjectProperties = mocks.Stub(); - - var toolWindowList = mocks.Stub(); - toolWindowList.Expect(l => l.Add(Arg.Matches(grid => - grid.Text == "Eigenschappen" && - grid.Data == selectedObjectProperties), - Arg.Is.Equal(ViewLocation.Right | ViewLocation.Bottom))); - + var viewHost = new AvalonDockViewHost(); var propertyResolver = mocks.Stub(); propertyResolver.Expect(r => r.GetObjectProperties(selectedObject)) .Return(selectedObjectProperties) .Repeat.Twice(); var gui = mocks.Stub(); - gui.Stub(g => g.ToolWindowViews).Return(toolWindowList); + gui.Stub(g => g.ViewHost).Return(viewHost); gui.Selection = selectedObject; gui.Stub(g => g.PropertyResolver).Return(propertyResolver); gui.Stub(g => g.SelectionChanged += null).IgnoreArguments(); @@ -500,21 +370,20 @@ using (var mainWindow = new Gui.Forms.MainWindow.MainWindow()) { mainWindow.SetGui(gui); - mainWindow.InitPropertiesWindowAndActivate(); + var originalPropertyGrid = mainWindow.PropertyGrid; // Call mainWindow.InitPropertiesWindowAndActivate(); // Assert - Assert.AreSame(originalPropertyGrid, toolWindowList.ActiveView); - Assert.AreSame(originalPropertyGrid, mainWindow.PropertyGrid, - "PropertyGrid instance should remain the same."); - + Assert.IsNull(viewHost.ActiveDocumentView); + Assert.AreSame(originalPropertyGrid, mainWindow.PropertyGrid, "PropertyGrid instance should remain the same."); Assert.AreEqual("Eigenschappen", mainWindow.PropertyGrid.Text); Assert.AreEqual(selectedObjectProperties, mainWindow.PropertyGrid.Data); } + mocks.VerifyAll(); } @@ -535,36 +404,20 @@ [Test] [STAThread] - [TestCase(false)] - [TestCase(true)] - public void InitializeToolWindows_GuiSet_InitializePropertyGridAndMessageWindowAndMakeActive(bool messageWindowAddedToViewList) + public void InitializeToolWindows_GuiSet_InitializePropertyGridAndMessageWindowAndMakeActive() { // Setup var selectedObject = new object(); var mocks = new MockRepository(); var selectedObjectProperties = mocks.Stub(); - - var toolWindowList = mocks.Stub(); - toolWindowList.Expect(l => l.Add(Arg.Matches(grid => - grid.Text == "Eigenschappen" && - grid.Data == selectedObjectProperties), - Arg.Is.Equal(ViewLocation.Right | ViewLocation.Bottom))); - - toolWindowList.Stub(l => l.Contains(Arg.Matches(messages => messages.Text == "Berichten"))) - .Return(messageWindowAddedToViewList); - if (!messageWindowAddedToViewList) - { - toolWindowList.Expect(l => l.Add(Arg.Matches(messages => messages.Text == "Berichten"), - Arg.Is.Equal(ViewLocation.Bottom))); - } - + var viewHost = new AvalonDockViewHost(); var propertyResolver = mocks.Stub(); propertyResolver.Expect(r => r.GetObjectProperties(selectedObject)) .Return(selectedObjectProperties); var gui = mocks.Stub(); - gui.Stub(g => g.ToolWindowViews).Return(toolWindowList); + gui.Stub(g => g.ViewHost).Return(viewHost); gui.Selection = selectedObject; gui.Stub(g => g.PropertyResolver).Return(propertyResolver); gui.Stub(g => g.SelectionChanged += null).IgnoreArguments(); @@ -586,8 +439,7 @@ Assert.IsInstanceOf(mainWindow.MessageWindow); Assert.AreEqual("Berichten", mainWindow.MessageWindow.Text); - Assert.AreSame(mainWindow.PropertyGrid, toolWindowList.ActiveView, - "PropertyGrid should be active view."); + Assert.IsNull(viewHost.ActiveDocumentView); } mocks.VerifyAll(); } @@ -699,7 +551,7 @@ mainWindow.SetGui(gui); // Call - mainWindow.ShowStartPage(true); + mainWindow.ShowStartPage(); } // Assert mocks.VerifyAll(); // Assert that expectancies are met Index: Core/Common/test/Core.Common.Gui.Test/GuiCoreTest.cs =================================================================== diff -u -r6fefc4422dcc5076f0ff430f73d829a6670f0285 -r5a856571ad752251b382db7c2b018a7e0cd1cca1 --- Core/Common/test/Core.Common.Gui.Test/GuiCoreTest.cs (.../GuiCoreTest.cs) (revision 6fefc4422dcc5076f0ff430f73d829a6670f0285) +++ Core/Common/test/Core.Common.Gui.Test/GuiCoreTest.cs (.../GuiCoreTest.cs) (revision 5a856571ad752251b382db7c2b018a7e0cd1cca1) @@ -20,7 +20,6 @@ // All rights reserved. using System; -using System.Collections.Generic; using System.Collections.Specialized; using System.Configuration; using System.Linq; @@ -31,17 +30,15 @@ using Core.Common.Base.Plugin; using Core.Common.Base.Storage; using Core.Common.Controls.TreeView; -using Core.Common.Controls.Views; using Core.Common.Gui.Commands; using Core.Common.Gui.ContextMenu; -using Core.Common.Gui.Forms; using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.Forms.MessageWindow; using Core.Common.Gui.Forms.PropertyGridView; +using Core.Common.Gui.Forms.ViewHost; using Core.Common.Gui.Plugin; using Core.Common.Gui.Settings; -using Core.Common.Gui.Test.Forms.ViewManager; -using Core.Common.Gui.Theme; +using Core.Common.Gui.Test.Forms.ViewHost; using Core.Common.TestUtil; using log4net; @@ -108,9 +105,8 @@ Assert.IsInstanceOf(gui.ViewCommands); Assert.AreEqual(null, gui.ApplicationCommands); - Assert.AreEqual(null, gui.ActiveView); - Assert.AreEqual(null, gui.DocumentViews); - Assert.AreEqual(null, gui.DocumentViewsResolver); + Assert.AreEqual(null, gui.ViewHost); + Assert.AreEqual(null, gui.DocumentViewController); AssertDefaultUserSettings(gui.UserSettings); Assert.AreSame(guiCoreSettings, gui.FixedSettings); @@ -119,8 +115,6 @@ Assert.AreEqual(mainWindow, gui.MainWindow); - Assert.AreEqual(null, gui.ToolWindowViews); - Assert.AreSame(ViewPropertyEditor.ViewCommands, gui.ViewCommands); // Check for OS settings that allow visual styles to be rendered in the first place: @@ -385,13 +379,13 @@ { gui.Run(); - gui.OpenToolView(toolView); + gui.ViewHost.AddToolView(toolView, ToolViewLocation.Left); // Call gui.Dispose(); // Assert - Assert.IsNull(gui.ToolWindowViews); + Assert.IsEmpty(gui.ViewHost.ToolViews); Assert.IsTrue(toolView.IsDisposed); } mocks.VerifyAll(); @@ -411,14 +405,14 @@ { gui.Run(); - gui.DocumentViews.Add(documentView); + gui.ViewHost.AddDocumentView(documentView); // Call gui.Dispose(); // Assert - Assert.IsNull(gui.DocumentViews); - Assert.IsNull(gui.DocumentViewsResolver); + Assert.IsEmpty(gui.ViewHost.DocumentViews); + Assert.IsNull(gui.DocumentViewController); Assert.IsTrue(documentView.IsDisposed); } mocks.VerifyAll(); @@ -732,7 +726,7 @@ [Test] [STAThread] - public void Run_InitializesDocumentViewController() + public void Run_InitializesViewController() { // Setup var mocks = new MockRepository(); @@ -742,42 +736,18 @@ using (var gui = new GuiCore(new MainWindow(), projectStore, new ApplicationCore(), new GuiCoreSettings())) { // Call - Action call = () => gui.Run(); + gui.Run(); // Assert - var expectedMessage = "Schermmanager voor documenten aan het maken..."; - TestHelper.AssertLogMessageIsGenerated(call, expectedMessage); + CollectionAssert.IsEmpty(gui.ViewHost.DocumentViews); + Assert.IsNull(gui.ViewHost.ActiveDocumentView); - CollectionAssert.IsEmpty(gui.DocumentViews); - Assert.IsFalse(gui.DocumentViews.IgnoreActivation); - Assert.IsNull(gui.DocumentViews.ActiveView); - - Assert.IsNotNull(gui.DocumentViewsResolver); - CollectionAssert.IsEmpty(gui.DocumentViewsResolver.DefaultViewTypes); - } - mocks.VerifyAll(); - } + Assert.AreEqual(2, gui.ViewHost.ToolViews.Count()); + Assert.AreEqual(1, gui.ViewHost.ToolViews.Count(v => v is PropertyGridView)); + Assert.AreEqual(1, gui.ViewHost.ToolViews.Count(v => v is MessageWindow)); - [Test] - [STAThread] - public void Run_InitializesToolViewController() - { - // Setup - var mocks = new MockRepository(); - var projectStore = mocks.Stub(); - mocks.ReplayAll(); - - using (var gui = new GuiCore(new MainWindow(), projectStore, new ApplicationCore(), new GuiCoreSettings())) - { - // Call - gui.Run(); - - // Assert - Assert.AreEqual(2, gui.ToolWindowViews.Count); - Assert.AreEqual(1, gui.ToolWindowViews.Count(v => v is PropertyGridView)); - Assert.AreEqual(1, gui.ToolWindowViews.Count(v => v is MessageWindow)); - Assert.IsFalse(gui.ToolWindowViews.IgnoreActivation); - Assert.IsNull(gui.ToolWindowViews.ActiveView); + Assert.IsNotNull(gui.DocumentViewController); + CollectionAssert.IsEmpty(gui.DocumentViewController.DefaultViewTypes); } mocks.VerifyAll(); } @@ -902,39 +872,6 @@ [Test] [RequiresSTA] - public void ActiveViewChanged_LastDocumentViewClosed_EventFired() - { - // Setup - var mocks = new MockRepository(); - var projectStore = mocks.Stub(); - mocks.ReplayAll(); - - using (var gui = new GuiCore(new MainWindow(), projectStore, new ApplicationCore(), new GuiCoreSettings())) - { - gui.Run(); - - var view = new TestView(); - - // Precondition - Assert.AreEqual(0, gui.DocumentViews.Count); - - gui.DocumentViews.Add(view); - - var hitCount = 0; - gui.ActiveViewChanged += (s, e) => hitCount++; - - // Call - gui.DocumentViews.RemoveAt(0); - - // Assert - Assert.AreEqual(0, gui.DocumentViews.Count); - Assert.AreEqual(1, hitCount); - } - mocks.VerifyAll(); - } - - [Test] - [RequiresSTA] public void GetTreeNodeInfos_NoPluginsConfigured_EmptyList() { // Setup @@ -964,13 +901,13 @@ }; var nodesPluginB = new[] { - new TreeNodeInfo(), + new TreeNodeInfo() }; var nodesPluginC = new[] { new TreeNodeInfo(), new TreeNodeInfo(), - new TreeNodeInfo(), + new TreeNodeInfo() }; var mocks = new MockRepository(); @@ -1065,41 +1002,6 @@ [Test] [STAThread] - public void GivenGuiRunCalled_WhenMainWindowOpens_EnsurePropertyGridAndMessageWindowAreActivated() - { - // Setup - var mocks = new MockRepository(); - var projectStore = mocks.Stub(); - mocks.ReplayAll(); - - using (var mainWindow = new MainWindow()) - using (var gui = new GuiCore(mainWindow, projectStore, new ApplicationCore(), new GuiCoreSettings())) - { - gui.Run(); - - var projectExplorerMock = new ProjectExplorerMock(); - gui.ToolWindowViews.Add(projectExplorerMock); - - var activatedViewsDuringShow = new List(); - gui.ToolWindowViews.ActiveViewChanged += (sender, args) => - { - activatedViewsDuringShow.Add(args.View); - }; - - // Call - mainWindow.Show(); - - // Assert - Assert.AreEqual(3, activatedViewsDuringShow.Count); - Assert.AreEqual(1, activatedViewsDuringShow.Count(v => v is MessageWindow)); - Assert.AreEqual(1, activatedViewsDuringShow.Count(v => v is PropertyGrid)); - Assert.AreEqual(1, activatedViewsDuringShow.Count(v => ReferenceEquals(v, projectExplorerMock))); - } - mocks.VerifyAll(); - } - - [Test] - [STAThread] public void Project_SetNewValue_FireProjectClosingAndOpenedEvents() { // Setup @@ -1148,7 +1050,7 @@ private static void AssertDefaultUserSettings(SettingsBase settings) { Assert.IsNotNull(settings); - Assert.AreEqual(15, settings.Properties.Count); + Assert.AreEqual(7, settings.Properties.Count); // Note: Cannot assert particular values, as they can be changed by user. var mruList = (StringCollection)settings["mruList"]; @@ -1159,32 +1061,12 @@ Assert.IsNotNull(defaultViews); var lastVisitedPath = (string)settings["lastVisitedPath"]; Assert.IsNotNull(lastVisitedPath); - var isMainWindowFullScreen = (bool)settings["MainWindow_FullScreen"]; - Assert.IsNotNull(isMainWindowFullScreen); - var x = (int)settings["MainWindow_X"]; - Assert.IsNotNull(x); - var y = (int)settings["MainWindow_Y"]; - Assert.IsNotNull(y); - var width = (int)settings["MainWindow_Width"]; - Assert.IsNotNull(width); - var height = (int)settings["MainWindow_Height"]; - Assert.IsNotNull(height); var startPageName = (string)settings["startPageName"]; Assert.IsNotNull(startPageName); var showStartPage = (bool)settings["showStartPage"]; Assert.IsNotNull(showStartPage); var showSplashScreen = (bool)settings["showSplashScreen"]; Assert.IsNotNull(showSplashScreen); - var showHiddenDataItems = (bool)settings["showHiddenDataItems"]; - Assert.IsNotNull(showHiddenDataItems); - var colorTheme = (ColorTheme)settings["colorTheme"]; - Assert.IsNotNull(colorTheme); } - - private class ProjectExplorerMock : UserControl, IProjectExplorer - { - public object Data { get; set; } - public TreeViewControl TreeViewControl { get; private set; } - } } } \ No newline at end of file Index: Core/Plugins/src/Core.Plugins.DotSpatial/DotSpatialGuiPlugin.cs =================================================================== diff -u -r6fefc4422dcc5076f0ff430f73d829a6670f0285 -r5a856571ad752251b382db7c2b018a7e0cd1cca1 --- Core/Plugins/src/Core.Plugins.DotSpatial/DotSpatialGuiPlugin.cs (.../DotSpatialGuiPlugin.cs) (revision 6fefc4422dcc5076f0ff430f73d829a6670f0285) +++ Core/Plugins/src/Core.Plugins.DotSpatial/DotSpatialGuiPlugin.cs (.../DotSpatialGuiPlugin.cs) (revision 5a856571ad752251b382db7c2b018a7e0cd1cca1) @@ -23,7 +23,6 @@ using System.Collections.Generic; using Core.Common.Gui; using Core.Common.Gui.Forms; -using Core.Common.Gui.Forms.ViewManager; using Core.Common.Gui.Plugin; using Core.Common.Gui.Properties; using Core.Components.Gis.Data; @@ -56,16 +55,16 @@ mapLegendController = CreateLegendController(Gui); mapRibbon = CreateMapRibbon(); - mapLegendController.ToggleLegend(); - Gui.ActiveViewChanged += GuiOnActiveViewChanged; + mapLegendController.ToggleView(); + Gui.ViewHost.ActiveDocumentViewChanged += OnActiveDocumentViewChanged; activated = true; } public override void Dispose() { if (activated) { - Gui.ActiveViewChanged -= GuiOnActiveViewChanged; + Gui.ViewHost.ActiveDocumentViewChanged -= OnActiveDocumentViewChanged; } base.Dispose(); } @@ -79,15 +78,15 @@ }; } - private MapLegendController CreateLegendController(IToolViewController toolViewController) + private MapLegendController CreateLegendController(IViewController viewController) { - if (toolViewController == null) + if (viewController == null) { - throw new ArgumentNullException("toolViewController", "Cannot create a MapLegendController when the tool view controller is null"); + throw new ArgumentNullException("viewController", "Cannot create a MapLegendController when the view controller is null"); } - var controller = new MapLegendController(toolViewController, Gui, Gui.MainWindow); - controller.OnOpenLegend += (s, e) => UpdateComponentsForActiveView(); + var controller = new MapLegendController(viewController, Gui, Gui.MainWindow); + controller.OnOpenLegend += (s, e) => UpdateComponentsForActiveDocumentView(); return controller; } @@ -99,18 +98,18 @@ }; } - private void GuiOnActiveViewChanged(object sender, ActiveViewChangeEventArgs activeViewChangeEventArgs) + private void OnActiveDocumentViewChanged(object sender, EventArgs e) { - UpdateComponentsForActiveView(); + UpdateComponentsForActiveDocumentView(); } /// /// Updates the components which the knows about so that it reflects /// the currently active view. /// - private void UpdateComponentsForActiveView() + private void UpdateComponentsForActiveDocumentView() { - var mapView = Gui.ActiveView as IMapView; + var mapView = Gui.ViewHost.ActiveDocumentView as IMapView; if (mapView != null) { mapRibbon.Map = mapView.Map; Index: Core/Plugins/src/Core.Plugins.OxyPlot/OxyPlotGuiPlugin.cs =================================================================== diff -u -r6fefc4422dcc5076f0ff430f73d829a6670f0285 -r5a856571ad752251b382db7c2b018a7e0cd1cca1 --- Core/Plugins/src/Core.Plugins.OxyPlot/OxyPlotGuiPlugin.cs (.../OxyPlotGuiPlugin.cs) (revision 6fefc4422dcc5076f0ff430f73d829a6670f0285) +++ Core/Plugins/src/Core.Plugins.OxyPlot/OxyPlotGuiPlugin.cs (.../OxyPlotGuiPlugin.cs) (revision 5a856571ad752251b382db7c2b018a7e0cd1cca1) @@ -19,10 +19,10 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Collections.Generic; using Core.Common.Gui; using Core.Common.Gui.Forms; -using Core.Common.Gui.Forms.ViewManager; using Core.Common.Gui.Plugin; using Core.Components.Charting.Data; using Core.Components.Charting.Forms; @@ -57,8 +57,8 @@ chartLegendController = CreateLegendController(Gui); chartingRibbon = CreateRibbon(chartLegendController, Gui); - chartLegendController.ToggleLegend(); - Gui.ActiveViewChanged += GuiOnActiveViewChanged; + chartLegendController.ToggleView(); + Gui.ViewHost.ActiveDocumentViewChanged += OnActiveDocumentViewChanged; activated = true; } @@ -75,21 +75,22 @@ { if (activated) { - Gui.ActiveViewChanged -= GuiOnActiveViewChanged; + Gui.ViewHost.ActiveDocumentViewChanged -= OnActiveDocumentViewChanged; } + base.Dispose(); } /// /// Creates a new . /// - /// The to use for the controller + /// The to use for the controller /// . /// A new instance. - private ChartLegendController CreateLegendController(IToolViewController toolViewController) + private ChartLegendController CreateLegendController(IViewController viewController) { - var controller = new ChartLegendController(toolViewController); - controller.OnOpenLegend += (s,e) => UpdateComponentsForActiveView(); + var controller = new ChartLegendController(viewController); + controller.OnOpenLegend += (s,e) => UpdateComponentsForActiveDocumentView(); return controller; } @@ -98,28 +99,28 @@ /// /// The to use for the /// . - /// The controller for Document Views. + /// The controller for views. /// A new instance. - private static ChartingRibbon CreateRibbon(ChartLegendController chartLegendController, IDocumentViewController documentViewController) + private static ChartingRibbon CreateRibbon(ChartLegendController chartLegendController, IViewController viewController) { return new ChartingRibbon { ToggleLegendViewCommand = new ToggleLegendViewCommand(chartLegendController) }; } - private void GuiOnActiveViewChanged(object sender, ActiveViewChangeEventArgs activeViewChangeEventArgs) + private void OnActiveDocumentViewChanged(object sender, EventArgs e) { - UpdateComponentsForActiveView(); + UpdateComponentsForActiveDocumentView(); } /// /// Updates the components which the knows about so that it reflects /// the currently active view. /// - private void UpdateComponentsForActiveView() + private void UpdateComponentsForActiveDocumentView() { - var chartView = Gui.ActiveView as IChartView; + var chartView = Gui.ViewHost.ActiveDocumentView as IChartView; if (chartView != null) { chartingRibbon.Chart = chartView.Chart; Index: Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorerGuiPlugin.cs =================================================================== diff -u -r6fefc4422dcc5076f0ff430f73d829a6670f0285 -r5a856571ad752251b382db7c2b018a7e0cd1cca1 --- Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorerGuiPlugin.cs (.../ProjectExplorerGuiPlugin.cs) (revision 6fefc4422dcc5076f0ff430f73d829a6670f0285) +++ Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorerGuiPlugin.cs (.../ProjectExplorerGuiPlugin.cs) (revision 5a856571ad752251b382db7c2b018a7e0cd1cca1) @@ -38,9 +38,8 @@ { public class ProjectExplorerGuiPlugin : PluginBase { - private IToolViewController toolViewController; + private IViewController viewController; private ProjectExplorerViewController projectExplorerViewController; - private IDocumentViewController documentViewController; private IViewCommands viewCommands; private IProjectOwner projectOwner; private IApplicationSelection applicationSelection; @@ -68,19 +67,17 @@ if (value != null) { - toolViewController = value; + viewController = value; projectOwner = value; applicationSelection = value; - documentViewController = value; viewCommands = value.ViewCommands; treeNodeInfos = value.GetTreeNodeInfos(); } else { - toolViewController = null; + viewController = null; projectOwner = null; applicationSelection = null; - documentViewController = null; viewCommands = null; treeNodeInfos = null; } @@ -144,7 +141,7 @@ base.Activate(); try { - projectExplorerViewController = new ProjectExplorerViewController(documentViewController, viewCommands, applicationSelection, toolViewController, treeNodeInfos); + projectExplorerViewController = new ProjectExplorerViewController(viewCommands, applicationSelection, viewController, treeNodeInfos); } catch (ArgumentNullException e) { @@ -158,7 +155,7 @@ }; projectExplorerViewController.OnOpenView += (s, e) => UpdateProject(); - projectExplorerViewController.OpenView(); + projectExplorerViewController.ToggleView(); projectOwner.ProjectOpened += ApplicationProjectOpened; active = true; @@ -167,10 +164,8 @@ public override void Dispose() { Deactivate(); - if (projectExplorerViewController != null) - { - projectExplorerViewController.Dispose(); - } + + base.Dispose(); } public override void Deactivate() Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/DotSpatialGuiPluginTest.cs =================================================================== diff -u -r6fefc4422dcc5076f0ff430f73d829a6670f0285 -r5a856571ad752251b382db7c2b018a7e0cd1cca1 --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/DotSpatialGuiPluginTest.cs (.../DotSpatialGuiPluginTest.cs) (revision 6fefc4422dcc5076f0ff430f73d829a6670f0285) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/DotSpatialGuiPluginTest.cs (.../DotSpatialGuiPluginTest.cs) (revision 5a856571ad752251b382db7c2b018a7e0cd1cca1) @@ -28,12 +28,11 @@ using Core.Common.Controls.Views; using Core.Common.Gui; using Core.Common.Gui.Forms.MainWindow; +using Core.Common.Gui.Forms.ViewHost; using Core.Common.Gui.Plugin; using Core.Common.Gui.Settings; using Core.Components.DotSpatial.Forms; -using Core.Components.DotSpatial.TestUtil; using Core.Components.Gis.Data; -using Core.Components.Gis.Forms; using Core.Plugins.DotSpatial.Forms; using Core.Plugins.DotSpatial.Legend; using NUnit.Framework; @@ -68,47 +67,31 @@ // Assert ArgumentNullException exception = Assert.Throws(test); - Assert.AreEqual("toolViewController", exception.ParamName); + Assert.AreEqual("viewController", exception.ParamName); } } [Test] [RequiresSTA] - [TestCase(true)] - [TestCase(false)] - public void Activate_WithGui_InitializeComponentsWithIMapViewAndBindsActiveViewChanged(bool useMapView) + public void Activate_WithGui_AddsMapLegendView() { // Setup var mocks = new MockRepository(); - IView view; - - if (useMapView) - { - var mapView = mocks.Stub(); - var map = new MapControl(); - map.Data.Add(new TestMapData("test data")); - mapView.Stub(v => v.Map).Return(map); - view = mapView; - } - else - { - view = mocks.StrictMock(); - } - using (var plugin = new DotSpatialGuiPlugin()) { var gui = mocks.StrictMock(); - var mainWindow = mocks.StrictMock(); + var viewHost = mocks.Stub(); - gui.Stub(g => g.IsToolWindowOpen()).Return(false); - - gui.Expect(g => g.OpenToolView(Arg.Matches(c => true))); - gui.Expect(g => g.ActiveViewChanged += null).IgnoreArguments(); - gui.Expect(g => g.ActiveViewChanged -= null).IgnoreArguments(); - gui.Expect(g => g.ActiveView).Return(view); gui.Expect(g => g.MainWindow).Return(mainWindow); + gui.Stub(g => g.ViewHost).Return(viewHost); + viewHost.Expect(vm => vm.ToolViews).Return(new IView[0]); + viewHost.Expect(vm => vm.AddToolView(Arg.Matches(c => true), 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(); mocks.ReplayAll(); @@ -148,7 +131,7 @@ [RequiresSTA] [TestCase(true)] [TestCase(false)] - public void GivenConfiguredGui_WhenActiveViewChangesToViewWithMap_ThenRibbonSetVisibility(bool visible) + public void GivenConfiguredGui_WhenActiveDocumentViewChangesToViewWithMap_ThenRibbonSetVisibility(bool visible) { // Given var mocks = new MockRepository(); @@ -169,8 +152,7 @@ gui.Run(); // When - gui.DocumentViews.Add(viewMock); - gui.DocumentViews.ActiveView = viewMock; + gui.ViewHost.AddDocumentView(viewMock); // Then Assert.AreEqual(visible ? Visibility.Visible : Visibility.Collapsed, plugin.RibbonCommandHandler.GetRibbonControl().ContextualGroups[0].Visibility); Index: Core/Plugins/test/Core.Plugins.OxyPlot.Test/OxyPlotGuiPluginTest.cs =================================================================== diff -u -r6fefc4422dcc5076f0ff430f73d829a6670f0285 -r5a856571ad752251b382db7c2b018a7e0cd1cca1 --- Core/Plugins/test/Core.Plugins.OxyPlot.Test/OxyPlotGuiPluginTest.cs (.../OxyPlotGuiPluginTest.cs) (revision 6fefc4422dcc5076f0ff430f73d829a6670f0285) +++ Core/Plugins/test/Core.Plugins.OxyPlot.Test/OxyPlotGuiPluginTest.cs (.../OxyPlotGuiPluginTest.cs) (revision 5a856571ad752251b382db7c2b018a7e0cd1cca1) @@ -28,11 +28,10 @@ using Core.Common.Controls.Views; using Core.Common.Gui; using Core.Common.Gui.Forms.MainWindow; +using Core.Common.Gui.Forms.ViewHost; using Core.Common.Gui.Plugin; using Core.Common.Gui.Settings; using Core.Components.Charting.Data; -using Core.Components.Charting.Forms; -using Core.Components.Charting.TestUtil; using Core.Components.OxyPlot.Forms; using Core.Plugins.OxyPlot.Forms; using Core.Plugins.OxyPlot.Legend; @@ -73,38 +72,24 @@ [Test] [RequiresSTA] - [TestCase(true)] - [TestCase(false)] - public void Activate_WithGui_InitializesComponentsWithIChartViewDataAndBindsActiveViewChanged(bool useChartView) + public void Activate_WithGui_AddsChartLegendView() { // Setup var mocks = new MockRepository(); - IView view; - if (useChartView) - { - var chartView = mocks.Stub(); - var chart = new ChartControl(); - chart.Data.Add(new TestChartData()); - chartView.Stub(v => v.Chart).Return(chart); - view = chartView; - } - else - { - view = mocks.StrictMock(); - } - using (var plugin = new OxyPlotGuiPlugin()) { var gui = mocks.StrictMock(); + var viewHost = mocks.Stub(); - gui.Stub(g => g.IsToolWindowOpen()).Return(false); + gui.Stub(g => g.ViewHost).Return(viewHost); + viewHost.Expect(vm => vm.ToolViews).Return(new IView[0]); + viewHost.Expect(vm => vm.AddToolView(Arg.Matches(c => true), 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(); - gui.Expect(g => g.OpenToolView(Arg.Matches(c => true))); - gui.Expect(g => g.ActiveViewChanged += null).IgnoreArguments(); - gui.Expect(g => g.ActiveViewChanged -= null).IgnoreArguments(); - gui.Expect(g => g.ActiveView).Return(view); - mocks.ReplayAll(); plugin.Gui = gui; @@ -142,7 +127,7 @@ [TestCase(true)] [TestCase(false)] [RequiresSTA] - public void GivenConfiguredGui_WhenActiveViewChangesToViewWithChart_ThenRibbonSetVisibility(bool visible) + public void GivenConfiguredGui_WhenActiveDocumentViewChangesToViewWithChart_ThenRibbonSetVisibility(bool visible) { // Given var mocks = new MockRepository(); @@ -163,8 +148,7 @@ gui.Run(); // When - gui.DocumentViews.Add(viewMock); - gui.DocumentViews.ActiveView = viewMock; + gui.ViewHost.AddDocumentView(viewMock); // Then Assert.AreEqual(visible ? Visibility.Visible : Visibility.Collapsed, plugin.RibbonCommandHandler.GetRibbonControl().ContextualGroups[0].Visibility); Index: Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectExplorerGuiPluginTest.cs =================================================================== diff -u -r6fefc4422dcc5076f0ff430f73d829a6670f0285 -r5a856571ad752251b382db7c2b018a7e0cd1cca1 --- Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectExplorerGuiPluginTest.cs (.../ProjectExplorerGuiPluginTest.cs) (revision 6fefc4422dcc5076f0ff430f73d829a6670f0285) +++ Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectExplorerGuiPluginTest.cs (.../ProjectExplorerGuiPluginTest.cs) (revision 5a856571ad752251b382db7c2b018a7e0cd1cca1) @@ -19,13 +19,14 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using System.Collections.Generic; using System.Linq; using Core.Common.Base.Data; using Core.Common.Controls.TreeView; +using Core.Common.Controls.Views; using Core.Common.Gui; using Core.Common.Gui.Commands; +using Core.Common.Gui.Forms.ViewHost; using Core.Common.Gui.Plugin; using Core.Plugins.ProjectExplorer.Exceptions; using Core.Plugins.ProjectExplorer.Properties; @@ -51,40 +52,6 @@ } [Test] - [RequiresSTA] - public void RegisteringTreeNodeAddsToTreeView() - { - // Setup - var mocks = new MockRepository(); - using (var projectExplorerGuiPlugin = new ProjectExplorerGuiPlugin()) - { - var gui = mocks.StrictMock(); - var otherGuiPlugin = mocks.StrictMock(); - - gui.Expect(g => g.ViewCommands).Return(mocks.Stub()); - gui.Expect(g => g.GetTreeNodeInfos()).Return(Enumerable.Empty()); - - gui.Expect(g => g.IsToolWindowOpen()).Return(true); - - gui.Expect(g => g.ProjectOpened += Arg>.Is.Anything); - gui.Expect(g => g.ProjectOpened -= Arg>.Is.Anything); - - gui.Expect(g => g.Plugins).Return(new List - { - projectExplorerGuiPlugin, otherGuiPlugin - }).Repeat.Any(); - - mocks.ReplayAll(); - - projectExplorerGuiPlugin.Gui = gui; - - // Call - projectExplorerGuiPlugin.Activate(); - } - mocks.VerifyAll(); - } - - [Test] public void Activate_WithoutGui_ThrowsPluginActivationException() { // Setup @@ -107,15 +74,17 @@ // Setup var mocks = new MockRepository(); var guiStub = mocks.Stub(); + var viewHost = mocks.Stub(); guiStub.Stub(g => g.ApplicationCommands).Return(mocks.Stub()); guiStub.Stub(g => g.ProjectCommands).Return(mocks.Stub()); guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); guiStub.Stub(g => g.GetTreeNodeInfos()).Return(Enumerable.Empty()); - guiStub.Stub(g => g.IsToolWindowOpen()).Return(false); - guiStub.Stub(g => g.OpenToolView(Arg.Is.TypeOf)); + viewHost.Stub(vm => vm.ToolViews).Return(new IView[0]); + viewHost.Stub(vm => vm.AddToolView(Arg.Is.TypeOf, Arg.Matches(vl => vl == ToolViewLocation.Left))); + viewHost.Stub(vm => vm.SetImage(null, null)).IgnoreArguments(); + guiStub.Stub(g => g.ViewHost).Return(viewHost); guiStub.Stub(g => g.SelectionChanged += null).IgnoreArguments(); guiStub.Stub(g => g.SelectionChanged -= null).IgnoreArguments(); - guiStub.Expect(g => g.ProjectOpened += null).IgnoreArguments(); guiStub.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); mocks.ReplayAll(); @@ -140,12 +109,15 @@ // Setup var mocks = new MockRepository(); var guiStub = mocks.Stub(); + var viewHost = mocks.Stub(); guiStub.Stub(g => g.ApplicationCommands).Return(mocks.Stub()); guiStub.Stub(g => g.ProjectCommands).Return(mocks.Stub()); guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); guiStub.Stub(g => g.GetTreeNodeInfos()).Return(Enumerable.Empty()); - guiStub.Stub(g => g.IsToolWindowOpen()).Return(false); - guiStub.Stub(g => g.OpenToolView(Arg.Is.TypeOf)); + viewHost.Stub(vm => vm.ToolViews).Return(new IView[0]); + viewHost.Stub(vm => vm.AddToolView(Arg.Is.TypeOf, Arg.Matches(vl => vl == ToolViewLocation.Left))); + viewHost.Stub(vm => vm.SetImage(null, null)).IgnoreArguments(); + guiStub.Stub(g => g.ViewHost).Return(viewHost); guiStub.Stub(g => g.SelectionChanged += null).IgnoreArguments(); guiStub.Stub(g => g.SelectionChanged -= null).IgnoreArguments(); guiStub.Stub(g => g.ProjectOpened += null).IgnoreArguments(); @@ -177,12 +149,15 @@ // Setup var mocks = new MockRepository(); var guiStub = mocks.Stub(); + var viewHost = mocks.Stub(); guiStub.Stub(g => g.ApplicationCommands).Return(mocks.Stub()); guiStub.Stub(g => g.ProjectCommands).Return(mocks.Stub()); guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); guiStub.Stub(g => g.GetTreeNodeInfos()).Return(Enumerable.Empty()); - guiStub.Stub(g => g.IsToolWindowOpen()).Return(false); - guiStub.Stub(g => g.OpenToolView(Arg.Is.TypeOf)); + viewHost.Stub(vm => vm.ToolViews).Return(new IView[0]); + viewHost.Stub(vm => vm.AddToolView(Arg.Is.TypeOf, Arg.Matches(vl => vl == ToolViewLocation.Left))); + viewHost.Stub(vm => vm.SetImage(null, null)).IgnoreArguments(); + guiStub.Stub(g => g.ViewHost).Return(viewHost); guiStub.Stub(g => g.SelectionChanged += null).IgnoreArguments(); guiStub.Stub(g => g.SelectionChanged -= null).IgnoreArguments(); guiStub.Stub(g => g.ProjectOpened += null).IgnoreArguments(); @@ -306,6 +281,7 @@ // Setup var mocks = new MockRepository(); var guiStub = mocks.Stub(); + var viewHost = mocks.StrictMock(); guiStub.Stub(g => g.ApplicationCommands).Return(mocks.Stub()); guiStub.Stub(g => g.ProjectCommands).Return(mocks.Stub()); guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); @@ -316,29 +292,22 @@ TagType = typeof(Project) } }); + guiStub.Stub(g => g.ViewHost).Return(viewHost); - ProjectExplorer view = null; - - using (mocks.Ordered()) + // Activate + var toolViews = new List(); + viewHost.Stub(vm => vm.ToolViews).Return(toolViews); + viewHost.Expect(vm => vm.AddToolView(Arg.Matches(v => true), Arg.Matches(vl => vl == ToolViewLocation.Left))).WhenCalled(invocation => { - // Activate - guiStub.Expect(tvc => tvc.IsToolWindowOpen()).Return(false); - guiStub.Expect(tvc => tvc.OpenToolView(Arg.Matches(v => true))).WhenCalled(invocation => { - view = invocation.Arguments[0] as ProjectExplorer; - }); - guiStub.Expect(tvc => tvc.IsToolWindowOpen()).Return(true); - guiStub.Expect(dvc => dvc.UpdateToolTips()); - guiStub.Expect(g => g.ProjectOpened += null).IgnoreArguments(); + toolViews.Add(invocation.Arguments[0] as ProjectExplorer); + }); + viewHost.Expect(vm => vm.SetImage(null, null)).IgnoreArguments(); - // UpdateProject - guiStub.Expect(tvc => tvc.IsToolWindowOpen()).Return(true); - guiStub.Expect(dvc => dvc.UpdateToolTips()); + // Dispose + viewHost.Expect(tvc => tvc.Remove(Arg.Matches(v => true))); - // Dispose - guiStub.Expect(g => g.ProjectOpened -= null).IgnoreArguments(); - guiStub.Expect(tvc => tvc.IsToolWindowOpen()).Return(true); - guiStub.Expect(tvc => tvc.CloseToolView(Arg.Matches(v => true))); - } + guiStub.Expect(g => g.ProjectOpened += null).IgnoreArguments(); + guiStub.Expect(g => g.ProjectOpened -= null).IgnoreArguments(); mocks.ReplayAll(); @@ -352,15 +321,16 @@ plugin.Activate(); // Precondition - Assert.AreSame(view.Data, initialProject); + Assert.AreEqual(1, toolViews.Count); + Assert.AreSame(initialProject, toolViews[0].Data); // Call var newProject = new Project(); guiStub.Project = newProject; guiStub.Raise(s => s.ProjectOpened += null, newProject); // Assert - Assert.AreSame(view.Data, newProject); + Assert.AreSame(newProject, toolViews[0].Data); } } }