Kirix Support Forums

Recommended way to save perspective in wxAuiNotebook

Please post all general questions, comments, bug reports, and any other wxAUI feedback here.

Recommended way to save perspective in wxAuiNotebook

Postby astigsen on Wed Sep 12, 2007 7:17 am

What is the recommended way to save perspective in wxAuiNotebook so that you can restore it with the same splits and tab orders?

I noticed that you can get a reference to the underlying manager, but I don't assume that the perspective from that contains any info about the tabs.
astigsen
Registered User
 
Posts: 8
Joined: Thu Jan 26, 2006 9:06 am

Re: Recommended way to save perspective in wxAuiNotebook

Postby Ben on Thu Sep 13, 2007 12:16 am

Hi there,

This functionality is not yet in wxAUI. So, unfortunately, the answer is that you have to code the load/save routine yourself.

This has been on the list of things to do ever since wxAuiNotebook was first included in wxAUI, but I still haven't had time to do it yet.

The way it needs to be done is actually through wxAuiManager. If you look inside auibook.h, you will see various tab classes, some windowed and some window-less. The window-less classes exist for future integration with wxAuiManager. We want to be able to plug the notebook functionality into the aui manager directly.

Best,
Ben
Ben Williams
Kirix Support Team
User avatar
Ben
Kirix Support Team
 
Posts: 522
Joined: Mon Dec 19, 2005 6:29 am

Re: Recommended way to save perspective in wxAuiNotebook

Postby astigsen on Mon Sep 17, 2007 4:32 pm

Hi Ben,

Do you have any plans about how it should be implemented? If I do implement it, it would be nice if I could submit it as a patch so you could save the double work.
astigsen
Registered User
 
Posts: 8
Joined: Thu Jan 26, 2006 9:06 am

Re: Recommended way to save perspective in wxAuiNotebook

Postby Ben on Mon Sep 17, 2007 11:48 pm

Hello,

It'd be fantastic if you could give it a try. It needs to be done like this:

1) wxAuiPaneInfo already has parameters specifying position: Direction, Layer, Row, etc. You would first need to add another one called Page. "page" by default would be zero for all pages added. If two tabs are docked in the same Direction/Layer/Row/Position, and their page variables are different, then tabs are automatically formed. For example, if you have two pane's, each in the exact same position, one with page 0 and one with page 1, tabs will form.

2) The work of forming tab controls would happen in the Update process. Pretty much all of wxAuiManager's work takes place there. The idea is that you have an array of panes, can change it as much as you want, and then commit the work by calling wxAuiMAnager::Update. This makes serializing/saving the pane array effortless.

3) I have already coded several classes which may be of use. wxAuiTabContainer is a window-less tab container control. There is also wxAuiTabArt which can draw tabs. The implementation might be able to make use of these. If it turns out to be too complicated to use them, I wouldn't force it though.

4) Basically, to sum it up, the main requirement is that tabs are not extra controls added to the frame window. They must be windowless controls, drawing directly on the owned frame, just like the rest of wxAUI. This allows effortless serialization.

Hope this helps.

All the best,
Ben
Ben Williams
Kirix Support Team
User avatar
Ben
Kirix Support Team
 
Posts: 522
Joined: Mon Dec 19, 2005 6:29 am

Re: Recommended way to save perspective in wxAuiNotebook

Postby astigsen on Wed Oct 17, 2007 10:49 am

Hi Ben,

I have made a simple implementation of Load/SavePerspective. It is really basic in that it just prepends information about the tab order to the framemanagers perspective string. This means that it is up to the app to track what is in the individual tabs.

Code: Select all
wxString wxAuiNotebook::SavePerspective() {
   // Build list of panes/tabs
   wxString tabs;
   wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes();
    const size_t pane_count = all_panes.GetCount();

    for (size_t i = 0; i < pane_count; ++i)
    {
      wxAuiPaneInfo& pane = all_panes.Item(i);
      if (pane.name == wxT("dummy"))
            continue;

        wxTabFrame* tabframe = (wxTabFrame*)pane.window;
      
      if (!tabs.empty()) tabs += wxT("|");
      tabs += pane.name;
      tabs += wxT("=");
      
      // add tab id's
      size_t page_count = tabframe->m_tabs->GetPageCount();
      for (size_t p = 0; p < page_count; ++p)
      {
         wxAuiNotebookPage& page = tabframe->m_tabs->GetPage(p);
         const size_t page_idx = m_tabs.GetIdxFromWindow(page.window);
         
         if (p) tabs += wxT(",");

         if ((int)page_idx == m_curpage) tabs += wxT("*");
         else if ((int)p == tabframe->m_tabs->GetActivePage()) tabs += wxT("+");
         tabs += wxString::Format(wxT("%u"), page_idx);
      }
   }
   tabs += wxT("@");

   // Add frame perspective
   tabs += m_mgr.SavePerspective();

   return tabs;
}

bool wxAuiNotebook::LoadPerspective(const wxString& layout) {
   // Remove all tab ctrls (but still keep them in main index)
   const size_t tab_count = m_tabs.GetPageCount();
   for (size_t i = 0; i < tab_count; ++i) {
      wxWindow* wnd = m_tabs.GetWindowFromIdx(i);

      // find out which onscreen tab ctrl owns this tab
      wxAuiTabCtrl* ctrl;
      int ctrl_idx;
      if (!FindTab(wnd, &ctrl, &ctrl_idx))
         return false;

      // remove the tab from ctrl
      if (!ctrl->RemovePage(wnd))
         return false;
   }
   RemoveEmptyTabFrames();

   size_t sel_page = 0;
   
   wxString tabs = layout.BeforeFirst(wxT('@'));
   while (1)
    {
      const wxString tab_part = tabs.BeforeFirst(wxT('|'));
      
      // if the string is empty, we're done parsing
        if (tab_part.empty())
            break;

      // Get pane name
      const wxString pane_name = tab_part.BeforeFirst(wxT('='));

      // create a new tab frame
      wxTabFrame* new_tabs = new wxTabFrame;
      new_tabs->m_tabs = new wxAuiTabCtrl(this,
                                 m_tab_id_counter++,
                                 wxDefaultPosition,
                                 wxDefaultSize,
                                 wxNO_BORDER|wxWANTS_CHARS);
      new_tabs->m_tabs->SetArtProvider(m_tabs.GetArtProvider()->Clone());
      new_tabs->SetTabCtrlHeight(m_tab_ctrl_height);
      new_tabs->m_tabs->SetFlags(m_flags);
      wxAuiTabCtrl *dest_tabs = new_tabs->m_tabs;

      // create a pane info structure with the information
      // about where the pane should be added
      wxAuiPaneInfo pane_info = wxAuiPaneInfo().Name(pane_name).Bottom().CaptionVisible(false);
      m_mgr.AddPane(new_tabs, pane_info);

      // Get list of tab id's and move them to pane
      wxString tab_list = tab_part.AfterFirst(wxT('='));
      while(1) {
         wxString tab = tab_list.BeforeFirst(wxT(','));
         if (tab.empty()) break;
         tab_list = tab_list.AfterFirst(wxT(','));

         // Check if this page has an 'active' marker
         const wxChar c = tab[0];
         if (c == wxT('+') || c == wxT('*')) {
            tab = tab.Mid(1);
         }

         const size_t tab_idx = wxAtoi(tab.c_str());
         if (tab_idx >= GetPageCount()) continue;

         // Move tab to pane
         wxAuiNotebookPage& page = m_tabs.GetPage(tab_idx);
         const size_t newpage_idx = dest_tabs->GetPageCount();
         dest_tabs->InsertPage(page.window, page, newpage_idx);

         if (c == wxT('+')) dest_tabs->SetActivePage(newpage_idx);
         else if ( c == wxT('*')) sel_page = tab_idx;
      }
      dest_tabs->DoShowHide();

      tabs = tabs.AfterFirst(wxT('|'));
   }
   
   // Load the frame perspective
   const wxString frames = layout.AfterFirst(wxT('@'));
   m_mgr.LoadPerspective(frames);

   // Force refresh of selection
   m_curpage = -1;
   SetSelection(sel_page);

   return true;
}


I have not submitted it as an official patch yet, as the approach is a bit different from what you had suggested, and I would like for you to take a look at it first.
astigsen
Registered User
 
Posts: 8
Joined: Thu Jan 26, 2006 9:06 am

Re: Recommended way to save perspective in wxAuiNotebook

Postby Ben on Mon Oct 22, 2007 6:48 am

Hello,

I will take a look at it. Thanks so much.

Best,
Ben
Ben Williams
Kirix Support Team
User avatar
Ben
Kirix Support Team
 
Posts: 522
Joined: Mon Dec 19, 2005 6:29 am

Re: Recommended way to save perspective in wxAuiNotebook

Postby mgenti on Thu Dec 13, 2007 12:59 pm

Has there been anymore development on this? I've tried astigsen's code and it seems to work most of the time, sometimes the tabs are in the wrong order.
--Mark
mgenti
Registered User
 
Posts: 1
Joined: Fri Nov 02, 2007 2:07 pm

Re: Recommended way to save perspective in wxAuiNotebook

Postby Game_Ender on Wed Jan 16, 2008 3:23 pm

I too would like to here about this. I would start using this immediately only it would require a custom version of wxWidgets & wxPython which is impossible for me to do at the moment. I checked SVN its not in there right now.

It seems like you have a larger plan for nicer integration, but you can always change how the feature works after you implement this basic version. The interface won't be changing.
Game_Ender
Registered User
 
Posts: 5
Joined: Sat Feb 18, 2006 12:33 pm

Re: Recommended way to save perspective in wxAuiNotebook

Postby Ben on Sat Jan 19, 2008 12:44 pm

Hello all,

The reason I hesitate with all of the proposed solutions is that the only way to do this right is a full implementation. That involves getting your hands dirty with wxAuiManager. This is why nobody has done it yet. Unfortunately we can't settle for band-aid solutions in this case.

Seeing all of the proposals people submit has really inspired a lot of good ideas which will finally go into the final solution, so I'm really happy about the proposals I've seen thus far. Thanks.

Best,
Ben
Ben Williams
Kirix Support Team
User avatar
Ben
Kirix Support Team
 
Posts: 522
Joined: Mon Dec 19, 2005 6:29 am

Re: Recommended way to save perspective in wxAuiNotebook

Postby evstevemd on Fri Sep 17, 2010 3:45 am

Hi Ben,
Where have you reached so far?
I would be happy to save my notebook Layout and reload them
evstevemd
Registered User
 
Posts: 5
Joined: Sun Jan 24, 2010 9:38 am

Return to wxAUI Questions, Thoughts & Feedback