瀏覽代碼

add: add notify util, Update gitignore

hwh97 4 年之前
父節點
當前提交
646a3bef6d
共有 5 個文件被更改,包括 63 次插入35 次删除
  1. 2 0
      .gitignore
  2. 22 2
      build.gradle.kts
  3. 3 6
      src/main/kotlin/RouterGenerateAction.kt
  4. 0 27
      src/main/kotlin/util/MessageUtil.kt
  5. 36 0
      src/main/kotlin/util/NotifierUtil.kt

+ 2 - 0
.gitignore

@@ -1,3 +1,5 @@
 .idea/
 /build/
 .gradle/
+.gradlew
+.gradlew.bat

+ 22 - 2
build.gradle.kts

@@ -1,3 +1,6 @@
+import org.gradle.api.JavaVersion.VERSION_1_8
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
+
 plugins {
     id("org.jetbrains.intellij") version "0.7.2"
     java
@@ -11,6 +14,11 @@ repositories {
     mavenCentral()
 }
 
+configure<JavaPluginConvention> {
+    sourceCompatibility = VERSION_1_8
+    targetCompatibility = VERSION_1_8
+}
+
 dependencies {
     implementation(kotlin("stdlib"))
     testCompile("junit", "junit", "4.12")
@@ -20,6 +28,18 @@ dependencies {
 intellij {
     version = "2020.3.1"
 }
-tasks.getByName<org.jetbrains.intellij.tasks.PatchPluginXmlTask>("patchPluginXml") {
-    changeNotes("""""")
+
+tasks {
+    withType<KotlinCompile> {
+        kotlinOptions {
+            jvmTarget = "1.8"
+            languageVersion = "1.4"
+            apiVersion = "1.3"
+            freeCompilerArgs = listOf("-Xjvm-default=enable")
+        }
+    }
+
+    getByName<org.jetbrains.intellij.tasks.PatchPluginXmlTask>("patchPluginXml") {
+        changeNotes("""""")
+    }
 }

+ 3 - 6
src/main/kotlin/RouterGenerateAction.kt

@@ -1,24 +1,21 @@
 import com.intellij.openapi.actionSystem.AnAction
 import com.intellij.openapi.actionSystem.AnActionEvent
-import com.intellij.openapi.actionSystem.CommonDataKeys
 import com.intellij.openapi.actionSystem.PlatformDataKeys
 import com.intellij.openapi.diagnostic.LoggerRt
-import com.intellij.psi.PsiFile
 
 class RouterGenerateAction : AnAction() {
     private val log = LoggerRt.getInstance(RouterGenerateAction::class.java)
 
     override fun actionPerformed(e: AnActionEvent) {
         val project = e.getData(PlatformDataKeys.PROJECT)!!
-        log.info(project.name)
-        print(project.name)
+//        log.info(project.name)
+//        print(project.)
 
 //        val psiFile = e.getData(CommonDataKeys.PSI_FILE)
 //
 //        val classPath = psiFile!!.virtualFile.path
 //
 //        val title = "Stupid Flutter";
-
-        MessageUtil.showMessage(project.name)
+        NotifierUtil.showNotifier(project, project.name)
     }
 }

+ 0 - 27
src/main/kotlin/util/MessageUtil.kt

@@ -1,27 +0,0 @@
-import com.intellij.openapi.ui.Messages
-import javax.swing.Icon
-
-enum class MessageType {
-    INFO, WARM, ERROR, QUESTION
-}
-
-object MessageUtil {
-    const val title: String = "提示"
-
-    fun showMessage(
-        content: String,
-        title: String = this.title,
-        messageType: MessageType = MessageType.INFO
-    ) {
-        Messages.showMessageDialog(content, title, getMessageIconByType(messageType));
-    }
-
-    private fun getMessageIconByType(type: MessageType): Icon {
-        return when (type) {
-            MessageType.INFO -> Messages.getInformationIcon()
-            MessageType.WARM -> Messages.getWarningIcon()
-            MessageType.ERROR -> Messages.getErrorIcon()
-            MessageType.QUESTION -> Messages.getQuestionIcon()
-        }
-    }
-}

+ 36 - 0
src/main/kotlin/util/NotifierUtil.kt

@@ -0,0 +1,36 @@
+import com.intellij.notification.NotificationGroupManager
+import com.intellij.notification.NotificationType
+import com.intellij.openapi.project.Project
+import com.intellij.openapi.ui.Messages
+import javax.swing.Icon
+import com.intellij.notification.NotificationDisplayType
+
+import com.intellij.notification.NotificationGroup
+
+
+enum class NotifierType {
+    INFO, WARM, ERROR
+}
+
+object NotifierUtil {
+    const val title: String = "提示"
+    private val NOTIFICATION_GROUP =
+        NotificationGroup("Custom Notification Group", NotificationDisplayType.BALLOON, true)
+
+    fun showNotifier(
+        project: Project,
+        content: String,
+        title: String = this.title,
+        type: NotifierType = NotifierType.INFO
+    ) = NOTIFICATION_GROUP
+        .createNotification(title, content, getNotifierByType(type))
+        .notify(project);
+
+    private fun getNotifierByType(type: NotifierType): NotificationType {
+        return when (type) {
+            NotifierType.INFO -> NotificationType.INFORMATION
+            NotifierType.WARM -> NotificationType.WARNING
+            NotifierType.ERROR -> NotificationType.ERROR
+        }
+    }
+}