⁠
rednesto: Translation: Remove superfluous "Convert to translation" action
- /*
- * Minecraft Development for IntelliJ
- *
- * https://mcdev.io/
- *
- * Copyright (C) 2024 minecraft-dev
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation, version 3.0 only.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- package com.demonwav.mcdev.translations.actions
- import com.demonwav.mcdev.translations.intentions.ConvertToTranslationIntention
- import com.intellij.openapi.actionSystem.ActionUpdateThread
- import com.intellij.openapi.actionSystem.AnAction
- import com.intellij.openapi.actionSystem.AnActionEvent
- import com.intellij.openapi.actionSystem.LangDataKeys
- import com.intellij.openapi.actionSystem.PlatformDataKeys
- import com.intellij.psi.PsiLiteral
- class ConvertToTranslationAction : AnAction() {
- override fun actionPerformed(e: AnActionEvent) {
- val file = e.getData(LangDataKeys.PSI_FILE) ?: return
- val editor = e.getData(PlatformDataKeys.EDITOR) ?: return
- val element = file.findElementAt(editor.caretModel.offset) ?: return
- ConvertToTranslationIntention().invoke(editor.project ?: return, editor, element)
- }
- override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
- override fun update(e: AnActionEvent) {
- val file = e.getData(LangDataKeys.PSI_FILE)
- val editor = e.getData(PlatformDataKeys.EDITOR)
- if (file == null || editor == null) {
- e.presentation.isEnabledAndVisible = false
- return
- }
- val element = file.findElementAt(editor.caretModel.offset)
- e.presentation.isEnabledAndVisible = (element?.parent as? PsiLiteral)?.value is String
- }
- }