mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Hide argument hints layer on console mode changes to prevent junk in console for PY-11855
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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<Strin
|
||||
@NotNull
|
||||
private final Object myConsumerSemaphore = new Object();
|
||||
|
||||
/**
|
||||
* Listener that will be notified when console state (mode?) changed.
|
||||
*/
|
||||
@NotNull
|
||||
private final Collection<Runnable> myStateChangeListeners = new ArrayList<Runnable>();
|
||||
|
||||
/**
|
||||
* @param module module console runs on
|
||||
* @param title console title
|
||||
@@ -126,6 +134,7 @@ final class CommandConsole extends LanguageConsoleImpl implements Consumer<Strin
|
||||
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
notifyStateChangeListeners();
|
||||
setLanguage(CommandLineLanguage.INSTANCE);
|
||||
final CommandLineFile file = PyUtil.as(getFile(), CommandLineFile.class);
|
||||
resetConsumer(null);
|
||||
@@ -148,8 +157,8 @@ final class CommandConsole extends LanguageConsoleImpl implements Consumer<Strin
|
||||
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
notifyStateChangeListeners();
|
||||
resetConsumer(new ProcessModeConsumer(processHandler));
|
||||
|
||||
// In process mode we do not need prompt and highlighting
|
||||
setLanguage(PlainTextLanguage.INSTANCE);
|
||||
setPrompt("");
|
||||
@@ -157,6 +166,15 @@ final class CommandConsole extends LanguageConsoleImpl implements Consumer<Strin
|
||||
}, ModalityState.NON_MODAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify listeners that state has been changed
|
||||
*/
|
||||
private void notifyStateChangeListeners() {
|
||||
for (final Runnable listener : myStateChangeListeners) {
|
||||
listener.run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Chooses consumer to delegate execute action to.
|
||||
@@ -188,6 +206,15 @@ final class CommandConsole extends LanguageConsoleImpl implements Consumer<Strin
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds listener that will be notified when console state (mode?) changed.
|
||||
* <strong>Called on EDT</strong>
|
||||
* @param listener listener to notify
|
||||
*/
|
||||
void addStateChangeListener(@NotNull final Runnable listener) {
|
||||
myStateChangeListeners.add(listener);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Listens for process to switch between modes
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user