Search in sources :

Example 6 with DocumentationManager

use of com.intellij.codeInsight.documentation.DocumentationManager 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)

Example 7 with DocumentationManager

use of com.intellij.codeInsight.documentation.DocumentationManager 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 8 with DocumentationManager

use of com.intellij.codeInsight.documentation.DocumentationManager 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)

Aggregations

DocumentationManager (com.intellij.codeInsight.documentation.DocumentationManager)8 Project (com.intellij.openapi.project.Project)6 JBPopup (com.intellij.openapi.ui.popup.JBPopup)5 DocumentationComponent (com.intellij.codeInsight.documentation.DocumentationComponent)4 RelativePoint (com.intellij.ui.awt.RelativePoint)3 Document (com.intellij.openapi.editor.Document)2 Editor (com.intellij.openapi.editor.Editor)2 PsiElement (com.intellij.psi.PsiElement)2 NotNull (org.jetbrains.annotations.NotNull)2 EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)1 CodeInsightBundle (com.intellij.codeInsight.CodeInsightBundle)1 TargetElementUtil (com.intellij.codeInsight.TargetElementUtil)1 DocumentationManagerProtocol (com.intellij.codeInsight.documentation.DocumentationManagerProtocol)1 HintManager (com.intellij.codeInsight.hint.HintManager)1 HintManagerImpl (com.intellij.codeInsight.hint.HintManagerImpl)1 HintUtil (com.intellij.codeInsight.hint.HintUtil)1 GotoDeclarationAction (com.intellij.codeInsight.navigation.actions.GotoDeclarationAction)1 GotoTypeDeclarationAction (com.intellij.codeInsight.navigation.actions.GotoTypeDeclarationAction)1 Property (com.intellij.designer.model.Property)1 IdeTooltipManager (com.intellij.ide.IdeTooltipManager)1