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. 56
      src/Main/SharpDevelop/Workbench/WpfWorkbench.cs

56
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,18 +302,24 @@ 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;
if (workbenchLayout != null) { Dispatcher.BeginInvoke(new Action(
this.ActiveContent = workbenchLayout.ActiveContent; delegate {
this.ActiveWorkbenchWindow = workbenchLayout.ActiveWorkbenchWindow; activeWindowWasChanged = false;
} else { if (workbenchLayout != null) {
this.ActiveContent = null; this.ActiveContent = workbenchLayout.ActiveContent;
this.ActiveWorkbenchWindow = null; this.ActiveWorkbenchWindow = workbenchLayout.ActiveWorkbenchWindow;
} } else {
this.ActiveContent = 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 { foreach (IWorkbenchWindow window in this.WorkbenchWindowCollection.ToArray()) {
closeAll = true; window.CloseWindow(false);
foreach (IWorkbenchWindow window in this.WorkbenchWindowCollection.ToArray()) {
window.CloseWindow(false);
}
} finally {
closeAll = false;
OnActiveWindowChanged(this, EventArgs.Empty);
} }
} }
public bool CloseAllSolutionViews() public bool CloseAllSolutionViews()
{ {
bool result = true; bool result = true;
foreach (IWorkbenchWindow window in this.WorkbenchWindowCollection.ToArray()) {
WorkbenchSingleton.AssertMainThread(); if (window.ActiveViewContent != null && window.ActiveViewContent.CloseWithSolution)
try { result &= window.CloseWindow(false);
closeAll = true;
foreach (IWorkbenchWindow window in this.WorkbenchWindowCollection.ToArray()) {
if (window.ActiveViewContent != null && window.ActiveViewContent.CloseWithSolution)
result &= window.CloseWindow(false);
}
} finally {
closeAll = false;
OnActiveWindowChanged(this, EventArgs.Empty);
} }
return result; return result;
} }

Loading…
Cancel
Save