Example usage for com.intellij.openapi.command CommandAdapter CommandAdapter

List of usage examples for com.intellij.openapi.command CommandAdapter CommandAdapter

Introduction

In this page you can find the example usage for com.intellij.openapi.command CommandAdapter CommandAdapter.

Prototype

CommandAdapter

Source Link

Usage

From source file:com.intellij.codeInsight.template.impl.TemplateState.java

License:Apache License

private void initListeners() {
    myEditorDocumentListener = new DocumentAdapter() {
        @Override/*from  w ww.j av a2 s.  com*/
        public void beforeDocumentChange(DocumentEvent e) {
            myDocumentChanged = true;
        }
    };

    myCommandListener = new CommandAdapter() {
        boolean started = false;

        @Override
        public void commandStarted(CommandEvent event) {
            if (myEditor != null) {
                final int offset = myEditor.getCaretModel().getOffset();
                myDocumentChangesTerminateTemplate = myCurrentSegmentNumber >= 0
                        && (offset < mySegments.getSegmentStart(myCurrentSegmentNumber)
                                || offset > mySegments.getSegmentEnd(myCurrentSegmentNumber));
            }
            started = true;
        }

        @Override
        public void beforeCommandFinished(CommandEvent event) {
            if (started) {
                Runnable runnable = new Runnable() {
                    @Override
                    public void run() {
                        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(false);
            }
        }

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

    if (myEditor != null) {
        myEditor.getCaretModel().addCaretListener(myCaretListener);
    }
    myDocument.addDocumentListener(myEditorDocumentListener, this);
    CommandProcessor.getInstance().addCommandListener(myCommandListener, this);
}

From source file:com.intellij.util.xml.ui.UndoHelper.java

License:Apache License

public UndoHelper(final Project project, final Committable committable) {
    myProject = project;//from w  w  w .  j av  a  2  s  .co  m
    final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
    CommandProcessor.getInstance().addCommandListener(new CommandAdapter() {
        public void commandStarted(CommandEvent event) {
            undoTransparentActionStarted();
        }

        public void undoTransparentActionStarted() {
            myDirty = false;
        }

        public void undoTransparentActionFinished() {
            if (myDirty) {
                psiDocumentManager.commitAllDocuments();
                committable.reset();
            }
        }

        public void commandFinished(CommandEvent event) {
            undoTransparentActionFinished();
        }
    }, committable);
}

From source file:org.community.intellij.plugins.communitycase.vfs.RootTracker.java

License:Apache License

/**
 * The constructor/*from   w  ww.jav a  2 s.c o  m*/
 *
 * @param project     the project instance
 * @param multicaster the listeners to notify
 */
public RootTracker(Vcs vcs, @NotNull Project project, @NotNull RootsListener multicaster) {

    myMulticaster = multicaster;
    if (project.isDefault()) {
        throw new IllegalArgumentException("The project must not be default");
    }
    myProject = project;
    myProjectRoots = ProjectRootManager.getInstance(myProject);
    myQueue = new MergingUpdateQueue("queue", 500, true, null, project, null, false);
    myVcs = vcs;
    myVcsManager = ProjectLevelVcsManager.getInstance(project);
    myVcsManager.addVcsListener(this);
    myLocalFileSystem = LocalFileSystem.getInstance();
    myMessageBusConnection = myProject.getMessageBus().connect();
    myMessageBusConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
        public void beforeRootsChange(ModuleRootEvent event) {
            // do nothing
        }

        public void rootsChanged(ModuleRootEvent event) {
            invalidate();
        }
    });
    myCommandListener = new CommandAdapter() {
        @Override
        public void commandFinished(CommandEvent event) {
            if (!myRootsInvalidated.compareAndSet(true, false)) {
                return;
            }
            scheduleRootsCheck(false);
        }
    };
    CommandProcessor.getInstance().addCommandListener(myCommandListener);
    myFileListener = new MyFileListener();
    VirtualFileManagerEx fileManager = (VirtualFileManagerEx) VirtualFileManager.getInstance();
    fileManager.addVirtualFileListener(myFileListener);
    myVirtualFileManagerListener = new VirtualFileManagerAdapter() {
        @Override
        public void afterRefreshFinish(boolean asynchonous) {
            if (!myRootsInvalidated.compareAndSet(true, false)) {
                return;
            }
            scheduleRootsCheck(false);
        }
    };
    fileManager.addVirtualFileManagerListener(myVirtualFileManagerListener);
    StartupManager.getInstance(myProject).runWhenProjectIsInitialized(new Runnable() {
        public void run() {
            myIsEnabled.set(true);
            scheduleRootsCheck(true);
        }
    });
}