Search in sources :

Example 51 with FileDocumentManager

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DataContext(com.intellij.openapi.actionSystem.DataContext) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) ActionManagerEx(com.intellij.openapi.actionSystem.ex.ActionManagerEx)

Example 52 with FileDocumentManager

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\"");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Document(com.intellij.openapi.editor.Document)

Example 53 with FileDocumentManager

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Nullable(org.jetbrains.annotations.Nullable)

Example 54 with FileDocumentManager

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) IOException(java.io.IOException) Document(com.intellij.openapi.editor.Document) EduDocumentListener(com.jetbrains.edu.learning.core.EduDocumentListener)

Example 55 with FileDocumentManager

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");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SupportedLanguages(org.stepik.core.SupportedLanguages) StudyStatus(org.stepik.core.courseFormat.StudyStatus) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Document(com.intellij.openapi.editor.Document)

Aggregations

FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)56 Document (com.intellij.openapi.editor.Document)39 VirtualFile (com.intellij.openapi.vfs.VirtualFile)32 IOException (java.io.IOException)16 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)7 File (java.io.File)7 Nullable (org.jetbrains.annotations.Nullable)7 Editor (com.intellij.openapi.editor.Editor)6 MockVirtualFile (com.intellij.mock.MockVirtualFile)5 PsiFile (com.intellij.psi.PsiFile)5 IncorrectOperationException (com.intellij.util.IncorrectOperationException)4 TaskFile (com.jetbrains.edu.learning.courseFormat.TaskFile)4 NotNull (org.jetbrains.annotations.NotNull)4 Project (com.intellij.openapi.project.Project)3 AnswerPlaceholder (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder)3 ArrayList (java.util.ArrayList)3 DataContext (com.intellij.openapi.actionSystem.DataContext)2 ActionManagerEx (com.intellij.openapi.actionSystem.ex.ActionManagerEx)2 Application (com.intellij.openapi.application.Application)2 Result (com.intellij.openapi.application.Result)2