Skip to content

Commit

Permalink
feat: add notification
Browse files Browse the repository at this point in the history
  • Loading branch information
MC-XiaoHei committed Jun 2, 2024
1 parent a74cd16 commit 226db97
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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" }) {

Check notice on line 37 in src/main/kotlin/cn/xor7/xiaohei/leavesknife/activities/ProjectStartupActivity.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nested lambda has shadowed implicit parameter

Implicit parameter 'it' of enclosing lambda is shadowed
// 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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class ProjectConfigService(private val project: Project) {
var enablePlugin = false
set(value) {
field = value
println("enablePlugin: $value")
runInEdt {
ToolWindowManager
.getInstance(project)
Expand Down
7 changes: 5 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
<depends>com.intellij.modules.platform</depends>
<depends>org.jetbrains.plugins.gradle</depends>

<resource-bundle>messages.MyBundle</resource-bundle>
<resource-bundle>messages.CommonBundle</resource-bundle>

<extensions defaultExtensionNs="com.intellij">
<postStartupActivity implementation="cn.xor7.xiaohei.leavesknife.activities.ProjectStartupActivity"/>
<toolWindow factoryClass="cn.xor7.xiaohei.leavesknife.toolWindow.PatchesToolWindowFactory"
id="Patches"
anchor="right"
icon="AllIcons.Vcs.Patch"
canCloseContents="true"
/>
<notificationGroup id="LeavesKnife"
displayType="STICKY_BALLOON"
key="notification.group.name"
/>
</extensions>

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/messages/CommonBundle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
notification.group.name=LeavesKnife
notification.configure.title=为此项目配置 LeavesKnife
notification.configure.action=配置
3 changes: 0 additions & 3 deletions src/main/resources/messages/MyBundle.properties

This file was deleted.

0 comments on commit 226db97

Please sign in to comment.