Browse Source

Delay the ActiveViewContentChanged event using the dispatcher so that it doesn't get executed within the callback from AvalonDock - this could lead to some unexpected reentrancy (e.g. when some event handler was opening/closing views).

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
975ea750ca
  1. 32
      src/Main/SharpDevelop/Workbench/WpfWorkbench.cs

32
src/Main/SharpDevelop/Workbench/WpfWorkbench.cs

@ -16,7 +16,7 @@ using System.Windows.Input;
using System.Windows.Interop; using System.Windows.Interop;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Threading;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.Core.Presentation; using ICSharpCode.Core.Presentation;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
@ -302,11 +302,16 @@ namespace ICSharpCode.SharpDevelop.Workbench
} }
} }
bool activeWindowWasChanged;
void OnActiveWindowChanged(object sender, EventArgs e) void OnActiveWindowChanged(object sender, EventArgs e)
{ {
if (closeAll) if (activeWindowWasChanged)
return; return;
activeWindowWasChanged = true;
Dispatcher.BeginInvoke(new Action(
delegate {
activeWindowWasChanged = false;
if (workbenchLayout != null) { if (workbenchLayout != null) {
this.ActiveContent = workbenchLayout.ActiveContent; this.ActiveContent = workbenchLayout.ActiveContent;
this.ActiveWorkbenchWindow = workbenchLayout.ActiveWorkbenchWindow; this.ActiveWorkbenchWindow = workbenchLayout.ActiveWorkbenchWindow;
@ -314,6 +319,7 @@ namespace ICSharpCode.SharpDevelop.Workbench
this.ActiveContent = null; this.ActiveContent = null;
this.ActiveWorkbenchWindow = null; this.ActiveWorkbenchWindow = null;
} }
}));
} }
IViewContent activeViewContent; IViewContent activeViewContent;
@ -431,41 +437,21 @@ namespace ICSharpCode.SharpDevelop.Workbench
return null; return null;
} }
/// <summary>
/// Flag used to prevent repeated ActiveWindowChanged events during CloseAllViews().
/// </summary>
bool closeAll;
public void CloseAllViews() public void CloseAllViews()
{ {
WorkbenchSingleton.AssertMainThread(); WorkbenchSingleton.AssertMainThread();
try {
closeAll = true;
foreach (IWorkbenchWindow window in this.WorkbenchWindowCollection.ToArray()) { foreach (IWorkbenchWindow window in this.WorkbenchWindowCollection.ToArray()) {
window.CloseWindow(false); window.CloseWindow(false);
} }
} finally {
closeAll = false;
OnActiveWindowChanged(this, EventArgs.Empty);
}
} }
public bool CloseAllSolutionViews() public bool CloseAllSolutionViews()
{ {
bool result = true; bool result = true;
WorkbenchSingleton.AssertMainThread();
try {
closeAll = true;
foreach (IWorkbenchWindow window in this.WorkbenchWindowCollection.ToArray()) { foreach (IWorkbenchWindow window in this.WorkbenchWindowCollection.ToArray()) {
if (window.ActiveViewContent != null && window.ActiveViewContent.CloseWithSolution) if (window.ActiveViewContent != null && window.ActiveViewContent.CloseWithSolution)
result &= window.CloseWindow(false); result &= window.CloseWindow(false);
} }
} finally {
closeAll = false;
OnActiveWindowChanged(this, EventArgs.Empty);
}
return result; return result;
} }

Loading…
Cancel
Save