use of com.intellij.psi.injection.Injectable in project intellij-community by JetBrains.
the class InjectLanguageAction method getAllInjectables.
public static List<Injectable> getAllInjectables() {
Language[] languages = InjectedLanguage.getAvailableLanguages();
List<Injectable> list = new ArrayList<>();
for (Language language : languages) {
list.add(Injectable.fromLanguage(language));
}
list.addAll(Arrays.asList(ReferenceInjector.EXTENSION_POINT_NAME.getExtensions()));
Collections.sort(list);
return list;
}
use of com.intellij.psi.injection.Injectable in project intellij-community by JetBrains.
the class InjectLanguageAction method doChooseLanguageToInject.
public static boolean doChooseLanguageToInject(Editor editor, final Processor<Injectable> onChosen) {
final List<Injectable> injectables = getAllInjectables();
final JList list = new JBList(injectables);
list.setCellRenderer(new ColoredListCellRendererWrapper<Injectable>() {
@Override
protected void doCustomize(JList list, Injectable language, int index, boolean selected, boolean hasFocus) {
setIcon(language.getIcon());
append(language.getDisplayName());
String description = language.getAdditionalDescription();
if (description != null) {
append(description, SimpleTextAttributes.GRAYED_ATTRIBUTES);
}
}
});
Dimension minSize = new JLabel(PlainTextLanguage.INSTANCE.getDisplayName(), EmptyIcon.ICON_16, SwingConstants.LEFT).getMinimumSize();
minSize.height *= 4;
list.setMinimumSize(minSize);
JBPopup popup = new PopupChooserBuilder(list).setItemChoosenCallback(() -> {
Injectable value = (Injectable) list.getSelectedValue();
if (value != null) {
onChosen.process(value);
PropertiesComponent.getInstance().setValue(LAST_INJECTED_LANGUAGE, value.getId());
}
}).setFilteringEnabled(language -> ((Injectable) language).getDisplayName()).setMinSize(minSize).createPopup();
final String lastInjected = PropertiesComponent.getInstance().getValue(LAST_INJECTED_LANGUAGE);
if (lastInjected != null) {
Injectable injectable = ContainerUtil.find(injectables, injectable1 -> lastInjected.equals(injectable1.getId()));
list.setSelectedValue(injectable, true);
}
popup.showInBestPositionFor(editor);
return true;
}
Aggregations