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);
}
}
}
}
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);
}
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());
}
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;
}
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();
}
Aggregations