1
0
mirror of https://invent.kde.org/system/dolphin synced 2024-07-04 17:30:55 +00:00

Bring back the "Create New" menu in the menu bar

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.
This commit is contained in:
Jakob Petsovits 2023-05-12 18:13:39 -04:00
parent 1b0caf69a8
commit b5b6762b15
5 changed files with 11 additions and 10 deletions

View 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());

View 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")));

View 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);
}

View 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:

View 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"));