Search in sources :

Example 1 with TransactionId

use of com.intellij.openapi.application.TransactionId in project intellij-community by JetBrains.

the class CheckRegExpForm method createUIComponents.

private void createUIComponents() {
    myProject = myRegexpFile.getProject();
    Document document = PsiDocumentManager.getInstance(myProject).getDocument(myRegexpFile);
    final Language language = myRegexpFile.getLanguage();
    final LanguageFileType fileType;
    if (language instanceof RegExpLanguage) {
        fileType = RegExpLanguage.INSTANCE.getAssociatedFileType();
    } else {
        // for correct syntax highlighting
        fileType = new RegExpFileType(language);
    }
    myRegExp = new EditorTextField(document, myProject, fileType);
    final String sampleText = PropertiesComponent.getInstance(myProject).getValue(LAST_EDITED_REGEXP, "Sample Text");
    mySampleText = new EditorTextField(sampleText, myProject, PlainTextFileType.INSTANCE) {

        @Override
        protected void updateBorder(@NotNull EditorEx editor) {
            setupBorder(editor);
        }
    };
    mySampleText.setOneLineMode(false);
    int preferredWidth = Math.max(JBUI.scale(250), myRegExp.getPreferredSize().width);
    myRegExp.setPreferredWidth(preferredWidth);
    mySampleText.setPreferredWidth(preferredWidth);
    myRootPanel = new JPanel(new BorderLayout()) {

        Disposable disposable;

        Alarm updater;

        @Override
        public void addNotify() {
            super.addNotify();
            disposable = Disposer.newDisposable();
            IdeFocusManager.getGlobalInstance().requestFocus(mySampleText, true);
            new AnAction() {

                @Override
                public void actionPerformed(AnActionEvent e) {
                    IdeFocusManager.findInstance().requestFocus(myRegExp.getFocusTarget(), true);
                }
            }.registerCustomShortcutSet(CustomShortcutSet.fromString("shift TAB"), mySampleText);
            updater = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, disposable);
            DocumentAdapter documentListener = new DocumentAdapter() {

                @Override
                public void documentChanged(DocumentEvent e) {
                    update();
                }
            };
            myRegExp.addDocumentListener(documentListener);
            mySampleText.addDocumentListener(documentListener);
            update();
            mySampleText.selectAll();
        }

        public void update() {
            final TransactionId transactionId = TransactionGuard.getInstance().getContextTransaction();
            updater.cancelAllRequests();
            if (!updater.isDisposed()) {
                updater.addRequest(() -> {
                    final RegExpMatchResult result = isMatchingText(myRegexpFile, mySampleText.getText());
                    TransactionGuard.getInstance().submitTransaction(myProject, transactionId, () -> setBalloonState(result));
                }, 200);
            }
        }

        @Override
        public void removeNotify() {
            super.removeNotify();
            Disposer.dispose(disposable);
            PropertiesComponent.getInstance(myProject).setValue(LAST_EDITED_REGEXP, mySampleText.getText());
        }
    };
    myRootPanel.setBorder(JBUI.Borders.empty(UIUtil.DEFAULT_VGAP, UIUtil.DEFAULT_HGAP));
}
Also used : Disposable(com.intellij.openapi.Disposable) EditorEx(com.intellij.openapi.editor.ex.EditorEx) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Document(com.intellij.openapi.editor.Document) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) TransactionId(com.intellij.openapi.application.TransactionId) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) EditorTextField(com.intellij.ui.EditorTextField) Alarm(com.intellij.util.Alarm)

Example 2 with TransactionId

use of com.intellij.openapi.application.TransactionId in project intellij-community by JetBrains.

the class AutoPopupController method runTransactionWithEverythingCommitted.

public static void runTransactionWithEverythingCommitted(@NotNull final Project project, @NotNull final Runnable runnable) {
    TransactionGuard guard = TransactionGuard.getInstance();
    TransactionId id = guard.getContextTransaction();
    final PsiDocumentManager pdm = PsiDocumentManager.getInstance(project);
    pdm.performLaterWhenAllCommitted(() -> guard.submitTransaction(project, id, () -> {
        if (pdm.hasUncommitedDocuments()) {
            // no luck, will try later
            runTransactionWithEverythingCommitted(project, runnable);
        } else {
            runnable.run();
        }
    }));
}
Also used : TransactionGuard(com.intellij.openapi.application.TransactionGuard) TransactionId(com.intellij.openapi.application.TransactionId) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 3 with TransactionId

use of com.intellij.openapi.application.TransactionId in project intellij-community by JetBrains.

the class InferNullityAnnotationsAction method restartAnalysis.

protected void restartAnalysis(final Project project, final AnalysisScope scope) {
    TransactionGuard guard = TransactionGuard.getInstance();
    TransactionId id = guard.getContextTransaction();
    DumbService.getInstance(project).smartInvokeLater(() -> TransactionGuard.getInstance().submitTransaction(project, id, () -> {
        if (DumbService.isDumb(project)) {
            restartAnalysis(project, scope);
        } else {
            analyze(project, scope);
        }
    }));
}
Also used : TransactionGuard(com.intellij.openapi.application.TransactionGuard) TransactionId(com.intellij.openapi.application.TransactionId)

Aggregations

TransactionId (com.intellij.openapi.application.TransactionId)3 TransactionGuard (com.intellij.openapi.application.TransactionGuard)2 Language (com.intellij.lang.Language)1 Disposable (com.intellij.openapi.Disposable)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 Document (com.intellij.openapi.editor.Document)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)1 EditorTextField (com.intellij.ui.EditorTextField)1 Alarm (com.intellij.util.Alarm)1