Skip to content

Commit

Permalink
Make setting the code not reset styling
Browse files Browse the repository at this point in the history
  • Loading branch information
adomasven committed Nov 16, 2017
1 parent b0326d9 commit 2deea6b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions build/source/org/zotero/integration/ooo/comp/ReferenceMark.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,31 @@ public void setCode(String code) throws Exception {
String oldRawCode = rawCode;
rawCode = Document.PREFIXES[0] + code + " RND" + Document.getRandomString(Document.REFMARK_ADD_CHARS);
doc.mMarkManager.renameMark(oldRawCode, rawCode);
// Setting the ReferenceMark name resets the style to the document default, so
// we store the previous style.
XPropertySet rangeProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, range);
Object[] oldPropertyValues = new Object[PROPERTIES_CHANGE_TO_DEFAULT.length];
for(int i=0; i<PROPERTIES_CHANGE_TO_DEFAULT.length; i++) {
Object result = rangeProps.getPropertyValue(PROPERTIES_CHANGE_TO_DEFAULT[i]);
oldPropertyValues[i] = result instanceof Any ? ((Any) result).getObject() : result;
}

// Set the actual referenceMark code.
if(isTextSection) {
named.setName(rawCode);
} else {
// The only way to rename a ReferenceMark is to delete it and add it again
removeCode();
reattachMark();
}

// And restore the style here
for(int i=0; i<PROPERTIES_CHANGE_TO_DEFAULT.length; i++) {
if(oldPropertyValues[i] != null) {
rangeProps.setPropertyValue(PROPERTIES_CHANGE_TO_DEFAULT[i], oldPropertyValues[i]);
}
}
getOutOfField();
}

public String getCode() throws Exception {
Expand Down

0 comments on commit 2deea6b

Please sign in to comment.