From 9a6214eb82f8ba0217d0654e770dd4b9f3544822 Mon Sep 17 00:00:00 2001 From: delvh Date: Tue, 9 Jun 2020 17:11:17 +0200 Subject: [PATCH] Fixed bug automatically sending a message when ctrl is being pressed --- .../envoy/client/ui/controller/ChatScene.java | 63 +++++++++++++++---- src/main/resources/fxml/ChatScene.fxml | 2 +- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index 4c3fe05..5b4b1a6 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -19,9 +19,9 @@ import envoy.client.data.Settings; import envoy.client.event.MessageCreationEvent; import envoy.client.net.Client; import envoy.client.net.WriteProxy; +import envoy.client.ui.ContactListCell; import envoy.client.ui.MessageListCell; import envoy.client.ui.SceneContext; -import envoy.client.ui.ContactListCell; import envoy.data.Contact; import envoy.data.Message; import envoy.data.MessageBuilder; @@ -74,6 +74,11 @@ public final class ChatScene { private static final Logger logger = EnvoyLog.getLogger(ChatScene.class); private static final int MAX_MESSAGE_LENGTH = 255; + /** + * Initializes the appearance of certain visual components. + * + * @since Envoy Client v0.1-beta + */ @FXML private void initialize() { @@ -121,6 +126,8 @@ public final class ChatScene { } /** + * Initializes all necessary data via dependency injection- + * * @param sceneContext the scene context used to load other scenes * @param localDB the local database form which chats and users are loaded * @param client the client used to request ID generators @@ -137,6 +144,11 @@ public final class ChatScene { userList.setItems(FXCollections.observableList(localDB.getChats().stream().map(Chat::getRecipient).collect(Collectors.toList()))); } + /** + * Actions to perform when the list of contacts has been clicked. + * + * @since Envoy Client v0.1-beta + */ @FXML private void userListClicked() { final Contact user = userList.getSelectionModel().getSelectedItem(); @@ -161,32 +173,43 @@ public final class ChatScene { messageTextArea.setDisable(currentChat == null); } + /** + * Actions to perform when the Post Button has been clicked. + * + * @since Envoy Client v0.1-beta + */ @FXML private void postButtonClicked() { postMessage(); } + /** + * Actions to perform when the Settings Button has been clicked. + * + * @since Envoy Client v0.1-beta + */ @FXML private void settingsButtonClicked() { sceneContext.load(SceneContext.SceneInfo.SETTINGS_SCENE); sceneContext.getController().initializeData(sceneContext); } + /** + * Actions to perform when the "Add Contact" - Button has been clicked. + * + * @since Envoy Client v0.1-beta + */ @FXML private void addContactButtonClicked() { sceneContext.load(SceneContext.SceneInfo.CONTACT_SEARCH_SCENE); sceneContext.getController().initializeData(sceneContext); } + /** + * Actions to perform when the text was updated in the messageTextArea. + * + * @since Envoy Client v0.1-beta + */ @FXML - private void messageTextUpdated(KeyEvent e) { - // TODO: Letting go of ctrl automatically posts a message. Needs to be fixed - // soon. - - // Automatic sending of messages via (ctrl +) enter - if (!postButton.isDisabled() && settings.isEnterToSend() && e.getCode() == KeyCode.ENTER - || !settings.isEnterToSend() && e.getCode() == KeyCode.CONTROL) - postMessage(); - else postButton.setDisable(messageTextArea.getText().isBlank() || currentChat == null); - + private void messageTextUpdated() { // Truncating messages that are too long and staying at the same position if (messageTextArea.getText().length() >= MAX_MESSAGE_LENGTH) { messageTextArea.setText(messageTextArea.getText().substring(0, MAX_MESSAGE_LENGTH)); @@ -201,6 +224,24 @@ public final class ChatScene { remainingChars.setTextFill(Color.rgb(currentLength, remainingLength, 0, 1)); } + /** + * Actions to perform when a key has been entered. + * + * @param e the Keys that have been entered + * @since Envoy Client v0.1-beta + */ + @FXML + private void checkKeyCombination(KeyEvent e) { + // TODO: Letting go of ctrl automatically posts a message. Needs to be fixed + // soon. + + // Automatic sending of messages via (ctrl +) enter + if (!postButton.isDisabled() && settings.isEnterToSend() && e.getCode() == KeyCode.ENTER + || !settings.isEnterToSend() && e.getCode() == KeyCode.ENTER && e.isControlDown()) + postMessage(); + postButton.setDisable(messageTextArea.getText().isBlank() || currentChat == null); + } + /** * Sends a new message to the server based on the text entered in the * messageTextArea. diff --git a/src/main/resources/fxml/ChatScene.fxml b/src/main/resources/fxml/ChatScene.fxml index a81cd00..c134894 100644 --- a/src/main/resources/fxml/ChatScene.fxml +++ b/src/main/resources/fxml/ChatScene.fxml @@ -27,7 +27,7 @@