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

Fix for issue 296 #12293

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,458 changes: 11 additions & 1,447 deletions CHANGELOG.md

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# JabRef Bibliography Management
# JabRef Fork - Issue #296 - Adding Ctrl+J to jump to a field

JabRef is an open-source, cross-platform citation and reference management tool.
JabRef is an open-source, cross-platform citation and reference management tool. For more info on JabRef, click [here](https://github.com/JabRef/jabref?tab=readme-ov-file#readme). In this repository, we aim to tackle [Issue #296](https://github.com/orgs/JabRef/projects/5/views/1?pane=issue&itemId=14151869&issue=koppor%7Cjabref%7C296) to add a function to give users easier access for navigating fields.

### Proposed Steps

- keyboard input Ctrl+J
- type a file name
- Then one can select the field using the cursor keys and ENTER
- Then, it jumps to the right field editor in the entry editor

### History
Issue #296 was first posted by [koppor](https://github.com/koppor) on January 30, 2018. It is now assigned to Jude Surin, Project Manager of Team 4-B.

### Commits
No commitments to date


### For more information on JabRef, please read below:

Stay on top of your literature: JabRef helps you to collect and organize sources, find the paper you need and discover the latest research.

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private static void addModeInfo(StringBuilder text, BibDatabaseContext bibDataba
String mode = bibDatabaseContext.getMode().getFormattedName();
String modeInfo = "\n%s".formatted(Localization.lang("%0 mode", mode));
text.append(modeInfo);
}
} // FIXME

private static void addSharedDbInformation(StringBuilder text, BibDatabaseContext bibDatabaseContext) {
text.append(bibDatabaseContext.getDBMSSynchronizer().getDBName());
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/org/jabref/gui/StateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import com.tobiasdiez.easybind.EasyBinding;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.jabref.model.entry.field.Field;
import javafx.scene.control.TextInputDialog;

/**
* This class manages the GUI-state of JabRef, including:
Expand Down Expand Up @@ -78,6 +80,8 @@ public class StateManager {
private final ObjectProperty<LastAutomaticFieldEditorEdit> lastAutomaticFieldEditorEdit = new SimpleObjectProperty<>();
private final ObservableList<String> searchHistory = FXCollections.observableArrayList();
private final List<AiChatWindow> aiChatWindows = new ArrayList<>();
private final OptionalObjectProperty<String> searchFieldName = OptionalObjectProperty.empty();
private final OptionalObjectProperty<BibEntry> selectedEntryForJump = OptionalObjectProperty.empty();

public ObservableList<SidePaneType> getVisibleSidePaneComponents() {
return visibleSidePanes;
Expand Down Expand Up @@ -231,4 +235,39 @@ public void clearSearchHistory() {
public List<AiChatWindow> getAiChatWindows() {
return aiChatWindows;
}




//methods
public OptionalObjectProperty<String> searchFieldNameProperty() {
return searchFieldName;
}

// public OptionalObjectProperty<BibEntry> selectedEntryForJumpProperty() {
// case CTRL_J:
// showFieldNameDialog();
// event.consume();
// break;
// return selectedEntryForJump;
// }

private void showFieldNameDialog() {
TextInputDialog dialog = new TextInputDialog();
dialog.setTitle("Search by File Name");
dialog.setHeaderText("Enter the field name to search for:");
dialog.setContentText("Field name:");

Optional<String> result = dialog.showAndWait();
// result.ifPresent(fieldName -> searchEntryByFieldName(fieldName));

}

public void searchEntryByFieldName(Field fieldName) {
searchFieldName.set(Optional.of(String.valueOf(fieldName)));
getSelectedEntries().stream()
.filter(entry -> entry.hasField(fieldName))
.findFirst()
.ifPresent(entry -> selectedEntryForJump.set(Optional.of(entry)));
}
}
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/actions/StandardActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public enum StandardActions implements Action {
UNDO(Localization.lang("Undo"), IconTheme.JabRefIcons.UNDO, KeyBinding.UNDO),
REDO(Localization.lang("Redo"), IconTheme.JabRefIcons.REDO, KeyBinding.REDO),
REPLACE_ALL(Localization.lang("Find and replace"), KeyBinding.REPLACE_STRING),
JUMP_SEARCH(Localization.lang("Search for entry field"), KeyBinding.JUMP_SEARCH),
MANAGE_KEYWORDS(Localization.lang("Manage keywords")),
MASS_SET_FIELDS(Localization.lang("Manage field names & content")),

Expand Down
66 changes: 66 additions & 0 deletions src/main/java/org/jabref/gui/edit/JumpSearch.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.ButtonType?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.DialogPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<DialogPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8"
fx:controller="org.jabref.gui.edit.JumpSearchView">
<content>
<BorderPane>
<center>
<BorderPane BorderPane.alignment="CENTER">
<center>
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<Label text="%Find and Replace"/>
<Label text="%Find:" GridPane.columnIndex="0" GridPane.rowIndex="1"/>
<TextField fx:id="findField" GridPane.columnIndex="1" GridPane.rowIndex="1"
GridPane.columnSpan="4"/>
<Label text="%Replace With:" wrapText="true" GridPane.columnIndex="0" GridPane.rowIndex="2"/>
<TextField fx:id="replaceField" GridPane.columnIndex="1" GridPane.rowIndex="2"
GridPane.columnSpan="4"/>
<CheckBox fx:id="selectFieldOnly" GridPane.columnIndex="0" GridPane.rowIndex="4" GridPane.columnSpan="2"
text="%Limit to Selected Entries"/>
<RadioButton fx:id="allReplace" GridPane.columnIndex="0" GridPane.rowIndex="5" GridPane.columnSpan="2"
selected="true" text="%All Field Replace">
<toggleGroup>
<ToggleGroup fx:id="radioGroup"/>
</toggleGroup>
</RadioButton>
<RadioButton GridPane.columnIndex="0" GridPane.rowIndex="6" GridPane.columnSpan="2"
text="%Limit to Fields" toggleGroup="$radioGroup"/>
<TextField fx:id="limitFieldInput" GridPane.columnIndex="2" GridPane.rowIndex="6"
GridPane.columnSpan="3"/>
</GridPane>
</center>
</BorderPane>
</center>
</BorderPane>
</content>
<ButtonType fx:id="replaceButton" text="%Replace" buttonData="OK_DONE"/>
<ButtonType fx:constant="CANCEL"/>
</DialogPane>
62 changes: 62 additions & 0 deletions src/main/java/org/jabref/gui/edit/JumpSearchAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.jabref.gui.edit;

import java.util.Collection;
import java.util.Optional;
import java.util.logging.Level;
import java.util.function.Supplier;

import javafx.scene.control.TextInputDialog;
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;
import org.jabref.gui.entryeditor.EntryEditor;

import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryType;
//import org.jabref.gui.autocompleter.AutoCompleter;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.gui.preferences.PreferencesService;

public class JumpSearchAction extends SimpleCommand {
//private final EntryEditor entryEditor;
//private final AutoCompleter<String> autoCompleter;

private final Supplier<LibraryTab> tabSupplier;
private final DialogService dialogService;
//private final Collection<BibEntryTypesManager> bibentrytype;

public JumpSearchAction( Supplier<LibraryTab> tabSupplier, StateManager stateManager, DialogService dialogService) {
//this.entryEditor = entryEditor;
//this.autoCompleter = new AutoCompleter<>(entryEditor.getAvailableFieldNames(), preferencesService);


this.tabSupplier = tabSupplier;
this.dialogService = dialogService;
//this.bibentrytype = bibentrytype;
this.executable.bind(ActionHelper.needsDatabase(stateManager));
}


@Override
public void execute() {
TextInputDialog dialog = new TextInputDialog();
dialog.setTitle("Jump to Field");
dialog.setHeaderText("Type a field name:");
// dialog.initOwner(new Stage());

//autoCompleter.bindTo(dialog.getEditor());


Optional<String> result = dialog.showAndWait();

// result.ifPresent(fieldName -> {
// if (!entryEditor.focusField(fieldName)) {
// entryEditor.showErrorMessage("Field not found: " + fieldName);
// }
// });

dialogService.showCustomDialogAndWait(new JumpSearchView(tabSupplier.get()));
}
}
64 changes: 64 additions & 0 deletions src/main/java/org/jabref/gui/edit/JumpSearchView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.jabref.gui.edit;

import javafx.fxml.FXML;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;

import org.jabref.gui.LibraryTab;
import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.ControlHelper;
import org.jabref.gui.util.IconValidationDecorator;
import org.jabref.logic.l10n.Localization;

import com.airhacks.afterburner.views.ViewLoader;
import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer;

public class JumpSearchView extends BaseDialog<Void> {
@FXML private RadioButton allReplace;
@FXML private CheckBox selectFieldOnly;
@FXML private ButtonType replaceButton;
@FXML private TextField limitFieldInput;
@FXML private TextField findField;
@FXML private TextField replaceField;

private JumpSearchViewModel viewModel;

private final ControlsFxVisualizer visualizer = new ControlsFxVisualizer();

public JumpSearchView(LibraryTab libraryTab) {
this.setTitle(Localization.lang("Search for entry field"));

viewModel = new JumpSearchViewModel(libraryTab);

ViewLoader.view(this)
.load()
.setAsDialogPane(this);

ControlHelper.setAction(replaceButton, getDialogPane(), event -> buttonReplace());
}

@FXML
public void initialize() {
visualizer.setDecoration(new IconValidationDecorator());

viewModel.findStringProperty().bind(findField.textProperty());
viewModel.replaceStringProperty().bind(replaceField.textProperty());
viewModel.fieldStringProperty().bind(limitFieldInput.textProperty());
viewModel.selectOnlyProperty().bind(selectFieldOnly.selectedProperty());
viewModel.allFieldReplaceProperty().bind(allReplace.selectedProperty());
}

@FXML
private void buttonReplace() {
String findString = findField.getText();
if ("".equals(findString)) {
this.close();
return;
}
viewModel.replace();
this.close();
}
}

Loading