From fc976bcec2315dc83d7eac2a5e001819d0453b3f Mon Sep 17 00:00:00 2001 From: "Maxim.Kolmakov" Date: Fri, 6 Oct 2017 18:39:30 +0200 Subject: [PATCH] [gui-tests] Make frame not nullable --- .../intellij/testGuiFramework/recorder/Writer.kt | 10 ++++------ .../recorder/actions/ShowGuiEditorWindowAction.kt | 4 ++-- .../recorder/actions/SyncEditorAction.kt | 5 ++--- .../recorder/actions/UpdateEditorAction.kt | 2 +- .../recorder/components/GuiRecorderComponent.kt | 13 +++++++++---- .../testGuiFramework/recorder/ui/GuiScriptEditor.kt | 2 -- .../recorder/ui/GuiScriptEditorFrame.kt | 12 ++++-------- .../recorder/ui/GuiScriptEditorPanel.java | 8 -------- .../testGuiFramework/recorder/ui/Notifier.kt | 3 +-- 9 files changed, 23 insertions(+), 36 deletions(-) diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/Writer.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/Writer.kt index 2b45d14f51d7..0f86a7ba96af 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/Writer.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/Writer.kt @@ -38,18 +38,16 @@ object Writer { private fun write(str: String) { print(str) - if (GuiRecorderComponent.frame != null && GuiRecorderComponent.frame!!.isSyncToEditor()) + if (GuiRecorderComponent.syncEditor) writeToEditor(str) else scriptBuffer.append(str) } private fun writeToEditor(str: String) { - if (GuiRecorderComponent.frame != null && GuiRecorderComponent.frame!!.getEditor() != null) { - val editor = GuiRecorderComponent.frame!!.getEditor() - val document = editor.document - WriteCommandAction.runWriteCommandAction(null, { document.insertString(document.textLength, str) }) - } + val editor = GuiRecorderComponent.frame.getEditor() + val document = editor.document + WriteCommandAction.runWriteCommandAction(null, { document.insertString(document.textLength, str) }) } fun writeWithIndent(code: String){ diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/ShowGuiEditorWindowAction.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/ShowGuiEditorWindowAction.kt index e2f2c64800d4..64f162f03e14 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/ShowGuiEditorWindowAction.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/ShowGuiEditorWindowAction.kt @@ -27,8 +27,8 @@ class ShowGuiEditorWindowAction() : AnAction() { override fun actionPerformed(p0: AnActionEvent?) { val frame = GuiRecorderComponent.frame - if (frame == null) { - GuiScriptEditorFrame() + if (!frame.isShowing()) { + frame.show() } else { frame.toFront() diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/SyncEditorAction.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/SyncEditorAction.kt index 28007dad8848..1870bc78bed6 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/SyncEditorAction.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/SyncEditorAction.kt @@ -26,11 +26,10 @@ import com.intellij.testGuiFramework.recorder.ui.Notifier */ class SyncEditorAction : ToggleAction(null, "Synchronize Editor with Generated GUI Script", AllIcons.Actions.Refresh) { - override fun isSelected(e: AnActionEvent?): Boolean = if (GuiRecorderComponent.frame != null) GuiRecorderComponent.frame!!.isSyncToEditor() else false + override fun isSelected(e: AnActionEvent?): Boolean = GuiRecorderComponent.syncEditor override fun setSelected(e: AnActionEvent?, toSync: Boolean) { - val frame = GuiRecorderComponent.frame ?: return - frame.setSyncToEditor(toSync) + GuiRecorderComponent.syncEditor = toSync if (toSync) Notifier.updateStatus("Synchronization is on") else diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/UpdateEditorAction.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/UpdateEditorAction.kt index 35493ef2532f..39b67a92b3b9 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/UpdateEditorAction.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/actions/UpdateEditorAction.kt @@ -14,7 +14,7 @@ import com.intellij.testGuiFramework.recorder.ui.Notifier class UpdateEditorAction : AnAction(null, "Update GUI Script Editor (get recorded from buffer)", AllIcons.Actions.NextOccurence) { override fun actionPerformed(actionEvent: AnActionEvent?) { - val editor = GuiRecorderComponent.frame!!.getEditor() + val editor = GuiRecorderComponent.frame.getEditor() ApplicationManager.getApplication().runWriteAction { editor.document.setText(getGuiScriptBuffer()) } Notifier.updateStatus("GUI script updated") } diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/components/GuiRecorderComponent.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/components/GuiRecorderComponent.kt index 8c5e54966a9c..e744c060c06b 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/components/GuiRecorderComponent.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/components/GuiRecorderComponent.kt @@ -29,12 +29,17 @@ object GuiRecorderComponent : ApplicationComponent, Disposable { enum class States {IDLE, COMPILING, COMPILATION_ERROR, COMPILATION_DONE, RUNNING, RUNNING_ERROR, TEST_INIT } var state: States = States.IDLE - var frame: GuiScriptEditorFrame? = null + lateinit var frame: GuiScriptEditorFrame var currentTask: Future<*>? = null + //let editor be synchronised by default + var syncEditor = true + + override fun initComponent() { + frame = GuiScriptEditorFrame() + } override fun dispose() { - frame?.dispose() - frame = null + frame.dispose() } override fun getComponentName() = "GuiRecorderComponent" @@ -43,7 +48,7 @@ object GuiRecorderComponent : ApplicationComponent, Disposable { if (currentTask != null && !currentTask!!.isDone) currentTask!!.cancel(true) } - fun getEditor() = frame!!.getGuiScriptEditorPanel().editor + fun getEditor() = frame.getGuiScriptEditorPanel().editor fun placeCaretToEnd() { val caretModel = getEditor().caretModel diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/GuiScriptEditor.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/GuiScriptEditor.kt index c73b60675ec6..18b9537eee32 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/GuiScriptEditor.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/GuiScriptEditor.kt @@ -32,8 +32,6 @@ import kotlin.with class GuiScriptEditor { val myEditor: EditorEx - //let editor be synchronised by default - var syncEditor = true fun getPanel() = myEditor.component diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/GuiScriptEditorFrame.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/GuiScriptEditorFrame.kt index 035a0c02b321..87fbb37490e6 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/GuiScriptEditorFrame.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/GuiScriptEditorFrame.kt @@ -49,15 +49,17 @@ class GuiScriptEditorFrame : Disposable { myFrame.contentPane = myContentPanel myFrame.pack() - myFrame.isVisible = true - GuiRecorderComponent.frame = this myFrame.addWindowListener(object : WindowAdapter() { override fun windowClosing(e: WindowEvent?) { dispose() } }) + } + fun isShowing() = myFrame.isShowing + fun show() { + myFrame.isVisible = true val recAction = StartPauseRecAction() recAction.setSelected(null, true) } @@ -69,10 +71,4 @@ class GuiScriptEditorFrame : Disposable { fun getGuiScriptEditorPanel() = guiScriptEditorPanel fun getEditor() = guiScriptEditorPanel.editor - - fun setSyncToEditor(toSync: Boolean) { - guiScriptEditorPanel.syncToEditor = toSync - } - - fun isSyncToEditor() = guiScriptEditorPanel.syncToEditor } diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/GuiScriptEditorPanel.java b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/GuiScriptEditorPanel.java index c5995d899b27..538dd926935a 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/GuiScriptEditorPanel.java +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/GuiScriptEditorPanel.java @@ -114,18 +114,10 @@ public class GuiScriptEditorPanel { progressIcon = new AsyncProcessIcon("Progress"); } - public boolean getSyncToEditor() { - return myEditor.getSyncEditor(); - } private class MyTextPanel extends TextPanel { MyTextPanel(){ super(); } } - - public void setSyncToEditor(boolean toSync){ - myEditor.setSyncEditor(toSync); - } - } diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/Notifier.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/Notifier.kt index 6cd780b4bbe2..3efa86bff256 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/Notifier.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/recorder/ui/Notifier.kt @@ -27,8 +27,7 @@ object Notifier { fun updateStatus(statusMessage: String) { - if (GuiRecorderComponent.frame == null) return - val guiScriptEditorPanel = GuiRecorderComponent.frame!!.getGuiScriptEditorPanel() + val guiScriptEditorPanel = GuiRecorderComponent.frame.getGuiScriptEditorPanel() val statusHandler: (String) -> Unit = { status -> if (status.startsWith(LONG_OPERATION_PREFIX)) {