diff options
| author | Méven Car <[email protected]> | 2023-08-24 10:27:02 +0200 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2023-08-24 18:27:23 +0200 |
| commit | 46d2d147bf0bcbfc6c8a69e1c49e0590b679b7b4 (patch) | |
| tree | 766912fe4044f97f46d0c1812483d1499177eaba /src/dolphinviewcontainer.cpp | |
| parent | 9b4c37ea6aa3644661bfc2425d970d56e618b3f3 (diff) | |
Special case file opening with middle click for executable scripts
Since the first action would launch the script, we can use the first application associated to open the file.
Diffstat (limited to 'src/dolphinviewcontainer.cpp')
| -rw-r--r-- | src/dolphinviewcontainer.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index ffd0d9b5e..2811a1ee4 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -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()}); |
