diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -168,6 +168,8 @@ void createDirectory(); + void createFile(); + /** Shows the error message in the status bar of the active view. */ void showErrorMessage(const QString& message); diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -143,6 +143,7 @@ m_actionHandler = new DolphinViewActionHandler(actionCollection(), this); connect(m_actionHandler, &DolphinViewActionHandler::actionBeingHandled, this, &DolphinMainWindow::clearStatusBar); connect(m_actionHandler, &DolphinViewActionHandler::createDirectoryTriggered, this, &DolphinMainWindow::createDirectory); + connect(m_actionHandler, &DolphinViewActionHandler::createFileTriggered, this, &DolphinMainWindow::createFile); m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler); connect(this, &DolphinMainWindow::urlChanged, @@ -464,6 +465,13 @@ m_newFileMenu->createDirectory(); } +void DolphinMainWindow::createFile() +{ + m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown()); + m_newFileMenu->setPopupFiles(activeViewContainer()->url()); + m_newFileMenu->createFile(); +} + void DolphinMainWindow::quit() { close(); diff --git a/src/dolphinpart.h b/src/dolphinpart.h --- a/src/dolphinpart.h +++ b/src/dolphinpart.h @@ -217,6 +217,8 @@ void createDirectory(); + void createFile(); + /** * Called by konqueror --select */ diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -116,6 +116,7 @@ m_actionHandler = new DolphinViewActionHandler(actionCollection(), this); m_actionHandler->setCurrentView(m_view); connect(m_actionHandler, &DolphinViewActionHandler::createDirectoryTriggered, this, &DolphinPart::createDirectory); + connect(m_actionHandler, &DolphinViewActionHandler::createFileTriggered, this, &DolphinPart::createFile); m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler); connect(this, &DolphinPart::aboutToOpenURL, @@ -583,6 +584,13 @@ m_newFileMenu->createDirectory(); } +void DolphinPart::createFile() +{ + m_newFileMenu->setViewShowsHiddenFiles(m_view->hiddenFilesShown()); + m_newFileMenu->setPopupFiles(url()); + m_newFileMenu->createFile(); +} + void DolphinPart::setFilesToSelect(const QList& files) { if (files.isEmpty()) { diff --git a/src/views/dolphinviewactionhandler.h b/src/views/dolphinviewactionhandler.h --- a/src/views/dolphinviewactionhandler.h +++ b/src/views/dolphinviewactionhandler.h @@ -95,6 +95,13 @@ */ void createDirectoryTriggered(); + /** + * Emitted if the user requested creating a new file by the Shift-F10 keys. + * The receiver of the signal (DolphinMainWindow or DolphinPart) invokes + * the method createFile of their KNewFileMenu instance. + */ + void createFileTriggered(); + private Q_SLOTS: /** * Emitted when the user requested a change of view mode diff --git a/src/views/dolphinviewactionhandler.cpp b/src/views/dolphinviewactionhandler.cpp --- a/src/views/dolphinviewactionhandler.cpp +++ b/src/views/dolphinviewactionhandler.cpp @@ -97,6 +97,15 @@ newDirAction->setEnabled(false); // Will be enabled in slotWriteStateChanged(bool) if the current URL is writable connect(newDirAction, &QAction::triggered, this, &DolphinViewActionHandler::createDirectoryTriggered); + // This action doesn't appear in the GUI, it's for the shortcut only. + // KNewFileMenu takes care of the GUI stuff. + QAction* newFileAction = m_actionCollection->addAction(QStringLiteral("create_file")); + newFileAction->setText(i18nc("@action", "Create File...")); + m_actionCollection->setDefaultShortcut(newFileAction, Qt::SHIFT + Qt::Key_F10); + newFileAction->setIcon(QIcon::fromTheme(QStringLiteral("document-new"))); + newFileAction->setEnabled(false); // Will be enabled in slotWriteStateChanged(bool) if the current URL is writable + connect(newFileAction, &QAction::triggered, this, &DolphinViewActionHandler::createFileTriggered); + // File menu KStandardAction::renameFile(this, &DolphinViewActionHandler::slotRename, m_actionCollection); @@ -484,6 +493,8 @@ { m_actionCollection->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable && KProtocolManager::supportsMakeDir(currentView()->url())); + m_actionCollection->action(QStringLiteral("create_file"))->setEnabled(isFolderWritable && + KProtocolManager::supportsWriting(currentView()->url())); } KToggleAction* DolphinViewActionHandler::iconsModeAction()