diff --git a/src/main/kotlin/cn/xor7/xiaohei/leavesknife/activities/ProjectStartupActivity.kt b/src/main/kotlin/cn/xor7/xiaohei/leavesknife/activities/ProjectStartupActivity.kt index 9401590..c6e8bc0 100644 --- a/src/main/kotlin/cn/xor7/xiaohei/leavesknife/activities/ProjectStartupActivity.kt +++ b/src/main/kotlin/cn/xor7/xiaohei/leavesknife/activities/ProjectStartupActivity.kt @@ -1,5 +1,7 @@ package cn.xor7.xiaohei.leavesknife.activities +import cn.xor7.xiaohei.leavesknife.services.ProjectConfigService +import cn.xor7.xiaohei.leavesknife.services.leavesknifeConfigService import com.intellij.openapi.project.Project import com.intellij.openapi.startup.ProjectActivity import org.gradle.tooling.GradleConnector @@ -9,18 +11,14 @@ import java.io.File class ProjectStartupActivity : ProjectActivity { override suspend fun execute(project: Project) { - println("Project opened.") val projectDir = project.basePath ?: return GradleConnector.newConnector() .forProjectDirectory(File(projectDir)) .connect().use { connection -> val ideaProject: IdeaProject = connection.getModel(IdeaProject::class.java) - for (module in ideaProject.modules) { - println("Module: ${module.name}") - for (dependency in module.dependencies) { - println(" Dependency: ${dependency}") - } - } + project.leavesknifeConfigService.enablePlugin = + ideaProject.modules + .filter { it.name == "paper-api-generator" }.isNotEmpty() } } } \ No newline at end of file diff --git a/src/main/kotlin/cn/xor7/xiaohei/leavesknife/services/ProjectConfigService.kt b/src/main/kotlin/cn/xor7/xiaohei/leavesknife/services/ProjectConfigService.kt index 8c28c62..7d085f6 100644 --- a/src/main/kotlin/cn/xor7/xiaohei/leavesknife/services/ProjectConfigService.kt +++ b/src/main/kotlin/cn/xor7/xiaohei/leavesknife/services/ProjectConfigService.kt @@ -23,3 +23,6 @@ class ProjectConfigService(project: Project) { } } } + +val Project.leavesknifeConfigService: ProjectConfigService + get() = this.getService(ProjectConfigService::class.java) diff --git a/src/main/kotlin/cn/xor7/xiaohei/leavesknife/toolWindow/PatchesToolWindowFactory.kt b/src/main/kotlin/cn/xor7/xiaohei/leavesknife/toolWindow/PatchesToolWindowFactory.kt index 3523bae..221dadc 100644 --- a/src/main/kotlin/cn/xor7/xiaohei/leavesknife/toolWindow/PatchesToolWindowFactory.kt +++ b/src/main/kotlin/cn/xor7/xiaohei/leavesknife/toolWindow/PatchesToolWindowFactory.kt @@ -2,6 +2,7 @@ package cn.xor7.xiaohei.leavesknife.toolWindow import cn.xor7.xiaohei.leavesknife.MyBundle import cn.xor7.xiaohei.leavesknife.services.ProjectConfigService +import cn.xor7.xiaohei.leavesknife.services.leavesknifeConfigService import com.intellij.openapi.components.service import com.intellij.openapi.project.Project import com.intellij.openapi.wm.ToolWindow @@ -14,18 +15,20 @@ import javax.swing.JButton class PatchesToolWindowFactory : ToolWindowFactory { override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { val serverPatchesToolWindow = ServerPatchesToolWindow(toolWindow) - val content = ContentFactory.getInstance().createContent(serverPatchesToolWindow.getContent(), null, false) + val content = ContentFactory.getInstance().createContent( + serverPatchesToolWindow.getContent(), + null, + false + ) toolWindow.contentManager.addContent(content) } - override suspend fun isApplicableAsync(project: Project): Boolean { - return project.getService(ProjectConfigService::class.java).enablePlugin - } + override suspend fun isApplicableAsync(project: Project): Boolean = + project.leavesknifeConfigService.enablePlugin override fun shouldBeAvailable(project: Project) = false class ServerPatchesToolWindow(toolWindow: ToolWindow) { - private val service = toolWindow.project.service() fun getContent() = JBPanel>().apply {