Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We excluded specific fields (e.g., `comment`, `pdf`, `sortkey`) from the consistency check to reduce false positives [#13131](https://github.com/JabRef/jabref/issues/13131)
- We fixed an issue where moved or renamed linked files in the file directory were not automatically relinked by the “search for unlinked files” feature. [#13264](https://github.com/JabRef/jabref/issues/13264)
- We fixed an issue with proxy setup in the absence of a password. [#12412](https://github.com/JabRef/jabref/issues/12412)
- We fixed an issue with the targets of the menu item "copy to". [#13741](https://github.com/JabRef/jabref/pull/13741)
- We fixed an issue where the tab showing the fulltext search results was not displayed. [#12865](https://github.com/JabRef/jabref/issues/12865)
- We fixed an issue showing an empty tooltip in maintable. [#11681](https://github.com/JabRef/jabref/issues/11681)
- We fixed an issue displaying a warning if a file to open is not found. [#13430](https://github.com/JabRef/jabref/pull/13430)
Expand Down
5 changes: 2 additions & 3 deletions jabgui/src/main/java/org/jabref/gui/actions/ActionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanExpression;
import javafx.collections.ObservableList;
import javafx.scene.control.TabPane;

import org.jabref.gui.StateManager;
import org.jabref.logic.preferences.CliPreferences;
Expand Down Expand Up @@ -38,8 +37,8 @@ public static BooleanExpression needsSharedDatabase(StateManager stateManager) {
return BooleanExpression.booleanExpression(binding);
}

public static BooleanExpression needsMultipleDatabases(TabPane tabbedPane) {
return Bindings.size(tabbedPane.getTabs()).greaterThan(1);
public static BooleanExpression needsMultipleDatabases(StateManager stateManager) {
return Bindings.size(stateManager.getOpenDatabases()).greaterThan(1);
}

public static BooleanExpression needsStudyDatabase(StateManager stateManager) {
Expand Down
2 changes: 1 addition & 1 deletion jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ private class CloseOthersDatabaseAction extends SimpleCommand {

public CloseOthersDatabaseAction(LibraryTab libraryTab) {
this.libraryTab = libraryTab;
this.executable.bind(ActionHelper.needsMultipleDatabases(tabbedPane));
this.executable.bind(ActionHelper.needsMultipleDatabases(stateManager));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public class MainTable extends TableView<BibEntryTableViewModel> {
private String columnSearchTerm;
private boolean citationMergeMode = false;

/// There is one maintable instance per library tab
public MainTable(MainTableDataModel model,
LibraryTab libraryTab,
LibraryTabContainer tabContainer,
Expand Down
66 changes: 28 additions & 38 deletions jabgui/src/main/java/org/jabref/gui/maintable/RightClickMenu.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package org.jabref.gui.maintable;

import java.util.Optional;

import javax.swing.undo.UndoManager;

import javafx.beans.binding.Bindings;
import javafx.collections.ObservableList;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
Expand All @@ -16,6 +12,7 @@
import org.jabref.gui.LibraryTab;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.ActionFactory;
import org.jabref.gui.actions.ActionHelper;
import org.jabref.gui.actions.StandardActions;
import org.jabref.gui.edit.CopyMoreAction;
import org.jabref.gui.edit.CopyTo;
Expand Down Expand Up @@ -127,45 +124,38 @@ private static Menu createCopyToMenu(ActionFactory factory,
ImportHandler importHandler) {
Menu copyToMenu = factory.createMenu(StandardActions.COPY_TO);
copyToMenu.disableProperty().bind(
Bindings.size(stateManager.getOpenDatabases()).lessThan(2)
ActionHelper.needsMultipleDatabases(stateManager).not()
);

ObservableList<BibDatabaseContext> openDatabases = stateManager.getOpenDatabases();
// Menu is created on each right-click, thus we can always assume that the list of open databases is up-to-date
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment restates what is obvious from the code context and doesn't provide additional value or reasoning. Comments should add new information not derivable from code.


BibDatabaseContext sourceDatabaseContext = libraryTab.getBibDatabaseContext();

Optional<String> sourceDatabaseName = libraryTab
.getBibDatabaseContext().getDatabasePath().stream()
.flatMap(path -> FileUtil.getUniquePathFragment(stateManager.getAllDatabasePaths(), path).stream())
.findFirst();

if (!openDatabases.isEmpty()) {
openDatabases.forEach(bibDatabaseContext -> {
Optional<String> destinationPath = Optional.empty();
String destinationDatabaseName = "";

if (bibDatabaseContext.getDatabasePath().isPresent()) {
Optional<String> uniqueFilePathFragment = FileUtil.getUniquePathFragment(stateManager.getAllDatabasePaths(), bibDatabaseContext.getDatabasePath().get());
if (uniqueFilePathFragment.equals(sourceDatabaseName)) {
return;
}
if (uniqueFilePathFragment.isPresent()) {
destinationDatabaseName = uniqueFilePathFragment.get();
}
} else if (bibDatabaseContext.getLocation() == DatabaseLocation.SHARED) {
destinationDatabaseName = bibDatabaseContext.getDBMSSynchronizer().getDBName() + " [" + Localization.lang("shared") + "]";
} else {
destinationDatabaseName = destinationPath.orElse(Localization.lang("untitled"));
}

copyToMenu.getItems().addAll(
factory.createCustomMenuItem(
StandardActions.COPY_TO,
new CopyTo(dialogService, stateManager, preferences.getCopyToPreferences(), importHandler, sourceDatabaseContext, bibDatabaseContext),
destinationDatabaseName
)
);
});
for (BibDatabaseContext targetDatabaseContext : stateManager.getOpenDatabases()) {
if (targetDatabaseContext == sourceDatabaseContext) {
continue;
}
String targetDatabaseName;

if (targetDatabaseContext.getDatabasePath().isPresent()) {
targetDatabaseName = FileUtil.getUniquePathFragment(
stateManager.getAllDatabasePaths(),
targetDatabaseContext.getDatabasePath().get()
).orElse(Localization.lang("untitled"));
} else if (targetDatabaseContext.getLocation() == DatabaseLocation.SHARED) {
targetDatabaseName = targetDatabaseContext.getDBMSSynchronizer().getDBName() + " [" + Localization.lang("shared") + "]";
} else {
targetDatabaseName = Localization.lang("untitled");
}

copyToMenu.getItems().add(
factory.createCustomMenuItem(
StandardActions.COPY_TO,
new CopyTo(dialogService, stateManager, preferences.getCopyToPreferences(),
importHandler, sourceDatabaseContext, targetDatabaseContext),
targetDatabaseName
)
);
}

return copyToMenu;
Expand Down