Search in sources :

Example 36 with OpenFileDescriptor

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;
}
Also used : AttributesTableModel(com.android.tools.idea.editors.theme.attributes.AttributesTableModel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) ActionEvent(java.awt.event.ActionEvent) JBPopupMenu(com.intellij.openapi.ui.JBPopupMenu) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) Project(com.intellij.openapi.project.Project) ResourceResolver(com.android.ide.common.resources.ResourceResolver) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) TableModel(javax.swing.table.TableModel) AttributesTableModel(com.android.tools.idea.editors.theme.attributes.AttributesTableModel)

Example 37 with OpenFileDescriptor

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 38 with OpenFileDescriptor

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 39 with OpenFileDescriptor

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");
}
Also used : OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 40 with OpenFileDescriptor

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) OpenGradleSettingsHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenGradleSettingsHyperlink) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) NotNull(org.jetbrains.annotations.NotNull) GradleWrapper(com.android.tools.idea.gradle.util.GradleWrapper) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)155 VirtualFile (com.intellij.openapi.vfs.VirtualFile)97 Project (com.intellij.openapi.project.Project)40 Editor (com.intellij.openapi.editor.Editor)30 PsiElement (com.intellij.psi.PsiElement)27 PsiFile (com.intellij.psi.PsiFile)21 Navigatable (com.intellij.pom.Navigatable)19 Nullable (org.jetbrains.annotations.Nullable)18 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)10 Document (com.intellij.openapi.editor.Document)9 FileEditor (com.intellij.openapi.fileEditor.FileEditor)9 TextRange (com.intellij.openapi.util.TextRange)9 IncorrectOperationException (com.intellij.util.IncorrectOperationException)9 File (java.io.File)9 Result (com.intellij.openapi.application.Result)8 EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)8 NotNull (org.jetbrains.annotations.NotNull)6 TemplateBuilder (com.intellij.codeInsight.template.TemplateBuilder)5 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)5 XmlTag (com.intellij.psi.xml.XmlTag)5