mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:10:43 +07:00
IFT-553 Adapt Local History lesson to new local history dialog UI
GitOrigin-RevId: 8c54467456e8e519a1de1ecbef00ac1fe30589da
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2aeceefae9
commit
9ee89b102b
@@ -12,12 +12,14 @@ import com.intellij.ui.components.JBList
|
||||
import com.intellij.ui.hover.ListHoverListener
|
||||
import com.intellij.ui.speedSearch.FilteringListModel
|
||||
import com.intellij.util.EventDispatcher
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import java.awt.event.KeyAdapter
|
||||
import java.awt.event.KeyEvent
|
||||
import java.awt.event.MouseEvent
|
||||
import java.util.*
|
||||
|
||||
internal class ActivityList(presentationFunction: (item: ActivityItem) -> ActivityPresentation?) : JBList<ActivityItem>() {
|
||||
@ApiStatus.Internal
|
||||
class ActivityList(presentationFunction: (item: ActivityItem) -> ActivityPresentation?) : JBList<ActivityItem>() {
|
||||
private val eventDispatcher = EventDispatcher.create(Listener::class.java)
|
||||
|
||||
private var data = ActivityData.EMPTY
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.intellij.openapi.application.ModalityState
|
||||
import com.intellij.openapi.application.invokeAndWaitIfNeeded
|
||||
import com.intellij.openapi.application.invokeLater
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.EditorKind
|
||||
import com.intellij.openapi.editor.EditorModificationUtil
|
||||
import com.intellij.openapi.editor.LogicalPosition
|
||||
import com.intellij.openapi.editor.ex.EditorEx
|
||||
@@ -27,17 +28,10 @@ import com.intellij.openapi.progress.runBackgroundableTask
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.openapi.ui.popup.Balloon
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.ui.components.JBLoadingPanel
|
||||
import com.intellij.ui.components.JBLoadingPanelListener
|
||||
import com.intellij.ui.table.JBTable
|
||||
import com.intellij.ui.tabs.impl.SingleHeightTabs
|
||||
import com.intellij.platform.lvcs.impl.ui.ActivityList
|
||||
import com.intellij.util.DocumentUtil
|
||||
import com.intellij.util.concurrency.annotations.RequiresBackgroundThread
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import org.assertj.swing.core.MouseButton
|
||||
import org.assertj.swing.data.TableCell
|
||||
import org.assertj.swing.fixture.JTableFixture
|
||||
import org.assertj.swing.fixture.JListFixture
|
||||
import org.jetbrains.annotations.Nls
|
||||
import training.FeaturesTrainerIcons
|
||||
import training.dsl.*
|
||||
@@ -55,8 +49,6 @@ import training.util.LessonEndInfo
|
||||
import java.awt.Component
|
||||
import java.awt.Point
|
||||
import java.awt.Rectangle
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import javax.swing.JFrame
|
||||
|
||||
class LocalHistoryLesson(
|
||||
override val sampleFilePath: String? = null,
|
||||
@@ -193,14 +185,11 @@ class LocalHistoryLesson(
|
||||
}
|
||||
}
|
||||
|
||||
var revisionsTable: JBTable? = null
|
||||
var revisionsList: ActivityList? = null
|
||||
task {
|
||||
triggerAndBorderHighlight().componentPart { ui: JBTable ->
|
||||
if (checkInsideLocalHistoryFrame(ui)) {
|
||||
revisionsTable = ui
|
||||
ui.getCellRect(revisionInd, 0, false)
|
||||
}
|
||||
else null
|
||||
triggerAndBorderHighlight().componentPart { ui: ActivityList ->
|
||||
revisionsList = ui
|
||||
ui.getCellBounds(revisionInd, revisionInd)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,31 +197,14 @@ class LocalHistoryLesson(
|
||||
task {
|
||||
selectRevisionTaskId = taskId
|
||||
text(LessonsBundle.message("local.history.select.revision", strong(localHistoryActionText), strong(localHistoryActionText)))
|
||||
val step = CompletableFuture<Boolean>()
|
||||
addStep(step)
|
||||
triggerUI { clearPreviousHighlights = false }.component l@{ ui: JBLoadingPanel ->
|
||||
if (!checkInsideLocalHistoryFrame(ui)) return@l false
|
||||
ui.addListener(object : JBLoadingPanelListener {
|
||||
override fun onLoadingStart() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
override fun onLoadingFinish() {
|
||||
val revisions = revisionsTable ?: return
|
||||
if (revisions.selectionModel.selectedIndices.let { it.size == 1 && it[0] == revisionInd }) {
|
||||
ui.removeListener(this)
|
||||
step.complete(true)
|
||||
}
|
||||
}
|
||||
})
|
||||
true
|
||||
stateCheck {
|
||||
revisionsList?.selectionModel?.selectedIndices?.let { it.size == 1 && it[0] == revisionInd } == true
|
||||
}
|
||||
restoreByUi(invokeMenuTaskId, delayMillis = defaultRestoreDelay)
|
||||
test {
|
||||
ideFrame {
|
||||
Thread.sleep(1000)
|
||||
val table = revisionsTable ?: error("revisionsTable is not initialized")
|
||||
JTableFixture(robot(), table).click(TableCell.row(revisionInd).column(0), MouseButton.LEFT_BUTTON)
|
||||
val list = revisionsList ?: error("revisionsTable is not initialized")
|
||||
JListFixture(robot(), list).clickItem(revisionInd)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -250,7 +222,7 @@ class LocalHistoryLesson(
|
||||
}
|
||||
restoreByUi(invokeMenuTaskId)
|
||||
restoreState(selectRevisionTaskId) l@{
|
||||
val revisions = revisionsTable ?: return@l false
|
||||
val revisions = revisionsList ?: return@l false
|
||||
revisions.selectionModel.selectedIndices.let { it.size != 1 || it[0] != revisionInd }
|
||||
}
|
||||
test {
|
||||
@@ -266,9 +238,7 @@ class LocalHistoryLesson(
|
||||
before { LearningUiHighlightingManager.clearHighlights() }
|
||||
text(LessonsBundle.message("local.history.close.window", action("EditorEscape")))
|
||||
stateCheck {
|
||||
val focusedEditor = focusOwner as? EditorComponentImpl
|
||||
// check that it is editor from main IDE frame
|
||||
focusedEditor != null && UIUtil.getParentOfType(SingleHeightTabs::class.java, focusedEditor) != null
|
||||
isMainEditorComponent(focusOwner)
|
||||
}
|
||||
test {
|
||||
invokeActionViaShortcut("ESCAPE")
|
||||
@@ -285,8 +255,8 @@ class LocalHistoryLesson(
|
||||
override fun onLessonEnd(project: Project, lessonEndInfo: LessonEndInfo) {
|
||||
if (!lessonEndInfo.lessonPassed) return
|
||||
ApplicationManager.getApplication().executeOnPooledThread {
|
||||
val editorComponent = LearningUiUtil.findComponentOrNull(project, EditorComponentImpl::class.java) { editor ->
|
||||
UIUtil.getParentOfType(SingleHeightTabs::class.java, editor) != null
|
||||
val editorComponent = LearningUiUtil.findComponentOrNull(project, EditorComponentImpl::class.java) { component ->
|
||||
isMainEditorComponent(component)
|
||||
} ?: error("Failed to find editor component")
|
||||
invokeLater {
|
||||
val lines = textToDelete.lines()
|
||||
@@ -322,9 +292,8 @@ class LocalHistoryLesson(
|
||||
else null
|
||||
}
|
||||
|
||||
private fun TaskRuntimeContext.checkInsideLocalHistoryFrame(component: Component): Boolean {
|
||||
val frame = UIUtil.getParentOfType(JFrame::class.java, component)
|
||||
return frame?.title == FileUtil.toSystemDependentName(virtualFile.path)
|
||||
private fun isMainEditorComponent(component: Component?): Boolean {
|
||||
return component is EditorComponentImpl && component.editor.editorKind == EditorKind.MAIN_EDITOR
|
||||
}
|
||||
|
||||
// If message is null it will remove the existing hint and allow file modification
|
||||
|
||||
Reference in New Issue
Block a user