diff --git a/app/main.cpp b/app/main.cpp --- a/app/main.cpp +++ b/app/main.cpp @@ -192,6 +192,21 @@ return nullptr; } +/// Tries to find sessions containing project @p projectUrl in @p sessions. +static const KDevelop::SessionInfos findSessionsWithProject(const SessionInfos& sessions, const QUrl& projectUrl) +{ + if (!projectUrl.isValid()) + return {}; + + KDevelop::SessionInfos infos; + for (auto it = sessions.constBegin(); it != sessions.constEnd(); ++it) { + if (it->projects.contains(projectUrl)) { + infos << *it; + } + } + return infos; +} + /// Performs a DBus call to open the given @p files in the running kdev instance identified by @p pid /// Returns the exit status static int openFilesInRunningInstance(const QVector& files, qint64 pid) @@ -673,8 +688,23 @@ } } + QStringList projectNames = parser.values(QStringLiteral("project")); + foreach(const QString& projectName, projectNames) + { + QFileInfo info( projectName ); + const auto projectUrl = QUrl::fromLocalFile(info.absoluteFilePath()); + const auto sessionInfos = findSessionsWithProject(availableSessionInfos, projectUrl); + qDebug(APP) << "Found matching sessions:" << sessionInfos.size(); + if (!sessionInfos.isEmpty()) { + // TODO: If there's more than one match: Allow the user to select which session to open? + qDebug(APP) << "Attempting to open session:" << sessionInfos.at(0).name; + session = sessionInfos.at(0).uuid.toString(); + } + } + KDevIDEExtension::init(); + qDebug(APP) << "Attempting to initialize session:" << session; if(!Core::initialize(Core::Default, session)) return 5; @@ -686,25 +716,6 @@ core->pluginController()->loadPlugin(QStringLiteral("KDevWelcomePage")); } - QStringList projectNames = parser.values(QStringLiteral("project")); - foreach(const QString& projectName, projectNames) - { - QFileInfo info( projectName ); - if( info.suffix() == QLatin1String("kdev4") ) { - // make sure the project is not already opened by the session controller - bool shouldOpen = true; - Path path(info.absoluteFilePath()); - foreach(KDevelop::IProject* project, core->projectController()->projects()) { - if (project->projectFile() == path) { - shouldOpen = false; - break; - } - } - if (shouldOpen) { - core->projectController()->openProject( path.toUrl() ); - } - } - } const QString debugStr = QStringLiteral("debug"); if ( parser.isSet(debugStr) ) {