]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Disable "Create folder" action if the location is not writable
authorGleb Kasachou <gkosachov99@gmail.com>
Tue, 29 Jul 2025 08:45:35 +0000 (11:45 +0300)
committerMéven Car <meven@kde.org>
Wed, 30 Jul 2025 07:57:20 +0000 (07:57 +0000)
Instead of hiding the action when the user lacks permission to create
the folder, it is now shown in a disabled state. The tooltip is also
updated to reflect the disabled state.

src/dolphinviewcontainer.cpp
src/dolphinviewcontainer.h

index 726e0d12912268e5efd873100e1532ff1808ea0e..1b87911673a528f0fd30ac7e83dc4ba878b97e17 100644 (file)
@@ -991,12 +991,11 @@ void DolphinViewContainer::slotErrorMessageFromView(const QString &message, cons
         }
         showMessage(i18nc("@info", "Authorization required to enter this folder."), KMessageWidget::Error, {m_authorizeToEnterFolderAction});
         return;
         }
         showMessage(i18nc("@info", "Authorization required to enter this folder."), KMessageWidget::Error, {m_authorizeToEnterFolderAction});
         return;
-    } else if (kioErrorCode == KIO::ERR_DOES_NOT_EXIST && m_view->url().isLocalFile() && isFolderCreatable(m_view->url())) {
+    } else if (kioErrorCode == KIO::ERR_DOES_NOT_EXIST && m_view->url().isLocalFile()) {
         if (!m_createFolderAction) {
             m_createFolderAction = new QAction(this);
             m_createFolderAction->setText(i18nc("@action", "Create missing folder"));
             m_createFolderAction->setIcon(QIcon::fromTheme(QStringLiteral("folder-new")));
         if (!m_createFolderAction) {
             m_createFolderAction = new QAction(this);
             m_createFolderAction->setText(i18nc("@action", "Create missing folder"));
             m_createFolderAction->setIcon(QIcon::fromTheme(QStringLiteral("folder-new")));
-            m_createFolderAction->setToolTip(i18nc("@info:tooltip", "Create the folder at this path and open it"));
             connect(m_createFolderAction, &QAction::triggered, this, [this](bool) {
                 KIO::MkpathJob *job = KIO::mkpath(m_view->url());
                 KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Mkpath, {}, m_view->url(), job);
             connect(m_createFolderAction, &QAction::triggered, this, [this](bool) {
                 KIO::MkpathJob *job = KIO::mkpath(m_view->url());
                 KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Mkpath, {}, m_view->url(), job);
@@ -1010,6 +1009,13 @@ void DolphinViewContainer::slotErrorMessageFromView(const QString &message, cons
                 });
             });
         }
                 });
             });
         }
+        if (isTopMostParentFolderWritable(m_view->url())) {
+            m_createFolderAction->setEnabled(true);
+            m_createFolderAction->setToolTip(i18nc("@info:tooltip", "Create the folder at this path and open it"));
+        } else {
+            m_createFolderAction->setEnabled(false);
+            m_createFolderAction->setToolTip(i18nc("@info:tooltip", "You do not have permission to create the folder"));
+        }
         showMessage(message, KMessageWidget::Error, {m_createFolderAction});
         return;
     }
         showMessage(message, KMessageWidget::Error, {m_createFolderAction});
         return;
     }
index 4acccdd8112d1e15a14c16ef61365633d2fed198..d2d322b08d3512a457183f48e93eccebb8504e40 100644 (file)
@@ -464,7 +464,7 @@ private:
      * Check if a folder can be created at url.
      * This method supports only local URLs.
      */
      * Check if a folder can be created at url.
      * This method supports only local URLs.
      */
-    bool isFolderCreatable(QUrl url);
+    bool isTopMostParentFolderWritable(QUrl url);
 
 protected:
     bool eventFilter(QObject *object, QEvent *event) override;
 
 protected:
     bool eventFilter(QObject *object, QEvent *event) override;