Search in sources :

Example 1 with CommandAdapter

use of com.intellij.openapi.command.CommandAdapter in project intellij-community by JetBrains.

the class ActionTracker method ignoreCurrentDocumentChange.

void ignoreCurrentDocumentChange() {
    final CommandProcessor commandProcessor = CommandProcessor.getInstance();
    if (commandProcessor.getCurrentCommand() == null)
        return;
    myIgnoreDocumentChanges = true;
    commandProcessor.addCommandListener(new CommandAdapter() {

        @Override
        public void commandFinished(CommandEvent event) {
            commandProcessor.removeCommandListener(this);
            myIgnoreDocumentChanges = false;
        }
    });
}
Also used : CommandAdapter(com.intellij.openapi.command.CommandAdapter) CommandEvent(com.intellij.openapi.command.CommandEvent) CommandProcessor(com.intellij.openapi.command.CommandProcessor)

Example 2 with CommandAdapter

use of com.intellij.openapi.command.CommandAdapter in project intellij-community by JetBrains.

the class TemplateState method initListeners.

private void initListeners() {
    if (isDisposed())
        return;
    myEditorDocumentListener = new DocumentAdapter() {

        @Override
        public void beforeDocumentChange(DocumentEvent e) {
            myDocumentChanged = true;
        }
    };
    myLookupListener = new LookupAdapter() {

        @Override
        public void itemSelected(LookupEvent event) {
            if (isCaretOutsideCurrentSegment(null)) {
                if (isCaretInsideNextVariable()) {
                    nextTab();
                } else {
                    gotoEnd(true);
                }
            }
        }
    };
    LookupManager.getInstance(myProject).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (LookupManager.PROP_ACTIVE_LOOKUP.equals(evt.getPropertyName())) {
                Lookup lookup = (Lookup) evt.getNewValue();
                if (lookup != null) {
                    lookup.addLookupListener(myLookupListener);
                }
            }
        }
    }, this);
    myCommandListener = new CommandAdapter() {

        boolean started = false;

        @Override
        public void commandStarted(CommandEvent event) {
            myDocumentChangesTerminateTemplate = isCaretOutsideCurrentSegment(event.getCommandName());
            started = true;
        }

        @Override
        public void beforeCommandFinished(CommandEvent event) {
            if (started && !isDisposed()) {
                Runnable runnable = () -> afterChangedUpdate();
                final LookupImpl lookup = myEditor != null ? (LookupImpl) LookupManager.getActiveLookup(myEditor) : null;
                if (lookup != null) {
                    lookup.performGuardedChange(runnable);
                } else {
                    runnable.run();
                }
            }
        }
    };
    myCaretListener = new CaretAdapter() {

        @Override
        public void caretAdded(CaretEvent e) {
            if (isMultiCaretMode()) {
                finishTemplateEditing();
            }
        }

        @Override
        public void caretRemoved(CaretEvent e) {
            if (isMultiCaretMode()) {
                finishTemplateEditing();
            }
        }
    };
    if (myEditor != null) {
        myEditor.getCaretModel().addCaretListener(myCaretListener);
    }
    myDocument.addDocumentListener(myEditorDocumentListener, this);
    CommandProcessor.getInstance().addCommandListener(myCommandListener, this);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) CommandAdapter(com.intellij.openapi.command.CommandAdapter) LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) CommandEvent(com.intellij.openapi.command.CommandEvent)

Aggregations

CommandAdapter (com.intellij.openapi.command.CommandAdapter)2 CommandEvent (com.intellij.openapi.command.CommandEvent)2 LookupImpl (com.intellij.codeInsight.lookup.impl.LookupImpl)1 CommandProcessor (com.intellij.openapi.command.CommandProcessor)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1