feat: complete initial submission UI

This commit is contained in:
Johannes Frohnmeyer 2024-05-12 17:12:22 +02:00
parent 9bdf0026f0
commit 501084ca58
Signed by: Johannes
GPG Key ID: E76429612C2929F4
2 changed files with 22 additions and 20 deletions

View File

@ -7,10 +7,10 @@ import com.intellij.notification.NotificationGroupManager
import com.intellij.notification.NotificationType import com.intellij.notification.NotificationType
import com.intellij.openapi.actionSystem.ActionUpdateThread import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.diagnostic.LogLevel import com.intellij.openapi.diagnostic.LogLevel
import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.diagnostic.Logger
import com.intellij.testFramework.utils.editor.getVirtualFile import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.vfs.readText
import io.gitlab.jfronny.sdom.SDom import io.gitlab.jfronny.sdom.SDom
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -26,9 +26,10 @@ class SDSubmitAction(text: String) : NotificationAction(text) {
override fun actionPerformed(e: AnActionEvent, notification: Notification) = actionPerformed(e) override fun actionPerformed(e: AnActionEvent, notification: Notification) = actionPerformed(e)
override fun actionPerformed(e: AnActionEvent) { override fun actionPerformed(e: AnActionEvent) {
println("Submitting") println("Submitting")
val editor = e.getData(CommonDataKeys.EDITOR) //val virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE)
e.project?.let { project -> e.project?.let { project ->
if (editor == null) { val virtualFile = FileEditorManager.getInstance(project).selectedTextEditor?.virtualFile
if (virtualFile == null) {
NotificationGroupManager.getInstance() NotificationGroupManager.getInstance()
.getNotificationGroup("sdom.notifications") .getNotificationGroup("sdom.notifications")
.createNotification("You have to select a file", NotificationType.ERROR) .createNotification("You have to select a file", NotificationType.ERROR)
@ -37,8 +38,8 @@ class SDSubmitAction(text: String) : NotificationAction(text) {
.notify(e.project) .notify(e.project)
return return
} }
val currentFile = editor.document.text val currentFile = virtualFile.readText()
val fileName = editor.document.getVirtualFile().name val fileName = virtualFile.name
val contest = SDom.currentContest val contest = SDom.currentContest
if (contest == null) { if (contest == null) {

View File

@ -27,24 +27,25 @@ class SDResultPanel(
private val panel = JPanel(BorderLayout()) private val panel = JPanel(BorderLayout())
init { init {
val loading = JLabel("Waiting for result...")
panel.add(loading, BorderLayout.CENTER)
CoroutineScope(Job() + Dispatchers.IO).launch { CoroutineScope(Job() + Dispatchers.IO).launch {
val resultResult = resultFlow.first() val resultResult = resultFlow.first()
if (resultResult.isSuccess) { resultResult.fold(
val result = resultResult.getOrThrow() onSuccess = { result ->
if (!result.valid) { val parsedResult =
panel.add(JLabel("Judgement failed"), BorderLayout.CENTER) result.judgementTypeId
return@launch ?.let { SDom.judgementTypes?.get(it) }
?.let { it.name to it.solved }
?: ("Unknown" to false)
panel.add(JLabel(parsedResult.first).apply { foreground = if (parsedResult.second) JBColor.GREEN else JBColor.RED }, BorderLayout.CENTER)
},
onFailure = { e ->
panel.add(JLabel("Judgement failed: ${e.message}"), BorderLayout.CENTER)
} }
val parsedResult = )
result.judgementTypeId panel.remove(loading)
?.let { SDom.judgementTypes?.get(it) }
?.let { it.name to it.solved }
?: ("Unknown" to false)
panel.add(JLabel(parsedResult.first).apply { foreground = if (parsedResult.second) JBColor.GREEN else JBColor.RED }, BorderLayout.CENTER)
} else {
panel.add(JLabel("Judgement failed"), BorderLayout.CENTER)
}
} }
} }