]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinrecenttabsmenu.cpp
dolphinui: Set view_mode action to low priority
[dolphin.git] / src / dolphinrecenttabsmenu.cpp
index 0a274fed86fdb17e109a13d05dbe45e0080912cb..74aaf232ed3f0ab21de8dde34f24c10245712f0c 100644 (file)
@@ -5,33 +5,42 @@
  */
 
 #include "dolphinrecenttabsmenu.h"
+#include "search/dolphinquery.h"
 
 #include <KAcceleratorManager>
 #include <KLocalizedString>
 #include <kio/global.h>
 
 #include <QMenu>
+#include <QUrlQuery>
 
-DolphinRecentTabsMenu::DolphinRecentTabsMenu(QObject* parent) :
-    KActionMenu(QIcon::fromTheme(QStringLiteral("edit-undo")), i18n("Recently Closed Tabs"), parent)
+DolphinRecentTabsMenu::DolphinRecentTabsMenu(QObject *parent)
+    KActionMenu(QIcon::fromTheme(QStringLiteral("edit-undo")), i18n("Recently Closed Tabs"), parent)
 {
-    setDelayed(false);
+    setPopupMode(QToolButton::InstantPopup);
     setEnabled(false);
 
     m_clearListAction = new QAction(i18n("Empty Recently Closed Tabs"), this);
-    m_clearListAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-clear-list")));
+    m_clearListAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-clear-history")));
     addAction(m_clearListAction);
 
     addSeparator();
 
-    connect(menu(), &QMenu::triggered,
-            this, &DolphinRecentTabsMenu::handleAction);
+    connect(menu(), &QMenu::triggered, this, &DolphinRecentTabsMenu::handleAction);
 }
 
-void DolphinRecentTabsMenu::rememberClosedTab(const QUrl& url, const QByteArray& state)
+void DolphinRecentTabsMenu::rememberClosedTab(const QUrl &url, const QByteArray &state)
 {
-    QAction* action = new QAction(menu());
-    action->setText(url.path());
+    QAction *action = new QAction(menu());
+    if (DolphinQuery::supportsScheme(url.scheme())) {
+        const DolphinQuery query = DolphinQuery::fromSearchUrl(url);
+        action->setText(i18n("Search for %1 in %2", query.text(), query.includeFolder()));
+    } else if (url.scheme() == QLatin1String("filenamesearch")) {
+        const QUrlQuery query(url);
+        action->setText(i18n("Search for %1 in %2", query.queryItemValue(QStringLiteral("search")), query.queryItemValue(QStringLiteral("url"))));
+    } else {
+        action->setText(url.path());
+    }
     action->setData(state);
     const QString iconName = KIO::iconNameForUrl(url);
     action->setIcon(QIcon::fromTheme(iconName));
@@ -43,7 +52,7 @@ void DolphinRecentTabsMenu::rememberClosedTab(const QUrl& url, const QByteArray&
     } else {
         insertAction(menu()->actions().at(2), action);
     }
-    emit closedTabsCountChanged(menu()->actions().size() - 2);
+    Q_EMIT closedTabsCountChanged(menu()->actions().size() - 2);
     // Assure that only up to 6 closed tabs are shown in the menu.
     // 8 because of clear action + separator + 6 closed tabs
     if (menu()->actions().size() > 8) {
@@ -59,27 +68,29 @@ void DolphinRecentTabsMenu::undoCloseTab()
     handleAction(menu()->actions().at(2));
 }
 
-void DolphinRecentTabsMenu::handleAction(QActionaction)
+void DolphinRecentTabsMenu::handleAction(QAction *action)
 {
     if (action == m_clearListAction) {
         // Clear all actions except the "Empty Recently Closed Tabs"
         // action and the separator
-        QList<QAction*> actions = menu()->actions();
+        QList<QAction *> actions = menu()->actions();
         const int count = actions.size();
-        for (int i = 2; i < count; ++i) {
+        for (int i = count - 1; i >= 2; i--) {
             removeAction(actions.at(i));
         }
-        emit closedTabsCountChanged(0);
+        Q_EMIT closedTabsCountChanged(0);
     } else {
         const QByteArray state = action->data().toByteArray();
         removeAction(action);
         delete action;
         action = nullptr;
-        emit restoreClosedTab(state);
-        emit closedTabsCountChanged(menu()->actions().size() - 2);
+        Q_EMIT restoreClosedTab(state);
+        Q_EMIT closedTabsCountChanged(menu()->actions().size() - 2);
     }
 
     if (menu()->actions().count() <= 2) {
         setEnabled(false);
     }
 }
+
+#include "moc_dolphinrecenttabsmenu.cpp"