Search in sources :

Example 11 with DocumentReference

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;
}
Also used : DocumentReference(com.intellij.openapi.command.undo.DocumentReference) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with DocumentReference

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;
}
Also used : DocumentReference(com.intellij.openapi.command.undo.DocumentReference) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with DocumentReference

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) DocumentReference(com.intellij.openapi.command.undo.DocumentReference)

Aggregations

DocumentReference (com.intellij.openapi.command.undo.DocumentReference)13 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 NotNull (org.jetbrains.annotations.NotNull)3 BasicUndoableAction (com.intellij.openapi.command.undo.BasicUndoableAction)2 THashSet (gnu.trove.THashSet)2 UndoManager (com.intellij.openapi.command.undo.UndoManager)1 Document (com.intellij.openapi.editor.Document)1 DocumentEx (com.intellij.openapi.editor.ex.DocumentEx)1 Project (com.intellij.openapi.project.Project)1 ReadonlyStatusHandler (com.intellij.openapi.vfs.ReadonlyStatusHandler)1 PsiFile (com.intellij.psi.PsiFile)1 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)1 RenameJavaVariableProcessor (com.intellij.refactoring.rename.RenameJavaVariableProcessor)1 RenameXmlAttributeProcessor (com.intellij.refactoring.rename.RenameXmlAttributeProcessor)1 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)1 HashMap (com.intellij.util.containers.HashMap)1 File (java.io.File)1