mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
When closing tab opened from another tab, it will get back to parent tab
if no tabs have been changed or moved.
This commit is contained in:
parent
8fccdf0848
commit
3e13ea8442
@ -99,6 +99,7 @@ TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent) :
|
|||||||
QTabWidget(parent)
|
QTabWidget(parent)
|
||||||
,p_QupZilla(mainClass)
|
,p_QupZilla(mainClass)
|
||||||
,m_lastTabIndex(0)
|
,m_lastTabIndex(0)
|
||||||
|
,m_isClosingToLastTabIndex(false)
|
||||||
,m_closedTabsManager(new ClosedTabsManager(this))
|
,m_closedTabsManager(new ClosedTabsManager(this))
|
||||||
{
|
{
|
||||||
m_tabBar = new TabBar(p_QupZilla);
|
m_tabBar = new TabBar(p_QupZilla);
|
||||||
@ -118,6 +119,7 @@ TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent) :
|
|||||||
connect(m_tabBar, SIGNAL(closeTab(int)), this, SLOT(closeTab(int)));
|
connect(m_tabBar, SIGNAL(closeTab(int)), this, SLOT(closeTab(int)));
|
||||||
connect(m_tabBar, SIGNAL(closeAllButCurrent(int)), this, SLOT(closeAllButCurrent(int)));
|
connect(m_tabBar, SIGNAL(closeAllButCurrent(int)), this, SLOT(closeAllButCurrent(int)));
|
||||||
connect(m_tabBar, SIGNAL(duplicateTab(int)), this, SLOT(duplicateTab(int)));
|
connect(m_tabBar, SIGNAL(duplicateTab(int)), this, SLOT(duplicateTab(int)));
|
||||||
|
connect(m_tabBar, SIGNAL(tabMoved(int,int)), this, SLOT(tabMoved(int,int)));
|
||||||
|
|
||||||
m_buttonListTabs = new TabListButton(this);
|
m_buttonListTabs = new TabListButton(this);
|
||||||
m_menuTabs = new QMenu();
|
m_menuTabs = new QMenu();
|
||||||
@ -205,6 +207,8 @@ void TabWidget::actionChangeIndex()
|
|||||||
|
|
||||||
int TabWidget::addView(QUrl url, const QString &title, OpenUrlIn openIn, bool selectLine)
|
int TabWidget::addView(QUrl url, const QString &title, OpenUrlIn openIn, bool selectLine)
|
||||||
{
|
{
|
||||||
|
m_lastTabIndex = currentIndex();
|
||||||
|
|
||||||
if (url.isEmpty())
|
if (url.isEmpty())
|
||||||
url = m_urlOnNewTab;
|
url = m_urlOnNewTab;
|
||||||
|
|
||||||
@ -236,6 +240,8 @@ int TabWidget::addView(QUrl url, const QString &title, OpenUrlIn openIn, bool se
|
|||||||
weView(index)->load(url);
|
weView(index)->load(url);
|
||||||
if (selectLine)
|
if (selectLine)
|
||||||
p_QupZilla->locationBar()->setFocus();
|
p_QupZilla->locationBar()->setFocus();
|
||||||
|
if (openIn == NewSelectedTab)
|
||||||
|
m_isClosingToLastTabIndex = true;
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
@ -257,7 +263,6 @@ void TabWidget::closeTab(int index)
|
|||||||
return;
|
return;
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
index = currentIndex();
|
index = currentIndex();
|
||||||
else m_lastTabIndex-=1;
|
|
||||||
|
|
||||||
if (weView(index)) {
|
if (weView(index)) {
|
||||||
disconnect(weView(index), SIGNAL(siteIconChanged()), p_QupZilla->locationBar(), SLOT(siteIconChanged()));
|
disconnect(weView(index), SIGNAL(siteIconChanged()), p_QupZilla->locationBar(), SLOT(siteIconChanged()));
|
||||||
@ -268,6 +273,9 @@ void TabWidget::closeTab(int index)
|
|||||||
//Save last tab url and history
|
//Save last tab url and history
|
||||||
m_closedTabsManager->saveView(weView(index));
|
m_closedTabsManager->saveView(weView(index));
|
||||||
|
|
||||||
|
if (m_isClosingToLastTabIndex && m_lastTabIndex < count())
|
||||||
|
setCurrentIndex(m_lastTabIndex);
|
||||||
|
|
||||||
delete weView(index);
|
delete weView(index);
|
||||||
removeTab(index);
|
removeTab(index);
|
||||||
|
|
||||||
@ -276,15 +284,25 @@ void TabWidget::closeTab(int index)
|
|||||||
if (count() == 1 && m_hideTabBarWithOneTab)
|
if (count() == 1 && m_hideTabBarWithOneTab)
|
||||||
tabBar()->setVisible(false);
|
tabBar()->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (count() < 1)
|
// if (count() < 1)
|
||||||
// p_QupZilla->close();
|
// p_QupZilla->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabWidget::tabMoved(int before, int after)
|
||||||
|
{
|
||||||
|
Q_UNUSED(before)
|
||||||
|
Q_UNUSED(after)
|
||||||
|
m_isClosingToLastTabIndex = false;
|
||||||
|
}
|
||||||
|
|
||||||
void TabWidget::tabChanged(int index)
|
void TabWidget::tabChanged(int index)
|
||||||
{
|
{
|
||||||
if (index<0)
|
if (index < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
m_isClosingToLastTabIndex = false;
|
||||||
|
|
||||||
QString title = p_QupZilla->weView()->title();
|
QString title = p_QupZilla->weView()->title();
|
||||||
if (title.isEmpty())
|
if (title.isEmpty())
|
||||||
title = tr("No Named Page");
|
title = tr("No Named Page");
|
||||||
@ -297,7 +315,6 @@ void TabWidget::tabChanged(int index)
|
|||||||
p_QupZilla->showInspector();
|
p_QupZilla->showInspector();
|
||||||
weView()->setFocus();
|
weView()->setFocus();
|
||||||
|
|
||||||
m_lastTabIndex = index;
|
|
||||||
m_tabBar->updateCloseButton(index);
|
m_tabBar->updateCloseButton(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@ private slots:
|
|||||||
void aboutToShowTabsMenu();
|
void aboutToShowTabsMenu();
|
||||||
void actionChangeIndex();
|
void actionChangeIndex();
|
||||||
void tabChanged(int index);
|
void tabChanged(int index);
|
||||||
|
void tabMoved(int before, int after);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline WebView* weView() { WebTab* webTab = qobject_cast<WebTab*>(widget(currentIndex())); if (!webTab) return 0; return webTab->view(); }
|
inline WebView* weView() { WebTab* webTab = qobject_cast<WebTab*>(widget(currentIndex())); if (!webTab) return 0; return webTab->view(); }
|
||||||
@ -84,6 +85,7 @@ private:
|
|||||||
QupZilla* p_QupZilla;
|
QupZilla* p_QupZilla;
|
||||||
|
|
||||||
int m_lastTabIndex;
|
int m_lastTabIndex;
|
||||||
|
bool m_isClosingToLastTabIndex;
|
||||||
|
|
||||||
TabBar* m_tabBar;
|
TabBar* m_tabBar;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user