Skip to content

Commit

Permalink
Add 'More' option to right click menu in the main table JabRef#9432 (J…
Browse files Browse the repository at this point in the history
…abRef#10659)

* add show more option in the right click main table header menu,
openingthe preferences

* comments

* Achieving contribution 2

* adjustments for right click menu on main table

* Update CHANGELOG.md for 9432

* PR test requirements

* Other PR requirements

* Other PR requirements

* remove optional from parameter

* openrewrite test

* openrewrite test

* change string to class for selection

* change string to class for selection

* remove comment + pass keybindings as parameter

* Update JabRef_en.properties

* Introduced StandardActions.withText

* Refactored for code maintenance

* Moved calls to frame out of PreferencesDialogView

---------

Co-authored-by: Théo Granier <[email protected]>
Co-authored-by: newma2n <[email protected]>
Co-authored-by: Carl Christian Snethlage <[email protected]>
  • Loading branch information
4 people authored Nov 27, 2023
1 parent 16d111a commit 2a4bd6c
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added a button to let users reset the cite command to the default value. [#10569](https://github.com/JabRef/jabref/issues/10569)
- We added the option to use System Preference for Light/Dark Theme [#8729](https://github.com/JabRef/jabref/issues/8729).
- We added [scholar.archive.org](https://scholar.archive.org/) as a new fetcher. [#10498](https://github.com/JabRef/jabref/issues/10498)
- We added a 'More options' section in the main table right click menu opening the preferences dialog. [#9432](https://github.com/JabRef/jabref/issues/9432)

### Changed

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private void createMenu() {

new SeparatorMenuItem(),

factory.createMenuItem(StandardActions.SHOW_PREFS, new ShowPreferencesAction(frame, taskExecutor)),
factory.createMenuItem(StandardActions.SHOW_PREFS, new ShowPreferencesAction(frame)),

new SeparatorMenuItem(),

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/jabref/gui/actions/StandardActions.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.gui.actions;

import java.util.Objects;
import java.util.Optional;

import org.jabref.gui.icon.IconTheme;
Expand Down Expand Up @@ -194,7 +195,7 @@ public enum StandardActions implements Action {
GROUP_ENTRIES_ADD(Localization.lang("Add selected entries to this group")),
GROUP_ENTRIES_REMOVE(Localization.lang("Remove selected entries from this group"));

private final String text;
private String text;
private final String description;
private final Optional<JabRefIcon> icon;
private final Optional<KeyBinding> keyBinding;
Expand Down Expand Up @@ -271,4 +272,9 @@ public String getText() {
public String getDescription() {
return description;
}

public Action withText(String text) {
this.text = Objects.requireNonNull(text);
return this;
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public MainTable(MainTableDataModel model,
taskExecutor);

// Enable the header right-click menu.
new MainTableHeaderContextMenu(this, rightClickMenuFactory).show(true);
new MainTableHeaderContextMenu(this, rightClickMenuFactory, this.libraryTab.frame(), keyBindingRepository).show(true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,42 @@

import javafx.collections.ObservableList;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.RadioMenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.TableColumn;
import javafx.scene.layout.StackPane;

import org.jabref.gui.JabRefFrame;
import org.jabref.gui.actions.ActionFactory;
import org.jabref.gui.actions.StandardActions;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.maintable.columns.MainTableColumn;
import org.jabref.gui.preferences.ShowPreferencesAction;
import org.jabref.gui.preferences.table.TableTab;
import org.jabref.logic.l10n.Localization;

public class MainTableHeaderContextMenu extends ContextMenu {

private static final int OUT_OF_BOUNDS = -1;
MainTable mainTable;
MainTableColumnFactory factory;
private final JabRefFrame frame;
private final KeyBindingRepository keyBindingRepository;

/**
* Constructor for the right click menu
*
*/
public MainTableHeaderContextMenu(MainTable mainTable, MainTableColumnFactory factory) {
public MainTableHeaderContextMenu(MainTable mainTable,
MainTableColumnFactory factory,
JabRefFrame frame,
KeyBindingRepository keyBindingRepository) {
super();
this.frame = frame;
this.mainTable = mainTable;
this.factory = factory;
this.keyBindingRepository = keyBindingRepository;
constructItems(mainTable);
}

Expand Down Expand Up @@ -66,15 +81,22 @@ private void constructItems(MainTable mainTable) {
}
}

SeparatorMenuItem separator = new SeparatorMenuItem();
this.getItems().add(separator);
if (!commonColumns.isEmpty()) {
this.getItems().add(new SeparatorMenuItem());

// Append to the menu the current remaining columns in the common columns.

for (TableColumn<BibEntryTableViewModel, ?> tableColumn : commonColumns) {
RightClickMenuItem itemToAdd = createMenuItem(tableColumn, false);
this.getItems().add(itemToAdd);
// Append to the menu the current remaining columns in the common columns.
for (TableColumn<BibEntryTableViewModel, ?> tableColumn : commonColumns) {
RightClickMenuItem itemToAdd = createMenuItem(tableColumn, false);
this.getItems().add(itemToAdd);
}
}

this.getItems().add(new SeparatorMenuItem());
ActionFactory actionfactory = new ActionFactory(this.keyBindingRepository);
MenuItem showMoreItem = actionfactory.createMenuItem(
StandardActions.SHOW_PREFS.withText(Localization.lang("More options...")),
new ShowPreferencesAction(frame, TableTab.class));
this.getItems().add(showMoreItem);
}

/**
Expand Down Expand Up @@ -110,7 +132,7 @@ private int obtainIndexOfColumn(MainTableColumn searchColumn) {
*/
@SuppressWarnings("rawtypes")
private void addColumn(MainTableColumn tableColumn, int index) {
if (index <= OUT_OF_BOUNDS || index >= mainTable.getColumns().size()) {
if ((index <= OUT_OF_BOUNDS) || (index >= mainTable.getColumns().size())) {
mainTable.getColumns().add(tableColumn);
} else {
mainTable.getColumns().add(index, tableColumn);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.gui.preferences;

import java.util.Locale;
import java.util.Optional;

import javafx.fxml.FXML;
import javafx.scene.control.ButtonType;
Expand All @@ -10,7 +11,6 @@
import javafx.scene.input.KeyCode;

import org.jabref.gui.DialogService;
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.keyboard.KeyBinding;
import org.jabref.gui.theme.ThemeManager;
Expand Down Expand Up @@ -42,12 +42,12 @@ public class PreferencesDialogView extends BaseDialog<PreferencesDialogViewModel
@Inject private PreferencesService preferencesService;
@Inject private ThemeManager themeManager;

private final JabRefFrame frame;
private PreferencesDialogViewModel viewModel;
private final Class<? extends PreferencesTab> preferencesTabToSelectClass;

public PreferencesDialogView(JabRefFrame frame) {
this.frame = frame;
public PreferencesDialogView(Class<? extends PreferencesTab> preferencesTabToSelectClass) {
this.setTitle(Localization.lang("JabRef preferences"));
this.preferencesTabToSelectClass = preferencesTabToSelectClass;

ViewLoader.view(this)
.load()
Expand All @@ -71,7 +71,7 @@ public PreferencesDialogViewModel getViewModel() {

@FXML
private void initialize() {
viewModel = new PreferencesDialogViewModel(dialogService, preferencesService, frame);
viewModel = new PreferencesDialogViewModel(dialogService, preferencesService);

preferenceTabList.itemsProperty().setValue(viewModel.getPreferenceTabs());

Expand Down Expand Up @@ -102,7 +102,16 @@ private void initialize() {
}
});

preferenceTabList.getSelectionModel().selectFirst();
if (this.preferencesTabToSelectClass != null) {
Optional<PreferencesTab> tabToSelectIfExist = preferenceTabList.getItems()
.stream()
.filter(prefTab -> prefTab.getClass().equals(preferencesTabToSelectClass))
.findFirst();
tabToSelectIfExist.ifPresent(preferencesTab -> preferenceTabList.getSelectionModel().select(preferencesTab));
} else {
preferenceTabList.getSelectionModel().selectFirst();
}

new ViewModelListCellFactory<PreferencesTab>()
.withText(PreferencesTab::getTabName)
.install(preferenceTabList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.jabref.gui.AbstractViewModel;
import org.jabref.gui.DialogService;
import org.jabref.gui.Globals;
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.preferences.autocompletion.AutoCompletionTab;
import org.jabref.gui.preferences.citationkeypattern.CitationKeyPatternTab;
import org.jabref.gui.preferences.customentrytypes.CustomEntryTypesTab;
Expand Down Expand Up @@ -55,12 +54,10 @@ public class PreferencesDialogViewModel extends AbstractViewModel {
private final DialogService dialogService;
private final PreferencesService preferences;
private final ObservableList<PreferencesTab> preferenceTabs;
private final JabRefFrame frame;

public PreferencesDialogViewModel(DialogService dialogService, PreferencesService preferences, JabRefFrame frame) {
public PreferencesDialogViewModel(DialogService dialogService, PreferencesService preferences) {
this.dialogService = dialogService;
this.preferences = preferences;
this.frame = frame;

preferenceTabs = FXCollections.observableArrayList(
new GeneralTab(),
Expand Down Expand Up @@ -102,7 +99,7 @@ public void importPreferences() {
.ifPresent(file -> {
try {
preferences.importPreferences(file);
updateAfterPreferenceChanges();
setValues();

dialogService.showWarningDialogAndWait(Localization.lang("Import preferences"),
Localization.lang("You must restart JabRef for this to come into effect."));
Expand Down Expand Up @@ -154,19 +151,10 @@ public void resetPreferences() {
dialogService.showErrorDialogAndWait(Localization.lang("Reset preferences"), ex);
}

updateAfterPreferenceChanges();
setValues();
}
}

/**
* Reloads the preferences into the UI
*/
private void updateAfterPreferenceChanges() {
setValues();

frame.getLibraryTabs().forEach(panel -> panel.getMainTable().getTableModel().refresh());
}

/**
* Checks if all tabs are valid
*/
Expand Down Expand Up @@ -203,12 +191,10 @@ public void storeAllSettings() {
+ Localization.lang("You must restart JabRef for this to come into effect."));
}

frame.setupAllTables();
frame.getGlobalSearchBar().updateHintVisibility();
Globals.entryTypesManager = preferences.getCustomEntryTypesRepository();
dialogService.notify(Localization.lang("Preferences recorded."));

updateAfterPreferenceChanges();
setValues();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,31 @@
import org.jabref.gui.DialogService;
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.util.TaskExecutor;

import com.airhacks.afterburner.injection.Injector;

public class ShowPreferencesAction extends SimpleCommand {

private final JabRefFrame jabRefFrame;
private final TaskExecutor taskExecutor;
private final Class<? extends PreferencesTab> preferencesTabToSelectClass;

public ShowPreferencesAction(JabRefFrame jabRefFrame, TaskExecutor taskExecutor) {
public ShowPreferencesAction(JabRefFrame jabRefFrame) {
this(jabRefFrame, null);
}

public ShowPreferencesAction(JabRefFrame jabRefFrame, Class<? extends PreferencesTab> preferencesTabToSelectClass) {
this.jabRefFrame = jabRefFrame;
this.taskExecutor = taskExecutor;
this.preferencesTabToSelectClass = preferencesTabToSelectClass;
}

@Override
public void execute() {
DialogService dialogService = Injector.instantiateModelOrService(DialogService.class);
dialogService.showCustomDialog(new PreferencesDialogView(jabRefFrame));
dialogService.showCustomDialog(new PreferencesDialogView(preferencesTabToSelectClass));

// Refresh frame and tables
jabRefFrame.getGlobalSearchBar().updateHintVisibility();
jabRefFrame.setupAllTables();
jabRefFrame.getLibraryTabs().forEach(panel -> panel.getMainTable().getTableModel().refresh());
}
}
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2621,3 +2621,4 @@ Would\ you\ like\ to\ enable\ fetching\ of\ journal\ information?\ This\ can\ be
Enable=Enable
Keep\ disabled=Keep disabled
More\ options...=More options...

0 comments on commit 2a4bd6c

Please sign in to comment.