mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-22 01:40:02 +00:00
Use DolphinTabPage saveState/restoreState to remember and re-open closed tabs.
REVIEW: 118968
This commit is contained in:
parent
4b70446c17
commit
62418c58a5
|
@ -1058,10 +1058,10 @@ void DolphinMainWindow::setupActions()
|
|||
|
||||
DolphinRecentTabsMenu* recentTabsMenu = new DolphinRecentTabsMenu(this);
|
||||
actionCollection()->addAction("closed_tabs", recentTabsMenu);
|
||||
connect(m_tabWidget, SIGNAL(rememberClosedTab(KUrl,KUrl)),
|
||||
recentTabsMenu, SLOT(rememberClosedTab(KUrl,KUrl)));
|
||||
connect(recentTabsMenu, SIGNAL(restoreClosedTab(KUrl,KUrl)),
|
||||
this, SLOT(openNewActivatedTab(KUrl,KUrl)));
|
||||
connect(m_tabWidget, SIGNAL(rememberClosedTab(KUrl,QByteArray)),
|
||||
recentTabsMenu, SLOT(rememberClosedTab(KUrl,QByteArray)));
|
||||
connect(recentTabsMenu, SIGNAL(restoreClosedTab(QByteArray)),
|
||||
m_tabWidget, SLOT(restoreClosedTab(QByteArray)));
|
||||
connect(recentTabsMenu, SIGNAL(closedTabsCountChanged(uint)),
|
||||
this, SLOT(closedTabsCountChanged(uint)));
|
||||
|
||||
|
|
|
@ -40,19 +40,14 @@ DolphinRecentTabsMenu::DolphinRecentTabsMenu(QObject* parent) :
|
|||
this, SLOT(handleAction(QAction*)));
|
||||
}
|
||||
|
||||
void DolphinRecentTabsMenu::rememberClosedTab(const KUrl& primaryUrl, const KUrl& secondaryUrl)
|
||||
void DolphinRecentTabsMenu::rememberClosedTab(const KUrl& url, const QByteArray& state)
|
||||
{
|
||||
QAction* action = new QAction(menu());
|
||||
action->setText(primaryUrl.path());
|
||||
|
||||
const QString iconName = KMimeType::iconNameForUrl(primaryUrl);
|
||||
action->setText(url.path());
|
||||
action->setData(state);
|
||||
const QString iconName = KMimeType::iconNameForUrl(url);
|
||||
action->setIcon(KIcon(iconName));
|
||||
|
||||
KUrl::List urls;
|
||||
urls << primaryUrl;
|
||||
urls << secondaryUrl;
|
||||
action->setData(QVariant::fromValue(urls));
|
||||
|
||||
// Add the closed tab menu entry after the separator and
|
||||
// "Empty Recently Closed Tabs" entry
|
||||
if (menu()->actions().size() == 2) {
|
||||
|
@ -88,13 +83,11 @@ void DolphinRecentTabsMenu::handleAction(QAction* action)
|
|||
}
|
||||
emit closedTabsCountChanged(0);
|
||||
} else {
|
||||
const KUrl::List urls = action->data().value<KUrl::List>();
|
||||
const QByteArray state = action->data().value<QByteArray>();
|
||||
removeAction(action);
|
||||
delete action;
|
||||
action = 0;
|
||||
if (urls.count() == 2) {
|
||||
emit restoreClosedTab(urls.first(), urls.last());
|
||||
}
|
||||
emit restoreClosedTab(state);
|
||||
emit closedTabsCountChanged(menu()->actions().size() - 2);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,11 +34,11 @@ public:
|
|||
explicit DolphinRecentTabsMenu(QObject* parent);
|
||||
|
||||
public slots:
|
||||
void rememberClosedTab(const KUrl& primaryUrl, const KUrl& secondaryUrl);
|
||||
void rememberClosedTab(const KUrl& url, const QByteArray& state);
|
||||
void undoCloseTab();
|
||||
|
||||
signals:
|
||||
void restoreClosedTab(const KUrl& primaryUrl, const KUrl& secondaryUrl);
|
||||
void restoreClosedTab(const QByteArray& state);
|
||||
void closedTabsCountChanged(unsigned int count);
|
||||
|
||||
private slots:
|
||||
|
|
|
@ -213,12 +213,7 @@ void DolphinTabWidget::closeTab(const int index)
|
|||
}
|
||||
|
||||
DolphinTabPage* tabPage = tabPageAt(index);
|
||||
if (tabPage->splitViewEnabled()) {
|
||||
emit rememberClosedTab(tabPage->primaryViewContainer()->url(),
|
||||
tabPage->secondaryViewContainer()->url());
|
||||
} else {
|
||||
emit rememberClosedTab(tabPage->primaryViewContainer()->url(), KUrl());
|
||||
}
|
||||
emit rememberClosedTab(tabPage->activeViewContainer()->url(), tabPage->saveState());
|
||||
|
||||
removeTab(index);
|
||||
tabPage->deleteLater();
|
||||
|
@ -249,6 +244,12 @@ void DolphinTabWidget::slotPlacesPanelVisibilityChanged(bool visible)
|
|||
}
|
||||
}
|
||||
|
||||
void DolphinTabWidget::restoreClosedTab(const QByteArray& state)
|
||||
{
|
||||
openNewActivatedTab();
|
||||
currentTabPage()->restoreState(state);
|
||||
}
|
||||
|
||||
void DolphinTabWidget::detachTab(int index)
|
||||
{
|
||||
Q_ASSERT(index >= 0);
|
||||
|
|
|
@ -70,7 +70,7 @@ signals:
|
|||
/**
|
||||
* Is emitted when a tab has been closed.
|
||||
*/
|
||||
void rememberClosedTab(const KUrl& primaryUrl, const KUrl& secondaryUrl);
|
||||
void rememberClosedTab(const KUrl& url, const QByteArray& state);
|
||||
|
||||
public slots:
|
||||
/**
|
||||
|
@ -133,6 +133,12 @@ public slots:
|
|||
*/
|
||||
void slotPlacesPanelVisibilityChanged(bool visible);
|
||||
|
||||
/**
|
||||
* Is called when the user wants to reopen a previously closed tab from
|
||||
* the recent tabs menu.
|
||||
*/
|
||||
void restoreClosedTab(const QByteArray& state);
|
||||
|
||||
private slots:
|
||||
/**
|
||||
* Opens the tab with the index \a index in a new Dolphin instance and closes
|
||||
|
|
Loading…
Reference in a new issue