List of usage examples for com.intellij.openapi.actionSystem EmptyAction registerActionShortcuts
public static void registerActionShortcuts(@NotNull JComponent component, @NotNull JComponent fromComponent)
From source file:com.intellij.execution.console.LanguageConsoleImpl.java
License:Apache License
private void setupComponents() { setupEditorDefault(myConsoleEditor); setupEditorDefault(myHistoryViewer); //noinspection ConstantConditions if (SEPARATOR_THICKNESS > 0 && myShowSeparatorLine) { myHistoryViewer.getComponent().setBorder(new SideBorder(JBColor.LIGHT_GRAY, SideBorder.BOTTOM)); }//from w w w .j a va2 s. c o m myHistoryViewer.getComponent().setMinimumSize(new Dimension(0, 0)); myHistoryViewer.getComponent().setPreferredSize(new Dimension(0, 0)); myHistoryViewer.setCaretEnabled(false); myConsoleEditor.setHorizontalScrollbarVisible(true); myConsoleEditor.addEditorMouseListener( EditorActionUtil.createEditorPopupHandler(IdeActions.GROUP_CONSOLE_EDITOR_POPUP)); myConsoleEditor.setHighlighter(EditorHighlighterFactory.getInstance().createEditorHighlighter(myVirtualFile, myConsoleEditor.getColorsScheme(), myProject)); myConsoleEditor.getScrollingModel().addVisibleAreaListener(new VisibleAreaListener() { @Override public void visibleAreaChanged(VisibleAreaEvent e) { final int offset = myConsoleEditor.getScrollingModel().getHorizontalScrollOffset(); final ScrollingModel model = myHistoryViewer.getScrollingModel(); final int historyOffset = model.getHorizontalScrollOffset(); if (historyOffset != offset) { try { model.disableAnimation(); model.scrollHorizontally(offset); } finally { model.enableAnimation(); } } } }); final DocumentAdapter docListener = new DocumentAdapter() { @Override public void documentChanged(final DocumentEvent e) { queueUiUpdate(false); } }; myEditorDocument.addDocumentListener(docListener, this); myHistoryViewer.getDocument().addDocumentListener(docListener, this); myHistoryViewer.getContentComponent().addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent event) { if (isConsoleEditorEnabled() && UIUtil.isReallyTypedEvent(event)) { myConsoleEditor.getContentComponent().requestFocus(); myConsoleEditor.processKeyTyped(event); } } }); //noinspection deprecation for (AnAction action : createActions()) { action.registerCustomShortcutSet(action.getShortcutSet(), myConsoleEditor.getComponent()); } EmptyAction.registerActionShortcuts(myHistoryViewer.getComponent(), myConsoleEditor.getComponent()); }
From source file:com.intellij.execution.console.LanguageConsoleImpl.java
License:Apache License
private void installEditorFactoryListener() { FileEditorManagerAdapter fileEditorListener = new FileEditorManagerAdapter() { @Override/*from ww w. ja v a 2s .com*/ public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) { if (myConsoleEditor == null || !Comparing.equal(file, myVirtualFile)) { 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()); editor.getCaretModel().addCaretListener(new CaretAdapter() { @Override public void caretPositionChanged(CaretEvent e) { queueUiUpdate(false); } }); } queueUiUpdate(false); } @Override public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) { if (!Comparing.equal(file, myVirtualFile)) { return; } if (myUiUpdateRunnable != null && !Boolean.TRUE.equals(file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN))) { if (myCurrentEditor != null && myCurrentEditor.isDisposed()) { myCurrentEditor = null; } ApplicationManager.getApplication().runReadAction(myUiUpdateRunnable); } } }; myProject.getMessageBus().connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, fileEditorListener); FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); if (editorManager.isFileOpen(myVirtualFile)) { fileEditorListener.fileOpened(editorManager, myVirtualFile); } }
From source file:javarepl.plugin.JavaREPLLanguageConsole.java
License:Apache License
private void setupComponents() { setupEditorDefault(myConsoleEditor); setupEditorDefault(myHistoryViewer); myConsoleEditor.addEditorMouseListener( EditorActionUtil.createEditorPopupHandler(IdeActions.GROUP_CONSOLE_EDITOR_POPUP)); //noinspection PointlessBooleanExpression,ConstantConditions if (SEPARATOR_THICKNESS > 0 && myShowSeparatorLine) { myHistoryViewer.getComponent().setBorder(new SideBorder(Color.LIGHT_GRAY, SideBorder.BOTTOM)); }/*from w ww . j ava 2s . co m*/ myHistoryViewer.getComponent().setMinimumSize(new Dimension(0, 0)); myHistoryViewer.getComponent().setPreferredSize(new Dimension(0, 0)); myConsoleEditor.getSettings().setAdditionalLinesCount(2); myConsoleEditor.setHighlighter( EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, myVirtualFile)); myHistoryViewer.setCaretEnabled(false); myConsoleEditor.setHorizontalScrollbarVisible(true); final VisibleAreaListener areaListener = new VisibleAreaListener() { public void visibleAreaChanged(VisibleAreaEvent e) { final int offset = myConsoleEditor.getScrollingModel().getHorizontalScrollOffset(); final ScrollingModel model = myHistoryViewer.getScrollingModel(); final int historyOffset = model.getHorizontalScrollOffset(); if (historyOffset != offset) { try { model.disableAnimation(); model.scrollHorizontally(offset); } finally { model.enableAnimation(); } } } }; myConsoleEditor.getScrollingModel().addVisibleAreaListener(areaListener); final DocumentAdapter docListener = new DocumentAdapter() { @Override public void documentChanged(final DocumentEvent e) { updateCodeCompletion(); queueUiUpdate(false); } }; myEditorDocument.addDocumentListener(docListener, this); myHistoryViewer.getDocument().addDocumentListener(docListener, this); myHistoryViewer.getContentComponent().addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent event) { if (isConsoleEditorEnabled() && UIUtil.isReallyTypedEvent(event)) { myConsoleEditor.getContentComponent().requestFocus(); myConsoleEditor.processKeyTyped(event); } } }); for (AnAction action : createActions()) { action.registerCustomShortcutSet(action.getShortcutSet(), myConsoleEditor.getComponent()); } EmptyAction.registerActionShortcuts(myHistoryViewer.getComponent(), myConsoleEditor.getComponent()); }
From source file:javarepl.plugin.JavaREPLLanguageConsole.java
License:Apache License
private void installEditorFactoryListener() { final FileEditorManagerAdapter fileEditorListener = new FileEditorManagerAdapter() { @Override//from w w w.j ava 2s . c o m public void fileOpened(FileEditorManager source, VirtualFile file) { if (!Comparing.equal(file, myVirtualFile) || myConsoleEditor == null) 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()); editor.getCaretModel().addCaretListener(new CaretListener() { public void caretPositionChanged(CaretEvent e) { queueUiUpdate(false); } }); } queueUiUpdate(false); } @Override public void fileClosed(FileEditorManager source, VirtualFile file) { if (!Comparing.equal(file, myVirtualFile)) return; if (myUiUpdateRunnable != null && !Boolean.TRUE.equals(file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN))) { if (myCurrentEditor != null && myCurrentEditor.isDisposed()) myCurrentEditor = null; ApplicationManager.getApplication().runReadAction(myUiUpdateRunnable); } } }; myProject.getMessageBus().connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, fileEditorListener); FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); if (editorManager.isFileOpen(myVirtualFile)) { fileEditorListener.fileOpened(editorManager, myVirtualFile); } }