]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Special case file opening with middle click for executable scripts
authorMéven Car <meven@kde.org>
Thu, 24 Aug 2023 08:27:02 +0000 (10:27 +0200)
committerMéven Car <meven@kde.org>
Thu, 24 Aug 2023 16:27:23 +0000 (18:27 +0200)
Since the first action would launch the script, we can use the first application associated to open the file.

src/dolphinviewcontainer.cpp

index ffd0d9b5eb0afba4ce7d4474714b757a7b2acb70..2811a1ee429d942878ba6c1cfb006d393a2690dd 100644 (file)
@@ -745,8 +745,23 @@ void DolphinViewContainer::slotfileMiddleClickActivated(const KFileItem &item)
 {
     KService::List services = KApplicationTrader::queryByMimeType(item.mimetype());
 
-    if (services.length() >= 2) {
-        auto service = services.at(1);
+    int indexOfAppToOpenFileWith = 1;
+
+    // executable scripts
+    auto mimeType = item.currentMimeType();
+    if (item.isLocalFile() && mimeType.inherits(QStringLiteral("application/x-executable")) && mimeType.inherits(QStringLiteral("text/plain"))
+        && QFileInfo(item.localPath()).isExecutable()) {
+        KConfigGroup cfgGroup(KSharedConfig::openConfig(QStringLiteral("kiorc")), "Executable scripts");
+        const QString value = cfgGroup.readEntry("behaviourOnLaunch", "alwaysAsk");
+
+        // in case KIO::WidgetsOpenOrExecuteFileHandler::promptUserOpenOrExecute would not open the file
+        if (value != QLatin1String("open")) {
+            indexOfAppToOpenFileWith = 0;
+        }
+    }
+
+    if (services.length() >= indexOfAppToOpenFileWith + 1) {
+        auto service = services.at(indexOfAppToOpenFileWith);
 
         KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(service, this);
         job->setUrls({item.url()});