Search in sources :

Example 76 with AccessToken

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

the class FormReferencesSearcher method processReferencesInUIForms.

private static boolean processReferencesInUIForms(Processor<PsiReference> processor, PsiManager psiManager, PsiField field, GlobalSearchScope scope1, LocalSearchScope filterScope) {
    GlobalSearchScope scope = GlobalSearchScope.projectScope(psiManager.getProject()).intersectWith(scope1);
    final AccessToken token = ReadAction.start();
    PsiClass containingClass = field.getContainingClass();
    if (containingClass == null)
        return true;
    String fieldName;
    try {
        fieldName = field.getName();
    } finally {
        token.finish();
    }
    final List<PsiFile> files = FormClassIndex.findFormsBoundToClass(psiManager.getProject(), containingClass, scope);
    return processReferencesInFiles(files, psiManager, fieldName, field, filterScope, processor);
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken)

Example 77 with AccessToken

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

the class HgRollbackEnvironment method rollbackChanges.

public void rollbackChanges(List<Change> changes, List<VcsException> vcsExceptions, @NotNull RollbackProgressListener listener) {
    if (changes == null || changes.isEmpty()) {
        return;
    }
    List<FilePath> toDelete = new ArrayList<>();
    List<FilePath> filePaths = new LinkedList<>();
    for (Change change : changes) {
        ContentRevision contentRevision;
        if (Change.Type.DELETED == change.getType()) {
            contentRevision = change.getBeforeRevision();
        } else {
            contentRevision = change.getAfterRevision();
        }
        if (contentRevision != null) {
            filePaths.add(contentRevision.getFile());
            if (Change.Type.MOVED == change.getType()) {
                toDelete.add(contentRevision.getFile());
            }
        }
    }
    AccessToken token = DvcsUtil.workingTreeChangeStarted(project);
    try {
        revert(filePaths);
        for (FilePath file : toDelete) {
            listener.accept(file);
            try {
                final File ioFile = file.getIOFile();
                if (ioFile.exists()) {
                    if (!ioFile.delete()) {
                        //noinspection ThrowableInstanceNeverThrown
                        vcsExceptions.add(new VcsException("Unable to delete file: " + file));
                    }
                }
            } catch (Exception e) {
                //noinspection ThrowableInstanceNeverThrown
                vcsExceptions.add(new VcsException("Unable to delete file: " + file, e));
            }
        }
    } finally {
        token.finish();
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) AccessToken(com.intellij.openapi.application.AccessToken) VcsException(com.intellij.openapi.vcs.VcsException) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) Change(com.intellij.openapi.vcs.changes.Change) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) VcsException(com.intellij.openapi.vcs.VcsException)

Example 78 with AccessToken

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

the class HgUpdateCommand method execute.

@Nullable
public HgCommandResult execute() {
    List<String> arguments = new LinkedList<>();
    if (clean) {
        arguments.add("--clean");
    }
    if (!StringUtil.isEmptyOrSpaces(revision)) {
        arguments.add("--rev");
        arguments.add(revision);
    }
    final HgPromptCommandExecutor executor = new HgPromptCommandExecutor(project);
    executor.setShowOutput(true);
    HgCommandResult result;
    AccessToken token = DvcsUtil.workingTreeChangeStarted(project);
    try {
        result = executor.executeInCurrentThread(repo, "update", arguments);
        if (!clean && hasUncommittedChangesConflict(result)) {
            final String message = "<html>Your uncommitted changes couldn't be merged into the requested changeset.<br>" + "Would you like to perform force update and discard them?";
            if (showDiscardChangesConfirmation(project, message) == Messages.OK) {
                arguments.add("-C");
                result = executor.executeInCurrentThread(repo, "update", arguments);
            }
        }
    } finally {
        token.finish();
    }
    VfsUtil.markDirtyAndRefresh(false, true, false, repo);
    return result;
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgPromptCommandExecutor(org.zmlx.hg4idea.execution.HgPromptCommandExecutor) AccessToken(com.intellij.openapi.application.AccessToken) LinkedList(java.util.LinkedList) Nullable(org.jetbrains.annotations.Nullable)

Example 79 with AccessToken

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

the class ExternalSystemImportingTestCase method getModule.

protected Module getModule(final String name) {
    AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
    try {
        Module m = ModuleManager.getInstance(myProject).findModuleByName(name);
        assertNotNull("Module " + name + " not found", m);
        return m;
    } finally {
        accessToken.finish();
    }
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) Module(com.intellij.openapi.module.Module)

Example 80 with AccessToken

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

the class SearchEverywhereAction method doNavigate.

private void doNavigate(final int index) {
    final DataManager dataManager = DataManager.getInstance();
    if (dataManager == null)
        return;
    final Project project = CommonDataKeys.PROJECT.getData(dataManager.getDataContext(getField().getTextEditor()));
    assert project != null;
    final SearchListModel model = getModel();
    if (isMoreItem(index)) {
        final String pattern = myPopupField.getText();
        WidgetID wid = null;
        if (index == model.moreIndex.classes)
            wid = WidgetID.CLASSES;
        else if (index == model.moreIndex.files)
            wid = WidgetID.FILES;
        else if (index == model.moreIndex.settings)
            wid = WidgetID.SETTINGS;
        else if (index == model.moreIndex.actions)
            wid = WidgetID.ACTIONS;
        else if (index == model.moreIndex.symbols)
            wid = WidgetID.SYMBOLS;
        else if (index == model.moreIndex.runConfigurations)
            wid = WidgetID.RUN_CONFIGURATIONS;
        if (wid != null) {
            final WidgetID widgetID = wid;
            myCurrentWorker.doWhenProcessed(() -> {
                myCalcThread = new CalcThread(project, pattern, true);
                myPopupActualWidth = 0;
                myCurrentWorker = myCalcThread.insert(index, widgetID);
            });
            return;
        }
    }
    final String pattern = getField().getText();
    final Object value = myList.getSelectedValue();
    saveHistory(project, pattern, value);
    IdeFocusManager focusManager = IdeFocusManager.findInstanceByComponent(getField().getTextEditor());
    if (myPopup != null && myPopup.isVisible()) {
        myPopup.cancel();
    }
    if (value instanceof BooleanOptionDescription) {
        final BooleanOptionDescription option = (BooleanOptionDescription) value;
        option.setOptionState(!option.isOptionEnabled());
        myList.revalidate();
        myList.repaint();
        getGlobalInstance().doWhenFocusSettlesDown(() -> {
            getGlobalInstance().requestFocus(getField(), true);
        });
        return;
    }
    if (value instanceof OptionsTopHitProvider) {
        //noinspection SSBasedInspection
        SwingUtilities.invokeLater(() -> getField().setText("#" + ((OptionsTopHitProvider) value).getId() + " "));
        return;
    }
    Runnable onDone = null;
    AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
    try {
        if (value instanceof PsiElement) {
            onDone = () -> NavigationUtil.activateFileWithPsiElement((PsiElement) value, true);
            return;
        } else if (isVirtualFile(value)) {
            onDone = () -> OpenSourceUtil.navigate(true, new OpenFileDescriptor(project, (VirtualFile) value));
            return;
        } else if (isActionValue(value) || isSetting(value) || isRunConfiguration(value)) {
            focusManager.requestDefaultFocus(true);
            final Component comp = myContextComponent;
            final AnActionEvent event = myActionEvent;
            IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(() -> {
                Component c = comp;
                if (c == null) {
                    c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
                }
                if (isRunConfiguration(value)) {
                    ChooseRunConfigurationPopup.ItemWrapper itemWrapper = (ChooseRunConfigurationPopup.ItemWrapper) value;
                    RunnerAndConfigurationSettings settings = ObjectUtils.tryCast(itemWrapper.getValue(), RunnerAndConfigurationSettings.class);
                    if (settings != null) {
                        Executor executor = findExecutor(settings);
                        if (executor != null) {
                            itemWrapper.perform(project, executor, dataManager.getDataContext(c));
                        }
                    }
                } else {
                    GotoActionAction.openOptionOrPerformAction(value, pattern, project, c, event);
                    if (isToolWindowAction(value))
                        return;
                }
            });
            return;
        } else if (value instanceof Navigatable) {
            onDone = () -> OpenSourceUtil.navigate(true, (Navigatable) value);
            return;
        }
    } finally {
        token.finish();
        final ActionCallback callback = onFocusLost();
        if (onDone != null) {
            callback.doWhenDone(onDone);
        }
    }
    focusManager.requestDefaultFocus(true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DataManager(com.intellij.ide.DataManager) Navigatable(com.intellij.pom.Navigatable) Project(com.intellij.openapi.project.Project) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) AccessToken(com.intellij.openapi.application.AccessToken) BooleanOptionDescription(com.intellij.ide.ui.search.BooleanOptionDescription) ChooseRunConfigurationPopup(com.intellij.execution.actions.ChooseRunConfigurationPopup) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) OptionsTopHitProvider(com.intellij.ide.ui.OptionsTopHitProvider) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Aggregations

AccessToken (com.intellij.openapi.application.AccessToken)89 VirtualFile (com.intellij.openapi.vfs.VirtualFile)25 Nullable (org.jetbrains.annotations.Nullable)15 Module (com.intellij.openapi.module.Module)12 Document (com.intellij.openapi.editor.Document)10 Project (com.intellij.openapi.project.Project)10 GitRepository (git4idea.repo.GitRepository)9 ArrayList (java.util.ArrayList)8 PsiElement (com.intellij.psi.PsiElement)7 NotNull (org.jetbrains.annotations.NotNull)6 File (java.io.File)5 IOException (java.io.IOException)5 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)4 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)4 CompileContext (com.intellij.openapi.compiler.CompileContext)3 CompileTask (com.intellij.openapi.compiler.CompileTask)3 PsiFile (com.intellij.psi.PsiFile)3 List (java.util.List)3 ProjectComponentReferenceCounter (com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter)2 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)2