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)?

asked 01 Jun '10, 20:48

Scott%20Whitlock's gravatar image

Scott Whitlock ♦♦
696262833
accept rate: 50%

1

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?

(02 Jun '10, 06:12) BSalita

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?

(02 Jun '10, 21:49) Scott Whitlock ♦♦

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.

(03 Jun '10, 01:32) BSalita

Thought about it some more. It would be better to add Unloading event to LayoutManger. I will make a formal request.

(04 Jun '10, 06:51) BSalita

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:

[Import(SoapBox.Core.Services.Layout.LayoutManager, typeof(ILayoutManager))]
private Lazy<ILayoutManager> layoutManager { get; set; }

Saving the Layout

Saving the layout is simple:

string layoutBlob = layoutManager.Value.SaveLayout();

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 Layout

Restoring is just as easy:

layoutManager.Value.RestoreLayout(layoutBlob);

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.

link

answered 01 Jun '10, 20:49

Scott%20Whitlock's gravatar image

Scott Whitlock ♦♦
696262833
accept rate: 50%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×23
×9
×2
×1

Asked: 01 Jun '10, 20:48

Seen: 1,997 times

Last updated: 04 Jun '10, 06:51

powered by OSQA