Skip to content

Commit

Permalink
Unmerge LO citations (#7455)
Browse files Browse the repository at this point in the history
  • Loading branch information
antalk2 committed Mar 2, 2021
1 parent 2643357 commit b856dd4
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue with TexGroups on Linux systems, where the modification of an aux-file did not trigger an auto-update for TexGroups. Furthermore, the detection of file modifications is now more reliable. [#7412](https://github.com/JabRef/jabref/pull/7412)
- We fixed an issue where the Unicode to Latex formatter produced wrong results for characters with a codepoint higher than Character.MAX_VALUE. [#7387](https://github.com/JabRef/jabref/issues/7387)
- We fixed an issue where a non valid value as font size results in an uncaught exception. [#7415](https://github.com/JabRef/jabref/issues/7415)
- We fixed an issue where "Merge citations" in the Openoffice/Libreoffice integration panel did not have a corresponding opposite. [#7454](https://github.com/JabRef/jabref/issues/7454)
- We fixed an issue where drag and drop of bib files for opening resulted in uncaught exceptions [#7464](https://github.com/JabRef/jabref/issues/7464)

### Removed
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/org/jabref/gui/openoffice/OOBibBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,70 @@ public void combineCiteMarkers(List<BibDatabase> databases, OOBibStyle style)
}
}

/**
* Do the opposite of combineCiteMarkers.
* Combined markers are split, with a space inserted between.
*/
public void unCombineCiteMarkers(List<BibDatabase> databases, OOBibStyle style)
throws IOException, WrappedTargetException, NoSuchElementException, IllegalArgumentException,
UndefinedCharacterFormatException, UnknownPropertyException, PropertyVetoException, CreationException,
BibEntryNotFoundException {
XNameAccess nameAccess = getReferenceMarks();
List<String> names = getSortedReferenceMarks(nameAccess);

final XTextRangeCompare compare = UnoRuntime.queryInterface(XTextRangeCompare.class, text);

int pivot = 0;
boolean madeModifications = false;
while (pivot < (names.size())) {
XTextRange range1 = UnoRuntime.queryInterface(XTextContent.class, nameAccess.getByName(names.get(pivot)))
.getAnchor();

XTextCursor textCursor = range1.getText().createTextCursorByRange(range1);

// If we are supposed to set character format for citations, test this before
// making any changes. This way we can throw an exception before any reference
// marks are removed, preventing damage to the user's document:
if (style.isFormatCitations()) {
XPropertySet xCursorProps = UnoRuntime.queryInterface(XPropertySet.class, textCursor);
String charStyle = style.getCitationCharacterFormat();
try {
xCursorProps.setPropertyValue(CHAR_STYLE_NAME, charStyle);
} catch (UnknownPropertyException | PropertyVetoException | IllegalArgumentException |
WrappedTargetException ex) {
// Setting the character format failed, so we throw an exception that
// will result in an error message for the user:
throw new UndefinedCharacterFormatException(charStyle);
}
}

List<String> keys = parseRefMarkName(names.get(pivot));
if (keys.size() > 1) {
removeReferenceMark(names.get(pivot));

// Insert bookmark for each key
int last = keys.size() - 1;
int i = 0;
for (String key : keys) {
String newName = getUniqueReferenceMarkName(key, OOBibBase.AUTHORYEAR_PAR);
insertReferenceMark(newName, "tmp", textCursor, true, style);
textCursor.collapseToEnd();
if (i != last) {
textCursor.setString(" ");
textCursor.collapseToEnd();
}
i++;
}
madeModifications = true;
}
pivot++;
}
if (madeModifications) {
updateSortedReferenceMarks();
refreshCiteMarkers(databases, style);
}
}

public BibDatabase generateDatabase(List<BibDatabase> databases)
throws NoSuchElementException, WrappedTargetException {
BibDatabase resultDatabase = new BibDatabase();
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class OpenOfficePanel {
private final Button pushEntriesAdvanced = new Button(Localization.lang("Cite special"));
private final Button update;
private final Button merge = new Button(Localization.lang("Merge citations"));
private final Button unmerge = new Button(Localization.lang("Separate citations"));
private final Button manageCitations = new Button(Localization.lang("Manage citations"));
private final Button exportCitations = new Button(Localization.lang("Export cited"));
private final Button settingsB = new Button(Localization.lang("Settings"));
Expand Down Expand Up @@ -239,6 +240,21 @@ private void initPanel() {
LOGGER.warn("Problem combining cite markers", ex);
}
});

unmerge.setMaxWidth(Double.MAX_VALUE);
unmerge.setTooltip(new Tooltip(Localization.lang("Separate merged citations")));
unmerge.setOnAction(e -> {
try {
ooBase.unCombineCiteMarkers(getBaseList(), style);
} catch (UndefinedCharacterFormatException ex) {
reportUndefinedCharacterFormat(ex);
} catch (com.sun.star.lang.IllegalArgumentException | UnknownPropertyException | PropertyVetoException |
CreationException | NoSuchElementException | WrappedTargetException | IOException |
BibEntryNotFoundException ex) {
LOGGER.warn("Problem uncombining cite markers", ex);
}
});

ContextMenu settingsMenu = createSettingsPopup();
settingsB.setMaxWidth(Double.MAX_VALUE);
settingsB.setContextMenu(settingsMenu);
Expand All @@ -258,6 +274,7 @@ private void initPanel() {
pushEntriesAdvanced.setDisable(true);
update.setDisable(true);
merge.setDisable(true);
unmerge.setDisable(true);
manageCitations.setDisable(true);
exportCitations.setDisable(true);

Expand All @@ -271,7 +288,7 @@ private void initPanel() {
flow.setHgap(4);
flow.setPrefWrapLength(200);
flow.getChildren().addAll(setStyleFile, pushEntries, pushEntriesInt);
flow.getChildren().addAll(pushEntriesAdvanced, pushEntriesEmpty, merge);
flow.getChildren().addAll(pushEntriesAdvanced, pushEntriesEmpty, merge, unmerge);
flow.getChildren().addAll(manageCitations, exportCitations, settingsB);

vbox.setFillWidth(true);
Expand Down Expand Up @@ -422,6 +439,7 @@ protected OOBibBase call() throws Exception {
pushEntriesAdvanced.setDisable(false);
update.setDisable(false);
merge.setDisable(false);
unmerge.setDisable(false);
manageCitations.setDisable(false);
exportCitations.setDisable(false);
});
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2282,6 +2282,9 @@ No\ metadata\ found.\ Creating\ empty\ entry\ with\ file\ link=No metadata found
Processing\ file\ %0=Processing file %0
Export\ selected=Export selected
Separate\ merged\ citations=Separate merged citations
Separate\ citations=Separate citations
Unprotect\ terms=Unprotect terms
Error\ connecting\ to\ Writer\ document=Error connecting to Writer document
You\ need\ to\ open\ Writer\ with\ a\ document\ before\ connecting=You need to open Writer with a document before connecting

0 comments on commit b856dd4

Please sign in to comment.