Search in sources :

Example 11 with DocumentListener

use of com.intellij.openapi.editor.event.DocumentListener in project intellij-community by JetBrains.

the class DocumentImpl method beforeChangedUpdate.

private void beforeChangedUpdate(DocumentEvent event) {
    Application app = ApplicationManager.getApplication();
    if (app != null) {
        FileDocumentManager manager = FileDocumentManager.getInstance();
        VirtualFile file = manager.getFile(this);
        if (file != null && !file.isValid()) {
            LOG.error("File of this document has been deleted.");
        }
    }
    assertInsideCommand();
    // initialize line set to track changed lines
    getLineSet();
    if (!ShutDownTracker.isShutdownHookRunning()) {
        DocumentListener[] listeners = getListeners();
        for (int i = listeners.length - 1; i >= 0; i--) {
            try {
                listeners[i].beforeDocumentChange(event);
            } catch (Throwable e) {
                LOG.error(e);
            }
        }
    }
    myEventsHandling = true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DocumentListener(com.intellij.openapi.editor.event.DocumentListener) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Application(com.intellij.openapi.application.Application)

Example 12 with DocumentListener

use of com.intellij.openapi.editor.event.DocumentListener in project intellij-community by JetBrains.

the class DocumentImpl method changedUpdate.

private void changedUpdate(@NotNull DocumentEvent event, long newModificationStamp, @NotNull CharSequence prevText) {
    try {
        if (LOG.isDebugEnabled())
            LOG.debug(event.toString());
        assert event.getOldFragment().length() == event.getOldLength() : "event.getOldFragment().length() = " + event.getOldFragment().length() + "; event.getOldLength() = " + event.getOldLength();
        assert event.getNewFragment().length() == event.getNewLength() : "event.getNewFragment().length() = " + event.getNewFragment().length() + "; event.getNewLength() = " + event.getNewLength();
        assert prevText.length() + event.getNewLength() - event.getOldLength() == getTextLength() : "prevText.length() = " + prevText.length() + "; event.getNewLength() = " + event.getNewLength() + "; event.getOldLength() = " + event.getOldLength() + "; getTextLength() = " + getTextLength();
        myLineSet = getLineSet().update(prevText, event.getOffset(), event.getOffset() + event.getOldLength(), event.getNewFragment(), event.isWholeTextReplaced());
        assert getTextLength() == myLineSet.getLength() : "getTextLength() = " + getTextLength() + "; myLineSet.getLength() = " + myLineSet.getLength();
        myFrozen = null;
        setModificationStamp(newModificationStamp);
        if (!ShutDownTracker.isShutdownHookRunning()) {
            DocumentListener[] listeners = getListeners();
            for (DocumentListener listener : listeners) {
                try {
                    listener.documentChanged(event);
                } catch (ProcessCanceledException e) {
                    if (!myAssertThreading) {
                        throw e;
                    } else {
                        LOG.error("ProcessCanceledException must not be thrown from document listeners for real document", new Throwable(e));
                    }
                } catch (Throwable e) {
                    LOG.error(e);
                }
            }
        }
    } finally {
        myEventsHandling = false;
    }
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 13 with DocumentListener

use of com.intellij.openapi.editor.event.DocumentListener in project intellij-plugins by JetBrains.

the class FlashRunConfigurationForm method initMainClassRelatedControls.

private void initMainClassRelatedControls() {
    myOverrideMainClassCheckBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            if (myOverrideMainClassCheckBox.isSelected()) {
                updateOutputFileName(myOutputFileNameTextField, false);
            }
            updateControls();
            if (myMainClassComponent.isEnabled()) {
                IdeFocusManager.getInstance(myProject).requestFocus(myMainClassComponent.getChildComponent(), true);
            }
        }
    });
    myMainClassComponent.addDocumentListener(new DocumentListener() {

        @Override
        public void documentChanged(final DocumentEvent e) {
            final String shortName = StringUtil.getShortName(myMainClassComponent.getText().trim());
            if (!shortName.isEmpty()) {
                myOutputFileNameTextField.setText(shortName + ".swf");
            }
        }
    });
    myOutputFileNameTextField.getDocument().addDocumentListener(new com.intellij.ui.DocumentAdapter() {

        @Override
        protected void textChanged(final javax.swing.event.DocumentEvent e) {
            final FlexBuildConfiguration bc = myBCCombo.getBC();
            if (bc != null && bc.getTargetPlatform() == TargetPlatform.Web) {
                updateBCOutputLabel(bc);
            }
        }
    });
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener) ActionEvent(java.awt.event.ActionEvent) FlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) ActionListener(java.awt.event.ActionListener)

Example 14 with DocumentListener

use of com.intellij.openapi.editor.event.DocumentListener in project android by JetBrains.

the class EditLogFilterDialog method createEditorFields.

private void createEditorFields() {
    myNameFieldLabel.setLabelFor(myFilterNameField);
    myLogMessageField = new RegexFilterComponent(LOG_FILTER_MESSAGE_HISTORY, FILTER_HISTORY_SIZE);
    myLogMessageFieldWrapper.add(myLogMessageField);
    myLogMessageLabel.setLabelFor(myLogMessageField);
    myTagField = new RegexFilterComponent(LOG_FILTER_TAG_HISTORY, FILTER_HISTORY_SIZE);
    myTagFieldWrapper.add(myTagField);
    myLogTagLabel.setLabelFor(myTagField);
    myPidField = new TextFieldWithAutoCompletion<>(myProject, new TextFieldWithAutoCompletion.StringsCompletionProvider(null, null) {

        @NotNull
        @Override
        public Collection<String> getItems(String prefix, boolean cached, CompletionParameters parameters) {
            parseExistingMessagesIfNecessary();
            setItems(myUsedPids);
            return super.getItems(prefix, cached, parameters);
        }

        @Override
        public int compare(String item1, String item2) {
            final int pid1 = Integer.parseInt(item1);
            final int pid2 = Integer.parseInt(item2);
            return Comparing.compare(pid1, pid2);
        }
    }, true, null);
    myPidFieldWrapper.add(myPidField);
    myPidLabel.setLabelFor(myPidField);
    myPackageNameField = new RegexFilterComponent(LOG_FILTER_PACKAGE_NAME_HISTORY, FILTER_HISTORY_SIZE);
    myPackageNameFieldWrapper.add(myPackageNameField);
    myPackageNameLabel.setLabelFor(myPackageNameField);
    myLogLevelCombo.setModel(new EnumComboBoxModel<>(Log.LogLevel.class));
    myLogLevelCombo.setRenderer(new ListCellRendererWrapper() {

        @Override
        public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
            if (value != null) {
                setText(StringUtil.capitalize(((Log.LogLevel) value).getStringValue().toLowerCase()));
            }
        }
    });
    myLogLevelCombo.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (myActiveFilter == null) {
                return;
            }
            Log.LogLevel selectedItem = (Log.LogLevel) myLogLevelCombo.getSelectedItem();
            myActiveFilter.setLogLevel(selectedItem.getStringValue());
        }
    });
    final Key<JComponent> componentKey = new Key<>("myComponent");
    myFilterNameField.getDocument().putUserData(componentKey, myFilterNameField);
    myPidField.getDocument().putUserData(componentKey, myPidField);
    DocumentListener l = new DocumentListener() {

        @Override
        public void documentChanged(DocumentEvent e) {
            if (myActiveFilter == null) {
                return;
            }
            String text = e.getDocument().getText().trim();
            JComponent src = e.getDocument().getUserData(componentKey);
            if (src == myPidField) {
                myActiveFilter.setPid(text);
            } else if (src == myFilterNameField) {
                int index = myFiltersList.getSelectedIndex();
                if (index != -1) {
                    myFiltersListModel.setElementAt(text, index);
                }
                myActiveFilter.setName(text);
            }
        }
    };
    myFilterNameField.getDocument().addDocumentListener(l);
    myPidField.getDocument().addDocumentListener(l);
    RegexFilterComponent.Listener rl = new RegexFilterComponent.Listener() {

        @Override
        public void filterChanged(RegexFilterComponent filter) {
            if (myActiveFilter == null) {
                return;
            }
            if (filter == myTagField) {
                myActiveFilter.setLogTagPattern(filter.getFilter());
                myActiveFilter.setLogTagIsRegex(filter.isRegex());
            } else if (filter == myLogMessageField) {
                myActiveFilter.setLogMessagePattern(filter.getFilter());
                myActiveFilter.setLogMessageIsRegex(filter.isRegex());
            } else if (filter == myPackageNameField) {
                myActiveFilter.setPackageNamePattern(filter.getFilter());
                myActiveFilter.setPackageNameIsRegex(filter.isRegex());
            }
        }
    };
    myTagField.addRegexListener(rl);
    myLogMessageField.addRegexListener(rl);
    myPackageNameField.addRegexListener(rl);
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener) DocumentListener(com.intellij.openapi.editor.event.DocumentListener) ActionListener(java.awt.event.ActionListener) ListSelectionListener(javax.swing.event.ListSelectionListener) Log(com.android.ddmlib.Log) ActionEvent(java.awt.event.ActionEvent) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) CompletionParameters(com.intellij.codeInsight.completion.CompletionParameters) ActionListener(java.awt.event.ActionListener) Key(com.intellij.openapi.util.Key)

Example 15 with DocumentListener

use of com.intellij.openapi.editor.event.DocumentListener in project android by JetBrains.

the class TemplateParameterStep2 method addJBDocumentListener.

private void addJBDocumentListener(com.intellij.openapi.editor.Document doc, final JComponent textField) {
    DocumentListener listener = new DocumentListener() {

        @Override
        public void documentChanged(DocumentEvent event) {
            saveState(textField);
        }
    };
    Disposable disposable = getDisposable();
    if (disposable != null) {
        doc.addDocumentListener(listener, disposable);
    } else {
        doc.addDocumentListener(listener);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) DocumentListener(com.intellij.openapi.editor.event.DocumentListener) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Aggregations

DocumentListener (com.intellij.openapi.editor.event.DocumentListener)22 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)13 Document (com.intellij.openapi.editor.Document)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Editor (com.intellij.openapi.editor.Editor)3 EditorTextField (com.intellij.ui.EditorTextField)3 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 TextEditor (com.intellij.openapi.fileEditor.TextEditor)2 PsiFile (com.intellij.psi.PsiFile)2 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)2 EditorComboBoxEditor (com.intellij.ui.EditorComboBoxEditor)2 EditorComboBoxRenderer (com.intellij.ui.EditorComboBoxRenderer)2 StringComboboxEditor (com.intellij.ui.StringComboboxEditor)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 Log (com.android.ddmlib.Log)1 CompletionParameters (com.intellij.codeInsight.completion.CompletionParameters)1 DocumentContent (com.intellij.diff.contents.DocumentContent)1 Language (com.intellij.lang.Language)1