aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Haumann <dhaumann@kde.org>2014-01-24 19:40:04 (GMT)
committerDominik Haumann <dhaumann@kde.org>2014-01-24 19:40:21 (GMT)
commitb2009c8357b56e1bcfd3c623352da96c25178f15 (patch)
treec0f7820700eb2c1900022b847c057c565f2fab78
parent6f38002e2e12bbc6fa7ca7a783dfec7727ec1e51 (diff)
merge tabs of closed viewspace into new active viewspace
-rw-r--r--kate/src/kateviewmanager.cpp14
-rw-r--r--kate/src/kateviewspace.cpp29
-rw-r--r--kate/src/kateviewspace.h16
3 files changed, 53 insertions, 6 deletions
diff --git a/kate/src/kateviewmanager.cpp b/kate/src/kateviewmanager.cpp
index f2c577c..45bbaa4 100644
--- a/kate/src/kateviewmanager.cpp
+++ b/kate/src/kateviewmanager.cpp
@@ -820,7 +820,16 @@ void KateViewManager::removeViewSpace(KateViewSpace *viewspace)
if (!currentSplitter) {
return;
}
-
+
+ //
+ // 1. get LRU document list from current viewspace
+ // 2. delete current view space
+ // 3. add LRU documents from deleted viewspace to new active viewspace
+ //
+
+ // backup LRU list
+ const QVector<KTextEditor::Document*> lruDocumntsList = viewspace->lruDocumentList();
+
// avoid flicker
KateUpdateDisabler disableUpdates (mainWindow());
@@ -865,6 +874,9 @@ void KateViewManager::removeViewSpace(KateViewSpace *viewspace)
currentSplitter->setSizes(sizes);
}
+ // merge docuemnts of closed view space
+ activeViewSpace()->mergeLruList(lruDocumntsList);
+
// find the view that is now active.
KTextEditor::View *v = activeViewSpace()->currentView();
if (v) {
diff --git a/kate/src/kateviewspace.cpp b/kate/src/kateviewspace.cpp
index 6f88265..a849a5e 100644
--- a/kate/src/kateviewspace.cpp
+++ b/kate/src/kateviewspace.cpp
@@ -138,6 +138,24 @@ void KateViewSpace::statusBarToggled()
}
}
+QVector<KTextEditor::Document*> KateViewSpace::lruDocumentList() const
+{
+ return m_lruDocList;
+}
+
+void KateViewSpace::mergeLruList(const QVector<KTextEditor::Document*> & lruList)
+{
+ // merge lruList documents that are not in m_lruDocList
+ QVectorIterator<KTextEditor::Document*> it(lruList);
+ it.toBack();
+ while (it.hasPrevious()) {
+ KTextEditor::Document *doc = it.previous();
+ if (! m_lruDocList.contains(doc)) {
+ registerDocument(doc, false);
+ }
+ }
+}
+
KTextEditor::View *KateViewSpace::createView(KTextEditor::Document *doc)
{
// should only be called if a view does not yet exist
@@ -328,20 +346,25 @@ void KateViewSpace::addTabs(int count)
}
}
-void KateViewSpace::registerDocument(KTextEditor::Document *doc)
+void KateViewSpace::registerDocument(KTextEditor::Document *doc, bool append)
{
// at this point, the doc should be completely unknown
Q_ASSERT(! m_lruDocList.contains(doc));
Q_ASSERT(! m_docToView.contains(doc));
Q_ASSERT(! m_docToTabId.contains(doc));
- m_lruDocList.append(doc);
+ if (append) {
+ m_lruDocList.append(doc);
+ } else {
+ // prepending == merge doc of closed viewspace
+ m_lruDocList.prepend(doc);
+ }
connect(doc, SIGNAL(destroyed(QObject*)), this, SLOT(documentDestroyed(QObject*)));
// if space is available, add button
if (m_tabBar->count() < m_tabBar->maxTabCount()) {
insertTab(m_tabBar->count(), doc);
- } else {
+ } else if (append) {
// remove "oldest" button and replace with new one
Q_ASSERT(m_lruDocList.size() > m_tabBar->count());
diff --git a/kate/src/kateviewspace.h b/kate/src/kateviewspace.h
index ccadd7b..c7ea294 100644
--- a/kate/src/kateviewspace.h
+++ b/kate/src/kateviewspace.h
@@ -65,10 +65,22 @@ public:
void restoreConfig(KateViewManager *viewMan, const KConfigBase *config, const QString &group);
/**
+ * Returns the document LRU list of this view space.
+ */
+ QVector<KTextEditor::Document*> lruDocumentList() const;
+
+ /**
+ * Called by the view manager if a viewspace was closed.
+ * The documents of the closed are merged into this viewspace
+ */
+ void mergeLruList(const QVector<KTextEditor::Document*> & lruList);
+
+ /**
* Called by the view manager to notify that new documents were created
- * while this view space was active.
+ * while this view space was active. If @p append is @e true, the @p doc
+ * is appended to the lru document list, otherwise, it is prepended.
*/
- void registerDocument(KTextEditor::Document *doc);
+ void registerDocument(KTextEditor::Document *doc, bool append = true);
/**
* Event filter to catch events from view space tool buttons.