summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Haumann <dhaumann@kde.org>2014-01-22 11:34:00 (GMT)
committerDominik Haumann <dhaumann@kde.org>2014-01-22 11:37:51 (GMT)
commitdb0734e5a309bcb26a150e7373dbddc8369bc3bb (patch)
treebc458cb54222994cba9cbf2f0ebedcd39789732f
parent4c0a321e216d3c96e7608bdc79bcfdb906d91148 (diff)
simplify keeping track of tabs
-rw-r--r--kate/app/kateviewmanager.cpp2
-rw-r--r--kate/app/kateviewspace.cpp69
-rw-r--r--kate/app/kateviewspace.h9
3 files changed, 41 insertions, 39 deletions
diff --git a/kate/app/kateviewmanager.cpp b/kate/app/kateviewmanager.cpp
index f2d29f5..6da1b14 100644
--- a/kate/app/kateviewmanager.cpp
+++ b/kate/app/kateviewmanager.cpp
@@ -332,7 +332,7 @@ KateMainWindow *KateViewManager::mainWindow()
void KateViewManager::documentCreated (KTextEditor::Document *doc)
{
// forward to currently active view space
- activeViewSpace()->registerDocumentWhileActive(doc);
+ activeViewSpace()->registerDocument(doc);
// to update open recent files on saving
connect (doc, SIGNAL(documentSavedOrUploaded(KTextEditor::Document*,bool)), this, SLOT(documentSavedOrUploaded(KTextEditor::Document*,bool)));
diff --git a/kate/app/kateviewspace.cpp b/kate/app/kateviewspace.cpp
index 141140d..370f3fa 100644
--- a/kate/app/kateviewspace.cpp
+++ b/kate/app/kateviewspace.cpp
@@ -113,18 +113,10 @@ KTextEditor::View *KateViewSpace::createView (KTextEditor::Document *doc)
}
}
- // 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;
+ // make sure the document is registered
+ if ( ! m_docToTabId.contains(doc)) {
+ registerDocument(doc);
+ Q_ASSERT(m_docToTabId.contains(doc));
}
// insert View into stack
@@ -138,9 +130,8 @@ KTextEditor::View *KateViewSpace::createView (KTextEditor::Document *doc)
void KateViewSpace::removeView(KTextEditor::View* v)
{
// remove from tab bar
- Q_ASSERT(m_viewToTabId.contains(v));
- m_tabBar->removeTab(m_viewToTabId[v]);
- m_viewToTabId.remove(v);
+ Q_ASSERT(m_docToTabId.contains(v->document()));
+ documentDestroyed(v->document());
// remove from view space
bool active = ( v == currentView() );
@@ -156,6 +147,18 @@ void KateViewSpace::removeView(KTextEditor::View* v)
showView(mViewList.last());
}
+KTextEditor::View * KateViewSpace::viewForDocument(KTextEditor::Document * doc) const
+{
+ QList<KTextEditor::View*>::const_iterator it = mViewList.constEnd();
+ while (it != mViewList.constBegin()) {
+ --it;
+ if ((*it)->document() == doc) {
+ return *it;
+ }
+ }
+ return 0;
+}
+
bool KateViewSpace::showView(KTextEditor::Document *document)
{
QList<KTextEditor::View*>::const_iterator it = mViewList.constEnd();
@@ -173,9 +176,9 @@ bool KateViewSpace::showView(KTextEditor::Document *document)
kv->show();
// raise tab in tab bar
- Q_ASSERT(m_viewToTabId.contains(kv));
-// m_tabBar->raiseTab(m_viewToTabId[kv]);
- m_tabBar->setCurrentTab(m_viewToTabId[kv]);
+ Q_ASSERT(m_docToTabId.contains(document));
+// m_tabBar->raiseTab(m_docToTabId[document]);
+ m_tabBar->setCurrentTab(m_docToTabId[document]);
return true;
}
@@ -185,21 +188,10 @@ bool KateViewSpace::showView(KTextEditor::Document *document)
void KateViewSpace::changeView(int buttonId)
{
- // 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));
+ Q_ASSERT(doc);
+
+ showView(doc);
}
KTextEditor::View* KateViewSpace::currentView()
@@ -222,10 +214,10 @@ void KateViewSpace::setActive( bool active, bool )
// FIXME KF5 mStatusBar->setEnabled(active);
}
-void KateViewSpace::registerDocumentWhileActive(KTextEditor::Document *doc)
+void KateViewSpace::registerDocument(KTextEditor::Document *doc)
{
Q_ASSERT( ! m_docToTabId.contains(doc));
- // add lazy to tab bar
+ // add to tab bar
const int index = m_tabBar->addTab(doc->url().toString(), doc->documentName());
m_docToTabId[doc] = index;
@@ -238,6 +230,15 @@ void KateViewSpace::documentDestroyed(QObject * doc)
const int index = m_docToTabId[static_cast<KTextEditor::Document*>(doc)];
m_tabBar->removeTab(index);
m_docToTabId.remove(static_cast<KTextEditor::Document*>(doc));
+ disconnect(doc, SIGNAL(destroyed(QObject*)), this, SLOT(documentDestroyed(QObject*)));
+}
+
+void KateViewSpace::updateDocumentName(KTextEditor::Document* doc)
+{
+ const int buttonId = m_docToTabId[doc];
+ Q_ASSERT(buttonId >= 0);
+ m_tabBar->setTabText(buttonId, doc->documentName());
+ m_tabBar->setTabURL(buttonId, doc->url().toDisplayString());
}
void KateViewSpace::saveConfig ( KConfigBase* config, int myIndex , const QString& viewConfGrp)
diff --git a/kate/app/kateviewspace.h b/kate/app/kateviewspace.h
index a194538..e7e6de7 100644
--- a/kate/app/kateviewspace.h
+++ b/kate/app/kateviewspace.h
@@ -61,6 +61,8 @@ class KateViewSpace : public QFrame
}
bool showView(KTextEditor::Document *document);
+ KTextEditor::View * viewForDocument(KTextEditor::Document *document) const;
+
KTextEditor::View* currentView();
int viewCount() const
{
@@ -74,10 +76,11 @@ class KateViewSpace : public QFrame
* Called by the view manager to notify that new documents were created
* while this view space was active.
*/
- void registerDocumentWhileActive(KTextEditor::Document *doc);
+ void registerDocument(KTextEditor::Document *doc);
public Q_SLOTS:
void documentDestroyed(QObject * doc);
+ void updateDocumentName(KTextEditor::Document* doc);
private Q_SLOTS:
void statusBarToggled ();
@@ -96,9 +99,7 @@ class KateViewSpace : public QFrame
// 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
+ // map from Document to button id
QHash<KTextEditor::Document*, int> m_docToTabId;
};