1
0
mirror of https://invent.kde.org/system/dolphin synced 2024-07-07 10:51:45 +00:00

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.
This commit is contained in:
Méven Car 2023-08-24 10:27:02 +02:00
parent 9b4c37ea6a
commit 46d2d147bf

View 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()});