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. 2
      src/Main/Base/Project/Src/Commands/FileMenuCommands.cs
  3. 5
      src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs
  4. 2
      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<
<data name="MainWindow.Windows.Debug.Watch.RemoveWatch" xml:space="preserve"> <data name="MainWindow.Windows.Debug.Watch.RemoveWatch" xml:space="preserve">
<value>Remove watch</value> <value>Remove watch</value>
</data> </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"> <data name="MainWindow.Windows.DefinitionViewLabel" xml:space="preserve">
<value>Definition View</value> <value>Definition View</value>
</data> </data>

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

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

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

@ -573,6 +573,8 @@ namespace ICSharpCode.SharpDevelop.Gui
return; return;
} }
if (!Project.ProjectService.IsClosingCanceled()) {
// save preferences
Project.ProjectService.SaveSolutionPreferences(); Project.ProjectService.SaveSolutionPreferences();
while (WorkbenchSingleton.Workbench.WorkbenchWindowCollection.Count > 0) { while (WorkbenchSingleton.Workbench.WorkbenchWindowCollection.Count > 0) {
@ -593,6 +595,9 @@ namespace ICSharpCode.SharpDevelop.Gui
foreach (PadDescriptor padDescriptor in this.PadContentCollection) { foreach (PadDescriptor padDescriptor in this.PadContentCollection) {
padDescriptor.Dispose(); padDescriptor.Dispose();
} }
} else {
e.Cancel = true;
}
} }
} }

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

@ -114,6 +114,7 @@ namespace ICSharpCode.SharpDevelop.Gui
/// </summary> /// </summary>
public static void OnWorkbenchUnloaded() public static void OnWorkbenchUnloaded()
{ {
if (!Project.ProjectService.IsClosingCanceled()) {
Project.ProjectService.CloseSolution(); Project.ProjectService.CloseSolution();
NavigationService.Unload(); NavigationService.Unload();
@ -123,6 +124,7 @@ namespace ICSharpCode.SharpDevelop.Gui
FileService.Unload(); FileService.Unload();
} }
}
#region Safe Thread Caller #region Safe Thread Caller
public static bool InvokeRequired { public static bool InvokeRequired {

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

@ -28,6 +28,8 @@ namespace ICSharpCode.SharpDevelop.Debugging
ClearDebugMessages(); ClearDebugMessages();
}; };
ProjectService.BeforeSolutionClosing += OnBeforeSolutionClosing;
BookmarkManager.Added += BookmarkAdded; BookmarkManager.Added += BookmarkAdded;
BookmarkManager.Removed += BookmarkRemoved; BookmarkManager.Removed += BookmarkRemoved;
} }
@ -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) public static void ToggleBreakpointAt(ITextEditor editor, int lineNumber)
{ {
BookmarkManager.ToggleBookmark( BookmarkManager.ToggleBookmark(

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

@ -242,7 +242,7 @@ namespace ICSharpCode.SharpDevelop.Project
static void BeforeLoadSolution() static void BeforeLoadSolution()
{ {
if (openSolution != null) { if (openSolution != null && !IsClosingCanceled()) {
SaveSolutionPreferences(); SaveSolutionPreferences();
WorkbenchSingleton.Workbench.CloseAllViews(); WorkbenchSingleton.Workbench.CloseAllViews();
CloseSolution(); CloseSolution();
@ -258,6 +258,10 @@ namespace ICSharpCode.SharpDevelop.Project
{ {
if (!Path.IsPathRooted(fileName)) if (!Path.IsPathRooted(fileName))
throw new ArgumentException("Path must be rooted!"); throw new ArgumentException("Path must be rooted!");
if (IsClosingCanceled())
return;
BeforeLoadSolution(); BeforeLoadSolution();
OnSolutionLoading(fileName); OnSolutionLoading(fileName);
try { try {
@ -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 a build is running, cancel it.
// If we would let a build run but unload the MSBuild projects, the next project.StartBuild call // 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
} }
} }
static void OnBeforeSolutionClosing(SolutionCancelEventArgs e)
{
if (BeforeSolutionClosing != null) {
BeforeSolutionClosing(null, e);
}
}
static void OnSolutionLoading(string fileName) static void OnSolutionLoading(string fileName)
{ {
if (SolutionLoading != null) { if (SolutionLoading != null) {
@ -714,6 +746,15 @@ namespace ICSharpCode.SharpDevelop.Project
public static event EventHandler<SolutionEventArgs> SolutionClosing; public static event EventHandler<SolutionEventArgs> SolutionClosing;
public static event EventHandler SolutionClosed; 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> /// <summary>
/// Raised before the solution preferences are being saved. Allows you to save /// Raised before the solution preferences are being saved. Allows you to save
/// your additional properties in the solution preferences. /// your additional properties in the solution preferences.

Loading…
Cancel
Save