diff --git a/CHANGELOG.md b/CHANGELOG.md index 4456c8c69af..cffb38db9c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ inserting new citations in a OpenOffic/LibreOffice document. [#6957](https://git - We improved the duplicate detection when identifiers like DOI or arxiv are semantiaclly the same, but just syntactically differ (e.g. with or without http(s):// prefix). [#6707](https://github.com/JabRef/jabref/issues/6707) - We changed in the group interface "Generate groups from keywords in a BibTeX field" by "Generate groups from keywords in the following field". [#6983](https://github.com/JabRef/jabref/issues/6983) - We changed the name of a group type from "Searching for keywords" to "Searching for a keyword". [6995](https://github.com/JabRef/jabref/pull/6995) +- We changed the way JabRef displays the title of a tab and of the window. [4161](https://github.com/JabRef/jabref/issues/4161) - We changed connect timeouts for server requests to 30 seconds in general and 5 seconds for GROBID server (special) and improved user notifications on connection issues. [7026](https://github.com/JabRef/jabref/pull/7026) ### Fixed diff --git a/src/main/java/org/jabref/gui/BasePanelPreferences.java b/src/main/java/org/jabref/gui/BasePanelPreferences.java deleted file mode 100644 index bc95224afa6..00000000000 --- a/src/main/java/org/jabref/gui/BasePanelPreferences.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.jabref.gui; - -import javafx.beans.property.DoubleProperty; -import javafx.beans.property.SimpleDoubleProperty; - -import org.jabref.gui.autocompleter.AutoCompletePreferences; -import org.jabref.gui.entryeditor.EntryEditorPreferences; -import org.jabref.gui.keyboard.KeyBindingRepository; -import org.jabref.gui.maintable.MainTablePreferences; -import org.jabref.preferences.JabRefPreferences; -import org.jabref.preferences.PreviewPreferences; - -import com.tobiasdiez.easybind.EasyBind; - -public class BasePanelPreferences { - private final MainTablePreferences tablePreferences; - private AutoCompletePreferences autoCompletePreferences; - private final EntryEditorPreferences entryEditorPreferences; - private final KeyBindingRepository keyBindings; - private final PreviewPreferences previewPreferences; - private final DoubleProperty entryEditorDividerPosition = new SimpleDoubleProperty(); - - public BasePanelPreferences(MainTablePreferences tablePreferences, AutoCompletePreferences autoCompletePreferences, EntryEditorPreferences entryEditorPreferences, KeyBindingRepository keyBindings, PreviewPreferences previewPreferences, Double entryEditorDividerPosition) { - this.tablePreferences = tablePreferences; - this.autoCompletePreferences = autoCompletePreferences; - this.entryEditorPreferences = entryEditorPreferences; - this.keyBindings = keyBindings; - this.previewPreferences = previewPreferences; - this.entryEditorDividerPosition.setValue(entryEditorDividerPosition); - } - - public static BasePanelPreferences from(JabRefPreferences preferences) { - BasePanelPreferences basePanelPreferences = new BasePanelPreferences( - preferences.getMainTablePreferences(), - preferences.getAutoCompletePreferences(), - preferences.getEntryEditorPreferences(), - Globals.getKeyPrefs(), - preferences.getPreviewPreferences(), - preferences.getDouble(JabRefPreferences.ENTRY_EDITOR_HEIGHT)); - EasyBind.subscribe(basePanelPreferences.entryEditorDividerPosition, value -> preferences.putDouble(JabRefPreferences.ENTRY_EDITOR_HEIGHT, value.doubleValue())); - return basePanelPreferences; - } - - public double getEntryEditorDividerPosition() { - return entryEditorDividerPosition.get(); - } - - public void setEntryEditorDividerPosition(double entryEditorDividerPosition) { - this.entryEditorDividerPosition.set(entryEditorDividerPosition); - } - - public DoubleProperty entryEditorDividerPositionProperty() { - return entryEditorDividerPosition; - } - - public MainTablePreferences getTablePreferences() { - return tablePreferences; - } - - public AutoCompletePreferences getAutoCompletePreferences() { - return autoCompletePreferences; - } - - public void setAutoCompletePreferences(AutoCompletePreferences autoCompletePreferences) { - this.autoCompletePreferences = autoCompletePreferences; - } - - public EntryEditorPreferences getEntryEditorPreferences() { - return entryEditorPreferences; - } - - public KeyBindingRepository getKeyBindings() { - return keyBindings; - } - - public PreviewPreferences getPreviewPreferences() { - return previewPreferences; - } -} diff --git a/src/main/java/org/jabref/gui/EntryTypeView.java b/src/main/java/org/jabref/gui/EntryTypeView.java index f304238b688..83d7baa191c 100644 --- a/src/main/java/org/jabref/gui/EntryTypeView.java +++ b/src/main/java/org/jabref/gui/EntryTypeView.java @@ -23,6 +23,7 @@ import org.jabref.gui.util.IconValidationDecorator; import org.jabref.gui.util.ViewModelListCellFactory; import org.jabref.logic.importer.IdBasedFetcher; +import org.jabref.logic.importer.WebFetcher; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntryType; @@ -60,7 +61,7 @@ public class EntryTypeView extends BaseDialog { @FXML private TitledPane customTitlePane; @FXML private TitledPane biblatexSoftwareTitlePane; - private final BasePanel basePanel; + private final LibraryTab libraryTab; private final DialogService dialogService; private final JabRefPreferences prefs; @@ -68,8 +69,8 @@ public class EntryTypeView extends BaseDialog { private EntryTypeViewModel viewModel; private final ControlsFxVisualizer visualizer = new ControlsFxVisualizer(); - public EntryTypeView(BasePanel basePanel, DialogService dialogService, JabRefPreferences preferences) { - this.basePanel = basePanel; + public EntryTypeView(LibraryTab libraryTab, DialogService dialogService, JabRefPreferences preferences) { + this.libraryTab = libraryTab; this.dialogService = dialogService; this.prefs = preferences; @@ -120,7 +121,7 @@ private void addEntriesToPane(FlowPane pane, Collection @FXML public void initialize() { visualizer.setDecoration(new IconValidationDecorator()); - viewModel = new EntryTypeViewModel(prefs, basePanel, dialogService, stateManager); + viewModel = new EntryTypeViewModel(prefs, libraryTab, dialogService, stateManager); idBasedFetchers.itemsProperty().bind(viewModel.fetcherItemsProperty()); idTextField.textProperty().bindBidirectional(viewModel.idTextProperty()); @@ -133,7 +134,7 @@ public void initialize() { } }); - new ViewModelListCellFactory().withText(item -> item.getName()).install(idBasedFetchers); + new ViewModelListCellFactory().withText(WebFetcher::getName).install(idBasedFetchers); // we set the managed property so that they will only be rendered when they are visble so that the Nodes only take the space when visible // avoids removing and adding from the scence graph @@ -143,7 +144,7 @@ public void initialize() { customTitlePane.managedProperty().bind(customTitlePane.visibleProperty()); biblatexSoftwareTitlePane.managedProperty().bind(biblatexSoftwareTitlePane.visibleProperty()); - if (basePanel.getBibDatabaseContext().isBiblatexMode()) { + if (libraryTab.getBibDatabaseContext().isBiblatexMode()) { addEntriesToPane(biblatexPane, BiblatexEntryTypeDefinitions.ALL); addEntriesToPane(biblatexSoftwarePane, BiblatexSoftwareEntryTypeDefinitions.ALL); diff --git a/src/main/java/org/jabref/gui/EntryTypeViewModel.java b/src/main/java/org/jabref/gui/EntryTypeViewModel.java index 926ad996e08..c2d055c08bb 100644 --- a/src/main/java/org/jabref/gui/EntryTypeViewModel.java +++ b/src/main/java/org/jabref/gui/EntryTypeViewModel.java @@ -46,13 +46,13 @@ public class EntryTypeViewModel { private final StringProperty idText = new SimpleStringProperty(); private final BooleanProperty focusAndSelectAllProperty = new SimpleBooleanProperty(); private Task> fetcherWorker = new FetcherWorker(); - private final BasePanel basePanel; + private final LibraryTab libraryTab; private final DialogService dialogService; private final Validator idFieldValidator; private final StateManager stateManager; - public EntryTypeViewModel(JabRefPreferences preferences, BasePanel basePanel, DialogService dialogService, StateManager stateManager) { - this.basePanel = basePanel; + public EntryTypeViewModel(JabRefPreferences preferences, LibraryTab libraryTab, DialogService dialogService, StateManager stateManager) { + this.libraryTab = libraryTab; this.prefs = preferences; this.dialogService = dialogService; this.stateManager = stateManager; @@ -147,22 +147,22 @@ public void runFetcherWorker() { Optional result = fetcherWorker.getValue(); if (result.isPresent()) { final BibEntry entry = result.get(); - ImportCleanup cleanup = new ImportCleanup(basePanel.getBibDatabaseContext().getMode()); + ImportCleanup cleanup = new ImportCleanup(libraryTab.getBibDatabaseContext().getMode()); cleanup.doPostCleanup(entry); - Optional duplicate = new DuplicateCheck(Globals.entryTypesManager).containsDuplicate(basePanel.getDatabase(), entry, basePanel.getBibDatabaseContext().getMode()); + Optional duplicate = new DuplicateCheck(Globals.entryTypesManager).containsDuplicate(libraryTab.getDatabase(), entry, libraryTab.getBibDatabaseContext().getMode()); if ((duplicate.isPresent())) { - DuplicateResolverDialog dialog = new DuplicateResolverDialog(entry, duplicate.get(), DuplicateResolverDialog.DuplicateResolverType.IMPORT_CHECK, basePanel.getBibDatabaseContext(), stateManager); + DuplicateResolverDialog dialog = new DuplicateResolverDialog(entry, duplicate.get(), DuplicateResolverDialog.DuplicateResolverType.IMPORT_CHECK, libraryTab.getBibDatabaseContext(), stateManager); switch (dialog.showAndWait().orElse(DuplicateResolverDialog.DuplicateResolverResult.BREAK)) { case KEEP_LEFT: - basePanel.getDatabase().removeEntry(duplicate.get()); - basePanel.getDatabase().insertEntry(entry); + libraryTab.getDatabase().removeEntry(duplicate.get()); + libraryTab.getDatabase().insertEntry(entry); break; case KEEP_BOTH: - basePanel.getDatabase().insertEntry(entry); + libraryTab.getDatabase().insertEntry(entry); break; case KEEP_MERGE: - basePanel.getDatabase().removeEntry(duplicate.get()); - basePanel.getDatabase().insertEntry(dialog.getMergedEntry()); + libraryTab.getDatabase().removeEntry(duplicate.get()); + libraryTab.getDatabase().insertEntry(dialog.getMergedEntry()); break; default: // Do nothing @@ -170,8 +170,8 @@ public void runFetcherWorker() { } } else { // Regenerate CiteKey of imported BibEntry - new CitationKeyGenerator(basePanel.getBibDatabaseContext(), prefs.getCitationKeyPatternPreferences()).generateAndSetKey(entry); - basePanel.insertEntry(entry); + new CitationKeyGenerator(libraryTab.getBibDatabaseContext(), prefs.getCitationKeyPatternPreferences()).generateAndSetKey(entry); + libraryTab.insertEntry(entry); } searchSuccesfulProperty.set(true); } else if (StringUtil.isBlank(idText.getValue())) { diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 612aa7d6e51..4855a16e3ca 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -1,6 +1,5 @@ package org.jabref.gui; -import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; @@ -11,8 +10,11 @@ import java.util.Objects; import java.util.Optional; import java.util.TimerTask; +import java.util.stream.Collectors; import javafx.application.Platform; +import javafx.beans.binding.Bindings; +import javafx.beans.binding.StringBinding; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.concurrent.Task; @@ -131,17 +133,15 @@ import org.jabref.logic.undo.UndoChangeEvent; import org.jabref.logic.undo.UndoRedoEvent; import org.jabref.logic.util.OS; -import org.jabref.logic.util.io.FileUtil; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.SpecialField; -import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; import org.jabref.preferences.JabRefPreferences; import org.jabref.preferences.LastFocusedTabPreferences; import com.google.common.eventbus.Subscribe; import com.tobiasdiez.easybind.EasyBind; +import com.tobiasdiez.easybind.EasyObservableList; import org.controlsfx.control.PopOver; import org.controlsfx.control.TaskProgressView; import org.fxmisc.richtext.CodeArea; @@ -153,7 +153,6 @@ */ public class JabRefFrame extends BorderPane { - // Frame titles. public static final String FRAME_TITLE = "JabRef"; private static final Logger LOGGER = LoggerFactory.getLogger(JabRefFrame.class); @@ -164,12 +163,13 @@ public class JabRefFrame extends BorderPane { private final FileHistoryMenu fileHistory; + @SuppressWarnings({"FieldCanBeLocal"}) private EasyObservableList openDatabaseList; + private final Stage mainStage; private final StateManager stateManager; private final CountingUndoManager undoManager; private final PushToApplicationsManager pushToApplicationsManager; private final DialogService dialogService; - private final JabRefExecutorService executorService; private SidePaneManager sidePaneManager; private TabPane tabbedPane; private SidePane sidePane; @@ -182,7 +182,6 @@ public JabRefFrame(Stage mainStage) { this.pushToApplicationsManager = new PushToApplicationsManager(dialogService, stateManager, prefs); this.undoManager = Globals.undoManager; this.fileHistory = new FileHistoryMenu(prefs, dialogService, getOpenDatabaseAction()); - this.executorService = JabRefExecutorService.INSTANCE; this.setOnKeyTyped(key -> { if (this.fileHistory.isShowing()) { if (this.fileHistory.openFileByKey(key)) { @@ -192,10 +191,6 @@ public JabRefFrame(Stage mainStage) { }); } - private static BasePanel getBasePanel(Tab tab) { - return (BasePanel) tab.getContent(); - } - private void initDragAndDrop() { Tab dndIndicator = new Tab(Localization.lang("Open files..."), null); dndIndicator.getStyleClass().add("drop"); @@ -236,7 +231,7 @@ private void initKeyBindings() { if (keyBinding.isPresent()) { switch (keyBinding.get()) { case FOCUS_ENTRY_TABLE: - getCurrentBasePanel().getMainTable().requestFocus(); + getCurrentLibraryTab().getMainTable().requestFocus(); event.consume(); break; case NEXT_LIBRARY: @@ -318,43 +313,6 @@ private Void showTrackingNotification() { return null; } - public void refreshTitleAndTabs() { - DefaultTaskExecutor.runInJavaFXThread(() -> { - - setWindowTitle(); - updateAllTabTitles(); - }); - } - - /** - * Sets the title of the main window. - */ - public void setWindowTitle() { - BasePanel panel = getCurrentBasePanel(); - - // no database open - if (panel == null) { - // setTitle(FRAME_TITLE); - return; - } - - String mode = panel.getBibDatabaseContext().getMode().getFormattedName(); - String modeInfo = String.format(" (%s)", Localization.lang("%0 mode", mode)); - boolean isAutosaveEnabled = Globals.prefs.getBoolean(JabRefPreferences.LOCAL_AUTO_SAVE); - - if (panel.getBibDatabaseContext().getLocation() == DatabaseLocation.LOCAL) { - String changeFlag = panel.isModified() && !isAutosaveEnabled ? "*" : ""; - String databaseFile = panel.getBibDatabaseContext() - .getDatabasePath() - .map(Path::toString) - .orElse(Localization.lang("untitled")); - // setTitle(FRAME_TITLE + " - " + databaseFile + changeFlag + modeInfo); - } else if (panel.getBibDatabaseContext().getLocation() == DatabaseLocation.SHARED) { - // setTitle(FRAME_TITLE + " - " + panel.getBibDatabaseContext().getDBMSSynchronizer().getDBName() + " [" - // + Localization.lang("shared") + "]" + modeInfo); - } - } - /** * The MacAdapter calls this method when a "BIB" file has been double-clicked from the Finder. */ @@ -394,7 +352,7 @@ private void tearDownJabRef(List filenames) { prefs.remove(JabRefPreferences.LAST_EDITED); } else { prefs.putStringList(JabRefPreferences.LAST_EDITED, filenames); - Path focusedDatabase = getCurrentBasePanel().getBibDatabaseContext().getDatabasePath().orElse(null); + Path focusedDatabase = getCurrentLibraryTab().getBibDatabaseContext().getDatabasePath().orElse(null); new LastFocusedTabPreferences(prefs).setLastFocusedTab(focusedDatabase); } } @@ -434,12 +392,12 @@ public boolean quit() { // Then ask if the user really wants to close, if the library has not been saved since last save. List filenames = new ArrayList<>(); for (int i = 0; i < tabbedPane.getTabs().size(); i++) { - BasePanel panel = getBasePanelAt(i); - final BibDatabaseContext context = panel.getBibDatabaseContext(); + LibraryTab libraryTab = getLibraryTabAt(i); + final BibDatabaseContext context = libraryTab.getBibDatabaseContext(); - if (panel.isModified() && (context.getLocation() == DatabaseLocation.LOCAL)) { + if (libraryTab.isModified() && (context.getLocation() == DatabaseLocation.LOCAL)) { tabbedPane.getSelectionModel().select(i); - if (!confirmClose(panel)) { + if (!confirmClose(libraryTab)) { return false; } } else if (context.getLocation() == DatabaseLocation.SHARED) { @@ -453,7 +411,7 @@ public boolean quit() { } WaitForSaveFinishedDialog waitForSaveFinishedDialog = new WaitForSaveFinishedDialog(dialogService); - waitForSaveFinishedDialog.showAndWait(getBasePanelList()); + waitForSaveFinishedDialog.showAndWait(getLibraryTabs()); // Good bye! tearDownJabRef(filenames); @@ -582,31 +540,29 @@ private Node createToolbar() { } /** - * Returns the indexed BasePanel. + * Returns the indexed LibraryTab. * * @param i Index of base */ - public BasePanel getBasePanelAt(int i) { - return (BasePanel) tabbedPane.getTabs().get(i).getContent(); + public LibraryTab getLibraryTabAt(int i) { + return (LibraryTab) tabbedPane.getTabs().get(i); } /** - * Returns a list of BasePanel. + * Returns a list of all LibraryTabs in this frame. */ - public List getBasePanelList() { - List returnList = new ArrayList<>(); - for (int i = 0; i < getBasePanelCount(); i++) { - returnList.add(getBasePanelAt(i)); - } - return returnList; + public List getLibraryTabs() { + return tabbedPane.getTabs().stream() + .map(tab -> (LibraryTab) tab) + .collect(Collectors.toList()); } - public void showBasePanelAt(int i) { + public void showLibraryTabAt(int i) { tabbedPane.getSelectionModel().select(i); } - public void showBasePanel(BasePanel bp) { - tabbedPane.getSelectionModel().select(getTab(bp)); + public void showLibraryTab(LibraryTab libraryTab) { + tabbedPane.getSelectionModel().select(libraryTab); } public void init() { @@ -617,26 +573,26 @@ public void init() { tabbedPane.setTabDragPolicy(TabPane.TabDragPolicy.REORDER); initLayout(); - initKeyBindings(); - initDragAndDrop(); - // setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()); - // WindowLocation pw = new WindowLocation(this, JabRefPreferences.POS_X, JabRefPreferences.POS_Y, JabRefPreferences.SIZE_X, - // JabRefPreferences.SIZE_Y); - // pw.displayWindowAtStoredLocation(); - // Bind global state + + // This variable cannot be inlined, since otherwise the list created by EasyBind is being garbage collected + openDatabaseList = EasyBind.map(tabbedPane.getTabs(), tab -> ((LibraryTab) tab).getBibDatabaseContext()); + EasyBind.bindContent(stateManager.getOpenDatabases(), openDatabaseList); + stateManager.activeDatabaseProperty().bind( EasyBind.map(tabbedPane.getSelectionModel().selectedItemProperty(), - tab -> Optional.ofNullable(tab).map(JabRefFrame::getBasePanel).map(BasePanel::getBibDatabaseContext))); + selectedTab -> Optional.ofNullable(selectedTab) + .map(tab -> (LibraryTab) tab) + .map(LibraryTab::getBibDatabaseContext))); // Subscribe to the search EasyBind.subscribe(stateManager.activeSearchQueryProperty(), query -> { - if (getCurrentBasePanel() != null) { - getCurrentBasePanel().setCurrentSearchQuery(query); + if (getCurrentLibraryTab() != null) { + getCurrentLibraryTab().setCurrentSearchQuery(query); } }); @@ -651,29 +607,30 @@ public void init() { EasyBind.subscribe(tabbedPane.getSelectionModel().selectedItemProperty(), tab -> { if (tab == null) { stateManager.setSelectedEntries(Collections.emptyList()); + mainStage.titleProperty().unbind(); + mainStage.setTitle(FRAME_TITLE); return; } - BasePanel newBasePanel = getBasePanel(tab); - if (newBasePanel != null) { - // Poor-mans binding to global state - stateManager.setSelectedEntries(newBasePanel.getSelectedEntries()); + LibraryTab libraryTab = (LibraryTab) tab; - // Update active search query when switching between databases - stateManager.activeSearchQueryProperty().set(newBasePanel.getCurrentSearchQuery()); + // Poor-mans binding to global state + stateManager.setSelectedEntries(libraryTab.getSelectedEntries()); - // groupSidePane.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(GroupSidePane.class)); - // previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled()); - // generalFetcher.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(WebSearchPane.class)); - // openOfficePanel.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(OpenOfficeSidePanel.class)); + // Update active search query when switching between databases + stateManager.activeSearchQueryProperty().set(libraryTab.getCurrentSearchQuery()); - setWindowTitle(); - // Update search autocompleter with information for the correct database: - newBasePanel.updateSearchManager(); + // Update search autocompleter with information for the correct database: + libraryTab.updateSearchManager(); - newBasePanel.getUndoManager().postUndoRedoEvent(); - newBasePanel.getMainTable().requestFocus(); - } + libraryTab.getUndoManager().postUndoRedoEvent(); + libraryTab.getMainTable().requestFocus(); + + // Set window title - copy tab title + StringBinding windowTitle = Bindings.createStringBinding( + () -> libraryTab.textProperty().getValue() + " \u2013 " + FRAME_TITLE, + libraryTab.textProperty()); + mainStage.titleProperty().bind(windowTitle); }); initShowTrackingNotification(); } @@ -681,11 +638,11 @@ public void init() { /** * Returns the currently viewed BasePanel. */ - public BasePanel getCurrentBasePanel() { + public LibraryTab getCurrentLibraryTab() { if ((tabbedPane == null) || (tabbedPane.getSelectionModel().getSelectedItem() == null)) { return null; } - return getBasePanel(tabbedPane.getSelectionModel().getSelectedItem()); + return (LibraryTab) tabbedPane.getSelectionModel().getSelectedItem(); } /** @@ -695,15 +652,6 @@ public int getBasePanelCount() { return tabbedPane.getTabs().size(); } - private Tab getTab(BasePanel comp) { - for (Tab tab : tabbedPane.getTabs()) { - if (tab.getContent() == comp) { - return tab; - } - } - return null; - } - /** * @deprecated do not operate on tabs but on BibDatabaseContexts */ @@ -712,14 +660,6 @@ public TabPane getTabbedPane() { return tabbedPane; } - public void setTabTitle(BasePanel comp, String title, String toolTip) { - DefaultTaskExecutor.runInJavaFXThread(() -> { - Tab tab = getTab(comp); - tab.setText(title); - tab.setTooltip(new Tooltip(toolTip)); - }); - } - private MenuBar createMenu() { ActionFactory factory = new ActionFactory(Globals.getKeyPrefs()); Menu file = new Menu(Localization.lang("File")); @@ -1025,21 +965,23 @@ hide it and clip it to a square of (width x width) each time width is updated. public void addParserResult(ParserResult parserResult, boolean focusPanel) { if (parserResult.toOpenTab()) { // Add the entries to the open tab. - BasePanel panel = getCurrentBasePanel(); - if (panel == null) { + LibraryTab libraryTab = getCurrentLibraryTab(); + if (libraryTab == null) { // There is no open tab to add to, so we create a new tab: addTab(parserResult.getDatabaseContext(), focusPanel); } else { - addImportedEntries(panel, parserResult); + addImportedEntries(libraryTab, parserResult); } } else { // only add tab if DB is not already open - Optional panel = getBasePanelList().stream() - .filter(p -> p.getBibDatabaseContext().getDatabasePath().equals(parserResult.getPath())) - .findFirst(); - - if (panel.isPresent()) { - tabbedPane.getSelectionModel().select(getTab(panel.get())); + Optional libraryTab = getLibraryTabs().stream() + .filter(p -> p.getBibDatabaseContext() + .getDatabasePath() + .equals(parserResult.getPath())) + .findFirst(); + + if (libraryTab.isPresent()) { + tabbedPane.getSelectionModel().select(libraryTab.get()); } else { addTab(parserResult.getDatabaseContext(), focusPanel); } @@ -1047,66 +989,17 @@ public void addParserResult(ParserResult parserResult, boolean focusPanel) { } /** - * This method causes all open BasePanels to set up their tables anew. When called from PrefsDialog3, this updates - * to the new settings. - */ + * This method causes all open LibraryTabs to set up their tables anew. When called from PreferencesDialogViewModel, + * this updates to the new settings. + * We need to notify all tabs about the changes to avoid problems when changing the column set. + * */ public void setupAllTables() { - // This action can be invoked without an open database, so - // we have to check if we have one before trying to invoke - // methods to execute changes in the preferences. - - // We want to notify all tabs about the changes to - // avoid problems when changing the column set. - for (int i = 0; i < tabbedPane.getTabs().size(); i++) { - BasePanel bf = getBasePanelAt(i); - - // Update tables: - if (bf.getDatabase() != null) { - DefaultTaskExecutor.runInJavaFXThread(bf::setupMainPanel); - } - } - } - - private List collectDatabaseFilePaths() { - List dbPaths = new ArrayList<>(getBasePanelCount()); - - for (BasePanel basePanel : getBasePanelList()) { - // db file exists - if (basePanel.getBibDatabaseContext().getDatabasePath().isPresent()) { - dbPaths.add(basePanel.getBibDatabaseContext().getDatabasePath().get().toAbsolutePath().toString()); - } else { - dbPaths.add(""); + tabbedPane.getTabs().forEach(tab -> { + LibraryTab libraryTab = (LibraryTab) tab; + if (libraryTab.getDatabase() != null) { + DefaultTaskExecutor.runInJavaFXThread(libraryTab::setupMainPanel); } - } - return dbPaths; - } - - private List getUniquePathParts() { - List dbPaths = collectDatabaseFilePaths(); - - return FileUtil.uniquePathSubstrings(dbPaths); - } - - public void updateAllTabTitles() { - List paths = getUniquePathParts(); - for (int i = 0; i < getBasePanelCount(); i++) { - String uniqPath = paths.get(i); - Optional file = getBasePanelAt(i).getBibDatabaseContext().getDatabasePath(); - - if (file.isPresent()) { - if (!uniqPath.equals(file.get().getFileName().toString()) && uniqPath.contains(File.separator)) { - // remove filename - uniqPath = uniqPath.substring(0, uniqPath.lastIndexOf(File.separator)); - tabbedPane.getTabs().get(i).setText(getBasePanelAt(i).getTabTitle() + " \u2014 " + uniqPath); - } else { - // set original filename (again) - tabbedPane.getTabs().get(i).setText(getBasePanelAt(i).getTabTitle()); - } - } else { - tabbedPane.getTabs().get(i).setText(getBasePanelAt(i).getTabTitle()); - } - tabbedPane.getTabs().get(i).setTooltip(new Tooltip(file.map(Path::toAbsolutePath).map(Path::toString).orElse(null))); - } + }); } private ContextMenu createTabContextMenu(KeyBindingRepository keyBindingRepository) { @@ -1125,55 +1018,48 @@ private ContextMenu createTabContextMenu(KeyBindingRepository keyBindingReposito return contextMenu; } - public void addTab(BasePanel basePanel, boolean raisePanel) { - // add tab - Tab newTab = new Tab(basePanel.getTabTitle(), basePanel); - tabbedPane.getTabs().add(newTab); - newTab.setOnCloseRequest(event -> { - closeTab((BasePanel) newTab.getContent()); + public void addTab(LibraryTab libraryTab, boolean raisePanel) { + tabbedPane.getTabs().add(libraryTab); + + libraryTab.setOnCloseRequest(event -> { + closeTab(libraryTab); event.consume(); }); - // add tab context menu - newTab.setContextMenu(createTabContextMenu(Globals.getKeyPrefs())); - - // update all tab titles - updateAllTabTitles(); + libraryTab.setContextMenu(createTabContextMenu(Globals.getKeyPrefs())); if (raisePanel) { - tabbedPane.getSelectionModel().select(newTab); + tabbedPane.getSelectionModel().select(libraryTab); } - // Register undo/redo listener - basePanel.getUndoManager().registerListener(new UndoRedoEventManager()); + libraryTab.getUndoManager().registerListener(new UndoRedoEventManager()); - BibDatabaseContext context = basePanel.getBibDatabaseContext(); + BibDatabaseContext context = libraryTab.getBibDatabaseContext(); if (readyForAutosave(context)) { AutosaveManager autosaver = AutosaveManager.start(context); - autosaver.registerListener(new AutosaveUiManager(basePanel)); + autosaver.registerListener(new AutosaveUiManager(libraryTab)); } BackupManager.start(context, Globals.entryTypesManager, prefs); - // Track opening - trackOpenNewDatabase(basePanel); + trackOpenNewDatabase(libraryTab); } - private void trackOpenNewDatabase(BasePanel basePanel) { + private void trackOpenNewDatabase(LibraryTab libraryTab) { Map properties = new HashMap<>(); Map measurements = new HashMap<>(); - measurements.put("NumberOfEntries", (double) basePanel.getBibDatabaseContext().getDatabase().getEntryCount()); + measurements.put("NumberOfEntries", (double) libraryTab.getBibDatabaseContext().getDatabase().getEntryCount()); Globals.getTelemetryClient().ifPresent(client -> client.trackEvent("OpenNewDatabase", properties, measurements)); } - public BasePanel addTab(BibDatabaseContext databaseContext, boolean raisePanel) { + public LibraryTab addTab(BibDatabaseContext databaseContext, boolean raisePanel) { Objects.requireNonNull(databaseContext); - BasePanel bp = new BasePanel(this, BasePanelPreferences.from(Globals.prefs), databaseContext, ExternalFileTypes.getInstance()); - addTab(bp, raisePanel); - return bp; + LibraryTab libraryTab = new LibraryTab(this, prefs, databaseContext, ExternalFileTypes.getInstance()); + addTab(libraryTab, raisePanel); + return libraryTab; } private boolean readyForAutosave(BibDatabaseContext context) { @@ -1189,7 +1075,7 @@ private boolean readyForAutosave(BibDatabaseContext context) { * @param panel The BasePanel to add to. * @param parserResult The entries to add. */ - private void addImportedEntries(final BasePanel panel, final ParserResult parserResult) { + private void addImportedEntries(final LibraryTab panel, final ParserResult parserResult) { BackgroundTask task = BackgroundTask.wrap(() -> parserResult); ImportCleanup cleanup = new ImportCleanup(panel.getBibDatabaseContext().getMode()); cleanup.doPostCleanup(parserResult.getDatabase().getEntries()); @@ -1202,47 +1088,17 @@ public FileHistoryMenu getFileHistory() { return fileHistory; } - /** - * Return a boolean, if the selected entry have file - * - * @param selectEntryList A selected entries list of the current base pane - * @return true, if the selected entry contains file. false, if multiple entries are selected or the selected entry - * doesn't contains file - */ - private boolean isExistFile(List selectEntryList) { - if (selectEntryList.size() == 1) { - BibEntry selectedEntry = selectEntryList.get(0); - return selectedEntry.getField(StandardField.FILE).isPresent(); - } - return false; - } - - /** - * Return a boolean, if the selected entry have url or doi - * - * @param selectEntryList A selected entries list of the current base pane - * @return true, if the selected entry contains url or doi. false, if multiple entries are selected or the selected - * entry doesn't contains url or doi - */ - private boolean isExistURLorDOI(List selectEntryList) { - if (selectEntryList.size() == 1) { - BibEntry selectedEntry = selectEntryList.get(0); - return (selectedEntry.getField(StandardField.URL).isPresent() || selectedEntry.getField(StandardField.DOI).isPresent()); - } - return false; - } - /** * Ask if the user really wants to close the given database * * @return true if the user choose to close the database */ - private boolean confirmClose(BasePanel panel) { - String filename = panel.getBibDatabaseContext() - .getDatabasePath() - .map(Path::toAbsolutePath) - .map(Path::toString) - .orElse(Localization.lang("untitled")); + private boolean confirmClose(LibraryTab libraryTab) { + String filename = libraryTab.getBibDatabaseContext() + .getDatabasePath() + .map(Path::toAbsolutePath) + .map(Path::toString) + .orElse(Localization.lang("untitled")); ButtonType saveChanges = new ButtonType(Localization.lang("Save changes"), ButtonBar.ButtonData.YES); ButtonType discardChanges = new ButtonType(Localization.lang("Discard changes"), ButtonBar.ButtonData.NO); @@ -1256,7 +1112,7 @@ private boolean confirmClose(BasePanel panel) { if (response.isPresent() && response.get().equals(saveChanges)) { // The user wants to save. try { - SaveDatabaseAction saveAction = new SaveDatabaseAction(panel, Globals.prefs, Globals.entryTypesManager); + SaveDatabaseAction saveAction = new SaveDatabaseAction(libraryTab, Globals.prefs, Globals.entryTypesManager); if (saveAction.save()) { return true; } @@ -1272,17 +1128,17 @@ private boolean confirmClose(BasePanel panel) { return response.isEmpty() || !response.get().equals(cancel); } - private void closeTab(BasePanel panel) { + private void closeTab(LibraryTab libraryTab) { // empty tab without database - if (panel == null) { + if (libraryTab == null) { return; } - final BibDatabaseContext context = panel.getBibDatabaseContext(); + final BibDatabaseContext context = libraryTab.getBibDatabaseContext(); - if (panel.isModified() && (context.getLocation() == DatabaseLocation.LOCAL)) { - if (confirmClose(panel)) { - removeTab(panel); + if (libraryTab.isModified() && (context.getLocation() == DatabaseLocation.LOCAL)) { + if (confirmClose(libraryTab)) { + removeTab(libraryTab); } else { return; } @@ -1290,26 +1146,23 @@ private void closeTab(BasePanel panel) { context.convertToLocalDatabase(); context.getDBMSSynchronizer().closeSharedDatabase(); context.clearDBMSSynchronizer(); - removeTab(panel); + removeTab(libraryTab); } else { - removeTab(panel); + removeTab(libraryTab); } AutosaveManager.shutdown(context); BackupManager.shutdown(context); } - private void removeTab(BasePanel panel) { + private void removeTab(LibraryTab libraryTab) { DefaultTaskExecutor.runInJavaFXThread(() -> { - panel.cleanUp(); - tabbedPane.getTabs().remove(getTab(panel)); - setWindowTitle(); - // update tab titles - updateAllTabTitles(); + libraryTab.cleanUp(); + tabbedPane.getTabs().remove(libraryTab); }); } public void closeCurrentTab() { - removeTab(getCurrentBasePanel()); + removeTab(getCurrentLibraryTab()); } public OpenDatabaseAction getOpenDatabaseAction() { @@ -1351,7 +1204,7 @@ private class CloseDatabaseAction extends SimpleCommand { @Override public void execute() { - closeTab(getCurrentBasePanel()); + closeTab(getCurrentLibraryTab()); } } @@ -1363,11 +1216,11 @@ public CloseOthersDatabaseAction() { @Override public void execute() { - BasePanel currentBasePanel = getCurrentBasePanel(); + LibraryTab currentLibraryTab = getCurrentLibraryTab(); for (Tab tab : tabbedPane.getTabs()) { - BasePanel basePanel = getBasePanel(tab); - if (basePanel != currentBasePanel) { - closeTab(basePanel); + LibraryTab libraryTab = (LibraryTab) tab; + if (libraryTab != currentLibraryTab) { + closeTab(libraryTab); } } } @@ -1378,8 +1231,7 @@ private class CloseAllDatabaseAction extends SimpleCommand { @Override public void execute() { for (Tab tab : tabbedPane.getTabs()) { - BasePanel basePanel = getBasePanel(tab); - closeTab(basePanel); + closeTab((LibraryTab) tab); } } } @@ -1403,7 +1255,7 @@ private class UndoRedoEventManager { @Subscribe public void listen(UndoRedoEvent event) { updateTexts(event); - JabRefFrame.this.getCurrentBasePanel().updateEntryEditorIfShowing(); + JabRefFrame.this.getCurrentLibraryTab().updateEntryEditorIfShowing(); } @Subscribe diff --git a/src/main/java/org/jabref/gui/JabRefGUI.java b/src/main/java/org/jabref/gui/JabRefGUI.java index c107fd46004..f9c9d646282 100644 --- a/src/main/java/org/jabref/gui/JabRefGUI.java +++ b/src/main/java/org/jabref/gui/JabRefGUI.java @@ -195,9 +195,9 @@ private void openDatabases() { for (int i = 0; (i < bibDatabases.size()) && (i < mainFrame.getBasePanelCount()); i++) { ParserResult pr = bibDatabases.get(i); - BasePanel panel = mainFrame.getBasePanelAt(i); + LibraryTab libraryTab = mainFrame.getLibraryTabAt(i); - OpenDatabaseAction.performPostOpenActions(panel, pr); + OpenDatabaseAction.performPostOpenActions(libraryTab, pr); } LOGGER.debug("Finished adding panels"); @@ -215,17 +215,17 @@ private void saveWindowState(Stage mainStage) { /** * outprints the Data from the Screen (only in debug mode) * - * @param mainStage + * @param mainStage JabRefs stage */ private void debugLogWindowState(Stage mainStage) { if (LOGGER.isDebugEnabled()) { StringBuilder debugLogString = new StringBuilder(); debugLogString.append("SCREEN DATA:"); - debugLogString.append("mainStage.WINDOW_MAXIMISED: " + mainStage.isMaximized() + "\n"); - debugLogString.append("mainStage.POS_X: " + mainStage.getX() + "\n"); - debugLogString.append("mainStage.POS_Y: " + mainStage.getY() + "\n"); - debugLogString.append("mainStage.SIZE_X: " + mainStage.getWidth() + "\n"); - debugLogString.append("mainStages.SIZE_Y: " + mainStage.getHeight() + "\n"); + debugLogString.append("mainStage.WINDOW_MAXIMISED: ").append(mainStage.isMaximized()).append("\n"); + debugLogString.append("mainStage.POS_X: ").append(mainStage.getX()).append("\n"); + debugLogString.append("mainStage.POS_Y: ").append(mainStage.getY()).append("\n"); + debugLogString.append("mainStage.SIZE_X: ").append(mainStage.getWidth()).append("\n"); + debugLogString.append("mainStages.SIZE_Y: ").append(mainStage.getHeight()).append("\n"); LOGGER.debug(debugLogString.toString()); } } diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/LibraryTab.java similarity index 71% rename from src/main/java/org/jabref/gui/BasePanel.java rename to src/main/java/org/jabref/gui/LibraryTab.java index e98e641a73b..2cb7174d95c 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/LibraryTab.java @@ -1,16 +1,22 @@ package org.jabref.gui; +import java.io.File; import java.nio.file.Path; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Optional; import javafx.application.Platform; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.collections.ListChangeListener; import javafx.geometry.Orientation; import javafx.scene.Node; import javafx.scene.control.SplitPane; -import javafx.scene.layout.StackPane; +import javafx.scene.control.Tab; +import javafx.scene.control.Tooltip; import org.jabref.gui.autocompleter.AutoCompletePreferences; import org.jabref.gui.autocompleter.PersonNameSuggestionProvider; @@ -34,6 +40,7 @@ import org.jabref.logic.search.SearchQuery; import org.jabref.logic.shared.DatabaseLocation; import org.jabref.logic.util.UpdateField; +import org.jabref.logic.util.io.FileUtil; import org.jabref.model.FieldChange; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; @@ -45,7 +52,7 @@ import org.jabref.model.entry.event.EntryChangedEvent; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldFactory; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import com.google.common.eventbus.Subscribe; import com.tobiasdiez.easybind.EasyBind; @@ -53,9 +60,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class BasePanel extends StackPane { +public class LibraryTab extends Tab { - private static final Logger LOGGER = LoggerFactory.getLogger(BasePanel.class); + private static final Logger LOGGER = LoggerFactory.getLogger(LibraryTab.class); private final BibDatabaseContext bibDatabaseContext; private final MainTableDataModel tableModel; @@ -71,39 +78,45 @@ public class BasePanel extends StackPane { private final EntryEditor entryEditor; private final DialogService dialogService; + private final PreferencesService preferencesService; + private MainTable mainTable; - private BasePanelPreferences preferences; private BasePanelMode mode = BasePanelMode.SHOWING_NOTHING; private SplitPane splitPane; private DatabaseChangePane changePane; private boolean saving; private PersonNameSuggestionProvider searchAutoCompleter; - private boolean baseChanged; - private boolean nonUndoableChange; + + private final BooleanProperty changedProperty = new SimpleBooleanProperty(false); + private final BooleanProperty nonUndoableChangeProperty = new SimpleBooleanProperty(false); // Used to track whether the base has changed since last save. + private BibEntry showing; private SuggestionProviders suggestionProviders; - @SuppressWarnings({"FieldCanBeLocal", "unused"}) private Subscription dividerPositionSubscription; + @SuppressWarnings({"FieldCanBeLocal"}) private Subscription dividerPositionSubscription; // the query the user searches when this BasePanel is active private Optional currentSearchQuery = Optional.empty(); private Optional changeMonitor = Optional.empty(); - public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabaseContext bibDatabaseContext, ExternalFileTypes externalFileTypes) { - this.preferences = Objects.requireNonNull(preferences); + public LibraryTab(JabRefFrame frame, + PreferencesService preferencesService, + BibDatabaseContext bibDatabaseContext, + ExternalFileTypes externalFileTypes) { this.frame = Objects.requireNonNull(frame); this.bibDatabaseContext = Objects.requireNonNull(bibDatabaseContext); this.externalFileTypes = Objects.requireNonNull(externalFileTypes); this.undoManager = frame.getUndoManager(); this.dialogService = frame.getDialogService(); + this.preferencesService = Objects.requireNonNull(preferencesService); bibDatabaseContext.getDatabase().registerListener(this); bibDatabaseContext.getMetaData().registerListener(this); this.sidePaneManager = frame.getSidePaneManager(); - this.tableModel = new MainTableDataModel(getBibDatabaseContext(), Globals.prefs, Globals.stateManager); + this.tableModel = new MainTableDataModel(getBibDatabaseContext(), preferencesService, Globals.stateManager); citationStyleCache = new CitationStyleCache(bibDatabaseContext); - annotationCache = new FileAnnotationCache(bibDatabaseContext, Globals.prefs.getFilePreferences()); + annotationCache = new FileAnnotationCache(bibDatabaseContext, preferencesService.getFilePreferences()); setupMainPanel(); setupAutoCompletion(); @@ -116,54 +129,136 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas // ensure that all entry changes mark the panel as changed this.bibDatabaseContext.getDatabase().registerListener(this); - this.getDatabase().registerListener(new UpdateTimestampListener(Globals.prefs)); + this.getDatabase().registerListener(new UpdateTimestampListener(preferencesService)); this.entryEditor = new EntryEditor(this, externalFileTypes); - } - @Subscribe - public void listen(BibDatabaseContextChangedEvent event) { - this.markBaseChanged(); + Platform.runLater(() -> { + EasyBind.subscribe(changedProperty, this::updateTabTitle); + Globals.stateManager.getOpenDatabases().addListener((ListChangeListener) c -> + updateTabTitle(changedProperty.getValue())); + }); } /** - * Returns a collection of suggestion providers, which are populated from the current library. + * Sets the title of the tab + * modification-asterisk filename – path-fragment + * + * The modification-asterisk (*) is shown if the file was modified since last save + * (path-fragment is only shown if filename is not (globally) unique) + * + * Example: + * *jabref-authors.bib – testbib */ - public SuggestionProviders getSuggestionProviders() { - return suggestionProviders; - } + public void updateTabTitle(boolean isChanged) { + boolean isAutosaveEnabled = preferencesService.getShouldAutosave(); + + DatabaseLocation databaseLocation = bibDatabaseContext.getLocation(); + Optional file = bibDatabaseContext.getDatabasePath(); - public String getTabTitle() { - StringBuilder title = new StringBuilder(); - DatabaseLocation databaseLocation = this.bibDatabaseContext.getLocation(); - boolean isAutosaveEnabled = Globals.prefs.getBoolean(JabRefPreferences.LOCAL_AUTO_SAVE); + StringBuilder tabTitle = new StringBuilder(); + StringBuilder toolTipText = new StringBuilder(); - if (databaseLocation == DatabaseLocation.LOCAL) { - if (this.bibDatabaseContext.getDatabasePath().isPresent()) { - title.append(this.bibDatabaseContext.getDatabasePath().get().getFileName()); - if (isModified() && !isAutosaveEnabled) { - title.append("*"); - } - } else { - title.append(Localization.lang("untitled")); + if (file.isPresent()) { + // Modification asterisk + if (isChanged && !isAutosaveEnabled) { + tabTitle.append('*'); + } + + // Filename + Path databasePath = file.get(); + String fileName = databasePath.getFileName().toString(); + tabTitle.append(fileName); + toolTipText.append(databasePath.toAbsolutePath().toString()); + + if (databaseLocation == DatabaseLocation.SHARED) { + tabTitle.append(" \u2013 "); + addSharedDbInformation(tabTitle, bibDatabaseContext); + toolTipText.append(' '); + addSharedDbInformation(toolTipText, bibDatabaseContext); + } + + // Database mode + addModeInfo(toolTipText, bibDatabaseContext); - if (getDatabase().hasEntries()) { + // Changed information (tooltip) + if (isChanged && !isAutosaveEnabled) { + addChangedInformation(toolTipText, fileName); + } + + // Unique path fragment + List uniquePathParts = FileUtil.uniquePathSubstrings(collectAllDatabasePaths()); + Optional uniquePathPart = uniquePathParts.stream() + .filter(part -> databasePath.toString().contains(part) + && !part.equals(fileName) && part.contains(File.separator)) + .findFirst(); + if (uniquePathPart.isPresent()) { + String uniquePath = uniquePathPart.get(); + // remove filename + uniquePath = uniquePath.substring(0, uniquePath.lastIndexOf(File.separator)); + tabTitle.append(" \u2013 ").append(uniquePath); + } + } else { + if (databaseLocation == DatabaseLocation.LOCAL) { + tabTitle.append(Localization.lang("untitled")); + if (bibDatabaseContext.getDatabase().hasEntries()) { // if the database is not empty and no file is assigned, // the database came from an import and has to be treated somehow // -> mark as changed - // This also happens internally at basepanel to ensure consistency line 224 - title.append('*'); + tabTitle.append('*'); } + } else { + addSharedDbInformation(tabTitle, bibDatabaseContext); + addSharedDbInformation(toolTipText, bibDatabaseContext); + } + addModeInfo(toolTipText, bibDatabaseContext); + if (databaseLocation == DatabaseLocation.LOCAL && bibDatabaseContext.getDatabase().hasEntries()) { + addChangedInformation(toolTipText, Localization.lang("untitled")); } - } else if (databaseLocation == DatabaseLocation.SHARED) { - title.append(this.bibDatabaseContext.getDBMSSynchronizer().getDBName() + " [" + Localization.lang("shared") + "]"); } - return title.toString(); + textProperty().setValue(tabTitle.toString()); + setTooltip(new Tooltip(toolTipText.toString())); } - public boolean isModified() { - return baseChanged; + private static void addChangedInformation(StringBuilder text, String fileName) { + text.append("\n"); + text.append(Localization.lang("Library '%0' has changed.", fileName)); + } + + private static void addModeInfo(StringBuilder text, BibDatabaseContext bibDatabaseContext) { + String mode = bibDatabaseContext.getMode().getFormattedName(); + String modeInfo = String.format("\n%s", Localization.lang("%0 mode", mode)); + text.append(modeInfo); + } + + private static void addSharedDbInformation(StringBuilder text, BibDatabaseContext bibDatabaseContext) { + text.append(bibDatabaseContext.getDBMSSynchronizer().getDBName()); + text.append(" ["); + text.append(Localization.lang("shared")); + text.append("]"); + } + + private List collectAllDatabasePaths() { + List list = new ArrayList<>(); + Globals.stateManager.getOpenDatabases().stream() + .map(BibDatabaseContext::getDatabasePath) + .forEachOrdered(pathOptional -> pathOptional.ifPresentOrElse( + path -> list.add(path.toAbsolutePath().toString()), + () -> list.add(""))); + return list; + } + + @Subscribe + public void listen(BibDatabaseContextChangedEvent event) { + this.changedProperty.setValue(true); + } + + /** + * Returns a collection of suggestion providers, which are populated from the current library. + */ + public SuggestionProviders getSuggestionProviders() { + return suggestionProviders; } public BasePanelMode getMode() { @@ -178,10 +273,6 @@ public JabRefFrame frame() { return frame; } - public void output(String s) { - dialogService.notify(s); - } - /** * Removes the selected entries from the database * @@ -210,8 +301,8 @@ private void delete(boolean cut, List entries) { bibDatabaseContext.getDatabase().removeEntries(entries); ensureNotShowingBottomPanel(entries); - markBaseChanged(); - this.output(formatOutputMessage(cut ? Localization.lang("Cut") : Localization.lang("Deleted"), entries.size())); + this.changedProperty.setValue(true); + dialogService.notify(formatOutputMessage(cut ? Localization.lang("Cut") : Localization.lang("Deleted"), entries.size())); // prevent the main table from loosing focus mainTable.requestFocus(); @@ -255,14 +346,14 @@ public void insertEntries(final List entries) { UpdateField.setAutomaticFields(entry, true, true, - Globals.prefs.getOwnerPreferences(), - Globals.prefs.getTimestampPreferences()); + preferencesService.getOwnerPreferences(), + preferencesService.getTimestampPreferences()); } // Create an UndoableInsertEntries object. getUndoManager().addEdit(new UndoableInsertEntries(bibDatabaseContext.getDatabase(), entries)); - markBaseChanged(); // The database just changed. - if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_OPEN_FORM)) { + this.changedProperty.setValue(true); // The database just changed. + if (preferencesService.getEntryEditorPreferences().shouldOpenOnNewEntry()) { showAndEdit(entries.get(0)); } clearAndSelect(entries.get(0)); @@ -284,11 +375,11 @@ private void createMainTable() { mainTable = new MainTable(tableModel, this, bibDatabaseContext, - Globals.prefs, + preferencesService, dialogService, Globals.stateManager, externalFileTypes, - preferences.getKeyBindings()); + Globals.getKeyPrefs()); // Add the listener that binds selection to state manager (TODO: should be replaced by proper JavaFX binding as soon as table is implemented in JavaFX) mainTable.addSelectionListener(listEvent -> Globals.stateManager.setSelectedEntries(mainTable.getSelectedEntries())); @@ -301,11 +392,8 @@ private void createMainTable() { } public void setupMainPanel() { - preferences = BasePanelPreferences.from(Globals.prefs); - splitPane = new SplitPane(); splitPane.setOrientation(Orientation.VERTICAL); - adjustSplitter(); // restore last splitting state (before mainTable is created as creation affects the stored size of the entryEditors) createMainTable(); @@ -327,10 +415,10 @@ public void setupMainPanel() { // if the database is not empty and no file is assigned, // the database came from an import and has to be treated somehow // -> mark as changed - this.baseChanged = true; + this.changedProperty.setValue(true); } changePane = null; - getChildren().add(splitPane); + this.setContent(splitPane); } } @@ -338,7 +426,7 @@ public void setupMainPanel() { * Set up auto completion for this database */ private void setupAutoCompletion() { - AutoCompletePreferences autoCompletePreferences = preferences.getAutoCompletePreferences(); + AutoCompletePreferences autoCompletePreferences = preferencesService.getAutoCompletePreferences(); if (autoCompletePreferences.shouldAutoComplete()) { suggestionProviders = new SuggestionProviders(getDatabase(), Globals.journalAbbreviationRepository); } else { @@ -352,12 +440,6 @@ public void updateSearchManager() { frame.getGlobalSearchBar().setAutoCompleter(searchAutoCompleter); } - private void adjustSplitter() { - if (mode == BasePanelMode.SHOWING_EDITOR) { - splitPane.setDividerPositions(preferences.getEntryEditorDividerPosition()); - } - } - public EntryEditor getEntryEditor() { return entryEditor; } @@ -390,7 +472,8 @@ private void showBottomPane(BasePanelMode newMode) { splitPane.getItems().add(1, pane); } mode = newMode; - adjustSplitter(); + + splitPane.setDividerPositions(preferencesService.getEntryEditorPreferences().getDividerPosition()); } /** @@ -409,16 +492,6 @@ public void clearAndSelect(final BibEntry bibEntry) { mainTable.clearAndSelect(bibEntry); } - /** - * Select and open entry editor for first entry in main table. - */ - private void clearAndSelectFirst() { - mainTable.clearAndSelectFirst(); - if (!mainTable.getSelectedEntries().isEmpty()) { - showAndEdit(mainTable.getSelectedEntries().get(0)); - } - } - public void selectPreviousEntry() { mainTable.getSelectionModel().clearAndSelect(mainTable.getSelectionModel().getSelectedIndex() - 1); } @@ -455,32 +528,16 @@ public void updateEntryEditorIfShowing() { } } - public void markBaseChanged() { - baseChanged = true; - // Put an asterisk behind the filename to indicate the database has changed. - frame.setWindowTitle(); - DefaultTaskExecutor.runInJavaFXThread(frame::updateAllTabTitles); - } - - public void markNonUndoableBaseChanged() { - nonUndoableChange = true; - markBaseChanged(); - } + /** + * Put an asterisk behind the filename to indicate the database has changed. + */ public synchronized void markChangedOrUnChanged() { if (getUndoManager().hasChanged()) { - if (!baseChanged) { - markBaseChanged(); - } - } else if (baseChanged && !nonUndoableChange) { - baseChanged = false; - if (getBibDatabaseContext().getDatabasePath().isPresent()) { - frame.setTabTitle(this, getTabTitle(), getBibDatabaseContext().getDatabasePath().get().toAbsolutePath().toString()); - } else { - frame.setTabTitle(this, Localization.lang("untitled"), null); - } + this.changedProperty.setValue(true); + } else if (changedProperty.getValue() && !nonUndoableChangeProperty.getValue()) { + this.changedProperty.setValue(false); } - frame.setWindowTitle(); } public BibDatabase getDatabase() { @@ -488,7 +545,7 @@ public BibDatabase getDatabase() { } private boolean showDeleteConfirmationDialog(int numberOfEntries) { - if (Globals.prefs.getBoolean(JabRefPreferences.CONFIRM_DELETE)) { + if (preferencesService.getGeneralPreferences().shouldConfirmDelete()) { String title = Localization.lang("Delete entry"); String message = Localization.lang("Really delete the selected entry?"); String okButton = Localization.lang("Delete entry"); @@ -505,7 +562,8 @@ private boolean showDeleteConfirmationDialog(int numberOfEntries) { okButton, cancelButton, Localization.lang("Disable this confirmation dialog"), - optOut -> Globals.prefs.putBoolean(JabRefPreferences.CONFIRM_DELETE, !optOut)); + optOut -> preferencesService.storeGeneralPreferences( + preferencesService.getGeneralPreferences().withConfirmDelete(!optOut))); } else { return true; } @@ -517,7 +575,8 @@ private boolean showDeleteConfirmationDialog(int numberOfEntries) { */ private void saveDividerLocation(Number position) { if (mode == BasePanelMode.SHOWING_EDITOR) { - preferences.setEntryEditorDividerPosition(position.doubleValue()); + preferencesService.storeEntryEditorPreferences( + preferencesService.getEntryEditorPreferences().withDividerPosition(position.doubleValue())); } } @@ -546,14 +605,6 @@ public SidePaneManager getSidePaneManager() { return sidePaneManager; } - public void setNonUndoableChange(boolean nonUndoableChange) { - this.nonUndoableChange = nonUndoableChange; - } - - public void setBaseChanged(boolean baseChanged) { - this.baseChanged = baseChanged; - } - public boolean isSaving() { return saving; } @@ -603,7 +654,7 @@ public void resetChangeMonitorAndChangePane() { changePane = new DatabaseChangePane(splitPane, bibDatabaseContext, changeMonitor.get()); - this.getChildren().setAll(changePane); + this.setContent(changePane); } public void copy() { @@ -618,6 +669,32 @@ public void cut() { mainTable.cut(); } + public BooleanProperty changedProperty() { + return changedProperty; + } + + public boolean isModified() { + return changedProperty.getValue(); + } + + public void markBaseChanged() { + this.changedProperty.setValue(true); + } + + public BooleanProperty nonUndoableChangeProperty() { + return nonUndoableChangeProperty; + } + + public void markNonUndoableBaseChanged() { + this.nonUndoableChangeProperty.setValue(true); + this.changedProperty.setValue(true); + } + + public void resetChangedProperties() { + this.nonUndoableChangeProperty.setValue(false); + this.changedProperty.setValue(false); + } + private class GroupTreeListener { @Subscribe @@ -628,7 +705,7 @@ public void listen(EntriesAddedEvent addedEntriesEvent) { } // Automatically add new entries to the selected group (or set of groups) - if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP)) { + if (preferencesService.getGroupsPreferences().shouldAutoAssignGroup()) { Globals.stateManager.getSelectedGroup(bibDatabaseContext).forEach( selectedGroup -> selectedGroup.addEntriesToGroup(addedEntriesEvent.getBibEntries())); } diff --git a/src/main/java/org/jabref/gui/StateManager.java b/src/main/java/org/jabref/gui/StateManager.java index 7554467b7ed..f1ffee17247 100644 --- a/src/main/java/org/jabref/gui/StateManager.java +++ b/src/main/java/org/jabref/gui/StateManager.java @@ -44,6 +44,7 @@ public class StateManager { private final CustomLocalDragboard localDragboard = new CustomLocalDragboard(); + private final ObservableList openDatabases = FXCollections.observableArrayList(); private final OptionalObjectProperty activeDatabase = OptionalObjectProperty.empty(); private final ReadOnlyListWrapper activeGroups = new ReadOnlyListWrapper<>(FXCollections.observableArrayList()); private final ObservableList selectedEntries = FXCollections.observableArrayList(); @@ -51,9 +52,7 @@ public class StateManager { private final OptionalObjectProperty activeSearchQuery = OptionalObjectProperty.empty(); private final ObservableMap searchResultMap = FXCollections.observableHashMap(); private final OptionalObjectProperty focusOwner = OptionalObjectProperty.empty(); - private final ObservableList> backgroundTasks = FXCollections.observableArrayList(task -> { - return new Observable[]{task.progressProperty(), task.runningProperty()}; - }); + private final ObservableList> backgroundTasks = FXCollections.observableArrayList(task -> new Observable[]{task.progressProperty(), task.runningProperty()}); private final EasyBinding anyTaskRunning = EasyBind.reduce(backgroundTasks, tasks -> tasks.anyMatch(Task::isRunning)); private final EasyBinding tasksProgress = EasyBind.reduce(backgroundTasks, tasks -> tasks.filter(Task::isRunning).mapToDouble(Task::getProgress).average().orElse(1)); private final ObservableMap dialogWindowStates = FXCollections.observableHashMap(); @@ -66,6 +65,10 @@ public CustomLocalDragboard getLocalDragboard() { return localDragboard; } + public ObservableList getOpenDatabases() { + return openDatabases; + } + public OptionalObjectProperty activeDatabaseProperty() { return activeDatabase; } diff --git a/src/main/java/org/jabref/gui/UpdateTimestampListener.java b/src/main/java/org/jabref/gui/UpdateTimestampListener.java index 4af4d661c29..aad998db035 100644 --- a/src/main/java/org/jabref/gui/UpdateTimestampListener.java +++ b/src/main/java/org/jabref/gui/UpdateTimestampListener.java @@ -1,7 +1,7 @@ package org.jabref.gui; import org.jabref.model.entry.event.EntryChangedEvent; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import com.google.common.eventbus.Subscribe; @@ -9,17 +9,17 @@ * Updates the timestamp of changed entries if the feature is enabled */ class UpdateTimestampListener { - private final JabRefPreferences jabRefPreferences; + private final PreferencesService preferencesService; - UpdateTimestampListener(JabRefPreferences jabRefPreferences) { - this.jabRefPreferences = jabRefPreferences; + UpdateTimestampListener(PreferencesService preferencesService) { + this.preferencesService = preferencesService; } @Subscribe public void listen(EntryChangedEvent event) { - if (jabRefPreferences.getTimestampPreferences().includeTimestamps()) { - event.getBibEntry().setField(jabRefPreferences.getTimestampPreferences().getTimestampField(), - jabRefPreferences.getTimestampPreferences().now()); + if (preferencesService.getTimestampPreferences().includeTimestamps()) { + event.getBibEntry().setField(preferencesService.getTimestampPreferences().getTimestampField(), + preferencesService.getTimestampPreferences().now()); } } } diff --git a/src/main/java/org/jabref/gui/WaitForSaveFinishedDialog.java b/src/main/java/org/jabref/gui/WaitForSaveFinishedDialog.java index 954d3fe47b0..43f784669de 100644 --- a/src/main/java/org/jabref/gui/WaitForSaveFinishedDialog.java +++ b/src/main/java/org/jabref/gui/WaitForSaveFinishedDialog.java @@ -17,12 +17,12 @@ public WaitForSaveFinishedDialog(DialogService dialogService) { this.dialogService = dialogService; } - public void showAndWait(List basePanels) { - if (basePanels.stream().anyMatch(BasePanel::isSaving)) { - Task waitForSaveFinished = new Task() { + public void showAndWait(List LibraryTabs) { + if (LibraryTabs.stream().anyMatch(LibraryTab::isSaving)) { + Task waitForSaveFinished = new Task<>() { @Override protected Void call() throws Exception { - while (basePanels.stream().anyMatch(BasePanel::isSaving)) { + while (LibraryTabs.stream().anyMatch(LibraryTab::isSaving)) { if (isCancelled()) { return null; } else { diff --git a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java index 518b09efc2b..5626bc8b60e 100644 --- a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java +++ b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java @@ -11,9 +11,9 @@ import javafx.scene.control.TextArea; import javafx.scene.control.TextField; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.util.BaseDialog; import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.logic.auxparser.AuxParser; @@ -32,7 +32,7 @@ */ public class FromAuxDialog extends BaseDialog { - private final BasePanel basePanel; + private final LibraryTab libraryTab; @FXML private ButtonType generateButtonType; private final Button generateButton; @FXML private TextField auxFileField; @@ -44,7 +44,7 @@ public class FromAuxDialog extends BaseDialog { @Inject private DialogService dialogService; public FromAuxDialog(JabRefFrame frame) { - basePanel = frame.getCurrentBasePanel(); + libraryTab = frame.getCurrentLibraryTab(); this.setTitle(Localization.lang("AUX file import")); ViewLoader.view(this) @@ -67,7 +67,7 @@ public FromAuxDialog(JabRefFrame frame) { private void parseActionPerformed() { notFoundList.getItems().clear(); statusInfos.setText(""); - BibDatabase refBase = basePanel.getDatabase(); + BibDatabase refBase = libraryTab.getDatabase(); String auxName = auxFileField.getText(); if ((auxName != null) && (refBase != null) && !auxName.isEmpty()) { diff --git a/src/main/java/org/jabref/gui/citationkeypattern/CitationKeyPatternAction.java b/src/main/java/org/jabref/gui/citationkeypattern/CitationKeyPatternAction.java index 74f20a3b7b4..983e9103e00 100644 --- a/src/main/java/org/jabref/gui/citationkeypattern/CitationKeyPatternAction.java +++ b/src/main/java/org/jabref/gui/citationkeypattern/CitationKeyPatternAction.java @@ -18,6 +18,6 @@ public CitationKeyPatternAction(JabRefFrame frame, StateManager stateManager) { @Override public void execute() { - new CitationKeyPatternDialog(frame.getCurrentBasePanel()).showAndWait(); + new CitationKeyPatternDialog(frame.getCurrentLibraryTab()).showAndWait(); } } diff --git a/src/main/java/org/jabref/gui/citationkeypattern/CitationKeyPatternDialog.java b/src/main/java/org/jabref/gui/citationkeypattern/CitationKeyPatternDialog.java index 4b33b9de97b..d92f35c7b35 100644 --- a/src/main/java/org/jabref/gui/citationkeypattern/CitationKeyPatternDialog.java +++ b/src/main/java/org/jabref/gui/citationkeypattern/CitationKeyPatternDialog.java @@ -2,8 +2,8 @@ import javafx.scene.control.ButtonType; -import org.jabref.gui.BasePanel; import org.jabref.gui.Globals; +import org.jabref.gui.LibraryTab; import org.jabref.gui.util.BaseDialog; import org.jabref.logic.citationkeypattern.AbstractCitationKeyPattern; import org.jabref.logic.l10n.Localization; @@ -12,13 +12,13 @@ public class CitationKeyPatternDialog extends BaseDialog { private final MetaData metaData; - private final BasePanel panel; + private final LibraryTab libraryTab; private final CitationKeyPatternPanel citationKeyPatternPanel; - public CitationKeyPatternDialog(BasePanel panel) { - this.citationKeyPatternPanel = new CitationKeyPatternPanel(panel); - this.panel = panel; - this.metaData = panel.getBibDatabaseContext().getMetaData(); + public CitationKeyPatternDialog(LibraryTab libraryTab) { + this.citationKeyPatternPanel = new CitationKeyPatternPanel(libraryTab.getBibDatabaseContext()); + this.libraryTab = libraryTab; + this.metaData = libraryTab.getBibDatabaseContext().getMetaData(); AbstractCitationKeyPattern keyPattern = metaData.getCiteKeyPattern(Globals.prefs.getGlobalCitationKeyPattern()); citationKeyPatternPanel.setValues(keyPattern); init(); @@ -34,7 +34,7 @@ private void init() { this.setResultConverter(button -> { if (button == ButtonType.APPLY) { metaData.setCiteKeyPattern(citationKeyPatternPanel.getKeyPatternAsDatabaseKeyPattern()); - panel.markNonUndoableBaseChanged(); + libraryTab.markNonUndoableBaseChanged(); } return null; diff --git a/src/main/java/org/jabref/gui/citationkeypattern/CitationKeyPatternPanel.java b/src/main/java/org/jabref/gui/citationkeypattern/CitationKeyPatternPanel.java index 56f98b88e26..9f1115d8c52 100644 --- a/src/main/java/org/jabref/gui/citationkeypattern/CitationKeyPatternPanel.java +++ b/src/main/java/org/jabref/gui/citationkeypattern/CitationKeyPatternPanel.java @@ -10,7 +10,6 @@ import javafx.scene.layout.GridPane; import javafx.scene.layout.Pane; -import org.jabref.gui.BasePanel; import org.jabref.gui.Globals; import org.jabref.gui.actions.ActionFactory; import org.jabref.gui.actions.StandardActions; @@ -19,6 +18,7 @@ import org.jabref.logic.citationkeypattern.DatabaseCitationKeyPattern; import org.jabref.logic.help.HelpFile; import org.jabref.logic.l10n.Localization; +import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntryType; import org.jabref.model.entry.types.EntryType; @@ -31,11 +31,11 @@ public class CitationKeyPatternPanel extends Pane { // one field for each type private final Map textFields = new HashMap<>(); - private final BasePanel panel; + private final BibDatabaseContext databaseContext; private final GridPane gridPane = new GridPane(); - public CitationKeyPatternPanel(BasePanel panel) { - this.panel = panel; + public CitationKeyPatternPanel(BibDatabaseContext databaseContext) { + this.databaseContext = databaseContext; gridPane.setHgap(10); gridPane.setVgap(5); buildGUI(); @@ -50,7 +50,12 @@ private static void setValue(TextField tf, EntryType fieldName, AbstractCitation } private void buildGUI() { - BibDatabaseMode mode; + BibDatabaseMode mode = databaseContext.getMode(); + + // The following got irrelevant - global settings for CitationKeyPattern are handled by + // commonfxcontrols/CitationKeyPatternPanel.java + // ToDo: this one should be abandoned + /* // check mode of currently used DB if (panel != null) { mode = panel.getBibDatabaseContext().getMode(); @@ -58,6 +63,7 @@ private void buildGUI() { // use preferences value if no DB is open mode = Globals.prefs.getDefaultBibDatabaseMode(); } + */ int rowIndex = 1; int columnIndex = 0; diff --git a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java index 4173db5cc65..0cf54e3ada9 100644 --- a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java +++ b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java @@ -101,7 +101,7 @@ private void generateKeys() { frame.getUndoManager().addEdit(compound); } - frame.getCurrentBasePanel().markBaseChanged(); + frame.getCurrentLibraryTab().markBaseChanged(); dialogService.notify(formatOutputMessage(Localization.lang("Generated citation key for"), entries.size())); }); } diff --git a/src/main/java/org/jabref/gui/cleanup/CleanupAction.java b/src/main/java/org/jabref/gui/cleanup/CleanupAction.java index 1fa40af1f84..50e7e703c0f 100644 --- a/src/main/java/org/jabref/gui/cleanup/CleanupAction.java +++ b/src/main/java/org/jabref/gui/cleanup/CleanupAction.java @@ -108,8 +108,8 @@ private void showResults() { } if (modifiedEntriesCount > 0) { - frame.getCurrentBasePanel().updateEntryEditorIfShowing(); - frame.getCurrentBasePanel().markBaseChanged(); + frame.getCurrentLibraryTab().updateEntryEditorIfShowing(); + frame.getCurrentLibraryTab().markBaseChanged(); } if (modifiedEntriesCount == 0) { diff --git a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogView.java b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogView.java index 766258c0b60..62832cb51ad 100644 --- a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogView.java +++ b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogView.java @@ -12,8 +12,8 @@ import javafx.scene.control.ListView; import javafx.scene.control.SelectionModel; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; +import org.jabref.gui.LibraryTab; import org.jabref.gui.util.BaseDialog; import org.jabref.gui.util.ControlHelper; import org.jabref.logic.l10n.Localization; @@ -41,14 +41,14 @@ public class ContentSelectorDialogView extends BaseDialog { @Inject private DialogService dialogService; - private final BasePanel basePanel; + private final LibraryTab libraryTab; private ContentSelectorDialogViewModel viewModel; - public ContentSelectorDialogView(BasePanel basePanel) { + public ContentSelectorDialogView(LibraryTab libraryTab) { this.setTitle(Localization.lang("Manage content selectors")); this.getDialogPane().setPrefSize(375, 475); - this.basePanel = basePanel; + this.libraryTab = libraryTab; ViewLoader.view(this) .load() @@ -59,7 +59,7 @@ public ContentSelectorDialogView(BasePanel basePanel) { @FXML public void initialize() { - viewModel = new ContentSelectorDialogViewModel(basePanel, dialogService); + viewModel = new ContentSelectorDialogViewModel(libraryTab, dialogService); initFieldNameComponents(); initKeywordsComponents(); diff --git a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogViewModel.java b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogViewModel.java index 7d10d5841e2..d83a4de4469 100644 --- a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogViewModel.java +++ b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialogViewModel.java @@ -20,8 +20,8 @@ import javafx.collections.FXCollections; import org.jabref.gui.AbstractViewModel; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; +import org.jabref.gui.LibraryTab; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldFactory; @@ -33,7 +33,7 @@ class ContentSelectorDialogViewModel extends AbstractViewModel { private static final List DEFAULT_FIELD_NAMES = Arrays.asList(StandardField.AUTHOR, StandardField.JOURNAL, StandardField.KEYWORDS, StandardField.PUBLISHER); - private final BasePanel basePanel; + private final LibraryTab libraryTab; private final MetaData metaData; private final DialogService dialogService; private final Map> fieldKeywordsMap = new HashMap<>(); @@ -43,9 +43,9 @@ class ContentSelectorDialogViewModel extends AbstractViewModel { private ObjectProperty selectedField = new SimpleObjectProperty<>(); private StringProperty selectedKeyword = new SimpleStringProperty(); - ContentSelectorDialogViewModel(BasePanel basePanel, DialogService dialogService) { - this.basePanel = basePanel; - this.metaData = basePanel.getBibDatabaseContext().getMetaData(); + ContentSelectorDialogViewModel(LibraryTab libraryTab, DialogService dialogService) { + this.libraryTab = libraryTab; + this.metaData = libraryTab.getBibDatabaseContext().getMetaData(); this.dialogService = dialogService; populateFieldNameKeywordsMapWithExistingValues(); populateFieldNamesListWithValues(); @@ -177,8 +177,8 @@ void saveChanges() { List fieldNamesToRemove = filterFieldsToRemove(); fieldNamesToRemove.forEach(metaData::clearContentSelectors); - basePanel.setupMainPanel(); - basePanel.markNonUndoableBaseChanged(); + libraryTab.setupMainPanel(); + libraryTab.markNonUndoableBaseChanged(); } private List filterFieldsToRemove() { diff --git a/src/main/java/org/jabref/gui/contentselector/ManageContentSelectorAction.java b/src/main/java/org/jabref/gui/contentselector/ManageContentSelectorAction.java index 555afe1dc20..e91c22b6e19 100644 --- a/src/main/java/org/jabref/gui/contentselector/ManageContentSelectorAction.java +++ b/src/main/java/org/jabref/gui/contentselector/ManageContentSelectorAction.java @@ -1,7 +1,7 @@ package org.jabref.gui.contentselector; -import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; @@ -19,7 +19,7 @@ public ManageContentSelectorAction(JabRefFrame jabRefFrame, StateManager stateMa @Override public void execute() { - BasePanel basePanel = jabRefFrame.getCurrentBasePanel(); - new ContentSelectorDialogView(basePanel).showAndWait(); + LibraryTab libraryTab = jabRefFrame.getCurrentLibraryTab(); + new ContentSelectorDialogView(libraryTab).showAndWait(); } } diff --git a/src/main/java/org/jabref/gui/dialogs/AutosaveUiManager.java b/src/main/java/org/jabref/gui/dialogs/AutosaveUiManager.java index 660995a0795..7aee99be695 100644 --- a/src/main/java/org/jabref/gui/dialogs/AutosaveUiManager.java +++ b/src/main/java/org/jabref/gui/dialogs/AutosaveUiManager.java @@ -1,7 +1,7 @@ package org.jabref.gui.dialogs; -import org.jabref.gui.BasePanel; import org.jabref.gui.Globals; +import org.jabref.gui.LibraryTab; import org.jabref.gui.exporter.SaveDatabaseAction; import org.jabref.model.database.event.AutosaveEvent; @@ -11,21 +11,21 @@ /** * This class has an abstract UI role as it listens for an {@link AutosaveEvent} and saves the bib file associated with - * the given {@link BasePanel}. + * the given {@link LibraryTab}. */ public class AutosaveUiManager { private static final Logger LOGGER = LoggerFactory.getLogger(AutosaveUiManager.class); - private final BasePanel panel; + private final LibraryTab libraryTab; - public AutosaveUiManager(BasePanel panel) { - this.panel = panel; + public AutosaveUiManager(LibraryTab libraryTab) { + this.libraryTab = libraryTab; } @Subscribe - public void listen(@SuppressWarnings("unused") AutosaveEvent event) { + public void listen(AutosaveEvent event) { try { - new SaveDatabaseAction(panel, Globals.prefs, Globals.entryTypesManager).save(SaveDatabaseAction.SaveDatabaseMode.SILENT); + new SaveDatabaseAction(libraryTab, Globals.prefs, Globals.entryTypesManager).save(SaveDatabaseAction.SaveDatabaseMode.SILENT); } catch (Throwable e) { LOGGER.error("Problem occurred while saving.", e); } diff --git a/src/main/java/org/jabref/gui/duplicationFinder/DuplicateSearch.java b/src/main/java/org/jabref/gui/duplicationFinder/DuplicateSearch.java index b0bdb122ea1..230c3165e4d 100644 --- a/src/main/java/org/jabref/gui/duplicationFinder/DuplicateSearch.java +++ b/src/main/java/org/jabref/gui/duplicationFinder/DuplicateSearch.java @@ -11,11 +11,11 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; import org.jabref.gui.Globals; import org.jabref.gui.JabRefExecutorService; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.duplicationFinder.DuplicateResolverDialog.DuplicateResolverResult; @@ -131,7 +131,7 @@ private DuplicateSearchResult verifyDuplicates() { } private void askResolveStrategy(DuplicateSearchResult result, BibEntry first, BibEntry second, DuplicateResolverType resolverType) { - DuplicateResolverDialog dialog = new DuplicateResolverDialog(first, second, resolverType, frame.getCurrentBasePanel().getBibDatabaseContext(), stateManager); + DuplicateResolverDialog dialog = new DuplicateResolverDialog(first, second, resolverType, frame.getCurrentLibraryTab().getBibDatabaseContext(), stateManager); DuplicateResolverResult resolverResult = dialog.showAndWait().orElse(DuplicateResolverResult.BREAK); @@ -156,25 +156,25 @@ private void handleDuplicates(DuplicateSearchResult result) { return; } - BasePanel panel = frame.getCurrentBasePanel(); + LibraryTab libraryTab = frame.getCurrentLibraryTab(); final NamedCompound compoundEdit = new NamedCompound(Localization.lang("duplicate removal")); // Now, do the actual removal: if (!result.getToRemove().isEmpty()) { - compoundEdit.addEdit(new UndoableRemoveEntries(panel.getDatabase(), result.getToRemove())); - panel.getDatabase().removeEntries(result.getToRemove()); - panel.markBaseChanged(); + compoundEdit.addEdit(new UndoableRemoveEntries(libraryTab.getDatabase(), result.getToRemove())); + libraryTab.getDatabase().removeEntries(result.getToRemove()); + libraryTab.markBaseChanged(); } // and adding merged entries: if (!result.getToAdd().isEmpty()) { - compoundEdit.addEdit(new UndoableInsertEntries(panel.getDatabase(), result.getToAdd())); - panel.getDatabase().insertEntries(result.getToAdd()); - panel.markBaseChanged(); + compoundEdit.addEdit(new UndoableInsertEntries(libraryTab.getDatabase(), result.getToAdd())); + libraryTab.getDatabase().insertEntries(result.getToAdd()); + libraryTab.markBaseChanged(); } dialogService.notify(Localization.lang("Duplicates found") + ": " + duplicateCount.get() + ' ' + Localization.lang("pairs processed") + ": " + result.getDuplicateCount()); compoundEdit.end(); - panel.getUndoManager().addEdit(compoundEdit); + libraryTab.getUndoManager().addEdit(compoundEdit); } /** diff --git a/src/main/java/org/jabref/gui/edit/EditAction.java b/src/main/java/org/jabref/gui/edit/EditAction.java index a979e51e7ec..5cdebd07b14 100644 --- a/src/main/java/org/jabref/gui/edit/EditAction.java +++ b/src/main/java/org/jabref/gui/edit/EditAction.java @@ -44,49 +44,31 @@ public String toString() { @Override public void execute() { stateManager.getFocusOwner().ifPresent(focusOwner -> { - LOGGER.debug("EditAction - focusOwner: {}; Action: {}", focusOwner.toString(), action.getText()); + LOGGER.debug("focusOwner: {}; Action: {}", focusOwner.toString(), action.getText()); if (focusOwner instanceof TextInputControl) { // Focus is on text field -> copy/paste/cut selected text TextInputControl textInput = (TextInputControl) focusOwner; + // DELETE_ENTRY in text field should do forward delete switch (action) { - case COPY: - textInput.copy(); - break; - case CUT: - textInput.cut(); - break; - case PASTE: - textInput.paste(); - break; - case DELETE_ENTRY: - // DELETE_ENTRY in text field should do forward delete - textInput.deleteNextChar(); - break; - default: - throw new IllegalStateException("Only cut/copy/paste supported in TextInputControl but got " + action); + case COPY -> textInput.copy(); + case CUT -> textInput.cut(); + case PASTE -> textInput.paste(); + case DELETE_ENTRY -> textInput.deleteNextChar(); + default -> throw new IllegalStateException("Only cut/copy/paste supported in TextInputControl but got " + action); } } else if (!(focusOwner instanceof CodeArea)) { - LOGGER.debug("EditAction - Else: {}", frame.getCurrentBasePanel().getTabTitle()); + LOGGER.debug("Else: {}", focusOwner.getClass().getSimpleName()); // Not sure what is selected -> copy/paste/cut selected entries - // ToDo: Should be handled by BibDatabaseContext instead of BasePanel + // ToDo: Should be handled by BibDatabaseContext instead of LibraryTab switch (action) { - case COPY: - frame.getCurrentBasePanel().copy(); - break; - case CUT: - frame.getCurrentBasePanel().cut(); - break; - case PASTE: - frame.getCurrentBasePanel().paste(); - break; - case DELETE_ENTRY: - frame.getCurrentBasePanel().delete(false); - break; - default: - throw new IllegalStateException("Only cut/copy/paste supported but got " + action); + case COPY -> frame.getCurrentLibraryTab().copy(); + case CUT -> frame.getCurrentLibraryTab().cut(); + case PASTE -> frame.getCurrentLibraryTab().paste(); + case DELETE_ENTRY -> frame.getCurrentLibraryTab().delete(false); + default -> throw new IllegalStateException("Only cut/copy/paste supported but got " + action); } } }); diff --git a/src/main/java/org/jabref/gui/edit/ReplaceStringAction.java b/src/main/java/org/jabref/gui/edit/ReplaceStringAction.java index 33b016ce9e7..7b8b9d4a288 100644 --- a/src/main/java/org/jabref/gui/edit/ReplaceStringAction.java +++ b/src/main/java/org/jabref/gui/edit/ReplaceStringAction.java @@ -16,7 +16,7 @@ public ReplaceStringAction(JabRefFrame frame, StateManager stateManager) { @Override public void execute() { - ReplaceStringView dialog = new ReplaceStringView(frame.getCurrentBasePanel()); + ReplaceStringView dialog = new ReplaceStringView(frame.getCurrentLibraryTab()); dialog.showAndWait(); } } diff --git a/src/main/java/org/jabref/gui/edit/ReplaceStringView.java b/src/main/java/org/jabref/gui/edit/ReplaceStringView.java index deb4c15c3d9..a931406c99c 100644 --- a/src/main/java/org/jabref/gui/edit/ReplaceStringView.java +++ b/src/main/java/org/jabref/gui/edit/ReplaceStringView.java @@ -6,7 +6,7 @@ import javafx.scene.control.RadioButton; import javafx.scene.control.TextField; -import org.jabref.gui.BasePanel; +import org.jabref.gui.LibraryTab; import org.jabref.gui.util.BaseDialog; import org.jabref.gui.util.ControlHelper; import org.jabref.gui.util.IconValidationDecorator; @@ -28,10 +28,10 @@ public class ReplaceStringView extends BaseDialog { private final ControlsFxVisualizer visualizer = new ControlsFxVisualizer(); - public ReplaceStringView(BasePanel basePanel) { + public ReplaceStringView(LibraryTab libraryTab) { this.setTitle(Localization.lang("Replace String")); - viewModel = new ReplaceStringViewModel(basePanel); + viewModel = new ReplaceStringViewModel(libraryTab); ViewLoader.view(this) .load() diff --git a/src/main/java/org/jabref/gui/edit/ReplaceStringViewModel.java b/src/main/java/org/jabref/gui/edit/ReplaceStringViewModel.java index a7a534c9603..04db4bf9147 100644 --- a/src/main/java/org/jabref/gui/edit/ReplaceStringViewModel.java +++ b/src/main/java/org/jabref/gui/edit/ReplaceStringViewModel.java @@ -9,7 +9,7 @@ import javafx.beans.property.StringProperty; import org.jabref.gui.AbstractViewModel; -import org.jabref.gui.BasePanel; +import org.jabref.gui.LibraryTab; import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.undo.UndoableFieldChange; import org.jabref.logic.l10n.Localization; @@ -22,7 +22,7 @@ public class ReplaceStringViewModel extends AbstractViewModel { private String findString; private String replaceString; private Set fields; - private BasePanel panel; + private LibraryTab panel; private StringProperty findStringProperty = new SimpleStringProperty(); private StringProperty replaceStringProperty = new SimpleStringProperty(); @@ -30,9 +30,9 @@ public class ReplaceStringViewModel extends AbstractViewModel { private BooleanProperty allFieldReplaceProperty = new SimpleBooleanProperty(); private BooleanProperty selectOnlyProperty = new SimpleBooleanProperty(); - public ReplaceStringViewModel(BasePanel basePanel) { - Objects.requireNonNull(basePanel); - this.panel = basePanel; + public ReplaceStringViewModel(LibraryTab libraryTab) { + Objects.requireNonNull(libraryTab); + this.panel = libraryTab; } public int replace() { diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 068e9ecd41d..7f05300ff00 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -25,9 +25,9 @@ import javafx.scene.input.TransferMode; import javafx.scene.layout.BorderPane; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; import org.jabref.gui.Globals; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.citationkeypattern.GenerateCitationKeySingleAction; import org.jabref.gui.entryeditor.fileannotationtab.FileAnnotationTab; @@ -69,7 +69,7 @@ public class EntryEditor extends BorderPane { private static final Logger LOGGER = LoggerFactory.getLogger(EntryEditor.class); - private final BasePanel panel; + private final LibraryTab libraryTab; private final BibDatabaseContext databaseContext; private final EntryEditorPreferences entryEditorPreferences; private final ExternalFilesEntryLinker fileLinker; @@ -100,9 +100,9 @@ public class EntryEditor extends BorderPane { @Inject private CountingUndoManager undoManager; private final List entryEditorTabs = new LinkedList<>(); - public EntryEditor(BasePanel panel, ExternalFileTypes externalFileTypes) { - this.panel = panel; - this.databaseContext = panel.getBibDatabaseContext(); + public EntryEditor(LibraryTab libraryTab, ExternalFileTypes externalFileTypes) { + this.libraryTab = libraryTab; + this.databaseContext = libraryTab.getBibDatabaseContext(); ViewLoader.view(this) .root(this) @@ -137,18 +137,18 @@ public EntryEditor(BasePanel panel, ExternalFileTypes externalFileTypes) { if (event.getDragboard().hasContent(DataFormat.FILES)) { List files = event.getDragboard().getFiles().stream().map(File::toPath).collect(Collectors.toList()); switch (event.getTransferMode()) { - case COPY: + case COPY -> { LOGGER.debug("Mode COPY"); fileLinker.copyFilesToFileDirAndAddToEntry(entry, files); - break; - case MOVE: + } + case MOVE -> { LOGGER.debug("Mode MOVE"); fileLinker.moveFilesToFileDirAndAddToEntry(entry, files); - break; - case LINK: + } + case LINK -> { LOGGER.debug("Mode LINK"); fileLinker.addFilesToEntry(entry, files); - break; + } } success = true; } @@ -177,11 +177,11 @@ private void setupKeyBindings() { event.consume(); break; case ENTRY_EDITOR_NEXT_ENTRY: - panel.selectNextEntry(); + libraryTab.selectNextEntry(); event.consume(); break; case ENTRY_EDITOR_PREVIOUS_ENTRY: - panel.selectPreviousEntry(); + libraryTab.selectPreviousEntry(); event.consume(); break; case HELP: @@ -202,12 +202,12 @@ private void setupKeyBindings() { @FXML public void close() { - panel.entryEditorClosing(); + libraryTab.entryEditorClosing(); } @FXML private void deleteEntry() { - panel.delete(entry); + libraryTab.delete(entry); } @FXML @@ -219,12 +219,12 @@ void generateCiteKeyButton() { @FXML private void navigateToPreviousEntry() { - panel.selectPreviousEntry(); + libraryTab.selectPreviousEntry(); } @FXML private void navigateToNextEntry() { - panel.selectNextEntry(); + libraryTab.selectNextEntry(); } private List createTabs() { @@ -232,24 +232,24 @@ private List createTabs() { entryEditorTabs.add(new PreviewTab(databaseContext, dialogService, Globals.prefs, ExternalFileTypes.getInstance())); // Required fields - entryEditorTabs.add(new RequiredFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); + entryEditorTabs.add(new RequiredFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); // Optional fields - entryEditorTabs.add(new OptionalFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); - entryEditorTabs.add(new OptionalFields2Tab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); - entryEditorTabs.add(new DeprecatedFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); + entryEditorTabs.add(new OptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); + entryEditorTabs.add(new OptionalFields2Tab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); + entryEditorTabs.add(new DeprecatedFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); // Other fields - entryEditorTabs.add(new OtherFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); + entryEditorTabs.add(new OtherFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); // General fields from preferences for (Map.Entry> tab : entryEditorPreferences.getEntryEditorTabList().entrySet()) { - entryEditorTabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, panel.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); + entryEditorTabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); } // Special tabs entryEditorTabs.add(new MathSciNetTab()); - entryEditorTabs.add(new FileAnnotationTab(panel.getAnnotationCache())); + entryEditorTabs.add(new FileAnnotationTab(libraryTab.getAnnotationCache())); entryEditorTabs.add(new RelatedArticlesTab(this, entryEditorPreferences, dialogService)); // Source tab @@ -361,7 +361,7 @@ private void setupToolBar() { } private void fetchAndMerge(EntryBasedFetcher fetcher) { - new FetchAndMergeEntry(panel, taskExecutor).fetchAndMerge(entry, fetcher); + new FetchAndMergeEntry(libraryTab, taskExecutor).fetchAndMerge(entry, fetcher); } public void setFocusToField(Field field) { diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java index 82d2fea3b06..278c9a85427 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java @@ -14,6 +14,7 @@ public class EntryEditorPreferences { private final boolean shouldShowLatexCitationsTab; private boolean showSourceTabByDefault; private boolean enableValidation; + private double dividerPosition; public EntryEditorPreferences(Map> entryEditorTabList, boolean shouldOpenOnNewEntry, @@ -21,7 +22,8 @@ public EntryEditorPreferences(Map> entryEditorTabList, boolean isMrdlibAccepted, boolean shouldShowLatexCitationsTab, boolean showSourceTabByDefault, - boolean enableValidation) { + boolean enableValidation, + double dividerPosition) { this.entryEditorTabList = entryEditorTabList; this.shouldOpenOnNewEntry = shouldOpenOnNewEntry; @@ -30,6 +32,7 @@ public EntryEditorPreferences(Map> entryEditorTabList, this.shouldShowLatexCitationsTab = shouldShowLatexCitationsTab; this.showSourceTabByDefault = showSourceTabByDefault; this.enableValidation = enableValidation; + this.dividerPosition = dividerPosition; } public Map> getEntryEditorTabList() { @@ -59,4 +62,13 @@ public boolean shouldShowLatexCitationsTab() { public boolean isEnableValidation() { return enableValidation; } + + public double getDividerPosition() { + return dividerPosition; + } + + public EntryEditorPreferences withDividerPosition(double dividerPosition) { + this.dividerPosition = dividerPosition; + return this; + } } diff --git a/src/main/java/org/jabref/gui/entryeditor/OpenEntryEditorAction.java b/src/main/java/org/jabref/gui/entryeditor/OpenEntryEditorAction.java index e6e759880e7..4fe0a8101b4 100644 --- a/src/main/java/org/jabref/gui/entryeditor/OpenEntryEditorAction.java +++ b/src/main/java/org/jabref/gui/entryeditor/OpenEntryEditorAction.java @@ -19,7 +19,7 @@ public OpenEntryEditorAction(JabRefFrame frame, StateManager stateManager) { public void execute() { if (!stateManager.getSelectedEntries().isEmpty()) { - frame.getCurrentBasePanel().showAndEdit(stateManager.getSelectedEntries().get(0)); + frame.getCurrentLibraryTab().showAndEdit(stateManager.getSelectedEntries().get(0)); } } } diff --git a/src/main/java/org/jabref/gui/entryeditor/PreviewSwitchAction.java b/src/main/java/org/jabref/gui/entryeditor/PreviewSwitchAction.java index 03247c4fdd0..366adcc70f8 100644 --- a/src/main/java/org/jabref/gui/entryeditor/PreviewSwitchAction.java +++ b/src/main/java/org/jabref/gui/entryeditor/PreviewSwitchAction.java @@ -23,9 +23,9 @@ public PreviewSwitchAction(Direction direction, JabRefFrame frame, StateManager @Override public void execute() { if (direction == Direction.NEXT) { - frame.getCurrentBasePanel().getEntryEditor().nextPreviewStyle(); + frame.getCurrentLibraryTab().getEntryEditor().nextPreviewStyle(); } else { - frame.getCurrentBasePanel().getEntryEditor().previousPreviewStyle(); + frame.getCurrentLibraryTab().getEntryEditor().previousPreviewStyle(); } } } diff --git a/src/main/java/org/jabref/gui/exporter/ExportCommand.java b/src/main/java/org/jabref/gui/exporter/ExportCommand.java index 70f4e5adca0..ef726e448fb 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCommand.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCommand.java @@ -82,16 +82,16 @@ private void export(Path file, FileChooser.ExtensionFilter selectedExtensionFilt List entries; if (selectedOnly) { // Selected entries - entries = frame.getCurrentBasePanel().getSelectedEntries(); + entries = frame.getCurrentLibraryTab().getSelectedEntries(); } else { // All entries - entries = frame.getCurrentBasePanel().getDatabase().getEntries(); + entries = frame.getCurrentLibraryTab().getDatabase().getEntries(); } // Set the global variable for this database's file directory before exporting, // so formatters can resolve linked files correctly. // (This is an ugly hack!) - Globals.prefs.fileDirForDatabase = frame.getCurrentBasePanel() + Globals.prefs.fileDirForDatabase = frame.getCurrentLibraryTab() .getBibDatabaseContext() .getFileDirectories(Globals.prefs.getFilePreferences()); @@ -103,9 +103,9 @@ private void export(Path file, FileChooser.ExtensionFilter selectedExtensionFilt final List finEntries = entries; BackgroundTask .wrap(() -> { - format.export(frame.getCurrentBasePanel().getBibDatabaseContext(), + format.export(frame.getCurrentLibraryTab().getBibDatabaseContext(), file, - frame.getCurrentBasePanel() + frame.getCurrentLibraryTab() .getBibDatabaseContext() .getMetaData() .getEncoding() diff --git a/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java b/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java index cd950e1ad2a..b5750b815e5 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java +++ b/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java @@ -13,11 +13,11 @@ import javafx.scene.input.ClipboardContent; -import org.jabref.gui.BasePanel; import org.jabref.gui.ClipBoardManager; import org.jabref.gui.DialogService; import org.jabref.gui.Globals; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.TaskExecutor; @@ -42,7 +42,7 @@ public class ExportToClipboardAction extends SimpleCommand { private JabRefFrame frame; private final DialogService dialogService; - private BasePanel panel; + private LibraryTab panel; private final List entries = new ArrayList<>(); private final ExporterFactory exporterFactory; private final ClipBoardManager clipBoardManager; @@ -56,7 +56,7 @@ public ExportToClipboardAction(JabRefFrame frame, DialogService dialogService, E this.taskExecutor = taskExecutor; } - public ExportToClipboardAction(BasePanel panel, DialogService dialogService, ExporterFactory exporterFactory, ClipBoardManager clipBoardManager, TaskExecutor taskExecutor) { + public ExportToClipboardAction(LibraryTab panel, DialogService dialogService, ExporterFactory exporterFactory, ClipBoardManager clipBoardManager, TaskExecutor taskExecutor) { this.panel = panel; this.dialogService = dialogService; this.exporterFactory = exporterFactory; @@ -67,7 +67,7 @@ public ExportToClipboardAction(BasePanel panel, DialogService dialogService, Exp @Override public void execute() { if (panel == null) { - panel = frame.getCurrentBasePanel(); + panel = frame.getCurrentLibraryTab(); } if (panel.getSelectedEntries().isEmpty()) { diff --git a/src/main/java/org/jabref/gui/exporter/SaveAction.java b/src/main/java/org/jabref/gui/exporter/SaveAction.java index 2a80a25148d..80061fa220c 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveAction.java @@ -30,22 +30,14 @@ public SaveAction(SaveMethod saveMethod, JabRefFrame frame, StateManager stateMa @Override public void execute() { SaveDatabaseAction saveDatabaseAction = new SaveDatabaseAction( - frame.getCurrentBasePanel(), + frame.getCurrentLibraryTab(), Globals.prefs, Globals.entryTypesManager); switch (saveMethod) { - case SAVE: - saveDatabaseAction.save(); - break; - case SAVE_AS: - saveDatabaseAction.saveAs(); - break; - case SAVE_SELECTED: - saveDatabaseAction.saveSelectedAsPlain(); - break; - default: - // Never happens + case SAVE -> saveDatabaseAction.save(); + case SAVE_AS -> saveDatabaseAction.saveAs(); + case SAVE_SELECTED -> saveDatabaseAction.saveSelectedAsPlain(); } } } diff --git a/src/main/java/org/jabref/gui/exporter/SaveAllAction.java b/src/main/java/org/jabref/gui/exporter/SaveAllAction.java index 4c2c1dd69a3..dd115d79ec8 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveAllAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveAllAction.java @@ -1,9 +1,9 @@ package org.jabref.gui.exporter; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; import org.jabref.gui.Globals; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.actions.SimpleCommand; import org.jabref.logic.l10n.Localization; @@ -21,8 +21,8 @@ public SaveAllAction(JabRefFrame frame) { public void execute() { dialogService.notify(Localization.lang("Saving all libraries...")); - for (BasePanel panel : frame.getBasePanelList()) { - SaveDatabaseAction saveDatabaseAction = new SaveDatabaseAction(panel, Globals.prefs, Globals.entryTypesManager); + for (LibraryTab libraryTab : frame.getLibraryTabs()) { + SaveDatabaseAction saveDatabaseAction = new SaveDatabaseAction(libraryTab, Globals.prefs, Globals.entryTypesManager); boolean saveResult = saveDatabaseAction.save(); if (!saveResult) { dialogService.notify(Localization.lang("Could not save file.")); diff --git a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java index 42c5a572c48..7e98241ad7d 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java @@ -14,9 +14,9 @@ import javafx.scene.layout.VBox; import javafx.scene.text.Text; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.dialogs.AutosaveUiManager; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.FileDialogConfiguration; @@ -49,7 +49,7 @@ public class SaveDatabaseAction { private static final Logger LOGGER = LoggerFactory.getLogger(SaveDatabaseAction.class); - private final BasePanel panel; + private final LibraryTab libraryTab; private final JabRefFrame frame; private final DialogService dialogService; private final JabRefPreferences preferences; @@ -59,20 +59,20 @@ public enum SaveDatabaseMode { SILENT, NORMAL } - public SaveDatabaseAction(BasePanel panel, JabRefPreferences preferences, BibEntryTypesManager entryTypesManager) { - this.panel = panel; - this.frame = panel.frame(); + public SaveDatabaseAction(LibraryTab libraryTab, JabRefPreferences preferences, BibEntryTypesManager entryTypesManager) { + this.libraryTab = libraryTab; + this.frame = libraryTab.frame(); this.dialogService = frame.getDialogService(); this.preferences = preferences; this.entryTypesManager = entryTypesManager; } public boolean save() { - return save(panel.getBibDatabaseContext(), SaveDatabaseMode.NORMAL); + return save(libraryTab.getBibDatabaseContext(), SaveDatabaseMode.NORMAL); } public boolean save(SaveDatabaseMode mode) { - return save(panel.getBibDatabaseContext(), mode); + return save(libraryTab.getBibDatabaseContext(), mode); } /** @@ -105,7 +105,7 @@ public void saveSelectedAsPlain() { * @return true on successful save */ boolean saveAs(Path file, SaveDatabaseMode mode) { - BibDatabaseContext context = panel.getBibDatabaseContext(); + BibDatabaseContext context = libraryTab.getBibDatabaseContext(); // Close AutosaveManager and BackupManager for original library Optional databasePath = context.getDatabasePath(); @@ -129,13 +129,13 @@ boolean saveAs(Path file, SaveDatabaseMode mode) { // we managed to successfully save the file // thus, we can store the store the path into the context context.setDatabasePath(file); - frame.refreshTitleAndTabs(); + // FIXME: We need to refresh the tab titles // Reinstall AutosaveManager and BackupManager for the new file name - panel.resetChangeMonitorAndChangePane(); + libraryTab.resetChangeMonitorAndChangePane(); if (readyForAutosave(context)) { AutosaveManager autosaver = AutosaveManager.start(context); - autosaver.registerListener(new AutosaveUiManager(panel)); + autosaver.registerListener(new AutosaveUiManager(libraryTab)); } if (readyForBackup(context)) { BackupManager.start(context, entryTypesManager, preferences); @@ -168,7 +168,7 @@ private boolean save(BibDatabaseContext bibDatabaseContext, SaveDatabaseMode mod Optional databasePath = bibDatabaseContext.getDatabasePath(); if (databasePath.isEmpty()) { Optional savePath = askForSavePath(); - if (!savePath.isPresent()) { + if (savePath.isEmpty()) { return false; } return saveAs(savePath.get(), mode); @@ -182,27 +182,21 @@ private boolean save(Path targetPath, SaveDatabaseMode mode) { dialogService.notify(String.format("%s...", Localization.lang("Saving library"))); } - panel.setSaving(true); + libraryTab.setSaving(true); try { - Charset encoding = panel.getBibDatabaseContext() - .getMetaData() - .getEncoding() - .orElse(preferences.getDefaultEncoding()); + Charset encoding = libraryTab.getBibDatabaseContext() + .getMetaData() + .getEncoding() + .orElse(preferences.getDefaultEncoding()); // Make sure to remember which encoding we used. - panel.getBibDatabaseContext().getMetaData().setEncoding(encoding, ChangePropagation.DO_NOT_POST_EVENT); + libraryTab.getBibDatabaseContext().getMetaData().setEncoding(encoding, ChangePropagation.DO_NOT_POST_EVENT); // Save the database boolean success = saveDatabase(targetPath, false, encoding, SavePreferences.DatabaseSaveType.ALL); if (success) { - panel.getUndoManager().markUnchanged(); - // After a successful save the following statement marks that the base is unchanged since last save - panel.setNonUndoableChange(false); - panel.setBaseChanged(false); - - frame.setTabTitle(panel, panel.getTabTitle(), targetPath.toAbsolutePath().toString()); - frame.setWindowTitle(); - frame.updateAllTabTitles(); + libraryTab.getUndoManager().markUnchanged(); + libraryTab.resetChangedProperties(); } return success; } catch (SaveException ex) { @@ -211,7 +205,7 @@ private boolean save(Path targetPath, SaveDatabaseMode mode) { return false; } finally { // release panel from save status - panel.setSaving(false); + libraryTab.setSaving(false); } } @@ -223,12 +217,12 @@ private boolean saveDatabase(Path file, boolean selectedOnly, Charset encoding, BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(fileWriter, preferences, entryTypesManager); if (selectedOnly) { - databaseWriter.savePartOfDatabase(panel.getBibDatabaseContext(), panel.getSelectedEntries()); + databaseWriter.savePartOfDatabase(libraryTab.getBibDatabaseContext(), libraryTab.getSelectedEntries()); } else { - databaseWriter.saveDatabase(panel.getBibDatabaseContext()); + databaseWriter.saveDatabase(libraryTab.getBibDatabaseContext()); } - panel.registerUndoableChanges(databaseWriter.getSaveActionsFieldChanges()); + libraryTab.registerUndoableChanges(databaseWriter.getSaveActionsFieldChanges()); if (fileWriter.hasEncodingProblems()) { saveWithDifferentEncoding(file, selectedOnly, preferences.getEncoding(), fileWriter.getEncodingProblems(), saveType); @@ -262,7 +256,7 @@ private void saveWithDifferentEncoding(Path file, boolean selectedOnly, Charset Optional newEncoding = dialogService.showChoiceDialogAndWait(Localization.lang("Save library"), Localization.lang("Select new encoding"), Localization.lang("Save library"), encoding, Encodings.getCharsets()); if (newEncoding.isPresent()) { // Make sure to remember which encoding we used. - panel.getBibDatabaseContext().getMetaData().setEncoding(newEncoding.get(), ChangePropagation.DO_NOT_POST_EVENT); + libraryTab.getBibDatabaseContext().getMetaData().setEncoding(newEncoding.get(), ChangePropagation.DO_NOT_POST_EVENT); saveDatabase(file, selectedOnly, newEncoding.get(), saveType); } diff --git a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java index 7c18e322bfd..65659729cd0 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java @@ -44,7 +44,7 @@ public IdentifierEditorViewModel(Field field, SuggestionProvider suggestionPr ); validIdentifierIsNotPresent.bind( - EasyBind.map(identifier, parsedIdentifier -> !parsedIdentifier.isPresent()) + EasyBind.map(identifier, parsedIdentifier -> parsedIdentifier.isEmpty()) ); idFetcherAvailable.setValue(WebFetchers.getIdFetcherForField(field).isPresent()); @@ -87,7 +87,7 @@ public BooleanProperty identifierLookupInProgressProperty() { } public void fetchInformationByIdentifier(BibEntry entry) { - new FetchAndMergeEntry(JabRefGUI.getMainFrame().getCurrentBasePanel(), taskExecutor).fetchAndMerge(entry, field); + new FetchAndMergeEntry(JabRefGUI.getMainFrame().getCurrentLibraryTab(), taskExecutor).fetchAndMerge(entry, field); } public void lookupIdentifier(BibEntry entry) { diff --git a/src/main/java/org/jabref/gui/importer/ImportAction.java b/src/main/java/org/jabref/gui/importer/ImportAction.java index 8dae27690a6..52ea32b30e4 100644 --- a/src/main/java/org/jabref/gui/importer/ImportAction.java +++ b/src/main/java/org/jabref/gui/importer/ImportAction.java @@ -8,10 +8,10 @@ import java.util.Optional; import java.util.stream.Collectors; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; import org.jabref.gui.Globals; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.TaskExecutor; @@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory; public class ImportAction { +// FixMe: Command pattern is broken, should extend SimpleCommand private static final Logger LOGGER = LoggerFactory.getLogger(ImportAction.class); @@ -84,9 +85,9 @@ public void automatedImport(List filenames) { }) .executeWith(taskExecutor); } else { - final BasePanel panel = frame.getCurrentBasePanel(); + final LibraryTab libraryTab = frame.getCurrentLibraryTab(); - ImportEntriesDialog dialog = new ImportEntriesDialog(panel.getBibDatabaseContext(), task); + ImportEntriesDialog dialog = new ImportEntriesDialog(libraryTab.getBibDatabaseContext(), task); dialog.setTitle(Localization.lang("Import")); dialog.showAndWait(); } @@ -97,7 +98,7 @@ private List doImport(List files) List imports = new ArrayList<>(); for (Path filename : files) { try { - if (!importer.isPresent()) { + if (importer.isEmpty()) { // Unknown format: DefaultTaskExecutor.runInJavaFXThread(() -> frame.getDialogService().notify(Localization.lang("Importing in unknown format") + "...")); // This import method never throws an IOException: diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java index 7b2bdd92be2..ddd581b2da7 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java @@ -155,7 +155,7 @@ public void importEntries(List entriesToImport, boolean shouldDownload parserResult.getFile().map(File::getName).orElse("unknown"), parserResult.getDatabase().getEntries()); - JabRefGUI.getMainFrame().getCurrentBasePanel().markBaseChanged(); + JabRefGUI.getMainFrame().getCurrentLibraryTab().markBaseChanged(); } private void buildImportHandlerThenImportEntries(List entriesToImport) { diff --git a/src/main/java/org/jabref/gui/importer/NewEntryAction.java b/src/main/java/org/jabref/gui/importer/NewEntryAction.java index 6221b335413..7869393367e 100644 --- a/src/main/java/org/jabref/gui/importer/NewEntryAction.java +++ b/src/main/java/org/jabref/gui/importer/NewEntryAction.java @@ -54,16 +54,16 @@ public void execute() { } if (type.isPresent()) { - jabRefFrame.getCurrentBasePanel().insertEntry(new BibEntry(type.get())); + jabRefFrame.getCurrentLibraryTab().insertEntry(new BibEntry(type.get())); } else { - EntryTypeView typeChoiceDialog = new EntryTypeView(jabRefFrame.getCurrentBasePanel(), dialogService, preferences); + EntryTypeView typeChoiceDialog = new EntryTypeView(jabRefFrame.getCurrentLibraryTab(), dialogService, preferences); EntryType selectedType = typeChoiceDialog.showAndWait().orElse(null); if (selectedType == null) { return; } trackNewEntry(selectedType); - jabRefFrame.getCurrentBasePanel().insertEntry(new BibEntry(selectedType)); + jabRefFrame.getCurrentLibraryTab().insertEntry(new BibEntry(selectedType)); } } diff --git a/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java b/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java index 43a0b2f4afe..ec07cbc93b4 100644 --- a/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java +++ b/src/main/java/org/jabref/gui/importer/ParserResultWarningDialog.java @@ -45,7 +45,7 @@ public static void showParserResultWarningDialog(final ParserResult parserResult // Switch tab if asked to do so if (dataBaseNumber >= 0) { - jabRefFrame.showBasePanelAt(dataBaseNumber); + jabRefFrame.showLibraryTabAt(dataBaseNumber); } // Generate string with warning texts @@ -59,10 +59,10 @@ public static void showParserResultWarningDialog(final ParserResult parserResult // Generate dialog title String dialogTitle; - if (dataBaseNumber < 0) { + if (dataBaseNumber < 0 || parserResult.getPath().isEmpty()) { dialogTitle = Localization.lang("Warnings"); } else { - dialogTitle = Localization.lang("Warnings") + " (" + parserResult.getFile().get().getName() + ")"; + dialogTitle = Localization.lang("Warnings") + " (" + parserResult.getPath().get().getFileName() + ")"; } // Show dialog diff --git a/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java b/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java index 86c50d19051..1da9f8d60de 100644 --- a/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java @@ -3,8 +3,8 @@ import java.util.List; import java.util.stream.Collectors; -import org.jabref.gui.BasePanel; import org.jabref.gui.Globals; +import org.jabref.gui.LibraryTab; import org.jabref.gui.importer.ImportCustomEntryTypesDialog; import org.jabref.logic.importer.ParserResult; import org.jabref.model.database.BibDatabaseMode; @@ -22,7 +22,7 @@ public boolean isActionNecessary(ParserResult parserResult) { } @Override - public void performAction(BasePanel panel, ParserResult parserResult) { + public void performAction(LibraryTab libraryTab, ParserResult parserResult) { BibDatabaseMode mode = getBibDatabaseModeFromParserResult(parserResult); ImportCustomEntryTypesDialog importBibEntryTypesDialog = new ImportCustomEntryTypesDialog(mode, getListOfUnknownAndUnequalCustomizations(parserResult)); diff --git a/src/main/java/org/jabref/gui/importer/actions/GUIPostOpenAction.java b/src/main/java/org/jabref/gui/importer/actions/GUIPostOpenAction.java index a8815ebc048..acdbd8726a7 100644 --- a/src/main/java/org/jabref/gui/importer/actions/GUIPostOpenAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/GUIPostOpenAction.java @@ -1,6 +1,6 @@ package org.jabref.gui.importer.actions; -import org.jabref.gui.BasePanel; +import org.jabref.gui.LibraryTab; import org.jabref.logic.importer.ParserResult; /** @@ -33,5 +33,5 @@ public interface GUIPostOpenAction { * @param panel The BasePanel where the database is shown. * @param pr The result of the BIB parse operation. */ - void performAction(BasePanel panel, ParserResult pr); + void performAction(LibraryTab panel, ParserResult pr); } diff --git a/src/main/java/org/jabref/gui/importer/actions/MergeReviewIntoCommentAction.java b/src/main/java/org/jabref/gui/importer/actions/MergeReviewIntoCommentAction.java index 3196f1c46aa..a8bb0a453f1 100644 --- a/src/main/java/org/jabref/gui/importer/actions/MergeReviewIntoCommentAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/MergeReviewIntoCommentAction.java @@ -2,7 +2,7 @@ import java.util.List; -import org.jabref.gui.BasePanel; +import org.jabref.gui.LibraryTab; import org.jabref.logic.importer.ParserResult; import org.jabref.migrations.MergeReviewIntoCommentMigration; import org.jabref.model.entry.BibEntry; @@ -15,12 +15,12 @@ public boolean isActionNecessary(ParserResult parserResult) { } @Override - public void performAction(BasePanel basePanel, ParserResult parserResult) { + public void performAction(LibraryTab libraryTab, ParserResult parserResult) { MergeReviewIntoCommentMigration migration = new MergeReviewIntoCommentMigration(); migration.performMigration(parserResult); List conflicts = MergeReviewIntoCommentMigration.collectConflicts(parserResult); - if (!conflicts.isEmpty() && new MergeReviewIntoCommentConfirmationDialog(basePanel.frame().getDialogService()).askUserForMerge(conflicts)) { + if (!conflicts.isEmpty() && new MergeReviewIntoCommentConfirmationDialog(libraryTab.frame().getDialogService()).askUserForMerge(conflicts)) { migration.performConflictingMigration(parserResult); } } diff --git a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java index 80d6f8fc158..8b2f79ec02d 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -11,11 +11,10 @@ import java.util.Objects; import java.util.Optional; -import org.jabref.gui.BasePanel; -import org.jabref.gui.BasePanelPreferences; import org.jabref.gui.DialogService; import org.jabref.gui.Globals; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.dialogs.BackupUIManager; import org.jabref.gui.externalfiletype.ExternalFileTypes; @@ -60,14 +59,14 @@ public OpenDatabaseAction(JabRefFrame frame) { /** * Go through the list of post open actions, and perform those that need to be performed. * - * @param panel The BasePanel where the database is shown. + * @param libraryTab The BasePanel where the database is shown. * @param result The result of the BIB file parse operation. */ - public static void performPostOpenActions(BasePanel panel, ParserResult result) { + public static void performPostOpenActions(LibraryTab libraryTab, ParserResult result) { for (GUIPostOpenAction action : OpenDatabaseAction.POST_OPEN_ACTIONS) { if (action.isActionNecessary(result)) { - action.performAction(panel, result); - panel.frame().showBasePanel(panel); + action.performAction(libraryTab, result); + libraryTab.frame().showLibraryTab(libraryTab); } } } @@ -91,7 +90,7 @@ private Path getInitialDirectory() { if (frame.getBasePanelCount() == 0) { return Globals.prefs.getWorkingDir(); } else { - Optional databasePath = frame.getCurrentBasePanel().getBibDatabaseContext().getDatabasePath(); + Optional databasePath = frame.getCurrentLibraryTab().getBibDatabaseContext().getDatabasePath(); return databasePath.map(Path::getParent).orElse(Globals.prefs.getWorkingDir()); } } @@ -111,7 +110,7 @@ public void openFile(Path file, boolean raisePanel) { * @param filesToOpen the filesToOpen, may be null or not existing */ public void openFiles(List filesToOpen, boolean raisePanel) { - BasePanel toRaise = null; + LibraryTab toRaise = null; int initialCount = filesToOpen.size(); int removed = 0; @@ -119,17 +118,17 @@ public void openFiles(List filesToOpen, boolean raisePanel) { for (Iterator iterator = filesToOpen.iterator(); iterator.hasNext(); ) { Path file = iterator.next(); for (int i = 0; i < frame.getTabbedPane().getTabs().size(); i++) { - BasePanel basePanel = frame.getBasePanelAt(i); - if ((basePanel.getBibDatabaseContext().getDatabasePath().isPresent()) - && basePanel.getBibDatabaseContext().getDatabasePath().get().equals(file)) { + LibraryTab libraryTab = frame.getLibraryTabAt(i); + if ((libraryTab.getBibDatabaseContext().getDatabasePath().isPresent()) + && libraryTab.getBibDatabaseContext().getDatabasePath().get().equals(file)) { iterator.remove(); removed++; // See if we removed the final one. If so, we must perhaps - // raise the BasePanel in question: + // raise the LibraryTab in question: if (removed == initialCount) { - toRaise = basePanel; + toRaise = libraryTab; } - // no more bps to check, we found a matching one + // no more LibraryTabs to check, we found a matching one break; } } @@ -151,7 +150,7 @@ public void openFiles(List filesToOpen, boolean raisePanel) { } else if (toRaise != null) { // If no files are remaining to open, this could mean that a file was // already open. If so, we may have to raise the correct tab: - frame.showBasePanel(toRaise); + frame.showLibraryTab(toRaise); } } @@ -164,8 +163,8 @@ private void openTheFile(Path file, boolean raisePanel) { BackgroundTask.wrap(() -> loadDatabase(file)) .onSuccess(result -> { - BasePanel panel = addNewDatabase(result, file, raisePanel); - OpenDatabaseAction.performPostOpenActions(panel, result); + LibraryTab libraryTab = addNewDatabase(result, file, raisePanel); + OpenDatabaseAction.performPostOpenActions(libraryTab, result); }) .onFailure(ex -> dialogService.showErrorDialogAndWait(Localization.lang("Connection error"), ex.getMessage() + "\n\n" + Localization.lang("A local copy will be opened."))) @@ -202,13 +201,13 @@ private ParserResult loadDatabase(Path file) throws Exception { return result; } - private BasePanel addNewDatabase(ParserResult result, final Path file, boolean raisePanel) { + private LibraryTab addNewDatabase(ParserResult result, final Path file, boolean raisePanel) { if (result.hasWarnings()) { ParserResultWarningDialog.showParserResultWarningDialog(result, frame); } - BasePanel basePanel = new BasePanel(frame, BasePanelPreferences.from(Globals.prefs), result.getDatabaseContext(), ExternalFileTypes.getInstance()); - frame.addTab(basePanel, raisePanel); - return basePanel; + LibraryTab libraryTab = new LibraryTab(frame, Globals.prefs, result.getDatabaseContext(), ExternalFileTypes.getInstance()); + frame.addTab(libraryTab, raisePanel); + return libraryTab; } } diff --git a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java index a51aeb51fca..773289143f5 100644 --- a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java +++ b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java @@ -101,7 +101,7 @@ public void search() { return; } - if (frame.getCurrentBasePanel() == null) { + if (frame.getCurrentLibraryTab() == null) { dialogService.notify(Localization.lang("Please open or start a new library before searching")); return; } @@ -120,7 +120,7 @@ public void search() { } task.onFailure(dialogService::showErrorDialogAndWait); - ImportEntriesDialog dialog = new ImportEntriesDialog(frame.getCurrentBasePanel().getBibDatabaseContext(), task); + ImportEntriesDialog dialog = new ImportEntriesDialog(frame.getCurrentLibraryTab().getBibDatabaseContext(), task); dialog.setTitle(activeFetcher.getName()); dialog.showAndWait(); } diff --git a/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java b/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java index 15b7baed8d2..197f2084876 100644 --- a/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java +++ b/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java @@ -72,7 +72,7 @@ protected List call() { if (messages.isEmpty()) { dialogService.notify(Localization.lang("No problems found.")); } else { - Dialog dialog = new IntegrityCheckDialog(messages, frame.getCurrentBasePanel()); + Dialog dialog = new IntegrityCheckDialog(messages, frame.getCurrentLibraryTab()); dialog.showAndWait(); } }); diff --git a/src/main/java/org/jabref/gui/integrity/IntegrityCheckDialog.java b/src/main/java/org/jabref/gui/integrity/IntegrityCheckDialog.java index 26de42d4bf3..7f190ebf036 100644 --- a/src/main/java/org/jabref/gui/integrity/IntegrityCheckDialog.java +++ b/src/main/java/org/jabref/gui/integrity/IntegrityCheckDialog.java @@ -12,7 +12,7 @@ import javafx.scene.input.MouseButton; import javafx.stage.Modality; -import org.jabref.gui.BasePanel; +import org.jabref.gui.LibraryTab; import org.jabref.gui.util.BaseDialog; import org.jabref.logic.integrity.IntegrityMessage; import org.jabref.logic.l10n.Localization; @@ -23,7 +23,7 @@ public class IntegrityCheckDialog extends BaseDialog { private final List messages; - private final BasePanel basePanel; + private final LibraryTab libraryTab; @FXML private TableView messagesTable; @FXML private TableColumn keyColumn; @FXML private TableColumn fieldColumn; @@ -34,9 +34,9 @@ public class IntegrityCheckDialog extends BaseDialog { private IntegrityCheckDialogViewModel viewModel; private TableFilter tableFilter; - public IntegrityCheckDialog(List messages, BasePanel basePanel) { + public IntegrityCheckDialog(List messages, LibraryTab libraryTab) { this.messages = messages; - this.basePanel = basePanel; + this.libraryTab = libraryTab; this.setTitle(Localization.lang("Check integrity")); this.initModality(Modality.NONE); @@ -48,7 +48,7 @@ public IntegrityCheckDialog(List messages, BasePanel basePanel private void onSelectionChanged(ListChangeListener.Change change) { if (change.next()) { change.getAddedSubList().stream().findFirst().ifPresent(message -> - basePanel.editEntryAndFocusField(message.getEntry(), message.getField())); + libraryTab.editEntryAndFocusField(message.getEntry(), message.getField())); } } diff --git a/src/main/java/org/jabref/gui/journals/AbbreviateAction.java b/src/main/java/org/jabref/gui/journals/AbbreviateAction.java index 6fd9421e2ac..81c5ea15322 100644 --- a/src/main/java/org/jabref/gui/journals/AbbreviateAction.java +++ b/src/main/java/org/jabref/gui/journals/AbbreviateAction.java @@ -50,18 +50,10 @@ public AbbreviateAction(StandardActions action, this.stateManager = stateManager; switch (action) { - case ABBREVIATE_DEFAULT: - abbreviationType = AbbreviationType.DEFAULT; - break; - case ABBREVIATE_MEDLINE: - abbreviationType = AbbreviationType.MEDLINE; - break; - case ABBREVIATE_SHORTEST_UNIQUE: - abbreviationType = AbbreviationType.SHORTEST_UNIQUE; - break; - default: - LOGGER.debug("Unknown action: " + action.name()); - break; + case ABBREVIATE_DEFAULT -> abbreviationType = AbbreviationType.DEFAULT; + case ABBREVIATE_MEDLINE -> abbreviationType = AbbreviationType.MEDLINE; + case ABBREVIATE_SHORTEST_UNIQUE -> abbreviationType = AbbreviationType.SHORTEST_UNIQUE; + default -> LOGGER.debug("Unknown action: " + action.name()); } this.executable.bind(ActionHelper.needsEntriesSelected(stateManager)); @@ -120,7 +112,7 @@ private String abbreviate(BibDatabaseContext databaseContext, List ent if (count > 0) { ce.end(); frame.getUndoManager().addEdit(ce); - frame.getCurrentBasePanel().markBaseChanged(); + frame.getCurrentLibraryTab().markBaseChanged(); return Localization.lang("Abbreviated %0 journal names.", String.valueOf(count)); } return Localization.lang("No journal names could be abbreviated."); @@ -136,7 +128,7 @@ private String unabbreviate(BibDatabaseContext databaseContext, List e if (count > 0) { ce.end(); frame.getUndoManager().addEdit(ce); - frame.getCurrentBasePanel().markBaseChanged(); + frame.getCurrentLibraryTab().markBaseChanged(); return Localization.lang("Unabbreviated %0 journal names.", String.valueOf(count)); } return Localization.lang("No journal names could be unabbreviated."); diff --git a/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesAction.java b/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesAction.java index e5a1960cd9f..ea8729837ee 100644 --- a/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesAction.java +++ b/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesAction.java @@ -17,7 +17,7 @@ public LibraryPropertiesAction(JabRefFrame frame, StateManager stateManager) { @Override public void execute() { - LibraryPropertiesDialogView propertiesDialog = new LibraryPropertiesDialogView(frame.getCurrentBasePanel()); + LibraryPropertiesDialogView propertiesDialog = new LibraryPropertiesDialogView(frame.getCurrentLibraryTab()); propertiesDialog.showAndWait(); } } diff --git a/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogView.java b/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogView.java index cada1936c9b..0a58302ae75 100644 --- a/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogView.java +++ b/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogView.java @@ -11,8 +11,8 @@ import javafx.scene.control.ComboBox; import javafx.scene.control.TextField; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; +import org.jabref.gui.LibraryTab; import org.jabref.gui.commonfxcontrols.FieldFormatterCleanupsPanel; import org.jabref.gui.commonfxcontrols.SaveOrderConfigPanel; import org.jabref.gui.util.BaseDialog; @@ -38,11 +38,11 @@ public class LibraryPropertiesDialogView extends BaseDialog { @Inject private PreferencesService preferencesService; @Inject private DialogService dialogService; - private final BasePanel panel; + private final LibraryTab libraryTab; private LibraryPropertiesDialogViewModel viewModel; - public LibraryPropertiesDialogView(BasePanel panel) { - this.panel = panel; + public LibraryPropertiesDialogView(LibraryTab libraryTab) { + this.libraryTab = libraryTab; ViewLoader.view(this) .load() @@ -60,7 +60,7 @@ public LibraryPropertiesDialogView(BasePanel panel) { @FXML private void initialize() { - viewModel = new LibraryPropertiesDialogViewModel(panel.getBibDatabaseContext(), dialogService, preferencesService); + viewModel = new LibraryPropertiesDialogViewModel(libraryTab.getBibDatabaseContext(), dialogService, preferencesService); encoding.disableProperty().bind(viewModel.encodingDisableProperty()); encoding.itemsProperty().bind(viewModel.encodingsProperty()); diff --git a/src/main/java/org/jabref/gui/linkedfile/AttachFileAction.java b/src/main/java/org/jabref/gui/linkedfile/AttachFileAction.java index 8892e6cc450..534de7c529f 100644 --- a/src/main/java/org/jabref/gui/linkedfile/AttachFileAction.java +++ b/src/main/java/org/jabref/gui/linkedfile/AttachFileAction.java @@ -3,8 +3,8 @@ import java.nio.file.Path; import java.util.Optional; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; @@ -21,13 +21,16 @@ public class AttachFileAction extends SimpleCommand { - private final BasePanel panel; + private final LibraryTab libraryTab; private final StateManager stateManager; private final DialogService dialogService; private final PreferencesService preferencesService; - public AttachFileAction(BasePanel panel, DialogService dialogService, StateManager stateManager, PreferencesService preferencesService) { - this.panel = panel; + public AttachFileAction(LibraryTab libraryTab, + DialogService dialogService, + StateManager stateManager, + PreferencesService preferencesService) { + this.libraryTab = libraryTab; this.stateManager = stateManager; this.dialogService = dialogService; this.preferencesService = preferencesService; @@ -70,8 +73,8 @@ public void execute() { Optional fieldChange = entry.addFile(editedLinkedFile); fieldChange.ifPresent(change -> { UndoableFieldChange ce = new UndoableFieldChange(change); - panel.getUndoManager().addEdit(ce); - panel.markBaseChanged(); + libraryTab.getUndoManager().addEdit(ce); + libraryTab.markBaseChanged(); }); }); }); diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index c1c5cab22ab..cf5c8cd2b2a 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -24,10 +24,10 @@ import javafx.scene.input.MouseEvent; import javafx.scene.input.TransferMode; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; import org.jabref.gui.DragAndDropDataFormats; import org.jabref.gui.Globals; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.StandardActions; import org.jabref.gui.edit.EditAction; @@ -57,7 +57,8 @@ public class MainTable extends TableView { private static final Logger LOGGER = LoggerFactory.getLogger(MainTable.class); - private final BasePanel panel; + private final LibraryTab libraryTab; + private final DialogService dialogService; private final BibDatabaseContext database; private final MainTableDataModel model; @@ -68,7 +69,7 @@ public class MainTable extends TableView { private String columnSearchTerm; public MainTable(MainTableDataModel model, - BasePanel panel, + LibraryTab libraryTab, BibDatabaseContext database, PreferencesService preferencesService, DialogService dialogService, @@ -77,10 +78,11 @@ public MainTable(MainTableDataModel model, KeyBindingRepository keyBindingRepository) { super(); - this.panel = panel; + this.libraryTab = libraryTab; + this.dialogService = dialogService; this.database = Objects.requireNonNull(database); this.model = model; - UndoManager undoManager = panel.getUndoManager(); + UndoManager undoManager = libraryTab.getUndoManager(); MainTablePreferences mainTablePreferences = preferencesService.getMainTablePreferences(); importHandler = new ImportHandler( @@ -93,18 +95,22 @@ public MainTable(MainTableDataModel model, localDragboard = stateManager.getLocalDragboard(); this.getColumns().addAll( - new MainTableColumnFactory(database, preferencesService, externalFileTypes, panel.getUndoManager(), dialogService) - .createColumns()); + new MainTableColumnFactory( + database, + preferencesService, + externalFileTypes, + libraryTab.getUndoManager(), + dialogService).createColumns()); new ViewModelTableRowFactory() .withOnMouseClickedEvent((entry, event) -> { if (event.getClickCount() == 2) { - panel.showAndEdit(entry.getEntry()); + libraryTab.showAndEdit(entry.getEntry()); } }) .withContextMenu(entry -> RightClickMenu.create(entry, keyBindingRepository, - panel, + libraryTab, dialogService, stateManager, preferencesService, @@ -221,7 +227,7 @@ public void copy() { if (!selectedEntries.isEmpty()) { try { Globals.clipboardManager.setContent(selectedEntries); - panel.output(panel.formatOutputMessage(Localization.lang("Copied"), selectedEntries.size())); + dialogService.notify(libraryTab.formatOutputMessage(Localization.lang("Copied"), selectedEntries.size())); } catch (IOException e) { LOGGER.error("Error while copying selected entries to clipboard", e); } @@ -230,7 +236,7 @@ public void copy() { public void cut() { copy(); - panel.delete(true); + libraryTab.delete(true); } private void setupKeyBindings(KeyBindingRepository keyBindings) { @@ -238,7 +244,7 @@ private void setupKeyBindings(KeyBindingRepository keyBindings) { if (event.getCode() == KeyCode.ENTER) { getSelectedEntries().stream() .findFirst() - .ifPresent(panel::showAndEdit); + .ifPresent(libraryTab::showAndEdit); event.consume(); return; } @@ -256,16 +262,16 @@ private void setupKeyBindings(KeyBindingRepository keyBindings) { break; case PASTE: if (!OS.OS_X) { - new EditAction(StandardActions.PASTE, panel.frame(), Globals.stateManager).execute(); + new EditAction(StandardActions.PASTE, libraryTab.frame(), Globals.stateManager).execute(); } event.consume(); break; case COPY: - new EditAction(StandardActions.COPY, panel.frame(), Globals.stateManager).execute(); + new EditAction(StandardActions.COPY, libraryTab.frame(), Globals.stateManager).execute(); event.consume(); break; case CUT: - new EditAction(StandardActions.CUT, panel.frame(), Globals.stateManager).execute(); + new EditAction(StandardActions.CUT, libraryTab.frame(), Globals.stateManager).execute(); event.consume(); break; default: @@ -292,7 +298,7 @@ public void paste(BibDatabaseMode bibDatabaseMode) { List entriesToAdd = Globals.clipboardManager.extractData(); ImportCleanup cleanup = new ImportCleanup(bibDatabaseMode); cleanup.doPostCleanup(entriesToAdd); - panel.insertEntries(entriesToAdd); + libraryTab.insertEntries(entriesToAdd); if (!entriesToAdd.isEmpty()) { this.requestFocus(); } @@ -348,29 +354,26 @@ private void handleOnDragDropped(TableRow row, BibEntryT // Different actions depending on where the user releases the drop in the target row // Bottom + top -> import entries // Center -> link files to entry + // Depending on the pressed modifier, move/copy/link files to drop target switch (ControlHelper.getDroppingMouseLocation(row, event)) { - case TOP: - case BOTTOM: - importHandler.importAsNewEntries(files); - break; - case CENTER: - // Depending on the pressed modifier, move/copy/link files to drop target + case TOP, BOTTOM -> importHandler.importAsNewEntries(files); + case CENTER -> { BibEntry entry = target.getEntry(); switch (event.getTransferMode()) { - case LINK: + case LINK -> { LOGGER.debug("Mode LINK"); // shift on win or no modifier importHandler.getLinker().addFilesToEntry(entry, files); - break; - case MOVE: + } + case MOVE -> { LOGGER.debug("Mode MOVE"); // alt on win importHandler.getLinker().moveFilesToFileDirAndAddToEntry(entry, files); - break; - case COPY: + } + case COPY -> { LOGGER.debug("Mode Copy"); // ctrl on win importHandler.getLinker().copyFilesToFileDirAndAddToEntry(entry, files); - break; + } } - break; + } } success = true; diff --git a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java index f7f46026857..6305baeaea7 100644 --- a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java @@ -4,10 +4,10 @@ import javafx.scene.control.Menu; import javafx.scene.control.SeparatorMenuItem; -import org.jabref.gui.BasePanel; import org.jabref.gui.ClipBoardManager; import org.jabref.gui.DialogService; import org.jabref.gui.Globals; +import org.jabref.gui.LibraryTab; import org.jabref.gui.SendAsEMailAction; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionFactory; @@ -33,7 +33,7 @@ public class RightClickMenu { public static ContextMenu create(BibEntryTableViewModel entry, KeyBindingRepository keyBindingRepository, - BasePanel panel, + LibraryTab libraryTab, DialogService dialogService, StateManager stateManager, PreferencesService preferencesService, @@ -41,11 +41,11 @@ public static ContextMenu create(BibEntryTableViewModel entry, ContextMenu contextMenu = new ContextMenu(); ActionFactory factory = new ActionFactory(keyBindingRepository); - contextMenu.getItems().add(factory.createMenuItem(StandardActions.COPY, new EditAction(StandardActions.COPY, panel.frame(), stateManager))); - contextMenu.getItems().add(createCopySubMenu(panel, factory, dialogService, stateManager, preferencesService, clipBoardManager)); - contextMenu.getItems().add(factory.createMenuItem(StandardActions.PASTE, new EditAction(StandardActions.PASTE, panel.frame(), stateManager))); - contextMenu.getItems().add(factory.createMenuItem(StandardActions.CUT, new EditAction(StandardActions.CUT, panel.frame(), stateManager))); - contextMenu.getItems().add(factory.createMenuItem(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, panel.frame(), stateManager))); + contextMenu.getItems().add(factory.createMenuItem(StandardActions.COPY, new EditAction(StandardActions.COPY, libraryTab.frame(), stateManager))); + contextMenu.getItems().add(createCopySubMenu(libraryTab, factory, dialogService, stateManager, preferencesService, clipBoardManager)); + contextMenu.getItems().add(factory.createMenuItem(StandardActions.PASTE, new EditAction(StandardActions.PASTE, libraryTab.frame(), stateManager))); + contextMenu.getItems().add(factory.createMenuItem(StandardActions.CUT, new EditAction(StandardActions.CUT, libraryTab.frame(), stateManager))); + contextMenu.getItems().add(factory.createMenuItem(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, libraryTab.frame(), stateManager))); contextMenu.getItems().add(new SeparatorMenuItem()); @@ -54,12 +54,12 @@ public static ContextMenu create(BibEntryTableViewModel entry, contextMenu.getItems().add(new SeparatorMenuItem()); if (preferencesService.getSpecialFieldsPreferences().isSpecialFieldsEnabled()) { - contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, panel.frame(), dialogService, stateManager)); - contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, panel.frame(), dialogService, stateManager)); - contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, panel.frame(), dialogService, stateManager)); - contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, panel.frame(), dialogService, stateManager)); - contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, panel.frame(), dialogService, stateManager)); - contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, panel.frame(), dialogService, stateManager)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, libraryTab.frame(), dialogService, stateManager)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, libraryTab.frame(), dialogService, stateManager)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, libraryTab.frame(), dialogService, stateManager)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, libraryTab.frame(), dialogService, stateManager)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, libraryTab.frame(), dialogService, stateManager)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, libraryTab.frame(), dialogService, stateManager)); } contextMenu.getItems().add(new SeparatorMenuItem()); @@ -71,16 +71,16 @@ public static ContextMenu create(BibEntryTableViewModel entry, contextMenu.getItems().add(new SeparatorMenuItem()); - contextMenu.getItems().add(new ChangeEntryTypeMenu().getChangeEntryTypeMenu(entry.getEntry(), panel.getBibDatabaseContext(), panel.getUndoManager())); - contextMenu.getItems().add(factory.createMenuItem(StandardActions.MERGE_WITH_FETCHED_ENTRY, new MergeWithFetchedEntryAction(panel, dialogService, stateManager))); - contextMenu.getItems().add(factory.createMenuItem(StandardActions.ATTACH_FILE, new AttachFileAction(panel, dialogService, stateManager, preferencesService))); + contextMenu.getItems().add(new ChangeEntryTypeMenu().getChangeEntryTypeMenu(entry.getEntry(), libraryTab.getBibDatabaseContext(), libraryTab.getUndoManager())); + contextMenu.getItems().add(factory.createMenuItem(StandardActions.MERGE_WITH_FETCHED_ENTRY, new MergeWithFetchedEntryAction(libraryTab, dialogService, stateManager))); + contextMenu.getItems().add(factory.createMenuItem(StandardActions.ATTACH_FILE, new AttachFileAction(libraryTab, dialogService, stateManager, preferencesService))); // ToDo: Refactor BasePanel, see ahead. - contextMenu.getItems().add(factory.createMenuItem(StandardActions.MERGE_ENTRIES, new MergeEntriesAction(panel.frame(), dialogService, stateManager))); + contextMenu.getItems().add(factory.createMenuItem(StandardActions.MERGE_ENTRIES, new MergeEntriesAction(libraryTab.frame(), dialogService, stateManager))); return contextMenu; } - private static Menu createCopySubMenu(BasePanel panel, + private static Menu createCopySubMenu(LibraryTab libraryTab, ActionFactory factory, DialogService dialogService, StateManager stateManager, @@ -108,7 +108,7 @@ private static Menu createCopySubMenu(BasePanel panel, copySpecialMenu.getItems().add(factory.createMenuItem(StandardActions.COPY_CITATION_PREVIEW, new CopyCitationAction(CitationStyleOutputFormat.HTML, dialogService, stateManager, clipBoardManager, previewPreferences))); } - copySpecialMenu.getItems().add(factory.createMenuItem(StandardActions.EXPORT_TO_CLIPBOARD, new ExportToClipboardAction(panel, dialogService, Globals.exportFactory, clipBoardManager, Globals.TASK_EXECUTOR))); + copySpecialMenu.getItems().add(factory.createMenuItem(StandardActions.EXPORT_TO_CLIPBOARD, new ExportToClipboardAction(libraryTab, dialogService, Globals.exportFactory, clipBoardManager, Globals.TASK_EXECUTOR))); return copySpecialMenu; } } diff --git a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java index 643f3bde53c..a64c0232111 100644 --- a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java +++ b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java @@ -8,9 +8,9 @@ import java.util.Set; import java.util.TreeSet; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; import org.jabref.gui.Globals; +import org.jabref.gui.LibraryTab; import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.undo.UndoableChangeType; import org.jabref.gui.undo.UndoableFieldChange; @@ -39,13 +39,13 @@ public class FetchAndMergeEntry { // A list of all field which are supported public static List SUPPORTED_FIELDS = Arrays.asList(StandardField.DOI, StandardField.EPRINT, StandardField.ISBN); private static final Logger LOGGER = LoggerFactory.getLogger(FetchAndMergeEntry.class); - private final BasePanel panel; + private final LibraryTab libraryTab; private final DialogService dialogService; private final TaskExecutor taskExecutor; - public FetchAndMergeEntry(BasePanel panel, TaskExecutor taskExecutor) { - this.dialogService = panel.frame().getDialogService(); - this.panel = panel; + public FetchAndMergeEntry(LibraryTab libraryTab, TaskExecutor taskExecutor) { + this.dialogService = libraryTab.frame().getDialogService(); + this.libraryTab = libraryTab; this.taskExecutor = taskExecutor; } @@ -65,7 +65,7 @@ public void fetchAndMerge(BibEntry entry, List fields) { if (fetcher.isPresent()) { BackgroundTask.wrap(() -> fetcher.get().performSearchById(fieldContent.get())) .onSuccess(fetchedEntry -> { - ImportCleanup cleanup = new ImportCleanup(panel.getBibDatabaseContext().getMode()); + ImportCleanup cleanup = new ImportCleanup(libraryTab.getBibDatabaseContext().getMode()); cleanup.doPostCleanup(entry); String type = field.getDisplayName(); if (fetchedEntry.isPresent()) { @@ -116,7 +116,7 @@ private void showMergeDialog(BibEntry originalEntry, BibEntry fetchedEntry, WebF for (Field field : jointFields) { Optional originalString = originalEntry.getField(field); Optional mergedString = mergedEntry.get().getField(field); - if (!originalString.isPresent() || !originalString.equals(mergedString)) { + if (originalString.isEmpty() || !originalString.equals(mergedString)) { originalEntry.setField(field, mergedString.get()); // mergedString always present ce.addEdit(new UndoableFieldChange(originalEntry, field, originalString.orElse(null), mergedString.get())); @@ -136,7 +136,7 @@ private void showMergeDialog(BibEntry originalEntry, BibEntry fetchedEntry, WebF if (edited) { ce.end(); - panel.getUndoManager().addEdit(ce); + libraryTab.getUndoManager().addEdit(ce); dialogService.notify(Localization.lang("Updated entry with info from %0", fetcher.getName())); } else { dialogService.notify(Localization.lang("No information added")); @@ -150,7 +150,7 @@ public void fetchAndMerge(BibEntry entry, EntryBasedFetcher fetcher) { BackgroundTask.wrap(() -> fetcher.performSearch(entry).stream().findFirst()) .onSuccess(fetchedEntry -> { if (fetchedEntry.isPresent()) { - ImportCleanup cleanup = new ImportCleanup(panel.getBibDatabaseContext().getMode()); + ImportCleanup cleanup = new ImportCleanup(libraryTab.getBibDatabaseContext().getMode()); cleanup.doPostCleanup(fetchedEntry.get()); showMergeDialog(entry, fetchedEntry.get(), fetcher); } else { diff --git a/src/main/java/org/jabref/gui/mergeentries/MergeEntriesAction.java b/src/main/java/org/jabref/gui/mergeentries/MergeEntriesAction.java index ec1ba539807..0b1991cdff6 100644 --- a/src/main/java/org/jabref/gui/mergeentries/MergeEntriesAction.java +++ b/src/main/java/org/jabref/gui/mergeentries/MergeEntriesAction.java @@ -59,7 +59,7 @@ public void execute() { // ToDo: BibDatabase::insertEntry does not contain logic to mark the BasePanel as changed and to mark // entries with a timestamp, only BasePanel::insertEntry does. Workaround for the moment is to get the // BasePanel from the constructor injected JabRefFrame. Should be refactored and extracted! - frame.getCurrentBasePanel().insertEntry(mergedEntry.get()); + frame.getCurrentLibraryTab().insertEntry(mergedEntry.get()); // Create a new entry and add it to the undo stack // Remove the other two entries and add them to the undo stack (which is not working...) diff --git a/src/main/java/org/jabref/gui/mergeentries/MergeWithFetchedEntryAction.java b/src/main/java/org/jabref/gui/mergeentries/MergeWithFetchedEntryAction.java index 5ebfb67676e..11aeaac50e0 100644 --- a/src/main/java/org/jabref/gui/mergeentries/MergeWithFetchedEntryAction.java +++ b/src/main/java/org/jabref/gui/mergeentries/MergeWithFetchedEntryAction.java @@ -1,8 +1,8 @@ package org.jabref.gui.mergeentries; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; import org.jabref.gui.Globals; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; @@ -13,12 +13,12 @@ public class MergeWithFetchedEntryAction extends SimpleCommand { - private final BasePanel basePanel; + private final LibraryTab libraryTab; private final DialogService dialogService; private final StateManager stateManager; - public MergeWithFetchedEntryAction(BasePanel basePanel, DialogService dialogService, StateManager stateManager) { - this.basePanel = basePanel; + public MergeWithFetchedEntryAction(LibraryTab libraryTab, DialogService dialogService, StateManager stateManager) { + this.libraryTab = libraryTab; this.dialogService = dialogService; this.stateManager = stateManager; @@ -35,6 +35,6 @@ public void execute() { } BibEntry originalEntry = stateManager.getSelectedEntries().get(0); - new FetchAndMergeEntry(basePanel, Globals.TASK_EXECUTOR).fetchAndMerge(originalEntry); + new FetchAndMergeEntry(libraryTab, Globals.TASK_EXECUTOR).fetchAndMerge(originalEntry); } } diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index 921ff24d050..90827514189 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -28,10 +28,10 @@ import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; import org.jabref.gui.Globals; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.actions.ActionFactory; import org.jabref.gui.actions.StandardActions; import org.jabref.gui.help.HelpAction; @@ -318,11 +318,11 @@ private void exportEntries() { private List getBaseList() { List databases = new ArrayList<>(); if (ooPrefs.getUseAllDatabases()) { - for (BasePanel basePanel : frame.getBasePanelList()) { - databases.add(basePanel.getDatabase()); + for (LibraryTab libraryTab : frame.getLibraryTabs()) { + databases.add(libraryTab.getDatabase()); } } else { - databases.add(frame.getCurrentBasePanel().getDatabase()); + databases.add(frame.getCurrentLibraryTab().getDatabase()); } return databases; @@ -338,7 +338,7 @@ private void connectAutomatically() { Task taskConnectIfInstalled = new Task<>() { @Override - protected Void call() throws Exception { + protected Void call() { updateProgress(ProgressBar.INDETERMINATE_PROGRESS, ProgressBar.INDETERMINATE_PROGRESS); boolean installed = officeInstallation.isInstalled(); @@ -474,10 +474,10 @@ private void pushEntries(boolean inParenthesisIn, boolean withText, boolean addP } } - BasePanel panel = frame.getCurrentBasePanel(); - if (panel != null) { - final BibDatabase database = panel.getDatabase(); - List entries = panel.getSelectedEntries(); + LibraryTab libraryTab = frame.getCurrentLibraryTab(); + if (libraryTab != null) { + final BibDatabase database = libraryTab.getDatabase(); + List entries = libraryTab.getSelectedEntries(); if (!entries.isEmpty() && checkThatEntriesHaveKeys(entries)) { try { @@ -519,7 +519,7 @@ private boolean checkThatEntriesHaveKeys(List entries) { // Check if there are empty keys boolean emptyKeys = false; for (BibEntry entry : entries) { - if (!entry.getCitationKey().isPresent()) { + if (entry.getCitationKey().isEmpty()) { // Found one, no need to look further for now emptyKeys = true; break; @@ -537,22 +537,22 @@ private boolean checkThatEntriesHaveKeys(List entries) { Localization.lang("Generate keys"), Localization.lang("Cancel")); - BasePanel panel = frame.getCurrentBasePanel(); - if (citePressed && (panel != null)) { + LibraryTab libraryTab = frame.getCurrentLibraryTab(); + if (citePressed && (libraryTab != null)) { // Generate keys CitationKeyPatternPreferences prefs = jabRefPreferences.getCitationKeyPatternPreferences(); NamedCompound undoCompound = new NamedCompound(Localization.lang("Cite")); for (BibEntry entry : entries) { - if (!entry.getCitationKey().isPresent()) { + if (entry.getCitationKey().isEmpty()) { // Generate key - new CitationKeyGenerator(panel.getBibDatabaseContext(), prefs) + new CitationKeyGenerator(libraryTab.getBibDatabaseContext(), prefs) .generateAndSetKey(entry) .ifPresent(change -> undoCompound.addEdit(new UndoableKeyChange(change))); } } undoCompound.end(); // Add all undos - panel.getUndoManager().addEdit(undoCompound); + libraryTab.getUndoManager().addEdit(undoCompound); // Now every entry has a key return true; } else { diff --git a/src/main/java/org/jabref/gui/preferences/EntryEditorTabViewModel.java b/src/main/java/org/jabref/gui/preferences/EntryEditorTabViewModel.java index de221e7dfc8..b3ccf7c58ec 100644 --- a/src/main/java/org/jabref/gui/preferences/EntryEditorTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/EntryEditorTabViewModel.java @@ -71,15 +71,9 @@ public void setValues() { } switch (initialAutoCompletePreferences.getFirstNameMode()) { - case ONLY_ABBREVIATED: - firstNameModeAbbreviatedProperty.setValue(true); - break; - case ONLY_FULL: - firstNameModeFullProperty.setValue(true); - break; - default: - firstNameModeBothProperty.setValue(true); - break; + case ONLY_ABBREVIATED -> firstNameModeAbbreviatedProperty.setValue(true); + case ONLY_FULL -> firstNameModeFullProperty.setValue(true); + default -> firstNameModeBothProperty.setValue(true); } } @@ -92,7 +86,8 @@ public void storeSettings() { acceptRecommendationsProperty.getValue(), enableLatexCitationsTabProperty.getValue(), defaultSourceProperty.getValue(), - enableValidationProperty.getValue())); + enableValidationProperty.getValue(), + initialEntryEditorPreferences.getDividerPosition())); // default AutoCompletePreferences.NameFormat nameFormat = AutoCompletePreferences.NameFormat.BOTH; diff --git a/src/main/java/org/jabref/gui/preferences/GeneralTabViewModel.java b/src/main/java/org/jabref/gui/preferences/GeneralTabViewModel.java index 59af8c67886..777dac8e66f 100644 --- a/src/main/java/org/jabref/gui/preferences/GeneralTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/GeneralTabViewModel.java @@ -103,8 +103,8 @@ public void setValues() { selectedBiblatexModeProperty.setValue(initialGeneralPreferences.getDefaultBibDatabaseMode()); inspectionWarningDuplicateProperty.setValue(initialGeneralPreferences.isWarnAboutDuplicatesInInspection()); - confirmDeleteProperty.setValue(initialGeneralPreferences.isConfirmDelete()); - allowIntegerEditionProperty.setValue(initialGeneralPreferences.isAllowIntegerEditionBibtex()); + confirmDeleteProperty.setValue(initialGeneralPreferences.shouldConfirmDelete()); + allowIntegerEditionProperty.setValue(initialGeneralPreferences.shouldAllowIntegerEditionBibtex()); memoryStickModeProperty.setValue(initialGeneralPreferences.isMemoryStickMode()); collectTelemetryProperty.setValue(preferencesService.shouldCollectTelemetry()); showAdvancedHintsProperty.setValue(initialGeneralPreferences.shouldShowAdvancedHints()); diff --git a/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java b/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java index 0d02d553374..a02a2bcd5d2 100644 --- a/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java @@ -150,7 +150,7 @@ private void updateAfterPreferenceChanges() { PushToApplicationsManager manager = frame.getPushToApplicationsManager(); manager.updateApplicationAction(manager.getApplicationByName(externalApplicationsPreferences.getPushToApplicationName())); - frame.getBasePanelList().forEach(panel -> panel.getMainTable().getTableModel().refresh()); + frame.getLibraryTabs().forEach(panel -> panel.getMainTable().getTableModel().refresh()); } /** diff --git a/src/main/java/org/jabref/gui/preferences/PreviewTabViewModel.java b/src/main/java/org/jabref/gui/preferences/PreviewTabViewModel.java index 78956920079..87479ec4d1c 100644 --- a/src/main/java/org/jabref/gui/preferences/PreviewTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/PreviewTabViewModel.java @@ -23,10 +23,10 @@ import javafx.scene.input.Dragboard; import javafx.scene.input.TransferMode; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; import org.jabref.gui.DragAndDropDataFormats; import org.jabref.gui.JabRefGUI; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.CustomLocalDragboard; @@ -216,9 +216,9 @@ public void storeSettings() { preferences.storePreviewPreferences(newPreviewPreferences); - for (BasePanel basePanel : JabRefGUI.getMainFrame().getBasePanelList()) { + for (LibraryTab libraryTab : JabRefGUI.getMainFrame().getLibraryTabs()) { // TODO: Find a better way to update preview - basePanel.closeBottomPane(); + libraryTab.closeBottomPane(); // basePanel.getPreviewPanel().updateLayout(preferences.getPreviewPreferences()); } } diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index 6e674d584b4..9cc91baeee2 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -113,7 +113,7 @@ public GlobalSearchBar(JabRefFrame frame, StateManager stateManager, Preferences if (keyBinding.get().equals(KeyBinding.CLOSE)) { // Clear search and select first entry, if available searchField.setText(""); - frame.getCurrentBasePanel().getMainTable().getSelectionModel().selectFirst(); + frame.getCurrentLibraryTab().getMainTable().getSelectionModel().selectFirst(); event.consume(); } } diff --git a/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java b/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java index 845732f020a..18ffe5c365f 100644 --- a/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java +++ b/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java @@ -20,10 +20,10 @@ import javafx.scene.control.ButtonType; import org.jabref.gui.AbstractViewModel; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; import org.jabref.gui.Globals; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.exporter.SaveDatabaseAction; import org.jabref.gui.help.HelpAction; import org.jabref.gui.util.FileDialogConfiguration; @@ -87,9 +87,7 @@ public SharedDatabaseLoginDialogViewModel(JabRefFrame frame, DialogService dialo this.frame = frame; this.dialogService = dialogService; - EasyBind.subscribe(selectedDBMSType, selected -> { - port.setValue(Integer.toString(selected.getDefaultPort())); - }); + EasyBind.subscribe(selectedDBMSType, selected -> port.setValue(Integer.toString(selected.getDefaultPort()))); Predicate notEmpty = input -> (input != null) && !input.trim().isEmpty(); Predicate fileExists = input -> Files.exists(Path.of(input)); @@ -124,8 +122,7 @@ public boolean openDatabase() { .createDBMSConnectionProperties(); setupKeyStore(); - boolean connected = openSharedDatabase(connectionProperties); - return connected; + return openSharedDatabase(connectionProperties); } private void setupKeyStore() { @@ -161,12 +158,12 @@ private boolean openSharedDatabase(DBMSConnectionProperties connectionProperties try { SharedDatabaseUIManager manager = new SharedDatabaseUIManager(frame); - BasePanel panel = manager.openNewSharedDatabaseTab(connectionProperties); + LibraryTab libraryTab = manager.openNewSharedDatabaseTab(connectionProperties); setPreferences(); if (!folder.getValue().isEmpty()) { try { - new SaveDatabaseAction(panel, Globals.prefs, Globals.entryTypesManager).saveAs(Path.of(folder.getValue())); + new SaveDatabaseAction(libraryTab, Globals.prefs, Globals.entryTypesManager).saveAs(Path.of(folder.getValue())); } catch (Throwable e) { LOGGER.error("Error while saving the database", e); } @@ -255,7 +252,7 @@ private void applyPreferences() { } private boolean isSharedDatabaseAlreadyPresent(DBMSConnectionProperties connectionProperties) { - List panels = frame.getBasePanelList(); + List panels = frame.getLibraryTabs(); return panels.parallelStream().anyMatch(panel -> { BibDatabaseContext context = panel.getBibDatabaseContext(); @@ -271,9 +268,7 @@ public void showSaveDbToFileDialog() { .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)) .build(); Optional exportPath = dialogService.showFileSaveDialog(fileDialogConfiguration); - exportPath.ifPresent(path -> { - folder.setValue(path.toString()); - }); + exportPath.ifPresent(path -> folder.setValue(path.toString())); } public void showOpenKeystoreFileDialog() { @@ -284,9 +279,7 @@ public void showOpenKeystoreFileDialog() { .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)) .build(); Optional keystorePath = dialogService.showFileOpenDialog(fileDialogConfiguration); - keystorePath.ifPresent(path -> { - keystore.setValue(path.toString()); - }); + keystorePath.ifPresent(path -> keystore.setValue(path.toString())); } public StringProperty databaseproperty() { diff --git a/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java b/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java index d80128d9af5..a089aadf723 100644 --- a/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java +++ b/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java @@ -9,10 +9,10 @@ import javafx.scene.control.ButtonBar.ButtonData; import javafx.scene.control.ButtonType; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; import org.jabref.gui.Globals; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.entryeditor.EntryEditor; import org.jabref.gui.exporter.SaveDatabaseAction; import org.jabref.gui.mergeentries.MergeEntriesDialog; @@ -66,7 +66,7 @@ public void listen(ConnectionLostEvent connectionLostEvent) { new SharedDatabaseLoginDialogView(jabRefFrame).showAndWait(); } else if (answer.get().equals(workOffline)) { connectionLostEvent.getBibDatabaseContext().convertToLocalDatabase(); - jabRefFrame.refreshTitleAndTabs(); + // jabRefFrame.refreshWindowAndTabTitles(); jabRefFrame.getDialogService().notify(Localization.lang("Working offline.")); } } else { @@ -115,10 +115,10 @@ public void listen(UpdateRefusedEvent updateRefusedEvent) { @Subscribe public void listen(SharedEntriesNotPresentEvent event) { - BasePanel panel = jabRefFrame.getCurrentBasePanel(); - EntryEditor entryEditor = panel.getEntryEditor(); + LibraryTab libraryTab = jabRefFrame.getCurrentLibraryTab(); + EntryEditor entryEditor = libraryTab.getEntryEditor(); - panel.getUndoManager().addEdit(new UndoableRemoveEntries(panel.getDatabase(), event.getBibEntries())); + libraryTab.getUndoManager().addEdit(new UndoableRemoveEntries(libraryTab.getDatabase(), event.getBibEntries())); if (Objects.nonNull(entryEditor) && (event.getBibEntries().contains(entryEditor.getEntry()))) { @@ -126,7 +126,7 @@ public void listen(SharedEntriesNotPresentEvent event) { Localization.lang("The entry you currently work on has been deleted on the shared side.") + "\n" + Localization.lang("You can restore the entry using the \"Undo\" operation.")); - panel.closeBottomPane(); + libraryTab.closeBottomPane(); } } @@ -136,7 +136,7 @@ public void listen(SharedEntriesNotPresentEvent event) { * @param dbmsConnectionProperties Connection data * @return BasePanel which also used by {@link SaveDatabaseAction} */ - public BasePanel openNewSharedDatabaseTab(DBMSConnectionProperties dbmsConnectionProperties) + public LibraryTab openNewSharedDatabaseTab(DBMSConnectionProperties dbmsConnectionProperties) throws SQLException, DatabaseNotSupportedException, InvalidDBMSConnectionPropertiesException { BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(); diff --git a/src/main/java/org/jabref/gui/specialfields/SpecialFieldAction.java b/src/main/java/org/jabref/gui/specialfields/SpecialFieldAction.java index 40f6567342e..4701b93a58d 100644 --- a/src/main/java/org/jabref/gui/specialfields/SpecialFieldAction.java +++ b/src/main/java/org/jabref/gui/specialfields/SpecialFieldAction.java @@ -76,9 +76,9 @@ public void execute() { } ce.end(); if (ce.hasEdits()) { - frame.getCurrentBasePanel().getUndoManager().addEdit(ce); - frame.getCurrentBasePanel().markBaseChanged(); - frame.getCurrentBasePanel().updateEntryEditorIfShowing(); + frame.getCurrentLibraryTab().getUndoManager().addEdit(ce); + frame.getCurrentLibraryTab().markBaseChanged(); + frame.getCurrentLibraryTab().updateEntryEditorIfShowing(); String outText; if (nullFieldIfValueIsTheSame || value == null) { outText = getTextDone(specialField, Integer.toString(bes.size())); diff --git a/src/main/java/org/jabref/gui/undo/UndoRedoAction.java b/src/main/java/org/jabref/gui/undo/UndoRedoAction.java index eb2e7e7cf50..9515bda0654 100644 --- a/src/main/java/org/jabref/gui/undo/UndoRedoAction.java +++ b/src/main/java/org/jabref/gui/undo/UndoRedoAction.java @@ -3,9 +3,9 @@ import javax.swing.undo.CannotRedoException; import javax.swing.undo.CannotUndoException; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; @@ -35,26 +35,26 @@ public UndoRedoAction(StandardActions action, JabRefFrame frame, DialogService d @Override public void execute() { - BasePanel panel = frame.getCurrentBasePanel(); + LibraryTab libraryTab = frame.getCurrentLibraryTab(); if (action == StandardActions.UNDO) { try { - panel.getUndoManager().undo(); - panel.markBaseChanged(); + libraryTab.getUndoManager().undo(); + libraryTab.markBaseChanged(); dialogService.notify(Localization.lang("Undo")); } catch (CannotUndoException ex) { dialogService.notify(Localization.lang("Nothing to undo") + '.'); } - frame.getCurrentBasePanel().markChangedOrUnChanged(); + frame.getCurrentLibraryTab().markChangedOrUnChanged(); } else if (action == StandardActions.REDO) { try { - panel.getUndoManager().redo(); - panel.markBaseChanged(); + libraryTab.getUndoManager().redo(); + libraryTab.markBaseChanged(); dialogService.notify(Localization.lang("Redo")); } catch (CannotRedoException ex) { dialogService.notify(Localization.lang("Nothing to redo") + '.'); } - panel.markChangedOrUnChanged(); + libraryTab.markChangedOrUnChanged(); } else { LOGGER.debug("No undo/redo action: " + action.name()); } diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizePagesFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizePagesFormatter.java index ff0d6d7028e..8a9163b73f5 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizePagesFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizePagesFormatter.java @@ -62,7 +62,7 @@ public String format(String value) { // Remove pages prefix String cleanValue = value.replace("pp.", "").replace("p.", ""); - // remove unwanted literals incl. whitespace + // remove unwanted literals including en dash, em dash, and whitespace cleanValue = cleanValue.replaceAll("\u2013|\u2014", "-").replaceAll(REJECT_LITERALS, ""); // try to find pages pattern Matcher matcher = PAGES_DETECT_PATTERN.matcher(cleanValue); diff --git a/src/main/java/org/jabref/preferences/GeneralPreferences.java b/src/main/java/org/jabref/preferences/GeneralPreferences.java index 8e80440da53..0db44970816 100644 --- a/src/main/java/org/jabref/preferences/GeneralPreferences.java +++ b/src/main/java/org/jabref/preferences/GeneralPreferences.java @@ -9,7 +9,7 @@ public class GeneralPreferences { private final BibDatabaseMode defaultBibDatabaseMode; private final boolean warnAboutDuplicatesInInspection; - private final boolean confirmDelete; + private boolean confirmDelete; private final boolean allowIntegerEditionBibtex; private final boolean memoryStickMode; private final boolean collectTelemetry; @@ -45,11 +45,16 @@ public boolean isWarnAboutDuplicatesInInspection() { return warnAboutDuplicatesInInspection; } - public boolean isConfirmDelete() { + public boolean shouldConfirmDelete() { return confirmDelete; } - public boolean isAllowIntegerEditionBibtex() { + public GeneralPreferences withConfirmDelete(boolean confirmDelete) { + this.confirmDelete = confirmDelete; + return this; + } + + public boolean shouldAllowIntegerEditionBibtex() { return allowIntegerEditionBibtex; } @@ -57,7 +62,7 @@ public boolean isMemoryStickMode() { return memoryStickMode; } - public boolean isCollectTelemetry() { + public boolean shouldCollectTelemetry() { return collectTelemetry; } diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index f3e6517cce9..2e908686c38 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -1526,10 +1526,10 @@ public void storeGeneralPreferences(GeneralPreferences preferences) { put(DEFAULT_ENCODING, preferences.getDefaultEncoding().name()); putBoolean(BIBLATEX_DEFAULT_MODE, (preferences.getDefaultBibDatabaseMode() == BibDatabaseMode.BIBLATEX)); putBoolean(WARN_ABOUT_DUPLICATES_IN_INSPECTION, preferences.isWarnAboutDuplicatesInInspection()); - putBoolean(CONFIRM_DELETE, preferences.isConfirmDelete()); - putBoolean(ALLOW_INTEGER_EDITION_BIBTEX, preferences.isAllowIntegerEditionBibtex()); + putBoolean(CONFIRM_DELETE, preferences.shouldConfirmDelete()); + putBoolean(ALLOW_INTEGER_EDITION_BIBTEX, preferences.shouldAllowIntegerEditionBibtex()); putBoolean(MEMORY_STICK_MODE, preferences.isMemoryStickMode()); - setShouldCollectTelemetry(preferences.isCollectTelemetry()); + setShouldCollectTelemetry(preferences.shouldCollectTelemetry()); putBoolean(SHOW_ADVANCED_HINTS, preferences.shouldShowAdvancedHints()); } @@ -1735,7 +1735,8 @@ public EntryEditorPreferences getEntryEditorPreferences() { getBoolean(ACCEPT_RECOMMENDATIONS), getBoolean(SHOW_LATEX_CITATIONS), getBoolean(DEFAULT_SHOW_SOURCE), - getBoolean(VALIDATE_IN_ENTRY_EDITOR)); + getBoolean(VALIDATE_IN_ENTRY_EDITOR), + getDouble(ENTRY_EDITOR_HEIGHT)); } @Override @@ -1747,6 +1748,7 @@ public void storeEntryEditorPreferences(EntryEditorPreferences preferences) { putBoolean(SHOW_LATEX_CITATIONS, preferences.shouldShowLatexCitationsTab()); putBoolean(DEFAULT_SHOW_SOURCE, preferences.showSourceTabByDefault()); putBoolean(VALIDATE_IN_ENTRY_EDITOR, preferences.isEnableValidation()); + putDouble(ENTRY_EDITOR_HEIGHT, preferences.getDividerPosition()); } //************************************************************************************************************* diff --git a/src/test/java/org/jabref/gui/exporter/SaveDatabaseActionTest.java b/src/test/java/org/jabref/gui/exporter/SaveDatabaseActionTest.java index 5ee07e4d58e..d6a4e5af45d 100644 --- a/src/test/java/org/jabref/gui/exporter/SaveDatabaseActionTest.java +++ b/src/test/java/org/jabref/gui/exporter/SaveDatabaseActionTest.java @@ -10,9 +10,9 @@ import java.util.Optional; import java.util.stream.Collectors; -import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.LibraryTab; import org.jabref.gui.undo.CountingUndoManager; import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.logic.bibtex.FieldContentFormatterPreferences; @@ -48,18 +48,18 @@ class SaveDatabaseActionTest { private Path file = Path.of(TEST_BIBTEX_LIBRARY_LOCATION); private DialogService dialogService = mock(DialogService.class); private JabRefPreferences preferences = mock(JabRefPreferences.class); - private BasePanel basePanel = mock(BasePanel.class); + private LibraryTab libraryTab = mock(LibraryTab.class); private JabRefFrame jabRefFrame = mock(JabRefFrame.class); private BibDatabaseContext dbContext = spy(BibDatabaseContext.class); private SaveDatabaseAction saveDatabaseAction; @BeforeEach public void setUp() { - when(basePanel.frame()).thenReturn(jabRefFrame); - when(basePanel.getBibDatabaseContext()).thenReturn(dbContext); + when(libraryTab.frame()).thenReturn(jabRefFrame); + when(libraryTab.getBibDatabaseContext()).thenReturn(dbContext); when(jabRefFrame.getDialogService()).thenReturn(dialogService); - saveDatabaseAction = spy(new SaveDatabaseAction(basePanel, preferences, mock(BibEntryTypesManager.class))); + saveDatabaseAction = spy(new SaveDatabaseAction(libraryTab, preferences, mock(BibEntryTypesManager.class))); } @Test @@ -106,7 +106,7 @@ private SaveDatabaseAction createSaveDatabaseActionForBibDatabase(BibDatabase da SavePreferences savePreferences = mock(SavePreferences.class); // In case a "thenReturn" is modified, the whole mock has to be recreated dbContext = mock(BibDatabaseContext.class); - basePanel = mock(BasePanel.class); + libraryTab = mock(LibraryTab.class); MetaData metaData = mock(MetaData.class); when(savePreferences.withEncoding(any(Charset.class))).thenReturn(savePreferences); when(savePreferences.withSaveType(any(SavePreferences.DatabaseSaveType.class))).thenReturn(savePreferences); @@ -125,11 +125,11 @@ private SaveDatabaseAction createSaveDatabaseActionForBibDatabase(BibDatabase da when(preferences.getDefaultEncoding()).thenReturn(StandardCharsets.UTF_8); when(preferences.getFieldContentParserPreferences()).thenReturn(mock(FieldContentFormatterPreferences.class)); when(preferences.getSavePreferences()).thenReturn(savePreferences); - when(basePanel.frame()).thenReturn(jabRefFrame); - when(basePanel.getBibDatabaseContext()).thenReturn(dbContext); - when(basePanel.getUndoManager()).thenReturn(mock(CountingUndoManager.class)); - when(basePanel.getBibDatabaseContext()).thenReturn(dbContext); - saveDatabaseAction = new SaveDatabaseAction(basePanel, preferences, mock(BibEntryTypesManager.class)); + when(libraryTab.frame()).thenReturn(jabRefFrame); + when(libraryTab.getBibDatabaseContext()).thenReturn(dbContext); + when(libraryTab.getUndoManager()).thenReturn(mock(CountingUndoManager.class)); + when(libraryTab.getBibDatabaseContext()).thenReturn(dbContext); + saveDatabaseAction = new SaveDatabaseAction(libraryTab, preferences, mock(BibEntryTypesManager.class)); return saveDatabaseAction; }