[Version 2.0] Document displayed ?

Apr 20, 2012 at 3:36 PM

DockingManager exposes a DocumentsSource property.

I'm looking for a bindable property to know the current displayed document (active or not).

I guess I can do it with at worst with ActiveContent  + DocumentClosing event :/

 

Thx

Apr 20, 2012 at 3:52 PM

The ActiveContent gives you the active content (Anchorable or Document) that has the focus. The DocumentClosing event is fired when user is about to close a document,

Ado

Apr 23, 2012 at 7:40 AM

These property and event's naming are clear ;)

But with them, there is a case painfull to cover : 3 or more documents opened, select the first, select the last, and then select an Anchorable. Now, close the last document (displayed one) : the first document is now displayed, Anchorable is still the ActiveContent.

With ActiveContent, I can track the last displayed document. With DocumentClosing, I know if the tracked "last displayed document" is closed ... but fallback on the previous displayed document need to track opened document activation order.

 

It's something AD already do to display the right document after closing one... why redo this ? :)

That's why I looked for a bindable property. ActiveDocument and ActiveAnchorable would simplify :)

Apr 23, 2012 at 12:15 PM

I vote for ActiveDocument as well, except I would name it SelectedDocument.
If there's ItemsSource property, which generates items and item can be selected, there should be SelectedItem property as well.

In wpf controls it is expected.

Apr 23, 2012 at 1:30 PM

Understand your problem, but consider that there can be more than one selected document when more than one document pane are displayed. Also the active/selected content can be a document or an anchorable.
If you see how VS works you can have 4 types of "selected/active" contents: The ActiveContent is what has the keyboard focus (the property grid pane display an object from this pane), the LastFocusedDocument that is the tab inside a document pane (document or anchorable) that has last gained focus, the selected tab (anchorable or document) inside a document pane and the selected tab (anchorable) inside an anchorable pane. Sometimes these properties point to the same object.

If you want to bind directly to the ActiveContent you should consider using a converter that can filter out the anchorables, if you want the last activated document that use the property LastFocusedDocument using the same converter.

If you want the list of selected documents, you can just work with the model (pseudo-code):
dockManager.Layout.Descents().OfType<LayoutDocument>().Where(d => d.IsSelected);

Said that I'm convinced too that maybe something easier to get work with should be implemented and for that I'm absolutely open to discussion,

Ado


Apr 25, 2012 at 5:18 PM

But in VS there is stil only one Document the ActiveOne, and if this one is for Example a WPF Document, then the WPF ToolBox is shown, if it is a WinformsOne another ToolBox is shown. So I think also AvalonDock should be able to tell wich Document is active (I think that should be the last one wich has had the focus. 

May 7, 2012 at 3:53 PM

ListBox also supports multiselection and SelectedItem property is still very usefull. It returns last selected item;

SelectedDocument
get: return last selected (or activated) document
set: find document pane and select document tab

 

May 19, 2014 at 10:36 PM
Edited May 19, 2014 at 10:39 PM
You can use the LayoutDocument's events "IsActiveChanged" and "Closed", combined with a removable stack(https://github.com/joazlazer/ModdingStudio/blob/master/ModdingStudio/ModdingStudio/RemovableStack(T).cs) to make it easy to track and have a stack of which documents have been activated and with RemovableStack<T>.Peek(), you can know what the last document that was "made active" (e.g. the one that has mouse focus).