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 @@ -294,8 +294,8 @@ namespace AvalonDock
if (ActiveDocument == null)
{
var docToActivate = Documents.OrderBy(d => d.LastActivation).FirstOrDefault();
if (docToActivate != null)
var docToActivate = Documents.OrderBy(d => d.LastActivation).LastOrDefault();
if (docToActivate != null && docToActivate.LastActivation != DateTime.MinValue)
docToActivate.Activate();
}
}
@ -3775,7 +3775,8 @@ namespace AvalonDock @@ -3775,7 +3775,8 @@ namespace AvalonDock
pane.ToggleAutoHide();
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
@ -3892,16 +3893,8 @@ namespace AvalonDock @@ -3892,16 +3893,8 @@ namespace AvalonDock
ClearEmptyPanes();
RefreshContents();
if (ActiveDocument != null &&
(ActiveDocument.ContainerPane == null ||
ActiveDocument.ContainerPane.GetManager() != this))
{
if (Documents.Count > 0)
ActiveDocument = Documents[0];
else
// by setting ActiveDocument to null, we activate the previously activated document (as per LastActivation)
ActiveDocument = null;
}
ActiveContent = ActiveDocument;
}
#endregion

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

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

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

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

Loading…
Cancel
Save