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
This commit is contained in:
committed by
Roman Golyshev
parent
f0f2fd5684
commit
870dbd158c
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+23
-1
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user