Пример #1
0
bool MainBook::AddPage(wxWindow *win, const wxString &text, const wxBitmap &bmp, bool selected, size_t insert_at_index /*=wxNOT_FOUND*/)
{
    if (m_book->GetPageIndex(win) != Notebook::npos)
        return false;

    long MaxBuffers = clConfig::Get().Read("MaxOpenedTabs", 15);
    bool closeLastTab = ((long)(m_book->GetPageCount()) >= MaxBuffers) && GetUseBuffereLimit();
    if ((insert_at_index == (size_t)wxNOT_FOUND) || (insert_at_index >= m_book->GetPageCount())) {

#if CL_USE_NATIVEBOOK
        // There seems to be a bug in wxGTK where we can't change
        // the selection programtically
        int next_pos = m_book->GetPageCount();
#endif
        m_book->AddPage(win, text, closeLastTab ? true : selected, bmp);

#if CL_USE_NATIVEBOOK
        // If the newly added page is expected to be the selected one
        // and it is NOT of type IEditor we provide a workaround that
        // uses direct gtk calls
        bool shouldSelect = (closeLastTab ? true : selected);
        IEditor *editor = dynamic_cast<IEditor*>(win);
        if(shouldSelect && (m_book->GetSelection() != (size_t)next_pos) && !editor) {
            // failed to insert the page AND the page is not of type
            // IEditor
            gtk_widget_show_all (win->m_widget);
            m_book->SetSelection(next_pos);
        }
#endif
    } else {
        m_book->InsertPage(insert_at_index, win, text, closeLastTab ? true : selected, bmp);
    }

    if( closeLastTab ) {
        // We have reached the limit of the number of open buffers
        // Close the last used buffer
        const wxArrayPtrVoid &arr = m_book->GetHistory();
        if ( arr.GetCount() ) {
            // We got at least one page, close the last used
            wxWindow *tab = static_cast<wxWindow*>(arr.Item(arr.GetCount()-1));
            ClosePage(tab);
        }
    }

#if !CL_USE_NATIVEBOOK
    if(m_book->GetPageCount() == 1) {
        m_book->GetSizer()->Layout();
    }
#endif
    return true;
}
Пример #2
0
bool MainBook::AddPage(wxWindow* win,
    const wxString& text,
    const wxString& tooltip,
    const wxBitmap& bmp,
    bool selected,
    int insert_at_index /*=wxNOT_FOUND*/)
{
    if(m_book->GetPageIndex(win) != wxNOT_FOUND) return false;

    long MaxBuffers = clConfig::Get().Read(kConfigMaxOpenedTabs, 15);
    bool closeLastTab = ((long)(m_book->GetPageCount()) >= MaxBuffers) && GetUseBuffereLimit();
    if(insert_at_index == wxNOT_FOUND) {
        m_book->AddPage(win, text, selected, bmp);
    } else {
        if(!m_book->InsertPage(insert_at_index, win, text, selected, bmp)) {
            // failed to insert, append it
            m_book->AddPage(win, text, selected, bmp);
        }
    }

    if(closeLastTab) {
#if 0
        // We have reached the limit of the number of open buffers
        // Close the last used buffer
        const wxArrayPtrVoid& arr = m_book->GetHistory();
        if(arr.GetCount()) {
            // We got at least one page, close the last used
            wxWindow* tab = static_cast<wxWindow*>(arr.Item(arr.GetCount() - 1));
            ClosePage(tab);
        }
#endif
    }

#if !CL_USE_NATIVEBOOK
    if(m_book->GetPageCount() == 1) {
        m_book->GetSizer()->Layout();
    }
#endif
    if(!tooltip.IsEmpty()) {
        m_book->SetPageToolTip(m_book->GetPageIndex(win), tooltip);
    }
    return true;
}