From 870dbd158c52ff9a44197cf61b7e6f9db2e24b40 Mon Sep 17 00:00:00 2001 From: Roman Golyshev Date: Tue, 27 Aug 2019 15:18:34 +0300 Subject: [PATCH] KT-28910: Add tooltips for toolbar checkboxes in .kts scratch editor - make `ScratchFileAutoRunner.AUTO_RUN_DELAY_IN_SECONDS` public - remove `Show preview only` mode button from the toolbar - ^KT-28910 Fixed --- .../kotlin/idea/KotlinBundle.properties | 7 ++++++ .../idea/scratch/ScratchFileAutoRunner.kt | 4 ++-- .../scratch/ui/KtScratchFileEditorProvider.kt | 24 ++++++++++++++++++- .../kotlin/idea/scratch/ui/ScratchTopPanel.kt | 14 +++++++++-- .../scratch/ui/SmallBorderCheckboxAction.kt | 2 +- .../ui/SmallBorderCheckboxAction.kt.183 | 2 +- 6 files changed, 46 insertions(+), 7 deletions(-) diff --git a/idea/idea-analysis/resources/org/jetbrains/kotlin/idea/KotlinBundle.properties b/idea/idea-analysis/resources/org/jetbrains/kotlin/idea/KotlinBundle.properties index 57b3c459959..e0aabc8a56f 100644 --- a/idea/idea-analysis/resources/org/jetbrains/kotlin/idea/KotlinBundle.properties +++ b/idea/idea-analysis/resources/org/jetbrains/kotlin/idea/KotlinBundle.properties @@ -258,6 +258,13 @@ scratch.stop.button=Stop scratch execution scratch.clear.button=Clear results scratch.module.combobox=Use classpath of module scratch.is.repl.checkbox=Use REPL +scratch.is.repl.checkbox.description=Runs in the Kotlin REPL. Executes only the new expressions added to the end of the scratch scratch.is.interactive.checkbox=Interactive mode +scratch.is.interactive.checkbox.description=Runs after you stop typing for {0} seconds scratch.make.before.run.checkbox=Make module before Run +scratch.make.before.run.checkbox.description=Make module {0} before running scratch. Only compiled code is reachable from this scope +scratch.inlay.output.mode=Inlay output mode\n\nThe output is shown in the code editor right next to the expression. Well suited for a short single-line output. +scratch.side.panel.output.mode.description=Side panel output mode +scratch.side.panel.output.mode=Side panel output mode\n\nThe output is shown in the separate panel. Useful if the output is long or multi-line. +scratch.inlay.output.mode.description=Inlay output mode diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ScratchFileAutoRunner.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ScratchFileAutoRunner.kt index 93cd29645c5..79131cb806b 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ScratchFileAutoRunner.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ScratchFileAutoRunner.kt @@ -34,7 +34,7 @@ class ScratchFileAutoRunner(private val project: Project) : DocumentListener { private fun getInstance(project: Project) = ServiceManager.getService(project, ScratchFileAutoRunner::class.java) - private const val auto_run_delay = 2000 + const val AUTO_RUN_DELAY_IN_SECONDS = 2 } private val myAlarm = Alarm(Alarm.ThreadToUse.SWING_THREAD, project) @@ -68,7 +68,7 @@ class ScratchFileAutoRunner(private val project: Project) : DocumentListener { RunScratchAction.doAction(scratchFile, true) } } - }, auto_run_delay, true + }, AUTO_RUN_DELAY_IN_SECONDS * 1000, true ) } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/KtScratchFileEditorProvider.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/KtScratchFileEditorProvider.kt index 47f11561f53..b121f0c0d10 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/KtScratchFileEditorProvider.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/KtScratchFileEditorProvider.kt @@ -9,7 +9,7 @@ import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer import com.intellij.diff.tools.util.BaseSyncScrollable import com.intellij.diff.tools.util.SyncScrollSupport.TwosideSyncScrollSupport import com.intellij.openapi.Disposable -import com.intellij.openapi.actionSystem.ActionToolbar +import com.intellij.openapi.actionSystem.* import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.EditorFactory @@ -27,6 +27,7 @@ import com.intellij.openapi.vfs.VirtualFile import com.intellij.pom.Navigatable import com.intellij.psi.PsiManager import org.jetbrains.annotations.TestOnly +import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.scratch.* import org.jetbrains.kotlin.idea.scratch.output.* import org.jetbrains.kotlin.psi.UserDataProperty @@ -136,6 +137,27 @@ class KtScratchFileEditorWithPreview private constructor( commonPreviewOutputHandler.clear(scratchFile) } + override fun createViewActionGroup(): ActionGroup { + return DefaultActionGroup(showEditorAction, showEditorAndPreviewAction) + } + + /** + * For simple actions, [Presentation.getText] is shown in the tooltip in the [ActionToolbar], and [Presentation.getDescription] is shown + * in the bottom tool panel. But when action implements [com.intellij.openapi.actionSystem.ex.CustomComponentAction], its tooltip is + * controlled only by its [javax.swing.JComponent.setToolTipText] method. + * + * That's why we set long and descriptive [Presentation.getText], but short [Presentation.getDescription]. + */ + override fun getShowEditorAction(): ToggleAction = super.getShowEditorAction().apply { + templatePresentation.text = KotlinBundle.message("scratch.inlay.output.mode") + templatePresentation.description = KotlinBundle.message("scratch.inlay.output.mode.description") + } + + override fun getShowEditorAndPreviewAction(): ToggleAction = super.getShowEditorAndPreviewAction().apply { + templatePresentation.text = KotlinBundle.message("scratch.side.panel.output.mode") + templatePresentation.description = KotlinBundle.message("scratch.side.panel.output.mode.description") + } + override fun setLayout(newLayout: Layout) { val previous = layout super.setLayout(newLayout) diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/ScratchTopPanel.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/ScratchTopPanel.kt index 75d8dca74bb..85efe773e4f 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/ScratchTopPanel.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/ScratchTopPanel.kt @@ -21,6 +21,7 @@ import com.intellij.openapi.actionSystem.* import com.intellij.openapi.application.ApplicationManager import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.scratch.ScratchFile +import org.jetbrains.kotlin.idea.scratch.ScratchFileAutoRunner import org.jetbrains.kotlin.idea.scratch.actions.ClearScratchAction import org.jetbrains.kotlin.idea.scratch.actions.RunScratchAction import org.jetbrains.kotlin.idea.scratch.actions.StopScratchAction @@ -80,6 +81,9 @@ class ScratchTopPanel(val scratchFile: ScratchFile) { override fun update(e: AnActionEvent) { super.update(e) e.presentation.isVisible = scratchFile.module != null + e.presentation.description = scratchFile.module?.let { selectedModule -> + KotlinBundle.message("scratch.make.before.run.checkbox.description", selectedModule.name) + } } override fun isSelected(e: AnActionEvent): Boolean { @@ -91,7 +95,10 @@ class ScratchTopPanel(val scratchFile: ScratchFile) { } } - private inner class IsInteractiveCheckboxAction : SmallBorderCheckboxAction(KotlinBundle.message("scratch.is.interactive.checkbox")) { + private inner class IsInteractiveCheckboxAction : SmallBorderCheckboxAction( + text = KotlinBundle.message("scratch.is.interactive.checkbox"), + description = KotlinBundle.message("scratch.is.interactive.checkbox.description", ScratchFileAutoRunner.AUTO_RUN_DELAY_IN_SECONDS) + ) { override fun isSelected(e: AnActionEvent): Boolean { return scratchFile.options.isInteractiveMode } @@ -101,7 +108,10 @@ class ScratchTopPanel(val scratchFile: ScratchFile) { } } - private inner class IsReplCheckboxAction : SmallBorderCheckboxAction(KotlinBundle.message("scratch.is.repl.checkbox")) { + private inner class IsReplCheckboxAction : SmallBorderCheckboxAction( + text = KotlinBundle.message("scratch.is.repl.checkbox"), + description = KotlinBundle.message("scratch.is.repl.checkbox.description") + ) { override fun isSelected(e: AnActionEvent): Boolean { return scratchFile.options.isRepl } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/SmallBorderCheckboxAction.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/SmallBorderCheckboxAction.kt index aee304b44d7..fda67cbeb01 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/SmallBorderCheckboxAction.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/SmallBorderCheckboxAction.kt @@ -10,7 +10,7 @@ import com.intellij.openapi.actionSystem.ex.CheckboxAction import com.intellij.util.ui.JBUI import javax.swing.JComponent -abstract class SmallBorderCheckboxAction(label: String) : CheckboxAction(label) { +abstract class SmallBorderCheckboxAction(text: String, description: String? = null) : CheckboxAction(text, description, null) { override fun createCustomComponent(presentation: Presentation, place: String): JComponent { val checkbox = super.createCustomComponent(presentation, place) checkbox.border = JBUI.Borders.emptyRight(4) diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/SmallBorderCheckboxAction.kt.183 b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/SmallBorderCheckboxAction.kt.183 index 29bec03cf83..855bae57d16 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/SmallBorderCheckboxAction.kt.183 +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/SmallBorderCheckboxAction.kt.183 @@ -10,7 +10,7 @@ import com.intellij.openapi.actionSystem.ex.CheckboxAction import com.intellij.util.ui.JBUI import javax.swing.JComponent -abstract class SmallBorderCheckboxAction(label: String) : CheckboxAction(label) { +abstract class SmallBorderCheckboxAction(text: String, description: String? = null) : CheckboxAction(text, description, null) { override fun createCustomComponent(presentation: Presentation): JComponent { val checkbox = super.createCustomComponent(presentation) checkbox.border = JBUI.Borders.emptyRight(4)