Skip to content

Commit f2b4331

Browse files
kopporpalukku
andauthored
Streamline code for getTabTitle() (#13781)
* Remove double display of library filename * Minor code improvements * Final code changes * Add CHANGELOG.md entry (and fix typo in other line) * Consistent string * Fix typo * fix typo --------- Co-authored-by: Philip <[email protected]>
1 parent 1472aa3 commit f2b4331

File tree

4 files changed

+31
-38
lines changed

4 files changed

+31
-38
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
110110
- We fixed an issue showing an empty tooltip in maintable. [#11681](https://github.com/JabRef/jabref/issues/11681)
111111
- We fixed an issue displaying a warning if a file to open is not found. [#13430](https://github.com/JabRef/jabref/pull/13430)
112112
- We fixed an issue where Document Viewer showed technical exceptions when opening entries with non-PDF files. [#13198](https://github.com/JabRef/jabref/issues/13198)
113+
- We fixed an issue with double display of the library filename in the tab tooltip in the case of a changed library. [#13781](https://github.com/JabRef/jabref/pull/13781)
113114
- When creating a library, if you drag a PDF file containing only a single column, the dialog will now automatically close. [#13262](https://github.com/JabRef/jabref/issues/13262)
114-
- We fixed an issue where the tab showing the fulltext search results would appear blank after switching library. [#13241](https://github.com/JabRef/jabref/issues/13241)
115+
- We fixed an issue where the tab showing the fulltext search results would appear blank after switching libraries. [#13241](https://github.com/JabRef/jabref/issues/13241)
115116
- We fixed an issue where "Copy to" was enabled even if no other library was opened. [#13280](https://github.com/JabRef/jabref/pull/13280)
116117
- We fixed an issue where the groups were still displayed after closing all libraries. [#13382](https://github.com/JabRef/jabref/issues/13382)
117118
- Enhanced field selection logic in the Merge Entries dialog when fetching from DOI to prefer valid years and entry types. [#12549](https://github.com/JabRef/jabref/issues/12549)

jabgui/src/main/java/org/jabref/gui/LibraryTab.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,14 @@ private void initializeComponentsAndListeners(boolean isDummyContext) {
253253

254254
Platform.runLater(() -> {
255255
EasyBind.subscribe(changedProperty, this::updateTabTitle);
256-
stateManager.getOpenDatabases().addListener((ListChangeListener<BibDatabaseContext>) c ->
256+
stateManager.getOpenDatabases().addListener((ListChangeListener<BibDatabaseContext>) _ ->
257257
updateTabTitle(changedProperty.getValue()));
258258
});
259259
}
260260

261-
private static void addChangedInformation(StringBuilder text, String fileName) {
261+
private static void addChangedInformation(StringBuilder text) {
262262
text.append("\n");
263-
text.append(Localization.lang("Library '%0' has changed.", fileName));
263+
text.append(Localization.lang("The library has been modified."));
264264
}
265265

266266
private static void addModeInfo(StringBuilder text, BibDatabaseContext bibDatabaseContext) {
@@ -399,10 +399,10 @@ public void updateTabTitle(boolean isChanged) {
399399
tabTitle.append('*');
400400
}
401401

402-
// Filename
403402
Path databasePath = file.get();
404-
String fileName = databasePath.getFileName().toString();
405-
tabTitle.append(fileName);
403+
tabTitle.append(databasePath.getFileName().toString());
404+
Optional<String> uniquePathPart = FileUtil.getUniquePathDirectory(stateManager.getAllDatabasePaths(), databasePath);
405+
uniquePathPart.ifPresent(part -> tabTitle.append(" \u2013 ").append(part));
406406
toolTipText.append(databasePath.toAbsolutePath());
407407

408408
if (databaseLocation == DatabaseLocation.SHARED) {
@@ -417,12 +417,8 @@ public void updateTabTitle(boolean isChanged) {
417417

418418
// Changed information (tooltip)
419419
if (isChanged && !isAutosaveEnabled) {
420-
addChangedInformation(toolTipText, fileName);
420+
addChangedInformation(toolTipText);
421421
}
422-
423-
// Unique path fragment
424-
Optional<String> uniquePathPart = FileUtil.getUniquePathDirectory(stateManager.getAllDatabasePaths(), databasePath);
425-
uniquePathPart.ifPresent(part -> tabTitle.append(" \u2013 ").append(part));
426422
} else {
427423
if (databaseLocation == DatabaseLocation.LOCAL) {
428424
tabTitle.append('*');
@@ -433,7 +429,7 @@ public void updateTabTitle(boolean isChanged) {
433429
}
434430
addModeInfo(toolTipText, bibDatabaseContext);
435431
if ((databaseLocation == DatabaseLocation.LOCAL) && bibDatabaseContext.getDatabase().hasEntries()) {
436-
addChangedInformation(toolTipText, Localization.lang("untitled"));
432+
addChangedInformation(toolTipText);
437433
}
438434
}
439435

@@ -615,7 +611,7 @@ public boolean requestClose() {
615611
* Ask if the user really wants to close the given database.
616612
* Offers to save or discard the changes -- or return to the library
617613
*
618-
* @return <code>true</code> if the user choose to close the database
614+
* @return <code>true</code> if the user chooses to close the database
619615
*/
620616
private boolean confirmClose() {
621617
// Database could not have been changed, since it is still loading
@@ -637,7 +633,7 @@ private boolean confirmClose() {
637633

638634
Optional<ButtonType> response = dialogService.showCustomButtonDialogAndWait(Alert.AlertType.CONFIRMATION,
639635
Localization.lang("Save before closing"),
640-
Localization.lang("Library '%0' has changed.", filename),
636+
Localization.lang("Library '%0' has been modified.", filename),
641637
saveChanges, discardChanges, returnToLibrary);
642638

643639
if (response.isEmpty()) {

jablib/src/main/java/org/jabref/logic/util/io/FileUtil.java

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -141,29 +141,24 @@ public static Path addExtension(Path path, String extension) {
141141
return path.resolveSibling(path.getFileName() + extension);
142142
}
143143

144-
/**
145-
* Looks for the unique directory, if any, different to the provided paths
146-
*
147-
* @param paths List of paths as Strings
148-
* @param comparePath The to be tested path
149-
*/
144+
/// Looks for the shortest unique path of the parent directory in the list of paths
145+
/// @param paths List of paths as Strings
146+
/// @param comparePath The to be tested path
147+
///
148+
/// @return Optional.empty() if the paths are disjoint
150149
public static Optional<String> getUniquePathDirectory(List<String> paths, Path comparePath) {
151-
String fileName = comparePath.getFileName().toString();
152-
153-
List<String> uniquePathParts = uniquePathSubstrings(paths);
154-
return uniquePathParts.stream()
155-
.filter(part -> comparePath.toString().contains(part)
156-
&& !part.equals(fileName) && part.contains(File.separator))
157-
.findFirst()
158-
.map(part -> part.substring(0, part.lastIndexOf(File.separator)));
150+
// Difference to getUniquePathFragment: We want the parent directory, so we cut off the last path fragment
151+
return getUniquePathFragment(paths, comparePath)
152+
.filter(part -> part.contains(File.separator))
153+
.map(part -> part.substring(0, part.lastIndexOf(File.separator)));
159154
}
160155

161-
/**
162-
* Looks for the shortest unique path of the in a list of paths
163-
*
164-
* @param paths List of paths as Strings
165-
* @param comparePath The to be shortened path
166-
*/
156+
/// Looks for the shortest unique path in the list of paths
157+
///
158+
/// @param paths List of paths as Strings
159+
/// @param comparePath The to be shortened path
160+
///
161+
/// @return Shortest unique path fragment (if exists) - Optional.empty() if the paths are disjoint
167162
public static Optional<String> getUniquePathFragment(List<String> paths, Path comparePath) {
168163
return uniquePathSubstrings(paths).stream()
169164
.filter(part -> comparePath.toString().contains(part))

jablib/src/main/resources/l10n/JabRef_en.properties

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,9 +1419,6 @@ Existing\ entry=Existing entry
14191419
From\ import=From import
14201420
From\ DOI=From DOI
14211421
No\ problems\ found.=No problems found.
1422-
Save\ changes=Save changes
1423-
Discard\ changes=Discard changes
1424-
Library\ '%0'\ has\ changed.=Library '%0' has changed.
14251422
Print\ entry\ preview=Print entry preview
14261423

14271424
Invalid\ DOI\:\ '%0'.=Invalid DOI: '%0'.
@@ -2106,7 +2103,11 @@ Find\ and\ replace=Find and replace
21062103
Found\ documents\:=Found documents\:
21072104
Use\ selected\ document=Use selected document
21082105
Dismiss\ changes=Dismiss changes
2106+
The\ library\ has\ been\ modified.=The library has been modified.
2107+
Library\ '%0'\ has\ been\ modified.=Library '%0' has been modified.
21092108
The\ library\ has\ been\ modified\ by\ another\ program.=The library has been modified by another program.
2109+
Save\ changes=Save changes
2110+
Discard\ changes=Discard changes
21102111
21112112
Set\ rank\ to\ one=Set rank to one
21122113
Set\ rank\ to\ two=Set rank to two

0 commit comments

Comments
 (0)