Search in sources :

Example 21 with IProperty

use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.

the class ResourceBundleEditor method setStructureViewSelection.

private void setStructureViewSelection(@NotNull final String propertyName) {
    if (myStructureViewComponent.isDisposed()) {
        return;
    }
    JTree tree = myStructureViewComponent.getTree();
    if (tree == null) {
        return;
    }
    Object root = tree.getModel().getRoot();
    if (AbstractTreeUi.isLoadingChildrenFor(root)) {
        boolean isEditorVisible = false;
        for (FileEditor editor : FileEditorManager.getInstance(myProject).getSelectedEditors()) {
            if (editor == this) {
                isEditorVisible = true;
                break;
            }
        }
        if (!isEditorVisible) {
            myPropertyToSelectWhenVisible = propertyName;
            return;
        }
        mySelectionChangeAlarm.cancelAllRequests();
        mySelectionChangeAlarm.addRequest(() -> {
            mySelectionChangeAlarm.cancelAllRequests();
            setStructureViewSelection(propertyName);
        }, 500);
        return;
    }
    Stack<TreeElement> toCheck = ContainerUtilRt.newStack();
    toCheck.push(myStructureViewComponent.getTreeModel().getRoot());
    while (!toCheck.isEmpty()) {
        TreeElement element = toCheck.pop();
        PsiElement value = element instanceof ResourceBundlePropertyStructureViewElement ? ((ResourceBundlePropertyStructureViewElement) element).getProperty().getPsiElement() : null;
        if (value != null) {
            final IProperty property = PropertiesImplUtil.getProperty(value);
            if (propertyName.equals(property.getUnescapedKey())) {
                myStructureViewComponent.select(property, true);
                selectionChanged();
                return;
            }
        } else {
            for (TreeElement treeElement : element.getChildren()) {
                toCheck.push(treeElement);
            }
        }
    }
}
Also used : IProperty(com.intellij.lang.properties.IProperty) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement)

Example 22 with IProperty

use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.

the class ResourceBundlePropertiesUpdateManager method insertAfter.

public void insertAfter(@NotNull String key, @NotNull String value, @NotNull String anchor) {
    if (myAlphaSorted || !myOrdered) {
        throw new IllegalStateException("Can't insert new properties by anchor while resource bundle is alpha-sorted");
    }
    final PropertiesFile file = myResourceBundle.getDefaultPropertiesFile();
    final IProperty anchorProperty = file.findPropertyByKey(anchor);
    file.addPropertyAfter(key, value, anchorProperty);
    final int anchorIndex = myKeysOrder.indexOf(anchor);
    myKeysOrder.add(anchorIndex + 1, key);
}
Also used : IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 23 with IProperty

use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.

the class ResourceBundlePropertiesUpdateManager method insertPropertyLast.

private void insertPropertyLast(String key, String value, PropertiesFile propertiesFile) {
    final List<IProperty> properties = propertiesFile.getProperties();
    final IProperty lastProperty = properties.isEmpty() ? null : properties.get(properties.size() - 1);
    myCodeStyleManager.reformat(propertiesFile.addPropertyAfter(key, value, lastProperty).getPsiElement());
}
Also used : IProperty(com.intellij.lang.properties.IProperty)

Example 24 with IProperty

use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.

the class ResourceBundlePropertiesUpdateManager method findExistedPrevSiblingProperty.

private Pair<IProperty, Integer> findExistedPrevSiblingProperty(String key, PropertiesFile file) {
    if (myKeysOrder.isEmpty()) {
        return null;
    }
    final int prevPosition = myKeysOrder.indexOf(key);
    for (int i = prevPosition; i >= 0; i--) {
        final String prevKey = myKeysOrder.get(i);
        final IProperty property = file.findPropertyByKey(prevKey);
        if (property != null) {
            return Pair.create(property, prevPosition + 1);
        }
    }
    return null;
}
Also used : IProperty(com.intellij.lang.properties.IProperty)

Example 25 with IProperty

use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.

the class I18nizeQuickFixDialog method doOKAction.

@Override
protected void doOKAction() {
    if (!createPropertiesFileIfNotExists())
        return;
    Collection<PropertiesFile> propertiesFiles = getAllPropertiesFiles();
    for (PropertiesFile propertiesFile : propertiesFiles) {
        IProperty existingProperty = propertiesFile.findPropertyByKey(getKey());
        final String propValue = myValue.getText();
        if (existingProperty != null && !Comparing.strEqual(existingProperty.getValue(), propValue)) {
            final String messageText = CodeInsightBundle.message("i18nize.dialog.error.property.already.defined.message", getKey(), propertiesFile.getName());
            final int code = Messages.showOkCancelDialog(myProject, messageText, CodeInsightBundle.message("i18nize.dialog.error.property.already.defined.title"), null);
            if (code == Messages.CANCEL) {
                return;
            }
        }
    }
    super.doOKAction();
}
Also used : IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Aggregations

IProperty (com.intellij.lang.properties.IProperty)75 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)45 PsiElement (com.intellij.psi.PsiElement)17 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 PsiFile (com.intellij.psi.PsiFile)13 NotNull (org.jetbrains.annotations.NotNull)13 Property (com.intellij.lang.properties.psi.Property)11 Project (com.intellij.openapi.project.Project)7 ArrayList (java.util.ArrayList)7 Nullable (org.jetbrains.annotations.Nullable)7 ResourceBundle (com.intellij.lang.properties.ResourceBundle)6 THashSet (gnu.trove.THashSet)6 XmlPropertiesFile (com.intellij.lang.properties.xml.XmlPropertiesFile)4 Module (com.intellij.openapi.module.Module)4 Collections (java.util.Collections)4 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)3 PropertiesImplUtil (com.intellij.lang.properties.PropertiesImplUtil)3 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)2 XmlProperty (com.intellij.lang.properties.xml.XmlProperty)2 Logger (com.intellij.openapi.diagnostic.Logger)2