Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting: always add "Cited on pages" text to JStyles. #11732

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Added

- We added a setting which always adds the literal "Cited on pages" text before each JStyle citation. [#11691](https://github.com/JabRef/jabref/pull/11732)
- We added probable search hits instead of exact matches. Sorting by hit score can be done by the new score table column. [#11542](https://github.com/JabRef/jabref/pull/11542)
- We added support finding LaTeX-encoded special characters based on plain Unicode and vice versa. [#11542](https://github.com/JabRef/jabref/pull/11542)
- When a search hits a file, the file icon of that entry is changed accordingly. [#11542](https://github.com/JabRef/jabref/pull/11542)
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,17 @@ private boolean checkThatEntriesHaveKeys(List<BibEntry> entries) {
}

private ContextMenu createSettingsPopup() {
OpenOfficePreferences openOfficePreferences = preferencesService.getOpenOfficePreferences();

ContextMenu contextMenu = new ContextMenu();

if (currentStyle instanceof JStyle) {
addAlwaysCitedOnPagesTextOption(contextMenu);
}

OpenOfficePreferences openOfficePreferences = preferencesService.getOpenOfficePreferences();

CheckMenuItem autoSync = new CheckMenuItem(Localization.lang("Automatically sync bibliography when inserting citations"));
autoSync.selectedProperty().set(preferencesService.getOpenOfficePreferences().getSyncWhenCiting());
autoSync.selectedProperty().set(openOfficePreferences.getSyncWhenCiting());

ToggleGroup toggleGroup = new ToggleGroup();
RadioMenuItem useActiveBase = new RadioMenuItem(Localization.lang("Look up BibTeX entries in the active tab only"));
Expand Down Expand Up @@ -657,4 +662,15 @@ private ContextMenu createSettingsPopup() {

return contextMenu;
}

private void addAlwaysCitedOnPagesTextOption(ContextMenu contextMenu) {
OpenOfficePreferences openOfficePreferences = preferencesService.getOpenOfficePreferences();
Copy link
Member

@subhramit subhramit Sep 8, 2024

Choose a reason for hiding this comment

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

Additional request for refactor (since we're here): If we require openOfficePreferences inside multiple methods, we can declare it at class-level and call the getter just once.

Note: Actually, it is slightly bad design that the entire preferencesService is passed to this class' constructor (not your fault). Could be abstracted, but that's out of scope for this PR an would require more effort to change. You can just do what I mentioned above.


CheckMenuItem alwaysAddCitedOnPagesText = new CheckMenuItem(Localization.lang("Automatically add Cited on pages"));

alwaysAddCitedOnPagesText.selectedProperty().set(openOfficePreferences.getAlwaysAddCitedOnPages());
alwaysAddCitedOnPagesText.setOnAction(e -> openOfficePreferences.setAlwaysAddCitedOnPages(alwaysAddCitedOnPagesText.isSelected()));

contextMenu.getItems().add(alwaysAddCitedOnPagesText);
Copy link
Member

@subhramit subhramit Sep 8, 2024

Choose a reason for hiding this comment

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

  1. Once added, this is never removed.
    In the issue, I had hinted on using a listener for the style type. We have to use it, otherwise once a JStyle is selected, this will always appear in the settings even if we select a CSL style afterwards.

  2. Can you add this below the option "Automatically sync bibliography when inserting citations" instead of above it? Reason: The pre-existing option should stay where it was, the new one should be added after it for the user's convenience.

  3. For design uniformity, you can also unify the code in this function into the existing createSettingsPopup(). Reason: Although delegating into separate functions makes code cleaner to read, each function of this class deals with a high-level activity.

Copy link
Contributor Author

@heyitsdross heyitsdross Sep 9, 2024

Choose a reason for hiding this comment

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

I'm really embarrassed I forgot about the CSL Styles, will add the removal mechanism and move the item below the "old" option as requested.

Copy link
Member

Choose a reason for hiding this comment

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

I'm really embarrassed I forgot about the CSL Styles, will add the removal mechanism and move the item below the "old" option as requested.

Please be comfortable, you are new to the codebase, so that's very normal!

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,21 @@ public class OpenOfficePreferences {
private final ObservableList<String> externalStyles;
private final StringProperty currentJStyle;
private final ObjectProperty<OOStyle> currentStyle;
private final BooleanProperty alwaysAddCitedOnPages;

public OpenOfficePreferences(String executablePath,
boolean useAllDatabases,
boolean syncWhenCiting,
List<String> externalStyles,
String currentJStyle,
OOStyle currentStyle) {
OOStyle currentStyle, boolean alwaysAddCitedOnPages) {
this.executablePath = new SimpleStringProperty(executablePath);
this.useAllDatabases = new SimpleBooleanProperty(useAllDatabases);
this.syncWhenCiting = new SimpleBooleanProperty(syncWhenCiting);
this.externalStyles = FXCollections.observableArrayList(externalStyles);
this.currentJStyle = new SimpleStringProperty(currentJStyle);
this.currentStyle = new SimpleObjectProperty<>(currentStyle);
this.alwaysAddCitedOnPages = new SimpleBooleanProperty(alwaysAddCitedOnPages);
}

public void clearConnectionSettings() {
Expand Down Expand Up @@ -137,4 +139,16 @@ public ObjectProperty<OOStyle> currentStyleProperty() {
public void setCurrentStyle(OOStyle style) {
this.currentStyle.set(style);
}

public boolean getAlwaysAddCitedOnPages() {
return this.alwaysAddCitedOnPages.get();
}

public BooleanProperty alwaysAddCitedOnPagesProperty() {
return this.alwaysAddCitedOnPages;
}

public void setAlwaysAddCitedOnPages(boolean alwaysAddCitedOnPages) {
this.alwaysAddCitedOnPages.set(alwaysAddCitedOnPages);
}
}
6 changes: 5 additions & 1 deletion src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ public class JabRefPreferences implements PreferencesService {
public static final String OO_BIBLIOGRAPHY_STYLE_FILE = "ooBibliographyStyleFile";
public static final String OO_EXTERNAL_STYLE_FILES = "ooExternalStyleFiles";
public static final String OO_CURRENT_STYLE = "ooCurrentStyle";
public static final String OO_ALWAYS_ADD_CITED_ON_PAGES = "ooAlwaysAddCitedOnPages";

// Special field preferences
public static final String SPECIALFIELDSENABLED = "specialFieldsEnabled";
Expand Down Expand Up @@ -756,6 +757,7 @@ private JabRefPreferences() {
}

defaults.put(OO_SYNC_WHEN_CITING, Boolean.TRUE);
defaults.put(OO_ALWAYS_ADD_CITED_ON_PAGES, Boolean.FALSE);
defaults.put(OO_SHOW_PANEL, Boolean.FALSE);
defaults.put(OO_USE_ALL_OPEN_BASES, Boolean.TRUE);
defaults.put(OO_BIBLIOGRAPHY_STYLE_FILE, StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH);
Expand Down Expand Up @@ -1377,10 +1379,12 @@ public OpenOfficePreferences getOpenOfficePreferences() {
getBoolean(OO_SYNC_WHEN_CITING),
getStringList(OO_EXTERNAL_STYLE_FILES),
get(OO_BIBLIOGRAPHY_STYLE_FILE),
currentStyle);
currentStyle,
getBoolean(OO_ALWAYS_ADD_CITED_ON_PAGES));

EasyBind.listen(openOfficePreferences.executablePathProperty(), (obs, oldValue, newValue) -> put(OO_EXECUTABLE_PATH, newValue));
EasyBind.listen(openOfficePreferences.useAllDatabasesProperty(), (obs, oldValue, newValue) -> putBoolean(OO_USE_ALL_OPEN_BASES, newValue));
EasyBind.listen(openOfficePreferences.alwaysAddCitedOnPagesProperty(), (obs, oldValue, newValue) -> putBoolean(OO_ALWAYS_ADD_CITED_ON_PAGES, newValue));
EasyBind.listen(openOfficePreferences.syncWhenCitingProperty(), (obs, oldValue, newValue) -> putBoolean(OO_SYNC_WHEN_CITING, newValue));

openOfficePreferences.getExternalStyles().addListener((InvalidationListener) change ->
Expand Down
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 @@ -1132,6 +1132,7 @@ Unable\ to\ reload\ style\ file=Unable to reload style file

Problem\ during\ separating\ cite\ markers=Problem during separating cite markers

Automatically\ add\ Cited\ on\ pages=Automatically add "Cited on pages..." at beginning of citation
Automatically\ sync\ bibliography\ when\ inserting\ citations=Automatically sync bibliography when inserting citations
Look\ up\ BibTeX\ entries\ in\ the\ active\ tab\ only=Look up BibTeX entries in the active tab only
Look\ up\ BibTeX\ entries\ in\ all\ open\ libraries=Look up BibTeX entries in all open libraries
Expand Down
Loading