Skip to content

Commit

Permalink
fix: fix merge errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MC-XiaoHei committed Jun 15, 2024
1 parent f933d7e commit e1988f4
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ class PluginConfigurationDialog(private val project: Project) : DialogWrapper(tr
}
}


private fun getFallbackOption(patchType: PatchType): String {
return if (patchType == PatchType.GENERATED_API)
store.modulePaths.keys.find { it.contains("generator", ignoreCase = true) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.xor7.xiaohei.leavesknife.services
package cn.xor7.xiaohei.leavesknife.listeners

import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package cn.xor7.xiaohei.leavesknife.activities
package cn.xor7.xiaohei.leavesknife.listeners

import cn.xor7.xiaohei.leavesknife.CommonBundle
import cn.xor7.xiaohei.leavesknife.dialogs.PluginConfigurationDialog
import cn.xor7.xiaohei.leavesknife.services.PatchType
import cn.xor7.xiaohei.leavesknife.services.PatchesInfo
import cn.xor7.xiaohei.leavesknife.services.PluginStatus
import cn.xor7.xiaohei.leavesknife.services.leavesknifeStoreService
import cn.xor7.xiaohei.leavesknife.utils.createPluginInfoNotification
import cn.xor7.xiaohei.leavesknife.utils.createSimpleNotification
import com.intellij.notification.NotificationType
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
Expand Down Expand Up @@ -46,9 +51,36 @@ class ProjectStartupActivity : ProjectActivity {
}
scanModules(project)
status = if (modulePaths.containsKey("paper-api-generator")) {
if (status != PluginStatus.TOOLWINDOW_ENABLED) PluginStatus.MISSING_CONFIG
else PluginStatus.ENABLED
when (status) {
PluginStatus.TOOLWINDOW_ENABLED -> PluginStatus.ENABLED
PluginStatus.BROKEN_CONFIG -> {
createSimpleNotification(
CommonBundle.message("notification.broken_config.title"),
NotificationType.ERROR,
CommonBundle.message("notification.broken_config.action")
) {
PluginConfigurationDialog(project).show()
}.notify(project)
PluginStatus.BROKEN_CONFIG
}

PluginStatus.DISABLED -> {
createPluginInfoNotification(
CommonBundle.message("notification.missing_config.title"),
CommonBundle.message("notification.missing_config.action")
) {
PluginConfigurationDialog(project).show()
}.notify(project)
PluginStatus.MISSING_CONFIG
}

else -> PluginStatus.DISABLED
}
} else {
createSimpleNotification(
CommonBundle.message("notification.unexpected_config.title"),
NotificationType.WARNING
).notify(project)
PluginStatus.DISABLED
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
package cn.xor7.xiaohei.leavesknife.services

import cn.xor7.xiaohei.leavesknife.CommonBundle
import cn.xor7.xiaohei.leavesknife.dialogs.PluginConfigurationDialog
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.application.runInEdt
import com.intellij.openapi.components.Service
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.util.IconLoader
import com.intellij.openapi.wm.ToolWindowManager
import java.nio.file.Path
import java.nio.file.Paths
Expand All @@ -21,45 +13,27 @@ const val LEAVESKNIFE_CONFIG_FILE = "leavesknife.properties"

@Service(Service.Level.PROJECT)
class ProjectStoreService(private val project: Project) {
var enablePlugin = false
var status = PluginStatus.DISABLED
set(value) {
field = value
if(field == value) return
runInEdt {
ToolWindowManager
.getInstance(project)
.getToolWindow("Patches")
?.isAvailable = value
?.isAvailable = value == PluginStatus.ENABLED || value == PluginStatus.TOOLWINDOW_ENABLED
}
}
var needConfigure = false
set(value) {
if (value) enablePlugin = false
if (field == value) return
field = value
if (value) {
@Suppress("DialogTitleCapitalization")
NotificationGroupManager.getInstance()
.getNotificationGroup("LeavesKnife")
.createNotification(
CommonBundle.message("notification.configure.title"),
NotificationType.INFORMATION,
)
.setIcon(IconLoader.getIcon("/icons/icon-16x.svg",this.javaClass.classLoader))
.addAction(object : NotificationAction(CommonBundle.message("notification.configure.action")) {
override fun actionPerformed(e: AnActionEvent, notification: Notification) {
notification.hideBalloon()
PluginConfigurationDialog(project).show()
}
})
.notify(project)
}
}
var modulePaths: MutableMap<String, String> = mutableMapOf()
val patchesInfo: MutableMap<PatchType, PatchesInfo> = mutableMapOf()
val properties = Properties()
val configPath: Path = Paths.get(project.guessProjectDir()?.path ?: ".", LEAVESKNIFE_CONFIG_FILE)
}

enum class PluginStatus {
DISABLED, MISSING_CONFIG, BROKEN_CONFIG, TOOLWINDOW_ENABLED, ENABLED
}

val Project.leavesknifeStoreService: ProjectStoreService
get() = this.getService(ProjectStoreService::class.java)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package cn.xor7.xiaohei.leavesknife.toolWindow

import cn.xor7.xiaohei.leavesknife.services.ProjectStoreService
import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindow
import com.intellij.openapi.wm.ToolWindowFactory
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.ui.components.JBPanel
import com.intellij.ui.content.ContentFactory
import com.intellij.ui.dsl.builder.panel

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
package cn.xor7.xiaohei.leavesknife.utils

import cn.xor7.xiaohei.leavesknife.CommonBundle
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.util.IconLoader

fun notifyPluginInfo(
project: Project,
fun createSimpleNotification(
title: String,
type: NotificationType,
): Notification = NotificationGroupManager.getInstance()
.getNotificationGroup("LeavesKnife")
.createNotification(title, type)

fun createSimpleNotification(
title: String,
type: NotificationType,
actionName: String,
action: (AnActionEvent) -> Unit,
): Notification = createSimpleNotification(title, type)
.addAction(object : NotificationAction(actionName) {
override fun actionPerformed(e: AnActionEvent, notification: Notification) {
notification.hideBalloon()
action(e)
}
})

fun createPluginInfoNotification(
title: String,
actionName: String,
action: (AnActionEvent) -> Unit,
) {
NotificationGroupManager.getInstance()
.getNotificationGroup("LeavesKnife")
.createNotification(
title,
NotificationType.INFORMATION
)
.addAction(object : NotificationAction(actionName) {
override fun actionPerformed(e: AnActionEvent, notification: Notification) {
notification.hideBalloon()
action(e)
}
})
.notify(project)
}
): Notification = createSimpleNotification(title, NotificationType.INFORMATION, actionName, action)
.setIcon(IconLoader.getIcon("/icons/icon-16x.svg", CommonBundle.javaClass.classLoader))
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<resource-bundle>messages.CommonBundle</resource-bundle>

<extensions defaultExtensionNs="com.intellij">
<postStartupActivity implementation="cn.xor7.xiaohei.leavesknife.activities.ProjectStartupActivity"/>
<postStartupActivity implementation="cn.xor7.xiaohei.leavesknife.listeners.ProjectStartupActivity"/>
<toolWindow factoryClass="cn.xor7.xiaohei.leavesknife.toolWindow.PatchesToolWindowFactory"
id="Patches"
anchor="right"
Expand All @@ -21,7 +21,7 @@
</extensions>

<extensions defaultExtensionNs="org.jetbrains.plugins.gradle">
<taskManager implementation="cn.xor7.xiaohei.leavesknife.services.GradleTaskManager"/>
<taskManager implementation="cn.xor7.xiaohei.leavesknife.listeners.GradleTaskManager"/>
</extensions>

<applicationListeners>
Expand Down
9 changes: 6 additions & 3 deletions src/main/resources/messages/CommonBundle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
notification.configure.title=\u7F3A\u5931 LeavesKnife \u914D\u7F6E
notification.configure.action=\u914D\u7F6E
notification.missing_config.title=\u7F3A\u5931 LeavesKnife \u914D\u7F6E
notification.missing_config.action=\u914D\u7F6E
dialog.configure.title=LeavesKnife \u914D\u7F6E
# suppress inspection "UnusedProperty"
dialog.configure.server.browse.title=\u9009\u62E9 Server Patches \u8865\u4E01\u76EE\u5F55
Expand All @@ -11,4 +11,7 @@ dialog.configure.common.module=\u6A21\u5757
dialog.configure.common.path=\u8865\u4E01\u76EE\u5F55
dialog.configure.common.path.error.empty=\u8865\u4E01\u76EE\u5F55\u4E0D\u80FD\u4E3A\u7A7A
dialog.configure.common.path.error.same=\u4E0D\u5141\u8BB8\u51FA\u73B0\u540C\u6837\u7684\u8865\u4E01\u76EE\u5F55
dialog.configure.common.module.error.same=\u4E0D\u5141\u8BB8\u51FA\u73B0\u540C\u6837\u7684\u6A21\u5757
dialog.configure.common.module.error.same=\u4E0D\u5141\u8BB8\u51FA\u73B0\u540C\u6837\u7684\u6A21\u5757
notification.unexpected_config.title=\u627E\u5230\u4E86 LeavesKnife \u914D\u7F6E\u6587\u4EF6\uFF0C\u4F46\u6B64\u9879\u76EE\u4F3C\u4E4E\u5E76\u4E0D\u662F\u5408\u9002\u7684\u9879\u76EE
notification.broken_config.title=LeavesKnife \u914D\u7F6E\u6587\u4EF6\u5DF2\u635F\u574F
notification.broken_config.action=\u4FEE\u590D

0 comments on commit e1988f4

Please sign in to comment.