Search in sources :

Example 1 with DocumentationComponent

use of com.intellij.codeInsight.documentation.DocumentationComponent in project intellij-community by JetBrains.

the class ShowJavadoc method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null) {
        return;
    }
    DocumentationManager documentationManager = DocumentationManager.getInstance(project);
    final DocumentationComponent component = new DocumentationComponent(documentationManager);
    final Property property = myTable.getSelectionProperty();
    if (property == null) {
        return;
    }
    PsiElement javadocElement = property.getJavadocElement();
    ActionCallback callback;
    if (javadocElement == null) {
        callback = new ActionCallback();
        component.setText(property.getJavadocText(), null, true);
    } else {
        callback = documentationManager.queueFetchDocInfo(javadocElement, component);
    }
    callback.doWhenProcessed(() -> {
        JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component).setProject(project).setDimensionServiceKey(project, DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false).setResizable(true).setMovable(true).setRequestFocus(true).setTitle(DesignerBundle.message("designer.properties.javadoc.title", property.getName())).setCancelCallback(() -> {
            Disposer.dispose(component);
            return Boolean.TRUE;
        }).createPopup();
        component.setHint(hint);
        Disposer.register(hint, component);
        hint.show(new RelativePoint(myTable.getParent(), new Point(0, 0)));
    });
    if (javadocElement == null) {
        callback.setDone();
    }
}
Also used : Project(com.intellij.openapi.project.Project) DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager) DocumentationComponent(com.intellij.codeInsight.documentation.DocumentationComponent) ActionCallback(com.intellij.openapi.util.ActionCallback) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) JBPopup(com.intellij.openapi.ui.popup.JBPopup) Property(com.intellij.designer.model.Property) PsiElement(com.intellij.psi.PsiElement)

Example 2 with DocumentationComponent

use of com.intellij.codeInsight.documentation.DocumentationComponent in project android by JetBrains.

the class ShowCustomIssueExplanationFix method apply.

@Override
public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
    Project project = myElement.getProject();
    DocumentationManager manager = DocumentationManager.getInstance(project);
    DocumentationComponent component = new DocumentationComponent(manager);
    component.setText("<html>" + myIssue.getExplanation(TextFormat.HTML) + "</html>", myElement, false);
    JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component).setDimensionServiceKey(project, DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false).setResizable(true).setMovable(true).setRequestFocus(true).createPopup();
    component.setHint(popup);
    if (context.getType() == AndroidQuickfixContexts.EditorContext.TYPE) {
        popup.showInBestPositionFor(((AndroidQuickfixContexts.EditorContext) context).getEditor());
    } else {
        popup.showCenteredInCurrentWindow(project);
    }
    Disposer.dispose(component);
}
Also used : Project(com.intellij.openapi.project.Project) DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager) DocumentationComponent(com.intellij.codeInsight.documentation.DocumentationComponent) AndroidQuickfixContexts(org.jetbrains.android.inspections.lint.AndroidQuickfixContexts) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 3 with DocumentationComponent

use of com.intellij.codeInsight.documentation.DocumentationComponent in project android by JetBrains.

the class ShowJavadocAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    EditedStyleItem item = myCurrentItem;
    if (item == null) {
        return;
    }
    Project project = myContext.getProject();
    DocumentationManager documentationManager = DocumentationManager.getInstance(project);
    final DocumentationComponent docComponent = new DocumentationComponent(documentationManager);
    String tooltip = ThemeEditorUtils.generateToolTipText(item.getSelectedValue(), myContext.getCurrentContextModule(), myContext.getConfiguration());
    // images will not work unless we pass a valid PsiElement {@link DocumentationComponent#myImageProvider}
    docComponent.setText(tooltip, new FakePsiElement() {

        @Override
        public boolean isValid() {
            // this needs to return true for the DocumentationComponent to accept this PsiElement {@link DocumentationComponent#setData(PsiElement, String, boolean, String, String)}
            return true;
        }

        @NotNull
        @Override
        public Project getProject() {
            // superclass implementation throws an exception
            return myContext.getProject();
        }

        @Override
        public PsiElement getParent() {
            return null;
        }

        @Override
        public PsiFile getContainingFile() {
            // superclass implementation throws an exception
            return null;
        }
    }, true);
    JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(docComponent, docComponent).setProject(project).setDimensionServiceKey(project, DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false).setResizable(true).setMovable(true).setRequestFocus(true).setTitle(item.getName()).setCancelCallback(new Computable<Boolean>() {

        @Override
        public Boolean compute() {
            Disposer.dispose(docComponent);
            return Boolean.TRUE;
        }
    }).createPopup();
    docComponent.setHint(hint);
    Disposer.register(hint, docComponent);
    hint.show(new RelativePoint(myAttributesTable.getParent(), ORIGIN));
}
Also used : DocumentationComponent(com.intellij.codeInsight.documentation.DocumentationComponent) FakePsiElement(com.intellij.psi.impl.FakePsiElement) RelativePoint(com.intellij.ui.awt.RelativePoint) NotNull(org.jetbrains.annotations.NotNull) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) Project(com.intellij.openapi.project.Project) DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager) PsiFile(com.intellij.psi.PsiFile) JBPopup(com.intellij.openapi.ui.popup.JBPopup) FakePsiElement(com.intellij.psi.impl.FakePsiElement) PsiElement(com.intellij.psi.PsiElement) Computable(com.intellij.openapi.util.Computable)

Example 4 with DocumentationComponent

use of com.intellij.codeInsight.documentation.DocumentationComponent in project intellij-community by JetBrains.

the class ShowJavadocAction method actionPerformed.

public void actionPerformed(final AnActionEvent e) {
    final PropertyInspectorTable inspector = PropertyInspectorTable.DATA_KEY.getData(e.getDataContext());
    final IntrospectedProperty introspectedProperty = inspector.getSelectedIntrospectedProperty();
    final PsiClass aClass = inspector.getComponentClass();
    final PsiMethod getter = PropertyUtil.findPropertyGetter(aClass, introspectedProperty.getName(), false, true);
    LOG.assertTrue(getter != null);
    final PsiMethod setter = PropertyUtil.findPropertySetter(aClass, introspectedProperty.getName(), false, true);
    LOG.assertTrue(setter != null);
    final DocumentationManager documentationManager = DocumentationManager.getInstance(aClass.getProject());
    final DocumentationComponent component1 = new DocumentationComponent(documentationManager);
    final DocumentationComponent component2 = new DocumentationComponent(documentationManager);
    final Disposable disposable = Disposer.newDisposable();
    final TabbedPaneWrapper tabbedPane = new TabbedPaneWrapper(disposable);
    tabbedPane.addTab(UIDesignerBundle.message("tab.getter"), component1);
    tabbedPane.addTab(UIDesignerBundle.message("tab.setter"), component2);
    documentationManager.fetchDocInfo(getter, component1);
    documentationManager.queueFetchDocInfo(setter, component2).doWhenProcessed(() -> {
        final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(tabbedPane.getComponent(), component1).setDimensionServiceKey(aClass.getProject(), DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false).setResizable(true).setMovable(true).setRequestFocus(true).setTitle(UIDesignerBundle.message("property.javadoc.title", introspectedProperty.getName())).createPopup();
        component1.setHint(hint);
        component2.setHint(hint);
        Disposer.register(hint, component1);
        Disposer.register(hint, component2);
        Disposer.register(hint, disposable);
        hint.show(new RelativePoint(inspector, new Point(0, 0)));
    //component1.requestFocus();
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager) PropertyInspectorTable(com.intellij.uiDesigner.propertyInspector.PropertyInspectorTable) PsiMethod(com.intellij.psi.PsiMethod) DocumentationComponent(com.intellij.codeInsight.documentation.DocumentationComponent) TabbedPaneWrapper(com.intellij.ui.TabbedPaneWrapper) IntrospectedProperty(com.intellij.uiDesigner.propertyInspector.IntrospectedProperty) PsiClass(com.intellij.psi.PsiClass) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Aggregations

DocumentationComponent (com.intellij.codeInsight.documentation.DocumentationComponent)4 DocumentationManager (com.intellij.codeInsight.documentation.DocumentationManager)4 JBPopup (com.intellij.openapi.ui.popup.JBPopup)4 Project (com.intellij.openapi.project.Project)3 RelativePoint (com.intellij.ui.awt.RelativePoint)3 PsiElement (com.intellij.psi.PsiElement)2 EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)1 Property (com.intellij.designer.model.Property)1 Disposable (com.intellij.openapi.Disposable)1 ActionCallback (com.intellij.openapi.util.ActionCallback)1 Computable (com.intellij.openapi.util.Computable)1 PsiClass (com.intellij.psi.PsiClass)1 PsiFile (com.intellij.psi.PsiFile)1 PsiMethod (com.intellij.psi.PsiMethod)1 FakePsiElement (com.intellij.psi.impl.FakePsiElement)1 TabbedPaneWrapper (com.intellij.ui.TabbedPaneWrapper)1 IntrospectedProperty (com.intellij.uiDesigner.propertyInspector.IntrospectedProperty)1 PropertyInspectorTable (com.intellij.uiDesigner.propertyInspector.PropertyInspectorTable)1 AndroidQuickfixContexts (org.jetbrains.android.inspections.lint.AndroidQuickfixContexts)1 NotNull (org.jetbrains.annotations.NotNull)1