public class FileDocumentManagerImpl extends FileDocumentManager implements SafeWriteRequestor
FileDocumentManager.WriteAccessStatus
Modifier and Type | Field and Description |
---|---|
static Key<Document> |
HARD_REF_TO_DOCUMENT_KEY |
static Key<java.lang.Object> |
NOT_RELOADABLE_DOCUMENT_KEY |
static boolean |
ourConflictsSolverEnabled |
Constructor and Description |
---|
FileDocumentManagerImpl() |
Modifier and Type | Method and Description |
---|---|
static boolean |
areTooManyDocumentsInTheQueue(java.util.Collection<? extends Document> documents) |
protected void |
cacheDocument(VirtualFile file,
Document document) |
void |
contentsChanged(VFileContentChangeEvent event) |
void |
dropAllUnsavedDocuments() |
Document |
getCachedDocument(VirtualFile file)
Returns the document for the specified file which has already been loaded into memory.
Client code shouldn't normally use this method, because it's unpredictable and any garbage collection can result in it returning null.
|
Document |
getDocument(VirtualFile file)
Returns the document for the specified virtual file.
Documents are cached on weak or strong references, depending on the nature of the virtual file.
|
protected Document |
getDocumentFromCache(VirtualFile file) |
VirtualFile |
getFile(Document document)
Returns the virtual file corresponding to the specified document.
|
static java.lang.String |
getLineSeparator(Document document,
VirtualFile file) |
java.lang.String |
getLineSeparator(VirtualFile file,
Project project) |
Document [] |
getUnsavedDocuments()
Returns all documents that have unsaved changes.
|
boolean |
isDocumentUnsaved(Document document)
Checks if the document has unsaved changes.
|
boolean |
isFileModified(VirtualFile file)
Checks if the document corresponding to the specified file has unsaved changes.
|
boolean |
isPartialPreviewOfALargeFile(Document document)
Check if only beginning of the file was loaded for Document.
|
static boolean |
recomputeFileTypeIfNecessary(VirtualFile virtualFile) |
static void |
registerDocument(Document document,
VirtualFile virtualFile) |
void |
reloadFiles(VirtualFile... files)
Discards unsaved changes for the specified files.
|
void |
reloadFromDisk(Document document)
Discards unsaved changes for the specified document and reloads it from disk.
|
protected void |
removeDocumentFromCache(VirtualFile file) |
boolean |
requestWriting(Document document,
Project project)
Requests writing access on the given document, possibly involving interaction with user.
|
FileDocumentManager.WriteAccessStatus |
requestWritingStatus(Document document,
Project project)
Requests writing access info on the given document.
|
void |
saveAllDocuments()
Saves all unsaved documents to disk.
|
void |
saveAllDocuments(boolean isExplicit) |
void |
saveDocument(Document document)
Saves the specified document to disk.
|
void |
saveDocument(Document document,
boolean explicit) |
void |
saveDocumentAsIs(Document document)
Saves the document without stripping the trailing spaces or adding a blank line in the end of the file.
Should be invoked on the event dispatch thread.
|
fileForDocumentCheckedOutSuccessfully, getInstance
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
shouldUseSafeWrite
public static final Key<java.lang.Object> NOT_RELOADABLE_DOCUMENT_KEY
public static boolean ourConflictsSolverEnabled
public Document getDocument(VirtualFile file)
FileDocumentManager
\n
.
Should be invoked in a read action.getDocument
in class FileDocumentManager
file
- the file for which the document is requested.VirtualFile.contentsToByteArray()
,
Application.runReadAction(Computable)
public static boolean areTooManyDocumentsInTheQueue(java.util.Collection<? extends Document> documents)
public Document getCachedDocument(VirtualFile file)
FileDocumentManager
getCachedDocument
in class FileDocumentManager
file
- the file for which the document is requested.public static void registerDocument(Document document, VirtualFile virtualFile)
public VirtualFile getFile(Document document)
FileDocumentManager
getFile
in class FileDocumentManager
document
- the document for which the virtual file is requested.public void dropAllUnsavedDocuments()
public void saveAllDocuments()
FileDocumentManager
\n
line separators are converted into
the ones used normally on the system, or the ones explicitly specified by the user. Encoding settings are honored.
Should be invoked on the event dispatch thread.saveAllDocuments
in class FileDocumentManager
public void saveAllDocuments(boolean isExplicit)
isExplicit
- caused by user directly (Save action) or indirectly (e.g. Compile)public void saveDocument(Document document)
FileDocumentManager
\n
line separators are converted into
the ones used normally on the system, or the ones explicitly specified by the user. Encoding settings are honored.
Should be invoked on the event dispatch thread.saveDocument
in class FileDocumentManager
document
- the document to save.public void saveDocument(Document document, boolean explicit)
public void saveDocumentAsIs(Document document)
FileDocumentManager
saveDocumentAsIs
in class FileDocumentManager
document
- the document to save.public static java.lang.String getLineSeparator(Document document, VirtualFile file)
public java.lang.String getLineSeparator(VirtualFile file, Project project)
getLineSeparator
in class FileDocumentManager
public boolean requestWriting(Document document, Project project)
FileDocumentManager
requestWriting
in class FileDocumentManager
document
- documentproject
- projectReadonlyStatusHandler.ensureFilesWritable(Project, VirtualFile...)
public FileDocumentManager.WriteAccessStatus requestWritingStatus(Document document, Project project)
FileDocumentManager
requestWritingStatus
in class FileDocumentManager
public void reloadFiles(VirtualFile... files)
FileDocumentManager
reloadFiles
in class FileDocumentManager
files
- the files to discard the changes for.public Document [] getUnsavedDocuments()
FileDocumentManager
getUnsavedDocuments
in class FileDocumentManager
public boolean isDocumentUnsaved(Document document)
FileDocumentManager
isDocumentUnsaved
in class FileDocumentManager
document
- the document to check.public boolean isFileModified(VirtualFile file)
FileDocumentManager
isFileModified
in class FileDocumentManager
file
- the file to check.public boolean isPartialPreviewOfALargeFile(Document document)
FileDocumentManager
isPartialPreviewOfALargeFile
in class FileDocumentManager
FileUtilRt.isTooLarge(long)
public void contentsChanged(VFileContentChangeEvent event)
public void reloadFromDisk(Document document)
FileDocumentManager
reloadFromDisk
in class FileDocumentManager
document
- the document to reload.public static boolean recomputeFileTypeIfNecessary(VirtualFile virtualFile)
protected void cacheDocument(VirtualFile file, Document document)
protected void removeDocumentFromCache(VirtualFile file)
protected Document getDocumentFromCache(VirtualFile file)