Search in sources :

Example 1 with CommandEvent

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

the class CoreCommandProcessor method fireCommandStarted.

private void fireCommandStarted() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    CommandDescriptor currentCommand = myCurrentCommand;
    CommandEvent event = new CommandEvent(this, currentCommand.myCommand, currentCommand.myName, currentCommand.myGroupId, currentCommand.myProject, currentCommand.myUndoConfirmationPolicy, currentCommand.myShouldRecordActionForActiveDocument, currentCommand.myDocument);
    for (CommandListener listener : myListeners) {
        try {
            listener.commandStarted(event);
        } catch (Throwable e) {
            CommandLog.LOG.error(e);
        }
    }
}
Also used : CommandListener(com.intellij.openapi.command.CommandListener) CommandEvent(com.intellij.openapi.command.CommandEvent)

Example 2 with CommandEvent

use of com.intellij.openapi.command.CommandEvent 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 3 with CommandEvent

use of com.intellij.openapi.command.CommandEvent 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)

Example 4 with CommandEvent

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

the class CoreCommandProcessor method fireCommandFinished.

protected void fireCommandFinished() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    CommandDescriptor currentCommand = myCurrentCommand;
    CommandEvent event = new CommandEvent(this, currentCommand.myCommand, currentCommand.myName, currentCommand.myGroupId, currentCommand.myProject, currentCommand.myUndoConfirmationPolicy, currentCommand.myShouldRecordActionForActiveDocument, currentCommand.myDocument);
    try {
        for (CommandListener listener : myListeners) {
            try {
                listener.beforeCommandFinished(event);
            } catch (Throwable e) {
                CommandLog.LOG.error(e);
            }
        }
    } finally {
        myCurrentCommand = null;
        for (CommandListener listener : myListeners) {
            try {
                listener.commandFinished(event);
            } catch (Throwable e) {
                CommandLog.LOG.error(e);
            }
        }
    }
}
Also used : CommandListener(com.intellij.openapi.command.CommandListener) CommandEvent(com.intellij.openapi.command.CommandEvent)

Aggregations

CommandEvent (com.intellij.openapi.command.CommandEvent)4 CommandAdapter (com.intellij.openapi.command.CommandAdapter)2 CommandListener (com.intellij.openapi.command.CommandListener)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