feat: improve username dialog text handling
This commit is contained in:
parent
3ed38442dc
commit
8d45d4c7e2
2 changed files with 13 additions and 8 deletions
|
@ -77,12 +77,8 @@ public class ChatFooterController implements Initializable {
|
||||||
textField.setOnKeyPressed(event -> {
|
textField.setOnKeyPressed(event -> {
|
||||||
if (event.getCode() == KeyCode.ENTER) {
|
if (event.getCode() == KeyCode.ENTER) {
|
||||||
event.consume();
|
event.consume();
|
||||||
if (event.isShiftDown()) {
|
if(!textField.getText().isEmpty()){
|
||||||
textField.appendText(System.getProperty("line.separator"));
|
onSend();
|
||||||
} else {
|
|
||||||
if(!textField.getText().isEmpty()){
|
|
||||||
onSend();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,6 +10,7 @@ import javafx.beans.value.ObservableValue;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
@ -74,6 +75,7 @@ public class EditUsernameDialogController implements Initializable {
|
||||||
setLocked(false);
|
setLocked(false);
|
||||||
setFieldError(State.VALID);
|
setFieldError(State.VALID);
|
||||||
setMode(mode);
|
setMode(mode);
|
||||||
|
textField.setText("");
|
||||||
dialog.show(root);
|
dialog.show(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +87,7 @@ public class EditUsernameDialogController implements Initializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setLocked(boolean state) {
|
private void setLocked(boolean state) {
|
||||||
confirmButton.setDisable(state);
|
confirmButton.setDisable(state || textField.getText().isEmpty());
|
||||||
cancelButton.setDisable(state);
|
cancelButton.setDisable(state);
|
||||||
dialog.setOverlayClose(!state);
|
dialog.setOverlayClose(!state);
|
||||||
textField.setDisable(state);
|
textField.setDisable(state);
|
||||||
|
@ -129,9 +131,16 @@ public class EditUsernameDialogController implements Initializable {
|
||||||
validator = new Validator();
|
validator = new Validator();
|
||||||
currentState = State.VALID;
|
currentState = State.VALID;
|
||||||
setMode(Mode.INITIAL);
|
setMode(Mode.INITIAL);
|
||||||
confirmButton.setDisable(true);
|
|
||||||
textField.textProperty().addListener(this::onUsernameChange);
|
textField.textProperty().addListener(this::onUsernameChange);
|
||||||
textField.getValidators().add(validator);
|
textField.getValidators().add(validator);
|
||||||
|
textField.setOnKeyPressed(event -> {
|
||||||
|
if (event.getCode() == KeyCode.ENTER) {
|
||||||
|
event.consume();
|
||||||
|
if(!textField.getText().isEmpty()){
|
||||||
|
onConfirm();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onSuccess() {
|
private void onSuccess() {
|
||||||
|
|
Loading…
Reference in a new issue