diff --git a/python/src/com/jetbrains/commandInterface/console/ArgumentHintLayer.java b/python/src/com/jetbrains/commandInterface/console/ArgumentHintLayer.java index c2760b25e009..9ca6937ce7ee 100644 --- a/python/src/com/jetbrains/commandInterface/console/ArgumentHintLayer.java +++ b/python/src/com/jetbrains/commandInterface/console/ArgumentHintLayer.java @@ -46,7 +46,7 @@ import java.awt.*; */ @SuppressWarnings({"InstanceVariableMayNotBeInitialized", "NonSerializableFieldInSerializableClass", "DeserializableClassInSecureContext", "SerializableClassInSecureContext"}) // Nobody would serialize this class -final class ArgumentHintLayer extends JPanel implements Listener { +final class ArgumentHintLayer extends JPanel implements Listener, Runnable { // Runnable to hide on console state changes /** * Braces for mandatory args are [] according to GNU/POSIX recommendations @@ -114,8 +114,6 @@ final class ArgumentHintLayer extends JPanel implements Listener { myConsole = console; myDocumentLengthInChars = console.getEditorDocument().getTextLength(); myLastText = console.getFile().getText(); - - final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); myRequiredColor = scheme.getAttributes(ConsoleViewContentType.ERROR_OUTPUT_KEY).getForegroundColor(); myOptionalColor = scheme.getAttributes(EditorColors.FOLDED_TEXT_ATTRIBUTES).getForegroundColor(); @@ -190,6 +188,12 @@ final class ArgumentHintLayer extends JPanel implements Listener { return String.format("%s%s%s", braces.first, textToShow, braces.second); } + @Override + public void run() { + // Console state changed! Hide... + myNextArg = null; + repaint(); + } /** * Attaches argument displaying layer to console. Be sure your console has commands. @@ -198,13 +202,14 @@ final class ArgumentHintLayer extends JPanel implements Listener { * @param console console to attach * @throws IllegalArgumentException is passed argument is not {@link CommandLineFile} */ - static void attach(@NotNull final LanguageConsoleImpl console) { + static void attach(@NotNull final CommandConsole console) { final PsiFile consoleFile = console.getFile(); if (!(consoleFile instanceof CommandLineFile)) { throw new IllegalArgumentException( String.format("Passed argument is %s, but has to be %s", consoleFile.getClass(), CommandLineFile.class)); } final ArgumentHintLayer argumentHintLayer = new ArgumentHintLayer(console); + console.addStateChangeListener(argumentHintLayer); final MessageBusConnection connection = console.getProject().getMessageBus().connect(); connection.subscribe(PsiModificationTracker.TOPIC, argumentHintLayer); console.addLayerToPane(argumentHintLayer); diff --git a/python/src/com/jetbrains/commandInterface/console/CommandConsole.java b/python/src/com/jetbrains/commandInterface/console/CommandConsole.java index 40d81a3a1d48..d5626325c827 100644 --- a/python/src/com/jetbrains/commandInterface/console/CommandConsole.java +++ b/python/src/com/jetbrains/commandInterface/console/CommandConsole.java @@ -34,6 +34,8 @@ import com.jetbrains.python.psi.PyUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; /** @@ -80,6 +82,12 @@ final class CommandConsole extends LanguageConsoleImpl implements Consumer myStateChangeListeners = new ArrayList(); + /** * @param module module console runs on * @param title console title @@ -126,6 +134,7 @@ final class CommandConsole extends LanguageConsoleImpl implements ConsumerCalled on EDT + * @param listener listener to notify + */ + void addStateChangeListener(@NotNull final Runnable listener) { + myStateChangeListeners.add(listener); + } + /** * Listens for process to switch between modes diff --git a/python/src/com/jetbrains/commandInterface/console/CommandLineConsoleApi.java b/python/src/com/jetbrains/commandInterface/console/CommandLineConsoleApi.java index cb3268607c3f..b8abb39625c8 100644 --- a/python/src/com/jetbrains/commandInterface/console/CommandLineConsoleApi.java +++ b/python/src/com/jetbrains/commandInterface/console/CommandLineConsoleApi.java @@ -16,7 +16,6 @@ package com.jetbrains.commandInterface.console; import com.intellij.execution.console.LanguageConsoleBuilder; -import com.intellij.execution.console.LanguageConsoleImpl; import com.intellij.execution.console.LanguageConsoleView; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; @@ -72,7 +71,7 @@ public final class CommandLineConsoleApi { final ContentManager contentManager = window.getContentManager(); contentManager.removeAllContents(true); - final LanguageConsoleImpl console = CommandConsole.createConsole(module, consoleName, commandList); + final CommandConsole console = CommandConsole.createConsole(module, consoleName, commandList); final Content content = new ContentImpl(console.getComponent(), "", true);