|
How do I save the layout of the pads and documents and restore the layout later (when the user resumes the session or opens the project again)? |
|
Earlier versions of SoapBox Core automatically saved the layout when the application exited, and restored the layout when it restarted. A real application has more complicated needs. You probably want to save the state of the layout along with some user saved file, and restore it when they open that project, solution, or whatever. Now you can do this. First, make sure you have a reference to your LayoutManager service:
Saving the LayoutSaving the layout is simple:
The layoutBlob string you get back is actually three Base64 encoded strings separated by dots (.) so the blob is easy to store inside of XML or other save files. Restoring the LayoutRestoring is just as easy:
The layout manager will show all the pads you originally had open, and it will also show all the documents. Note that this means it's going to show the document and pass in the memento string that the document was exposing as the Memento property when you called SaveLayout. Typically this is a file name, so it should work fine, but it's up to your logic to interpret what the Memento means in your overloaded CreateDocument routine, so that it opens the right file, view, or whatever. |
I tried putting SaveLayout in ShutdownCommand but it errors out because Layout manager has been unloaded. Putting it in LayoutUpdated event seems like a good alternative except the event is called very frequently such as when the mousepointer skims the menubar. Too frequently to be doing a SaveLayout. I think LayoutManager should have an Unloading event or am I missing something?
I think you're right that we could add an Unloading event to Layout Manager, but for now, would it work if you hooked a reference to Main Window and grabbed the closing event? Can you add the idea of the LayoutManager.Unloading event as a new question, and tag it with the feature-request tag?
I'll hook MainWindow Closing event. Likely that's entirely satisfactory. The only issue is that LayoutManager Unloading event guarantees the last best time to SaveLayout whereas MainWindow Closing makes no such guarantee about LayoutManager status.
Thought about it some more. It would be better to add Unloading event to LayoutManger. I will make a formal request.