| 46 | } |
| 47 | |
| 48 | CraftPlugin::CraftPlugin(QObject* parent, const KPluginMetaData& metaData, const QVariantList& /*args*/) |
| 49 | : IPlugin(QStringLiteral("kdevcraft"), parent, metaData) |
| 50 | { |
| 51 | const QString pythonExecutable = CraftRuntime::findPython(); |
| 52 | if (pythonExecutable.isEmpty()) |
| 53 | return; |
| 54 | |
| 55 | // If KDevelop itself runs under Craft env, this plugin has nothing to do |
| 56 | if (qEnvironmentVariableIsSet("KDEROOT")) |
| 57 | return; |
| 58 | |
| 59 | connect(ICore::self()->projectController(), &IProjectController::projectAboutToBeOpened, this, |
| 60 | [pythonExecutable](KDevelop::IProject* project) { |
| 61 | const QString craftRoot = CraftRuntime::findCraftRoot(project->path()); |
| 62 | auto* currentCraftRuntime = |
| 63 | qobject_cast<CraftRuntime*>(ICore::self()->runtimeController()->currentRuntime()); |
| 64 | |
| 65 | if (craftRoot.isEmpty()) { |
| 66 | if (currentCraftRuntime) |
| 67 | qCDebug(CRAFT) << "Loading a non-Craft project while Craft runtime is enabled. This will cause " |
| 68 | "the project to build and run under a Craft env!"; |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | qCDebug(CRAFT) << "Found Craft root at" << craftRoot; |
| 73 | if (currentCraftRuntime) { |
| 74 | qCDebug(CRAFT) << "A Craft runtime rooted at" << currentCraftRuntime->craftRoot() |
| 75 | << "is already active. Will not create another one"; |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | auto* runtime = new CraftRuntime(craftRoot, pythonExecutable); |
| 80 | ICore::self()->runtimeController()->addRuntimes(runtime); |
| 81 | if (wantAutoEnable(project, craftRoot)) |
| 82 | ICore::self()->runtimeController()->setCurrentRuntime(runtime); |
| 83 | }); |
| 84 | } |
| 85 | |
| 86 | #include "craftplugin.moc" |
| 87 | #include "moc_craftplugin.cpp" |
nothing calls this directly
no test coverage detected