KToggleAction* editableLocation = actionCollection()->add<KToggleAction>("editable_location");
editableLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
editableLocation->setShortcut(Qt::Key_F6);
- connect(editableLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
+ connect(editableLocation, &KToggleAction::triggered, this, &DolphinMainWindow::toggleEditLocation);
- KAction* replaceLocation = actionCollection()->addAction("replace_location");
+ QAction* replaceLocation = actionCollection()->addAction("replace_location");
replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
replaceLocation->setShortcut(Qt::CTRL | Qt::Key_L);
- connect(replaceLocation, SIGNAL(triggered()), this, SLOT(replaceLocation()));
+ connect(replaceLocation, &QAction::triggered, this, &DolphinMainWindow::replaceLocation);
// setup 'Go' menu
- KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
- connect(backAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goBack(Qt::MouseButtons)));
- KShortcut backShortcut = backAction->shortcut();
- backShortcut.setAlternate(Qt::Key_Backspace);
- backAction->setShortcut(backShortcut);
+ QAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
+ auto backShortcuts = backAction->shortcuts();
+ backShortcuts.append(QKeySequence(Qt::Key_Backspace));
+ backAction->setShortcuts(backShortcuts);
- m_recentTabsMenu = new KActionMenu(i18n("Recently Closed Tabs"), this);
- m_recentTabsMenu->setIcon(QIcon::fromTheme("edit-undo"));
- m_recentTabsMenu->setDelayed(false);
- actionCollection()->addAction("closed_tabs", m_recentTabsMenu);
- connect(m_recentTabsMenu->menu(), &QMenu::triggered,
- this, &DolphinMainWindow::restoreClosedTab);
-
- QAction* action = new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu);
- action->setIcon(QIcon::fromTheme("edit-clear-list"));
- action->setData(QVariant::fromValue(true));
- m_recentTabsMenu->addAction(action);
- m_recentTabsMenu->addSeparator();
- m_recentTabsMenu->setEnabled(false);
+ DolphinRecentTabsMenu* recentTabsMenu = new DolphinRecentTabsMenu(this);
+ actionCollection()->addAction("closed_tabs", recentTabsMenu);
+ connect(this, SIGNAL(rememberClosedTab(KUrl,KUrl)),
+ recentTabsMenu, SLOT(rememberClosedTab(KUrl,KUrl)));
+ connect(recentTabsMenu, SIGNAL(restoreClosedTab(KUrl,KUrl)),
+ this, SLOT(restoreClosedTab(KUrl,KUrl)));
- KAction* forwardAction = KStandardAction::forward(this, SLOT(goForward()), actionCollection());
- connect(forwardAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goForward(Qt::MouseButtons)));
-
- KAction* upAction = KStandardAction::up(this, SLOT(goUp()), actionCollection());
- connect(upAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goUp(Qt::MouseButtons)));
-
- KAction* homeAction = KStandardAction::home(this, SLOT(goHome()), actionCollection());
- connect(homeAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goHome(Qt::MouseButtons)));
+ KStandardAction::forward(this, SLOT(goForward()), actionCollection());
+ KStandardAction::up(this, SLOT(goUp()), actionCollection());
+ KStandardAction::home(this, SLOT(goHome()), actionCollection());
// setup 'Tools' menu
- KAction* showFilterBar = actionCollection()->addAction("show_filter_bar");
+ QAction* showFilterBar = actionCollection()->addAction("show_filter_bar");
showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
- showFilterBar->setIcon(KIcon("view-filter"));
+ showFilterBar->setIcon(QIcon::fromTheme("view-filter"));
showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
- connect(showFilterBar, SIGNAL(triggered()), this, SLOT(showFilterBar()));
+ connect(showFilterBar, &QAction::triggered, this, &DolphinMainWindow::showFilterBar);
- KAction* compareFiles = actionCollection()->addAction("compare_files");
+ QAction* compareFiles = actionCollection()->addAction("compare_files");
compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
- compareFiles->setIcon(KIcon("kompare"));
+ compareFiles->setIcon(QIcon::fromTheme("kompare"));
compareFiles->setEnabled(false);
- connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
+ connect(compareFiles, &QAction::triggered, this, &DolphinMainWindow::compareFiles);
- KAction* openTerminal = actionCollection()->addAction("open_terminal");
+ QAction* openTerminal = actionCollection()->addAction("open_terminal");
openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
- openTerminal->setIcon(KIcon("utilities-terminal"));
+ openTerminal->setIcon(QIcon::fromTheme("utilities-terminal"));
openTerminal->setShortcut(Qt::SHIFT | Qt::Key_F4);
- connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal()));
+ connect(openTerminal, &QAction::triggered, this, &DolphinMainWindow::openTerminal);
// setup 'Settings' menu
KToggleAction* showMenuBar = KStandardAction::showMenubar(0, 0, actionCollection());
--- /dev/null
- KActionMenu(KIcon("edit-undo"), i18n("Recently Closed Tabs"), parent)
+ /***************************************************************************
+ * Copyright (C) 2014 by Emmanuel Pescosta <emmanuelpescosta099@gmail.com> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+ #include "dolphinrecenttabsmenu.h"
+
+ #include <KLocalizedString>
+ #include <KAcceleratorManager>
+ #include <KMimeType>
+ #include <KMenu>
+
+ DolphinRecentTabsMenu::DolphinRecentTabsMenu(QObject* parent) :
- m_clearListAction->setIcon(KIcon("edit-clear-list"));
++ KActionMenu(QIcon::fromTheme("edit-undo"), i18n("Recently Closed Tabs"), parent)
+ {
+ setDelayed(false);
+ setEnabled(false);
+
+ m_clearListAction = new QAction(i18n("Empty Recently Closed Tabs"), this);
- action->setIcon(KIcon(iconName));
++ m_clearListAction->setIcon(QIcon::fromTheme("edit-clear-list"));
+ addAction(m_clearListAction);
+
+ addSeparator();
+
+ connect(menu(), SIGNAL(triggered(QAction*)),
+ this, SLOT(handleAction(QAction*)));
+ }
+
+ void DolphinRecentTabsMenu::rememberClosedTab(const KUrl& primaryUrl, const KUrl& secondaryUrl)
+ {
+ QAction* action = new QAction(menu());
+ action->setText(primaryUrl.path());
+
+ const QString iconName = KMimeType::iconNameForUrl(primaryUrl);
++ action->setIcon(QIcon::fromTheme(iconName));
+
+ KUrl::List urls;
+ urls << primaryUrl;
+ urls << secondaryUrl;
+ action->setData(QVariant::fromValue(urls));
+
+ // 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);
+ }
+
+ // 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::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 = 2; i < count; ++i) {
+ removeAction(actions.at(i));
+ }
+ } else {
+ const KUrl::List urls = action->data().value<KUrl::List>();
+ if (urls.count() == 2) {
+ emit restoreClosedTab(urls.first(), urls.last());
+ }
+ removeAction(action);
+ delete action;
+ action = 0;
+ }
+
+ if (menu()->actions().count() <= 2) {
+ setEnabled(false);
+ }
+ }