use of com.intellij.openapi.command.undo.DocumentReference in project intellij-community by JetBrains.
the class DocumentReferenceManagerImpl method create.
@NotNull
@Override
public DocumentReference create(@NotNull VirtualFile file) {
assertInDispatchThread();
if (!file.isInLocalFileSystem()) {
// we treat local files differently from non local because we can undo their deletion
DocumentReference reference = file.getUserData(FILE_TO_STRONG_REF_KEY);
if (reference == null) {
file.putUserData(FILE_TO_STRONG_REF_KEY, reference = new DocumentReferenceByNonlocalVirtualFile(file));
}
return reference;
}
assert file.isValid() : "file is invalid: " + file;
DocumentReference result = SoftReference.dereference(file.getUserData(FILE_TO_REF_KEY));
if (result == null) {
result = new DocumentReferenceByVirtualFile(file);
file.putUserData(FILE_TO_REF_KEY, new WeakReference<>(result));
}
return result;
}
use of com.intellij.openapi.command.undo.DocumentReference in project intellij-community by JetBrains.
the class UndoRedoStacksHolder method getLastAction.
@NotNull
UndoableGroup getLastAction(@NotNull Collection<DocumentReference> refs) {
if (refs.isEmpty())
return myGlobalStack.getLast();
UndoableGroup mostRecentAction = null;
int mostRecentDocTimestamp = myUndo ? -1 : Integer.MAX_VALUE;
for (DocumentReference each : refs) {
LinkedList<UndoableGroup> stack = getStack(each);
// the stack for a document can be empty in case of compound editors with several documents
if (stack.isEmpty())
continue;
UndoableGroup lastAction = stack.getLast();
int timestamp = lastAction.getCommandTimestamp();
if (myUndo ? timestamp > mostRecentDocTimestamp : timestamp < mostRecentDocTimestamp) {
mostRecentAction = lastAction;
mostRecentDocTimestamp = timestamp;
}
}
// result must not be null
return mostRecentAction;
}
use of com.intellij.openapi.command.undo.DocumentReference in project intellij-community by JetBrains.
the class CvsFileOperationsHandler method doMoveRename.
private boolean doMoveRename(final VirtualFile file, final VirtualFile newParent, final String newName) throws IOException {
if (!CvsUtil.fileIsUnderCvs(file))
return false;
if (newParent == null)
return false;
final File newFile = new File(newParent.getPath(), newName);
myComponent.getDeleteHandler().addDeletedRoot(file);
if (!file.isDirectory()) {
myComponent.getAddHandler().addFile(newFile);
return false;
}
newFile.mkdir();
copyDirectoryStructure(file, newFile);
myComponent.getAddHandler().addFile(newFile);
final DocumentReference ref = DocumentReferenceManager.getInstance().create(file);
UndoManager.getInstance(myProject).nonundoableActionPerformed(ref, false);
return true;
}
Aggregations