Skip to content
Permalink
Browse files

Make setting the code not reset styling

  • Loading branch information...
adomasven committed Nov 16, 2017
1 parent b0326d9 commit 2deea6bd46b50f72cdc937a468e88ab6cd4461ad
Showing with 18 additions and 0 deletions.
  1. +18 −0 build/source/org/zotero/integration/ooo/comp/ReferenceMark.java
@@ -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 {

0 comments on commit 2deea6b

Please sign in to comment.
You can’t perform that action at this time.