Browse Source

fix SD-1269 - Ask to close debugger (or not) while it's running - http://bugtracker.sharpdevelop.net/issue/ViewIssue.aspx?id=1269&PROJID=4

4.1
Eusebiu Marcu 14 years ago
parent
commit
b6c6535da2
  1. 3
      data/resources/StringResources.resx
  2. 8
      src/Main/Base/Project/Src/Commands/FileMenuCommands.cs
  3. 41
      src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs
  4. 18
      src/Main/Base/Project/Src/Gui/WorkbenchSingleton.cs
  5. 25
      src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs
  6. 45
      src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs

3
data/resources/StringResources.resx

@ -5862,6 +5862,9 @@ Microsoft.Tools.WindowsInstallerXml.Extensions.NetFxCompiler, WixNetFxExtension< @@ -5862,6 +5862,9 @@ Microsoft.Tools.WindowsInstallerXml.Extensions.NetFxCompiler, WixNetFxExtension<
<data name="MainWindow.Windows.Debug.Watch.RemoveWatch" xml:space="preserve">
<value>Remove watch</value>
</data>
<data name="MainWindow.Windows.Debug.StopDebugging.Message" xml:space="preserve">
<value>Do you want to stop debugging?</value>
</data>
<data name="MainWindow.Windows.DefinitionViewLabel" xml:space="preserve">
<value>Definition View</value>
</data>

8
src/Main/Base/Project/Src/Commands/FileMenuCommands.cs

@ -39,9 +39,11 @@ namespace ICSharpCode.SharpDevelop.Project.Commands @@ -39,9 +39,11 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
{
public override void Run()
{
ProjectService.SaveSolutionPreferences();
if (WorkbenchSingleton.Workbench.CloseAllSolutionViews()) {
ProjectService.CloseSolution();
if (!ProjectService.IsClosingCanceled()) {
ProjectService.SaveSolutionPreferences();
if (WorkbenchSingleton.Workbench.CloseAllSolutionViews()) {
ProjectService.CloseSolution();
}
}
}
}

41
src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs

@ -573,25 +573,30 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -573,25 +573,30 @@ namespace ICSharpCode.SharpDevelop.Gui
return;
}
Project.ProjectService.SaveSolutionPreferences();
while (WorkbenchSingleton.Workbench.WorkbenchWindowCollection.Count > 0) {
IWorkbenchWindow window = WorkbenchSingleton.Workbench.WorkbenchWindowCollection[0];
if (!window.CloseWindow(false)) {
e.Cancel = true;
return;
if (!Project.ProjectService.IsClosingCanceled()) {
// save preferences
Project.ProjectService.SaveSolutionPreferences();
while (WorkbenchSingleton.Workbench.WorkbenchWindowCollection.Count > 0) {
IWorkbenchWindow window = WorkbenchSingleton.Workbench.WorkbenchWindowCollection[0];
if (!window.CloseWindow(false)) {
e.Cancel = true;
return;
}
}
}
Project.ProjectService.CloseSolution();
ParserService.StopParserThread();
restoreBoundsBeforeClosing = this.RestoreBounds;
this.WorkbenchLayout = null;
foreach (PadDescriptor padDescriptor in this.PadContentCollection) {
padDescriptor.Dispose();
Project.ProjectService.CloseSolution();
ParserService.StopParserThread();
restoreBoundsBeforeClosing = this.RestoreBounds;
this.WorkbenchLayout = null;
foreach (PadDescriptor padDescriptor in this.PadContentCollection) {
padDescriptor.Dispose();
}
} else {
e.Cancel = true;
}
}
}

18
src/Main/Base/Project/Src/Gui/WorkbenchSingleton.cs

@ -114,14 +114,16 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -114,14 +114,16 @@ namespace ICSharpCode.SharpDevelop.Gui
/// </summary>
public static void OnWorkbenchUnloaded()
{
Project.ProjectService.CloseSolution();
NavigationService.Unload();
ApplicationStateInfoService.UnregisterStateGetter(activeContentState);
WorkbenchUnloaded(null, EventArgs.Empty);
FileService.Unload();
if (!Project.ProjectService.IsClosingCanceled()) {
Project.ProjectService.CloseSolution();
NavigationService.Unload();
ApplicationStateInfoService.UnregisterStateGetter(activeContentState);
WorkbenchUnloaded(null, EventArgs.Empty);
FileService.Unload();
}
}
#region Safe Thread Caller

25
src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs

@ -28,6 +28,8 @@ namespace ICSharpCode.SharpDevelop.Debugging @@ -28,6 +28,8 @@ namespace ICSharpCode.SharpDevelop.Debugging
ClearDebugMessages();
};
ProjectService.BeforeSolutionClosing += OnBeforeSolutionClosing;
BookmarkManager.Added += BookmarkAdded;
BookmarkManager.Removed += BookmarkRemoved;
}
@ -222,6 +224,29 @@ namespace ICSharpCode.SharpDevelop.Debugging @@ -222,6 +224,29 @@ namespace ICSharpCode.SharpDevelop.Debugging
}
}
static void OnBeforeSolutionClosing(object sender, SolutionCancelEventArgs e)
{
if (currentDebugger == null)
return;
if (currentDebugger.IsDebugging) {
string caption = StringParser.Parse("${res:XML.MainMenu.DebugMenu.Stop}");
string message = StringParser.Parse("${res:MainWindow.Windows.Debug.StopDebugging.Message}");
string[] buttonLabels = new string[] { StringParser.Parse("${res:Global.Yes}"), StringParser.Parse("${res:Global.No}") };
int result = MessageService.ShowCustomDialog(caption,
message,
0, // yes
1, // no
buttonLabels);
if (result == 0) {
currentDebugger.Stop();
} else {
e.Cancel = true;
}
}
}
public static void ToggleBreakpointAt(ITextEditor editor, int lineNumber)
{
BookmarkManager.ToggleBookmark(

45
src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs

@ -242,7 +242,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -242,7 +242,7 @@ namespace ICSharpCode.SharpDevelop.Project
static void BeforeLoadSolution()
{
if (openSolution != null) {
if (openSolution != null && !IsClosingCanceled()) {
SaveSolutionPreferences();
WorkbenchSingleton.Workbench.CloseAllViews();
CloseSolution();
@ -258,6 +258,10 @@ namespace ICSharpCode.SharpDevelop.Project @@ -258,6 +258,10 @@ namespace ICSharpCode.SharpDevelop.Project
{
if (!Path.IsPathRooted(fileName))
throw new ArgumentException("Path must be rooted!");
if (IsClosingCanceled())
return;
BeforeLoadSolution();
OnSolutionLoading(fileName);
try {
@ -500,7 +504,28 @@ namespace ICSharpCode.SharpDevelop.Project @@ -500,7 +504,28 @@ namespace ICSharpCode.SharpDevelop.Project
}
}
public static void CloseSolution()
/// <summary>
/// Executes the OnBeforeSolutionClosing event.
/// </summary>
/// <remarks>This method must be used after CloseSolution is called.</remarks>
/// <returns><c>true</c>, if closing solution was canceled; <c>false</c>, otherwise.</returns>
internal static bool IsClosingCanceled()
{
// run onbefore closing
var beforeClosingArgs = new SolutionCancelEventArgs(openSolution);
OnBeforeSolutionClosing(beforeClosingArgs);
return beforeClosingArgs.Cancel;
}
/// <summary>
/// Closes the solution: cancels build, clears solution data, fires the SolutionClosing and SolutionClosed events.
/// <remarks>
/// Before invoking this method, one should check if the closing was canceled (<see cref="IsClosingCanceled"/>),
/// save solution and project data (e.g. files, bookmarks), then invoke CloseSolution().
/// </remarks>
/// </summary>
internal static void CloseSolution()
{
// If a build is running, cancel it.
// If we would let a build run but unload the MSBuild projects, the next project.StartBuild call
@ -541,6 +566,13 @@ namespace ICSharpCode.SharpDevelop.Project @@ -541,6 +566,13 @@ namespace ICSharpCode.SharpDevelop.Project
}
}
static void OnBeforeSolutionClosing(SolutionCancelEventArgs e)
{
if (BeforeSolutionClosing != null) {
BeforeSolutionClosing(null, e);
}
}
static void OnSolutionLoading(string fileName)
{
if (SolutionLoading != null) {
@ -714,6 +746,15 @@ namespace ICSharpCode.SharpDevelop.Project @@ -714,6 +746,15 @@ namespace ICSharpCode.SharpDevelop.Project
public static event EventHandler<SolutionEventArgs> SolutionClosing;
public static event EventHandler SolutionClosed;
/// <summary>
/// Raised before SolutionClosing.
/// <remarks>
/// When one modifies the e.Cancel property, should have in mind that other consumers might want to cancel the closing.<br/>
/// Setting e.Cancel = false might override other consumers (if they exist) e.Cancel = true, and might break other functionalities.
/// </remarks>
/// </summary>
public static event EventHandler<SolutionCancelEventArgs> BeforeSolutionClosing;
/// <summary>
/// Raised before the solution preferences are being saved. Allows you to save
/// your additional properties in the solution preferences.

Loading…
Cancel
Save