use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class GotoFileAction method gotoActionPerformed.
@Override
public void gotoActionPerformed(AnActionEvent e) {
final Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null)
return;
FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.file");
final GotoFileModel gotoFileModel = new GotoFileModel(project);
GotoActionCallback<FileType> callback = new GotoActionCallback<FileType>() {
@Override
protected ChooseByNameFilter<FileType> createFilter(@NotNull ChooseByNamePopup popup) {
return new GotoFileFilter(popup, gotoFileModel, project);
}
@Override
public void elementChosen(final ChooseByNamePopup popup, final Object element) {
if (element == null)
return;
ApplicationManager.getApplication().assertIsDispatchThread();
Navigatable n = (Navigatable) element;
//this is for better cursor position
if (element instanceof PsiFile) {
VirtualFile file = ((PsiFile) element).getVirtualFile();
if (file == null)
return;
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, popup.getLinePosition(), popup.getColumnPosition());
n = descriptor.setUseCurrentWindow(popup.isOpenInCurrentWindowRequested());
}
if (n.canNavigate()) {
n.navigate(true);
}
}
};
GotoFileItemProvider provider = new GotoFileItemProvider(project, getPsiContext(e), gotoFileModel);
showNavigationPopup(e, gotoFileModel, callback, IdeBundle.message("go.to.file.toolwindow.title"), true, true, provider);
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class EditorHelper method openInEditor.
@Nullable
public static FileEditor openInEditor(@NotNull PsiElement element, boolean switchToText) {
PsiFile file;
int offset;
if (element instanceof PsiFile) {
file = (PsiFile) element;
offset = -1;
} else {
file = element.getContainingFile();
offset = element.getTextOffset();
}
//SCR44414
if (file == null)
return null;
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null)
return null;
OpenFileDescriptor descriptor = new OpenFileDescriptor(element.getProject(), virtualFile, offset);
Project project = element.getProject();
if (offset == -1 && !switchToText) {
FileEditorManager.getInstance(project).openEditor(descriptor, false);
} else {
FileEditorManager.getInstance(project).openTextEditor(descriptor, false);
}
return FileEditorManager.getInstance(project).getSelectedEditor(virtualFile);
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class GotoDeclarationAction method navigateInCurrentEditor.
private static boolean navigateInCurrentEditor(@NotNull PsiElement element, @NotNull PsiFile currentFile, @NotNull Editor currentEditor) {
if (element.getContainingFile() == currentFile) {
int offset = element.getTextOffset();
PsiElement leaf = currentFile.findElementAt(offset);
// there are fake elements with custom navigation (e.g. opening URL in browser) that override getContainingFile for various reasons
if (leaf != null && PsiTreeUtil.isAncestor(element, leaf, false)) {
Project project = element.getProject();
CommandProcessor.getInstance().executeCommand(project, () -> {
IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation();
new OpenFileDescriptor(project, currentFile.getViewProvider().getVirtualFile(), offset).navigateIn(currentEditor);
}, "", null);
return true;
}
}
return false;
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class GotoTypeDeclarationAction method navigate.
private static void navigate(@NotNull Project project, @NotNull PsiElement symbolType) {
PsiElement element = symbolType.getNavigationElement();
assert element != null : "SymbolType :" + symbolType + "; file: " + symbolType.getContainingFile();
VirtualFile file = element.getContainingFile().getVirtualFile();
if (file != null) {
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, element.getTextOffset());
FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
}
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class TemplateBuilderImpl method run.
@Override
public void run() {
final Project project = myFile.getProject();
VirtualFile file = myFile.getVirtualFile();
assert file != null : "Virtual file is null for " + myFile;
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file);
final Editor editor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
assert editor != null : "Editor is null";
run(editor, false);
}
Aggregations