mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-17 15:31:20 +00:00
ed2d352c42
* speeds up incremental builds as changes to a header will not always need the full mocs_compilation.cpp for all the target's headers rebuild, while having a moc file sourced into a source file only adds minor extra costs, due to small own code and the used headers usually already covered by the source file, being for the same class/struct * seems to not slow down clean builds, due to empty mocs_compilation.cpp resulting in those quickly processed, while the minor extra cost of the sourced moc files does not outweigh that in summary. Measured times actually improved by some percent points. (ideally CMake would just skip empty mocs_compilation.cpp & its object file one day) * enables compiler to see all methods of a class in same compilation unit to do some sanity checks * potentially more inlining in general, due to more in the compilation unit * allows to keep using more forward declarations in the header, as with the moc code being sourced into the cpp file there definitions can be ensured and often are already for the needs of the normal class methods
87 lines
2.6 KiB
C++
87 lines
2.6 KiB
C++
/*
|
|
* SPDX-FileCopyrightText: 2014 Emmanuel Pescosta <emmanuelpescosta099@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
#include "dolphinrecenttabsmenu.h"
|
|
|
|
#include <KAcceleratorManager>
|
|
#include <KLocalizedString>
|
|
#include <kio/global.h>
|
|
|
|
#include <QMenu>
|
|
|
|
DolphinRecentTabsMenu::DolphinRecentTabsMenu(QObject *parent)
|
|
: KActionMenu(QIcon::fromTheme(QStringLiteral("edit-undo")), i18n("Recently Closed Tabs"), parent)
|
|
{
|
|
setPopupMode(QToolButton::InstantPopup);
|
|
setEnabled(false);
|
|
|
|
m_clearListAction = new QAction(i18n("Empty Recently Closed Tabs"), this);
|
|
m_clearListAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-clear-history")));
|
|
addAction(m_clearListAction);
|
|
|
|
addSeparator();
|
|
|
|
connect(menu(), &QMenu::triggered, this, &DolphinRecentTabsMenu::handleAction);
|
|
}
|
|
|
|
void DolphinRecentTabsMenu::rememberClosedTab(const QUrl &url, const QByteArray &state)
|
|
{
|
|
QAction *action = new QAction(menu());
|
|
action->setText(url.path());
|
|
action->setData(state);
|
|
const QString iconName = KIO::iconNameForUrl(url);
|
|
action->setIcon(QIcon::fromTheme(iconName));
|
|
|
|
// Add the closed tab menu entry after the separator and
|
|
// "Empty Recently Closed Tabs" entry
|
|
if (menu()->actions().size() == 2) {
|
|
addAction(action);
|
|
} else {
|
|
insertAction(menu()->actions().at(2), action);
|
|
}
|
|
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) {
|
|
removeAction(menu()->actions().last());
|
|
}
|
|
setEnabled(true);
|
|
KAcceleratorManager::manage(menu());
|
|
}
|
|
|
|
void DolphinRecentTabsMenu::undoCloseTab()
|
|
{
|
|
Q_ASSERT(menu()->actions().size() > 2);
|
|
handleAction(menu()->actions().at(2));
|
|
}
|
|
|
|
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();
|
|
const int count = actions.size();
|
|
for (int i = count - 1; i >= 2; i--) {
|
|
removeAction(actions.at(i));
|
|
}
|
|
Q_EMIT closedTabsCountChanged(0);
|
|
} else {
|
|
const QByteArray state = action->data().toByteArray();
|
|
removeAction(action);
|
|
delete action;
|
|
action = nullptr;
|
|
Q_EMIT restoreClosedTab(state);
|
|
Q_EMIT closedTabsCountChanged(menu()->actions().size() - 2);
|
|
}
|
|
|
|
if (menu()->actions().count() <= 2) {
|
|
setEnabled(false);
|
|
}
|
|
}
|
|
|
|
#include "moc_dolphinrecenttabsmenu.cpp"
|