use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class EditVarConstraintsDialog method createEditor.
private static Editor createEditor(final Project project, final String text, final String fileName) {
final FileType fileType = getFileType(fileName);
final Document doc = createDocument(fileName, fileType, text);
final Editor editor = EditorFactory.getInstance().createEditor(doc, project);
((EditorEx) editor).setEmbeddedIntoDialogWrapper(true);
final EditorSettings settings = editor.getSettings();
settings.setLineNumbersShown(false);
settings.setFoldingOutlineShown(false);
settings.setRightMarginShown(false);
settings.setLineMarkerAreaShown(false);
settings.setIndentGuidesShown(false);
((EditorEx) editor).setHighlighter(HighlighterFactory.createHighlighter(fileType, DefaultColorSchemesManager.getInstance().getFirstScheme(), project));
return editor;
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class SearchDialog method buildOptions.
protected void buildOptions(JPanel searchOptions) {
recursiveMatching = new JCheckBox(SSRBundle.message("recursive.matching.checkbox"), true);
if (isRecursiveSearchEnabled()) {
searchOptions.add(UIUtil.createOptionLine(recursiveMatching));
}
caseSensitiveMatch = new JCheckBox(FindBundle.message("find.options.case.sensitive"), true);
searchOptions.add(UIUtil.createOptionLine(caseSensitiveMatch));
final List<FileType> types = new ArrayList<>();
for (FileType fileType : StructuralSearchUtil.getSuitableFileTypes()) {
if (StructuralSearchUtil.getProfileByFileType(fileType) != null) {
types.add(fileType);
}
}
Collections.sort(types, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
final DefaultComboBoxModel<FileType> comboBoxModel = new DefaultComboBoxModel<>(types.toArray(new FileType[types.size()]));
fileTypes = new ComboBox<>(comboBoxModel);
fileTypes.setRenderer(new FileTypeRenderer());
new ComboboxSpeedSearch(fileTypes) {
@Override
protected String getElementText(Object element) {
return ((FileType) element).getName();
}
};
contexts = new ComboBox<>();
contexts.setPreferredSize(new Dimension(60, -1));
dialects = new ComboBox<>();
dialects.setRenderer(new ListCellRendererWrapper<Language>() {
@Override
public void customize(JList list, Language value, int index, boolean selected, boolean hasFocus) {
if (value == null) {
setText("None");
} else {
setText(value.getDisplayName());
}
}
});
dialects.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
updateEditor();
}
});
new ComboboxSpeedSearch(dialects);
dialects.setPreferredSize(new Dimension(120, -1));
final JLabel jLabel = new JLabel(SSRBundle.message("search.dialog.file.type.label"));
final JLabel jLabel2 = new JLabel(SSRBundle.message("search.dialog.context.label"));
final JLabel jLabel3 = new JLabel(SSRBundle.message("search.dialog.file.dialect.label"));
searchOptions.add(UIUtil.createOptionLine(new JComponent[] { jLabel, fileTypes, (JComponent) Box.createHorizontalStrut(8), jLabel2, contexts, (JComponent) Box.createHorizontalStrut(8), jLabel3, dialects }));
jLabel.setLabelFor(fileTypes);
jLabel2.setLabelFor(contexts);
jLabel3.setLabelFor(dialects);
detectFileTypeAndDialect();
fileTypes.setSelectedItem(ourFtSearchVariant);
fileTypes.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
updateDialectsAndContexts();
updateEditor();
initiateValidation();
}
}
});
dialects.setSelectedItem(ourDialect);
contexts.setSelectedItem(ourContext);
updateDialectsAndContexts();
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class SearchDialog method detectFileTypeAndDialect.
private void detectFileTypeAndDialect() {
final PsiFile file = searchContext.getFile();
if (file != null) {
PsiElement context = null;
if (searchContext.getEditor() != null) {
context = file.findElementAt(searchContext.getEditor().getCaretModel().getOffset());
if (context != null) {
context = context.getParent();
}
}
if (context == null) {
context = file;
}
FileType detectedFileType = null;
StructuralSearchProfile profile = StructuralSearchUtil.getProfileByPsiElement(context);
if (profile != null) {
FileType fileType = profile.detectFileType(context);
if (fileType != null) {
detectedFileType = fileType;
}
}
if (detectedFileType == null) {
for (FileType fileType : StructuralSearchUtil.getSuitableFileTypes()) {
if (fileType instanceof LanguageFileType && ((LanguageFileType) fileType).getLanguage().equals(context.getLanguage())) {
detectedFileType = fileType;
break;
}
}
}
ourFtSearchVariant = detectedFileType != null ? detectedFileType : StructuralSearchUtil.getDefaultFileType();
}
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class SettingsImpl method getTabSize.
@Override
public int getTabSize(Project project) {
if (myTabSize != null)
return myTabSize.intValue();
if (myCachedTabSize != null)
return myCachedTabSize.intValue();
int tabSize;
try {
if (project == null || project.isDisposed()) {
tabSize = CodeStyleSettingsManager.getSettings(null).getTabSize(null);
} else {
PsiFile file = getPsiFile(project);
if (myEditor != null && myEditor.isViewer()) {
FileType fileType = file != null ? file.getFileType() : null;
tabSize = CodeStyleSettingsManager.getSettings(project).getIndentOptions(fileType).TAB_SIZE;
} else {
tabSize = CodeStyleSettingsManager.getSettings(project).getIndentOptionsByFile(file).TAB_SIZE;
}
}
} catch (Exception e) {
LOG.error("Error determining tab size", e);
tabSize = new CommonCodeStyleSettings.IndentOptions().TAB_SIZE;
}
myCachedTabSize = Integer.valueOf(tabSize);
return tabSize;
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class FileAppearanceServiceImpl method forIoFile.
@NotNull
@Override
public CellAppearanceEx forIoFile(@NotNull final File file) {
final String absolutePath = file.getAbsolutePath();
if (!file.exists()) {
return forInvalidUrl(absolutePath);
}
if (file.isDirectory()) {
return SimpleTextCellAppearance.regular(absolutePath, PlatformIcons.FOLDER_ICON);
}
final String name = file.getName();
final FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(name);
final File parent = file.getParentFile();
final CompositeAppearance appearance = CompositeAppearance.textComment(name, parent.getAbsolutePath());
appearance.setIcon(fileType.getIcon());
return appearance;
}
Aggregations