private void updateDocumentFromPropertyValue( final String value, final Document document, final PropertiesFile propertiesFile) { @NonNls String text = value; if (myBackSlashPressed.contains(propertiesFile)) { text += "\\"; } document.replaceString(0, document.getTextLength(), text); }
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); }
@Nullable private static String getPropertyName(@NotNull Document document, int line) { int startOffset = document.getLineStartOffset(line); int endOffset = StringUtil.indexOf( document.getCharsSequence(), '=', startOffset, document.getLineEndOffset(line)); if (endOffset <= startOffset) { return null; } String propertyName = document.getCharsSequence().subSequence(startOffset, endOffset).toString().trim(); return propertyName.isEmpty() ? null : 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; } } }