aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Haumann <dhaumann@kde.org>2014-01-22 00:32:55 (GMT)
committerDominik Haumann <dhaumann@kde.org>2014-01-22 11:37:51 (GMT)
commit4c0a321e216d3c96e7608bdc79bcfdb906d91148 (patch)
treed7bb3043384813162745c7b672024d86aefd4069
parent271b4e9adc88db1db752bd05749296e4e3f4059b (diff)
tab bar: for documents without view, still add a button (lazy loading)
-rw-r--r--kate/app/kateviewmanager.cpp4
-rw-r--r--kate/app/kateviewspace.cpp56
-rw-r--r--kate/app/kateviewspace.h14
3 files changed, 64 insertions, 10 deletions
diff --git a/kate/app/kateviewmanager.cpp b/kate/app/kateviewmanager.cpp
index 0ef2aa8..f2d29f5 100644
--- a/kate/app/kateviewmanager.cpp
+++ b/kate/app/kateviewmanager.cpp
@@ -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;
}
diff --git a/kate/app/kateviewspace.cpp b/kate/app/kateviewspace.cpp
index 9d4799f..141140d 100644
--- a/kate/app/kateviewspace.cpp
+++ b/kate/app/kateviewspace.cpp
@@ -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()<<")";
diff --git a/kate/app/kateviewspace.h b/kate/app/kateviewspace.h
index b30f995..a194538 100644
--- a/kate/app/kateviewspace.h
+++ b/kate/app/kateviewspace.h
@@ -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