locked
Saving UI state when closing a custom editor. RRS feed

  • Question

  • I have a custom editor within a Dev10-based VSPackage and need to save the UI state (open-close state of treeview folders, etc) between VS sessions as well as between open-close operations on the editor.  In my WindowPane-derived class, I override IVsUIElementPane.SaveUIElementState and LoadUIElementState.  Those methods are called by the shell when I open/close the solution and everything seems to work fine.  However, those methods do not seem to be called when I simply close the pane and re-open it.  Is that the expected behavior of those methods?

    I'd like to preserve UI state in both scenarios.  Do I need to use some out-of-band mechanism to save UI state across editor open/close operations (when the project itself is not being closed), such as saving the state on the ProjectNode or some such?

    Any advice is much appreciated.

    Thanks in advance.

    Tuesday, October 16, 2012 5:04 PM

Answers

  • I really am not very familiar with this area, a quick look at the code implies to me that it is only ever called when closing a project/re-opening a project, as you seem to be seeing. This doesn’t appear accidental, I suspect it is a long standing behavior, why it was designed this way, I don’t know.

    > It would seem to be a fairly common requirement

    I don’t think it is really that common. I suspect the design centers around the fact that editors, by and large, are expected to be text editors or visual designers. I can’t think of any built in ones that remember previous-state for and each and every file they have edited in the past and re-apply it every time you open that file. The reason it happens for things that were opened when the project was closed is probably the idea that you were still working on these items so you may want to bring your context back next time you load the project. The same is not necessarily true of an editor you have explicitly closed.

    I suspect if you want this to work you need your editor factory to supply the state to your editors and you need to persist it yourself in your own storage location on editor closing.

    Ryan

    Wednesday, October 24, 2012 5:09 PM

All replies

  • Hi Kirk,

    Can we use WindowPane.LoadUIState to load UI state?

    The article below may be useful to you:

    http://blogs.msdn.com/b/visualstudio/archive/2010/03/16/wpf-in-visual-studio-2010-part-4-direct-hosting-of-wpf-content.aspx

    Best regards,

    Disley

    Thursday, October 18, 2012 6:10 AM
  • Hello Disley,

    Thanks very much for your reply.  Indeed, I am using precisely that at the moment.  And, it does work, but that method only seems to get called when opening or closing the project itself.  It does not seem to get called when open/closing the editor.  I would like the user to see the editor come up in the state in which they last left it after closing the editor -- not in the last state it was when they closed the entire project.

    Thursday, October 18, 2012 2:09 PM
  • I really am not very familiar with this area, a quick look at the code implies to me that it is only ever called when closing a project/re-opening a project, as you seem to be seeing. This doesn’t appear accidental, I suspect it is a long standing behavior, why it was designed this way, I don’t know.

    > It would seem to be a fairly common requirement

    I don’t think it is really that common. I suspect the design centers around the fact that editors, by and large, are expected to be text editors or visual designers. I can’t think of any built in ones that remember previous-state for and each and every file they have edited in the past and re-apply it every time you open that file. The reason it happens for things that were opened when the project was closed is probably the idea that you were still working on these items so you may want to bring your context back next time you load the project. The same is not necessarily true of an editor you have explicitly closed.

    I suspect if you want this to work you need your editor factory to supply the state to your editors and you need to persist it yourself in your own storage location on editor closing.

    Ryan

    Wednesday, October 24, 2012 5:09 PM
  • Hi Ryan,

    Thanks for taking the time to look at the code for us.  I appreciate your insights.  We'll figure out if the user really needs this level of persistence and go from there.  Not hard to do on our own, just didn't know if there already was something available.

    Thanks again.

    Wednesday, October 24, 2012 5:11 PM