use of com.intellij.openapi.command.undo.DocumentReference in project intellij-community by JetBrains.
the class UndoRedoStacksHolder method clearStacks.
void clearStacks(boolean clearGlobal, @NotNull Set<DocumentReference> refs) {
for (LinkedList<UndoableGroup> each : getAffectedStacks(clearGlobal, refs)) {
while (!each.isEmpty()) {
clearStacksFrom(each.getLast());
}
}
Set<DocumentReference> stacksToDrop = new THashSet<>();
for (Map.Entry<DocumentReference, LinkedList<UndoableGroup>> each : myDocumentStacks.entrySet()) {
if (each.getValue().isEmpty())
stacksToDrop.add(each.getKey());
}
for (DocumentReference each : stacksToDrop) {
myDocumentStacks.remove(each);
}
cleanWeaklyTrackedEmptyStacks(myDocumentsWithStacks);
cleanWeaklyTrackedEmptyStacks(myNonlocalVirtualFilesWithStacks);
}
use of com.intellij.openapi.command.undo.DocumentReference in project intellij-community by JetBrains.
the class UndoableGroup method getDocumentToSetBulkMode.
private static DocumentEx getDocumentToSetBulkMode(UndoableAction action) {
// not allowed in bulk update.
if (!(action instanceof EditorChangeAction))
return null;
//noinspection ConstantConditions
DocumentReference newDocumentRef = action.getAffectedDocuments()[0];
if (newDocumentRef == null)
return null;
VirtualFile file = newDocumentRef.getFile();
if (file != null && !file.isValid())
return null;
return (DocumentEx) newDocumentRef.getDocument();
}
use of com.intellij.openapi.command.undo.DocumentReference in project intellij-community by JetBrains.
the class FinishMarkAction method finish.
public static void finish(final Project project, final Editor editor, @Nullable final StartMarkAction startAction) {
if (startAction == null)
return;
CommandProcessor.getInstance().executeCommand(project, () -> {
DocumentReference reference = DocumentReferenceManager.getInstance().create(editor.getDocument());
UndoManager.getInstance(project).undoableActionPerformed(new FinishMarkAction(reference, startAction));
StartMarkAction.markFinished(project);
}, "finish", null);
}
use of com.intellij.openapi.command.undo.DocumentReference in project intellij-community by JetBrains.
the class UndoRedo method execute.
public boolean execute(boolean drop, boolean isInsideStartFinishGroup) {
if (!myUndoableGroup.isUndoable()) {
reportCannotUndo(CommonBundle.message("cannot.undo.error.contains.nonundoable.changes.message"), myUndoableGroup.getAffectedDocuments());
return false;
}
Set<DocumentReference> clashing = getStackHolder().collectClashingActions(myUndoableGroup);
if (!clashing.isEmpty()) {
reportCannotUndo(CommonBundle.message("cannot.undo.error.other.affected.files.changed.message"), clashing);
return false;
}
if (!isInsideStartFinishGroup && myUndoableGroup.shouldAskConfirmation(isRedo())) {
if (!askUser())
return false;
} else {
if (restore(getBeforeState(), true)) {
setBeforeState(new EditorAndState(myEditor, myEditor.getState(FileEditorStateLevel.UNDO)));
return true;
}
}
Collection<VirtualFile> readOnlyFiles = collectReadOnlyAffectedFiles();
if (!readOnlyFiles.isEmpty()) {
final Project project = myManager.getProject();
final VirtualFile[] files = VfsUtil.toVirtualFileArray(readOnlyFiles);
if (project == null) {
return false;
}
final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(files);
if (operationStatus.hasReadonlyFiles()) {
return false;
}
}
Collection<Document> readOnlyDocuments = collectReadOnlyDocuments();
if (!readOnlyDocuments.isEmpty()) {
for (Document document : readOnlyDocuments) {
document.fireReadOnlyModificationAttempt();
}
return false;
}
getStackHolder().removeFromStacks(myUndoableGroup);
if (!drop) {
getReverseStackHolder().addToStacks(myUndoableGroup);
}
performAction();
restore(getAfterState(), false);
return true;
}
use of com.intellij.openapi.command.undo.DocumentReference in project intellij-community by JetBrains.
the class TemplateState method start.
public void start(@NotNull TemplateImpl template, @Nullable final PairProcessor<String, String> processor, @Nullable Map<String, String> predefinedVarValues) {
LOG.assertTrue(!myStarted, "Already started");
myStarted = true;
final PsiFile file = getPsiFile();
myTemplate = substituteTemplate(file, myEditor.getCaretModel().getOffset(), template);
myProcessor = processor;
DocumentReference[] refs = myDocument != null ? new DocumentReference[] { DocumentReferenceManager.getInstance().create(myDocument) } : null;
UndoManager.getInstance(myProject).undoableActionPerformed(new BasicUndoableAction(refs) {
@Override
public void undo() {
if (!isDisposed()) {
fireTemplateCancelled();
LookupManager.getInstance(myProject).hideActiveLookup();
int oldVar = myCurrentVariableNumber;
setCurrentVariableNumber(-1);
currentVariableChanged(oldVar);
}
}
@Override
public void redo() {
//TODO:
// throw new UnexpectedUndoException("Not implemented");
}
});
myTemplateIndented = false;
myCurrentVariableNumber = -1;
mySegments = new TemplateSegments(myEditor);
myPrevTemplate = myTemplate;
//myArgument = argument;
myPredefinedVariableValues = predefinedVarValues;
if (myTemplate.isInline()) {
int caretOffset = myEditor.getCaretModel().getOffset();
myTemplateRange = myDocument.createRangeMarker(caretOffset, caretOffset + myTemplate.getTemplateText().length());
} else {
preprocessTemplate(file, myEditor.getCaretModel().getOffset(), myTemplate.getTemplateText());
int caretOffset = myEditor.getCaretModel().getOffset();
myTemplateRange = myDocument.createRangeMarker(caretOffset, caretOffset);
}
myTemplateRange.setGreedyToLeft(true);
myTemplateRange.setGreedyToRight(true);
processAllExpressions(myTemplate);
}
Aggregations