Index: Core/Plugins/src/Core.Plugins.ProjectExplorer/Commands/ShowProjectExplorerCommand.cs =================================================================== diff -u -rd1a8aeaa05c36dfe386de7586dd129819594ee97 -ra6df46f9508fcedf716bb84ec0076d7df104155f --- Core/Plugins/src/Core.Plugins.ProjectExplorer/Commands/ShowProjectExplorerCommand.cs (.../ShowProjectExplorerCommand.cs) (revision d1a8aeaa05c36dfe386de7586dd129819594ee97) +++ Core/Plugins/src/Core.Plugins.ProjectExplorer/Commands/ShowProjectExplorerCommand.cs (.../ShowProjectExplorerCommand.cs) (revision a6df46f9508fcedf716bb84ec0076d7df104155f) @@ -1,9 +1,17 @@ +using Core.Common.Controls.Commands; using Core.Common.Gui; namespace Core.Plugins.ProjectExplorer.Commands { - public class ShowProjectExplorerCommand : IGuiCommand + public class ShowProjectExplorerCommand : ICommand { + private readonly IToolViewController toolViewController; + + public ShowProjectExplorerCommand(IToolViewController toolViewController) + { + this.toolViewController = toolViewController; + } + public bool Enabled { get @@ -16,25 +24,23 @@ { get { - if (Gui == null || Gui.ToolWindowViews == null) + if (toolViewController == null || toolViewController.ToolWindowViews == null) { return false; } - return Gui.ToolWindowViews.Contains(ProjectExplorerGuiPlugin.Instance.ProjectExplorer); + return toolViewController.ToolWindowViews.Contains(ProjectExplorerGuiPlugin.Instance.ProjectExplorer); } } - public IGui Gui { get; set; } - public void Execute(params object[] arguments) { var view = ProjectExplorerGuiPlugin.Instance.ProjectExplorer; - var active = Gui.ToolWindowViews.Contains(view); + var active = toolViewController.ToolWindowViews.Contains(view); if (active) { - Gui.ToolWindowViews.Remove(view); + toolViewController.ToolWindowViews.Remove(view); } else { Index: Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorer.cs =================================================================== diff -u -r7993dddd622b104506d59a43fd9add82d6ce48ae -ra6df46f9508fcedf716bb84ec0076d7df104155f --- Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorer.cs (.../ProjectExplorer.cs) (revision 7993dddd622b104506d59a43fd9add82d6ce48ae) +++ Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorer.cs (.../ProjectExplorer.cs) (revision a6df46f9508fcedf716bb84ec0076d7df104155f) @@ -11,25 +11,27 @@ public partial class ProjectExplorer : UserControl, IProjectExplorer { private static readonly ILog log = LogManager.GetLogger(typeof(ProjectExplorer)); - private IGui gui; + private readonly IDocumentViewController documentViewController; + private readonly IViewCommands viewCommands; public ProjectExplorer() { InitializeComponent(); } - public ProjectExplorer(GuiPlugin guiPlugin) + public ProjectExplorer(IGui gui) { - gui = guiPlugin.Gui; + documentViewController = gui; + viewCommands = gui.ViewCommands; InitializeComponent(); - ProjectTreeView = new ProjectTreeView(guiPlugin) + ProjectTreeView = new ProjectTreeView(gui, viewCommands, gui, documentViewController) { Dock = DockStyle.Fill }; treeViewPanel.Controls.Add(ProjectTreeView); - gui.DocumentViews.ActiveViewChanged += DocumentViewsActiveViewChanged; + documentViewController.DocumentViews.ActiveViewChanged += DocumentViewsActiveViewChanged; } public ProjectTreeView ProjectTreeView { get; private set; } @@ -49,11 +51,10 @@ public new void Dispose() { ProjectTreeView.Data = null; - if (gui != null && gui.DocumentViews != null) + if (documentViewController != null && documentViewController.DocumentViews != null) { - gui.DocumentViews.ActiveViewChanged -= DocumentViewsActiveViewChanged; + documentViewController.DocumentViews.ActiveViewChanged -= DocumentViewsActiveViewChanged; } - gui = null; ProjectTreeView.Dispose(); base.Dispose(); @@ -82,21 +83,21 @@ private void DocumentViewsActiveViewChanged(object sender, ActiveViewChangeEventArgs e) { - buttonScrollToItemInActiveView.Enabled = gui.DocumentViews.ActiveView != null && - gui.ViewCommands.GetDataOfActiveView() != null; + buttonScrollToItemInActiveView.Enabled = documentViewController.DocumentViews.ActiveView != null && + viewCommands.GetDataOfActiveView() != null; } private void ButtonScrollToItemInActiveViewClick(object sender, EventArgs e) { - var dataOfActiveView = gui.ViewCommands.GetDataOfActiveView(); + var dataOfActiveView = viewCommands.GetDataOfActiveView(); if (dataOfActiveView != null) { ScrollTo(dataOfActiveView); return; } - log.WarnFormat(Resources.ProjectExplorer_ButtonScrollToItemInActiveViewClick_Can_t_find_project_item_for_view_data_0_, gui.DocumentViews.ActiveView.Data); + log.WarnFormat(Resources.ProjectExplorer_ButtonScrollToItemInActiveViewClick_Can_t_find_project_item_for_view_data_0_, documentViewController.DocumentViews.ActiveView.Data); } } } \ No newline at end of file Index: Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorerGuiPlugin.cs =================================================================== diff -u -r98939d3757e99732f74f6345b5eb58c90e30a4d4 -ra6df46f9508fcedf716bb84ec0076d7df104155f --- Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorerGuiPlugin.cs (.../ProjectExplorerGuiPlugin.cs) (revision 98939d3757e99732f74f6345b5eb58c90e30a4d4) +++ Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorerGuiPlugin.cs (.../ProjectExplorerGuiPlugin.cs) (revision a6df46f9508fcedf716bb84ec0076d7df104155f) @@ -26,7 +26,7 @@ { get { - return new Ribbon(); + return new Ribbon(Gui); } } @@ -64,7 +64,7 @@ { if ((ProjectExplorer == null) || (ProjectExplorer.IsDisposed)) { - ProjectExplorer = new ProjectExplorer(this); + ProjectExplorer = new ProjectExplorer(Gui); UpdateProjectTreeViewWithRegisteredNodePresenters(); Index: Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectTreeView.cs =================================================================== diff -u -rc193816bfb4f31ff0c79559c7c3ff4ddd9a3110b -ra6df46f9508fcedf716bb84ec0076d7df104155f --- Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectTreeView.cs (.../ProjectTreeView.cs) (revision c193816bfb4f31ff0c79559c7c3ff4ddd9a3110b) +++ Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectTreeView.cs (.../ProjectTreeView.cs) (revision a6df46f9508fcedf716bb84ec0076d7df104155f) @@ -1,7 +1,6 @@ using System; using System.Windows.Forms; using Core.Common.Base.Data; -using Core.Common.Base.Plugin; using Core.Common.Controls.Views; using Core.Common.Gui; using TreeNode = Core.Common.Controls.TreeView.TreeNode; @@ -15,19 +14,29 @@ public class ProjectTreeView : UserControl, IView { private readonly TreeView treeView; - private GuiPlugin guiPlugin; - private ApplicationCore applicationCore; - private IGui gui; + private readonly IApplicationSelection applicationSelection; + private readonly IViewCommands viewCommands; + private readonly IProjectOwner projectOwner; + private readonly IDocumentViewController documentViewController; private Project project; private bool selectingNode; - public ProjectTreeView(GuiPlugin guiPlugin) : this() + public ProjectTreeView(IApplicationSelection applicationSelection, IViewCommands viewCommands, + IProjectOwner projectOwner, IDocumentViewController documentViewController) + : this() { - GuiPlugin = guiPlugin; + this.applicationSelection = applicationSelection; + this.applicationSelection.SelectionChanged += GuiSelectionChanged; + + this.viewCommands = viewCommands; + + this.projectOwner = projectOwner; + + this.documentViewController = documentViewController; } - public ProjectTreeView() + private ProjectTreeView() { treeView = new TreeView { @@ -46,19 +55,6 @@ Controls.Add(treeView); } - public GuiPlugin GuiPlugin - { - set - { - guiPlugin = value; - - applicationCore = guiPlugin.Gui.ApplicationCore; - gui = guiPlugin.Gui; - - gui.SelectionChanged += GuiSelectionChanged; - } - } - public TreeView TreeView { get @@ -105,12 +101,9 @@ public new void Dispose() { - if (gui != null) - { - gui.SelectionChanged -= GuiSelectionChanged; - } + applicationSelection.SelectionChanged -= GuiSelectionChanged; - if (applicationCore != null) + if (project != null) { UnsubscribeProjectEvents(); } @@ -119,9 +112,6 @@ treeView.Dispose(); base.Dispose(); - - applicationCore = null; - gui = null; } /// @@ -131,13 +121,13 @@ /// protected virtual void GuiSelectionChanged(object sender, EventArgs e) { - if (selectingNode || gui.Selection == null - || (treeView.SelectedNode != null && treeView.SelectedNode.Tag == gui.Selection)) + if (selectingNode || applicationSelection.Selection == null + || (treeView.SelectedNode != null && treeView.SelectedNode.Tag == applicationSelection.Selection)) { return; } - TreeNode node = treeView.GetNodeByTag(gui.Selection); + TreeNode node = treeView.GetNodeByTag(applicationSelection.Selection); if (node != null) { treeView.SelectedNode = node; @@ -150,7 +140,7 @@ var tag = treeView.SelectedNode != null ? treeView.SelectedNode.Tag : null; - gui.Selection = tag; + applicationSelection.Selection = tag; selectingNode = false; } @@ -164,7 +154,7 @@ if (keyData == Keys.Enter) { - gui.ViewCommands.OpenViewForSelection(); + viewCommands.OpenViewForSelection(); return true; } @@ -178,9 +168,9 @@ if (keyData == Keys.Escape) { - if (gui.DocumentViews.ActiveView != null) + if (documentViewController.DocumentViews.ActiveView != null) { - ((Control) gui.DocumentViews.ActiveView).Focus(); + ((Control)documentViewController.DocumentViews.ActiveView).Focus(); } return true; @@ -196,15 +186,12 @@ private void SubscribeProjectEvents() { - gui.ProjectOpened += ApplicationCoreProjectOpened; + projectOwner.ProjectOpened += ApplicationCoreProjectOpened; } private void UnsubscribeProjectEvents() { - if (project != null) - { - gui.ProjectOpened -= ApplicationCoreProjectOpened; - } + projectOwner.ProjectOpened -= ApplicationCoreProjectOpened; } private void ApplicationCoreProjectOpened(Project project) @@ -214,17 +201,17 @@ private void TreeViewDoubleClick(object sender, EventArgs e) { - if (!Equals(gui.Selection, TreeView.SelectedNode.Tag)) + if (!Equals(applicationSelection.Selection, TreeView.SelectedNode.Tag)) { // Necessary if WinForms skips single click event (see TOOLS-8722)... - gui.Selection = TreeView.SelectedNode.Tag; + applicationSelection.Selection = TreeView.SelectedNode.Tag; } - gui.ViewCommands.OpenViewForSelection(); + viewCommands.OpenViewForSelection(); } private void ProjectDataDeleted(object sender, TreeView.TreeViewDataDeletedEventArgs e) { - gui.ViewCommands.RemoveAllViewsForItem(e.DeletedDataInstance); + viewCommands.RemoveAllViewsForItem(e.DeletedDataInstance); } } } \ No newline at end of file Index: Core/Plugins/src/Core.Plugins.ProjectExplorer/Ribbon.xaml.cs =================================================================== diff -u -r42ca97fdb85a553c6aac3bfdfe57c7be4af90821 -ra6df46f9508fcedf716bb84ec0076d7df104155f --- Core/Plugins/src/Core.Plugins.ProjectExplorer/Ribbon.xaml.cs (.../Ribbon.xaml.cs) (revision 42ca97fdb85a553c6aac3bfdfe57c7be4af90821) +++ Core/Plugins/src/Core.Plugins.ProjectExplorer/Ribbon.xaml.cs (.../Ribbon.xaml.cs) (revision a6df46f9508fcedf716bb84ec0076d7df104155f) @@ -2,6 +2,7 @@ using System.Windows; using Core.Common.Controls; using Core.Common.Controls.Commands; +using Core.Common.Gui; using Core.Common.Gui.Forms; using Core.Plugins.ProjectExplorer.Commands; @@ -14,11 +15,11 @@ { private readonly ICommand showProjectExplorerCommand; - public Ribbon() + public Ribbon(IToolViewController toolViewController) { InitializeComponent(); - showProjectExplorerCommand = new ShowProjectExplorerCommand(); + showProjectExplorerCommand = new ShowProjectExplorerCommand(toolViewController); } public IEnumerable Commands Index: Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectExplorerGuiPluginTest.cs =================================================================== diff -u -r98939d3757e99732f74f6345b5eb58c90e30a4d4 -ra6df46f9508fcedf716bb84ec0076d7df104155f --- Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectExplorerGuiPluginTest.cs (.../ProjectExplorerGuiPluginTest.cs) (revision 98939d3757e99732f74f6345b5eb58c90e30a4d4) +++ Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectExplorerGuiPluginTest.cs (.../ProjectExplorerGuiPluginTest.cs) (revision a6df46f9508fcedf716bb84ec0076d7df104155f) @@ -48,6 +48,7 @@ }).Repeat.Any(); gui.Stub(g=>g.ApplicationCommands).Return(mocks.StrictMock()); gui.Stub(g => g.ProjectCommands).Return(mocks.StrictMock()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); gui.Project = project; Index: Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectTreeViewTest.cs =================================================================== diff -u -r7993dddd622b104506d59a43fd9add82d6ce48ae -ra6df46f9508fcedf716bb84ec0076d7df104155f --- Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectTreeViewTest.cs (.../ProjectTreeViewTest.cs) (revision 7993dddd622b104506d59a43fd9add82d6ce48ae) +++ Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectTreeViewTest.cs (.../ProjectTreeViewTest.cs) (revision a6df46f9508fcedf716bb84ec0076d7df104155f) @@ -20,24 +20,14 @@ public void Init() { var mocks = new MockRepository(); - var gui = mocks.Stub(); - var documentViews = mocks.Stub(); - var settings = mocks.Stub(); - var applicationCore = new ApplicationCore(); - - Expect.Call(gui.ApplicationCore).Return(applicationCore).Repeat.Any(); - Expect.Call(gui.UserSettings).Return(settings).Repeat.Any(); - Expect.Call(gui.DocumentViews).Return(documentViews).Repeat.Any(); - + var selectionStub = mocks.Stub(); + var viewCommandsStub = mocks.Stub(); + var projectOwner = mocks.Stub(); + var documentViewController = mocks.Stub(); mocks.ReplayAll(); - var pluginGui = new ProjectExplorerGuiPlugin + using (var projectTreeView = new ProjectTreeView(selectionStub, viewCommandsStub, projectOwner, documentViewController)) { - Gui = gui - }; - - using (var projectTreeView = new ProjectTreeView(pluginGui)) - { Assert.IsNotNull(projectTreeView); } @@ -76,19 +66,19 @@ var commandHandler = mocks.Stub(); commandHandler.Expect(ch => ch.RemoveAllViewsForItem(item)); - var applicationCoreStub = mocks.Stub(); + var projectOwner = mocks.Stub(); + projectOwner.Stub(g => g.ProjectOpened += Arg>.Is.Anything); + projectOwner.Stub(g => g.ProjectOpened -= Arg>.Is.Anything); - var gui = mocks.Stub(); - gui.Stub(g => g.ViewCommands).Return(commandHandler); - gui.Stub(g => g.ApplicationCore).Return(applicationCoreStub); - gui.Stub(g => g.SelectionChanged += Arg>.Is.Anything); - gui.Stub(g => g.SelectionChanged -= Arg>.Is.Anything); - gui.Stub(g => g.ProjectOpened += Arg>.Is.Anything); - gui.Stub(g => g.ProjectOpened -= Arg>.Is.Anything); + var selectionStub = mocks.Stub(); + selectionStub.Stub(g => g.SelectionChanged += Arg>.Is.Anything); + selectionStub.Stub(g => g.SelectionChanged -= Arg>.Is.Anything); + + var documentViewController = mocks.Stub(); + mocks.ReplayAll(); - using(var guiPlugin = new ProjectExplorerGuiPlugin { Gui = gui }) - using (var projectTree = new ProjectTreeView(guiPlugin)) + using (var projectTree = new ProjectTreeView(selectionStub, commandHandler, projectOwner, documentViewController)) { projectTree.TreeView.RegisterNodePresenter(new ProjectNodePresenter(menuBuilderProvider, projectCommands)); projectTree.TreeView.RegisterNodePresenter(integerNodePresenter);