Search in sources :

Example 1 with IntroStringProperty

use of com.intellij.uiDesigner.propertyInspector.properties.IntroStringProperty in project intellij-community by JetBrains.

the class FormSpellCheckingInspection method checkStringDescriptor.

@Override
protected void checkStringDescriptor(Module module, final IComponent component, final IProperty prop, final StringDescriptor descriptor, final FormErrorCollector collector) {
    final String value = descriptor.getResolvedValue();
    if (value == null) {
        return;
    }
    final SpellCheckerManager manager = SpellCheckerManager.getInstance(module.getProject());
    PlainTextSplitter.getInstance().split(value, TextRange.allOf(value), textRange -> {
        final String word = textRange.substring(value);
        if (manager.hasProblem(word)) {
            final List<String> suggestions = manager.getSuggestions(word);
            if (!suggestions.isEmpty() && prop instanceof IntroStringProperty) {
                EditorQuickFixProvider changeToProvider = new EditorQuickFixProvider() {

                    @Override
                    public QuickFix createQuickFix(final GuiEditor editor, final RadComponent component1) {
                        return new PopupQuickFix<String>(editor, "Change to...", component1) {

                            @Override
                            public void run() {
                                ListPopup popup = JBPopupFactory.getInstance().createListPopup(getPopupStep());
                                popup.showUnderneathOf(component1.getDelegee());
                            }

                            @Override
                            public ListPopupStep<String> getPopupStep() {
                                return new BaseListPopupStep<String>("Select Replacement", suggestions) {

                                    @Override
                                    public PopupStep onChosen(String selectedValue, boolean finalChoice) {
                                        FormInspectionUtil.updateStringPropertyValue(editor, component1, (IntroStringProperty) prop, descriptor, selectedValue);
                                        return FINAL_CHOICE;
                                    }
                                };
                            }
                        };
                    }
                };
                EditorQuickFixProvider acceptProvider = new EditorQuickFixProvider() {

                    @Override
                    public QuickFix createQuickFix(final GuiEditor editor, RadComponent component1) {
                        return new QuickFix(editor, "Save '" + word + "' to dictionary", component1) {

                            @Override
                            public void run() {
                                manager.acceptWordAsCorrect(word, editor.getProject());
                            }
                        };
                    }
                };
                collector.addError(getID(), component, prop, "Typo in word '" + word + "'", changeToProvider, acceptProvider);
            } else {
                collector.addError(getID(), component, prop, "Typo in word '" + word + "'");
            }
        }
    });
}
Also used : QuickFix(com.intellij.uiDesigner.quickFixes.QuickFix) PopupQuickFix(com.intellij.uiDesigner.quickFixes.PopupQuickFix) PopupQuickFix(com.intellij.uiDesigner.quickFixes.PopupQuickFix) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) SpellCheckerManager(com.intellij.spellchecker.SpellCheckerManager) IntroStringProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroStringProperty) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) ListPopup(com.intellij.openapi.ui.popup.ListPopup) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor)

Example 2 with IntroStringProperty

use of com.intellij.uiDesigner.propertyInspector.properties.IntroStringProperty in project intellij-community by JetBrains.

the class RadComponent method getComponentTitle.

@Nullable
public String getComponentTitle() {
    Palette palette = Palette.getInstance(getProject());
    IntrospectedProperty[] props = palette.getIntrospectedProperties(this);
    for (IntrospectedProperty prop : props) {
        if (prop.getName().equals(SwingProperties.TEXT) && prop instanceof IntroStringProperty) {
            StringDescriptor value = (StringDescriptor) prop.getValue(this);
            if (value != null) {
                return "\"" + value.getResolvedValue() + "\"";
            }
        }
    }
    if (this instanceof RadContainer) {
        RadContainer container = (RadContainer) this;
        StringDescriptor descriptor = container.getBorderTitle();
        if (descriptor != null) {
            if (descriptor.getResolvedValue() == null) {
                descriptor.setResolvedValue(StringDescriptorManager.getInstance(getModule()).resolve(this, descriptor));
            }
            return "\"" + descriptor.getResolvedValue() + "\"";
        }
    }
    if (getParent() instanceof RadTabbedPane) {
        RadTabbedPane parentTabbedPane = (RadTabbedPane) getParent();
        final StringDescriptor descriptor = parentTabbedPane.getChildTitle(this);
        if (descriptor != null) {
            if (descriptor.getResolvedValue() == null) {
                descriptor.setResolvedValue(StringDescriptorManager.getInstance(getModule()).resolve(this, descriptor));
            }
            return "\"" + descriptor.getResolvedValue() + "\"";
        } else {
            parentTabbedPane.getChildTitle(this);
        }
    }
    return null;
}
Also used : Palette(com.intellij.uiDesigner.palette.Palette) IntrospectedProperty(com.intellij.uiDesigner.propertyInspector.IntrospectedProperty) IntroStringProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroStringProperty) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with IntroStringProperty

use of com.intellij.uiDesigner.propertyInspector.properties.IntroStringProperty in project intellij-community by JetBrains.

the class GuiEditor method refreshProperties.

private void refreshProperties() {
    final Ref<Boolean> anythingModified = new Ref<>();
    FormEditingUtil.iterate(myRootContainer, new FormEditingUtil.ComponentVisitor() {

        public boolean visit(final IComponent component) {
            final RadComponent radComponent = (RadComponent) component;
            boolean componentModified = false;
            for (IProperty prop : component.getModifiedProperties()) {
                if (prop instanceof IntroStringProperty) {
                    IntroStringProperty strProp = (IntroStringProperty) prop;
                    componentModified = strProp.refreshValue(radComponent) || componentModified;
                }
            }
            if (component instanceof RadContainer) {
                componentModified = ((RadContainer) component).updateBorder() || componentModified;
            }
            if (component.getParentContainer() instanceof RadTabbedPane) {
                componentModified = ((RadTabbedPane) component.getParentContainer()).refreshChildTitle(radComponent) || componentModified;
            }
            if (componentModified) {
                anythingModified.set(Boolean.TRUE);
            }
            return true;
        }
    });
    if (!anythingModified.isNull()) {
        refresh();
        DesignerToolWindow designerToolWindow = DesignerToolWindowManager.getInstance(this);
        ComponentTree tree = designerToolWindow.getComponentTree();
        if (tree != null)
            tree.repaint();
        PropertyInspector inspector = designerToolWindow.getPropertyInspector();
        if (inspector != null)
            inspector.synchWithTree(true);
    }
}
Also used : IComponent(com.intellij.uiDesigner.lw.IComponent) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) DesignerToolWindow(com.intellij.uiDesigner.propertyInspector.DesignerToolWindow) PropertyInspector(com.intellij.uiDesigner.propertyInspector.PropertyInspector) ComponentTree(com.intellij.uiDesigner.componentTree.ComponentTree) Ref(com.intellij.openapi.util.Ref) RadTabbedPane(com.intellij.uiDesigner.radComponents.RadTabbedPane) IProperty(com.intellij.uiDesigner.lw.IProperty) IntroStringProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroStringProperty) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Aggregations

IntroStringProperty (com.intellij.uiDesigner.propertyInspector.properties.IntroStringProperty)3 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)2 ListPopup (com.intellij.openapi.ui.popup.ListPopup)1 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)1 Ref (com.intellij.openapi.util.Ref)1 SpellCheckerManager (com.intellij.spellchecker.SpellCheckerManager)1 ComponentTree (com.intellij.uiDesigner.componentTree.ComponentTree)1 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)1 IComponent (com.intellij.uiDesigner.lw.IComponent)1 IProperty (com.intellij.uiDesigner.lw.IProperty)1 Palette (com.intellij.uiDesigner.palette.Palette)1 DesignerToolWindow (com.intellij.uiDesigner.propertyInspector.DesignerToolWindow)1 IntrospectedProperty (com.intellij.uiDesigner.propertyInspector.IntrospectedProperty)1 PropertyInspector (com.intellij.uiDesigner.propertyInspector.PropertyInspector)1 PopupQuickFix (com.intellij.uiDesigner.quickFixes.PopupQuickFix)1 QuickFix (com.intellij.uiDesigner.quickFixes.QuickFix)1 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)1 RadTabbedPane (com.intellij.uiDesigner.radComponents.RadTabbedPane)1 Nullable (org.jetbrains.annotations.Nullable)1