use of com.intellij.ide.structureView.StructureView in project idea-handlebars by dmarcotte.
the class HbStructureViewFactory method getStructureViewBuilder.
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
return new TemplateLanguageStructureViewBuilder(psiFile) {
@Override
protected StructureViewComposite.StructureViewDescriptor createMainView(FileEditor fileEditor, PsiFile mainFile) {
if (!psiFile.isValid())
return null;
final StructureViewBuilder builder = new TreeBasedStructureViewBuilder() {
@NotNull
@Override
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
return new HbStructureViewModel((HbPsiFile) psiFile, editor);
}
};
StructureView structureView = builder.createStructureView(fileEditor, psiFile.getProject());
return new StructureViewComposite.StructureViewDescriptor(HbLanguage.INSTANCE.getDisplayName(), structureView, HbFileType.INSTANCE.getIcon());
}
};
}
use of com.intellij.ide.structureView.StructureView in project intellij-community by JetBrains.
the class ViewStructureAction method createPopup.
@Nullable
public static FileStructurePopup createPopup(@NotNull Project project, @NotNull FileEditor fileEditor) {
StructureViewBuilder structureViewBuilder = fileEditor.getStructureViewBuilder();
if (structureViewBuilder == null)
return null;
StructureView structureView = structureViewBuilder.createStructureView(fileEditor, project);
StructureViewModel model = structureView.getTreeModel();
if (model instanceof PlaceHolder) {
//noinspection unchecked
((PlaceHolder) model).setPlace(TreeStructureUtil.PLACE);
}
return createStructureViewPopup(project, fileEditor, structureView);
}
use of com.intellij.ide.structureView.StructureView in project intellij-community by JetBrains.
the class GotoClassAction method findMember.
@Nullable
private static Navigatable findMember(String pattern, PsiElement psiElement, VirtualFile file) {
final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiElement.getLanguage());
final StructureViewBuilder builder = factory == null ? null : factory.getStructureViewBuilder(psiElement.getContainingFile());
final FileEditor[] editors = FileEditorManager.getInstance(psiElement.getProject()).getEditors(file);
if (builder == null || editors.length == 0) {
return null;
}
final StructureView view = builder.createStructureView(editors[0], psiElement.getProject());
try {
final StructureViewTreeElement element = findElement(view.getTreeModel().getRoot(), psiElement, 4);
if (element == null) {
return null;
}
final MinusculeMatcher matcher = NameUtil.buildMatcher(pattern).build();
int max = Integer.MIN_VALUE;
Object target = null;
for (TreeElement treeElement : element.getChildren()) {
if (treeElement instanceof StructureViewTreeElement) {
String presentableText = treeElement.getPresentation().getPresentableText();
if (presentableText != null) {
final int degree = matcher.matchingDegree(presentableText);
if (degree > max) {
max = degree;
target = ((StructureViewTreeElement) treeElement).getValue();
}
}
}
}
return target instanceof Navigatable ? (Navigatable) target : null;
} finally {
Disposer.dispose(view);
}
}
use of com.intellij.ide.structureView.StructureView in project intellij-community by JetBrains.
the class SelectInContextImpl method doCreateEditorContext.
private static SelectInContext doCreateEditorContext(Project project, FileEditor editor, @Nullable DataContext dataContext) {
if (project == null || editor == null) {
return null;
}
VirtualFile file = FileEditorManagerEx.getInstanceEx(project).getFile(editor);
if (file == null) {
file = dataContext == null ? null : CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
if (file == null) {
return null;
}
}
final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (psiFile == null) {
return null;
}
if (editor instanceof TextEditor) {
return new TextEditorContext((TextEditor) editor, psiFile);
} else {
StructureViewBuilder builder = editor.getStructureViewBuilder();
StructureView structureView = builder != null ? builder.createStructureView(editor, project) : null;
Object selectorInFile = structureView != null ? structureView.getTreeModel().getCurrentEditorElement() : null;
if (structureView != null)
Disposer.dispose(structureView);
return new SimpleSelectInContext(psiFile, ObjectUtils.chooseNotNull(selectorInFile, psiFile));
}
}
use of com.intellij.ide.structureView.StructureView in project intellij-plugins by JetBrains.
the class CfmlStructureViewTest method getTopLevelItems.
private Object[] getTopLevelItems() {
StructureView structureView = createStructureViewModel();
final StructureViewModel structureViewModel = structureView.getTreeModel();
AbstractTreeStructure jsTreeStructure = new SmartTreeStructure(getProject(), structureViewModel);
Object[] items = jsTreeStructure.getChildElements(jsTreeStructure.getRootElement());
structureViewModel.dispose();
Disposer.dispose(structureView);
return items;
}
Aggregations