Commit 4c0a321e authored by Dominik Haumann's avatar Dominik Haumann

tab bar: for documents without view, still add a button (lazy loading)

parent 271b4e9a
......@@ -331,6 +331,9 @@ KateMainWindow *KateViewManager::mainWindow()
void KateViewManager::documentCreated (KTextEditor::Document *doc)
{
// forward to currently active view space
activeViewSpace()->registerDocumentWhileActive(doc);
// to update open recent files on saving
connect (doc, SIGNAL(documentSavedOrUploaded(KTextEditor::Document*,bool)), this, SLOT(documentSavedOrUploaded(KTextEditor::Document*,bool)));
......@@ -439,6 +442,7 @@ KateViewSpace* KateViewManager::activeViewSpace ()
return m_viewSpaceList.first();
}
Q_ASSERT(false);
return 0L;
}
......
......@@ -113,12 +113,21 @@ KTextEditor::View *KateViewSpace::createView (KTextEditor::Document *doc)
}
}
// add to tab bar
const int index = m_tabBar->addTab(doc->url().toString(), doc->documentName());
Q_ASSERT(index >= 0);
m_viewToTabId[v] = index;
// check whether the document is in lazy list
if (m_docToTabId.contains(doc)) {
// reuse tab id by moving it from doc mapper to view mapper
m_viewToTabId[v] = m_docToTabId[doc];
// no need to track it here anymore
m_docToTabId.remove(doc);
disconnect(doc, SIGNAL(destroyed(QObject*)), this, SLOT(documentDestroyed(QObject*)));
} else {
// create new tab bar button
const int index = m_tabBar->addTab(doc->url().toString(), doc->documentName());
Q_ASSERT(index >= 0);
m_viewToTabId[v] = index;
}
// insert into stack
// insert View into stack
stack->addWidget(v);
mViewList.append(v);
showView( v );
......@@ -176,12 +185,21 @@ bool KateViewSpace::showView(KTextEditor::Document *document)
void KateViewSpace::changeView(int buttonId)
{
KTextEditor::View * view = m_viewToTabId.key(buttonId);
Q_ASSERT(view);
if (view != currentView()) {
showView(view);
// lazy button?
KTextEditor::Document * doc = m_docToTabId.key(buttonId);
if (doc) {
// make sure this view space is active, so that the view is created in this view
m_viewManager->setActiveSpace(this);
m_viewManager->createView(doc);
} else {
KTextEditor::View * view = m_viewToTabId.key(buttonId);
Q_ASSERT(view);
if (view != currentView()) {
showView(view);
}
}
Q_ASSERT(! m_docToTabId.contains(doc));
}
KTextEditor::View* KateViewSpace::currentView()
......@@ -204,6 +222,24 @@ void KateViewSpace::setActive( bool active, bool )
// FIXME KF5 mStatusBar->setEnabled(active);
}
void KateViewSpace::registerDocumentWhileActive(KTextEditor::Document *doc)
{
Q_ASSERT( ! m_docToTabId.contains(doc));
// add lazy to tab bar
const int index = m_tabBar->addTab(doc->url().toString(), doc->documentName());
m_docToTabId[doc] = index;
connect(doc, SIGNAL(destroyed(QObject*)), this, SLOT(documentDestroyed(QObject*)));
}
void KateViewSpace::documentDestroyed(QObject * doc)
{
Q_ASSERT(m_docToTabId.contains(static_cast<KTextEditor::Document*>(doc)));
const int index = m_docToTabId[static_cast<KTextEditor::Document*>(doc)];
m_tabBar->removeTab(index);
m_docToTabId.remove(static_cast<KTextEditor::Document*>(doc));
}
void KateViewSpace::saveConfig ( KConfigBase* config, int myIndex , const QString& viewConfGrp)
{
// qCDebug(LOG_KATE)<<"KateViewSpace::saveConfig("<<myIndex<<", "<<viewConfGrp<<") - currentView: "<<currentView()<<")";
......
......@@ -70,6 +70,15 @@ class KateViewSpace : public QFrame
void saveConfig (KConfigBase* config, int myIndex, const QString& viewConfGrp);
void restoreConfig ( KateViewManager *viewMan, const KConfigBase* config, const QString &group );
/**
* Called by the view manager to notify that new documents were created
* while this view space was active.
*/
void registerDocumentWhileActive(KTextEditor::Document *doc);
public Q_SLOTS:
void documentDestroyed(QObject * doc);
private Q_SLOTS:
void statusBarToggled ();
void changeView(int buttonId);
......@@ -84,8 +93,13 @@ class KateViewSpace : public QFrame
QList<KTextEditor::View*> mViewList;
KateViewManager *m_viewManager;
QString m_group;
// tab bar that contains viewspace tabs
KateTabBar * m_tabBar;
// map from View to button id
QHash<KTextEditor::View*, int> m_viewToTabId;
// map from lazy Document to button id. contains only Documents that have no view
QHash<KTextEditor::Document*, int> m_docToTabId;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment