Skip to content

Commit

Permalink
feat: fetch module path
Browse files Browse the repository at this point in the history
  • Loading branch information
MC-XiaoHei committed Jun 6, 2024
1 parent 7a3c77d commit 512b247
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cn.xor7.xiaohei.leavesknife.activities

import cn.xor7.xiaohei.leavesknife.services.LEAVESKNIFE_CONFIG_FILE
import cn.xor7.xiaohei.leavesknife.services.leavesknifeConfigService
import cn.xor7.xiaohei.leavesknife.services.leavesknifeStoreService
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.startup.ProjectActivity
Expand All @@ -11,27 +11,24 @@ import java.io.File
import java.nio.file.Files
import java.nio.file.Paths


class ProjectStartupActivity : ProjectActivity {
override suspend fun execute(project: Project) {
project.guessProjectDir()?.let {
if (Files.exists(
Paths.get(
it.path,
LEAVESKNIFE_CONFIG_FILE
)
)
) {
// TODO 检查配置文件合法性
return@let
val store = project.leavesknifeStoreService
project.guessProjectDir()?.let { projectDir ->
if (Files.exists(Paths.get(projectDir.path, LEAVESKNIFE_CONFIG_FILE))) {
// TODO 检查配置文件合法性 合法则设置 enablePlugin 为 true 否则设置 needConfigure 为 true
store.enablePlugin = true
}
GradleConnector.newConnector()
.forProjectDirectory(File(it.path))
.forProjectDirectory(File(projectDir.path))
.connect().use { connection ->
val ideaProject: IdeaProject = connection.getModel(IdeaProject::class.java)
if (ideaProject.modules.any { it.name == "paper-api-generator" }) {
project.leavesknifeConfigService.needConfigure = true
return@let
store.modulePaths = ideaProject.modules.associateTo(mutableMapOf()) {
it.name to it.contentRoots.first().rootDirectory.absolutePath
}
if (!store.modulePaths.containsKey("paper-api-generator") && !store.enablePlugin) return@let
store.enablePlugin = true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.intellij.openapi.wm.ToolWindowManager
const val LEAVESKNIFE_CONFIG_FILE = "leavesknife.properties"

@Service(Service.Level.PROJECT)
class ProjectConfigService(private val project: Project) {
class ProjectStoreService(private val project: Project) {
var enablePlugin = false
set(value) {
field = value
Expand All @@ -27,6 +27,7 @@ class ProjectConfigService(private val project: Project) {
}
var needConfigure = false

Check warning on line 28 in src/main/kotlin/cn/xor7/xiaohei/leavesknife/services/ProjectStoreService.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Property "needConfigure" is never used
set(value) {
if (value) enablePlugin = false
if (field == value) return
field = value
if (value) {
Expand All @@ -37,9 +38,7 @@ class ProjectConfigService(private val project: Project) {
CommonBundle.message("notification.configure.title"),
NotificationType.INFORMATION
)
.addAction(object : NotificationAction(
CommonBundle.message("notification.configure.action")
) {
.addAction(object : NotificationAction(CommonBundle.message("notification.configure.action")) {
override fun actionPerformed(e: AnActionEvent, notification: Notification) {
// TODO 打开配置窗口
notification.hideBalloon()
Expand All @@ -48,7 +47,8 @@ class ProjectConfigService(private val project: Project) {
.notify(project)
}
}
var modulePaths: MutableMap<String, String> = mutableMapOf()
}

val Project.leavesknifeConfigService: ProjectConfigService
get() = this.getService(ProjectConfigService::class.java)
val Project.leavesknifeStoreService: ProjectStoreService
get() = this.getService(ProjectStoreService::class.java)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cn.xor7.xiaohei.leavesknife.toolWindow

import cn.xor7.xiaohei.leavesknife.services.ProjectConfigService
import cn.xor7.xiaohei.leavesknife.services.ProjectStoreService
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindow
Expand All @@ -24,7 +24,7 @@ class PatchesToolWindowFactory : ToolWindowFactory {
override fun shouldBeAvailable(project: Project) = false

class ServerPatchesToolWindow(toolWindow: ToolWindow) {
private val service = toolWindow.project.service<ProjectConfigService>()
private val service = toolWindow.project.service<ProjectStoreService>()

Check warning on line 27 in src/main/kotlin/cn/xor7/xiaohei/leavesknife/toolWindow/PatchesToolWindowFactory.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Property "service" is never used

fun getContent() = JBPanel<JBPanel<*>>().apply {

Expand Down

0 comments on commit 512b247

Please sign in to comment.