2929
3030public class WebSearchPane extends SidePaneComponent {
3131
32- private final JabRefFrame frame ;
3332 private final JabRefPreferences preferences ;
3433 private final WebSearchPaneViewModel viewModel ;
3534
3635 public WebSearchPane (SidePaneManager sidePaneManager , JabRefPreferences preferences , JabRefFrame frame ) {
3736 super (sidePaneManager , IconTheme .JabRefIcons .WWW , Localization .lang ("Web search" ));
38- this .frame = frame ;
3937 this .preferences = preferences ;
40- this .viewModel = new WebSearchPaneViewModel (preferences .getImportFormatPreferences (), frame );
38+ this .viewModel = new WebSearchPaneViewModel (preferences .getImportFormatPreferences (), frame , preferences );
4139 }
4240
4341 @ Override
@@ -52,8 +50,8 @@ protected Node createContentPane() {
5250 new ViewModelListCellFactory <SearchBasedFetcher >()
5351 .withText (SearchBasedFetcher ::getName )
5452 .install (fetchers );
55- viewModel .selectedFetcherProperty ().bind (fetchers .getSelectionModel ().selectedItemProperty ());
5653 fetchers .itemsProperty ().bind (viewModel .fetchersProperty ());
54+ fetchers .valueProperty ().bindBidirectional (viewModel .selectedFetcherProperty ());
5755 fetchers .setMaxWidth (Double .POSITIVE_INFINITY );
5856
5957 // Create help button for currently selected fetcher
@@ -79,17 +77,6 @@ protected Node createContentPane() {
7977 Button search = new Button (Localization .lang ("Search" ));
8078 search .setOnAction (event -> viewModel .search ());
8179
82- // Poor mans binding of default index
83- // (this logic should actually be in the view model but selected item property is readonly)
84- int defaultFetcher = preferences .getInt (JabRefPreferences .SELECTED_FETCHER_INDEX );
85- if (defaultFetcher <= 0 || defaultFetcher >= fetchers .getItems ().size ()) {
86- fetchers .getSelectionModel ().selectFirst ();
87- } else {
88- fetchers .getSelectionModel ().select (defaultFetcher );
89- }
90- EasyBind .subscribe (fetchers .getSelectionModel ().selectedIndexProperty (),
91- newIndex -> preferences .putInt (JabRefPreferences .SELECTED_FETCHER_INDEX , newIndex ));
92-
9380 // Put everything together
9481 VBox container = new VBox ();
9582 container .setAlignment (Pos .CENTER );
0 commit comments