Commit b2009c83 authored by Dominik Haumann's avatar Dominik Haumann

merge tabs of closed viewspace into new active viewspace

parent 6f38002e
......@@ -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) {
......
......@@ -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());
......
......@@ -64,11 +64,23 @@ public:
void saveConfig(KConfigBase *config, int myIndex, const QString &viewConfGrp);
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.
......
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