diff --git a/src/widgets/krun.h b/src/widgets/krun.h --- a/src/widgets/krun.h +++ b/src/widgets/krun.h @@ -179,6 +179,13 @@ */ void setShowScriptExecutionPrompt(bool showPrompt); + /** + * Sets cursor position for text files. + * If service supports it, this information gets passed to it. + * @since 5.54 + */ + void setCursorInformation(unsigned row, unsigned column); + /** * Suggested file name given by the server (e.g. HTTP content-disposition) */ @@ -230,7 +237,8 @@ */ static qint64 runService(const KService &service, const QList &urls, QWidget *window, bool tempFiles = false, const QString &suggestedFileName = QString(), - const QByteArray &asn = QByteArray()); // TODO KF6: deprecate/remove + const QByteArray &asn = QByteArray(), unsigned cursorRow = 0, + unsigned cursorColumn = 0); // TODO KF6: deprecate/remove enum RunFlag { DeleteTemporaryFiles = 0x1, ///< the URLs passed to the service will be deleted when it exits (if the URLs are local files) @@ -320,7 +328,8 @@ * @since 5.31 */ static bool runUrl(const QUrl &url, const QString &mimetype, QWidget *window, RunFlags flags, - const QString &suggestedFileName = QString(), const QByteArray &asn = QByteArray()); + const QString &suggestedFileName = QString(), const QByteArray &asn = QByteArray(), + unsigned cursorRow = 0, unsigned cursorColumn = 0); /** * Run the given shell command and notifies KDE of the starting diff --git a/src/widgets/krun.cpp b/src/widgets/krun.cpp --- a/src/widgets/krun.cpp +++ b/src/widgets/krun.cpp @@ -177,7 +177,7 @@ #endif // This is called by foundMimeType, since it knows the mimetype of the URL -bool KRun::runUrl(const QUrl &u, const QString &_mimetype, QWidget *window, RunFlags flags, const QString &suggestedFileName, const QByteArray &asn) +bool KRun::runUrl(const QUrl &u, const QString &_mimetype, QWidget *window, RunFlags flags, const QString &suggestedFileName, const QByteArray &asn, unsigned cursorRow, unsigned cursorColumn) { const bool runExecutables = flags.testFlag(KRun::RunExecutables); const bool tempFile = flags.testFlag(KRun::DeleteTemporaryFiles); @@ -243,7 +243,7 @@ #endif } - return KRun::runService(*offer, lst, window, tempFile, suggestedFileName, asn); + return KRun::runService(*offer, lst, window, tempFile, suggestedFileName, asn, cursorRow, cursorColumn); } bool KRun::displayOpenWithDialog(const QList &lst, QWidget *window, bool tempFiles, @@ -766,7 +766,8 @@ } qint64 KRun::runService(const KService &_service, const QList &_urls, QWidget *window, - bool tempFiles, const QString &suggestedFileName, const QByteArray &asn) + bool tempFiles, const QString &suggestedFileName, const QByteArray &asn, + unsigned cursorRow, unsigned cursorColumn) { if (!_service.entryPath().isEmpty() && !KDesktopFile::isAuthorizedDesktopFile(_service.entryPath()) && @@ -828,8 +829,15 @@ } } + QStringList args = QUrl::toStringList(urls); + // factor into KService::supportsPassingCursorInformation() ? + if(_service.name() == QStringLiteral("KWrite") || _service.name() == QStringLiteral("Kate")) { + args << QStringLiteral("--line") << QString::number(cursorRow == 0 ? 1 : cursorRow); // Kate counts lines/cols from 1 + args << QStringLiteral("--column") << QString::number(cursorColumn == 0 ? 1 : cursorColumn); + } + int i = KToolInvocation::startServiceByDesktopPath( - _service.entryPath(), QUrl::toStringList(urls), &error, nullptr, &pid, myasn + _service.entryPath(), args, &error, nullptr, &pid, myasn ); if (i != 0) { @@ -913,6 +921,8 @@ m_runExecutables = true; m_window = window; m_asn = asn; + m_cursorRow = 0; + m_cursorColumn = 0; q->setEnableExternalBrowser(true); // Start the timer. This means we will return to the event @@ -1353,7 +1363,7 @@ if (d->m_runExecutables) { runFlags |= KRun::RunExecutables; } - if (!KRun::runUrl(d->m_strURL, type, d->m_window, runFlags, d->m_suggestedFileName, d->m_asn)) { + if (!KRun::runUrl(d->m_strURL, type, d->m_window, runFlags, d->m_suggestedFileName, d->m_asn, d->m_cursorRow, d->m_cursorColumn)) { d->m_bFault = true; } setFinished(true); @@ -1456,6 +1466,12 @@ d->m_bCheckPrompt = showPrompt; } +void KRun::setCursorInformation(unsigned row, unsigned column) +{ + d->m_cursorRow = row; + d->m_cursorColumn = column; +} + QString KRun::suggestedFileName() const { return d->m_suggestedFileName; diff --git a/src/widgets/krun_p.h b/src/widgets/krun_p.h --- a/src/widgets/krun_p.h +++ b/src/widgets/krun_p.h @@ -115,6 +115,8 @@ bool m_bFinished; KIO::Job *m_job; QTimer *m_timer; + unsigned m_cursorRow; + unsigned m_cursorColumn; /** * Used to indicate that the next action is to scan the file.