use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class YYYYYYY 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;
}
ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
DataContext dataContext = getDataContext();
actionManager.fireBeforeEditorTyping(c, dataContext);
MacUIUtil.hideCursor();
EditorActionManager.getInstance().getTypedAction().actionPerformed(this, c, dataContext);
return true;
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class JsonSchemaCrossReferencesTest method checkSchemaCompletion.
private void checkSchemaCompletion(VirtualFile moduleFile, final String fileName) {
doHighlighting();
complete();
assertStringItems("\"one\"", "\"two\"");
final VirtualFile baseFile = moduleFile.findChild(fileName);
Assert.assertNotNull(baseFile);
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
Document document = fileDocumentManager.getDocument(baseFile);
Assert.assertNotNull(document);
String str = "\"enum\": [\"one\", \"two\"]";
int start = document.getText().indexOf(str);
Assert.assertTrue(start > 0);
ApplicationManager.getApplication().runWriteAction(() -> {
document.replaceString(start, start + str.length(), "\"enum\": [\"one1\", \"two1\"]");
fileDocumentManager.saveAllDocuments();
});
LookupImpl lookup = getActiveLookup();
if (lookup != null)
lookup.hide();
JsonSchemaService.Impl.get(getProject()).reset();
doHighlighting();
complete();
assertStringItems("\"one1\"", "\"two1\"");
lookup = getActiveLookup();
if (lookup != null)
lookup.hide();
JsonSchemaService.Impl.get(getProject()).reset();
doHighlighting();
complete();
assertStringItems("\"one1\"", "\"two1\"");
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class PsiBasedStripTrailingSpacesFilter method getDocumentLanguage.
@Nullable
public static Language getDocumentLanguage(@NotNull Document document) {
FileDocumentManager manager = FileDocumentManager.getInstance();
VirtualFile file = manager.getFile(document);
if (file != null && file.isValid()) {
return LanguageUtil.getFileLanguage(file);
}
return null;
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class StudyCheckUtils method getCopyWithAnswers.
private static Pair<VirtualFile, TaskFile> getCopyWithAnswers(@NotNull final VirtualFile taskDir, @NotNull final VirtualFile file, @NotNull final TaskFile source) {
try {
VirtualFile answerFile = file.copy(taskDir, taskDir, file.getNameWithoutExtension() + EduNames.ANSWERS_POSTFIX + "." + file.getExtension());
final FileDocumentManager documentManager = FileDocumentManager.getInstance();
final Document document = documentManager.getDocument(answerFile);
if (document != null) {
TaskFile answerTaskFile = source.getTask().copy().getTaskFile(StudyUtils.pathRelativeToTask(file));
if (answerTaskFile == null) {
return null;
}
EduDocumentListener listener = new EduDocumentListener(answerTaskFile);
document.addDocumentListener(listener);
for (AnswerPlaceholder answerPlaceholder : answerTaskFile.getActivePlaceholders()) {
final int start = answerPlaceholder.getOffset();
final int end = start + answerPlaceholder.getRealLength();
final String text = answerPlaceholder.getPossibleAnswer();
document.replaceString(start, end, text);
}
ApplicationManager.getApplication().runWriteAction(() -> documentManager.saveDocument(document));
return Pair.create(answerFile, answerTaskFile);
}
} catch (IOException e) {
LOG.error(e);
}
return null;
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-plugins by StepicOrg.
the class DownloadSubmission method loadSubmission.
private void loadSubmission(@NotNull Project project, @NotNull StepNode stepNode, @NotNull Submission submission) {
String fileName = stepNode.getCurrentLang().getMainFileName();
VirtualFile src = getOrCreateSrcDirectory(project, stepNode, true);
if (src == null) {
Metrics.downloadAction(project, stepNode, TARGET_NOT_FOUND);
return;
}
VirtualFile mainFile = src.findChild(fileName);
if (mainFile == null) {
Metrics.downloadAction(project, stepNode, TARGET_NOT_FOUND);
return;
}
final String finalCode = submission.getReply().getCode();
CommandProcessor.getInstance().executeCommand(project, () -> ApplicationManager.getApplication().runWriteAction(() -> {
FileDocumentManager documentManager = FileDocumentManager.getInstance();
Document document = documentManager.getDocument(mainFile);
if (document != null) {
SupportedLanguages language = langOfName(submission.getReply().getLanguage());
if (containsDirectives(finalCode, language)) {
String text = uncommentAmbientCode(finalCode, language);
document.setText(text);
} else {
String code = replaceCode(document.getText(), finalCode, language);
document.setText(code);
}
StudyStatus status = StudyStatus.of(submission.getStatus());
stepNode.setStatus(status);
FileEditorManager.getInstance(project).openFile(mainFile, true);
ProjectView.getInstance(project).refresh();
Metrics.downloadAction(project, stepNode, SUCCESSFUL);
}
}), "Download submission", "Download submission");
}
Aggregations