style: clean up notifications
This commit is contained in:
parent
ac8e2f5443
commit
eed25918d9
|
@ -1,7 +1,6 @@
|
|||
package io.gitlab.jfronny.sdom
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent
|
||||
import com.intellij.notification.NotificationGroupManager
|
||||
import com.intellij.notification.NotificationType
|
||||
import com.intellij.openapi.actionSystem.*
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
|
@ -10,9 +9,8 @@ import com.intellij.openapi.diagnostic.Logger
|
|||
import com.intellij.openapi.project.Project
|
||||
import io.gitlab.jfronny.sdom.actions.SDGetContestsAction
|
||||
import io.gitlab.jfronny.sdom.actions.SDGetProblemsAction
|
||||
import io.gitlab.jfronny.sdom.actions.SDProblemSelectionNotificationAction
|
||||
import io.gitlab.jfronny.sdom.actions.SDSubmitAction
|
||||
import io.gitlab.jfronny.sdom.model.*
|
||||
import io.gitlab.jfronny.sdom.util.notify
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.call.*
|
||||
import io.ktor.client.engine.java.*
|
||||
|
@ -205,11 +203,11 @@ object SDom {
|
|||
.flatMap { l -> l.extensions.map { it to l } }
|
||||
.toMap()
|
||||
} catch (e: Exception) {
|
||||
NotificationGroupManager.getInstance()
|
||||
.getNotificationGroup("sdom.notifications")
|
||||
.createNotification("You have to select a problem", NotificationType.ERROR)
|
||||
.setTitle("No problem selected")
|
||||
.notify(context)
|
||||
notify(context,
|
||||
"Unable to load data",
|
||||
"Unable to get judgement types and supported languages for the contest",
|
||||
NotificationType.WARNING
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package io.gitlab.jfronny.sdom.actions
|
||||
|
||||
import com.intellij.notification.NotificationGroupManager
|
||||
import com.intellij.notification.NotificationType
|
||||
import com.intellij.openapi.actionSystem.ActionUpdateThread
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
|
@ -13,6 +12,7 @@ import io.gitlab.jfronny.sdom.SDom.currentContest
|
|||
import io.gitlab.jfronny.sdom.SDom.currentProblem
|
||||
import io.gitlab.jfronny.sdom.ui.ByteVirtualFile
|
||||
import io.gitlab.jfronny.sdom.util.OSUtils
|
||||
import io.gitlab.jfronny.sdom.util.notify
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
|
@ -33,21 +33,21 @@ class SDStatementAction(name: String) : DumbAwareAction(name) {
|
|||
val contest = currentContest
|
||||
val problem = currentProblem
|
||||
if (contest == null) {
|
||||
NotificationGroupManager.getInstance()
|
||||
.getNotificationGroup("sdom.notifications")
|
||||
.createNotification("You have to select a contest", NotificationType.ERROR)
|
||||
.setTitle("No contest selected")
|
||||
.addAction(SDStatementAction("Retry"))
|
||||
.notify(e.project)
|
||||
notify(e.project,
|
||||
"No contest selected",
|
||||
"You have to select a contest",
|
||||
NotificationType.ERROR,
|
||||
SDStatementAction("Retry")
|
||||
)
|
||||
return
|
||||
}
|
||||
if (problem == null) {
|
||||
NotificationGroupManager.getInstance()
|
||||
.getNotificationGroup("sdom.notifications")
|
||||
.createNotification("You have to select a problem", NotificationType.ERROR)
|
||||
.setTitle("No problem selected")
|
||||
.addAction(SDStatementAction("Retry"))
|
||||
.notify(e.project)
|
||||
notify(e.project,
|
||||
"No problem selected",
|
||||
"You have to select a problem",
|
||||
NotificationType.ERROR,
|
||||
SDStatementAction("Retry")
|
||||
)
|
||||
return
|
||||
}
|
||||
CoroutineScope(Job() + Dispatchers.IO).launch {
|
||||
|
|
|
@ -2,7 +2,6 @@ package io.gitlab.jfronny.sdom.actions
|
|||
|
||||
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.ActionUpdateThread
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
|
@ -11,6 +10,7 @@ import com.intellij.openapi.diagnostic.Logger
|
|||
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||
import com.intellij.openapi.vfs.readText
|
||||
import io.gitlab.jfronny.sdom.SDom
|
||||
import io.gitlab.jfronny.sdom.util.notify
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
|
@ -34,12 +34,12 @@ class SDSubmitAction(text: String) : NotificationAction(text) {
|
|||
e.project?.let { project ->
|
||||
val virtualFile = FileEditorManager.getInstance(project).selectedTextEditor?.virtualFile
|
||||
if (virtualFile == null) {
|
||||
NotificationGroupManager.getInstance()
|
||||
.getNotificationGroup("sdom.notifications")
|
||||
.createNotification("You have to select a file", NotificationType.ERROR)
|
||||
.setTitle("No file selected")
|
||||
.addAction(SDSubmitAction("Retry"))
|
||||
.notify(e.project)
|
||||
notify(e.project,
|
||||
"No file selected",
|
||||
"You have to select a file",
|
||||
NotificationType.ERROR,
|
||||
SDSubmitAction("Retry")
|
||||
)
|
||||
return
|
||||
}
|
||||
val currentFile = virtualFile.readText()
|
||||
|
@ -47,34 +47,34 @@ class SDSubmitAction(text: String) : NotificationAction(text) {
|
|||
val language = virtualFile.extension?.let { SDom.identifyLanguage(it) }
|
||||
|
||||
if (language == null) {
|
||||
NotificationGroupManager.getInstance()
|
||||
.getNotificationGroup("sdom.notifications")
|
||||
.createNotification("Could not identify the language of that file", NotificationType.ERROR)
|
||||
.setTitle("Unknown file extension")
|
||||
.notify(e.project)
|
||||
notify(e.project,
|
||||
"Unknown file extension",
|
||||
"Could not identify the language of that file",
|
||||
NotificationType.ERROR
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
val contest = SDom.currentContest
|
||||
if (contest == null) {
|
||||
NotificationGroupManager.getInstance()
|
||||
.getNotificationGroup("sdom.notifications")
|
||||
.createNotification("You have to select a contest", NotificationType.ERROR)
|
||||
.setTitle("No contest selected")
|
||||
.addAction(SDContestSelectionNotificationAction("Select Contest"))
|
||||
.addAction(SDSubmitAction("Retry"))
|
||||
.notify(e.project)
|
||||
notify(e.project,
|
||||
"No contest selected",
|
||||
"You have to select a contest",
|
||||
NotificationType.ERROR,
|
||||
SDContestSelectionNotificationAction("Select Contest"),
|
||||
SDSubmitAction("Retry")
|
||||
)
|
||||
return
|
||||
}
|
||||
val problem = SDom.currentProblem
|
||||
if (problem == null) {
|
||||
NotificationGroupManager.getInstance()
|
||||
.getNotificationGroup("sdom.notifications")
|
||||
.createNotification("You have to select a problem", NotificationType.ERROR)
|
||||
.setTitle("No problem selected")
|
||||
.addAction(SDProblemSelectionNotificationAction("Select Problem"))
|
||||
.addAction(SDSubmitAction("Retry"))
|
||||
.notify(e.project)
|
||||
notify(e.project,
|
||||
"No problem selected",
|
||||
"You have to select a problem",
|
||||
NotificationType.ERROR,
|
||||
SDProblemSelectionNotificationAction("Select Problem"),
|
||||
SDSubmitAction("Retry")
|
||||
)
|
||||
return
|
||||
}
|
||||
CoroutineScope(Job() + Dispatchers.IO).launch {
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package io.gitlab.jfronny.sdom.util
|
||||
|
||||
import com.intellij.notification.NotificationGroupManager
|
||||
import com.intellij.notification.NotificationType
|
||||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.project.Project
|
||||
|
||||
fun notify(context: Project?, title: String, content: String, notificationType: NotificationType = NotificationType.ERROR, vararg actions: AnAction) {
|
||||
NotificationGroupManager.getInstance()
|
||||
.getNotificationGroup("sdom.notifications")
|
||||
.createNotification(content, notificationType)
|
||||
.setTitle(title)
|
||||
.apply { actions.forEach { addAction(it) } }
|
||||
.notify(context)
|
||||
}
|
Loading…
Reference in New Issue