use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class DvcsUtil method getSelectedFile.
/**
* Returns the currently selected file, based on which VcsBranch or StatusBar components will identify the current repository root.
*/
@Nullable
@CalledInAwt
public static VirtualFile getSelectedFile(@NotNull Project project) {
StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
final FileEditor fileEditor = StatusBarUtil.getCurrentFileEditor(project, statusBar);
VirtualFile result = null;
if (fileEditor != null) {
if (fileEditor instanceof TextEditor) {
Document document = ((TextEditor) fileEditor).getEditor().getDocument();
result = FileDocumentManager.getInstance().getFile(document);
} else if (fileEditor instanceof ImageFileEditor) {
result = ((ImageFileEditor) fileEditor).getImageEditor().getFile();
}
}
if (result == null) {
final FileEditorManager manager = FileEditorManager.getInstance(project);
if (manager != null) {
Editor editor = manager.getSelectedTextEditor();
if (editor != null) {
result = FileDocumentManager.getInstance().getFile(editor.getDocument());
}
}
}
return result;
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class AutoScrollFromSourceHandler method install.
public void install() {
final MessageBusConnection connection = myProject.getMessageBus().connect(myProject);
connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
final FileEditor editor = event.getNewEditor();
if (editor != null && myComponent.isShowing() && isAutoScrollEnabled()) {
myAlarm.cancelAllRequests();
myAlarm.addRequest(() -> selectElementFromEditor(editor), getAlarmDelay(), getModalityState());
}
}
});
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-plugins by JetBrains.
the class HbStructureViewTest method testStructureView.
public void testStructureView(PsiFile file, Consumer<StructureViewComposite> consumer) {
final VirtualFile vFile = file.getVirtualFile();
final FileEditor fileEditor = FileEditorManager.getInstance(getProject()).getSelectedEditor(vFile);
final StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(file);
assert builder != null;
StructureViewComposite composite = null;
try {
composite = (StructureViewComposite) builder.createStructureView(fileEditor, file.getProject());
consumer.consume(composite);
} finally {
if (composite != null)
Disposer.dispose(composite);
}
}
use of com.intellij.openapi.fileEditor.FileEditor in project android by JetBrains.
the class ConnectionDetailsView method update.
/**
* Updates the view to show given data. If given {@code httpData} is not null, show the details and set the view to be visible;
* otherwise, clears the view and set view to be invisible.
*/
public void update(@Nullable HttpData httpData) {
setBackground(JBColor.background());
myEditorPanel.removeAll();
myFieldsPanel.removeAll();
myCallstackView.setText("");
if (httpData != null) {
VirtualFile payloadVirtualFile = httpData.getResponsePayloadFile() != null ? LocalFileSystem.getInstance().findFileByIoFile(httpData.getResponsePayloadFile()) : null;
if (payloadVirtualFile != null) {
// TODO: Find proper project to refactor this.
Project project = ProjectManager.getInstance().getDefaultProject();
// TODO: Investigate when the editor provider is null.
FileEditorProvider[] editorProviders = FileEditorProviderManager.getInstance().getProviders(project, payloadVirtualFile);
FileEditor editor = editorProviders.length > 0 ? editorProviders[0].createEditor(project, payloadVirtualFile) : null;
if (editor != null) {
myEditorPanel.add(editor.getComponent(), BorderLayout.CENTER);
}
}
int row = 0;
myFieldsPanel.add(new NoWrapBoldLabel("Request"), new TabularLayout.Constraint(row, 0));
myFieldsPanel.add(new JLabel(HttpData.getUrlName(httpData.getUrl())), new TabularLayout.Constraint(row, 2));
String contentType = httpData.getResponseField(HttpData.FIELD_CONTENT_TYPE);
if (contentType != null) {
row++;
myFieldsPanel.add(new NoWrapBoldLabel("Content type"), new TabularLayout.Constraint(row, 0));
// Content type looks like "type/subtype;" or "type/subtype; parameters".
// Always convert to "type"
contentType = contentType.split(";")[0];
myFieldsPanel.add(new JLabel(contentType), new TabularLayout.Constraint(row, 2));
}
HyperlinkLabel urlLabel = new HyperlinkLabel(httpData.getUrl());
urlLabel.setHyperlinkTarget(httpData.getUrl());
row++;
myFieldsPanel.add(new NoWrapBoldLabel("URL"), new TabularLayout.Constraint(row, 0));
myFieldsPanel.add(urlLabel, new TabularLayout.Constraint(row, 2));
String contentLength = httpData.getResponseField(HttpData.FIELD_CONTENT_LENGTH);
if (contentLength != null) {
contentLength = contentLength.split(";")[0];
row++;
myFieldsPanel.add(new NoWrapBoldLabel("Content length"), new TabularLayout.Constraint(row, 0));
myFieldsPanel.add(new JLabel(contentLength), new TabularLayout.Constraint(row, 2));
}
// TODO: We are showing the callstack but we can't currently click on any of the links to
// navigate to the code.
myCallstackView.setText(httpData.getTrace());
repaint();
}
setVisible(httpData != null);
revalidate();
}
use of com.intellij.openapi.fileEditor.FileEditor in project android by JetBrains.
the class EditorFixture method selectEditorTab.
/**
* Selects the given tab in the current editor. Used to switch between
* design mode and editor mode for example.
*
* @param tab the tab to switch to
*/
public EditorFixture selectEditorTab(@NotNull final Tab tab) {
String tabName = tab.myTabName;
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
VirtualFile currentFile = getCurrentFile();
assertNotNull("Can't switch to tab " + tabName + " when no file is open in the editor", currentFile);
FileEditorManager manager = FileEditorManager.getInstance(myFrame.getProject());
FileEditor[] editors = manager.getAllEditors(currentFile);
FileEditor target = null;
for (FileEditor editor : editors) {
if (tabName == null || tabName.equals(editor.getName())) {
target = editor;
break;
}
}
if (target != null) {
// Have to use reflection
//FileEditorManagerImpl#setSelectedEditor(final FileEditor editor)
method("setSelectedEditor").withParameterTypes(FileEditor.class).in(manager).invoke(target);
return;
}
List<String> tabNames = Lists.newArrayList();
for (FileEditor editor : editors) {
tabNames.add(editor.getName());
}
fail("Could not find editor tab \"" + (tabName != null ? tabName : "<default>") + "\": Available tabs = " + tabNames);
}
});
return this;
}
Aggregations