From 226db97e9cf67da0db3c718a157fe6dbf98b93b9 Mon Sep 17 00:00:00 2001 From: MC_XiaoHei Date: Sun, 2 Jun 2024 16:33:55 +0800 Subject: [PATCH] feat: add notification --- .../{MyBundle.kt => CommonBundle.kt} | 4 ++-- .../activities/ProjectStartupActivity.kt | 24 +++++++++++++++++-- .../services/ProjectConfigService.kt | 1 - src/main/resources/META-INF/plugin.xml | 7 ++++-- .../messages/CommonBundle.properties | 3 +++ .../resources/messages/MyBundle.properties | 3 --- 6 files changed, 32 insertions(+), 10 deletions(-) rename src/main/kotlin/cn/xor7/xiaohei/leavesknife/{MyBundle.kt => CommonBundle.kt} (83%) create mode 100644 src/main/resources/messages/CommonBundle.properties delete mode 100644 src/main/resources/messages/MyBundle.properties diff --git a/src/main/kotlin/cn/xor7/xiaohei/leavesknife/MyBundle.kt b/src/main/kotlin/cn/xor7/xiaohei/leavesknife/CommonBundle.kt similarity index 83% rename from src/main/kotlin/cn/xor7/xiaohei/leavesknife/MyBundle.kt rename to src/main/kotlin/cn/xor7/xiaohei/leavesknife/CommonBundle.kt index 74e352e..c8d2bc6 100644 --- a/src/main/kotlin/cn/xor7/xiaohei/leavesknife/MyBundle.kt +++ b/src/main/kotlin/cn/xor7/xiaohei/leavesknife/CommonBundle.kt @@ -5,9 +5,9 @@ import org.jetbrains.annotations.NonNls import org.jetbrains.annotations.PropertyKey @NonNls -private const val BUNDLE = "messages.MyBundle" +private const val BUNDLE = "messages.CommonBundle" -object MyBundle : DynamicBundle(BUNDLE) { +object CommonBundle : DynamicBundle(BUNDLE) { @JvmStatic fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) = 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 ef9968a..3cd1ec2 100644 --- a/src/main/kotlin/cn/xor7/xiaohei/leavesknife/activities/ProjectStartupActivity.kt +++ b/src/main/kotlin/cn/xor7/xiaohei/leavesknife/activities/ProjectStartupActivity.kt @@ -1,7 +1,13 @@ package cn.xor7.xiaohei.leavesknife.activities +import cn.xor7.xiaohei.leavesknife.CommonBundle import cn.xor7.xiaohei.leavesknife.services.LEAVESKNIFE_CONFIG_FILE import cn.xor7.xiaohei.leavesknife.services.leavesknifeConfigService +import com.intellij.notification.Notification +import com.intellij.notification.NotificationAction +import com.intellij.notification.NotificationGroupManager +import com.intellij.notification.NotificationType +import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.project.Project import com.intellij.openapi.project.guessProjectDir import com.intellij.openapi.startup.ProjectActivity @@ -29,8 +35,22 @@ class ProjectStartupActivity : ProjectActivity { .connect().use { connection -> val ideaProject: IdeaProject = connection.getModel(IdeaProject::class.java) if (ideaProject.modules.any { it.name == "paper-api-generator" }) { - // project.leavesknifeConfigService.enablePlugin = true - // TODO: 提示用户是否启用插件 + @Suppress("DialogTitleCapitalization") + NotificationGroupManager.getInstance() + .getNotificationGroup("LeavesKnife") + .createNotification( + CommonBundle.message("notification.configure.title"), + NotificationType.INFORMATION + ) + .addAction(object : NotificationAction( + CommonBundle.message("notification.configure.action") + ) { + override fun actionPerformed(e: AnActionEvent, notification: Notification) { + project.leavesknifeConfigService.enablePlugin = true + notification.hideBalloon() + } + }) + .notify(project) return@let } } 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 83264db..e54363f 100644 --- a/src/main/kotlin/cn/xor7/xiaohei/leavesknife/services/ProjectConfigService.kt +++ b/src/main/kotlin/cn/xor7/xiaohei/leavesknife/services/ProjectConfigService.kt @@ -12,7 +12,6 @@ class ProjectConfigService(private val project: Project) { var enablePlugin = false set(value) { field = value - println("enablePlugin: $value") runInEdt { ToolWindowManager .getInstance(project) diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 11d4963..bc239fa 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -6,7 +6,7 @@ com.intellij.modules.platform org.jetbrains.plugins.gradle - messages.MyBundle + messages.CommonBundle @@ -14,7 +14,10 @@ id="Patches" anchor="right" icon="AllIcons.Vcs.Patch" - canCloseContents="true" + /> + diff --git a/src/main/resources/messages/CommonBundle.properties b/src/main/resources/messages/CommonBundle.properties new file mode 100644 index 0000000..016b8b9 --- /dev/null +++ b/src/main/resources/messages/CommonBundle.properties @@ -0,0 +1,3 @@ +notification.group.name=LeavesKnife +notification.configure.title=为此项目配置 LeavesKnife +notification.configure.action=配置 \ No newline at end of file diff --git a/src/main/resources/messages/MyBundle.properties b/src/main/resources/messages/MyBundle.properties deleted file mode 100644 index 2e041d8..0000000 --- a/src/main/resources/messages/MyBundle.properties +++ /dev/null @@ -1,3 +0,0 @@ -projectService=Project service: {0} -randomLabel=The random number is: {0} -shuffle=Shuffle