com.intellij.openapi.fileTypes.PlainTextLanguage Java Examples

The following examples show how to use com.intellij.openapi.fileTypes.PlainTextLanguage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FluidFileViewProvider.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
public FluidFileViewProvider(PsiManager manager, VirtualFile file, boolean physical) {
    super(manager, file, physical);

    Language dataLang = TemplateDataLanguageMappings.getInstance(manager.getProject()).getMapping(file);
    if (dataLang == null) {
        dataLang = StdFileTypes.HTML.getLanguage();
    }

    if (dataLang instanceof TemplateLanguage) {
        myTemplateDataLanguage = PlainTextLanguage.INSTANCE;
    } else {
        // The substitutor signals, that a files content should be substituted
        Language mySubstitutedLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(dataLang, file, manager.getProject());
        if (mySubstitutedLanguage == FluidLanguage.INSTANCE) {
            this.myTemplateDataLanguage = StdFileTypes.HTML.getLanguage();
        } else {
            this.myTemplateDataLanguage = mySubstitutedLanguage;
        }
    }
}
 
Example #2
Source File: LSPQuickDocAction.java    From lsp4intellij with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    Editor editor = e.getData(CommonDataKeys.EDITOR);
    VirtualFile file = FileDocumentManager.getInstance().getFile(editor.getDocument());
    Language language = PsiManager.getInstance(editor.getProject()).findFile(file).getLanguage();
    //Hack for IntelliJ 2018 TODO proper way
    if (LanguageDocumentation.INSTANCE.allForLanguage(language).isEmpty()
            || (Integer.parseInt(ApplicationInfo.getInstance().getMajorVersion()) > 2017)
            && language == PlainTextLanguage.INSTANCE) {
        EditorEventManager manager = EditorEventManagerBase.forEditor(editor);
        if (manager != null) {
            manager.quickDoc(editor);
        } else {
            super.actionPerformed(e);
        }
    } else
        super.actionPerformed(e);
}
 
Example #3
Source File: CommitMessage.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a text editor appropriate for creating commit messages.
 *
 * @param project project this commit message editor is intended for
 * @param forceSpellCheckOn if false, {@link com.intellij.openapi.vcs.VcsConfiguration#CHECK_COMMIT_MESSAGE_SPELLING} will control
 *                          whether or not the editor has spell check enabled
 * @return a commit message editor
 */
public static EditorTextField createCommitTextEditor(final Project project, boolean forceSpellCheckOn) {
  Set<EditorCustomization> features = new HashSet<EditorCustomization>();

  final SpellCheckerCustomization spellChecker = SpellCheckerCustomization.getInstance();
  VcsConfiguration configuration = VcsConfiguration.getInstance(project);
  if (configuration != null) {
    boolean enableSpellChecking = forceSpellCheckOn || configuration.CHECK_COMMIT_MESSAGE_SPELLING;
    if(spellChecker.isEnabled()) {
      features.add(spellChecker.getCustomization(enableSpellChecking));
    }
    features.add(new RightMarginEditorCustomization(configuration.USE_COMMIT_MESSAGE_MARGIN, configuration.COMMIT_MESSAGE_MARGIN_SIZE));
    features.add(WrapWhenTypingReachesRightMarginCustomization.getInstance(configuration.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN));
  } else {
    if(spellChecker.isEnabled()) {
      features.add(spellChecker.getCustomization(true));
    }
    features.add(new RightMarginEditorCustomization(false, -1));
  }

  features.add(SoftWrapsEditorCustomization.ENABLED);
  features.add(AdditionalPageAtBottomEditorCustomization.DISABLED);

  EditorTextFieldProvider service = ServiceManager.getService(project, EditorTextFieldProvider.class);
  return service.getEditorField(PlainTextLanguage.INSTANCE, project, features);
}
 
Example #4
Source File: NewEditChangelistPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static EditorTextField createEditorField(final Project project, final int defaultLines) {
  final EditorTextFieldProvider service = ServiceManager.getService(project, EditorTextFieldProvider.class);
  final EditorTextField editorField;

  final Set<EditorCustomization> editorFeatures = ContainerUtil.newHashSet();
  final SpellCheckerCustomization spellChecker = SpellCheckerCustomization.getInstance();
  if(spellChecker.isEnabled())  {
    editorFeatures.add(spellChecker.getCustomization(true));
  }

  if (defaultLines == 1) {
    editorFeatures.add(HorizontalScrollBarEditorCustomization.DISABLED);
    editorFeatures.add(OneLineEditorCustomization.ENABLED);
  } else {
    editorFeatures.add(SoftWrapsEditorCustomization.ENABLED);
  }
  editorField = service.getEditorField(PlainTextLanguage.INSTANCE, project, editorFeatures);
  final int height = editorField.getFontMetrics(editorField.getFont()).getHeight();
  editorField.getComponent().setMinimumSize(new Dimension(100, (int)(height * 1.3)));
  return editorField;
}
 
Example #5
Source File: DustFileViewProvider.java    From Intellij-Dust with MIT License 5 votes vote down vote up
public DustFileViewProvider(PsiManager manager, VirtualFile file, boolean physical) {
  super(manager, file, physical);

  // get the main language of the file
  Language dataLang = TemplateDataLanguageMappings.getInstance(manager.getProject()).getMapping(file);
  if (dataLang == null) dataLang = StdFileTypes.HTML.getLanguage();

  // some magic?
  if (dataLang instanceof TemplateLanguage) {
    myTemplateDataLanguage = PlainTextLanguage.INSTANCE;
  } else {
    myTemplateDataLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(dataLang, file, manager.getProject());
  }
}
 
Example #6
Source File: ScratchFileActions.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  Project project = e.getProject();
  if (project == null) return;
  ScratchFileCreationHelper.Context context = createContext(e, project);
  context.filePrefix = "buffer";
  context.createOption = ScratchFileService.Option.create_if_missing;
  context.fileCounter = ScratchFileActions::nextBufferIndex;
  if (context.language == null) context.language = PlainTextLanguage.INSTANCE;
  doCreateNewScratch(project, context);
}
 
Example #7
Source File: TextFieldWithCompletion.java    From consulo with Apache License 2.0 5 votes vote down vote up
public TextFieldWithCompletion(@Nullable Project project,
                               @Nonnull TextCompletionProvider provider,
                               @Nonnull String value,
                               boolean oneLineMode,
                               boolean autoPopup,
                               boolean forceAutoPopup,
                               boolean showHint) {
  super(PlainTextLanguage.INSTANCE, project, value, new TextCompletionUtil.DocumentWithCompletionCreator(provider, autoPopup),
        oneLineMode);
  myForceAutoPopup = forceAutoPopup;
  myShowHint = showHint;
}
 
Example #8
Source File: TextFieldCompletionProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public EditorTextField createEditor(Project project,
                                    final boolean shouldHaveBorder,
                                    @Nullable final Consumer<Editor> editorConstructionCallback)
{
  return new EditorTextField(createDocument(project, ""), project, PlainTextLanguage.INSTANCE.getAssociatedFileType()) {
    @Override
    protected boolean shouldHaveBorder() {
      return shouldHaveBorder;
    }

    @Override
    protected void updateBorder(@Nonnull EditorEx editor) {
      if (shouldHaveBorder) {
        super.updateBorder(editor);
      }
      else {
        editor.setBorder(null);
      }
    }

    @Override
    protected EditorEx createEditor() {
      EditorEx result = super.createEditor();
      if (editorConstructionCallback != null) {
        editorConstructionCallback.consume(result);
      }
      return result;
    }
  };
}
 
Example #9
Source File: GraphQLSchemaErrorNode.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
@Override
public void handleDoubleClickOrEnter(SimpleTree tree, InputEvent inputEvent) {
    final SourceLocation location = getLocation();
    if (location != null && location.getSourceName() != null) {
        GraphQLTreeNodeNavigationUtil.openSourceLocation(myProject, location, false);
    } else if (error instanceof GraphQLInternalSchemaError) {
        String stackTrace = ExceptionUtil.getThrowableText(((GraphQLInternalSchemaError) error).getException());
        PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText("graphql-error.txt", PlainTextLanguage.INSTANCE, stackTrace);
        new OpenFileDescriptor(myProject, file.getVirtualFile()).navigate(true);
    }
}
 
Example #10
Source File: CodeStyleManager.java    From editorconfig-jetbrains with MIT License 5 votes vote down vote up
private void applyCodeStyleSettings(final List<OutPair> outPairs, final CodeStyleSettings codeStyleSettings,
                                    final VirtualFile file) {
    // Apply indent options
    final String indentSize = Utils.configValueForKey(outPairs, indentSizeKey);
    final String tabWidth = Utils.configValueForKey(outPairs, tabWidthKey);
    final String indentStyle = Utils.configValueForKey(outPairs, indentStyleKey);
    final FileType fileType = file.getFileType();
    final Language language = fileType instanceof LanguageFileType ? ((LanguageFileType)fileType).getLanguage() :
        PlainTextLanguage.INSTANCE;
    final CommonCodeStyleSettings commonSettings = codeStyleSettings.getCommonSettings(language);
    final CommonCodeStyleSettings.IndentOptions indentOptions = commonSettings.getIndentOptions();
    applyIndentOptions(indentOptions, indentSize, tabWidth, indentStyle, file.getCanonicalPath());
}
 
Example #11
Source File: CommentForm.java    From Crucible4IDEA with MIT License 5 votes vote down vote up
public CommentForm(@NotNull Project project, boolean isGeneral, boolean isReply, @Nullable FilePath filePath) {
  super(new BorderLayout());
  myProject = project;
  myGeneral = isGeneral;
  myReply = isReply;
  myFilePath = filePath;

  final EditorTextFieldProvider service = ServiceManager.getService(project, EditorTextFieldProvider.class);
  final Set<EditorCustomization> editorFeatures =
    ContainerUtil.newHashSet(SoftWrapsEditorCustomization.ENABLED,
                             SpellCheckingEditorCustomizationProvider.getInstance().getEnabledCustomization());
  myReviewTextField = service.getEditorField(PlainTextLanguage.INSTANCE, project, editorFeatures);

  final JScrollPane pane = ScrollPaneFactory.createScrollPane(myReviewTextField);
  pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  add(pane);

  myReviewTextField.setPreferredSize(new Dimension(ourBalloonWidth, ourBalloonHeight));

  myReviewTextField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).
    put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK), "postComment");
  myReviewTextField.getActionMap().put("postComment", new AbstractAction() {
    @Override
    public void actionPerformed(ActionEvent e) {
      myOK = true;
      if (myBalloon != null) {
        myBalloon.dispose();
      }
    }
  });
}
 
Example #12
Source File: SingleRootFileViewProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static Language calcBaseLanguage(@Nonnull VirtualFile file, @Nonnull Project project, @Nonnull final FileType fileType) {
  if (fileType.isBinary()) return Language.ANY;
  if (isTooLargeForIntelligence(file)) return PlainTextLanguage.INSTANCE;

  Language language = LanguageUtil.getLanguageForPsi(project, file);

  return language != null ? language : PlainTextLanguage.INSTANCE;
}
 
Example #13
Source File: TextFieldWithAutoCompletion.java    From consulo with Apache License 2.0 5 votes vote down vote up
public TextFieldWithAutoCompletion(final Project project,
                                   @Nonnull final TextFieldWithAutoCompletionListProvider<T> provider,
                                   final boolean showAutocompletionIsAvailableHint, @Nullable final String text) {
  super(PlainTextLanguage.INSTANCE, project, text == null ? "" : text);

  myShowAutocompletionIsAvailableHint = showAutocompletionIsAvailableHint;
  myProvider = provider;

  TextFieldWithAutoCompletionContributor.installCompletion(getDocument(), project, provider, true);
}
 
Example #14
Source File: TypedHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
static FileType getFileType(@Nonnull PsiFile file, @Nonnull Editor editor) {
  FileType fileType = file.getFileType();
  Language language = PsiUtilBase.getLanguageInEditor(editor, file.getProject());
  if (language != null && language != PlainTextLanguage.INSTANCE) {
    LanguageFileType associatedFileType = language.getAssociatedFileType();
    if (associatedFileType != null) fileType = associatedFileType;
  }
  return fileType;
}
 
Example #15
Source File: PsiPlainTextFileImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public PsiPlainTextFileImpl(FileViewProvider viewProvider) {
  super(PlainTextTokenTypes.PLAIN_TEXT_FILE, PlainTextTokenTypes.PLAIN_TEXT_FILE, viewProvider);
  myFileType = viewProvider.getBaseLanguage() != PlainTextLanguage.INSTANCE ? PlainTextFileType.INSTANCE : viewProvider.getFileType();
}
 
Example #16
Source File: FormatConstants.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean isPlainTextFile(@Nonnull Editor editor) {
  return editor.getProject() != null && PlainTextLanguage.INSTANCE.is(getLanguageInEditor(editor, editor.getProject()));
}
 
Example #17
Source File: DummyHolder.java    From consulo with Apache License 2.0 4 votes vote down vote up
public DummyHolder(@Nonnull PsiManager manager, @Nullable TreeElement contentElement, PsiElement context, @Nullable CharTable table) {
  this(manager, contentElement, context, table, null, language(context, PlainTextLanguage.INSTANCE));
}
 
Example #18
Source File: DummyHolder.java    From consulo with Apache License 2.0 4 votes vote down vote up
public DummyHolder(@Nonnull PsiManager manager, CharTable table, boolean validity) {
  this(manager, null, null, table, Boolean.valueOf(validity), PlainTextLanguage.INSTANCE);
}
 
Example #19
Source File: ScriptDialog.java    From PackageTemplates with Apache License 2.0 4 votes vote down vote up
private void createEditorField() {
    PsiFile psiFile = PsiFileFactory.getInstance(project).createFileFromText("Script", PlainTextLanguage.INSTANCE, code);

    etfCode = new EditorTextField(PsiDocumentManager.getInstance(project).getDocument(psiFile), project, PlainTextFileType.INSTANCE);
    etfCode.setOneLineMode(false);
}
 
Example #20
Source File: CsvLanguage.java    From intellij-csv-validator with Apache License 2.0 4 votes vote down vote up
private CsvLanguage() {
    super(PlainTextLanguage.INSTANCE, "csv");
}
 
Example #21
Source File: LSPPSiElement.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
@NotNull
@Override
public Language getLanguage() {
    return PlainTextLanguage.INSTANCE;
}
 
Example #22
Source File: EditorEventManager.java    From lsp4intellij with Apache License 2.0 4 votes vote down vote up
private boolean isSupportedLanguageFile(PsiFile file) {
    return file.getLanguage().isKindOf(PlainTextLanguage.INSTANCE)
            || FileUtils.isFileSupported(file.getVirtualFile());
}
 
Example #23
Source File: LSPPsiElement.java    From lsp4intellij with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the language of the PSI element.
 *
 * @return the language instance.
 */
@NotNull
public Language getLanguage() {
    return PlainTextLanguage.INSTANCE;
}