From b9c465ec9e185188bd5e6aa8f2f5c0433d04f3d3 Mon Sep 17 00:00:00 2001 From: Viktor Shatrov Date: Mon, 24 Sep 2018 12:10:37 +0300 Subject: [PATCH 1/9] WebConsole: init --- .../intellij/execution/impl/TokenBuffer.java | 26 +++++++++---------- .../util/resources/misc/registry.properties | 1 + 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/impl/TokenBuffer.java b/platform/lang-impl/src/com/intellij/execution/impl/TokenBuffer.java index 3584e9f04341..fd4a43e70fd9 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/TokenBuffer.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/TokenBuffer.java @@ -33,7 +33,7 @@ import java.util.stream.Collectors; * Add token via {@link #print(String, ConsoleViewContentType, HyperlinkInfo)} * Get all tokens via {@link #drain()} */ -class TokenBuffer { +public class TokenBuffer { // special token which means that the deferred text starts with "\r" so it shouldn't be appended to the document end. // Instead, the last line of the document should be removed static final TokenInfo CR_TOKEN = new TokenInfo(ConsoleViewContentType.SYSTEM_OUTPUT, "\r", null); @@ -42,11 +42,11 @@ class TokenBuffer { private int size; // total lengths of all tokens private int startIndex; // index of text start in the first TokeInfo. This TokenInfo can become sliced after total size overflows maxCapacity - TokenBuffer(int maxCapacity) { + public TokenBuffer(int maxCapacity) { this.maxCapacity = maxCapacity; } - void print(@NotNull String text, @NotNull ConsoleViewContentType contentType, @Nullable HyperlinkInfo info) { + public void print(@NotNull String text, @NotNull ConsoleViewContentType contentType, @Nullable HyperlinkInfo info) { int start = 0; while (start < text.length()) { if (hasTrailingCR()) { @@ -134,18 +134,18 @@ class TokenBuffer { //assert tokens.toList().stream().mapToInt(TokenInfo::length).sum() == size; } - int length() { + public int length() { return size - startIndex; } - void clear() { + public void clear() { tokens.clear(); startIndex = 0; size = 0; } @NotNull - CharSequence getText() { + public CharSequence getText() { if (hasTrailingCR()) { removeLastLine(); } @@ -156,7 +156,7 @@ class TokenBuffer { // the first token may be CR_TOKEN meaning that instead of appending it we should delete the last line of the document // all the remaining text is guaranteed not to contain CR_TOKEN - they can be appended safely to the document end @NotNull - List drain() { + public List drain() { if (hasTrailingCR()) { removeLastLine(); } @@ -180,17 +180,17 @@ class TokenBuffer { return list; } - int getCycleBufferSize() { + public int getCycleBufferSize() { return maxCapacity; } - static class TokenInfo { + public static class TokenInfo { @NotNull final ConsoleViewContentType contentType; private final String text; private final HyperlinkInfo myHyperlinkInfo; - TokenInfo(@NotNull ConsoleViewContentType contentType, + public TokenInfo(@NotNull ConsoleViewContentType contentType, @NotNull String text, @Nullable HyperlinkInfo hyperlinkInfo) { this.contentType = contentType; @@ -198,7 +198,7 @@ class TokenBuffer { this.text = text; } - int length() { + public int length() { return text.length(); } @@ -207,12 +207,12 @@ class TokenBuffer { return contentType + "[" + length() + "]"; } - HyperlinkInfo getHyperlinkInfo() { + public HyperlinkInfo getHyperlinkInfo() { return myHyperlinkInfo; } @NotNull - String getText() { + public String getText() { return text; } } diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index d5a8fb62a41c..06c1035b4714 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -978,6 +978,7 @@ js.debugger.break.on.first.statement=false js.debugger.break.on.first.statement.description=Puts instrumentation breakpoint on first statement of each script. js.debugger.break.on.first.statement.with.regexp=false js.debugger.break.on.first.statement.with.regexp.description=Puts regexp breakpoint on first statement of each script. +js.debugger.webconsole=false nodejs.core.library.use.typings=false nodejs.core.library.use.typings.description=Enables using @types/node for Node.js coding assistance in "Node.js Core" library From 340c3a553c58ffe5e5c81a861ead45b2ab1d133a Mon Sep 17 00:00:00 2001 From: Viktor Shatrov Date: Tue, 2 Oct 2018 16:05:05 +0300 Subject: [PATCH 2/9] WebConsole: - block creation --- .../lang-impl/src/com/intellij/execution/impl/TokenBuffer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/execution/impl/TokenBuffer.java b/platform/lang-impl/src/com/intellij/execution/impl/TokenBuffer.java index fd4a43e70fd9..6183aec229cc 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/TokenBuffer.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/TokenBuffer.java @@ -186,7 +186,7 @@ public class TokenBuffer { public static class TokenInfo { @NotNull - final ConsoleViewContentType contentType; + public final ConsoleViewContentType contentType; private final String text; private final HyperlinkInfo myHyperlinkInfo; From 2bd18d2fefca1e6c2ca0b9e8b9bb4c38cd70d4e9 Mon Sep 17 00:00:00 2001 From: Viktor Shatrov Date: Wed, 3 Oct 2018 12:15:47 +0300 Subject: [PATCH 3/9] WebConsole: Extract ConsoleEditor from LanguageConsoleImpl --- .../execution/console/ConsoleEditor.java | 215 ++++++++++++++++++ .../console/LanguageConsoleImpl.java | 171 +++----------- 2 files changed, 252 insertions(+), 134 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/execution/console/ConsoleEditor.java diff --git a/platform/lang-impl/src/com/intellij/execution/console/ConsoleEditor.java b/platform/lang-impl/src/com/intellij/execution/console/ConsoleEditor.java new file mode 100644 index 000000000000..be96bf5093b0 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/execution/console/ConsoleEditor.java @@ -0,0 +1,215 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.execution.console; + +import com.intellij.execution.ui.ConsoleViewContentType; +import com.intellij.ide.GeneralSettings; +import com.intellij.openapi.Disposable; +import com.intellij.openapi.actionSystem.EmptyAction; +import com.intellij.openapi.actionSystem.IdeActions; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.TransactionGuard; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.EditorFactory; +import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.openapi.editor.ex.FocusChangeListener; +import com.intellij.openapi.editor.highlighter.EditorHighlighterFactory; +import com.intellij.openapi.fileEditor.*; +import com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.DocumentUtil; +import com.intellij.util.ObjectUtils; +import com.intellij.util.messages.MessageBusConnection; +import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +public class ConsoleEditor implements Disposable { + private final EditorEx myConsoleEditor; + private EditorEx myCurrentEditor; + private final Document myEditorDocument; + private final LanguageConsoleImpl.Helper myHelper; + private final MessageBusConnection myBusConnection; + + @Nullable + private String myPrompt = "> "; + @NotNull + private ConsoleViewContentType myPromptAttributes = ConsoleViewContentType.USER_INPUT; + + public ConsoleEditor(@NotNull LanguageConsoleImpl.Helper helper) { + myHelper = helper; + EditorFactory editorFactory = EditorFactory.getInstance(); + myEditorDocument = helper.getDocument(); + myConsoleEditor = (EditorEx)editorFactory.createEditor(myEditorDocument, helper.project); + myConsoleEditor.getScrollPane().getHorizontalScrollBar().setEnabled(false); + myConsoleEditor.addFocusListener(myFocusListener); + myConsoleEditor.getSettings().setVirtualSpace(false); + myCurrentEditor = myConsoleEditor; + + myBusConnection = getProject().getMessageBus().connect(); + // action shortcuts are not yet registered + ApplicationManager.getApplication().invokeLater(() -> installEditorFactoryListener(), getProject().getDisposed()); + } + + private final FocusChangeListener myFocusListener = new FocusChangeListener() { + @Override + public void focusGained(@NotNull Editor editor) { + myCurrentEditor = (EditorEx)editor; + if (GeneralSettings.getInstance().isSaveOnFrameDeactivation()) { + TransactionGuard.submitTransaction(ConsoleEditor.this, () -> FileDocumentManager.getInstance().saveAllDocuments()); // PY-12487 + } + } + + @Override + public void focusLost(@NotNull Editor editor) { + } + }; + + public void initComponent() { + myConsoleEditor.setContextMenuGroupId(IdeActions.GROUP_CONSOLE_EDITOR_POPUP); + myConsoleEditor.setHighlighter( + EditorHighlighterFactory.getInstance().createEditorHighlighter(getVirtualFile(), myConsoleEditor.getColorsScheme(), getProject())); + setPromptInner(myPrompt); + } + + @NotNull + public final VirtualFile getVirtualFile() { + return myHelper.virtualFile; + } + + public EditorEx getEditor() { + return myConsoleEditor; + } + + @NotNull + public EditorEx getCurrentEditor() { + return ObjectUtils.notNull(myCurrentEditor, myConsoleEditor); + } + + public Document getDocument() { + return myEditorDocument; + } + + public JComponent getComponent() { + return myConsoleEditor.getComponent(); + } + + public void setConsoleEditorEnabled(boolean consoleEditorEnabled) { + if (isConsoleEditorEnabled() == consoleEditorEnabled) { + return; + } + if (consoleEditorEnabled) { + FileEditorManager.getInstance(getProject()).closeFile(getVirtualFile()); + myCurrentEditor = myConsoleEditor; + } + myConsoleEditor.getComponent().setVisible(consoleEditorEnabled); + } + + private Project getProject() { + return myHelper.project; + } + + public final boolean isConsoleEditorEnabled() { + return myConsoleEditor.getComponent().isVisible(); + } + + @Nullable + public String getPrompt() { + return myPrompt; + } + + @NotNull + public ConsoleViewContentType getPromptAttributes() { + return myPromptAttributes; + } + + public void setPromptAttributes(@NotNull ConsoleViewContentType textAttributes) { + myPromptAttributes = textAttributes; + } + + public void setPrompt(@Nullable String prompt) { + // always add space to the prompt otherwise it may look ugly + myPrompt = prompt != null && !prompt.endsWith(" ") ? prompt + " " : prompt; + setPromptInner(myPrompt); + } + + + public void setEditable(boolean editable) { + myConsoleEditor.setRendererMode(!editable); + setPromptInner(editable ? myPrompt : ""); + } + + public boolean isEditable() { + return !myConsoleEditor.isRendererMode(); + } + + + private void setPromptInner(@Nullable final String prompt) { + UIUtil.invokeAndWaitIfNeeded((Runnable)() -> { + if (!myConsoleEditor.isDisposed()) { + myConsoleEditor.setPrefixTextAndAttributes(prompt, myPromptAttributes.getAttributes()); + } + }); + } + + private void installEditorFactoryListener() { + FileEditorManagerListener fileEditorListener = new FileEditorManagerListener() { + @Override + public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) { + if (myConsoleEditor == null || !Comparing.equal(file, getVirtualFile())) { + return; + } + + Editor selectedTextEditor = source.getSelectedTextEditor(); + for (FileEditor fileEditor : source.getAllEditors(file)) { + if (!(fileEditor instanceof TextEditor)) { + continue; + } + + final EditorEx editor = (EditorEx)((TextEditor)fileEditor).getEditor(); + editor.addFocusListener(myFocusListener); + if (selectedTextEditor == editor) { // already focused + myCurrentEditor = editor; + } + EmptyAction.registerActionShortcuts(editor.getComponent(), myConsoleEditor.getComponent()); + } + } + + @Override + public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) { + if (!Comparing.equal(file, getVirtualFile())) { + return; + } + if (!Boolean.TRUE.equals(file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN))) { + if (myCurrentEditor != null && myCurrentEditor.isDisposed()) { + myCurrentEditor = null; + } + } + } + }; + myBusConnection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, fileEditorListener); + FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); + if (editorManager.isFileOpen(getVirtualFile())) { + fileEditorListener.fileOpened(editorManager, getVirtualFile()); + } + } + + @Override + public void dispose() { + myBusConnection.deliverImmediately(); + Disposer.dispose(myBusConnection); + EditorFactory editorFactory = EditorFactory.getInstance(); + editorFactory.releaseEditor(myConsoleEditor); + + } + + public void setInputText(@NotNull final String query) { + DocumentUtil.writeInRunUndoTransparentAction(() -> myConsoleEditor.getDocument().setText(StringUtil.convertLineSeparators(query))); + } +} diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java index 9a879a4b75b3..851032bca133 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java @@ -5,37 +5,31 @@ import com.intellij.execution.impl.ConsoleViewImpl; import com.intellij.execution.impl.ConsoleViewUtil; import com.intellij.execution.ui.ConsoleViewContentType; import com.intellij.ide.DataManager; -import com.intellij.ide.GeneralSettings; import com.intellij.ide.highlighter.HighlighterFactory; import com.intellij.injected.editor.EditorWindow; import com.intellij.lang.Language; import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.actionSystem.EmptyAction; -import com.intellij.openapi.actionSystem.IdeActions; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ReadAction; -import com.intellij.openapi.application.TransactionGuard; import com.intellij.openapi.command.undo.UndoUtil; import com.intellij.openapi.editor.*; import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.event.DocumentEvent; import com.intellij.openapi.editor.event.DocumentListener; import com.intellij.openapi.editor.ex.EditorEx; -import com.intellij.openapi.editor.ex.FocusChangeListener; import com.intellij.openapi.editor.ex.util.EditorUtil; import com.intellij.openapi.editor.ex.util.LexerEditorHighlighter; import com.intellij.openapi.editor.highlighter.EditorHighlighter; -import com.intellij.openapi.editor.highlighter.EditorHighlighterFactory; import com.intellij.openapi.editor.impl.EditorFactoryImpl; -import com.intellij.openapi.fileEditor.*; +import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.fileEditor.FileEditorManager; +import com.intellij.openapi.fileEditor.OpenFileDescriptor; import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx; -import com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl; import com.intellij.openapi.fileTypes.SyntaxHighlighter; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.TextRange; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.psi.PsiFile; @@ -47,8 +41,6 @@ import com.intellij.ui.components.JBScrollBar; import com.intellij.ui.components.JBScrollPane.Alignment; import com.intellij.util.DocumentUtil; import com.intellij.util.FileContentUtil; -import com.intellij.util.ObjectUtils; -import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.ui.AbstractLayoutManager; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; @@ -69,10 +61,8 @@ import java.util.Collections; public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageConsoleView, DataProvider { private final Helper myHelper; - private final EditorEx myConsoleEditor; + private final ConsoleEditor myConsoleEditor; private final EditorEx myHistoryViewer; - private final Document myEditorDocument; - private final JPanel myPanel = new JPanel(new MyLayout()); private final JScrollBar myScrollBar = new JBScrollBar(Adjustable.HORIZONTAL); private final DocumentListener myDocumentAdapter = new DocumentListener() { @@ -82,27 +72,6 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons } }; - @Nullable - private String myPrompt = "> "; - private ConsoleViewContentType myPromptAttributes = ConsoleViewContentType.USER_INPUT; - - private EditorEx myCurrentEditor; - - private final MessageBusConnection myBusConnection; - private final FocusChangeListener myFocusListener = new FocusChangeListener() { - @Override - public void focusGained(@NotNull Editor editor) { - myCurrentEditor = (EditorEx)editor; - if (GeneralSettings.getInstance().isSaveOnFrameDeactivation()) { - TransactionGuard.submitTransaction(LanguageConsoleImpl.this, () -> FileDocumentManager.getInstance().saveAllDocuments()); // PY-12487 - } - } - - @Override - public void focusLost(@NotNull Editor editor) { - } - }; - public LanguageConsoleImpl(@NotNull Project project, @NotNull String title, @NotNull Language language) { this(new Helper(project, new LightVirtualFile(title, language, ""))); } @@ -115,24 +84,15 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons super(helper.project, GlobalSearchScope.allScope(helper.project), true, true); myHelper = helper; EditorFactory editorFactory = EditorFactory.getInstance(); - myEditorDocument = helper.getDocument(); - myConsoleEditor = (EditorEx)editorFactory.createEditor(myEditorDocument, getProject()); - myConsoleEditor.getDocument().addDocumentListener(myDocumentAdapter); - myConsoleEditor.getScrollPane().getHorizontalScrollBar().setEnabled(false); - myConsoleEditor.addFocusListener(myFocusListener); - myConsoleEditor.getSettings().setVirtualSpace(false); - myCurrentEditor = myConsoleEditor; + myConsoleEditor = new ConsoleEditor(helper); + Document historyDocument = ((EditorFactoryImpl)editorFactory).createDocument(true); UndoUtil.disableUndoFor(historyDocument); myHistoryViewer = (EditorEx)editorFactory.createViewer(historyDocument, getProject(), EditorKind.CONSOLE); myHistoryViewer.getDocument().addDocumentListener(myDocumentAdapter); - - myScrollBar.setModel(new MyModel(myScrollBar, myHistoryViewer, myConsoleEditor)); + myConsoleEditor.getDocument().addDocumentListener(myDocumentAdapter); + myScrollBar.setModel(new MyModel(myScrollBar, myHistoryViewer, myConsoleEditor.getEditor())); myScrollBar.putClientProperty(Alignment.class, Alignment.BOTTOM); - - myBusConnection = getProject().getMessageBus().connect(); - // action shortcuts are not yet registered - ApplicationManager.getApplication().invokeLater(() -> installEditorFactoryListener(), getProject().getDisposed()); } @NotNull @@ -163,10 +123,8 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons myPanel.add(myHistoryViewer.getComponent()); myPanel.add(myConsoleEditor.getComponent()); myPanel.add(myScrollBar); - myPanel.setBackground(myConsoleEditor.getBackgroundColor()); - + myPanel.setBackground(myConsoleEditor.getEditor().getBackgroundColor()); DataManager.registerDataProvider(myPanel, this); - setPromptInner(myPrompt); } @Override @@ -174,13 +132,9 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons if (isConsoleEditorEnabled() == consoleEditorEnabled) { return; } - if (consoleEditorEnabled) { - FileEditorManager.getInstance(getProject()).closeFile(getVirtualFile()); - myCurrentEditor = myConsoleEditor; - } + myConsoleEditor.setConsoleEditorEnabled(consoleEditorEnabled); setHistoryScrollBarVisible(!consoleEditorEnabled); myScrollBar.setVisible(consoleEditorEnabled); - myConsoleEditor.getComponent().setVisible(consoleEditorEnabled); } private void setHistoryScrollBarVisible(boolean visible) { @@ -189,16 +143,15 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons } private void setupComponents() { - myHelper.setupEditor(myConsoleEditor); + myHelper.setupEditor(myConsoleEditor.getEditor()); myHelper.setupEditor(myHistoryViewer); myHistoryViewer.getComponent().setMinimumSize(JBUI.emptySize()); myHistoryViewer.getComponent().setPreferredSize(JBUI.emptySize()); myHistoryViewer.setCaretEnabled(false); - myConsoleEditor.setContextMenuGroupId(IdeActions.GROUP_CONSOLE_EDITOR_POPUP); - myConsoleEditor.setHighlighter( - EditorHighlighterFactory.getInstance().createEditorHighlighter(getVirtualFile(), myConsoleEditor.getColorsScheme(), getProject())); + myConsoleEditor.initComponent(); + Disposer.register(this, myConsoleEditor); setHistoryScrollBarVisible(false); @@ -206,8 +159,10 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons @Override public void keyTyped(KeyEvent event) { if (isConsoleEditorEnabled() && UIUtil.isReallyTypedEvent(event)) { - IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(myConsoleEditor.getContentComponent(), true)); - myConsoleEditor.processKeyTyped(event); + IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown( + () -> IdeFocusManager.getGlobalInstance().requestFocus(myConsoleEditor.getEditor().getContentComponent(), true) + ); + myConsoleEditor.getEditor().processKeyTyped(event); } } }); @@ -217,50 +172,39 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons @Override public final boolean isConsoleEditorEnabled() { - return myConsoleEditor.getComponent().isVisible(); + return myConsoleEditor.isConsoleEditorEnabled(); } @Override @Nullable public String getPrompt() { - return myPrompt; + return myConsoleEditor.getPrompt(); } @Override @Nullable public ConsoleViewContentType getPromptAttributes() { - return myPromptAttributes; + return myConsoleEditor.getPromptAttributes(); } @Override public void setPromptAttributes(@NotNull ConsoleViewContentType textAttributes) { - myPromptAttributes = textAttributes; + myConsoleEditor.setPromptAttributes(textAttributes); } @Override public void setPrompt(@Nullable String prompt) { - // always add space to the prompt otherwise it may look ugly - myPrompt = prompt != null && !prompt.endsWith(" ") ? prompt + " " : prompt; - setPromptInner(myPrompt); - } - - private void setPromptInner(@Nullable final String prompt) { - UIUtil.invokeAndWaitIfNeeded((Runnable)() -> { - if (!myConsoleEditor.isDisposed()) { - myConsoleEditor.setPrefixTextAndAttributes(prompt, myPromptAttributes.getAttributes()); - } - }); + myConsoleEditor.setPrompt(prompt); } @Override public void setEditable(boolean editable) { - myConsoleEditor.setRendererMode(!editable); - setPromptInner(editable ? myPrompt : ""); + myConsoleEditor.setEditable(editable); } @Override public boolean isEditable() { - return !myConsoleEditor.isRendererMode(); + return myConsoleEditor.isEditable(); } @Override @@ -272,7 +216,7 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons @Override @NotNull public final VirtualFile getVirtualFile() { - return myHelper.virtualFile; + return myConsoleEditor.getVirtualFile(); } @Override @@ -284,13 +228,13 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons @Override @NotNull public final Document getEditorDocument() { - return myEditorDocument; + return myConsoleEditor.getDocument(); } @Override @NotNull public final EditorEx getConsoleEditor() { - return myConsoleEditor; + return myConsoleEditor.getEditor(); } @Override @@ -382,8 +326,8 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons } protected void doAddPromptToHistory() { - if (myPrompt != null) { - print(myPrompt, myPromptAttributes); + if (myConsoleEditor.getPrompt() != null) { + print(myConsoleEditor.getPrompt(), myConsoleEditor.getPromptAttributes()); } } @@ -424,11 +368,7 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons myConsoleEditor.getDocument().removeDocumentListener(myDocumentAdapter); myHistoryViewer.getDocument().removeDocumentListener(myDocumentAdapter); - myBusConnection.deliverImmediately(); - Disposer.dispose(myBusConnection); - EditorFactory editorFactory = EditorFactory.getInstance(); - editorFactory.releaseEditor(myConsoleEditor); editorFactory.releaseEditor(myHistoryViewer); if (getProject().isOpen()) { @@ -445,52 +385,11 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons return super.getData(dataId); } - private void installEditorFactoryListener() { - FileEditorManagerListener fileEditorListener = new FileEditorManagerListener() { - @Override - public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) { - if (myConsoleEditor == null || !Comparing.equal(file, getVirtualFile())) { - return; - } - - Editor selectedTextEditor = source.getSelectedTextEditor(); - for (FileEditor fileEditor : source.getAllEditors(file)) { - if (!(fileEditor instanceof TextEditor)) { - continue; - } - - final EditorEx editor = (EditorEx)((TextEditor)fileEditor).getEditor(); - editor.addFocusListener(myFocusListener); - if (selectedTextEditor == editor) { // already focused - myCurrentEditor = editor; - } - EmptyAction.registerActionShortcuts(editor.getComponent(), myConsoleEditor.getComponent()); - } - } - - @Override - public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) { - if (!Comparing.equal(file, getVirtualFile())) { - return; - } - if (!Boolean.TRUE.equals(file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN))) { - if (myCurrentEditor != null && myCurrentEditor.isDisposed()) { - myCurrentEditor = null; - } - } - } - }; - myBusConnection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, fileEditorListener); - FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); - if (editorManager.isFileOpen(getVirtualFile())) { - fileEditorListener.fileOpened(editorManager, getVirtualFile()); - } - } @Override @NotNull public EditorEx getCurrentEditor() { - return ObjectUtils.notNull(myCurrentEditor, myConsoleEditor); + return myConsoleEditor.getCurrentEditor(); } @Override @@ -507,7 +406,7 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons @Override public void setInputText(@NotNull final String query) { - DocumentUtil.writeInRunUndoTransparentAction(() -> myConsoleEditor.getDocument().setText(StringUtil.convertLineSeparators(query))); + myConsoleEditor.setInputText(query); } boolean isHistoryViewerForceAdditionalColumnsUsage() { @@ -530,6 +429,10 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons title = virtualFile.getName(); } + public String getTitle() { + return this.title; + } + public Helper setTitle(String title) { this.title = title; return this; @@ -576,7 +479,7 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons } @NotNull - PsiFile getFileSafe() { + public PsiFile getFileSafe() { return file == null || !file.isValid() ? file = getFile() : file; } @@ -607,7 +510,7 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons } final EditorEx history = myHistoryViewer; - final EditorEx input = isConsoleEditorEnabled() ? myConsoleEditor : null; + final EditorEx input = isConsoleEditorEnabled() ? myConsoleEditor.getEditor() : null; if (input == null) { parent.getComponent(0).setBounds(parent.getBounds()); return; From 0c48a62b264aeb68eaa72e401e0171074b8baeb0 Mon Sep 17 00:00:00 2001 From: Viktor Shatrov Date: Thu, 4 Oct 2018 19:01:19 +0300 Subject: [PATCH 4/9] WebConsole: execution --- .../com/intellij/ui/javafx/KeyEventHandler.kt | 303 ++++++++++++++++++ 1 file changed, 303 insertions(+) create mode 100644 platform/platform-impl/src/com/intellij/ui/javafx/KeyEventHandler.kt diff --git a/platform/platform-impl/src/com/intellij/ui/javafx/KeyEventHandler.kt b/platform/platform-impl/src/com/intellij/ui/javafx/KeyEventHandler.kt new file mode 100644 index 000000000000..e456335c6462 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ui/javafx/KeyEventHandler.kt @@ -0,0 +1,303 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.ui.javafx + +import com.intellij.ui.AppUIUtil +import javafx.event.EventHandler +import javafx.event.EventType +import javafx.scene.input.KeyCode +import javafx.scene.input.KeyEvent +import java.awt.KeyboardFocusManager +import java.awt.event.KeyListener +import java.awt.event.MouseEvent +import java.util.* + + +class KeyEventHandler(private val awtListener: KeyListener) : EventHandler { + + companion object { + private val keyEventMap: Map, Int> + + init { + val map = HashMap, Int>() + map[javafx.scene.input.KeyEvent.KEY_PRESSED] = java.awt.event.KeyEvent.KEY_PRESSED + map[javafx.scene.input.KeyEvent.KEY_RELEASED] = java.awt.event.KeyEvent.KEY_RELEASED + map[javafx.scene.input.KeyEvent.KEY_TYPED] = java.awt.event.KeyEvent.KEY_TYPED + keyEventMap = Collections.unmodifiableMap(map) + } + } + + override fun handle(ke: javafx.scene.input.KeyEvent) { + val focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().focusOwner ?: return + + val id = getKeyEventId(ke) + val time = System.currentTimeMillis() + val mods = getAWTModifiers(ke) + val keyCode = getAWTKeyCode(ke) + val keyChar = if (!ke.character.isEmpty()) + ke.character[0] + else + java.awt.event.KeyEvent.CHAR_UNDEFINED + if (id == java.awt.event.KeyEvent.KEY_TYPED && keyChar == java.awt.event.KeyEvent.CHAR_UNDEFINED) { + return + } + + val kp = java.awt.event.KeyEvent(focusOwner, id, time, mods, keyCode, keyChar) + AppUIUtil.invokeOnEdt { + when (id) { + java.awt.event.KeyEvent.KEY_PRESSED -> awtListener.keyPressed(kp) + java.awt.event.KeyEvent.KEY_RELEASED -> awtListener.keyReleased(kp) + java.awt.event.KeyEvent.KEY_TYPED -> awtListener.keyTyped(kp) + } + } + } + + private fun getKeyEventId(ke: javafx.scene.input.KeyEvent): Int { + return keyEventMap[ke.eventType]!! + } + + private fun getAWTModifiers(jfxKeyEvent: javafx.scene.input.KeyEvent): Int { + var mods = 0 + if (jfxKeyEvent.isAltDown) { + mods = mods or (MouseEvent.ALT_MASK or MouseEvent.ALT_DOWN_MASK) + } + if (jfxKeyEvent.isControlDown) { + mods = mods or (MouseEvent.CTRL_MASK or MouseEvent.CTRL_DOWN_MASK) + } + if (jfxKeyEvent.isShiftDown) { + mods = mods or (MouseEvent.SHIFT_MASK or MouseEvent.SHIFT_DOWN_MASK) + } + if (jfxKeyEvent.isMetaDown) { + mods = mods or (MouseEvent.META_MASK or MouseEvent.META_DOWN_MASK) + } + return mods + } + + private fun getAWTKeyCode(jfxKeyEvent: javafx.scene.input.KeyEvent): Int { + return when (jfxKeyEvent.code) { + KeyCode.A -> java.awt.event.KeyEvent.VK_A + KeyCode.ACCEPT -> java.awt.event.KeyEvent.VK_ACCEPT + KeyCode.ADD -> java.awt.event.KeyEvent.VK_ADD + KeyCode.AGAIN -> java.awt.event.KeyEvent.VK_AGAIN + KeyCode.ALL_CANDIDATES -> java.awt.event.KeyEvent.VK_ALL_CANDIDATES + KeyCode.ALPHANUMERIC -> java.awt.event.KeyEvent.VK_ALPHANUMERIC + KeyCode.ALT -> java.awt.event.KeyEvent.VK_ALT + KeyCode.ALT_GRAPH -> java.awt.event.KeyEvent.VK_ALT_GRAPH + KeyCode.AMPERSAND -> java.awt.event.KeyEvent.VK_AMPERSAND + KeyCode.ASTERISK -> java.awt.event.KeyEvent.VK_ASTERISK + KeyCode.AT -> java.awt.event.KeyEvent.VK_AT + KeyCode.B -> java.awt.event.KeyEvent.VK_B + KeyCode.BACK_QUOTE -> java.awt.event.KeyEvent.VK_BACK_QUOTE + KeyCode.BACK_SLASH -> java.awt.event.KeyEvent.VK_BACK_SLASH + KeyCode.BACK_SPACE -> java.awt.event.KeyEvent.VK_BACK_SPACE + KeyCode.BEGIN -> java.awt.event.KeyEvent.VK_BEGIN + KeyCode.BRACELEFT -> java.awt.event.KeyEvent.VK_BRACELEFT + KeyCode.BRACERIGHT -> java.awt.event.KeyEvent.VK_BRACERIGHT + KeyCode.C -> java.awt.event.KeyEvent.VK_C + KeyCode.CANCEL -> java.awt.event.KeyEvent.VK_CANCEL + KeyCode.CAPS -> java.awt.event.KeyEvent.VK_CAPS_LOCK + KeyCode.CHANNEL_DOWN -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.CHANNEL_UP -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.CIRCUMFLEX -> java.awt.event.KeyEvent.VK_CIRCUMFLEX + KeyCode.CLEAR -> java.awt.event.KeyEvent.VK_CLEAR + KeyCode.CLOSE_BRACKET -> java.awt.event.KeyEvent.VK_CLOSE_BRACKET + KeyCode.CODE_INPUT -> java.awt.event.KeyEvent.VK_CODE_INPUT + KeyCode.COLON -> java.awt.event.KeyEvent.VK_COLON + KeyCode.COLORED_KEY_0 -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.COLORED_KEY_1 -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.COLORED_KEY_2 -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.COLORED_KEY_3 -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.COMMA -> java.awt.event.KeyEvent.VK_COMMA + KeyCode.COMPOSE -> java.awt.event.KeyEvent.VK_COMPOSE + KeyCode.CONTEXT_MENU -> java.awt.event.KeyEvent.VK_CONTEXT_MENU + KeyCode.CONTROL -> java.awt.event.KeyEvent.VK_CONTROL + KeyCode.CONVERT -> java.awt.event.KeyEvent.VK_CONVERT + KeyCode.COPY -> java.awt.event.KeyEvent.VK_COPY + KeyCode.CUT -> java.awt.event.KeyEvent.VK_CUT + KeyCode.D -> java.awt.event.KeyEvent.VK_D + KeyCode.DEAD_ABOVEDOT -> java.awt.event.KeyEvent.VK_DEAD_ABOVEDOT + KeyCode.DEAD_ABOVERING -> java.awt.event.KeyEvent.VK_DEAD_ABOVERING + KeyCode.DEAD_ACUTE -> java.awt.event.KeyEvent.VK_DEAD_ACUTE + KeyCode.DEAD_BREVE -> java.awt.event.KeyEvent.VK_DEAD_BREVE + KeyCode.DEAD_CARON -> java.awt.event.KeyEvent.VK_DEAD_CARON + KeyCode.DEAD_CEDILLA -> java.awt.event.KeyEvent.VK_DEAD_CEDILLA + KeyCode.DEAD_CIRCUMFLEX -> java.awt.event.KeyEvent.VK_DEAD_CIRCUMFLEX + KeyCode.DEAD_DIAERESIS -> java.awt.event.KeyEvent.VK_DEAD_DIAERESIS + KeyCode.DEAD_DOUBLEACUTE -> java.awt.event.KeyEvent.VK_DEAD_DOUBLEACUTE + KeyCode.DEAD_GRAVE -> java.awt.event.KeyEvent.VK_DEAD_GRAVE + KeyCode.DEAD_IOTA -> java.awt.event.KeyEvent.VK_DEAD_IOTA + KeyCode.DEAD_MACRON -> java.awt.event.KeyEvent.VK_DEAD_MACRON + KeyCode.DEAD_OGONEK -> java.awt.event.KeyEvent.VK_DEAD_OGONEK + KeyCode.DEAD_SEMIVOICED_SOUND -> java.awt.event.KeyEvent.VK_DEAD_SEMIVOICED_SOUND + KeyCode.DEAD_TILDE -> java.awt.event.KeyEvent.VK_DEAD_TILDE + KeyCode.DEAD_VOICED_SOUND -> java.awt.event.KeyEvent.VK_DEAD_VOICED_SOUND + KeyCode.DECIMAL -> java.awt.event.KeyEvent.VK_DECIMAL + KeyCode.DELETE -> java.awt.event.KeyEvent.VK_DELETE + KeyCode.DIGIT0 -> java.awt.event.KeyEvent.VK_0 + KeyCode.DIGIT1 -> java.awt.event.KeyEvent.VK_1 + KeyCode.DIGIT2 -> java.awt.event.KeyEvent.VK_2 + KeyCode.DIGIT3 -> java.awt.event.KeyEvent.VK_3 + KeyCode.DIGIT4 -> java.awt.event.KeyEvent.VK_4 + KeyCode.DIGIT5 -> java.awt.event.KeyEvent.VK_5 + KeyCode.DIGIT6 -> java.awt.event.KeyEvent.VK_6 + KeyCode.DIGIT7 -> java.awt.event.KeyEvent.VK_7 + KeyCode.DIGIT8 -> java.awt.event.KeyEvent.VK_8 + KeyCode.DIGIT9 -> java.awt.event.KeyEvent.VK_9 + KeyCode.DIVIDE -> java.awt.event.KeyEvent.VK_DIVIDE + KeyCode.DOLLAR -> java.awt.event.KeyEvent.VK_DOLLAR + KeyCode.DOWN -> java.awt.event.KeyEvent.VK_DOWN + KeyCode.E -> java.awt.event.KeyEvent.VK_E + KeyCode.EJECT_TOGGLE -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.END -> java.awt.event.KeyEvent.VK_END + KeyCode.ENTER -> java.awt.event.KeyEvent.VK_ENTER + KeyCode.EQUALS -> java.awt.event.KeyEvent.VK_EQUALS + KeyCode.ESCAPE -> java.awt.event.KeyEvent.VK_ESCAPE + KeyCode.EURO_SIGN -> java.awt.event.KeyEvent.VK_EURO_SIGN + KeyCode.EXCLAMATION_MARK -> java.awt.event.KeyEvent.VK_EXCLAMATION_MARK + KeyCode.F -> java.awt.event.KeyEvent.VK_F + KeyCode.F1 -> java.awt.event.KeyEvent.VK_F1 + KeyCode.F10 -> java.awt.event.KeyEvent.VK_F10 + KeyCode.F11 -> java.awt.event.KeyEvent.VK_F11 + KeyCode.F12 -> java.awt.event.KeyEvent.VK_F12 + KeyCode.F13 -> java.awt.event.KeyEvent.VK_F13 + KeyCode.F14 -> java.awt.event.KeyEvent.VK_F14 + KeyCode.F15 -> java.awt.event.KeyEvent.VK_F15 + KeyCode.F16 -> java.awt.event.KeyEvent.VK_F16 + KeyCode.F17 -> java.awt.event.KeyEvent.VK_F17 + KeyCode.F18 -> java.awt.event.KeyEvent.VK_F18 + KeyCode.F19 -> java.awt.event.KeyEvent.VK_F19 + KeyCode.F2 -> java.awt.event.KeyEvent.VK_F2 + KeyCode.F20 -> java.awt.event.KeyEvent.VK_F20 + KeyCode.F21 -> java.awt.event.KeyEvent.VK_F21 + KeyCode.F22 -> java.awt.event.KeyEvent.VK_F22 + KeyCode.F23 -> java.awt.event.KeyEvent.VK_F23 + KeyCode.F24 -> java.awt.event.KeyEvent.VK_F24 + KeyCode.F3 -> java.awt.event.KeyEvent.VK_F3 + KeyCode.F4 -> java.awt.event.KeyEvent.VK_F4 + KeyCode.F5 -> java.awt.event.KeyEvent.VK_F5 + KeyCode.F6 -> java.awt.event.KeyEvent.VK_F6 + KeyCode.F7 -> java.awt.event.KeyEvent.VK_F7 + KeyCode.F8 -> java.awt.event.KeyEvent.VK_F8 + KeyCode.F9 -> java.awt.event.KeyEvent.VK_F9 + KeyCode.FAST_FWD -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.FINAL -> java.awt.event.KeyEvent.VK_FINAL + KeyCode.FIND -> java.awt.event.KeyEvent.VK_FIND + KeyCode.FULL_WIDTH -> java.awt.event.KeyEvent.VK_FULL_WIDTH + KeyCode.G -> java.awt.event.KeyEvent.VK_G + KeyCode.GAME_A -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.GAME_B -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.GAME_C -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.GAME_D -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.GREATER -> java.awt.event.KeyEvent.VK_GREATER + KeyCode.H -> java.awt.event.KeyEvent.VK_H + KeyCode.HALF_WIDTH -> java.awt.event.KeyEvent.VK_HALF_WIDTH + KeyCode.HELP -> java.awt.event.KeyEvent.VK_HELP + KeyCode.HIRAGANA -> java.awt.event.KeyEvent.VK_HIRAGANA + KeyCode.HOME -> java.awt.event.KeyEvent.VK_HOME + KeyCode.I -> java.awt.event.KeyEvent.VK_I + KeyCode.INFO -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.INPUT_METHOD_ON_OFF -> java.awt.event.KeyEvent.VK_INPUT_METHOD_ON_OFF + KeyCode.INSERT -> java.awt.event.KeyEvent.VK_INSERT + KeyCode.INVERTED_EXCLAMATION_MARK -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.J -> java.awt.event.KeyEvent.VK_J + KeyCode.JAPANESE_HIRAGANA -> java.awt.event.KeyEvent.VK_JAPANESE_HIRAGANA + KeyCode.JAPANESE_KATAKANA -> java.awt.event.KeyEvent.VK_JAPANESE_KATAKANA + KeyCode.JAPANESE_ROMAN -> java.awt.event.KeyEvent.VK_JAPANESE_ROMAN + KeyCode.K -> java.awt.event.KeyEvent.VK_K + KeyCode.KANA -> java.awt.event.KeyEvent.VK_KANA + KeyCode.KANA_LOCK -> java.awt.event.KeyEvent.VK_KANA_LOCK + KeyCode.KANJI -> java.awt.event.KeyEvent.VK_KANJI + KeyCode.KATAKANA -> java.awt.event.KeyEvent.VK_KATAKANA + KeyCode.KP_DOWN -> java.awt.event.KeyEvent.VK_KP_DOWN + KeyCode.KP_LEFT -> java.awt.event.KeyEvent.VK_KP_LEFT + KeyCode.KP_RIGHT -> java.awt.event.KeyEvent.VK_KP_RIGHT + KeyCode.KP_UP -> java.awt.event.KeyEvent.VK_KP_UP + KeyCode.L -> java.awt.event.KeyEvent.VK_L + KeyCode.LEFT -> java.awt.event.KeyEvent.VK_LEFT + KeyCode.LEFT_PARENTHESIS -> java.awt.event.KeyEvent.VK_LEFT_PARENTHESIS + KeyCode.LESS -> java.awt.event.KeyEvent.VK_LESS + KeyCode.M -> java.awt.event.KeyEvent.VK_M + KeyCode.META -> java.awt.event.KeyEvent.VK_META + KeyCode.MINUS -> java.awt.event.KeyEvent.VK_MINUS + KeyCode.MODECHANGE -> java.awt.event.KeyEvent.VK_MODECHANGE + KeyCode.MULTIPLY -> java.awt.event.KeyEvent.VK_MULTIPLY + KeyCode.MUTE -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.N -> java.awt.event.KeyEvent.VK_N + KeyCode.NONCONVERT -> java.awt.event.KeyEvent.VK_NONCONVERT + KeyCode.NUMBER_SIGN -> java.awt.event.KeyEvent.VK_NUMBER_SIGN + KeyCode.NUMPAD0 -> java.awt.event.KeyEvent.VK_NUMPAD0 + KeyCode.NUMPAD1 -> java.awt.event.KeyEvent.VK_NUMPAD1 + KeyCode.NUMPAD2 -> java.awt.event.KeyEvent.VK_NUMPAD2 + KeyCode.NUMPAD3 -> java.awt.event.KeyEvent.VK_NUMPAD3 + KeyCode.NUMPAD4 -> java.awt.event.KeyEvent.VK_NUMPAD4 + KeyCode.NUMPAD5 -> java.awt.event.KeyEvent.VK_NUMPAD5 + KeyCode.NUMPAD6 -> java.awt.event.KeyEvent.VK_NUMPAD6 + KeyCode.NUMPAD7 -> java.awt.event.KeyEvent.VK_NUMPAD7 + KeyCode.NUMPAD8 -> java.awt.event.KeyEvent.VK_NUMPAD8 + KeyCode.NUMPAD9 -> java.awt.event.KeyEvent.VK_NUMPAD9 + KeyCode.NUM_LOCK -> java.awt.event.KeyEvent.VK_NUM_LOCK + KeyCode.O -> java.awt.event.KeyEvent.VK_O + KeyCode.OPEN_BRACKET -> java.awt.event.KeyEvent.VK_OPEN_BRACKET + KeyCode.P -> java.awt.event.KeyEvent.VK_P + KeyCode.PAGE_DOWN -> java.awt.event.KeyEvent.VK_PAGE_DOWN + KeyCode.PAGE_UP -> java.awt.event.KeyEvent.VK_PAGE_UP + KeyCode.PASTE -> java.awt.event.KeyEvent.VK_PASTE + KeyCode.PAUSE -> java.awt.event.KeyEvent.VK_PAUSE + KeyCode.PERIOD -> java.awt.event.KeyEvent.VK_PERIOD + KeyCode.PLAY -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.PLUS -> java.awt.event.KeyEvent.VK_PLUS + KeyCode.POUND -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.POWER -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.PREVIOUS_CANDIDATE -> java.awt.event.KeyEvent.VK_PREVIOUS_CANDIDATE + KeyCode.PRINTSCREEN -> java.awt.event.KeyEvent.VK_PRINTSCREEN + KeyCode.PROPS -> java.awt.event.KeyEvent.VK_PROPS + KeyCode.Q -> java.awt.event.KeyEvent.VK_Q + KeyCode.QUOTE -> java.awt.event.KeyEvent.VK_QUOTE + KeyCode.QUOTEDBL -> java.awt.event.KeyEvent.VK_QUOTEDBL + KeyCode.R -> java.awt.event.KeyEvent.VK_R + KeyCode.RECORD -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.REWIND -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.RIGHT -> java.awt.event.KeyEvent.VK_RIGHT + KeyCode.RIGHT_PARENTHESIS -> java.awt.event.KeyEvent.VK_RIGHT_PARENTHESIS + KeyCode.ROMAN_CHARACTERS -> java.awt.event.KeyEvent.VK_ROMAN_CHARACTERS + KeyCode.S -> java.awt.event.KeyEvent.VK_S + KeyCode.SCROLL_LOCK -> java.awt.event.KeyEvent.VK_SCROLL_LOCK + KeyCode.SEMICOLON -> java.awt.event.KeyEvent.VK_SEMICOLON + KeyCode.SEPARATOR -> java.awt.event.KeyEvent.VK_SEPARATOR + KeyCode.SHIFT -> java.awt.event.KeyEvent.VK_SHIFT + KeyCode.SHORTCUT -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.SLASH -> java.awt.event.KeyEvent.VK_SLASH + KeyCode.SOFTKEY_0 -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.SOFTKEY_1 -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.SOFTKEY_2 -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.SOFTKEY_3 -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.SOFTKEY_4 -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.SOFTKEY_5 -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.SOFTKEY_6 -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.SOFTKEY_7 -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.SOFTKEY_8 -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.SOFTKEY_9 -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.SPACE -> java.awt.event.KeyEvent.VK_SPACE + KeyCode.STAR -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.STOP -> java.awt.event.KeyEvent.VK_STOP + KeyCode.SUBTRACT -> java.awt.event.KeyEvent.VK_SUBTRACT + KeyCode.T -> java.awt.event.KeyEvent.VK_T + KeyCode.TAB -> java.awt.event.KeyEvent.VK_TAB + KeyCode.TRACK_NEXT -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.TRACK_PREV -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.U -> java.awt.event.KeyEvent.VK_U + KeyCode.UNDEFINED -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.UNDERSCORE -> java.awt.event.KeyEvent.VK_UNDERSCORE + KeyCode.UNDO -> java.awt.event.KeyEvent.VK_UNDO + KeyCode.UP -> java.awt.event.KeyEvent.VK_UP + KeyCode.V -> java.awt.event.KeyEvent.VK_V + KeyCode.VOLUME_DOWN -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.VOLUME_UP -> java.awt.event.KeyEvent.VK_UNDEFINED + KeyCode.W -> java.awt.event.KeyEvent.VK_W + KeyCode.WINDOWS -> java.awt.event.KeyEvent.VK_WINDOWS + KeyCode.X -> java.awt.event.KeyEvent.VK_X + KeyCode.Y -> java.awt.event.KeyEvent.VK_Y + KeyCode.Z -> java.awt.event.KeyEvent.VK_Z + else -> java.awt.event.KeyEvent.VK_UNDEFINED + } + } +} \ No newline at end of file From ab85ddc53014850cce46bc335f603c9e9744e4ba Mon Sep 17 00:00:00 2001 From: Viktor Shatrov Date: Mon, 8 Oct 2018 10:22:07 +0300 Subject: [PATCH 5/9] WebConsole: soft-wrap --- ...ditor.java => ConsoleExecutionEditor.java} | 6 +- .../console/LanguageConsoleImpl.java | 58 +++++++++---------- 2 files changed, 32 insertions(+), 32 deletions(-) rename platform/lang-impl/src/com/intellij/execution/console/{ConsoleEditor.java => ConsoleExecutionEditor.java} (96%) diff --git a/platform/lang-impl/src/com/intellij/execution/console/ConsoleEditor.java b/platform/lang-impl/src/com/intellij/execution/console/ConsoleExecutionEditor.java similarity index 96% rename from platform/lang-impl/src/com/intellij/execution/console/ConsoleEditor.java rename to platform/lang-impl/src/com/intellij/execution/console/ConsoleExecutionEditor.java index be96bf5093b0..41720b8a8cd1 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/ConsoleEditor.java +++ b/platform/lang-impl/src/com/intellij/execution/console/ConsoleExecutionEditor.java @@ -30,7 +30,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; -public class ConsoleEditor implements Disposable { +public class ConsoleExecutionEditor implements Disposable { private final EditorEx myConsoleEditor; private EditorEx myCurrentEditor; private final Document myEditorDocument; @@ -42,7 +42,7 @@ public class ConsoleEditor implements Disposable { @NotNull private ConsoleViewContentType myPromptAttributes = ConsoleViewContentType.USER_INPUT; - public ConsoleEditor(@NotNull LanguageConsoleImpl.Helper helper) { + public ConsoleExecutionEditor(@NotNull LanguageConsoleImpl.Helper helper) { myHelper = helper; EditorFactory editorFactory = EditorFactory.getInstance(); myEditorDocument = helper.getDocument(); @@ -62,7 +62,7 @@ public class ConsoleEditor implements Disposable { public void focusGained(@NotNull Editor editor) { myCurrentEditor = (EditorEx)editor; if (GeneralSettings.getInstance().isSaveOnFrameDeactivation()) { - TransactionGuard.submitTransaction(ConsoleEditor.this, () -> FileDocumentManager.getInstance().saveAllDocuments()); // PY-12487 + TransactionGuard.submitTransaction(ConsoleExecutionEditor.this, () -> FileDocumentManager.getInstance().saveAllDocuments()); // PY-12487 } } diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java index 851032bca133..74206db66d22 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java @@ -61,7 +61,7 @@ import java.util.Collections; public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageConsoleView, DataProvider { private final Helper myHelper; - private final ConsoleEditor myConsoleEditor; + private final ConsoleExecutionEditor myConsoleExecutionEditor; private final EditorEx myHistoryViewer; private final JPanel myPanel = new JPanel(new MyLayout()); private final JScrollBar myScrollBar = new JBScrollBar(Adjustable.HORIZONTAL); @@ -84,14 +84,14 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons super(helper.project, GlobalSearchScope.allScope(helper.project), true, true); myHelper = helper; EditorFactory editorFactory = EditorFactory.getInstance(); - myConsoleEditor = new ConsoleEditor(helper); + myConsoleExecutionEditor = new ConsoleExecutionEditor(helper); Document historyDocument = ((EditorFactoryImpl)editorFactory).createDocument(true); UndoUtil.disableUndoFor(historyDocument); myHistoryViewer = (EditorEx)editorFactory.createViewer(historyDocument, getProject(), EditorKind.CONSOLE); myHistoryViewer.getDocument().addDocumentListener(myDocumentAdapter); - myConsoleEditor.getDocument().addDocumentListener(myDocumentAdapter); - myScrollBar.setModel(new MyModel(myScrollBar, myHistoryViewer, myConsoleEditor.getEditor())); + myConsoleExecutionEditor.getDocument().addDocumentListener(myDocumentAdapter); + myScrollBar.setModel(new MyModel(myScrollBar, myHistoryViewer, myConsoleExecutionEditor.getEditor())); myScrollBar.putClientProperty(Alignment.class, Alignment.BOTTOM); } @@ -121,9 +121,9 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons setupComponents(); myPanel.add(myHistoryViewer.getComponent()); - myPanel.add(myConsoleEditor.getComponent()); + myPanel.add(myConsoleExecutionEditor.getComponent()); myPanel.add(myScrollBar); - myPanel.setBackground(myConsoleEditor.getEditor().getBackgroundColor()); + myPanel.setBackground(myConsoleExecutionEditor.getEditor().getBackgroundColor()); DataManager.registerDataProvider(myPanel, this); } @@ -132,7 +132,7 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons if (isConsoleEditorEnabled() == consoleEditorEnabled) { return; } - myConsoleEditor.setConsoleEditorEnabled(consoleEditorEnabled); + myConsoleExecutionEditor.setConsoleEditorEnabled(consoleEditorEnabled); setHistoryScrollBarVisible(!consoleEditorEnabled); myScrollBar.setVisible(consoleEditorEnabled); } @@ -143,15 +143,15 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons } private void setupComponents() { - myHelper.setupEditor(myConsoleEditor.getEditor()); + myHelper.setupEditor(myConsoleExecutionEditor.getEditor()); myHelper.setupEditor(myHistoryViewer); myHistoryViewer.getComponent().setMinimumSize(JBUI.emptySize()); myHistoryViewer.getComponent().setPreferredSize(JBUI.emptySize()); myHistoryViewer.setCaretEnabled(false); - myConsoleEditor.initComponent(); - Disposer.register(this, myConsoleEditor); + myConsoleExecutionEditor.initComponent(); + Disposer.register(this, myConsoleExecutionEditor); setHistoryScrollBarVisible(false); @@ -160,51 +160,51 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons public void keyTyped(KeyEvent event) { if (isConsoleEditorEnabled() && UIUtil.isReallyTypedEvent(event)) { IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown( - () -> IdeFocusManager.getGlobalInstance().requestFocus(myConsoleEditor.getEditor().getContentComponent(), true) + () -> IdeFocusManager.getGlobalInstance().requestFocus(myConsoleExecutionEditor.getEditor().getContentComponent(), true) ); - myConsoleEditor.getEditor().processKeyTyped(event); + myConsoleExecutionEditor.getEditor().processKeyTyped(event); } } }); - EmptyAction.registerActionShortcuts(myHistoryViewer.getComponent(), myConsoleEditor.getComponent()); + EmptyAction.registerActionShortcuts(myHistoryViewer.getComponent(), myConsoleExecutionEditor.getComponent()); } @Override public final boolean isConsoleEditorEnabled() { - return myConsoleEditor.isConsoleEditorEnabled(); + return myConsoleExecutionEditor.isConsoleEditorEnabled(); } @Override @Nullable public String getPrompt() { - return myConsoleEditor.getPrompt(); + return myConsoleExecutionEditor.getPrompt(); } @Override @Nullable public ConsoleViewContentType getPromptAttributes() { - return myConsoleEditor.getPromptAttributes(); + return myConsoleExecutionEditor.getPromptAttributes(); } @Override public void setPromptAttributes(@NotNull ConsoleViewContentType textAttributes) { - myConsoleEditor.setPromptAttributes(textAttributes); + myConsoleExecutionEditor.setPromptAttributes(textAttributes); } @Override public void setPrompt(@Nullable String prompt) { - myConsoleEditor.setPrompt(prompt); + myConsoleExecutionEditor.setPrompt(prompt); } @Override public void setEditable(boolean editable) { - myConsoleEditor.setEditable(editable); + myConsoleExecutionEditor.setEditable(editable); } @Override public boolean isEditable() { - return myConsoleEditor.isEditable(); + return myConsoleExecutionEditor.isEditable(); } @Override @@ -216,7 +216,7 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons @Override @NotNull public final VirtualFile getVirtualFile() { - return myConsoleEditor.getVirtualFile(); + return myConsoleExecutionEditor.getVirtualFile(); } @Override @@ -228,13 +228,13 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons @Override @NotNull public final Document getEditorDocument() { - return myConsoleEditor.getDocument(); + return myConsoleExecutionEditor.getDocument(); } @Override @NotNull public final EditorEx getConsoleEditor() { - return myConsoleEditor.getEditor(); + return myConsoleExecutionEditor.getEditor(); } @Override @@ -326,8 +326,8 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons } protected void doAddPromptToHistory() { - if (myConsoleEditor.getPrompt() != null) { - print(myConsoleEditor.getPrompt(), myConsoleEditor.getPromptAttributes()); + if (myConsoleExecutionEditor.getPrompt() != null) { + print(myConsoleExecutionEditor.getPrompt(), myConsoleExecutionEditor.getPromptAttributes()); } } @@ -365,7 +365,7 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons // double dispose via RunContentDescriptor and ContentImpl if (myHistoryViewer.isDisposed()) return; - myConsoleEditor.getDocument().removeDocumentListener(myDocumentAdapter); + myConsoleExecutionEditor.getDocument().removeDocumentListener(myDocumentAdapter); myHistoryViewer.getDocument().removeDocumentListener(myDocumentAdapter); EditorFactory editorFactory = EditorFactory.getInstance(); @@ -389,7 +389,7 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons @Override @NotNull public EditorEx getCurrentEditor() { - return myConsoleEditor.getCurrentEditor(); + return myConsoleExecutionEditor.getCurrentEditor(); } @Override @@ -406,7 +406,7 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons @Override public void setInputText(@NotNull final String query) { - myConsoleEditor.setInputText(query); + myConsoleExecutionEditor.setInputText(query); } boolean isHistoryViewerForceAdditionalColumnsUsage() { @@ -510,7 +510,7 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons } final EditorEx history = myHistoryViewer; - final EditorEx input = isConsoleEditorEnabled() ? myConsoleEditor.getEditor() : null; + final EditorEx input = isConsoleEditorEnabled() ? myConsoleExecutionEditor.getEditor() : null; if (input == null) { parent.getComponent(0).setBounds(parent.getBounds()); return; From b6b0df66c66a2d3c8dc63a08465f08323d59a32e Mon Sep 17 00:00:00 2001 From: Viktor Shatrov Date: Tue, 27 Nov 2018 13:10:55 +0300 Subject: [PATCH 6/9] WebConsole: replace token buffer with tasks buffer. --- .../intellij/execution/impl/TokenBuffer.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/impl/TokenBuffer.java b/platform/lang-impl/src/com/intellij/execution/impl/TokenBuffer.java index 6183aec229cc..3584e9f04341 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/TokenBuffer.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/TokenBuffer.java @@ -33,7 +33,7 @@ import java.util.stream.Collectors; * Add token via {@link #print(String, ConsoleViewContentType, HyperlinkInfo)} * Get all tokens via {@link #drain()} */ -public class TokenBuffer { +class TokenBuffer { // special token which means that the deferred text starts with "\r" so it shouldn't be appended to the document end. // Instead, the last line of the document should be removed static final TokenInfo CR_TOKEN = new TokenInfo(ConsoleViewContentType.SYSTEM_OUTPUT, "\r", null); @@ -42,11 +42,11 @@ public class TokenBuffer { private int size; // total lengths of all tokens private int startIndex; // index of text start in the first TokeInfo. This TokenInfo can become sliced after total size overflows maxCapacity - public TokenBuffer(int maxCapacity) { + TokenBuffer(int maxCapacity) { this.maxCapacity = maxCapacity; } - public void print(@NotNull String text, @NotNull ConsoleViewContentType contentType, @Nullable HyperlinkInfo info) { + void print(@NotNull String text, @NotNull ConsoleViewContentType contentType, @Nullable HyperlinkInfo info) { int start = 0; while (start < text.length()) { if (hasTrailingCR()) { @@ -134,18 +134,18 @@ public class TokenBuffer { //assert tokens.toList().stream().mapToInt(TokenInfo::length).sum() == size; } - public int length() { + int length() { return size - startIndex; } - public void clear() { + void clear() { tokens.clear(); startIndex = 0; size = 0; } @NotNull - public CharSequence getText() { + CharSequence getText() { if (hasTrailingCR()) { removeLastLine(); } @@ -156,7 +156,7 @@ public class TokenBuffer { // the first token may be CR_TOKEN meaning that instead of appending it we should delete the last line of the document // all the remaining text is guaranteed not to contain CR_TOKEN - they can be appended safely to the document end @NotNull - public List drain() { + List drain() { if (hasTrailingCR()) { removeLastLine(); } @@ -180,17 +180,17 @@ public class TokenBuffer { return list; } - public int getCycleBufferSize() { + int getCycleBufferSize() { return maxCapacity; } - public static class TokenInfo { + static class TokenInfo { @NotNull - public final ConsoleViewContentType contentType; + final ConsoleViewContentType contentType; private final String text; private final HyperlinkInfo myHyperlinkInfo; - public TokenInfo(@NotNull ConsoleViewContentType contentType, + TokenInfo(@NotNull ConsoleViewContentType contentType, @NotNull String text, @Nullable HyperlinkInfo hyperlinkInfo) { this.contentType = contentType; @@ -198,7 +198,7 @@ public class TokenBuffer { this.text = text; } - public int length() { + int length() { return text.length(); } @@ -207,12 +207,12 @@ public class TokenBuffer { return contentType + "[" + length() + "]"; } - public HyperlinkInfo getHyperlinkInfo() { + HyperlinkInfo getHyperlinkInfo() { return myHyperlinkInfo; } @NotNull - public String getText() { + String getText() { return text; } } From baa7f3f71d7c51d873417cec510666ff7427ad49 Mon Sep 17 00:00:00 2001 From: Viktor Shatrov Date: Thu, 6 Dec 2018 19:25:57 +0300 Subject: [PATCH 7/9] WebConsole: Extract ConsoleEditor from LanguageConsoleImpl - dispose fix --- .../com/intellij/execution/console/LanguageConsoleImpl.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java index 74206db66d22..2dfeb27d0ece 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java @@ -85,7 +85,7 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons myHelper = helper; EditorFactory editorFactory = EditorFactory.getInstance(); myConsoleExecutionEditor = new ConsoleExecutionEditor(helper); - + Disposer.register(this, myConsoleExecutionEditor); Document historyDocument = ((EditorFactoryImpl)editorFactory).createDocument(true); UndoUtil.disableUndoFor(historyDocument); myHistoryViewer = (EditorEx)editorFactory.createViewer(historyDocument, getProject(), EditorKind.CONSOLE); @@ -151,7 +151,6 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons myHistoryViewer.setCaretEnabled(false); myConsoleExecutionEditor.initComponent(); - Disposer.register(this, myConsoleExecutionEditor); setHistoryScrollBarVisible(false); From 4431e4a6949a8614f164baa420674bbb881b965b Mon Sep 17 00:00:00 2001 From: Viktor Shatrov Date: Fri, 14 Dec 2018 23:05:09 +0300 Subject: [PATCH 8/9] WebConsole: remove KeyEventHandler --- .../intellij/ui/javafx/JavaFxHtmlPanel.java | 6 + .../com/intellij/ui/javafx/KeyEventHandler.kt | 303 ------------------ 2 files changed, 6 insertions(+), 303 deletions(-) delete mode 100644 platform/platform-impl/src/com/intellij/ui/javafx/KeyEventHandler.kt diff --git a/platform/platform-impl/src/com/intellij/ui/javafx/JavaFxHtmlPanel.java b/platform/platform-impl/src/com/intellij/ui/javafx/JavaFxHtmlPanel.java index a06b66bfb0a5..e33257650c37 100644 --- a/platform/platform-impl/src/com/intellij/ui/javafx/JavaFxHtmlPanel.java +++ b/platform/platform-impl/src/com/intellij/ui/javafx/JavaFxHtmlPanel.java @@ -17,6 +17,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; +import java.awt.event.KeyListener; import java.util.ArrayList; import java.util.List; @@ -103,6 +104,11 @@ public class JavaFxHtmlPanel implements Disposable { public void dispose() { } + public void addKeyListener(KeyListener l) { + runInPlatformWhenAvailable(() -> myPanel.addKeyListener(l)); + } + + @NotNull protected WebView getWebViewGuaranteed() { if (myWebView == null) { diff --git a/platform/platform-impl/src/com/intellij/ui/javafx/KeyEventHandler.kt b/platform/platform-impl/src/com/intellij/ui/javafx/KeyEventHandler.kt deleted file mode 100644 index e456335c6462..000000000000 --- a/platform/platform-impl/src/com/intellij/ui/javafx/KeyEventHandler.kt +++ /dev/null @@ -1,303 +0,0 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.ui.javafx - -import com.intellij.ui.AppUIUtil -import javafx.event.EventHandler -import javafx.event.EventType -import javafx.scene.input.KeyCode -import javafx.scene.input.KeyEvent -import java.awt.KeyboardFocusManager -import java.awt.event.KeyListener -import java.awt.event.MouseEvent -import java.util.* - - -class KeyEventHandler(private val awtListener: KeyListener) : EventHandler { - - companion object { - private val keyEventMap: Map, Int> - - init { - val map = HashMap, Int>() - map[javafx.scene.input.KeyEvent.KEY_PRESSED] = java.awt.event.KeyEvent.KEY_PRESSED - map[javafx.scene.input.KeyEvent.KEY_RELEASED] = java.awt.event.KeyEvent.KEY_RELEASED - map[javafx.scene.input.KeyEvent.KEY_TYPED] = java.awt.event.KeyEvent.KEY_TYPED - keyEventMap = Collections.unmodifiableMap(map) - } - } - - override fun handle(ke: javafx.scene.input.KeyEvent) { - val focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().focusOwner ?: return - - val id = getKeyEventId(ke) - val time = System.currentTimeMillis() - val mods = getAWTModifiers(ke) - val keyCode = getAWTKeyCode(ke) - val keyChar = if (!ke.character.isEmpty()) - ke.character[0] - else - java.awt.event.KeyEvent.CHAR_UNDEFINED - if (id == java.awt.event.KeyEvent.KEY_TYPED && keyChar == java.awt.event.KeyEvent.CHAR_UNDEFINED) { - return - } - - val kp = java.awt.event.KeyEvent(focusOwner, id, time, mods, keyCode, keyChar) - AppUIUtil.invokeOnEdt { - when (id) { - java.awt.event.KeyEvent.KEY_PRESSED -> awtListener.keyPressed(kp) - java.awt.event.KeyEvent.KEY_RELEASED -> awtListener.keyReleased(kp) - java.awt.event.KeyEvent.KEY_TYPED -> awtListener.keyTyped(kp) - } - } - } - - private fun getKeyEventId(ke: javafx.scene.input.KeyEvent): Int { - return keyEventMap[ke.eventType]!! - } - - private fun getAWTModifiers(jfxKeyEvent: javafx.scene.input.KeyEvent): Int { - var mods = 0 - if (jfxKeyEvent.isAltDown) { - mods = mods or (MouseEvent.ALT_MASK or MouseEvent.ALT_DOWN_MASK) - } - if (jfxKeyEvent.isControlDown) { - mods = mods or (MouseEvent.CTRL_MASK or MouseEvent.CTRL_DOWN_MASK) - } - if (jfxKeyEvent.isShiftDown) { - mods = mods or (MouseEvent.SHIFT_MASK or MouseEvent.SHIFT_DOWN_MASK) - } - if (jfxKeyEvent.isMetaDown) { - mods = mods or (MouseEvent.META_MASK or MouseEvent.META_DOWN_MASK) - } - return mods - } - - private fun getAWTKeyCode(jfxKeyEvent: javafx.scene.input.KeyEvent): Int { - return when (jfxKeyEvent.code) { - KeyCode.A -> java.awt.event.KeyEvent.VK_A - KeyCode.ACCEPT -> java.awt.event.KeyEvent.VK_ACCEPT - KeyCode.ADD -> java.awt.event.KeyEvent.VK_ADD - KeyCode.AGAIN -> java.awt.event.KeyEvent.VK_AGAIN - KeyCode.ALL_CANDIDATES -> java.awt.event.KeyEvent.VK_ALL_CANDIDATES - KeyCode.ALPHANUMERIC -> java.awt.event.KeyEvent.VK_ALPHANUMERIC - KeyCode.ALT -> java.awt.event.KeyEvent.VK_ALT - KeyCode.ALT_GRAPH -> java.awt.event.KeyEvent.VK_ALT_GRAPH - KeyCode.AMPERSAND -> java.awt.event.KeyEvent.VK_AMPERSAND - KeyCode.ASTERISK -> java.awt.event.KeyEvent.VK_ASTERISK - KeyCode.AT -> java.awt.event.KeyEvent.VK_AT - KeyCode.B -> java.awt.event.KeyEvent.VK_B - KeyCode.BACK_QUOTE -> java.awt.event.KeyEvent.VK_BACK_QUOTE - KeyCode.BACK_SLASH -> java.awt.event.KeyEvent.VK_BACK_SLASH - KeyCode.BACK_SPACE -> java.awt.event.KeyEvent.VK_BACK_SPACE - KeyCode.BEGIN -> java.awt.event.KeyEvent.VK_BEGIN - KeyCode.BRACELEFT -> java.awt.event.KeyEvent.VK_BRACELEFT - KeyCode.BRACERIGHT -> java.awt.event.KeyEvent.VK_BRACERIGHT - KeyCode.C -> java.awt.event.KeyEvent.VK_C - KeyCode.CANCEL -> java.awt.event.KeyEvent.VK_CANCEL - KeyCode.CAPS -> java.awt.event.KeyEvent.VK_CAPS_LOCK - KeyCode.CHANNEL_DOWN -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.CHANNEL_UP -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.CIRCUMFLEX -> java.awt.event.KeyEvent.VK_CIRCUMFLEX - KeyCode.CLEAR -> java.awt.event.KeyEvent.VK_CLEAR - KeyCode.CLOSE_BRACKET -> java.awt.event.KeyEvent.VK_CLOSE_BRACKET - KeyCode.CODE_INPUT -> java.awt.event.KeyEvent.VK_CODE_INPUT - KeyCode.COLON -> java.awt.event.KeyEvent.VK_COLON - KeyCode.COLORED_KEY_0 -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.COLORED_KEY_1 -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.COLORED_KEY_2 -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.COLORED_KEY_3 -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.COMMA -> java.awt.event.KeyEvent.VK_COMMA - KeyCode.COMPOSE -> java.awt.event.KeyEvent.VK_COMPOSE - KeyCode.CONTEXT_MENU -> java.awt.event.KeyEvent.VK_CONTEXT_MENU - KeyCode.CONTROL -> java.awt.event.KeyEvent.VK_CONTROL - KeyCode.CONVERT -> java.awt.event.KeyEvent.VK_CONVERT - KeyCode.COPY -> java.awt.event.KeyEvent.VK_COPY - KeyCode.CUT -> java.awt.event.KeyEvent.VK_CUT - KeyCode.D -> java.awt.event.KeyEvent.VK_D - KeyCode.DEAD_ABOVEDOT -> java.awt.event.KeyEvent.VK_DEAD_ABOVEDOT - KeyCode.DEAD_ABOVERING -> java.awt.event.KeyEvent.VK_DEAD_ABOVERING - KeyCode.DEAD_ACUTE -> java.awt.event.KeyEvent.VK_DEAD_ACUTE - KeyCode.DEAD_BREVE -> java.awt.event.KeyEvent.VK_DEAD_BREVE - KeyCode.DEAD_CARON -> java.awt.event.KeyEvent.VK_DEAD_CARON - KeyCode.DEAD_CEDILLA -> java.awt.event.KeyEvent.VK_DEAD_CEDILLA - KeyCode.DEAD_CIRCUMFLEX -> java.awt.event.KeyEvent.VK_DEAD_CIRCUMFLEX - KeyCode.DEAD_DIAERESIS -> java.awt.event.KeyEvent.VK_DEAD_DIAERESIS - KeyCode.DEAD_DOUBLEACUTE -> java.awt.event.KeyEvent.VK_DEAD_DOUBLEACUTE - KeyCode.DEAD_GRAVE -> java.awt.event.KeyEvent.VK_DEAD_GRAVE - KeyCode.DEAD_IOTA -> java.awt.event.KeyEvent.VK_DEAD_IOTA - KeyCode.DEAD_MACRON -> java.awt.event.KeyEvent.VK_DEAD_MACRON - KeyCode.DEAD_OGONEK -> java.awt.event.KeyEvent.VK_DEAD_OGONEK - KeyCode.DEAD_SEMIVOICED_SOUND -> java.awt.event.KeyEvent.VK_DEAD_SEMIVOICED_SOUND - KeyCode.DEAD_TILDE -> java.awt.event.KeyEvent.VK_DEAD_TILDE - KeyCode.DEAD_VOICED_SOUND -> java.awt.event.KeyEvent.VK_DEAD_VOICED_SOUND - KeyCode.DECIMAL -> java.awt.event.KeyEvent.VK_DECIMAL - KeyCode.DELETE -> java.awt.event.KeyEvent.VK_DELETE - KeyCode.DIGIT0 -> java.awt.event.KeyEvent.VK_0 - KeyCode.DIGIT1 -> java.awt.event.KeyEvent.VK_1 - KeyCode.DIGIT2 -> java.awt.event.KeyEvent.VK_2 - KeyCode.DIGIT3 -> java.awt.event.KeyEvent.VK_3 - KeyCode.DIGIT4 -> java.awt.event.KeyEvent.VK_4 - KeyCode.DIGIT5 -> java.awt.event.KeyEvent.VK_5 - KeyCode.DIGIT6 -> java.awt.event.KeyEvent.VK_6 - KeyCode.DIGIT7 -> java.awt.event.KeyEvent.VK_7 - KeyCode.DIGIT8 -> java.awt.event.KeyEvent.VK_8 - KeyCode.DIGIT9 -> java.awt.event.KeyEvent.VK_9 - KeyCode.DIVIDE -> java.awt.event.KeyEvent.VK_DIVIDE - KeyCode.DOLLAR -> java.awt.event.KeyEvent.VK_DOLLAR - KeyCode.DOWN -> java.awt.event.KeyEvent.VK_DOWN - KeyCode.E -> java.awt.event.KeyEvent.VK_E - KeyCode.EJECT_TOGGLE -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.END -> java.awt.event.KeyEvent.VK_END - KeyCode.ENTER -> java.awt.event.KeyEvent.VK_ENTER - KeyCode.EQUALS -> java.awt.event.KeyEvent.VK_EQUALS - KeyCode.ESCAPE -> java.awt.event.KeyEvent.VK_ESCAPE - KeyCode.EURO_SIGN -> java.awt.event.KeyEvent.VK_EURO_SIGN - KeyCode.EXCLAMATION_MARK -> java.awt.event.KeyEvent.VK_EXCLAMATION_MARK - KeyCode.F -> java.awt.event.KeyEvent.VK_F - KeyCode.F1 -> java.awt.event.KeyEvent.VK_F1 - KeyCode.F10 -> java.awt.event.KeyEvent.VK_F10 - KeyCode.F11 -> java.awt.event.KeyEvent.VK_F11 - KeyCode.F12 -> java.awt.event.KeyEvent.VK_F12 - KeyCode.F13 -> java.awt.event.KeyEvent.VK_F13 - KeyCode.F14 -> java.awt.event.KeyEvent.VK_F14 - KeyCode.F15 -> java.awt.event.KeyEvent.VK_F15 - KeyCode.F16 -> java.awt.event.KeyEvent.VK_F16 - KeyCode.F17 -> java.awt.event.KeyEvent.VK_F17 - KeyCode.F18 -> java.awt.event.KeyEvent.VK_F18 - KeyCode.F19 -> java.awt.event.KeyEvent.VK_F19 - KeyCode.F2 -> java.awt.event.KeyEvent.VK_F2 - KeyCode.F20 -> java.awt.event.KeyEvent.VK_F20 - KeyCode.F21 -> java.awt.event.KeyEvent.VK_F21 - KeyCode.F22 -> java.awt.event.KeyEvent.VK_F22 - KeyCode.F23 -> java.awt.event.KeyEvent.VK_F23 - KeyCode.F24 -> java.awt.event.KeyEvent.VK_F24 - KeyCode.F3 -> java.awt.event.KeyEvent.VK_F3 - KeyCode.F4 -> java.awt.event.KeyEvent.VK_F4 - KeyCode.F5 -> java.awt.event.KeyEvent.VK_F5 - KeyCode.F6 -> java.awt.event.KeyEvent.VK_F6 - KeyCode.F7 -> java.awt.event.KeyEvent.VK_F7 - KeyCode.F8 -> java.awt.event.KeyEvent.VK_F8 - KeyCode.F9 -> java.awt.event.KeyEvent.VK_F9 - KeyCode.FAST_FWD -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.FINAL -> java.awt.event.KeyEvent.VK_FINAL - KeyCode.FIND -> java.awt.event.KeyEvent.VK_FIND - KeyCode.FULL_WIDTH -> java.awt.event.KeyEvent.VK_FULL_WIDTH - KeyCode.G -> java.awt.event.KeyEvent.VK_G - KeyCode.GAME_A -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.GAME_B -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.GAME_C -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.GAME_D -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.GREATER -> java.awt.event.KeyEvent.VK_GREATER - KeyCode.H -> java.awt.event.KeyEvent.VK_H - KeyCode.HALF_WIDTH -> java.awt.event.KeyEvent.VK_HALF_WIDTH - KeyCode.HELP -> java.awt.event.KeyEvent.VK_HELP - KeyCode.HIRAGANA -> java.awt.event.KeyEvent.VK_HIRAGANA - KeyCode.HOME -> java.awt.event.KeyEvent.VK_HOME - KeyCode.I -> java.awt.event.KeyEvent.VK_I - KeyCode.INFO -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.INPUT_METHOD_ON_OFF -> java.awt.event.KeyEvent.VK_INPUT_METHOD_ON_OFF - KeyCode.INSERT -> java.awt.event.KeyEvent.VK_INSERT - KeyCode.INVERTED_EXCLAMATION_MARK -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.J -> java.awt.event.KeyEvent.VK_J - KeyCode.JAPANESE_HIRAGANA -> java.awt.event.KeyEvent.VK_JAPANESE_HIRAGANA - KeyCode.JAPANESE_KATAKANA -> java.awt.event.KeyEvent.VK_JAPANESE_KATAKANA - KeyCode.JAPANESE_ROMAN -> java.awt.event.KeyEvent.VK_JAPANESE_ROMAN - KeyCode.K -> java.awt.event.KeyEvent.VK_K - KeyCode.KANA -> java.awt.event.KeyEvent.VK_KANA - KeyCode.KANA_LOCK -> java.awt.event.KeyEvent.VK_KANA_LOCK - KeyCode.KANJI -> java.awt.event.KeyEvent.VK_KANJI - KeyCode.KATAKANA -> java.awt.event.KeyEvent.VK_KATAKANA - KeyCode.KP_DOWN -> java.awt.event.KeyEvent.VK_KP_DOWN - KeyCode.KP_LEFT -> java.awt.event.KeyEvent.VK_KP_LEFT - KeyCode.KP_RIGHT -> java.awt.event.KeyEvent.VK_KP_RIGHT - KeyCode.KP_UP -> java.awt.event.KeyEvent.VK_KP_UP - KeyCode.L -> java.awt.event.KeyEvent.VK_L - KeyCode.LEFT -> java.awt.event.KeyEvent.VK_LEFT - KeyCode.LEFT_PARENTHESIS -> java.awt.event.KeyEvent.VK_LEFT_PARENTHESIS - KeyCode.LESS -> java.awt.event.KeyEvent.VK_LESS - KeyCode.M -> java.awt.event.KeyEvent.VK_M - KeyCode.META -> java.awt.event.KeyEvent.VK_META - KeyCode.MINUS -> java.awt.event.KeyEvent.VK_MINUS - KeyCode.MODECHANGE -> java.awt.event.KeyEvent.VK_MODECHANGE - KeyCode.MULTIPLY -> java.awt.event.KeyEvent.VK_MULTIPLY - KeyCode.MUTE -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.N -> java.awt.event.KeyEvent.VK_N - KeyCode.NONCONVERT -> java.awt.event.KeyEvent.VK_NONCONVERT - KeyCode.NUMBER_SIGN -> java.awt.event.KeyEvent.VK_NUMBER_SIGN - KeyCode.NUMPAD0 -> java.awt.event.KeyEvent.VK_NUMPAD0 - KeyCode.NUMPAD1 -> java.awt.event.KeyEvent.VK_NUMPAD1 - KeyCode.NUMPAD2 -> java.awt.event.KeyEvent.VK_NUMPAD2 - KeyCode.NUMPAD3 -> java.awt.event.KeyEvent.VK_NUMPAD3 - KeyCode.NUMPAD4 -> java.awt.event.KeyEvent.VK_NUMPAD4 - KeyCode.NUMPAD5 -> java.awt.event.KeyEvent.VK_NUMPAD5 - KeyCode.NUMPAD6 -> java.awt.event.KeyEvent.VK_NUMPAD6 - KeyCode.NUMPAD7 -> java.awt.event.KeyEvent.VK_NUMPAD7 - KeyCode.NUMPAD8 -> java.awt.event.KeyEvent.VK_NUMPAD8 - KeyCode.NUMPAD9 -> java.awt.event.KeyEvent.VK_NUMPAD9 - KeyCode.NUM_LOCK -> java.awt.event.KeyEvent.VK_NUM_LOCK - KeyCode.O -> java.awt.event.KeyEvent.VK_O - KeyCode.OPEN_BRACKET -> java.awt.event.KeyEvent.VK_OPEN_BRACKET - KeyCode.P -> java.awt.event.KeyEvent.VK_P - KeyCode.PAGE_DOWN -> java.awt.event.KeyEvent.VK_PAGE_DOWN - KeyCode.PAGE_UP -> java.awt.event.KeyEvent.VK_PAGE_UP - KeyCode.PASTE -> java.awt.event.KeyEvent.VK_PASTE - KeyCode.PAUSE -> java.awt.event.KeyEvent.VK_PAUSE - KeyCode.PERIOD -> java.awt.event.KeyEvent.VK_PERIOD - KeyCode.PLAY -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.PLUS -> java.awt.event.KeyEvent.VK_PLUS - KeyCode.POUND -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.POWER -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.PREVIOUS_CANDIDATE -> java.awt.event.KeyEvent.VK_PREVIOUS_CANDIDATE - KeyCode.PRINTSCREEN -> java.awt.event.KeyEvent.VK_PRINTSCREEN - KeyCode.PROPS -> java.awt.event.KeyEvent.VK_PROPS - KeyCode.Q -> java.awt.event.KeyEvent.VK_Q - KeyCode.QUOTE -> java.awt.event.KeyEvent.VK_QUOTE - KeyCode.QUOTEDBL -> java.awt.event.KeyEvent.VK_QUOTEDBL - KeyCode.R -> java.awt.event.KeyEvent.VK_R - KeyCode.RECORD -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.REWIND -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.RIGHT -> java.awt.event.KeyEvent.VK_RIGHT - KeyCode.RIGHT_PARENTHESIS -> java.awt.event.KeyEvent.VK_RIGHT_PARENTHESIS - KeyCode.ROMAN_CHARACTERS -> java.awt.event.KeyEvent.VK_ROMAN_CHARACTERS - KeyCode.S -> java.awt.event.KeyEvent.VK_S - KeyCode.SCROLL_LOCK -> java.awt.event.KeyEvent.VK_SCROLL_LOCK - KeyCode.SEMICOLON -> java.awt.event.KeyEvent.VK_SEMICOLON - KeyCode.SEPARATOR -> java.awt.event.KeyEvent.VK_SEPARATOR - KeyCode.SHIFT -> java.awt.event.KeyEvent.VK_SHIFT - KeyCode.SHORTCUT -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.SLASH -> java.awt.event.KeyEvent.VK_SLASH - KeyCode.SOFTKEY_0 -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.SOFTKEY_1 -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.SOFTKEY_2 -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.SOFTKEY_3 -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.SOFTKEY_4 -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.SOFTKEY_5 -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.SOFTKEY_6 -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.SOFTKEY_7 -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.SOFTKEY_8 -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.SOFTKEY_9 -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.SPACE -> java.awt.event.KeyEvent.VK_SPACE - KeyCode.STAR -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.STOP -> java.awt.event.KeyEvent.VK_STOP - KeyCode.SUBTRACT -> java.awt.event.KeyEvent.VK_SUBTRACT - KeyCode.T -> java.awt.event.KeyEvent.VK_T - KeyCode.TAB -> java.awt.event.KeyEvent.VK_TAB - KeyCode.TRACK_NEXT -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.TRACK_PREV -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.U -> java.awt.event.KeyEvent.VK_U - KeyCode.UNDEFINED -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.UNDERSCORE -> java.awt.event.KeyEvent.VK_UNDERSCORE - KeyCode.UNDO -> java.awt.event.KeyEvent.VK_UNDO - KeyCode.UP -> java.awt.event.KeyEvent.VK_UP - KeyCode.V -> java.awt.event.KeyEvent.VK_V - KeyCode.VOLUME_DOWN -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.VOLUME_UP -> java.awt.event.KeyEvent.VK_UNDEFINED - KeyCode.W -> java.awt.event.KeyEvent.VK_W - KeyCode.WINDOWS -> java.awt.event.KeyEvent.VK_WINDOWS - KeyCode.X -> java.awt.event.KeyEvent.VK_X - KeyCode.Y -> java.awt.event.KeyEvent.VK_Y - KeyCode.Z -> java.awt.event.KeyEvent.VK_Z - else -> java.awt.event.KeyEvent.VK_UNDEFINED - } - } -} \ No newline at end of file From 888c2fec71c4bc987def4044cdfd830ab6c1d0fa Mon Sep 17 00:00:00 2001 From: Viktor Shatrov Date: Mon, 17 Dec 2018 16:36:16 +0300 Subject: [PATCH 9/9] WebConsole: add registry keys to plugin.xml --- platform/util/resources/misc/registry.properties | 1 - 1 file changed, 1 deletion(-) diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index e9784ef99eff..14820cf86259 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -1005,7 +1005,6 @@ js.debugger.use.vm.receiver=false js.debugger.auto.expressions.all.qualifiers=false js.debugger.async.call.stack.depth=10 js.debugger.async.call.stack.depth.description=Enables or disables async call stacks tracking in JS debugger -js.debugger.webconsole=false nodejs.core.library.use.typings=true nodejs.core.library.use.typings.description=Enables using @types/node for Node.js coding assistance in "Node.js Core" library