use of com.intellij.openapi.fileTypes.impl.AbstractFileType in project intellij-community by JetBrains.
the class CommentByBlockCommentAction method isValidFor.
@Override
protected boolean isValidFor(@NotNull Project project, @NotNull Editor editor, @NotNull Caret caret, @NotNull final PsiFile file) {
final FileType fileType = file.getFileType();
if (fileType instanceof AbstractFileType) {
return ((AbstractFileType) fileType).getCommenter() != null;
}
Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(file.getLanguage());
if (commenter == null)
commenter = LanguageCommenters.INSTANCE.forLanguage(file.getViewProvider().getBaseLanguage());
if (commenter == null)
return false;
return commenter.getBlockCommentPrefix() != null && commenter.getBlockCommentSuffix() != null;
}
use of com.intellij.openapi.fileTypes.impl.AbstractFileType in project intellij-community by JetBrains.
the class CustomFileTypeEditorTest method testInsertDeleteQuotes.
public void testInsertDeleteQuotes() throws Exception {
configureByFile(BASE_PATH + "InsertDeleteQuote.cs");
EditorTestUtil.performTypingAction(getEditor(), '"');
checkResultByFile(BASE_PATH + "InsertDeleteQuote_after.cs");
configureByFile(BASE_PATH + "InsertDeleteQuote_after.cs");
EditorTestUtil.performTypingAction(getEditor(), BACKSPACE_FAKE_CHAR);
checkResultByFile(BASE_PATH + "InsertDeleteQuote.cs");
FileType extension = FileTypeManager.getInstance().getFileTypeByExtension("pl");
assertTrue("Test is not set up correctly:" + extension, extension instanceof AbstractFileType);
configureByFile(BASE_PATH + "InsertDeleteQuote.pl");
EditorTestUtil.performTypingAction(getEditor(), '"');
checkResultByFile(BASE_PATH + "InsertDeleteQuote_after.pl");
configureByFile(BASE_PATH + "InsertDeleteQuote_after.pl");
EditorTestUtil.performTypingAction(getEditor(), BACKSPACE_FAKE_CHAR);
checkResultByFile(BASE_PATH + "InsertDeleteQuote.pl");
configureByFile(BASE_PATH + "InsertDeleteQuote.aj");
EditorTestUtil.performTypingAction(getEditor(), '"');
checkResultByFile(BASE_PATH + "InsertDeleteQuote_after.aj");
configureByFile(BASE_PATH + "InsertDeleteQuote_after.aj");
EditorTestUtil.performTypingAction(getEditor(), BACKSPACE_FAKE_CHAR);
checkResultByFile(BASE_PATH + "InsertDeleteQuote.aj");
}
use of com.intellij.openapi.fileTypes.impl.AbstractFileType in project intellij-community by JetBrains.
the class PsiViewerDialog method init.
@Override
protected void init() {
initMnemonics();
initTree(myPsiTree);
final TreeCellRenderer renderer = myPsiTree.getCellRenderer();
myPsiTree.setCellRenderer(new TreeCellRenderer() {
@Override
public Component getTreeCellRendererComponent(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
final Component c = renderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
if (value instanceof DefaultMutableTreeNode) {
final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
if (userObject instanceof ViewerNodeDescriptor) {
final Object element = ((ViewerNodeDescriptor) userObject).getElement();
if (c instanceof NodeRenderer) {
((NodeRenderer) c).setToolTipText(element == null ? null : element.getClass().getName());
}
if (element instanceof PsiElement && FileContextUtil.getFileContext(((PsiElement) element).getContainingFile()) != null || element instanceof ViewerTreeStructure.Inject) {
final TextAttributes attr = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.INJECTED_LANGUAGE_FRAGMENT);
c.setBackground(attr.getBackgroundColor());
}
}
}
return c;
}
});
myPsiTreeBuilder = new ViewerTreeBuilder(myProject, myPsiTree);
Disposer.register(getDisposable(), myPsiTreeBuilder);
myPsiTree.addTreeSelectionListener(new MyPsiTreeSelectionListener());
final GoToListener listener = new GoToListener();
myRefs.addKeyListener(listener);
myRefs.addMouseListener(listener);
myRefs.getSelectionModel().addListSelectionListener(listener);
myRefs.setCellRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(@NotNull JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
final Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
try {
if (resolve(index) == null) {
comp.setForeground(JBColor.RED);
}
} catch (IndexNotReadyException ignore) {
}
return comp;
}
});
initTree(myBlockTree);
myEditor.getSettings().setFoldingOutlineShown(false);
myEditor.getDocument().addDocumentListener(myEditorListener);
myEditor.getSelectionModel().addSelectionListener(myEditorListener);
myEditor.getCaretModel().addCaretListener(myEditorListener);
getPeer().getWindow().setFocusTraversalPolicy(new LayoutFocusTraversalPolicy() {
@Override
public Component getInitialComponent(@NotNull Window window) {
return myEditor.getComponent();
}
});
PsiViewerSettings settings = PsiViewerSettings.getSettings();
VirtualFile file = myExternalDocument ? FileDocumentManager.getInstance().getFile(myEditor.getDocument()) : null;
Language curLanguage = LanguageUtil.getLanguageForPsi(myProject, file);
String type = curLanguage != null ? curLanguage.getDisplayName() : settings.type;
SourceWrapper lastUsed = null;
for (PsiViewerExtension extension : Extensions.getExtensions(PsiViewerExtension.EP_NAME)) {
SourceWrapper wrapper = new SourceWrapper(extension);
mySourceWrappers.add(wrapper);
}
Set<FileType> allFileTypes = ContainerUtil.newHashSet();
Collections.addAll(allFileTypes, FileTypeManager.getInstance().getRegisteredFileTypes());
for (Language language : Language.getRegisteredLanguages()) {
FileType fileType = language.getAssociatedFileType();
if (fileType != null) {
allFileTypes.add(fileType);
}
}
for (FileType fileType : allFileTypes) {
if (fileType != StdFileTypes.GUI_DESIGNER_FORM && fileType != StdFileTypes.IDEA_MODULE && fileType != StdFileTypes.IDEA_PROJECT && fileType != StdFileTypes.IDEA_WORKSPACE && fileType != FileTypes.ARCHIVE && fileType != FileTypes.UNKNOWN && fileType != FileTypes.PLAIN_TEXT && !(fileType instanceof AbstractFileType) && !fileType.isBinary() && !fileType.isReadOnly()) {
final SourceWrapper wrapper = new SourceWrapper(fileType);
mySourceWrappers.add(wrapper);
if (lastUsed == null && wrapper.getText().equals(type))
lastUsed = wrapper;
if (curLanguage != null && wrapper.myFileType == curLanguage.getAssociatedFileType()) {
lastUsed = wrapper;
}
}
}
myFileTypeComboBox.setModel(new CollectionComboBoxModel<>(ContainerUtil.newArrayList(mySourceWrappers), lastUsed));
myFileTypeComboBox.setRenderer(new ListCellRendererWrapper<SourceWrapper>() {
@Override
public void customize(JList list, SourceWrapper value, int index, boolean selected, boolean hasFocus) {
if (value != null) {
setText(value.getText());
setIcon(value.getIcon());
}
}
});
new ComboboxSpeedSearch(myFileTypeComboBox) {
@Override
protected String getElementText(Object element) {
return element instanceof SourceWrapper ? ((SourceWrapper) element).getText() : null;
}
};
myFileTypeComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@NotNull ActionEvent e) {
updateDialectsCombo(null);
updateExtensionsCombo();
updateEditor();
}
});
myDialectComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@NotNull ActionEvent e) {
updateEditor();
}
});
new ComboboxSpeedSearch(myDialectComboBox) {
@Override
protected String getElementText(Object element) {
return element instanceof Language ? ((Language) element).getDisplayName() : "<default>";
}
};
myFileTypeComboBox.addFocusListener(new AutoExpandFocusListener(myFileTypeComboBox));
if (!myExternalDocument && lastUsed == null && mySourceWrappers.size() > 0) {
myFileTypeComboBox.setSelectedIndex(0);
}
myDialectComboBox.setRenderer(new ListCellRendererWrapper<Language>() {
@Override
public void customize(final JList list, final Language value, final int index, final boolean selected, final boolean hasFocus) {
setText(value != null ? value.getDisplayName() : "<default>");
}
});
myDialectComboBox.addFocusListener(new AutoExpandFocusListener(myDialectComboBox));
myExtensionComboBox.setRenderer(new ListCellRendererWrapper<String>() {
@Override
public void customize(JList list, String value, int index, boolean selected, boolean hasFocus) {
if (value != null)
setText("." + value);
}
});
myExtensionComboBox.addFocusListener(new AutoExpandFocusListener(myExtensionComboBox));
final ViewerTreeStructure psiTreeStructure = getTreeStructure();
myShowWhiteSpacesBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@NotNull ActionEvent e) {
psiTreeStructure.setShowWhiteSpaces(myShowWhiteSpacesBox.isSelected());
myPsiTreeBuilder.queueUpdate();
}
});
myShowTreeNodesCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@NotNull ActionEvent e) {
psiTreeStructure.setShowTreeNodes(myShowTreeNodesCheckBox.isSelected());
myPsiTreeBuilder.queueUpdate();
}
});
myShowWhiteSpacesBox.setSelected(settings.showWhiteSpaces);
psiTreeStructure.setShowWhiteSpaces(settings.showWhiteSpaces);
myShowTreeNodesCheckBox.setSelected(settings.showTreeNodes);
psiTreeStructure.setShowTreeNodes(settings.showTreeNodes);
myShowBlocksCheckBox.setSelected(settings.showBlocks);
myBlockStructurePanel.setVisible(settings.showBlocks);
myShowBlocksCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@NotNull ActionEvent e) {
if (!myShowBlocksCheckBox.isSelected()) {
settings.blockRefDividerLocation = myBlockRefSplitPane.getDividerLocation();
} else {
myBlockRefSplitPane.setDividerLocation(settings.blockRefDividerLocation);
}
myBlockStructurePanel.setVisible(myShowBlocksCheckBox.isSelected());
myBlockStructurePanel.repaint();
}
});
myTextPanel.setLayout(new BorderLayout());
myTextPanel.add(myEditor.getComponent(), BorderLayout.CENTER);
updateDialectsCombo(settings.dialect);
updateExtensionsCombo();
registerCustomKeyboardActions();
final Dimension size = DimensionService.getInstance().getSize(getDimensionServiceKey(), myProject);
if (size == null) {
DimensionService.getInstance().setSize(getDimensionServiceKey(), JBUI.size(800, 600));
}
myTextSplit.setDividerLocation(settings.textDividerLocation);
myTreeSplit.setDividerLocation(settings.treeDividerLocation);
myBlockRefSplitPane.setDividerLocation(settings.blockRefDividerLocation);
updateEditor();
super.init();
}
Aggregations