Search in sources :

Example 1 with LocalHistoryAction

use of com.intellij.history.LocalHistoryAction in project intellij-community by JetBrains.

the class BasicAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    if (isEmpty(files))
        return;
    SvnVcs vcs = SvnVcs.getInstance(project);
    if (!ProjectLevelVcsManager.getInstance(project).checkAllFilesAreUnder(vcs, files))
        return;
    project.save();
    String actionName = getActionName();
    LocalHistoryAction action = LocalHistory.getInstance().startAction(actionName);
    AbstractVcsHelper helper = AbstractVcsHelper.getInstance(project);
    try {
        List<VcsException> exceptions = helper.runTransactionRunnable(vcs, exceptionList -> {
            VirtualFile badFile = null;
            try {
                if (isBatchAction()) {
                    batchExecute(vcs, files, e.getDataContext());
                } else {
                    for (VirtualFile file : files) {
                        badFile = file;
                        execute(vcs, file, e.getDataContext());
                    }
                }
            } catch (VcsException ex) {
                ex.setVirtualFile(badFile);
                exceptionList.add(ex);
            }
        }, null);
        helper.showErrors(exceptions, actionName);
    } finally {
        action.finish();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) AbstractVcsHelper(com.intellij.openapi.vcs.AbstractVcsHelper) VcsException(com.intellij.openapi.vcs.VcsException) LocalHistoryAction(com.intellij.history.LocalHistoryAction) SvnVcs(org.jetbrains.idea.svn.SvnVcs)

Example 2 with LocalHistoryAction

use of com.intellij.history.LocalHistoryAction in project intellij-community by JetBrains.

the class GetVersionAction method refreshFile.

private static void refreshFile(@NotNull FilePath filePath, @NotNull VcsFileRevision revision, @NotNull Project project) {
    Runnable refresh = null;
    VirtualFile vf = filePath.getVirtualFile();
    if (vf == null) {
        LocalHistoryAction action = startLocalHistoryAction(filePath, revision);
        VirtualFile vp = filePath.getVirtualFileParent();
        if (vp != null) {
            refresh = () -> vp.refresh(false, true, action::finish);
        }
    } else {
        refresh = () -> vf.refresh(false, false);
    }
    if (refresh != null) {
        ProgressManager.getInstance().runProcessWithProgressSynchronously(refresh, "Refreshing Files...", false, project);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalHistoryAction(com.intellij.history.LocalHistoryAction)

Example 3 with LocalHistoryAction

use of com.intellij.history.LocalHistoryAction in project intellij-community by JetBrains.

the class MigrationProcessor method performRefactoring.

protected void performRefactoring(@NotNull UsageInfo[] usages) {
    final PsiMigration psiMigration = PsiMigrationManager.getInstance(myProject).startMigration();
    LocalHistoryAction a = LocalHistory.getInstance().startAction(getCommandName());
    myRefsToShorten = new ArrayList<>();
    try {
        boolean sameShortNames = false;
        for (int i = 0; i < myMigrationMap.getEntryCount(); i++) {
            MigrationMapEntry entry = myMigrationMap.getEntryAt(i);
            String newName = entry.getNewName();
            PsiElement element = entry.getType() == MigrationMapEntry.PACKAGE ? MigrationUtil.findOrCreatePackage(myProject, psiMigration, newName) : MigrationUtil.findOrCreateClass(myProject, psiMigration, newName);
            MigrationUtil.doMigration(element, newName, usages, myRefsToShorten);
            if (!sameShortNames && Comparing.strEqual(StringUtil.getShortName(entry.getOldName()), StringUtil.getShortName(entry.getNewName()))) {
                sameShortNames = true;
            }
        }
        if (!sameShortNames) {
            myRefsToShorten.clear();
        }
    } finally {
        a.finish();
        psiMigration.finish();
    }
}
Also used : LocalHistoryAction(com.intellij.history.LocalHistoryAction) PsiElement(com.intellij.psi.PsiElement) PsiMigration(com.intellij.psi.PsiMigration)

Example 4 with LocalHistoryAction

use of com.intellij.history.LocalHistoryAction in project intellij-community by JetBrains.

the class ExtractSuperclassHandler method doRefactoring.

// invoked inside Command and Atomic action
private static void doRefactoring(final Project project, final PsiClass subclass, final ExtractSuperclassDialog dialog) {
    final String superclassName = dialog.getExtractedSuperName();
    final PsiDirectory targetDirectory = dialog.getTargetDirectory();
    final MemberInfo[] selectedMemberInfos = ArrayUtil.toObjectArray(dialog.getSelectedMemberInfos(), MemberInfo.class);
    final DocCommentPolicy javaDocPolicy = new DocCommentPolicy(dialog.getDocCommentPolicy());
    LocalHistoryAction a = LocalHistory.getInstance().startAction(getCommandName(subclass, superclassName));
    try {
        final PsiClass superclass;
        try {
            superclass = ExtractSuperClassUtil.extractSuperClass(project, targetDirectory, superclassName, subclass, selectedMemberInfos, javaDocPolicy);
        } finally {
            a.finish();
        }
        // ask whether to search references to subclass and turn them into refs to superclass if possible
        ExtractClassUtil.suggestToTurnRefsToSuper(project, superclass, subclass);
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) LocalHistoryAction(com.intellij.history.LocalHistoryAction) IncorrectOperationException(com.intellij.util.IncorrectOperationException) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy)

Example 5 with LocalHistoryAction

use of com.intellij.history.LocalHistoryAction in project intellij-community by JetBrains.

the class ActionsTest method testActionInsideCommand.

/**
   * <strong>This is very important test.</strong>
   * Almost all actions are performed inside surrounding command.
   * Therefore we have to correctly handle such situations.
   */
public void testActionInsideCommand() throws Exception {
    final VirtualFile f = createFile("f.txt");
    setContent(f, "file");
    setDocumentTextFor(f, "doc1");
    CommandProcessor.getInstance().executeCommand(myProject, () -> {
        LocalHistoryAction a = LocalHistory.getInstance().startAction("action");
        setDocumentTextFor(f, "doc2");
        a.finish();
    }, "command", null);
    List<Revision> rr = getRevisionsFor(f);
    assertEquals(5, rr.size());
    assertContent("doc2", rr.get(0).findEntry());
    assertEquals("command", rr.get(1).getChangeSetName());
    assertContent("doc1", rr.get(1).findEntry());
    assertContent("file", rr.get(2).findEntry());
    assertContent("", rr.get(3).findEntry());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Revision(com.intellij.history.core.revisions.Revision) LocalHistoryAction(com.intellij.history.LocalHistoryAction)

Aggregations

LocalHistoryAction (com.intellij.history.LocalHistoryAction)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 Result (com.intellij.openapi.application.Result)7 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)7 NotNull (org.jetbrains.annotations.NotNull)7 UsageInfo (com.intellij.usageView.UsageInfo)4 Revision (com.intellij.history.core.revisions.Revision)3 Project (com.intellij.openapi.project.Project)3 PsiElement (com.intellij.psi.PsiElement)3 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3 SequentialModalProgressTask (com.intellij.util.SequentialModalProgressTask)3 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)2 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)2 DependenciesModel (com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel)2 AndroidModuleInfo (com.android.tools.idea.model.AndroidModuleInfo)2 RepositoryUrlManager (com.android.tools.idea.templates.RepositoryUrlManager)2 BuildFileModifier (com.google.idea.blaze.base.buildmodifier.BuildFileModifier)2 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)2 LocalHistory (com.intellij.history.LocalHistory)2 Module (com.intellij.openapi.module.Module)2