]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Use DolphinTabPage saveState/restoreState to remember and re-open closed tabs.
authorEmmanuel Pescosta <emmanuelpescosta099@gmail.com>
Sun, 10 Aug 2014 18:36:44 +0000 (20:36 +0200)
committerEmmanuel Pescosta <emmanuelpescosta099@gmail.com>
Wed, 13 Aug 2014 18:50:36 +0000 (20:50 +0200)
REVIEW: 118968

src/dolphinmainwindow.cpp
src/dolphinrecenttabsmenu.cpp
src/dolphinrecenttabsmenu.h
src/dolphintabwidget.cpp
src/dolphintabwidget.h

index 0882bac71745ba6d9fdb7bcb525b8b1cc037a828..588bfda64fdcc1edcc912b9559cffbe5444b03ea 100644 (file)
@@ -1058,10 +1058,10 @@ void DolphinMainWindow::setupActions()
 
     DolphinRecentTabsMenu* recentTabsMenu = new DolphinRecentTabsMenu(this);
     actionCollection()->addAction("closed_tabs", recentTabsMenu);
 
     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)));
 
     connect(recentTabsMenu, SIGNAL(closedTabsCountChanged(uint)),
             this, SLOT(closedTabsCountChanged(uint)));
 
index 2335f1bf48ef8df63b2fe404fe0bc1a46e6600ec..fa3eaf166d4db726b21c3c786e44d4825b7c04c1 100644 (file)
@@ -40,19 +40,14 @@ DolphinRecentTabsMenu::DolphinRecentTabsMenu(QObject* parent) :
             this, SLOT(handleAction(QAction*)));
 }
 
             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());
 {
     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));
 
     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) {
     // 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 {
         }
         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;
         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);
     }
 
         emit closedTabsCountChanged(menu()->actions().size() - 2);
     }
 
index b5acc735e57ef9d96bc1d652e2510cb58fd74ee0..910e564a19bb7f2850feec88cffaef89583fa99c 100644 (file)
@@ -34,11 +34,11 @@ public:
     explicit DolphinRecentTabsMenu(QObject* parent);
 
 public slots:
     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 undoCloseTab();
 
 signals:
-    void restoreClosedTab(const KUrl& primaryUrl, const KUrl& secondaryUrl);
+    void restoreClosedTab(const QByteArray& state);
     void closedTabsCountChanged(unsigned int count);
 
 private slots:
     void closedTabsCountChanged(unsigned int count);
 
 private slots:
index 4bb70b4eab62a75151b1f07a9b509113583cd9f6..ea71b48566c4feb1d1589d2f5c50480aeb66360d 100644 (file)
@@ -213,12 +213,7 @@ void DolphinTabWidget::closeTab(const int index)
     }
 
     DolphinTabPage* tabPage = tabPageAt(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();
 
     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);
 void DolphinTabWidget::detachTab(int index)
 {
     Q_ASSERT(index >= 0);
index a9bef11be155374dc98f6899b11e0e1a7c3adb1f..aaadbc997b583e0703826b3e07850b5d841bb8ee 100644 (file)
@@ -70,7 +70,7 @@ signals:
     /**
      * Is emitted when a tab has been closed.
      */
     /**
      * 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:
     /**
 
 public slots:
     /**
@@ -133,6 +133,12 @@ public slots:
      */
     void slotPlacesPanelVisibilityChanged(bool visible);
 
      */
     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
 private slots:
     /**
      * Opens the tab with the index \a index in a new Dolphin instance and closes