]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Bring back the "Create New" menu in the menu bar
authorJakob Petsovits <jpetso@petsovits.com>
Fri, 12 May 2023 22:13:39 +0000 (18:13 -0400)
committerJakob Petsovits <jpetso@petsovits.com>
Tue, 16 May 2023 15:11:51 +0000 (11:11 -0400)
This commit is the result of a three-way diff that
combines my own initial patch with related changes from
Felix Ernst's MR !545 and further suggestions by Méven Car.

Fixes DolphinMainWindowTest::testNewFileMenuEnabled().
Tests are now passing again for my build.

"Create New" was broken by commit c64059bd which switched to the
new, non-deprecated KNewFileMenu constructor (kio commit 89bc6bad)
that doesn't add itself to the passed KActionCollection parameter.
After the switch, hamburger menu and context menu was still working
as intended but the menu bar was missing the "Create New" menu.

This commit adds the addAction("new_menu") call to the File menu
setup that would have previously been called by the deprecated
KNewFileMenu constructor. The corresponding test can now find
the QObject for the menu's named action again, verifying its
existence and enabled-ness like it did before.

The DolphinNewFileMenu constructor's unused actionCollection
parameter serves no use anymore except to confuse people.
We replace it with a single QAction* parameter, createDirAction,
which gets passed to setNewFolderShortcutAction().

2 out of 3 constructor call sites have access to this action,
while the remaining call site in dolphinmainwindow.cpp must wait
until after it has been initialized by DolphinViewActionHandler.
In this case, setNewFolderShortcutAction() is still called manually
at a later time.

src/dolphincontextmenu.cpp
src/dolphinmainwindow.cpp
src/dolphinnewfilemenu.cpp
src/dolphinnewfilemenu.h
src/dolphinpart.cpp

index 3519d416a66cc64b32b0c0c08d788b3f6738bba0..62990cab2b77cea1f4151a0854c38b5b147a6b78 100644 (file)
@@ -168,8 +168,7 @@ void DolphinContextMenu::addDirectoryItemContextMenu()
     addOpenWithActions();
 
     // set up 'Create New' menu
-    DolphinNewFileMenu *newFileMenu = new DolphinNewFileMenu(m_mainWindow->actionCollection(), m_mainWindow);
-    newFileMenu->setNewFolderShortcutAction(m_mainWindow->actionCollection()->action("create_dir"));
+    DolphinNewFileMenu *newFileMenu = new DolphinNewFileMenu(m_mainWindow->actionCollection()->action(QStringLiteral("create_dir")), m_mainWindow);
     newFileMenu->checkUpToDate();
     newFileMenu->setWorkingDirectory(m_fileInfo.url());
     newFileMenu->setEnabled(selectedItemsProps.supportsWriting());
index 80dcff1c3a60d1057f46149f4baf0c33fba0fec6..ef8f9770f334019fb1cec123315b09b7d71b257e 100644 (file)
@@ -159,7 +159,8 @@ DolphinMainWindow::DolphinMainWindow()
     connect(m_actionHandler, &DolphinViewActionHandler::createDirectoryTriggered, this, &DolphinMainWindow::createDirectory);
     connect(m_actionHandler, &DolphinViewActionHandler::selectionModeChangeTriggered, this, &DolphinMainWindow::slotSetSelectionMode);
 
-    m_newFileMenu->setNewFolderShortcutAction(actionCollection()->action("create_dir"));
+    Q_CHECK_PTR(actionCollection()->action(QStringLiteral("create_dir")));
+    m_newFileMenu->setNewFolderShortcutAction(actionCollection()->action(QStringLiteral("create_dir")));
 
     m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
     connect(this, &DolphinMainWindow::urlChanged, m_remoteEncoding, &DolphinRemoteEncoding::slotAboutToOpenUrl);
@@ -1551,7 +1552,8 @@ void DolphinMainWindow::setupActions()
     auto hamburgerMenuAction = KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
 
     // setup 'File' menu
-    m_newFileMenu = new DolphinNewFileMenu(actionCollection(), this);
+    m_newFileMenu = new DolphinNewFileMenu(nullptr, this);
+    actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu);
     QMenu *menu = m_newFileMenu->menu();
     menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
     menu->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
index 55c11bc2f683e7a38695f24388880ee10648c9bb..d499ae42c14c1c59e10d68a123c91c7287b6acbe 100644 (file)
@@ -8,13 +8,14 @@
 
 #include "views/dolphinnewfilemenuobserver.h"
 
-#include <KActionCollection>
 #include <KIO/Job>
 
-DolphinNewFileMenu::DolphinNewFileMenu(KActionCollection *collection, QObject *parent)
+#include <QAction>
+
+DolphinNewFileMenu::DolphinNewFileMenu(QAction *createDirAction, QObject *parent)
     : KNewFileMenu(parent)
 {
-    Q_UNUSED(collection)
+    setNewFolderShortcutAction(createDirAction);
     DolphinNewFileMenuObserver::instance().attach(this);
 }
 
index 4fa173ef9dce8d6906f78c9ca67cb73e60fa887f..5538c92659ee8c9ff187e4ba3f4817818fd744cc 100644 (file)
@@ -25,7 +25,7 @@ class DOLPHIN_EXPORT DolphinNewFileMenu : public KNewFileMenu
     Q_OBJECT
 
 public:
-    DolphinNewFileMenu(KActionCollection *collection, QObject *parent);
+    DolphinNewFileMenu(QAction *createDirAction, QObject *parent);
     ~DolphinNewFileMenu() override;
 
 Q_SIGNALS:
index c3447ad6e45185c2c422a8bec7e1e938b85ed485..46b5e7e948dd607858e2118510585043171d56ff 100644 (file)
@@ -141,9 +141,8 @@ void DolphinPart::createActions()
 {
     // Edit menu
 
-    m_newFileMenu = new DolphinNewFileMenu(actionCollection(), this);
+    m_newFileMenu = new DolphinNewFileMenu(actionCollection()->action(QStringLiteral("create_dir")), this);
     m_newFileMenu->setParentWidget(widget());
-    m_newFileMenu->setNewFolderShortcutAction(actionCollection()->action("create_dir"));
     connect(m_newFileMenu->menu(), &QMenu::aboutToShow, this, &DolphinPart::updateNewMenu);
 
     QAction *editMimeTypeAction = actionCollection()->addAction(QStringLiteral("editMimeType"));