diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ba222766b1..6f0f409ca3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,8 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where imports to a custom group would only work for the first entry [#11085](https://github.com/JabRef/jabref/issues/11085), [#11269](https://github.com/JabRef/jabref/issues/11269) - We fixed an issue where a new entry was not added to the selected group [#8933](https://github.com/JabRef/jabref/issues/8933) - We fixed an issue where the horizontal position of the Entry Preview inside the entry editor was not remembered across restarts [#11281](https://github.com/JabRef/jabref/issues/11281) +- We fixed an issue where the search index was not updated after linking PDF files. [#11317](https://github.com/JabRef/jabref/pull/11317) +- We fixed an issue where the entry editor context menu was not shown correctly when JabRef is opened on a second, extended screen [#11323](https://github.com/JabRef/jabref/issues/11323), [#11174](https://github.com/JabRef/jabref/issues/11174) ### Removed diff --git a/docs/code-howtos/index.md b/docs/code-howtos/index.md index 9d7a81c5337..ce306d9721f 100644 --- a/docs/code-howtos/index.md +++ b/docs/code-howtos/index.md @@ -41,7 +41,7 @@ Optional file = FileHelper.expandFilename(database, fileText, preferences. `String path` Can be the files name or a relative path to it. The Preferences should only be directly accessed in the GUI. For the usage in logic pass them as parameter -## Setting a Database Directory for a .bib File +## Setting a Directory for a .bib File * `@comment{jabref-meta: fileDirectory:` * “fileDirectory” is determined by Globals.pref.get(“userFileDir”) (which defaults to “fileDirectory” diff --git a/src/main/java/org/jabref/gui/LibraryTab.java b/src/main/java/org/jabref/gui/LibraryTab.java index fee48206318..590b9749e9a 100644 --- a/src/main/java/org/jabref/gui/LibraryTab.java +++ b/src/main/java/org/jabref/gui/LibraryTab.java @@ -313,6 +313,7 @@ private void setDatabaseContext(BibDatabaseContext bibDatabaseContext) { setupMainPanel(); setupAutoCompletion(); + this.getDatabase().registerListener(new IndexUpdateListener()); this.getDatabase().registerListener(new EntriesRemovedListener()); // ensure that at each addition of a new entry, the entry is added to the groups interface @@ -1098,9 +1099,9 @@ public void listen(FieldChangedEvent fieldChangedEvent) { List newFileList = FileFieldParser.parse(fieldChangedEvent.getNewValue()); List addedFiles = new ArrayList<>(newFileList); - addedFiles.remove(oldFileList); + addedFiles.removeAll(oldFileList); List removedFiles = new ArrayList<>(oldFileList); - removedFiles.remove(newFileList); + removedFiles.removeAll(newFileList); try { PdfIndexer indexer = PdfIndexerManager.getIndexer(bibDatabaseContext, preferencesService.getFilePreferences()); diff --git a/src/main/java/org/jabref/gui/fieldeditors/EditorTextArea.java b/src/main/java/org/jabref/gui/fieldeditors/EditorTextArea.java index 1091cb68ddc..a7487580ce9 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/EditorTextArea.java +++ b/src/main/java/org/jabref/gui/fieldeditors/EditorTextArea.java @@ -42,8 +42,7 @@ public void initContextMenu(final Supplier> items, KeyBindingRepo setOnContextMenuRequested(event -> { contextMenu.getItems().setAll(EditorContextAction.getDefaultContextMenuItems(this)); contextMenu.getItems().addAll(0, items.get()); - - TextInputControlBehavior.showContextMenu(this, contextMenu, event); + contextMenu.show(this, event.getScreenX(), event.getScreenY()); }); } diff --git a/src/main/java/org/jabref/gui/fieldeditors/EditorTextField.java b/src/main/java/org/jabref/gui/fieldeditors/EditorTextField.java index b54a5f4f442..03629650698 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/EditorTextField.java +++ b/src/main/java/org/jabref/gui/fieldeditors/EditorTextField.java @@ -38,8 +38,7 @@ public void initContextMenu(final Supplier> items, KeyBindingRepo setOnContextMenuRequested(event -> { contextMenu.getItems().setAll(EditorContextAction.getDefaultContextMenuItems(this)); contextMenu.getItems().addAll(0, items.get()); - - TextInputControlBehavior.showContextMenu(this, contextMenu, event); + contextMenu.show(this, event.getScreenX(), event.getScreenY()); }); } diff --git a/src/main/java/org/jabref/gui/fieldeditors/OptionEditor.java b/src/main/java/org/jabref/gui/fieldeditors/OptionEditor.java index f2be6350337..6f087db6df0 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/OptionEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/OptionEditor.java @@ -22,8 +22,6 @@ public class OptionEditor extends HBox implements FieldEditorFX { @FXML private final OptionEditorViewModel viewModel; @FXML private ComboBox comboBox; - @Inject private KeyBindingRepository keyBindingRepository; - public OptionEditor(OptionEditorViewModel viewModel) { ViewLoader.view(this) .root(this) @@ -39,7 +37,7 @@ public OptionEditor(OptionEditorViewModel viewModel) { comboBox.getEditor().setOnContextMenuRequested(event -> { ContextMenu contextMenu = new ContextMenu(); contextMenu.getItems().setAll(EditorContextAction.getDefaultContextMenuItems(comboBox.getEditor())); - TextInputControlBehavior.showContextMenu(comboBox.getEditor(), contextMenu, event); + contextMenu.show(comboBox, event.getScreenX(), event.getScreenY()); }); } diff --git a/src/main/java/org/jabref/gui/fieldeditors/TextInputControlBehavior.java b/src/main/java/org/jabref/gui/fieldeditors/TextInputControlBehavior.java deleted file mode 100644 index 31a45bc8c68..00000000000 --- a/src/main/java/org/jabref/gui/fieldeditors/TextInputControlBehavior.java +++ /dev/null @@ -1,140 +0,0 @@ -package org.jabref.gui.fieldeditors; - -import javafx.geometry.Point2D; -import javafx.geometry.Rectangle2D; -import javafx.scene.Scene; -import javafx.scene.control.ContextMenu; -import javafx.scene.control.TextArea; -import javafx.scene.control.TextField; -import javafx.scene.control.skin.TextAreaSkin; -import javafx.scene.control.skin.TextFieldSkin; -import javafx.scene.input.ContextMenuEvent; -import javafx.stage.Screen; -import javafx.stage.Window; - -import com.sun.javafx.scene.control.Properties; - -/** - * This class contains some code taken from {@link com.sun.javafx.scene.control.behavior.TextInputControlBehavior}, - * witch is not accessible and thus we have no other choice. - * TODO: remove this ugly workaround as soon as control behavior is made public - * reported at https://github.com/javafxports/openjdk-jfx/issues/583 - */ -public class TextInputControlBehavior { - - /** - * taken from {@link com.sun.javafx.scene.control.behavior.TextFieldBehavior#contextMenuRequested(javafx.scene.input.ContextMenuEvent)} - */ - public static void showContextMenu(TextField textField, ContextMenu contextMenu, ContextMenuEvent e) { - double screenX = e.getScreenX(); - double screenY = e.getScreenY(); - double sceneX = e.getSceneX(); - - TextFieldSkin skin = (TextFieldSkin) textField.getSkin(); - - if (Properties.IS_TOUCH_SUPPORTED) { - Point2D menuPos; - if (textField.getSelection().getLength() == 0) { - skin.positionCaret(skin.getIndex(e.getX(), e.getY()), false); - menuPos = skin.getMenuPosition(); - } else { - menuPos = skin.getMenuPosition(); - if (menuPos != null && (menuPos.getX() <= 0 || menuPos.getY() <= 0)) { - skin.positionCaret(skin.getIndex(e.getX(), e.getY()), false); - menuPos = skin.getMenuPosition(); - } - } - - if (menuPos != null) { - Point2D p = textField.localToScene(menuPos); - Scene scene = textField.getScene(); - Window window = scene.getWindow(); - Point2D location = new Point2D(window.getX() + scene.getX() + p.getX(), - window.getY() + scene.getY() + p.getY()); - screenX = location.getX(); - sceneX = p.getX(); - screenY = location.getY(); - } - } - - double menuWidth = contextMenu.prefWidth(-1); - double menuX = screenX - (Properties.IS_TOUCH_SUPPORTED ? (menuWidth / 2) : 0); - Screen currentScreen = Screen.getPrimary(); - Rectangle2D bounds = currentScreen.getBounds(); - - if (menuX < bounds.getMinX()) { - textField.getProperties().put("CONTEXT_MENU_SCREEN_X", screenX); - textField.getProperties().put("CONTEXT_MENU_SCENE_X", sceneX); - contextMenu.show(textField, bounds.getMinX(), screenY); - } else if (screenX + menuWidth > bounds.getMaxX()) { - double leftOver = menuWidth - (bounds.getMaxX() - screenX); - textField.getProperties().put("CONTEXT_MENU_SCREEN_X", screenX); - textField.getProperties().put("CONTEXT_MENU_SCENE_X", sceneX); - contextMenu.show(textField, screenX - leftOver, screenY); - } else { - textField.getProperties().put("CONTEXT_MENU_SCREEN_X", 0); - textField.getProperties().put("CONTEXT_MENU_SCENE_X", 0); - contextMenu.show(textField, menuX, screenY); - } - - e.consume(); - } - - /** - * taken from {@link com.sun.javafx.scene.control.behavior.TextAreaBehavior#contextMenuRequested(javafx.scene.input.ContextMenuEvent)} - */ - public static void showContextMenu(TextArea textArea, ContextMenu contextMenu, ContextMenuEvent e) { - double screenX = e.getScreenX(); - double screenY = e.getScreenY(); - double sceneX = e.getSceneX(); - - TextAreaSkin skin = (TextAreaSkin) textArea.getSkin(); - - if (Properties.IS_TOUCH_SUPPORTED) { - Point2D menuPos; - if (textArea.getSelection().getLength() == 0) { - skin.positionCaret(skin.getIndex(e.getX(), e.getY()), false); - menuPos = skin.getMenuPosition(); - } else { - menuPos = skin.getMenuPosition(); - if (menuPos != null && (menuPos.getX() <= 0 || menuPos.getY() <= 0)) { - skin.positionCaret(skin.getIndex(e.getX(), e.getY()), false); - menuPos = skin.getMenuPosition(); - } - } - - if (menuPos != null) { - Point2D p = textArea.localToScene(menuPos); - Scene scene = textArea.getScene(); - Window window = scene.getWindow(); - Point2D location = new Point2D(window.getX() + scene.getX() + p.getX(), - window.getY() + scene.getY() + p.getY()); - screenX = location.getX(); - sceneX = p.getX(); - screenY = location.getY(); - } - } - - double menuWidth = contextMenu.prefWidth(-1); - double menuX = screenX - (Properties.IS_TOUCH_SUPPORTED ? (menuWidth / 2) : 0); - Screen currentScreen = Screen.getPrimary(); - Rectangle2D bounds = currentScreen.getBounds(); - - if (menuX < bounds.getMinX()) { - textArea.getProperties().put("CONTEXT_MENU_SCREEN_X", screenX); - textArea.getProperties().put("CONTEXT_MENU_SCENE_X", sceneX); - contextMenu.show(textArea, bounds.getMinX(), screenY); - } else if (screenX + menuWidth > bounds.getMaxX()) { - double leftOver = menuWidth - (bounds.getMaxX() - screenX); - textArea.getProperties().put("CONTEXT_MENU_SCREEN_X", screenX); - textArea.getProperties().put("CONTEXT_MENU_SCENE_X", sceneX); - contextMenu.show(textArea, screenX - leftOver, screenY); - } else { - textArea.getProperties().put("CONTEXT_MENU_SCREEN_X", 0); - textArea.getProperties().put("CONTEXT_MENU_SCENE_X", 0); - contextMenu.show(textArea, menuX, screenY); - } - - e.consume(); - } -} diff --git a/src/main/java/org/jabref/gui/util/component/TemporalAccessorPicker.java b/src/main/java/org/jabref/gui/util/component/TemporalAccessorPicker.java index 77ea9d30a07..4b40aeb5e4f 100644 --- a/src/main/java/org/jabref/gui/util/component/TemporalAccessorPicker.java +++ b/src/main/java/org/jabref/gui/util/component/TemporalAccessorPicker.java @@ -18,7 +18,6 @@ import javafx.scene.control.DatePicker; import javafx.util.StringConverter; -import org.jabref.gui.fieldeditors.TextInputControlBehavior; import org.jabref.gui.fieldeditors.contextmenu.EditorContextAction; import org.jabref.gui.util.BindingsHelper; import org.jabref.model.entry.Date; @@ -27,18 +26,18 @@ /** * A date picker with configurable datetime format where both date and time can be changed via the text field and the * date can additionally be changed via the JavaFX default date picker. Also supports incomplete dates. - * + *

* First recall how the date picker normally works: - The user selects a date in the popup, which sets {@link * #valueProperty()} to the selected date. - The converter ({@link #converterProperty()}) is used to transform the date * to a string representation and display it in the text field. - * + *

* The idea is now to intercept the process and add an additional step: - The user selects a date in the popup, which * sets {@link #valueProperty()} to the selected date. - The date is converted to a {@link TemporalAccessor} (i.e, * enriched by a time component) using {@link #addCurrentTime(LocalDate)} - The string converter ({@link * #stringConverterProperty()}) is used to transform the temporal accessor to a string representation and display it in * the text field. - * - * Inspiration taken from https://github.com/edvin/tornadofx-controls/blob/master/src/main/java/tornadofx/control/DateTimePicker.java + *

+ * Inspiration taken from Controlsfx DateTimePicker */ public class TemporalAccessorPicker extends DatePicker { private final ObjectProperty temporalAccessorValue = new SimpleObjectProperty<>(null); @@ -57,7 +56,7 @@ public TemporalAccessorPicker() { getEditor().setOnContextMenuRequested(event -> { ContextMenu contextMenu = new ContextMenu(); contextMenu.getItems().setAll(EditorContextAction.getDefaultContextMenuItems(getEditor())); - TextInputControlBehavior.showContextMenu(getEditor(), contextMenu, event); + contextMenu.show(this, event.getScreenX(), event.getScreenY()); }); } diff --git a/src/main/java/org/jabref/model/database/BibDatabaseContext.java b/src/main/java/org/jabref/model/database/BibDatabaseContext.java index f8d4c3dfdcf..058a238187d 100644 --- a/src/main/java/org/jabref/model/database/BibDatabaseContext.java +++ b/src/main/java/org/jabref/model/database/BibDatabaseContext.java @@ -255,8 +255,8 @@ public Path getFulltextIndexPath() { Path indexPath; if (getDatabasePath().isPresent()) { - Path databaseFileName = getDatabasePath().get().getFileName(); - String fileName = BackupFileUtil.getUniqueFilePrefix(databaseFileName) + "--" + databaseFileName; + Path databasePath = getDatabasePath().get(); + String fileName = BackupFileUtil.getUniqueFilePrefix(databasePath) + "--" + databasePath.getFileName(); indexPath = appData.resolve(fileName); LOGGER.debug("Index path for {} is {}", getDatabasePath().get(), indexPath); return indexPath;