Skip to content

Commit

Permalink
updated jump search to entry field with working control input binding
Browse files Browse the repository at this point in the history
  • Loading branch information
aleeraudales committed Nov 9, 2024
1 parent 43f8781 commit d01dcb8
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 12 deletions.
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)));
}
}
45 changes: 36 additions & 9 deletions src/main/java/org/jabref/gui/edit/JumpSearchAction.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,62 @@
package org.jabref.gui.edit;

import java.util.logging.Logger;
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);


public JumpSearchAction(Supplier<LibraryTab> tabSupplier, StateManager stateManager, DialogService dialogService) {
this.tabSupplier = tabSupplier;
this.dialogService = dialogService;
//this.bibentrytype = bibentrytype;
this.executable.bind(ActionHelper.needsDatabase(stateManager));
}

private static final Logger logger = Logger.getLogger(JumpSearchAction.class.getName());

public static void main(String[] args) {
// Log a simple INFO message
logger.info("Application has started.");

}

@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()));
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/frame/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.jabref.gui.edit.ReplaceStringAction;
import org.jabref.gui.edit.JumpSearchAction;
import org.jabref.gui.edit.automaticfiededitor.AutomaticFieldEditorAction;
import org.jabref.gui.entryeditor.EntryEditor;
import org.jabref.gui.entryeditor.OpenEntryEditorAction;
import org.jabref.gui.entryeditor.PreviewSwitchAction;
import org.jabref.gui.exporter.ExportCommand;
Expand Down Expand Up @@ -81,6 +82,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.os.OS;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.SpecialField;
import org.jabref.model.util.FileUpdateMonitor;
Expand Down Expand Up @@ -206,6 +208,7 @@ private void createMenu() {

factory.createMenuItem(StandardActions.REPLACE_ALL, new ReplaceStringAction(frame::getCurrentLibraryTab, stateManager, dialogService)),
factory.createMenuItem(StandardActions.GENERATE_CITE_KEYS, new GenerateCitationKeyAction(frame::getCurrentLibraryTab, dialogService, stateManager, taskExecutor, preferences, undoManager)),
factory.createMenuItem(StandardActions.JUMP_SEARCH, new JumpSearchAction(frame::getCurrentLibraryTab, stateManager, dialogService)),

new SeparatorMenuItem(),

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/model/entry/BibEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ private Optional<Field> getSourceField(Field targetField, EntryType targetEntry,
*/
public Optional<String> getResolvedFieldOrAlias(Field field, @Nullable BibDatabase database) {
return genericGetResolvedFieldOrAlias(field, database, BibEntry::getFieldOrAlias);
}
} //FIXME

public Optional<String> getResolvedFieldOrAliasLatexFree(Field field, @Nullable BibDatabase database) {
return genericGetResolvedFieldOrAlias(field, database, BibEntry::getFieldOrAliasLatexFree);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/model/entry/BibEntryType.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public boolean isRequired(Field field) {
* If you need all required fields as sole entities use @see{getRequiredFieldsFlat} .
*
* @return a Set of required field name Strings
*/
*/ // FIXME
public SequencedSet<OrFields> getRequiredFields() {
return Collections.unmodifiableSequencedSet(requiredFields);
}
Expand Down

0 comments on commit d01dcb8

Please sign in to comment.