IFT-455 Show GotIt tooltips during editor steps in onboarding lessons

GitOrigin-RevId: 7d7b2c7a32f1e7c1c01b28cd8b6401a38e7b08ca
This commit is contained in:
Konstantin Hudyakov
2023-03-21 18:32:25 +02:00
committed by intellij-monorepo-bot
parent 56f3f86a1f
commit bc56e3da3b
5 changed files with 72 additions and 5 deletions

View File

@@ -41,15 +41,18 @@ java.onboarding.stop.debugging=Let''s stop debugging. Click the {0} icon.
java.onboarding.type.division=Once you have discovered the problem in the code, let''s fix it. Divide the resulting sum by the length of the values. \
The lesson script inserts {0} already.
java.onboarding.invoke.completion=Now let''s type a period {0} to show all available completion options.
java.onboarding.invoke.completion.balloon=Type a period {0} to show all available completion options
java.onboarding.choose.values.item=Now you can start typing {0} to reduce the completion list or select this item and press {1}.
java.onboarding.invoke.completion.tip=<strong>Tip</strong>: <ide/> shows completion options automatically as you type. \
Also, you can press {0} to show completion items in any place of the code.
java.onboarding.invoke.intention.for.warning.1=You have just fixed a bug, but you can make this code look even better. \
IDEA highlights and adds a yellow bulb to the code lines that can be improved.
java.onboarding.invoke.intention.for.warning.2=Press {0} to preview the warnings and apply a quick-fix.
java.onboarding.invoke.intention.for.warning.balloon=Press {0} to show available quick-fixes
java.onboarding.select.fix=Apply the first item: {0}. In this case, the <strong>for-each</strong> loop will make code easier to understand.
java.onboarding.invoke.intention.for.code=Intentions also save your time and make coding easier. Let''s use an intention to reformat string concatenation. \
Press {0} to show possible options.
java.onboarding.invoke.intention.for.code.balloon=Press {0} to show available intentions
java.onboarding.apply.intention=Select {0} and press {1}.
java.onboarding.invoke.search.everywhere.1=While working in <ide/>, you might want to search for files in your project, symbols, classes, or even IDE actions. In this lesson, let''s search for the {0} action to make the {1} string low-case.
java.onboarding.invoke.search.everywhere.2=Press {0} two times to open the {1} dialog.

View File

@@ -553,10 +553,17 @@ class JavaOnboardingTourLesson : KLesson("java.onboarding", JavaLessonsBundle.me
FocusManagerImpl.getInstance(project).requestFocusInProject(editor.contentComponent, project)
}
task {
val textToFind = "result / values"
triggerOnEditorText(textToFind, centerOffset = textToFind.length)
}
task {
text(JavaLessonsBundle.message("java.onboarding.type.division",
code(" / values")))
text(JavaLessonsBundle.message("java.onboarding.invoke.completion", code(".")))
text(JavaLessonsBundle.message("java.onboarding.invoke.completion.balloon", code(".")),
LearningBalloonConfig(Balloon.Position.below, width = 0))
triggerAndBorderHighlight().listItem { // no highlighting
it.isToStringContains("length")
}
@@ -576,9 +583,16 @@ class JavaOnboardingTourLesson : KLesson("java.onboarding", JavaLessonsBundle.me
private fun LessonContext.contextActions() {
val quickFixMessage = InspectionGadgetsBundle.message("foreach.replace.quickfix")
caret(sample.getPosition(3))
task {
triggerOnEditorText("for", highlightBorder = true)
}
task("ShowIntentionActions") {
text(JavaLessonsBundle.message("java.onboarding.invoke.intention.for.warning.1"))
text(JavaLessonsBundle.message("java.onboarding.invoke.intention.for.warning.2", action(it)))
text(JavaLessonsBundle.message("java.onboarding.invoke.intention.for.warning.balloon", action(it)),
LearningBalloonConfig(Balloon.Position.above, width = 0, cornerToPointerDistance = 80))
triggerAndBorderHighlight().listItem { item ->
item.isToStringContains(quickFixMessage)
}
@@ -604,8 +618,15 @@ class JavaOnboardingTourLesson : KLesson("java.onboarding", JavaLessonsBundle.me
}
caret("RAGE")
task {
triggerOnEditorText("AVERAGE")
}
task("ShowIntentionActions") {
text(JavaLessonsBundle.message("java.onboarding.invoke.intention.for.code", action(it)))
text(JavaLessonsBundle.message("java.onboarding.invoke.intention.for.code.balloon", action(it)),
LearningBalloonConfig(Balloon.Position.below, width = 0))
val intentionMessage = getIntentionMessage(project)
triggerAndBorderHighlight().listItem { item ->
item.isToStringContains(intentionMessage)

View File

@@ -28,6 +28,8 @@ import com.intellij.openapi.editor.LogicalPosition
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.editor.ex.EditorGutterComponentEx
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.openapi.editor.impl.EditorComponentImpl
import com.intellij.openapi.editor.impl.EditorImpl
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.options.OptionsBundle
import com.intellij.openapi.project.DumbService
@@ -699,6 +701,23 @@ fun TaskContext.triggerOnQuickDocumentationPopup() {
}
}
fun TaskContext.triggerOnEditorText(text: String, centerOffset: Int? = null, highlightBorder: Boolean = false) {
triggerUI { this.highlightBorder = highlightBorder }.componentPart l@{ ui: EditorComponentImpl ->
if (ui.editor != editor) return@l null
val offset = editor.document.charsSequence.indexOf(text)
if (offset < 0) return@l null
if (centerOffset == null) {
val point = editor.offsetToPoint2D(offset)
val width = (editor as EditorImpl).charHeight * text.length
Rectangle(point.x.toInt(), point.y.toInt(), width, editor.lineHeight)
}
else {
val point = editor.offsetToPoint2D(offset + centerOffset)
Rectangle(point.x.toInt() - 1, point.y.toInt(), 2, editor.lineHeight)
}
}
}
fun TaskContext.showBalloonOnHighlightingComponent(@Language("HTML") @Nls message: String,
position: Balloon.Position = Balloon.Position.below,
chooser: (List<JComponent>) -> JComponent? = { it.firstOrNull() }) {

View File

@@ -43,12 +43,15 @@ python.onboarding.type.division=Once you have discovered the problem in the code
The lesson script inserts {0} already.
python.onboarding.invoke.completion=Now let''s start typing {0} inside the parentheses {1}. \
<ide/> shows completion options automatically as you type. Alternatively, you can also press {2} and continue typing to reduce the list.
python.onboarding.invoke.completion.balloon=Start typing {0} to show all available completion options
python.onboarding.choose.values.item=Select {0} and press {1}.
python.onboarding.invoke.intention.for.warning.1=You have just fixed a bug, but you can make this code look even better.\
PyCharm highlights and adds a yellow bulb to the code lines that can be improved.
python.onboarding.invoke.intention.for.warning.2=Press {0} to preview the warnings and apply a quick-fix.
python.onboarding.invoke.intention.for.warning.balloon=Press {0} to show available quick-fixes
python.onboarding.select.fix=Apply the first item: {0}. With this fix, your code looks neat.
python.onboarding.invoke.intention.for.code=Intentions also save your time and make coding easier. Let''s use an intention to quickly add a return type for {0}. Press {1}.
python.onboarding.invoke.intention.for.code.balloon=Press {0} to show available intentions
python.onboarding.apply.intention=Select {0} and press {1}.
python.onboarding.complete.template=Type {0} and then press {1}.
python.onboarding.invoke.search.everywhere.1=While working in <ide/>, you might want to search for files in your project, symbols, classes, or even IDE actions. In this lesson, let''s search for the {0} action to make the {1} string low-case.

View File

@@ -454,6 +454,11 @@ class PythonOnboardingTourLesson :
setSample(sample.insertAtPosition(2, " / len(<caret>)"))
}
task {
val textToFind = "len()"
triggerOnEditorText(textToFind, centerOffset = textToFind.length - 1)
}
task {
text(PythonLessonsBundle.message("python.onboarding.type.division",
code(" / len()")))
@@ -461,6 +466,8 @@ class PythonOnboardingTourLesson :
code("values"),
code("()"),
action("CodeCompletion")))
text(PythonLessonsBundle.message("python.onboarding.invoke.completion.balloon", code("values")),
LearningBalloonConfig(Balloon.Position.below, width = 0))
triggerAndBorderHighlight().listItem { // no highlighting
it.isToStringContains("values")
}
@@ -480,9 +487,16 @@ class PythonOnboardingTourLesson :
private fun LessonContext.contextActions() {
val reformatMessage = PyBundle.message("QFIX.reformat.file")
caret(",6")
task {
triggerOnEditorText("5,6")
}
task("ShowIntentionActions") {
text(PythonLessonsBundle.message("python.onboarding.invoke.intention.for.warning.1"))
text(PythonLessonsBundle.message("python.onboarding.invoke.intention.for.warning.2", action(it)))
text(PythonLessonsBundle.message("python.onboarding.invoke.intention.for.warning.balloon", action(it)),
LearningBalloonConfig(Balloon.Position.below, width = 0))
triggerAndBorderHighlight().listItem { item ->
item.isToStringContains(reformatMessage)
}
@@ -502,10 +516,17 @@ class PythonOnboardingTourLesson :
if (PythonLessonsUtil.isPython3Installed(project)) PyPsiBundle.message("INTN.specify.return.type.in.annotation")
else PyPsiBundle.message("INTN.specify.return.type.in.docstring")
caret("find_average")
caret("average")
task {
triggerOnEditorText("find_average", highlightBorder = true)
}
task("ShowIntentionActions") {
text(PythonLessonsBundle.message("python.onboarding.invoke.intention.for.code",
code("find_average"), action(it)))
text(PythonLessonsBundle.message("python.onboarding.invoke.intention.for.code.balloon", action(it)),
LearningBalloonConfig(Balloon.Position.below, width = 0, cornerToPointerDistance = 50))
triggerAndBorderHighlight().listItem { item ->
item.isToStringContains(returnTypeMessage(project))
}