Restore docking layout of previously opened documents

1 Answer 107 Views
Dock
Carlos
Top achievements
Rank 1
Carlos asked on 08 May 2023, 09:14 AM

Hi,

We have a RadDock with multiple open documents (of type DocumentWindow), like the attached "DocumentsLayout" image.

These documents belong to a specific parent (what we call the "MainFolder"). Once the "MainFolder" is closed, we have a process that closes all opened documents and saves some metadata, including which documents were opened (currently we only save the names of those documents). We want to be able to restore the docking layout and restore the location of those previously opened documents, but we are not sure how to.

Currently, once we get the list of documents that we want to reopen, we restore them with:

public void RestoreDocuments(RadDock radDock, IEnumerable<DocumentWindow> documents)
{
  foreach (DocumentWindow document in documents)
  {
    radDock.AddDocument(document);
  }
}
But of course the docking layout is lost, and all documents are added to the default DocumentTabStrip (even floating ones were added to the main one).

What is the best way to achieve this? We also care about the order they were originally located within the tab strips (i.e. in the image, Document 2 on the left and Document 1 on the right)

Note: We are using version 2018_3_911, but we can upgrade if necessary.

Thank you for your help.

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 11 May 2023, 05:59 AM

Hello, Carlos,

RadDock offers save/load layout functionality out of the box which I believe would be the perfect fit to cover your scenario. This saves all managed windows (ToolWindow and DocumentWindow) regardless of state (i.e. a window may be hidden or floating and still be saved). Please refer to the following help article which gives you more information how to use it: https://docs.telerik.com/devtools/winforms/controls/dock/loading-and-saving-layouts/loading-and-saving-layouts 

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Carlos
Top achievements
Rank 1
commented on 11 May 2023, 07:35 AM | edited

Hi,

We are currently loading and saving the xml for the whole "Application's dock" and it works fine, but this is a specific scenario that goes into more detail because we only want to "save/load" the state of some specific documents, and not for the rest of the docking panels (i.e. toolbars).

The case is: we have a panel on the left that lists multiple "MainFolders". Each "MainFolder" contains documents. You can "open" a "MainFolder" and open only documents that belong to this "MainFolder". You can then "close" the "MainFolder", and the "layout" of those opened documents should be saved so that when you open this "MainFolder" again, those documents are opened with the previous "layout". This applies to each "MainFolder" in the list and each "MainFolder" should persist their own "dock layout" only for the documents that are opened. The other toolbars are not affected by this functionality.

Is there a way to achieve this? for example by saving a partial xml and reloading it so that the rest of the toolbars in the layout are not affected? 

Dess | Tech Support Engineer, Principal
Telerik team
commented on 15 May 2023, 04:59 PM

Thank you. Carlos, for the additional information. Note that the layout is stored in the xml file per each RadDock. If you want to separate the layouts in different files, I believe that the easiest way would be to use different RadDock controls even though using multiple RadDock controls is not a common scenario. Thus, each RadDock will contain the documents you want and the layout will have only the windows you need to be stored. Would this approach be applicable for you?
Carlos
Top achievements
Rank 1
commented on 16 May 2023, 09:48 AM

Hi,

A separate Raddock is probably not a good option for us, because we allow docking documents within any part of the main raddock.

Is there another option by using the overloads of "AddDocument" from RadDock? I've seen some overloads that use "DockWindow" and "DockPosition", and although we could save the DockPosition, I'm not sure if we can get somehow the DockWindow by another API from RadDock.

Do you have any suggestions for this?

Dess | Tech Support Engineer, Principal
Telerik team
commented on 19 May 2023, 05:54 AM

Hi, Carlos,

RadDock offers the DockWindowAdded event which indicates the moment when a new document is added to the dock control. In addition, the DockStateChanging and DockStateChanged events allows you to track when a document is moved from one position to another. The DockStateChangingEventArgs and DockWindowEventArgs give information the new/previous state. 

RadDock offers several overloads for the DockWindow method accepting the source window, the target window and the DockPosition. Thus, you can dock a window at a certain position, e.g. bottom, according to another target window: 

            ToolWindow toolWindow1 = new ToolWindow();
            toolWindow1.Text = "A ToolWindow";
            radDock1.DockWindow(toolWindow1,this.documentWindow1, DockPosition.Bottom);

Before:

After:

I hope that the provided information will be useful.

Carlos
Top achievements
Rank 1
commented on 22 May 2023, 10:26 AM

Hi Dess,

it might work, but the problem that we have is that those windows can be floating or not floating, and there can be multiple layouts in different floating windows, and matching the TabStrip is not trivial once they are closed (because the name of the TabStrip changes everytime you create one).

Also, we found out that if you have a document docked as "Fill" and one docked as "Bottom" requires a specific order in which the documents have to be loaded. If I load first the "Bottom" one, and then the "Fill" document, the "Fill" will cover the "Bottom" one (it won't be seen).

It's also tough to find a TabStrip with floating docking panels, so in the end this solution of taking overriden "AddDocument" methods is probably not a good approach in terms of complexity and performance.

The most ideal scenario would be to save/load a partial layout (only include some documents in the process) but I guess the only way of doing it would be to modify this XML while saving (not sure if possible or even safe).

If there is no other option, I guess this would be the correct answer but we won't be able to solve our issue.

Please let me know if you have any further advice.

Dess | Tech Support Engineer, Principal
Telerik team
commented on 24 May 2023, 12:31 PM

Hi, Carlos,

Excluding some documents from the XML is possible. It is necessary to handle the DockWindowSerializing event. The DockWindowCancelEventArgs gives you access to the NewWindow and if you want to skip serializing the window, set the Cancel argument to true. 

        private void RadDock1_DockWindowSerializing(object sender, DockWindowCancelEventArgs e)
        {
            if (e.NewWindow.Text.Contains("Window2"))
            {
                e.Cancel = true;
            }
        }

Thus, you can restrict which documents to be included in the xml.

Carlos
Top achievements
Rank 1
commented on 14 Jun 2023, 10:13 AM

Hi Dess, 

thank you for your support. I tried some of the ideas presented here but unfortunately I couldn't achieve what I wanted, even with the latest suggestion. This latest suggestion still adds extra information in the generated XML (not just the documents I wanted), thus preventing us to really only save and load what we desire. Once tried, I got some flickering in the other docking panels inside the RadDock, which looks weird (for the customer looks like a bug).

I also tried modifying this XML (for debugging purposes) to see if I could really only save the documents that I needed, but this feature of loading the XML loads absolutely everything in the RadDock, and deleted the other docked panels I already had placed inside that RadDock. It seems the loading deletes everything, and adds whatever this XML has.

It would be nice to have a feature where I can save/load only the documents I want without affecting anything else in the RadDock. But for now it's not possible for us to use it like it is because of the flickering of the window and the extra information that is saved/loaded with the current functionality.

Thank you again, and I will close this for now.

Dess | Tech Support Engineer, Principal
Telerik team
commented on 16 Jun 2023, 01:58 PM

Hi, Carlos,

I just wanted to share that we already have a feature request for suspending the layout while XML file is being loaded. Thus, side effects like flickering should be eliminated. You can track its progress, subscribe for status changes and add your comments on the following link: 

https://feedback.telerik.com/winforms/1591839-raddock-add-functionality-for-suspending-the-layout-while-loading-the-xml-layout-with-loadfromxml 

We are planning to investigate the possible options for this item for the next release. Stay tuned.

Tags
Dock
Asked by
Carlos
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or