com.intellij.openapi.editor.event.DocumentAdapter Java Examples
The following examples show how to use
com.intellij.openapi.editor.event.DocumentAdapter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TemplateConfigurable.java From android-codegenerator-plugin-intellij with Apache License 2.0 | 6 votes |
private Editor createEditorInPanel(String string) { EditorFactory editorFactory = EditorFactory.getInstance(); Editor editor = editorFactory.createEditor(editorFactory.createDocument(string)); EditorSettings editorSettings = editor.getSettings(); editorSettings.setVirtualSpace(false); editorSettings.setLineMarkerAreaShown(false); editorSettings.setIndentGuidesShown(false); editorSettings.setLineNumbersShown(false); editorSettings.setFoldingOutlineShown(false); editorSettings.setAdditionalColumnsCount(3); editorSettings.setAdditionalLinesCount(3); editor.getDocument().addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { onTextChanged(); } }); ((EditorEx) editor).setHighlighter(getEditorHighlighter()); addEditorToPanel(editor); return editor; }
Example #2
Source File: ClassCompletionPanelWrapper.java From idea-php-symfony2-plugin with MIT License | 6 votes |
private void init() { this.field = new EditorTextField("", project, com.jetbrains.php.lang.PhpFileType.INSTANCE); PhpCompletionUtil.installClassCompletion(this.field, null, getDisposable()); this.field.getDocument().addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { String text = field.getText(); if (StringUtil.isEmpty(text) || StringUtil.endsWith(text, "\\")) { return; } addUpdateRequest(250, () -> consumer.consume(field.getText())); } }); GridBagConstraints gbConstraints = new GridBagConstraints(); gbConstraints.fill = 1; gbConstraints.weightx = 1.0D; gbConstraints.gridx = 1; gbConstraints.gridy = 1; panel.add(field, gbConstraints); }
Example #3
Source File: InputPanel.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void createManualInputPreviewEditor(final PreviewState previewState) { final EditorFactory factory = EditorFactory.getInstance(); Document doc = factory.createDocument(""); doc.addDocumentListener( new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { previewState.manualInputText = e.getDocument().getCharsSequence(); } } ); Editor editor = createPreviewEditor(previewState.grammarFile, doc, false); setEditorComponent(editor.getComponent()); // do before setting state previewState.setInputEditor(editor); // Set text last to trigger change events ApplicationManager.getApplication().runWriteAction(() -> doc.setText(previewState.manualInputText)); }
Example #4
Source File: RangeMarkerTest.java From consulo with Apache License 2.0 | 6 votes |
public void testDocSynchronizerPrefersLineBoundaryChanges() throws Exception { String text = "import java.awt.List;\n" + "[import java.util.ArrayList;\n]" + "import java.util.HashMap;\n" + "import java.util.Map;"; RangeMarker marker = createMarker(text); synchronizer.startTransaction(getProject(), document, psiFile); String newText = StringUtil.replaceSubstring(document.getText(), TextRange.create(marker), ""); synchronizer.replaceString(document, 0, document.getTextLength(), newText); final List<DocumentEvent> events = new ArrayList<DocumentEvent>(); document.addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { events.add(e); } }); synchronizer.commitTransaction(document); assertEquals(newText, document.getText()); DocumentEvent event = assertOneElement(events); assertEquals("DocumentEventImpl[myOffset=22, myOldLength=28, myNewLength=0, myOldString='import java.util.ArrayList;\n', myNewString=''].", event.toString()); }
Example #5
Source File: ParameterNameHintsConfigurable.java From consulo with Apache License 2.0 | 6 votes |
private void createUIComponents() { List<Language> languages = getBaseLanguagesWithProviders(); Language selected = myInitiallySelectedLanguage; if (selected == null) { selected = languages.get(0); } String text = getLanguageBlackList(selected); myEditorTextField = createEditor(text, myNewPreselectedItem); myEditorTextField.addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { updateOkEnabled(); } }); myDoNotShowIfParameterNameContainedInMethodName = new JBCheckBox(); myShowWhenMultipleParamsWithSameType = new JBCheckBox(); ParameterNameHintsSettings settings = ParameterNameHintsSettings.getInstance(); myDoNotShowIfParameterNameContainedInMethodName.setSelected(settings.isDoNotShowIfMethodNameContainsParameterName()); myShowWhenMultipleParamsWithSameType.setSelected(settings.isShowForParamsWithSameType()); initLanguageCombo(languages, selected); }
Example #6
Source File: ActionTracker.java From consulo with Apache License 2.0 | 6 votes |
ActionTracker(Editor editor, Disposable parentDisposable) { myEditor = editor; myProject = editor.getProject(); ActionManager.getInstance().addAnActionListener(new AnActionListener.Adapter() { @Override public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) { myActionsHappened = true; } }, parentDisposable); myEditor.getDocument().addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { if (!myIgnoreDocumentChanges) { myActionsHappened = true; } } }, parentDisposable); }
Example #7
Source File: InputPanel.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Editor createPreviewEditor(final VirtualFile grammarFile, Document doc, boolean readOnly) { LOG.info("createEditor: create new editor for "+grammarFile.getPath()+" "+previewPanel.project.getName()); final EditorFactory factory = EditorFactory.getInstance(); doc.addDocumentListener( new DocumentAdapter() { VirtualFile grammarFileForThisPreviewEditor; { { // faux ctor this.grammarFileForThisPreviewEditor = grammarFile; } } @Override public void documentChanged(DocumentEvent event) { previewPanel.updateParseTreeFromDoc(grammarFileForThisPreviewEditor); } } ); final Editor editor = readOnly ? factory.createViewer(doc, previewPanel.project) : factory.createEditor(doc, previewPanel.project); // force right margin ((EditorMarkupModel) editor.getMarkupModel()).setErrorStripeVisible(true); EditorSettings settings = editor.getSettings(); settings.setWhitespacesShown(true); settings.setLineNumbersShown(true); settings.setLineMarkerAreaShown(true); installListeners(editor); return editor; }
Example #8
Source File: FileStatusManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Inject public FileStatusManagerImpl(Project project, StartupManager startupManager, @SuppressWarnings("UnusedParameters") DirectoryIndex makeSureIndexIsInitializedFirst) { myProject = project; project.getMessageBus().connect().subscribe(EditorColorsManager.TOPIC, new EditorColorsListener() { @Override public void globalSchemeChange(EditorColorsScheme scheme) { fileStatusesChanged(); } }); if (project.isDefault()) return; startupManager.registerPreStartupActivity(() -> { DocumentAdapter documentListener = new DocumentAdapter() { @Override public void documentChanged(DocumentEvent event) { if (event.getOldLength() == 0 && event.getNewLength() == 0) return; VirtualFile file = FileDocumentManager.getInstance().getFile(event.getDocument()); if (file != null) { refreshFileStatusFromDocument(file, event.getDocument()); } } }; final EditorFactory factory = EditorFactory.getInstance(); if (factory != null) { factory.getEventMulticaster().addDocumentListener(documentListener, myProject); } }); startupManager.registerPostStartupActivity(new DumbAwareRunnable() { @Override public void run() { fileStatusesChanged(); } }); }
Example #9
Source File: NewEditChangelistPanel.java From consulo with Apache License 2.0 | 5 votes |
public void init(final LocalChangeList initial) { myMakeActiveCheckBox.setSelected(VcsConfiguration.getInstance(myProject).MAKE_NEW_CHANGELIST_ACTIVE); for (EditChangelistSupport support : Extensions.getExtensions(EditChangelistSupport.EP_NAME, myProject)) { support.installSearch(myNameTextField, myDescriptionTextArea); myConsumer = support.addControls(myAdditionalControlsPanel, initial); } myNameTextField.getDocument().addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent event) { nameChangedImpl(myProject, initial); } }); nameChangedImpl(myProject, initial); }
Example #10
Source File: StatisticsUpdate.java From consulo with Apache License 2.0 | 5 votes |
public void trackStatistics(InsertionContext context) { if (ourPendingUpdate != this) { return; } if (!context.getOffsetMap().containsOffset(CompletionInitializationContext.START_OFFSET)) { return; } final Document document = context.getDocument(); int startOffset = context.getStartOffset(); int tailOffset = context.getEditor().getCaretModel().getOffset(); if (startOffset < 0 || tailOffset <= startOffset) { return; } final RangeMarker marker = document.createRangeMarker(startOffset, tailOffset); final DocumentAdapter listener = new DocumentAdapter() { @Override public void beforeDocumentChange(DocumentEvent e) { if (!marker.isValid() || e.getOffset() > marker.getStartOffset() && e.getOffset() < marker.getEndOffset()) { cancelLastCompletionStatisticsUpdate(); } } }; ourStatsAlarm.addRequest(() -> { if (ourPendingUpdate == this) { applyLastCompletionStatisticsUpdate(); } }, 20 * 1000); document.addDocumentListener(listener); Disposer.register(this, () -> { document.removeDocumentListener(listener); marker.dispose(); ourStatsAlarm.cancelAllRequests(); }); }
Example #11
Source File: MindMapDocumentEditor.java From netbeans-mmd-plugin with Apache License 2.0 | 4 votes |
public MindMapDocumentEditor( final Project project, final VirtualFile file ) { this.project = project; this.file = file; this.panelController = new MindMapPanelControllerImpl(this); this.mindMapPanel = new MindMapPanel(panelController); this.mindMapPanel.putTmpObject("project", project); this.mindMapPanel.putTmpObject("editor", this); this.mindMapPanel.addMindMapListener(this); this.mainScrollPane = new JScrollPane(this.mindMapPanel, JBScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JBScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); // NB! JBScrollPane sometime doesn't show scrollbars so that it replaced by swing panel this.mainScrollPane.getVerticalScrollBar().setUnitIncrement(16); this.mainScrollPane.getVerticalScrollBar().setBlockIncrement(128); this.mainScrollPane.getHorizontalScrollBar().setUnitIncrement(16); this.mainScrollPane.getHorizontalScrollBar().setBlockIncrement(128); this.mainScrollPane.setWheelScrollingEnabled(true); this.mainScrollPane.setAutoscrolls(true); final Document document = FileDocumentManager.getInstance().getDocument(this.file); this.documents = new Document[] {document}; this.mindMapPanel.setDropTarget(new DropTarget(this.mindMapPanel, this)); loadMindMapFromDocument(); this.undoHelper = new UndoHelper(this.project, this); this.undoHelper.addWatchedDocument(getDocument()); this.documentListener = new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { loadMindMapFromDocument(); } }; this.getDocument().addDocumentListener(this.documentListener); DataManager.registerDataProvider(this.mainScrollPane, this); this.findTextPanel = new FindTextPanel(this); this.mainScrollPane.setColumnHeaderView(this.findTextPanel); this.mainScrollPane.getHorizontalScrollBar().addAdjustmentListener(this); this.mainScrollPane.getVerticalScrollBar().addAdjustmentListener(this); this.mainPanel = new JBPanel(new BorderLayout()); this.mainPanel.add(this.mainScrollPane, BorderLayout.CENTER); this.mainPanel.add(this.findTextPanel, BorderLayout.NORTH); }
Example #12
Source File: ChangelistConflictTracker.java From consulo with Apache License 2.0 | 4 votes |
public ChangelistConflictTracker(@Nonnull Project project, @Nonnull ChangeListManager changeListManager, @Nonnull FileStatusManager fileStatusManager, @Nonnull EditorNotifications editorNotifications) { myProject = project; myChangeListManager = changeListManager; myEditorNotifications = editorNotifications; myDocumentManager = FileDocumentManager.getInstance(); myFileStatusManager = fileStatusManager; myCheckSetLock = new Object(); myCheckSet = new HashSet<>(); final Application application = ApplicationManager.getApplication(); final ZipperUpdater zipperUpdater = new ZipperUpdater(300, Alarm.ThreadToUse.SWING_THREAD, project); final Runnable runnable = () -> { if (application.isDisposed() || myProject.isDisposed() || !myProject.isOpen()) { return; } final Set<VirtualFile> localSet; synchronized (myCheckSetLock) { localSet = new HashSet<>(); localSet.addAll(myCheckSet); myCheckSet.clear(); } checkFiles(localSet); }; myDocumentListener = new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { if (!myOptions.TRACKING_ENABLED) { return; } Document document = e.getDocument(); VirtualFile file = myDocumentManager.getFile(document); if (ProjectUtil.guessProjectForFile(file) == myProject) { synchronized (myCheckSetLock) { myCheckSet.add(file); } zipperUpdater.queue(runnable); } } }; myChangeListListener = new ChangeListAdapter() { @Override public void changeListChanged(ChangeList list) { if (myChangeListManager.isDefaultChangeList(list)) { clearChanges(list.getChanges()); } } @Override public void changesMoved(Collection<Change> changes, ChangeList fromList, ChangeList toList) { if (myChangeListManager.isDefaultChangeList(toList)) { clearChanges(changes); } } @Override public void changesRemoved(Collection<Change> changes, ChangeList fromList) { clearChanges(changes); } @Override public void defaultListChanged(ChangeList oldDefaultList, ChangeList newDefaultList) { clearChanges(newDefaultList.getChanges()); } }; }
Example #13
Source File: CopyrightManager.java From consulo with Apache License 2.0 | 4 votes |
@Inject public CopyrightManager(@Nonnull Project project, @Nonnull final EditorFactory editorFactory, @Nonnull final Application application, @Nonnull final FileDocumentManager fileDocumentManager, @Nonnull final ProjectRootManager projectRootManager, @Nonnull final PsiManager psiManager, @Nonnull StartupManager startupManager) { myProject = project; if (myProject.isDefault()) { return; } final NewFileTracker newFileTracker = NewFileTracker.getInstance(); Disposer.register(myProject, newFileTracker::clear); startupManager.runWhenProjectIsInitialized(new Runnable() { @Override public void run() { DocumentListener listener = new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { final Document document = e.getDocument(); final VirtualFile virtualFile = fileDocumentManager.getFile(document); if (virtualFile == null) return; if (!newFileTracker.poll(virtualFile)) return; if (!CopyrightUpdaters.hasExtension(virtualFile)) return; final Module module = projectRootManager.getFileIndex().getModuleForFile(virtualFile); if (module == null) return; final PsiFile file = psiManager.findFile(virtualFile); if (file == null) return; application.invokeLater(new Runnable() { @Override public void run() { if (myProject.isDisposed()) return; if (file.isValid() && file.isWritable()) { final CopyrightProfile opts = getCopyrightOptions(file); if (opts != null) { new UpdateCopyrightProcessor(myProject, module, file).run(); } } } }, ModalityState.NON_MODAL, myProject.getDisposed()); } }; editorFactory.getEventMulticaster().addDocumentListener(listener, myProject); } }); }
Example #14
Source File: AbstractInplaceIntroducer.java From consulo with Apache License 2.0 | 4 votes |
/** * Begins the in-place refactoring operation. * * @return true if the in-place refactoring was successfully started, false if it failed to start and a dialog should be shown instead. */ public boolean startInplaceIntroduceTemplate() { final boolean replaceAllOccurrences = isReplaceAllOccurrences(); final Ref<Boolean> result = new Ref<Boolean>(); CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { @Override public void run() { final String[] names = suggestNames(replaceAllOccurrences, getLocalVariable()); final V variable = createFieldToStartTemplateOn(replaceAllOccurrences, names); boolean started = false; if (variable != null) { int caretOffset = getCaretOffset(); myEditor.getCaretModel().moveToOffset(caretOffset); myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); final LinkedHashSet<String> nameSuggestions = new LinkedHashSet<String>(); nameSuggestions.add(variable.getName()); nameSuggestions.addAll(Arrays.asList(names)); initOccurrencesMarkers(); setElementToRename(variable); updateTitle(getVariable()); started = AbstractInplaceIntroducer.super.performInplaceRefactoring(nameSuggestions); if (started) { myDocumentAdapter = new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { if (myPreview == null) return; final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor); if (templateState != null) { final TextResult value = templateState.getVariableValue(InplaceRefactoring.PRIMARY_VARIABLE_NAME); if (value != null) { updateTitle(getVariable(), value.getText()); } } } }; myEditor.getDocument().addDocumentListener(myDocumentAdapter); updateTitle(getVariable()); if (TemplateManagerImpl.getTemplateState(myEditor) != null) { myEditor.putUserData(ACTIVE_INTRODUCE, AbstractInplaceIntroducer.this); } } } result.set(started); if (!started) { finish(true); } } }, getCommandName(), getCommandName()); return result.get(); }