]>
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-list")));
23 addAction(m_clearListAction
);
27 connect(menu(), &QMenu::triggered
,
28 this, &DolphinRecentTabsMenu::handleAction
);
31 void DolphinRecentTabsMenu::rememberClosedTab(const QUrl
& url
, const QByteArray
& state
)
33 QAction
* action
= new QAction(menu());
34 action
->setText(url
.path());
35 action
->setData(state
);
36 const QString iconName
= KIO::iconNameForUrl(url
);
37 action
->setIcon(QIcon::fromTheme(iconName
));
39 // Add the closed tab menu entry after the separator and
40 // "Empty Recently Closed Tabs" entry
41 if (menu()->actions().size() == 2) {
44 insertAction(menu()->actions().at(2), action
);
46 Q_EMIT
closedTabsCountChanged(menu()->actions().size() - 2);
47 // Assure that only up to 6 closed tabs are shown in the menu.
48 // 8 because of clear action + separator + 6 closed tabs
49 if (menu()->actions().size() > 8) {
50 removeAction(menu()->actions().last());
53 KAcceleratorManager::manage(menu());
56 void DolphinRecentTabsMenu::undoCloseTab()
58 Q_ASSERT(menu()->actions().size() > 2);
59 handleAction(menu()->actions().at(2));
62 void DolphinRecentTabsMenu::handleAction(QAction
* action
)
64 if (action
== m_clearListAction
) {
65 // Clear all actions except the "Empty Recently Closed Tabs"
66 // action and the separator
67 QList
<QAction
*> actions
= menu()->actions();
68 const int count
= actions
.size();
69 for (int i
= count
- 1; i
>= 2; i
--) {
70 removeAction(actions
.at(i
));
72 Q_EMIT
closedTabsCountChanged(0);
74 const QByteArray state
= action
->data().toByteArray();
78 Q_EMIT
restoreClosedTab(state
);
79 Q_EMIT
closedTabsCountChanged(menu()->actions().size() - 2);
82 if (menu()->actions().count() <= 2) {