use of com.intellij.history.LocalHistoryAction in project intellij-community by JetBrains.
the class ActionsTest method testSavingDocumentBeforeAndAfterAction.
public void testSavingDocumentBeforeAndAfterAction() throws Exception {
VirtualFile f = createFile("f.txt", "file1");
loadContent(f);
setContent(f, "file2");
setDocumentTextFor(f, "doc1");
LocalHistoryAction a = LocalHistory.getInstance().startAction("name");
setDocumentTextFor(f, "doc2");
a.finish();
List<Revision> rr = getRevisionsFor(f);
assertEquals(5, rr.size());
assertContent("doc2", rr.get(0).findEntry());
assertEquals("name", rr.get(1).getChangeSetName());
assertContent("doc1", rr.get(1).findEntry());
assertContent("file2", rr.get(2).findEntry());
assertContent("file1", rr.get(3).findEntry());
}
use of com.intellij.history.LocalHistoryAction in project intellij-community by JetBrains.
the class ActionsTest method testActionInsideCommandSurroundedWithSomeChanges.
public void testActionInsideCommandSurroundedWithSomeChanges() throws Exception {
// see testActionInsideCommand comment
final VirtualFile f = createFile("f.txt");
CommandProcessor.getInstance().executeCommand(myProject, new RunnableAdapter() {
@Override
public void doRun() throws IOException {
setContent(f, "file");
setDocumentTextFor(f, "doc1");
LocalHistoryAction a = LocalHistory.getInstance().startAction("action");
setDocumentTextFor(f, "doc2");
a.finish();
saveDocument(f);
setContent(f, "doc3");
}
}, "command", null);
List<Revision> rr = getRevisionsFor(f);
assertEquals(4, rr.size());
assertContent("doc3", rr.get(0).findEntry());
assertContent("doc1", rr.get(1).findEntry());
assertContent("", rr.get(2).findEntry());
assertEquals("command", rr.get(1).getChangeSetName());
assertNull(rr.get(2).getChangeSetName());
}
use of com.intellij.history.LocalHistoryAction in project intellij-community by JetBrains.
the class GettingContentAtDateTest method testWithUnsavedDocuments.
public void testWithUnsavedDocuments() throws Exception {
setContent(f, "FILE1", TIMESTAMP_INCREMENT);
Clock.setTime(TIMESTAMP_INCREMENT * 2);
LocalHistoryAction a = LocalHistory.getInstance().startAction(null);
setDocumentTextFor(f, "DOC1");
a.finish();
Clock.setTime(TIMESTAMP_INCREMENT * 3);
a = LocalHistory.getInstance().startAction(null);
setDocumentTextFor(f, "DOC2");
a.finish();
FileDocumentManager.getInstance().saveAllDocuments();
setContent(f, "FILE2", TIMESTAMP_INCREMENT * 4);
assertContentAt(new FileRevisionTimestampComparator() {
@Override
public boolean isSuitable(long revisionTimestamp) {
return revisionTimestamp == TIMESTAMP_INCREMENT * 4;
}
}, "FILE2");
assertContentAt(new FileRevisionTimestampComparator() {
@Override
public boolean isSuitable(long revisionTimestamp) {
return revisionTimestamp == TIMESTAMP_INCREMENT * 3;
}
}, "DOC2");
assertContentAt(new FileRevisionTimestampComparator() {
@Override
public boolean isSuitable(long revisionTimestamp) {
return revisionTimestamp == TIMESTAMP_INCREMENT * 2;
}
}, "DOC1");
assertContentAt(new FileRevisionTimestampComparator() {
@Override
public boolean isSuitable(long revisionTimestamp) {
return revisionTimestamp == TIMESTAMP_INCREMENT;
}
}, "FILE1");
}
use of com.intellij.history.LocalHistoryAction in project android by JetBrains.
the class AndroidInferNullityAnnotationAction method applyRunnable.
// Intellij code from InferNullityAnnotationsAction.
private static Runnable applyRunnable(Project project, Computable<UsageInfo[]> computable) {
return () -> {
LocalHistoryAction action = LocalHistory.getInstance().startAction(INFER_NULLITY_ANNOTATIONS);
try {
new WriteCommandAction(project, INFER_NULLITY_ANNOTATIONS) {
@Override
protected void run(@NotNull Result result) throws Throwable {
UsageInfo[] infos = computable.compute();
if (infos.length > 0) {
Set<PsiElement> elements = new LinkedHashSet<>();
for (UsageInfo info : infos) {
PsiElement element = info.getElement();
if (element != null) {
ContainerUtil.addIfNotNull(elements, element.getContainingFile());
}
}
if (!FileModificationService.getInstance().preparePsiElementsForWrite(elements))
return;
SequentialModalProgressTask progressTask = new SequentialModalProgressTask(project, INFER_NULLITY_ANNOTATIONS, false);
progressTask.setMinIterationTime(200);
progressTask.setTask(new AnnotateTask(project, progressTask, infos));
ProgressManager.getInstance().run(progressTask);
} else {
NullityInferrer.nothingFoundMessage(project);
}
}
}.execute();
} finally {
action.finish();
}
};
}
use of com.intellij.history.LocalHistoryAction in project intellij-community by JetBrains.
the class MethodDuplicatesHandler method replaceDuplicate.
private static void replaceDuplicate(final Project project, final Map<PsiMember, List<Match>> duplicates, final Set<PsiMember> methods) {
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
if (progressIndicator != null && progressIndicator.isCanceled())
return;
final Runnable replaceRunnable = () -> {
LocalHistoryAction a = LocalHistory.getInstance().startAction(REFACTORING_NAME);
try {
for (final PsiMember member : methods) {
final List<Match> matches = duplicates.get(member);
if (matches == null)
continue;
final int duplicatesNo = matches.size();
WindowManager.getInstance().getStatusBar(project).setInfo(getStatusMessage(duplicatesNo));
CommandProcessor.getInstance().executeCommand(project, () -> PostprocessReformattingAspect.getInstance(project).postponeFormattingInside(() -> {
final MatchProvider matchProvider = member instanceof PsiMethod ? new MethodDuplicatesMatchProvider((PsiMethod) member, matches) : new ConstantMatchProvider(member, project, matches);
DuplicatesImpl.invoke(project, matchProvider);
}), REFACTORING_NAME, REFACTORING_NAME);
WindowManager.getInstance().getStatusBar(project).setInfo("");
}
} finally {
a.finish();
}
};
ApplicationManager.getApplication().invokeLater(replaceRunnable, ModalityState.NON_MODAL);
}
Aggregations