use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project android by JetBrains.
the class ThemeEditorTable method getPopupMenuAtCell.
private JPopupMenu getPopupMenuAtCell(final int row, final int column) {
if (row < 0 || column < 0) {
return null;
}
TableModel rawModel = getModel();
if (!(rawModel instanceof AttributesTableModel)) {
return null;
}
final AttributesTableModel model = (AttributesTableModel) rawModel;
AttributesTableModel.RowContents contents = model.getRowContents(this.convertRowIndexToModel(row));
if (contents instanceof AttributesTableModel.AttributeContents) {
final AttributesTableModel.AttributeContents attribute = (AttributesTableModel.AttributeContents) contents;
final EditedStyleItem item = attribute.getValue();
if (item == null) {
return null;
}
final JBPopupMenu popupMenu = new JBPopupMenu();
if (attribute.getCellClass(1) == ConfiguredThemeEditorStyle.class) {
popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {
@Override
public void actionPerformed(ActionEvent e) {
myGoToListener.goTo(item);
}
});
} else {
final ResourceResolver resolver = myContext.getResourceResolver();
assert resolver != null;
final Project project = myContext.getProject();
final ResourceValue resourceValue = resolver.resolveResValue(item.getSelectedValue());
final File file = new File(resourceValue.getValue());
final VirtualFileManager manager = VirtualFileManager.getInstance();
final VirtualFile virtualFile = file.exists() ? manager.findFileByUrl("file://" + file.getAbsolutePath()) : null;
if (virtualFile != null) {
popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {
@Override
public void actionPerformed(ActionEvent e) {
final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile);
FileEditorManager.getInstance(project).openEditor(descriptor, true);
}
});
}
}
myJavadocAction.setCurrentItem(item);
popupMenu.add(myJavadocAction);
final ConfiguredThemeEditorStyle selectedStyle = model.getSelectedStyle();
if (!selectedStyle.isReadOnly() && selectedStyle.hasItem(item)) {
popupMenu.add(new AbstractAction("Reset value") {
@Override
public void actionPerformed(ActionEvent e) {
selectedStyle.removeAttribute(item.getQualifiedName());
model.fireTableCellUpdated(attribute.getRowIndex(), 0);
}
});
}
return popupMenu;
} else if (contents instanceof AttributesTableModel.ParentAttribute) {
final ConfiguredThemeEditorStyle parentStyle = model.getSelectedStyle().getParent();
if (parentStyle == null) {
return null;
}
final JBPopupMenu menu = new JBPopupMenu();
menu.add(new AbstractAction(GO_TO_DECLARATION) {
@Override
public void actionPerformed(ActionEvent e) {
myGoToListener.goToParent();
}
});
return menu;
}
return null;
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project android by JetBrains.
the class GradleBuildTreeStructure method addMessage.
@Override
public void addMessage(@NotNull ErrorTreeElementKind kind, @NotNull String[] text, @Nullable VirtualFile underFileGroup, @Nullable VirtualFile file, int line, int column, @Nullable Object data) {
if (underFileGroup != null || file != null) {
if (file == null)
line = column = -1;
int uiLine = line < 0 ? -1 : line + 1;
int uiColumn = column < 0 ? -1 : column + 1;
VirtualFile group = underFileGroup != null ? underFileGroup : file;
VirtualFile nav = file != null ? file : underFileGroup;
addNavigatableMessage(group.getPresentableUrl(), new OpenFileDescriptor(myProject, nav, line, column), kind, text, data, createExportPrefix(uiLine), createRendererPrefix(uiLine, uiColumn), group);
return;
}
addSimpleMessage(kind, text, data);
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project android by JetBrains.
the class GradleBuildTreeViewPanel method addMessage.
@Override
public void addMessage(int type, @NotNull String[] text, @Nullable String groupName, @NotNull Navigatable navigatable, @Nullable String exportTextPrefix, @Nullable String rendererTextPrefix, @Nullable Object data) {
if (myDisposed) {
return;
}
VirtualFile file = data instanceof VirtualFile ? (VirtualFile) data : null;
if (file == null && navigatable instanceof OpenFileDescriptor) {
file = ((OpenFileDescriptor) navigatable).getFile();
}
ErrorTreeElementKind kind = ErrorTreeElementKind.convertMessageFromCompilerErrorType(type);
myTreeStructure.addNavigatableMessage(groupName, navigatable, kind, text, data, nullToEmpty(exportTextPrefix), nullToEmpty(rendererTextPrefix), file);
myBuilder.updateTree();
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project android by JetBrains.
the class PermissionUsageQuickFix method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable /*is null when called from inspection*/
Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
//The Editor can be null at any time.
//Open the editor manually
openFile(project, file);
OpenFileDescriptor fileDesc = new OpenFileDescriptor(project, file.getVirtualFile(), startElement.getTextOffset());
editor = FileEditorManager.getInstance(project).openTextEditor(fileDesc, true);
assert editor != null;
int startOffset = startElement.getTextOffset();
int endOffset = endElement.getTextOffset() + endElement.getTextLength();
editor.getSelectionModel().setSelection(startOffset, endOffset);
PermissionUsageQuickFixRunnable job = new PermissionUsageQuickFixRunnable(project, editor);
execRunnable(job, "Permission Fix");
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project android by JetBrains.
the class GradleDslMethodNotFoundErrorHandler method getGradleSettingsHyperlink.
@NotNull
private static NotificationHyperlink getGradleSettingsHyperlink(@NotNull Project project) {
if (isUsingWrapper(project)) {
GradleWrapper gradleWrapper = GradleWrapper.find(project);
if (gradleWrapper != null) {
VirtualFile propertiesFile = gradleWrapper.getPropertiesFile();
if (propertiesFile != null) {
return new NotificationHyperlink("open.wrapper.file", "Open Gradle wrapper file") {
@Override
protected void execute(@NotNull Project project) {
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, propertiesFile);
FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
}
};
}
}
}
return new OpenGradleSettingsHyperlink();
}
Aggregations