aui LoadPerspective with a new window

Leslie Newell lesnewell at fmail.co.uk
Tue Feb 12 11:02:32 PST 2008


The problem is that perspectives save the exact AUI state. If you add or 
remove something, the AUI manager gets upset. IMHO this is a fairly 
major problem with AUI.

I ended up writing my own version of LoadPerspective that gets around 
this. As it has considerably different behavior to the existing AUI load 
and could potentially break code that relies on it, I haven't submitted 
it as a patch. This version safely handles new/missing panes and also 
only updates the data that I think needs to be saved. It does not load 
the caption or size hints (I can't see why you would ever want to load 
these).

void wxPositionChecker::LoadAui(const wxString& name, wxAuiManager& 
manager, wxConfigBase& cfg, bool update)
{
    cfg.SetPath(name);
    wxAuiPaneInfoArray& panes = manager.GetAllPanes();
    int nPanes = panes.GetCount();
    for(int ct=0; ct<nPanes; ct++)
    {
        wxAuiPaneInfo& pane = panes[ct];
        wxString paneData;
        cfg.Read(pane.name,&paneData);
        if(!paneData.IsEmpty())
        {
            wxAuiPaneInfo tempPane;
            manager.LoadPaneInfo(paneData, tempPane);
            if (pane.IsOk())
            {
                tempPane.caption = pane.caption;
                tempPane.best_size = pane.best_size;
                tempPane.min_size = pane.min_size;
                tempPane.max_size = pane.max_size;
                pane.SafeSet(tempPane);
            }
        }
    }
    if(update)
    {
        manager.Update();
    }
    cfg.SetPath(_T(".."));
}


Les

Riccardo Cohen wrote:
> Hi
> I have 2 panes. and I save the perspective.
> Then I restart my program but for some reason there is an additionnal 
> pane in aui manager.(lets say on monday I need 3 panes)
>
> If I call LoadPerspective(), the 3rd pane disappear, since it is not 
> in the saved configuration.
> I tried to call Show() again, change the size etc. Impossible to see 
> the new window
> I tried to add the pane once more, and it gave me an assertion failure 
> (A pane with that name already exists in the manager!) but finally 
> showed the 3rd window:
>
>   // add the window
>   m_auiManager.AddPane(thirdwindow,paneinfo);
>
>   // load perspective that does not have the third window in it
>   m_auiManager.LoadPerspective(str);
>
>   // test if the window appear
>   wxSize size=thirdwindow->GetSize();
>   if (size.GetWidth()==0 || size.GetHeight()==0)
>     m_auiManager.AddPane(thirdwindow,paneinfo); // THIS GIVES AN 
> ASSERTION FAILURE BUT SHOWS THE WINDOW
>
>
> What is the best practice for this case ?
>
> Thanks
>





More information about the wx-users mailing list