Browse Source

Preserve active document (and order of documents) on layout switches.

Based on Andrew Olson's suggestion http://community.sharpdevelop.net/forums/t/13034.aspx.
4.0
Daniel Grunwald 15 years ago
parent
commit
d6918254e9
  1. 17
      src/Libraries/AvalonDock/AvalonDock/DockingManager.cs
  2. 1
      src/Libraries/AvalonDock/AvalonDock/DocumentContent.cs
  3. 9
      src/Libraries/AvalonDock/AvalonDock/ManagedContent.cs

17
src/Libraries/AvalonDock/AvalonDock/DockingManager.cs

@ -294,8 +294,8 @@ namespace AvalonDock
if (ActiveDocument == null) if (ActiveDocument == null)
{ {
var docToActivate = Documents.OrderBy(d => d.LastActivation).FirstOrDefault(); var docToActivate = Documents.OrderBy(d => d.LastActivation).LastOrDefault();
if (docToActivate != null) if (docToActivate != null && docToActivate.LastActivation != DateTime.MinValue)
docToActivate.Activate(); docToActivate.Activate();
} }
} }
@ -3775,7 +3775,8 @@ namespace AvalonDock
pane.ToggleAutoHide(); pane.ToggleAutoHide();
DockableContent[] actualContents = DockableContents.ToArray(); DockableContent[] actualContents = DockableContents.ToArray();
DocumentContent[] actualDocuments = Documents.ToArray(); // preserve the order of the documents
DocumentContent[] actualDocuments = Documents.OrderBy(d => d.ContainerPane != null ? d.ContainerPane.Items.IndexOf(d) : -1).ToArray();
//first detach all my actual contents //first detach all my actual contents
@ -3892,16 +3893,8 @@ namespace AvalonDock
ClearEmptyPanes(); ClearEmptyPanes();
RefreshContents(); RefreshContents();
if (ActiveDocument != null && // by setting ActiveDocument to null, we activate the previously activated document (as per LastActivation)
(ActiveDocument.ContainerPane == null ||
ActiveDocument.ContainerPane.GetManager() != this))
{
if (Documents.Count > 0)
ActiveDocument = Documents[0];
else
ActiveDocument = null; ActiveDocument = null;
}
ActiveContent = ActiveDocument; ActiveContent = ActiveDocument;
} }
#endregion #endregion

1
src/Libraries/AvalonDock/AvalonDock/DocumentContent.cs

@ -340,6 +340,7 @@ namespace AvalonDock
/// </summary> /// </summary>
internal void InternalClose() internal void InternalClose()
{ {
this.LastActivation = DateTime.MinValue; // make this content ineligible for ActiveDocument selection when ActiveDocument is set to null
DockingManager manager = Manager; DockingManager manager = Manager;
if (manager != null) if (manager != null)

9
src/Libraries/AvalonDock/AvalonDock/ManagedContent.cs

@ -559,12 +559,7 @@ namespace AvalonDock
((ManagedContent)d).OnIsActiveContentChanged(e); ((ManagedContent)d).OnIsActiveContentChanged(e);
} }
DateTime _lastActivation = DateTime.MinValue; internal DateTime LastActivation = DateTime.MinValue;
internal DateTime LastActivation
{
get { return _lastActivation; }
}
/// <summary> /// <summary>
/// Provides derived classes an opportunity to handle changes to the IsActiveContent property. /// Provides derived classes an opportunity to handle changes to the IsActiveContent property.
@ -572,7 +567,7 @@ namespace AvalonDock
protected virtual void OnIsActiveContentChanged(DependencyPropertyChangedEventArgs e) protected virtual void OnIsActiveContentChanged(DependencyPropertyChangedEventArgs e)
{ {
if (IsActiveContent) if (IsActiveContent)
_lastActivation = DateTime.Now; this.LastActivation = DateTime.UtcNow;
FocusContent(); FocusContent();

Loading…
Cancel
Save