diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -43,6 +43,7 @@ class KFileItemList; class KJob; class KNewFileMenu; +class KToolBarPopupAction; class QToolButton; class QIcon; class PlacesPanel; @@ -444,6 +445,31 @@ */ void slotToolBarActionMiddleClicked(QAction *action); + /** + * Is called before the Back popup menu is shown. This slot will populate + * the menu with history data + */ + void slotAboutToShowBackPopupMenu(); + + /** + * This slot is used by the Back Popup Menu to go back to a specific + * history index. The QAction::data will carry an int with the index + * to go to. + */ + void slotGoBack(QAction* action); + + /** + * Is called before the Forward popup menu is shown. This slot will populate + * the menu with history data + */ + void slotAboutToShowForwardPopupMenu(); + + /** + * This slot is used by the Forward Popup Menu to go forward to a specific + * history index. The QAction::data will carry an int with the index + * to go to. + */ + void slotGoForward(QAction* action); private: void setupActions(); void setupDockWidgets(); @@ -521,6 +547,9 @@ TerminalPanel* m_terminalPanel; PlacesPanel* m_placesPanel; bool m_tearDownFromPlacesRequested; + + KToolBarPopupAction* m_backAction; + KToolBarPopupAction* m_forwardAction; }; inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include @@ -85,6 +86,8 @@ // Used for GeneralSettings::version() to determine whether // an updated version of Dolphin is running. const int CurrentDolphinVersion = 200; + // The maximum number of entries in the back/forward popup menu + const int MaxNumberOfNavigationentries = 10; } DolphinMainWindow::DolphinMainWindow() : @@ -100,7 +103,9 @@ m_lastHandleUrlStatJob(nullptr), m_terminalPanel(nullptr), m_placesPanel(nullptr), - m_tearDownFromPlacesRequested(false) + m_tearDownFromPlacesRequested(false), + m_backAction(nullptr), + m_forwardAction(nullptr) { Q_INIT_RESOURCE(dolphin); setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName()); @@ -596,6 +601,48 @@ } } +void DolphinMainWindow::slotAboutToShowBackPopupMenu() +{ + KUrlNavigator* urlNav = m_activeViewContainer->urlNavigator(); + int entries = 0; + m_backAction->menu()->clear(); + for (int i = urlNav->historyIndex() + 1; i < urlNav->historySize() && entries < MaxNumberOfNavigationentries; ++i, ++entries) { + QAction* action = new QAction(urlNav->locationUrl(i).toString(), m_backAction->menu()); + action->setData(i); + m_backAction->menu()->addAction(action); + } +} + +void DolphinMainWindow::slotGoBack(QAction* action) +{ + int gotoIndex = action->data().value(); + KUrlNavigator* urlNav = m_activeViewContainer->urlNavigator(); + for (int numBack = gotoIndex - urlNav->historyIndex(); numBack; --numBack) { + goBack(); + } +} + +void DolphinMainWindow::slotAboutToShowForwardPopupMenu() +{ + KUrlNavigator* urlNav = m_activeViewContainer->urlNavigator(); + int entries = 0; + m_forwardAction->menu()->clear(); + for (int i = urlNav->historyIndex() - 1; i >= 0 && entries < MaxNumberOfNavigationentries; --i, ++entries) { + QAction* action = new QAction(urlNav->locationUrl(i).toString(), m_forwardAction->menu()); + action->setData(i); + m_forwardAction->menu()->addAction(action); + } +} + +void DolphinMainWindow::slotGoForward(QAction* action) +{ + int gotoIndex = action->data().value(); + KUrlNavigator* urlNav = m_activeViewContainer->urlNavigator(); + for (int numForward = urlNav->historyIndex() - gotoIndex; numForward; --numForward) { + goForward(); + } +} + void DolphinMainWindow::selectAll() { clearStatusBar(); @@ -1173,10 +1220,18 @@ connect(replaceLocation, &QAction::triggered, this, &DolphinMainWindow::replaceLocation); // setup 'Go' menu - QAction* backAction = KStandardAction::back(this, &DolphinMainWindow::goBack, actionCollection()); - auto backShortcuts = backAction->shortcuts(); + // TODO - FIX RightToLeft + m_backAction = new KToolBarPopupAction(QIcon::fromTheme(QStringLiteral("go-previous")), i18nc("go back", "&Back"), + actionCollection()); + m_backAction->setObjectName("go_back"); + connect(m_backAction, &QAction::triggered, this, &DolphinMainWindow::goBack); + connect(m_backAction->menu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu); + connect(m_backAction->menu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoBack); + actionCollection()->addAction(m_backAction->objectName(), m_backAction); + + auto backShortcuts = m_backAction->shortcuts(); backShortcuts.append(QKeySequence(Qt::Key_Backspace)); - actionCollection()->setDefaultShortcuts(backAction, backShortcuts); + actionCollection()->setDefaultShortcuts(m_backAction, backShortcuts); DolphinRecentTabsMenu* recentTabsMenu = new DolphinRecentTabsMenu(this); actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu); @@ -1197,7 +1252,14 @@ auto undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo)); undoAction->setEnabled(false); // undo should be disabled by default - KStandardAction::forward(this, &DolphinMainWindow::goForward, actionCollection()); + // TODO - FIX RightToLeft + m_forwardAction = new KToolBarPopupAction(QIcon::fromTheme(QStringLiteral("go-next")), + i18nc("go forward", "&Forward"), actionCollection()); + m_forwardAction->setObjectName("go_forward"); + connect(m_forwardAction, &QAction::triggered, this, &DolphinMainWindow::goForward); + connect(m_forwardAction->menu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu); + connect(m_forwardAction->menu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoForward); + actionCollection()->addAction(m_forwardAction->objectName(), m_forwardAction); KStandardAction::up(this, &DolphinMainWindow::goUp, actionCollection()); KStandardAction::home(this, &DolphinMainWindow::goHome, actionCollection());