Skip to content

Commit

Permalink
✨ Search with enter in Google Books Import. Closes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
Dansoftowner committed Jul 14, 2021
1 parent 6a102c6 commit 92a60c1
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@
import com.dansoftware.boomega.gui.api.Context;
import com.dansoftware.boomega.gui.control.TextFieldLanguageSelectorControl;
import com.dlsc.formsfx.view.controls.SimpleTextControl;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class LanguageSelectionControl extends SimpleTextControl {
public class LanguageSelectionControl extends OnActionTextControl {

private final Context context;

public LanguageSelectionControl(@NotNull Context context) {
this(context, null);
}

public LanguageSelectionControl(@NotNull Context context, @Nullable EventHandler<ActionEvent> onAction) {
super(onAction);
this.context = context;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Boomega
* Copyright (C) 2021 Daniel Gyoerffy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.dansoftware.boomega.gui.control.formsfx;

import com.dlsc.formsfx.view.controls.SimpleTextControl;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import org.jetbrains.annotations.Nullable;

public class OnActionTextControl extends SimpleTextControl {

private final EventHandler<ActionEvent> onAction;

public OnActionTextControl(@Nullable EventHandler<ActionEvent> onAction) {
this.onAction = onAction;
}

@Override
public void initializeParts() {
super.initializeParts();
editableField.setOnAction(onAction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package com.dansoftware.boomega.gui.google
import com.dansoftware.boomega.gui.api.Context
import com.dansoftware.boomega.gui.control.SearchTextField
import com.dansoftware.boomega.gui.control.formsfx.LanguageSelectionControl
import com.dansoftware.boomega.gui.control.formsfx.OnActionTextControl
import com.dansoftware.boomega.gui.util.onScenePresent
import com.dansoftware.boomega.i18n.I18N
import com.dansoftware.boomega.i18n.i18n
Expand Down Expand Up @@ -106,6 +107,7 @@ class GoogleBooksSearchForm(
generalText.bindBidirectional(textProperty())
textProperty().bindBidirectional(generalText)
promptText = i18n("google.books.add.form.gtext")
setOnAction { search() }
}

private fun buildDetailsSearchArea() =
Expand All @@ -117,28 +119,33 @@ class GoogleBooksSearchForm(
Field.ofStringType(author)
.placeholder("google.books.add.form.author.prompt")
.label("google.books.add.form.author")
.span(ColSpan.HALF),
.span(ColSpan.HALF)
.render(OnActionTextControl { search() }),
Field.ofStringType(title)
.placeholder("google.books.add.form.title.prompt")
.label("google.books.add.form.title")
.span(ColSpan.HALF),
.span(ColSpan.HALF)
.render(OnActionTextControl { search() }),
Field.ofStringType(publisher)
.placeholder("google.books.add.form.publisher.prompt")
.label("google.books.add.form.publisher")
.span(ColSpan.HALF),
.span(ColSpan.HALF)
.render(OnActionTextControl { search() }),
Field.ofStringType(subject)
.placeholder("google.books.add.form.subject.prompt")
.label("google.books.add.form.subject")
.span(ColSpan.HALF),
.span(ColSpan.HALF)
.render(OnActionTextControl { search() }),
Field.ofStringType(isbn)
.placeholder("google.books.add.form.isbn.prompt")
.label("google.books.add.form.isbn")
.span(ColSpan.HALF),
.span(ColSpan.HALF)
.render(OnActionTextControl { search() }),
Field.ofStringType(language)
.styleClass("languageSelector")
.placeholder("google.books.add.form.lang.prompt")
.label("google.books.add.form.lang")
.render(LanguageSelectionControl(context))
.render(LanguageSelectionControl(context) { search() })
.span(ColSpan.HALF),
//TODO: sort type
//TODO: print type
Expand Down

0 comments on commit 92a60c1

Please sign in to comment.