Java源码示例:com.intellij.openapi.fileTypes.PlainTextLanguage
示例1
@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);
}
示例2
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;
}
}
}
示例3
/**
* 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);
}
示例4
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;
}
示例5
@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);
}
}
示例6
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());
}
示例7
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();
}
}
});
}
示例8
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;
}
示例9
@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;
}
示例10
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);
}
示例11
@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;
}
};
}
示例12
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;
}
示例13
@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);
}
示例14
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());
}
}
示例15
private boolean isSupportedLanguageFile(PsiFile file) {
return file.getLanguage().isKindOf(PlainTextLanguage.INSTANCE)
|| FileUtils.isFileSupported(file.getVirtualFile());
}
示例16
@NotNull
@Override
public Language getLanguage() {
return PlainTextLanguage.INSTANCE;
}
示例17
private CsvLanguage() {
super(PlainTextLanguage.INSTANCE, "csv");
}
示例18
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);
}
示例19
public PsiPlainTextFileImpl(FileViewProvider viewProvider) {
super(PlainTextTokenTypes.PLAIN_TEXT_FILE, PlainTextTokenTypes.PLAIN_TEXT_FILE, viewProvider);
myFileType = viewProvider.getBaseLanguage() != PlainTextLanguage.INSTANCE ? PlainTextFileType.INSTANCE : viewProvider.getFileType();
}
示例20
public DummyHolder(@Nonnull PsiManager manager, CharTable table, boolean validity) {
this(manager, null, null, table, Boolean.valueOf(validity), PlainTextLanguage.INSTANCE);
}
示例21
public DummyHolder(@Nonnull PsiManager manager, @Nullable TreeElement contentElement, PsiElement context, @Nullable CharTable table) {
this(manager, contentElement, context, table, null, language(context, PlainTextLanguage.INSTANCE));
}
示例22
private static boolean isPlainTextFile(@Nonnull Editor editor) {
return editor.getProject() != null && PlainTextLanguage.INSTANCE.is(getLanguageInEditor(editor, editor.getProject()));
}
示例23
/**
* Returns the language of the PSI element.
*
* @return the language instance.
*/
@NotNull
public Language getLanguage() {
return PlainTextLanguage.INSTANCE;
}