Skip to content

Commit

Permalink
Use FileUtil to collect file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
priyanshu16095 committed Jan 14, 2025
1 parent 31bb403 commit 858015f
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions src/main/java/org/jabref/gui/maintable/RightClickMenu.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.gui.maintable;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -36,7 +37,10 @@
import org.jabref.logic.citationstyle.CitationStyleOutputFormat;
import org.jabref.logic.citationstyle.CitationStylePreviewLayout;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.shared.DatabaseLocation;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.SpecialField;
Expand Down Expand Up @@ -121,24 +125,28 @@ private static Menu createCopyToMenu(ActionFactory factory,
List<String> checkedPaths = new ArrayList<>();

if (!openDatabases.isEmpty()) {
openDatabases.forEach(library -> {
library.getDatabasePath().ifPresent(databasePath -> {
String path = databasePath.toString();
String name = path.substring(path.lastIndexOf('\\') + 1);

if (!checkedPaths.contains(path)) {
checkedPaths.add(path);
}

copyToMenu.getItems().addAll(
factory.createCustomCheckMenuItem(
StandardActions.COPY_TO,
new CopyTo(dialogService, stateManager, preferences.getCopyToPreferences(), checkedPaths, path),
true,
name
)
);
});
openDatabases.forEach(bibDatabaseContext -> {
String path = " ";

if (bibDatabaseContext.getDatabasePath().isPresent()) {
Path databasePath = bibDatabaseContext.getDatabasePath().get();
path = FileUtil.getUniquePathFragment(stateManager.collectAllDatabasePaths(), databasePath).get();
} else if (bibDatabaseContext.getLocation() == DatabaseLocation.SHARED) {
path = bibDatabaseContext.getDBMSSynchronizer().getDBName() + " [" + Localization.lang("shared") + "]";
}

if (!checkedPaths.contains(path)) {
checkedPaths.add(path);
}

copyToMenu.getItems().addAll(
factory.createCustomCheckMenuItem(
StandardActions.COPY_TO,
new CopyTo(dialogService, stateManager, preferences.getCopyToPreferences(), checkedPaths, path),
true,
path
)
);
});
}

Expand Down

0 comments on commit 858015f

Please sign in to comment.