Fixed bug automatically sending a message when ctrl is being pressed
This commit is contained in:
parent
fc4fb4cdae
commit
9a6214eb82
@ -19,9 +19,9 @@ import envoy.client.data.Settings;
|
|||||||
import envoy.client.event.MessageCreationEvent;
|
import envoy.client.event.MessageCreationEvent;
|
||||||
import envoy.client.net.Client;
|
import envoy.client.net.Client;
|
||||||
import envoy.client.net.WriteProxy;
|
import envoy.client.net.WriteProxy;
|
||||||
|
import envoy.client.ui.ContactListCell;
|
||||||
import envoy.client.ui.MessageListCell;
|
import envoy.client.ui.MessageListCell;
|
||||||
import envoy.client.ui.SceneContext;
|
import envoy.client.ui.SceneContext;
|
||||||
import envoy.client.ui.ContactListCell;
|
|
||||||
import envoy.data.Contact;
|
import envoy.data.Contact;
|
||||||
import envoy.data.Message;
|
import envoy.data.Message;
|
||||||
import envoy.data.MessageBuilder;
|
import envoy.data.MessageBuilder;
|
||||||
@ -74,6 +74,11 @@ public final class ChatScene {
|
|||||||
private static final Logger logger = EnvoyLog.getLogger(ChatScene.class);
|
private static final Logger logger = EnvoyLog.getLogger(ChatScene.class);
|
||||||
private static final int MAX_MESSAGE_LENGTH = 255;
|
private static final int MAX_MESSAGE_LENGTH = 255;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the appearance of certain visual components.
|
||||||
|
*
|
||||||
|
* @since Envoy Client v0.1-beta
|
||||||
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
private void initialize() {
|
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 sceneContext the scene context used to load other scenes
|
||||||
* @param localDB the local database form which chats and users are loaded
|
* @param localDB the local database form which chats and users are loaded
|
||||||
* @param client the client used to request ID generators
|
* @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())));
|
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
|
@FXML
|
||||||
private void userListClicked() {
|
private void userListClicked() {
|
||||||
final Contact user = userList.getSelectionModel().getSelectedItem();
|
final Contact user = userList.getSelectionModel().getSelectedItem();
|
||||||
@ -161,32 +173,43 @@ public final class ChatScene {
|
|||||||
messageTextArea.setDisable(currentChat == null);
|
messageTextArea.setDisable(currentChat == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Actions to perform when the Post Button has been clicked.
|
||||||
|
*
|
||||||
|
* @since Envoy Client v0.1-beta
|
||||||
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
private void postButtonClicked() { postMessage(); }
|
private void postButtonClicked() { postMessage(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Actions to perform when the Settings Button has been clicked.
|
||||||
|
*
|
||||||
|
* @since Envoy Client v0.1-beta
|
||||||
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
private void settingsButtonClicked() {
|
private void settingsButtonClicked() {
|
||||||
sceneContext.load(SceneContext.SceneInfo.SETTINGS_SCENE);
|
sceneContext.load(SceneContext.SceneInfo.SETTINGS_SCENE);
|
||||||
sceneContext.<SettingsScene>getController().initializeData(sceneContext);
|
sceneContext.<SettingsScene>getController().initializeData(sceneContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Actions to perform when the "Add Contact" - Button has been clicked.
|
||||||
|
*
|
||||||
|
* @since Envoy Client v0.1-beta
|
||||||
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
private void addContactButtonClicked() {
|
private void addContactButtonClicked() {
|
||||||
sceneContext.load(SceneContext.SceneInfo.CONTACT_SEARCH_SCENE);
|
sceneContext.load(SceneContext.SceneInfo.CONTACT_SEARCH_SCENE);
|
||||||
sceneContext.<ContactSearchScene>getController().initializeData(sceneContext);
|
sceneContext.<ContactSearchScene>getController().initializeData(sceneContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Actions to perform when the text was updated in the messageTextArea.
|
||||||
|
*
|
||||||
|
* @since Envoy Client v0.1-beta
|
||||||
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
private void messageTextUpdated(KeyEvent e) {
|
private void messageTextUpdated() {
|
||||||
// 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);
|
|
||||||
|
|
||||||
// Truncating messages that are too long and staying at the same position
|
// Truncating messages that are too long and staying at the same position
|
||||||
if (messageTextArea.getText().length() >= MAX_MESSAGE_LENGTH) {
|
if (messageTextArea.getText().length() >= MAX_MESSAGE_LENGTH) {
|
||||||
messageTextArea.setText(messageTextArea.getText().substring(0, 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));
|
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
|
* Sends a new message to the server based on the text entered in the
|
||||||
* messageTextArea.
|
* messageTextArea.
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
<Button fx:id="settingsButton" mnemonicParsing="true" onAction="#settingsButtonClicked" text="_Settings" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
|
<Button fx:id="settingsButton" mnemonicParsing="true" onAction="#settingsButtonClicked" text="_Settings" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
|
||||||
<ListView fx:id="messageList" prefHeight="257.0" prefWidth="155.0" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.rowIndex="1" GridPane.rowSpan="2" />
|
<ListView fx:id="messageList" prefHeight="257.0" prefWidth="155.0" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.rowIndex="1" GridPane.rowSpan="2" />
|
||||||
<Button fx:id="postButton" defaultButton="true" disable="true" mnemonicParsing="true" onAction="#postButtonClicked" prefHeight="10.0" prefWidth="65.0" text="_Post" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER" />
|
<Button fx:id="postButton" defaultButton="true" disable="true" mnemonicParsing="true" onAction="#postButtonClicked" prefHeight="10.0" prefWidth="65.0" text="_Post" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER" />
|
||||||
<TextArea fx:id="messageTextArea" disable="true" onInputMethodTextChanged="#messageTextUpdated" onKeyPressed="#messageTextUpdated" onKeyTyped="#messageTextUpdated" prefHeight="200.0" prefWidth="200.0" wrapText="true" GridPane.columnIndex="1" GridPane.rowIndex="3" />
|
<TextArea fx:id="messageTextArea" disable="true" onInputMethodTextChanged="#messageTextUpdated" onKeyPressed="#checkKeyCombination" onKeyTyped="#messageTextUpdated" prefHeight="200.0" prefWidth="200.0" wrapText="true" GridPane.columnIndex="1" GridPane.rowIndex="3" />
|
||||||
<Button mnemonicParsing="true" onAction="#addContactButtonClicked" text="_Add Contacts" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER">
|
<Button mnemonicParsing="true" onAction="#addContactButtonClicked" text="_Add Contacts" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER">
|
||||||
<padding>
|
<padding>
|
||||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||||
|
Reference in New Issue
Block a user