]>
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"
9 #include <KAcceleratorManager>
10 #include <KLocalizedString>
11 #include <kio/global.h>
15 DolphinRecentTabsMenu::DolphinRecentTabsMenu(QObject
*parent
)
16 : KActionMenu(QIcon::fromTheme(QStringLiteral("edit-undo")), i18n("Recently Closed Tabs"), parent
)
18 setPopupMode(QToolButton::InstantPopup
);
21 m_clearListAction
= new QAction(i18n("Empty Recently Closed Tabs"), this);
22 m_clearListAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-clear-history")));
23 addAction(m_clearListAction
);
27 connect(menu(), &QMenu::triggered
, this, &DolphinRecentTabsMenu::handleAction
);
30 void DolphinRecentTabsMenu::rememberClosedTab(const QUrl
&url
, const QByteArray
&state
)
32 QAction
*action
= new QAction(menu());
33 action
->setText(url
.path());
34 action
->setData(state
);
35 const QString iconName
= KIO::iconNameForUrl(url
);
36 action
->setIcon(QIcon::fromTheme(iconName
));
38 // Add the closed tab menu entry after the separator and
39 // "Empty Recently Closed Tabs" entry
40 if (menu()->actions().size() == 2) {
43 insertAction(menu()->actions().at(2), action
);
45 Q_EMIT
closedTabsCountChanged(menu()->actions().size() - 2);
46 // Assure that only up to 6 closed tabs are shown in the menu.
47 // 8 because of clear action + separator + 6 closed tabs
48 if (menu()->actions().size() > 8) {
49 removeAction(menu()->actions().last());
52 KAcceleratorManager::manage(menu());
55 void DolphinRecentTabsMenu::undoCloseTab()
57 Q_ASSERT(menu()->actions().size() > 2);
58 handleAction(menu()->actions().at(2));
61 void DolphinRecentTabsMenu::handleAction(QAction
*action
)
63 if (action
== m_clearListAction
) {
64 // Clear all actions except the "Empty Recently Closed Tabs"
65 // action and the separator
66 QList
<QAction
*> actions
= menu()->actions();
67 const int count
= actions
.size();
68 for (int i
= count
- 1; i
>= 2; i
--) {
69 removeAction(actions
.at(i
));
71 Q_EMIT
closedTabsCountChanged(0);
73 const QByteArray state
= action
->data().toByteArray();
77 Q_EMIT
restoreClosedTab(state
);
78 Q_EMIT
closedTabsCountChanged(menu()->actions().size() - 2);
81 if (menu()->actions().count() <= 2) {
86 #include "moc_dolphinrecenttabsmenu.cpp"