]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Closed tabs are now remembered within Dolphin, so if you accidentally close them...
authorShaun Reich <shaun.reich@kdemail.net>
Sun, 1 Mar 2009 01:38:20 +0000 (01:38 +0000)
committerShaun Reich <shaun.reich@kdemail.net>
Sun, 1 Mar 2009 01:38:20 +0000 (01:38 +0000)
Closed tabs now become stored in the "Go"->"Recently Closed Tabs" menu.

To clear this list, there is an action within that menu.

Clicking on a remembered tab's action, will remove that entry, restore that tab, and focus it.

svn path=/trunk/KDE/kdebase/apps/; revision=933483

src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinui.rc

index 627c6a43a91b93a171600e1cbe7157407f75b2a5..78e48991557aeff3c9581abc421b59ac570f6f26 100644 (file)
@@ -490,6 +490,35 @@ void DolphinMainWindow::slotUndoAvailable(bool available)
     }
 }
 
+void DolphinMainWindow::restoreClosedTab(QAction* action)
+{
+    //The Clear Recently Closed Tabs List QAction, has it's data set to true, so we can detect it in here, as it's an exception.
+    if (action->data().toBool() == true) {
+        // Lets preserve the separator, and the clear action within this menu.
+        QList<QAction*> actionlist = m_recentTabsMenu->menu()->actions();
+        for (int i = 2; i < actionlist.size(); i++) {
+        m_recentTabsMenu->menu()->removeAction(actionlist.at(i));
+        }
+    } else {
+        const ClosedTab closedTab = action->data().value<ClosedTab>();
+
+        openNewTab(closedTab.primaryUrl);
+        m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
+
+        if (closedTab.isSplit) {
+            //Create secondary view.
+            toggleSplitView();
+            m_viewTab[m_tabIndex].secondaryView->setUrl(closedTab.secondaryUrl);
+        }
+
+        m_recentTabsMenu->removeAction(action);
+    }
+
+    if (m_recentTabsMenu->menu()->actions().count() == 2) {
+        m_recentTabsMenu->setEnabled(false);
+    }
+}
+
 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
 {
     QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
@@ -778,8 +807,8 @@ void DolphinMainWindow::closeTab(int index)
         // previous tab before closing the tab.
         m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1);
     }
-
-    // delete tab
+    rememberClosedTab(index);
+    //Delete this tab.
     m_viewTab[index].primaryView->deleteLater();
     if (m_viewTab[index].secondaryView != 0) {
         m_viewTab[index].secondaryView->deleteLater();
@@ -1078,6 +1107,19 @@ void DolphinMainWindow::setupActions()
     backShortcut.setAlternate(Qt::Key_Backspace);
     backAction->setShortcut(backShortcut);
 
+    m_recentTabsMenu = new KActionMenu(i18n("&Recently Closed Tabs"), this);
+    m_recentTabsMenu->setIcon(KIcon("edit-undo"));
+    actionCollection()->addAction("closed_tabs", m_recentTabsMenu);
+    connect(m_recentTabsMenu->menu(), SIGNAL(triggered(QAction *)),
+            this, SLOT(restoreClosedTab(QAction *)));
+
+    QAction* action = new QAction("&Empty Recently Closed Tabs", m_recentTabsMenu);
+    action->setIcon(KIcon("edit-clear-list"));
+    action->setData(QVariant::fromValue(true));
+    m_recentTabsMenu->addAction(action);
+    m_recentTabsMenu->addSeparator();
+    m_recentTabsMenu->setEnabled(false);
+
     KStandardAction::forward(this, SLOT(goForward()), actionCollection());
     KStandardAction::up(this, SLOT(goUp()), actionCollection());
     KStandardAction::home(this, SLOT(goHome()), actionCollection());
@@ -1291,6 +1333,37 @@ void DolphinMainWindow::updateGoActions()
     goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
 }
 
+void DolphinMainWindow::rememberClosedTab(int index)
+{
+    KMenu* tabsMenu = m_recentTabsMenu->menu();
+
+    const QString primaryPath = m_viewTab[index].primaryView->url().path();
+    const QString iconName = KMimeType::iconNameForUrl(primaryPath);
+
+    QAction* action = new QAction(primaryPath, tabsMenu);
+
+    ClosedTab closedTab;
+    closedTab.primaryUrl = m_viewTab[index].primaryView->url();
+
+    if (m_viewTab[index].secondaryView != 0) {
+        closedTab.secondaryUrl = m_viewTab[index].secondaryView->url();
+        closedTab.isSplit = true;
+    } else {
+        closedTab.isSplit = false;
+    }
+
+    action->setData(QVariant::fromValue(closedTab));
+    action->setIcon(KIcon(iconName));
+
+    //Add our action at the first element, but only do that if it isn't empty, else just append
+    if (tabsMenu->actions().isEmpty()) {
+        tabsMenu->addAction(action);
+    } else {
+        tabsMenu->insertAction(tabsMenu->actions().first() + 2, action);
+    }
+    actionCollection()->action("closed_tabs")->setEnabled(true);
+}
+
 void DolphinMainWindow::clearStatusBar()
 {
     m_activeViewContainer->statusBar()->clear();
index 2e49cc67ae5160d6cfaaf21e9cdec859a9822406..8fe9e350a2c55cf7b060e78e58e4b1fa0932a12e 100644 (file)
@@ -31,6 +31,7 @@
 #include <kio/fileundomanager.h>
 #include <ksortablelist.h>
 #include <kxmlguiwindow.h>
+#include <kactionmenu.h>
 
 #include <QtCore/QList>
 
@@ -62,6 +63,14 @@ class DolphinMainWindow: public KXmlGuiWindow
 
 public:
     virtual ~DolphinMainWindow();
+    //TODO: This struct should be private, but I couldn't figure out how to make it that way
+    //when using Q_DECLARE_METATYPE(), which is a needed macro.
+    struct ClosedTab
+    {
+        KUrl primaryUrl;
+        KUrl secondaryUrl;
+        bool isSplit;
+    };
 
     /**
      * Returns the currently active view.
@@ -179,6 +188,9 @@ private slots:
      */
     void slotUndoAvailable(bool available);
 
+    /** Invoked when an action in the recent tabs menu is clicked. */
+    void restoreClosedTab(QAction* action);
+
     /** Sets the text of the 'Undo' menu action to \a text. */
     void slotUndoTextChanged(const QString& text);
 
@@ -389,6 +401,11 @@ private:
     void updateViewActions();
     void updateGoActions();
 
+    /**
+     * Adds the tab[\a index] to the closed tab menu's list of actions.
+     */
+    void rememberClosedTab(int index);
+
     /**
      * Connects the signals from the created DolphinView with
      * the DolphinViewContainer \a container with the corresponding slots of
@@ -427,6 +444,7 @@ private:
     };
 
     KNewMenu* m_newMenu;
+    KActionMenu* m_recentTabsMenu;
     KAction* m_showMenuBar;
     KTabBar* m_tabBar;
     DolphinViewContainer* m_activeViewContainer;
@@ -450,6 +468,8 @@ private:
     QPointer<DolphinSettingsDialog> m_settingsDialog;
 };
 
+Q_DECLARE_METATYPE(DolphinMainWindow::ClosedTab)
+
 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
 {
     return m_activeViewContainer;
index 566393e6b7223356934ffc57397d24c9bad94144..b770d96f6072e1aca92251c08371fb53ac07242c 100644 (file)
@@ -1,5 +1,5 @@
 <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui name="dolphin" version="8">
+<kpartgui name="dolphin" version="9">
     <MenuBar>
         <Menu name="file">
             <Action name="create_new" />
@@ -70,6 +70,9 @@
             <Separator/>
             <Action name="view_properties" />
         </Menu>
+        <Menu name="go">
+            <Action name="closed_tabs" />
+        </Menu>
         <Menu name="tools">
             <Action name="find_file" />
             <Action name="show_filter_bar" />