┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/views
diff options
context:
space:
mode:
authorChristian Schwarz <[email protected]>2025-02-03 18:23:16 +0000
committerMéven Car <[email protected]>2025-02-03 18:23:16 +0000
commitf81d73a7f3a851dc755ef0cd1fd2a2507587a900 (patch)
tree58e66690a91048fd965e0885880b7c07a3185c91 /src/views
parent726753f81a96f15e1d88165cf93d55c7aac03707 (diff)
implement shortcut action for file creation
BUG: 462899
Diffstat (limited to 'src/views')
-rw-r--r--src/views/dolphinviewactionhandler.cpp10
-rw-r--r--src/views/dolphinviewactionhandler.h7
2 files changed, 16 insertions, 1 deletions
diff --git a/src/views/dolphinviewactionhandler.cpp b/src/views/dolphinviewactionhandler.cpp
index 88d5c015b..4d5dba070 100644
--- a/src/views/dolphinviewactionhandler.cpp
+++ b/src/views/dolphinviewactionhandler.cpp
@@ -84,6 +84,12 @@ void DolphinViewActionHandler::createActions(SelectionMode::ActionTextHelper *ac
newDirAction->setEnabled(false); // Will be enabled in slotWriteStateChanged(bool) if the current URL is writable
connect(newDirAction, &QAction::triggered, this, &DolphinViewActionHandler::createDirectoryTriggered);
+ QAction *newFileAction = m_actionCollection->addAction(QStringLiteral("create_file"));
+ newFileAction->setText(i18nc("@action", "Create File…"));
+ 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
auto renameAction = KStandardAction::renameFile(this, &DolphinViewActionHandler::slotRename, m_actionCollection);
@@ -639,7 +645,9 @@ void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown)
void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable)
{
- m_actionCollection->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable && KProtocolManager::supportsMakeDir(currentView()->url()));
+ const bool supportsMakeDir = KProtocolManager::supportsMakeDir(currentView()->url());
+ m_actionCollection->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable && supportsMakeDir);
+ m_actionCollection->action(QStringLiteral("create_file"))->setEnabled(isFolderWritable);
}
KToggleAction *DolphinViewActionHandler::iconsModeAction()
diff --git a/src/views/dolphinviewactionhandler.h b/src/views/dolphinviewactionhandler.h
index f36b3d1d0..20d62cf64 100644
--- a/src/views/dolphinviewactionhandler.h
+++ b/src/views/dolphinviewactionhandler.h
@@ -87,6 +87,13 @@ Q_SIGNALS:
*/
void createDirectoryTriggered();
+ /**
+ * Emitted if the user requested creating a new file.
+ * The receiver of the signal (DolphinMainWindow or DolphinPart) invokes
+ * the method createFile of their KNewFileMenu instance.
+ */
+ void createFileTriggered();
+
/** Used to request either entering or leaving of selection mode */
void selectionModeChangeTriggered(bool enabled, SelectionMode::BottomBar::Contents bottomBarContents = SelectionMode::BottomBar::Contents::GeneralContents);