use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class ActionsTest method saveDocument.
private static void saveDocument(VirtualFile f) {
FileDocumentManager dm = FileDocumentManager.getInstance();
Document document = dm.getDocument(f);
assertNotNull(f.getPath(), document);
dm.saveDocument(document);
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class FileEncodingTest method testUndoChangeEncoding.
public void testUndoChangeEncoding() throws IOException {
VirtualFile file = createTempFile("txt", null, "xxx", CharsetToolkit.UTF8_CHARSET);
file.setCharset(CharsetToolkit.UTF8_CHARSET);
UIUtil.dispatchAllInvocationEvents();
assertEquals(CharsetToolkit.UTF8_CHARSET, file.getCharset());
FileDocumentManager documentManager = FileDocumentManager.getInstance();
assertNull(documentManager.getCachedDocument(file));
change(file, WINDOWS_1251);
assertEquals(WINDOWS_1251, file.getCharset());
Document document = documentManager.getDocument(file);
change(file, CharsetToolkit.UTF8_CHARSET);
assertEquals(CharsetToolkit.UTF8_CHARSET, file.getCharset());
globalUndo();
UIUtil.dispatchAllInvocationEvents();
assertEquals(WINDOWS_1251, file.getCharset());
document.getText();
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class EditorImpl method processKeyTyped.
private boolean processKeyTyped(char c) {
// [vova] This is patch for Mac OS X. Under Mac "input methods"
// is handled before our EventQueue consume upcoming KeyEvents.
IdeEventQueue queue = IdeEventQueue.getInstance();
if (queue.shouldNotTypeInEditor() || ProgressManager.getInstance().hasModalProgressIndicator()) {
return false;
}
FileDocumentManager manager = FileDocumentManager.getInstance();
final VirtualFile file = manager.getFile(myDocument);
if (file != null && !file.isValid()) {
return false;
}
DataContext context = getDataContext();
Graphics graphics = GraphicsUtil.safelyGetGraphics(myEditorComponent);
if (graphics != null) {
// editor component is not showing
processKeyTypedImmediately(c, graphics, context);
graphics.dispose();
}
ActionManagerEx.getInstanceEx().fireBeforeEditorTyping(c, context);
EditorUIUtil.hideCursorInEditor(this);
processKeyTypedNormally(c, context);
return true;
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class TrailingSpacesStripper method strip.
private void strip(@NotNull final Document document) {
if (!document.isWritable())
return;
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
VirtualFile file = fileDocumentManager.getFile(document);
if (file == null || !file.isValid() || Boolean.TRUE.equals(DISABLE_FOR_FILE_KEY.get(file)))
return;
final EditorSettingsExternalizable settings = EditorSettingsExternalizable.getInstance();
if (settings == null)
return;
final String overrideStripTrailingSpacesData = file.getUserData(OVERRIDE_STRIP_TRAILING_SPACES_KEY);
final Boolean overrideEnsureNewlineData = file.getUserData(OVERRIDE_ENSURE_NEWLINE_KEY);
@EditorSettingsExternalizable.StripTrailingSpaces String stripTrailingSpaces = overrideStripTrailingSpacesData != null ? overrideStripTrailingSpacesData : settings.getStripTrailingSpaces();
final boolean doStrip = !stripTrailingSpaces.equals(EditorSettingsExternalizable.STRIP_TRAILING_SPACES_NONE);
final boolean ensureEOL = overrideEnsureNewlineData != null ? overrideEnsureNewlineData.booleanValue() : settings.isEnsureNewLineAtEOF();
if (doStrip) {
final boolean inChangedLinesOnly = !stripTrailingSpaces.equals(EditorSettingsExternalizable.STRIP_TRAILING_SPACES_WHOLE);
boolean success = strip(document, inChangedLinesOnly, settings.isKeepTrailingSpacesOnCaretLine());
if (!success) {
myDocumentsToStripLater.add(document);
}
}
final int lines = document.getLineCount();
if (ensureEOL && lines > 0) {
final int start = document.getLineStartOffset(lines - 1);
final int end = document.getLineEndOffset(lines - 1);
if (start != end) {
final CharSequence content = document.getCharsSequence();
ApplicationManager.getApplication().runWriteAction(new DocumentRunnable(document, null) {
@Override
public void run() {
CommandProcessor.getInstance().runUndoTransparentAction(() -> {
if (CharArrayUtil.containsOnlyWhiteSpaces(content.subSequence(start, end)) && doStrip) {
document.deleteString(start, end);
} else {
document.insertString(end, "\n");
}
});
}
});
}
}
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class HgChangeProvider method processUnsavedChanges.
/**
* Finds modified but unsaved files in the given list of dirty files and notifies the builder about MODIFIED changes.
* Changes contained in <code>alreadyProcessed</code> are skipped - they have already been processed as modified, or else.
*/
public void processUnsavedChanges(ChangelistBuilder builder, Set<FilePath> dirtyFiles, Collection<HgChange> alreadyProcessed) {
// exclude already processed
for (HgChange c : alreadyProcessed) {
dirtyFiles.remove(c.beforeFile().toFilePath());
dirtyFiles.remove(c.afterFile().toFilePath());
}
final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
for (FilePath filePath : dirtyFiles) {
final VirtualFile vf = filePath.getVirtualFile();
if (vf != null && fileDocumentManager.isFileModified(vf)) {
final VirtualFile root = vcsManager.getVcsRootFor(vf);
if (root != null && HgUtil.isHgRoot(root)) {
final HgRevisionNumber beforeRevisionNumber = new HgWorkingCopyRevisionsCommand(myProject).firstParent(root);
final ContentRevision beforeRevision = (beforeRevisionNumber == null ? null : HgContentRevision.create(myProject, new HgFile(myProject, vf), beforeRevisionNumber));
builder.processChange(new Change(beforeRevision, CurrentContentRevision.create(filePath), FileStatus.MODIFIED), myVcsKey);
}
}
}
}
Aggregations