Search in sources :

Example 91 with AccessToken

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

the class PyStackFrame method customizePresentation.

@Override
public void customizePresentation(@NotNull ColoredTextContainer component) {
    component.setIcon(AllIcons.Debugger.StackFrame);
    if (myPosition == null) {
        component.append("<frame not available>", SimpleTextAttributes.GRAY_ATTRIBUTES);
        return;
    }
    boolean isExternal = true;
    final VirtualFile file = myPosition.getFile();
    AccessToken lock = ApplicationManager.getApplication().acquireReadActionLock();
    try {
        final Document document = FileDocumentManager.getInstance().getDocument(file);
        if (document != null) {
            isExternal = !ProjectRootManager.getInstance(myProject).getFileIndex().isInContent(file);
        }
    } finally {
        lock.finish();
    }
    component.append(myFrameInfo.getName(), gray(SimpleTextAttributes.REGULAR_ATTRIBUTES, isExternal));
    component.append(", ", gray(SimpleTextAttributes.REGULAR_ATTRIBUTES, isExternal));
    component.append(myPosition.getFile().getName(), gray(SimpleTextAttributes.REGULAR_ATTRIBUTES, isExternal));
    component.append(":", gray(SimpleTextAttributes.REGULAR_ATTRIBUTES, isExternal));
    component.append(Integer.toString(myPosition.getLine() + 1), gray(SimpleTextAttributes.REGULAR_ATTRIBUTES, isExternal));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AccessToken(com.intellij.openapi.application.AccessToken) Document(com.intellij.openapi.editor.Document)

Example 92 with AccessToken

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

the class PydevConsoleCommunication method execIPythonEditor.

private Object execIPythonEditor(Vector params) {
    String path = (String) params.get(0);
    int line = Integer.parseInt((String) params.get(1));
    final VirtualFile file = StringUtil.isEmpty(path) ? null : LocalFileSystem.getInstance().findFileByPath(path);
    if (file != null) {
        ApplicationManager.getApplication().invokeLater(() -> {
            AccessToken at = ApplicationManager.getApplication().acquireReadActionLock();
            try {
                FileEditorManager.getInstance(myProject).openFile(file, true);
            } finally {
                at.finish();
            }
        });
        return Boolean.TRUE;
    }
    return Boolean.FALSE;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AccessToken(com.intellij.openapi.application.AccessToken)

Example 93 with AccessToken

use of com.intellij.openapi.application.AccessToken in project google-cloud-intellij by GoogleCloudPlatform.

the class ProjectRepositoryValidator method unstash.

private void unstash(@NotNull final Project project, @NotNull final Ref<StashInfo> targetStash, @NotNull final VirtualFile root) {
    if (repoState.getSourceRepository() == null || repoState.getOriginalBranchName() == null || (!repoState.getOriginalBranchName().equals(repoState.getSourceRepository().getCurrentBranchName()) && !repoState.getOriginalBranchName().equals(repoState.getSourceRepository().getCurrentRevision()))) {
        Messages.showErrorDialog(GctBundle.getString("clouddebug.erroroncheckout", repoState.getOriginalBranchName()), "Error");
        return;
    }
    final GitLineHandler handler = new GitLineHandler(project, root, GitCommand.STASH);
    handler.addParameters("apply");
    handler.addParameters("--index");
    addStashParameter(project, handler, targetStash.get().getStash());
    final AtomicBoolean conflict = new AtomicBoolean();
    handler.addLineListener(new GitLineHandlerAdapter() {

        @Override
        public void onLineAvailable(String line, Key outputType) {
            if (line.contains("Merge conflict")) {
                conflict.set(true);
            }
        }
    });
    GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector = new GitUntrackedFilesOverwrittenByOperationDetector(root);
    GitLocalChangesWouldBeOverwrittenDetector localChangesDetector = new GitLocalChangesWouldBeOverwrittenDetector(root, MERGE);
    handler.addLineListener(untrackedFilesDetector);
    handler.addLineListener(localChangesDetector);
    AccessToken token = DvcsUtil.workingTreeChangeStarted(project);
    try {
        final Ref<GitCommandResult> result = Ref.create();
        ProgressManager.getInstance().run(new Task.Modal(handler.project(), GitBundle.getString("unstash.unstashing"), false) {

            @Override
            public void run(@NotNull final ProgressIndicator indicator) {
                indicator.setIndeterminate(true);
                handler.addLineListener(new GitHandlerUtil.GitLineHandlerListenerProgress(indicator, handler, "stash", false));
                Git git = ServiceManager.getService(Git.class);
                result.set(git.runCommand(new Computable.PredefinedValueComputable<GitLineHandler>(handler)));
            }
        });
        ServiceManager.getService(project, GitPlatformFacade.class).hardRefresh(root);
        GitCommandResult res = result.get();
        if (conflict.get()) {
            Messages.showDialog(GctBundle.getString("clouddebug.unstashmergeconflicts"), "Merge Conflicts", new String[] { "Ok" }, 0, Messages.getErrorIcon());
        } else if (untrackedFilesDetector.wasMessageDetected()) {
            GitUntrackedFilesHelper.notifyUntrackedFilesOverwrittenBy(project, root, untrackedFilesDetector.getRelativeFilePaths(), "unstash", null);
        } else if (localChangesDetector.wasMessageDetected()) {
            LocalChangesWouldBeOverwrittenHelper.showErrorDialog(project, root, "unstash", localChangesDetector.getRelativeFilePaths());
        } else if (!res.success()) {
            GitUIUtil.showOperationErrors(project, handler.errors(), handler.printableCommandLine());
        } else if (res.success()) {
            ProgressManager.getInstance().run(new Task.Modal(project, GctBundle.getString("clouddebug.removestashx", targetStash.get().getStash()), false) {

                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    if (project == null) {
                        return;
                    }
                    final GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.STASH);
                    h.addParameters("drop");
                    addStashParameter(project, h, targetStash.get().getStash());
                    try {
                        h.run();
                        h.unsilence();
                    } catch (final VcsException ex) {
                        ApplicationManager.getApplication().invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                GitUIUtil.showOperationError(project, ex, h.printableCommandLine());
                            }
                        });
                    }
                }
            });
        }
    } finally {
        DvcsUtil.workingTreeChangeFinished(project, token);
    }
}
Also used : GitLineHandler(git4idea.commands.GitLineHandler) Task(com.intellij.openapi.progress.Task) GitSimpleHandler(git4idea.commands.GitSimpleHandler) GitLocalChangesWouldBeOverwrittenDetector(git4idea.commands.GitLocalChangesWouldBeOverwrittenDetector) GitPlatformFacade(git4idea.GitPlatformFacade) GitUntrackedFilesOverwrittenByOperationDetector(git4idea.commands.GitUntrackedFilesOverwrittenByOperationDetector) GitCommandResult(git4idea.commands.GitCommandResult) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Git(git4idea.commands.Git) AccessToken(com.intellij.openapi.application.AccessToken) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) GitLineHandlerAdapter(git4idea.commands.GitLineHandlerAdapter) Key(com.intellij.openapi.util.Key) Computable(com.intellij.openapi.util.Computable)

Example 94 with AccessToken

use of com.intellij.openapi.application.AccessToken in project ballerina by ballerina-lang.

the class BallerinaDebugProcess method doSetBreakpoints.

private void doSetBreakpoints() {
    AccessToken token = ReadAction.start();
    try {
        getSession().initBreakpoints();
    } finally {
        token.finish();
        token.close();
    }
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken)

Example 95 with AccessToken

use of com.intellij.openapi.application.AccessToken in project azure-tools-for-java by Microsoft.

the class LibrariesConfigurationDialog method addLibrary.

private void addLibrary() {
    AddLibraryWizardModel model = new AddLibraryWizardModel(module);
    AddLibraryWizardDialog wizard = new AddLibraryWizardDialog(model);
    wizard.setTitle(message("addLibraryTitle"));
    wizard.show();
    if (wizard.isOK()) {
        AzureLibrary azureLibrary = model.getSelectedLibrary();
        final LibrariesContainer.LibraryLevel level = LibrariesContainer.LibraryLevel.MODULE;
        AccessToken token = WriteAction.start();
        try {
            final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
            for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
                if (orderEntry instanceof ModuleLibraryOrderEntryImpl && azureLibrary.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
                    AzureTaskManager.getInstance().runLater(() -> PluginUtil.displayErrorDialog(message("error"), message("libraryExistsError")));
                    return;
                }
            }
            Library newLibrary = LibrariesContainerFactory.createContainer(modifiableModel).createLibrary(azureLibrary.getName(), level, new ArrayList<OrderRoot>());
            if (model.isExported()) {
                for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
                    if (orderEntry instanceof ModuleLibraryOrderEntryImpl && azureLibrary.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
                        ((ModuleLibraryOrderEntryImpl) orderEntry).setExported(true);
                        break;
                    }
                }
            }
            Library.ModifiableModel newLibraryModel = newLibrary.getModifiableModel();
            // if there is separate resources folder
            if (azureLibrary.getLocation() != null) {
                File file = new File(String.format("%s%s%s", AzurePlugin.pluginFolder, File.separator, azureLibrary.getLocation()));
                AddLibraryUtility.addLibraryRoot(file, newLibraryModel);
            }
            // if some files already contained in plugin dependencies, take them from there - true for azure sdk library
            if (azureLibrary.getFiles().length > 0) {
                AddLibraryUtility.addLibraryFiles(new File(PluginHelper.getAzureLibLocation()), newLibraryModel, azureLibrary.getFiles());
            }
            newLibraryModel.commit();
            modifiableModel.commit();
            ((DefaultListModel) librariesList.getModel()).addElement(azureLibrary);
            tempList.add(azureLibrary);
        } catch (Exception ex) {
            PluginUtil.displayErrorDialogAndLog(message("error"), message("addLibraryError"), ex);
        } finally {
            token.finish();
        }
        LocalFileSystem.getInstance().findFileByPath(PluginUtil.getModulePath(module)).refresh(true, true);
    }
}
Also used : ModuleLibraryOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) OrderEntry(com.intellij.openapi.roots.OrderEntry) AccessToken(com.intellij.openapi.application.AccessToken) LibrariesContainer(com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer) Library(com.intellij.openapi.roots.libraries.Library) File(java.io.File)

Aggregations

AccessToken (com.intellij.openapi.application.AccessToken)97 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 Nullable (org.jetbrains.annotations.Nullable)15 Module (com.intellij.openapi.module.Module)13 Project (com.intellij.openapi.project.Project)12 Document (com.intellij.openapi.editor.Document)10 GitRepository (git4idea.repo.GitRepository)9 ArrayList (java.util.ArrayList)9 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 PsiFile (com.intellij.psi.PsiFile)4 List (java.util.List)4 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)4 ReadAction (com.intellij.openapi.application.ReadAction)3 CompileContext (com.intellij.openapi.compiler.CompileContext)3 CompileTask (com.intellij.openapi.compiler.CompileTask)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3