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();
}
}
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);
}
}
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();
}
}
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);
}
}
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());
}
Aggregations