diff --git a/src/Main/Base/Project/Src/Commands/FileMenuCommands.cs b/src/Main/Base/Project/Src/Commands/FileMenuCommands.cs index a7b07b2a69..f5e0bb27d3 100644 --- a/src/Main/Base/Project/Src/Commands/FileMenuCommands.cs +++ b/src/Main/Base/Project/Src/Commands/FileMenuCommands.cs @@ -40,8 +40,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands public override void Run() { ProjectService.SaveSolutionPreferences(); - WorkbenchSingleton.Workbench.CloseAllViews(); - if (WorkbenchSingleton.Workbench.WorkbenchWindowCollection.Count == 0) { + if (WorkbenchSingleton.Workbench.CloseAllSolutionViews()) { ProjectService.CloseSolution(); } } diff --git a/src/Main/Base/Project/Src/Gui/IWorkbench.cs b/src/Main/Base/Project/Src/Gui/IWorkbench.cs index 5f4afa32e3..3e44abe380 100644 --- a/src/Main/Base/Project/Src/Gui/IWorkbench.cs +++ b/src/Main/Base/Project/Src/Gui/IWorkbench.cs @@ -163,6 +163,14 @@ namespace ICSharpCode.SharpDevelop.Gui /// void CloseAllViews(); + /// + /// Closes all views related to current solution. + /// + /// + /// True if all views were closed properly, false if closing was aborted. + /// + bool CloseAllSolutionViews(); + /// /// Is called, when a workbench view was opened /// diff --git a/src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs b/src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs index a5431e6c7d..b335d5512c 100644 --- a/src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs +++ b/src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs @@ -17,6 +17,7 @@ using System.Windows.Media; using System.Windows.Navigation; using ICSharpCode.Core; using ICSharpCode.Core.Presentation; +using ICSharpCode.SharpDevelop.Project; namespace ICSharpCode.SharpDevelop.Gui { @@ -433,6 +434,43 @@ namespace ICSharpCode.SharpDevelop.Gui } } + public bool CloseAllSolutionViews() + { + bool isSolutionWindow; + bool result = true; + + WorkbenchSingleton.AssertMainThread(); + try + { + closeAll = true; + foreach (IWorkbenchWindow window in this.WorkbenchWindowCollection.ToArray()) + { + isSolutionWindow = false; + foreach (IViewContent content in window.ViewContents) + { + foreach (OpenedFile file in content.Files) + { + if (ProjectService.OpenSolution.FindProjectContainingFile(file.FileName) != null) + { + isSolutionWindow = true; + break; + } + } + } + + if (isSolutionWindow) + result = window.CloseWindow(false) && result; + } + } + finally + { + closeAll = false; + OnActiveWindowChanged(this, EventArgs.Empty); + } + + return result; + } + #region ViewContent Memento Handling string viewContentMementosFileName;