feat: deactivate actions that are not possible currently

This commit is contained in:
Johannes Frohnmeyer 2024-05-17 08:59:21 +02:00
parent 83f06878f2
commit 5671847bf7
Signed by: Johannes
GPG Key ID: E76429612C2929F4
7 changed files with 23 additions and 11 deletions

View File

@ -1,6 +1,5 @@
package io.gitlab.jfronny.sdom.actions
import com.intellij.icons.AllIcons
import com.intellij.notification.Notification
import com.intellij.notification.NotificationAction
import com.intellij.openapi.actionSystem.*
@ -22,10 +21,8 @@ import javax.swing.JComponent
class SDContestSelectionComboBoxAction : ComboBoxAction(), DumbAware {
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
private val icon = AllIcons.Actions.ListChanges
override fun update(e: AnActionEvent) {
e.presentation.isEnabledAndVisible = SDom.loggedIn
e.presentation.icon = icon
SDom.currentContest?.let { e.presentation.setText(it.name, false) }
}

View File

@ -12,6 +12,10 @@ import kotlinx.coroutines.launch
class SDGetContestsAction : DumbAwareAction() {
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
override fun update(e: AnActionEvent) {
e.presentation.isEnabledAndVisible = SDom.loggedIn
}
override fun actionPerformed(e: AnActionEvent) {
CoroutineScope(Job() + Dispatchers.IO).launch {
SDom.getContests()

View File

@ -12,6 +12,11 @@ import kotlinx.coroutines.launch
class SDGetProblemsAction : DumbAwareAction() {
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
override fun update(e: AnActionEvent) {
e.presentation.isVisible = SDom.loggedIn
e.presentation.isEnabled = SDom.loggedIn && SDom.currentContest != null
}
override fun actionPerformed(e: AnActionEvent) {
CoroutineScope(Job() + Dispatchers.IO).launch {
SDom.fetchProblems()

View File

@ -1,6 +1,5 @@
package io.gitlab.jfronny.sdom.actions
import com.intellij.icons.AllIcons
import com.intellij.notification.Notification
import com.intellij.notification.NotificationAction
import com.intellij.openapi.actionSystem.*
@ -18,10 +17,9 @@ import javax.swing.JComponent
class SDProblemSelectionComboBoxAction : ComboBoxAction(), DumbAware {
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
private val icon = AllIcons.Actions.ListChanges
override fun update(e: AnActionEvent) {
e.presentation.isEnabledAndVisible = SDom.loggedIn
e.presentation.icon = icon
e.presentation.isVisible = SDom.loggedIn
e.presentation.isEnabled = SDom.loggedIn && SDom.currentContest != null
SDom.currentProblem?.let { e.presentation.setText(it.name, false) }
}

View File

@ -22,6 +22,11 @@ import java.nio.file.Files
class SDStatementAction(name: String) : DumbAwareAction(name) {
constructor() : this("")
override fun update(e: AnActionEvent) {
e.presentation.isVisible = SDom.loggedIn
e.presentation.isEnabled = SDom.loggedIn && currentContest != null && currentProblem != null
}
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
override fun actionPerformed(e: AnActionEvent) {

View File

@ -20,6 +20,11 @@ import kotlinx.coroutines.launch
class SDSubmitAction(text: String) : NotificationAction(text) {
constructor() : this("")
override fun update(e: AnActionEvent) {
e.presentation.isVisible = SDom.loggedIn && e.project != null
e.presentation.isEnabled = SDom.loggedIn && e.project != null && SDom.currentContest != null && SDom.currentProblem != null
}
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
override fun actionPerformed(e: AnActionEvent, notification: Notification) = actionPerformed(e)
@ -79,10 +84,6 @@ class SDSubmitAction(text: String) : NotificationAction(text) {
}
}
override fun update(e: AnActionEvent) {
e.presentation.isEnabledAndVisible = e.project != null
}
companion object {
private val LOG = Logger.getInstance(SDSubmitAction::class.java).apply {
setLevel(LogLevel.DEBUG)

View File

@ -39,6 +39,7 @@
description="Login to a DOMjudge instance"/>
<action id="io.gitlab.jfronny.sdom.actions.SDContestSelectionComboBoxAction"
class="io.gitlab.jfronny.sdom.actions.SDContestSelectionComboBoxAction"
icon="AllIcons.Actions.ListChanges"
text="Select Contest">
<add-to-group group-id="io.gitlab.jfronny.sdom.actions.SDToolbarActions"/>
</action>
@ -50,6 +51,7 @@
</action>
<action id="io.gitlab.jfronny.sdom.actions.SDProblemSelectionComboBoxAction"
class="io.gitlab.jfronny.sdom.actions.SDProblemSelectionComboBoxAction"
icon="AllIcons.Actions.ListChanges"
text="Select Problem">
<add-to-group group-id="io.gitlab.jfronny.sdom.actions.SDToolbarActions"/>
</action>