private void setStructureViewSelectionFromPropertiesFile(@NotNull Editor propertiesFileEditor) { int line = propertiesFileEditor.getCaretModel().getLogicalPosition().line; Document document = propertiesFileEditor.getDocument(); if (line >= document.getLineCount()) { return; } final String propertyName = getPropertyName(document, line); if (propertyName == null) { return; } setStructureViewSelection(propertyName); }
private void setPropertiesFileSelectionFromStructureView(@NotNull Editor propertiesFileEditor) { String selectedPropertyName = getSelectedPropertyName(); if (selectedPropertyName == null) { return; } Document document = propertiesFileEditor.getDocument(); for (int i = 0; i < document.getLineCount(); i++) { String propertyName = getPropertyName(document, i); if (selectedPropertyName.equals(propertyName)) { propertiesFileEditor.getCaretModel().moveToLogicalPosition(new LogicalPosition(i, 0)); return; } } }
private void writeEditorPropertyValue( final Editor editor, final PropertiesFile propertiesFile, final @Nullable String propertyName) { final String currentValue = editor.getDocument().getText(); final String currentSelectedProperty = propertyName == null ? getSelectedPropertyName() : propertyName; if (currentSelectedProperty == null) { return; } ApplicationManager.getApplication() .runWriteAction( new Runnable() { @Override public void run() { WriteCommandAction.runWriteCommandAction( myProject, new Runnable() { @Override public void run() { final IProperty property = propertiesFile.findPropertyByKey(currentSelectedProperty); try { if (property == null) { propertiesFile.addProperty(currentSelectedProperty, currentValue); } else { property.setValue(currentValue); } } catch (final IncorrectOperationException e) { LOG.error(e); } } }); } }); }