public abstract class FileDocumentManager extends java.lang.Object implements SavingRequestor
VirtualFile
instances and corresponding Document
instances.
Manages the saving of changes to disk.Modifier and Type | Class and Description |
---|---|
static class |
FileDocumentManager.WriteAccessStatus
Stores the write access status (true if the document has the write access; false otherwise)
and a message about the reason for the read-only status.
|
Constructor and Description |
---|
FileDocumentManager() |
Modifier and Type | Method and Description |
---|---|
static boolean |
fileForDocumentCheckedOutSuccessfully(Document document,
Project project) |
abstract 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.
|
abstract 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.
|
abstract VirtualFile |
getFile(Document document)
Returns the virtual file corresponding to the specified document.
|
static FileDocumentManager |
getInstance() |
abstract java.lang.String |
getLineSeparator(VirtualFile file,
Project project) |
abstract Document [] |
getUnsavedDocuments()
Returns all documents that have unsaved changes.
|
abstract boolean |
isDocumentUnsaved(Document document)
Checks if the document has unsaved changes.
|
abstract boolean |
isFileModified(VirtualFile file)
Checks if the document corresponding to the specified file has unsaved changes.
|
abstract boolean |
isPartialPreviewOfALargeFile(Document document)
Check if only beginning of the file was loaded for Document.
|
abstract void |
reloadFiles(VirtualFile... files)
Discards unsaved changes for the specified files.
|
abstract void |
reloadFromDisk(Document document)
Discards unsaved changes for the specified document and reloads it from disk.
|
abstract 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.
|
abstract void |
saveAllDocuments()
Saves all unsaved documents to disk.
|
abstract void |
saveDocument(Document document)
Saves the specified document to disk.
|
abstract 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.
|
public static FileDocumentManager getInstance()
public abstract Document getDocument(VirtualFile file)
\n
.
Should be invoked in a read action.file
- the file for which the document is requested.VirtualFile.contentsToByteArray()
,
Application.runReadAction(Computable)
public abstract Document getCachedDocument(VirtualFile file)
file
- the file for which the document is requested.public abstract VirtualFile getFile(Document document)
document
- the document for which the virtual file is requested.public abstract void saveAllDocuments()
\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.public abstract void saveDocument(Document document)
\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.document
- the document to save.public abstract void saveDocumentAsIs(Document document)
document
- the document to save.public abstract Document [] getUnsavedDocuments()
public abstract boolean isDocumentUnsaved(Document document)
document
- the document to check.public abstract boolean isFileModified(VirtualFile file)
file
- the file to check.public abstract boolean isPartialPreviewOfALargeFile(Document document)
FileUtilRt.isTooLarge(long)
public abstract void reloadFromDisk(Document document)
document
- the document to reload.public abstract java.lang.String getLineSeparator(VirtualFile file, Project project)
public abstract boolean requestWriting(Document document, Project project)
document
- documentproject
- projectReadonlyStatusHandler.ensureFilesWritable(Project, VirtualFile...)
public FileDocumentManager.WriteAccessStatus requestWritingStatus(Document document, Project project)
public static boolean fileForDocumentCheckedOutSuccessfully(Document document, Project project)
public abstract void reloadFiles(VirtualFile... files)
files
- the files to discard the changes for.