mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
TabTreeModel: Sync top-level tabs with main tabbar
This way the order of top-level tabs is also preserved in session.
This commit is contained in:
parent
a1101c129c
commit
e9f3679bb1
@ -19,6 +19,7 @@
|
|||||||
#include "tabmodel.h"
|
#include "tabmodel.h"
|
||||||
#include "webtab.h"
|
#include "webtab.h"
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
|
|
||||||
class TabTreeModelItem
|
class TabTreeModelItem
|
||||||
@ -83,6 +84,11 @@ void TabTreeModelItem::addChild(TabTreeModelItem *item, int index)
|
|||||||
TabTreeModel::TabTreeModel(QObject *parent)
|
TabTreeModel::TabTreeModel(QObject *parent)
|
||||||
: QAbstractProxyModel(parent)
|
: QAbstractProxyModel(parent)
|
||||||
{
|
{
|
||||||
|
m_syncTimer = new QTimer(this);
|
||||||
|
m_syncTimer->setInterval(100);
|
||||||
|
m_syncTimer->setSingleShot(true);
|
||||||
|
connect(m_syncTimer, &QTimer::timeout, this, &TabTreeModel::syncTopLevelTabs);
|
||||||
|
|
||||||
connect(this, &QAbstractProxyModel::sourceModelChanged, this, &TabTreeModel::init);
|
connect(this, &QAbstractProxyModel::sourceModelChanged, this, &TabTreeModel::init);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,6 +239,7 @@ bool TabTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action, in
|
|||||||
}
|
}
|
||||||
m_root->addChild(it, childPos);
|
m_root->addChild(it, childPos);
|
||||||
endMoveRows();
|
endMoveRows();
|
||||||
|
m_syncTimer->start();
|
||||||
} else {
|
} else {
|
||||||
parentItem->tab->addChildTab(tab, row);
|
parentItem->tab->addChildTab(tab, row);
|
||||||
}
|
}
|
||||||
@ -383,6 +390,7 @@ void TabTreeModel::connectTab(WebTab *tab)
|
|||||||
}
|
}
|
||||||
m_root->addChild(item, pos);
|
m_root->addChild(item, pos);
|
||||||
endMoveRows();
|
endMoveRows();
|
||||||
|
m_syncTimer->start();
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(tab, &WebTab::childTabAdded, this, [=](WebTab *child, int pos) {
|
connect(tab, &WebTab::childTabAdded, this, [=](WebTab *child, int pos) {
|
||||||
@ -399,5 +407,35 @@ void TabTreeModel::connectTab(WebTab *tab)
|
|||||||
}
|
}
|
||||||
item->addChild(from, childPos);
|
item->addChild(from, childPos);
|
||||||
endMoveRows();
|
endMoveRows();
|
||||||
|
if (item->parent == m_root) {
|
||||||
|
m_syncTimer->start();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabTreeModel::syncTopLevelTabs()
|
||||||
|
{
|
||||||
|
// Move all normal top-level tabs to the beginning to preserve order in session
|
||||||
|
|
||||||
|
int index = -1;
|
||||||
|
|
||||||
|
const auto items = m_root->children;
|
||||||
|
for (TabTreeModelItem *item : items) {
|
||||||
|
if (!item->tab->isPinned()) {
|
||||||
|
const int tabIndex = item->tab->tabIndex();
|
||||||
|
if (index < 0 || tabIndex < index) {
|
||||||
|
index = tabIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (TabTreeModelItem *item : items) {
|
||||||
|
if (!item->tab->isPinned()) {
|
||||||
|
item->tab->moveTab(index++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
#include "qzcommon.h"
|
#include "qzcommon.h"
|
||||||
|
|
||||||
|
class QTimer;
|
||||||
|
|
||||||
class WebTab;
|
class WebTab;
|
||||||
class TabTreeModelItem;
|
class TabTreeModelItem;
|
||||||
|
|
||||||
@ -62,7 +64,9 @@ private:
|
|||||||
void insertIndex(const QModelIndex &sourceIndex);
|
void insertIndex(const QModelIndex &sourceIndex);
|
||||||
void removeIndex(const QModelIndex &sourceIndex);
|
void removeIndex(const QModelIndex &sourceIndex);
|
||||||
void connectTab(WebTab *tab);
|
void connectTab(WebTab *tab);
|
||||||
|
void syncTopLevelTabs();
|
||||||
|
|
||||||
TabTreeModelItem *m_root = nullptr;
|
TabTreeModelItem *m_root = nullptr;
|
||||||
QHash<WebTab*, TabTreeModelItem*> m_items;
|
QHash<WebTab*, TabTreeModelItem*> m_items;
|
||||||
|
QTimer *m_syncTimer = nullptr;
|
||||||
};
|
};
|
||||||
|
@ -634,6 +634,13 @@ void WebTab::closeTab()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebTab::moveTab(int to)
|
||||||
|
{
|
||||||
|
if (m_tabBar) {
|
||||||
|
m_tabBar->tabWidget()->moveTab(tabIndex(), to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int WebTab::tabIndex() const
|
int WebTab::tabIndex() const
|
||||||
{
|
{
|
||||||
return m_tabBar ? m_tabBar->tabWidget()->indexOf(const_cast<WebTab*>(this)) : -1;
|
return m_tabBar ? m_tabBar->tabWidget()->indexOf(const_cast<WebTab*>(this)) : -1;
|
||||||
|
@ -102,6 +102,7 @@ public:
|
|||||||
bool isCurrentTab() const;
|
bool isCurrentTab() const;
|
||||||
void makeCurrentTab();
|
void makeCurrentTab();
|
||||||
void closeTab();
|
void closeTab();
|
||||||
|
void moveTab(int to);
|
||||||
|
|
||||||
bool haveInspector() const;
|
bool haveInspector() const;
|
||||||
void showWebInspector(bool inspectElement = false);
|
void showWebInspector(bool inspectElement = false);
|
||||||
|
Loading…
Reference in New Issue
Block a user