Gets the PID of a running KDevelop instance, eventually asking the user if there is more than one. Returns -1 in case there are no running sessions.
| 257 | /// Gets the PID of a running KDevelop instance, eventually asking the user if there is more than one. |
| 258 | /// Returns -1 in case there are no running sessions. |
| 259 | static qint64 getRunningSessionPid() |
| 260 | { |
| 261 | SessionInfos candidates; |
| 262 | const auto availableSessionInfos = KDevelop::SessionController::availableSessionInfos(); |
| 263 | for (const KDevelop::SessionInfo& si : availableSessionInfos) { |
| 264 | if( KDevelop::SessionController::isSessionRunning(si.uuid.toString()) ) { |
| 265 | candidates << si; |
| 266 | } |
| 267 | } |
| 268 | if ( candidates.isEmpty() ) { |
| 269 | return -1; |
| 270 | } |
| 271 | |
| 272 | QString sessionUuid; |
| 273 | if ( candidates.size() == 1 ) { |
| 274 | sessionUuid = candidates.first().uuid.toString(); |
| 275 | } |
| 276 | else { |
| 277 | const QString title = i18n("Select the session to open the document in"); |
| 278 | sessionUuid = KDevelop::SessionController::showSessionChooserDialog(title, true); |
| 279 | } |
| 280 | return KDevelop::SessionController::sessionRunInfo(sessionUuid).holderPid; |
| 281 | } |
| 282 | |
| 283 | static QString findSessionId(const SessionInfos& availableSessionInfos, const QString& session) |
| 284 | { |