Skip to content

Commit b8c0e4d

Browse files
committed
Merge remote-tracking branch 'upstream/main' into jabrefonline
* upstream/main: Update Gradle Wrapper from 7.0.2 to 7.1. (#7829) Oobranch b : add utilies (#7787)
2 parents e7cda72 + 2f0c683 commit b8c0e4d

31 files changed

+1565
-29
lines changed

gradle/wrapper/gradle-wrapper.jar

333 Bytes
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionSha256Sum=0e46229820205440b48a5501122002842b82886e76af35f0f3a069243dca4b3c
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
3+
distributionSha256Sum=2debee19271e1b82c6e41137d78e44e6e841035230a1a169ca47fd3fb09ed87b
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

gradlew

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ case "`uname`" in
7272
Darwin* )
7373
darwin=true
7474
;;
75-
MINGW* )
75+
MSYS* | MINGW* )
7676
msys=true
7777
;;
7878
NONSTOP* )

src/main/java/org/jabref/gui/openoffice/CreationException.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/main/java/org/jabref/gui/openoffice/NoDocumentException.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/main/java/org/jabref/gui/openoffice/OOBibBase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import org.jabref.model.database.BibDatabase;
3737
import org.jabref.model.entry.BibEntry;
3838
import org.jabref.model.entry.field.StandardField;
39+
import org.jabref.model.openoffice.uno.CreationException;
40+
import org.jabref.model.openoffice.uno.NoDocumentException;
3941

4042
import com.sun.star.awt.Point;
4143
import com.sun.star.beans.IllegalTypeException;

src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
import org.jabref.model.database.BibDatabase;
5353
import org.jabref.model.database.BibDatabaseContext;
5454
import org.jabref.model.entry.BibEntry;
55+
import org.jabref.model.openoffice.uno.CreationException;
56+
import org.jabref.model.openoffice.uno.NoDocumentException;
5557
import org.jabref.preferences.PreferencesService;
5658

5759
import com.sun.star.beans.IllegalTypeException;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.jabref.model.openoffice.uno;
2+
3+
/**
4+
* Exception used to indicate failure in either
5+
*
6+
* XMultiServiceFactory.createInstance()
7+
* XMultiComponentFactory.createInstanceWithContext()
8+
*/
9+
public class CreationException extends Exception {
10+
11+
public CreationException(String message) {
12+
super(message);
13+
}
14+
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.jabref.model.openoffice.uno;
2+
3+
public class NoDocumentException extends Exception {
4+
5+
public NoDocumentException(String message) {
6+
super(message);
7+
}
8+
9+
public NoDocumentException() {
10+
super("Not connected to a document");
11+
}
12+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package org.jabref.model.openoffice.uno;
2+
3+
import java.util.Optional;
4+
5+
import com.sun.star.container.NoSuchElementException;
6+
import com.sun.star.container.XNameAccess;
7+
import com.sun.star.container.XNamed;
8+
import com.sun.star.lang.DisposedException;
9+
import com.sun.star.lang.WrappedTargetException;
10+
import com.sun.star.text.XBookmarksSupplier;
11+
import com.sun.star.text.XTextContent;
12+
import com.sun.star.text.XTextDocument;
13+
import com.sun.star.text.XTextRange;
14+
15+
public class UnoBookmark {
16+
17+
private UnoBookmark() { }
18+
19+
/**
20+
* Provides access to bookmarks by name.
21+
*/
22+
public static XNameAccess getNameAccess(XTextDocument doc)
23+
throws
24+
NoDocumentException {
25+
26+
XBookmarksSupplier supplier = UnoCast.cast(XBookmarksSupplier.class, doc).get();
27+
try {
28+
return supplier.getBookmarks();
29+
} catch (DisposedException ex) {
30+
throw new NoDocumentException("UnoBookmark.getNameAccess failed with" + ex);
31+
}
32+
}
33+
34+
/**
35+
* Get the XTextRange corresponding to the named bookmark.
36+
*
37+
* @param name The name of the bookmark to find.
38+
* @return The XTextRange for the bookmark, or Optional.empty().
39+
*/
40+
public static Optional<XTextRange> getAnchor(XTextDocument doc, String name)
41+
throws
42+
WrappedTargetException,
43+
NoDocumentException {
44+
45+
XNameAccess nameAccess = getNameAccess(doc);
46+
return (UnoNameAccess.getTextContentByName(nameAccess, name).map(XTextContent::getAnchor));
47+
}
48+
49+
/**
50+
* Insert a bookmark with the given name at the cursor provided, or with another name if the one
51+
* we asked for is already in use.
52+
*
53+
* In LibreOffice the another name is in "{name}{number}" format.
54+
*
55+
* @param name For the bookmark.
56+
* @param range Cursor marking the location or range for the bookmark.
57+
* @param absorb Shall we incorporate range?
58+
*
59+
* @return The XNamed interface of the bookmark.
60+
*
61+
* result.getName() should be checked by the caller, because its name may differ from
62+
* the one requested.
63+
*/
64+
public static XNamed create(XTextDocument doc, String name, XTextRange range, boolean absorb)
65+
throws
66+
CreationException {
67+
return UnoNamed.insertNamedTextContent(doc, "com.sun.star.text.Bookmark", name, range, absorb);
68+
}
69+
70+
/**
71+
* Remove the named bookmark if it exists.
72+
*/
73+
public static void removeIfExists(XTextDocument doc, String name)
74+
throws
75+
NoDocumentException,
76+
WrappedTargetException {
77+
78+
XNameAccess marks = UnoBookmark.getNameAccess(doc);
79+
80+
if (marks.hasByName(name)) {
81+
Optional<XTextContent> mark = UnoNameAccess.getTextContentByName(marks, name);
82+
if (mark.isEmpty()) {
83+
return;
84+
}
85+
try {
86+
doc.getText().removeTextContent(mark.get());
87+
} catch (NoSuchElementException ex) {
88+
// The caller gets what it expects.
89+
}
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)