]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinrecenttabsmenu.cpp
2 * SPDX-FileCopyrightText: 2014 Emmanuel Pescosta <emmanuelpescosta099@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #include "dolphinrecenttabsmenu.h"
8 #include "search/dolphinquery.h"
10 #include <KAcceleratorManager>
11 #include <KLocalizedString>
12 #include <kio/global.h>
17 DolphinRecentTabsMenu::DolphinRecentTabsMenu(QObject
*parent
)
18 : KActionMenu(QIcon::fromTheme(QStringLiteral("edit-undo")), i18n("Recently Closed Tabs"), parent
)
20 setPopupMode(QToolButton::InstantPopup
);
23 m_clearListAction
= new QAction(i18n("Empty Recently Closed Tabs"), this);
24 m_clearListAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-clear-history")));
25 addAction(m_clearListAction
);
29 connect(menu(), &QMenu::triggered
, this, &DolphinRecentTabsMenu::handleAction
);
32 void DolphinRecentTabsMenu::rememberClosedTab(const QUrl
&url
, const QByteArray
&state
)
34 QAction
*action
= new QAction(menu());
35 if (Search::isSupportedSearchScheme(url
.scheme())) {
36 action
->setText(Search::DolphinQuery
{url
, QUrl
{}}.title());
38 action
->setText(url
.path());
40 action
->setData(state
);
41 const QString iconName
= KIO::iconNameForUrl(url
);
42 action
->setIcon(QIcon::fromTheme(iconName
));
44 // Add the closed tab menu entry after the separator and
45 // "Empty Recently Closed Tabs" entry
46 if (menu()->actions().size() == 2) {
49 insertAction(menu()->actions().at(2), action
);
51 Q_EMIT
closedTabsCountChanged(menu()->actions().size() - 2);
52 // Assure that only up to 6 closed tabs are shown in the menu.
53 // 8 because of clear action + separator + 6 closed tabs
54 if (menu()->actions().size() > 8) {
55 removeAction(menu()->actions().last());
58 KAcceleratorManager::manage(menu());
61 void DolphinRecentTabsMenu::undoCloseTab()
63 Q_ASSERT(menu()->actions().size() > 2);
64 handleAction(menu()->actions().at(2));
67 void DolphinRecentTabsMenu::handleAction(QAction
*action
)
69 if (action
== m_clearListAction
) {
70 // Clear all actions except the "Empty Recently Closed Tabs"
71 // action and the separator
72 QList
<QAction
*> actions
= menu()->actions();
73 const int count
= actions
.size();
74 for (int i
= count
- 1; i
>= 2; i
--) {
75 removeAction(actions
.at(i
));
77 Q_EMIT
closedTabsCountChanged(0);
79 const QByteArray state
= action
->data().toByteArray();
83 Q_EMIT
restoreClosedTab(state
);
84 Q_EMIT
closedTabsCountChanged(menu()->actions().size() - 2);
87 if (menu()->actions().count() <= 2) {
92 #include "moc_dolphinrecenttabsmenu.cpp"