Added a context menu to the message list and ability to copy a message

context menu contains a few menu items that will be populated with
functionality later on.
This commit is contained in:
delvh 2020-06-22 22:51:10 +02:00
parent 9e886c3f45
commit d47a99d637
5 changed files with 49 additions and 7 deletions

View File

@ -1,5 +1,7 @@
package envoy.client.ui.controller; package envoy.client.ui.controller;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -310,4 +312,22 @@ public final class ChatScene {
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
private void scrollToMessageListEnd() { messageList.scrollTo(messageList.getItems().size() - 1); } private void scrollToMessageListEnd() { messageList.scrollTo(messageList.getItems().size() - 1); }
// =========== contextMenu actions ========== //
@FXML
private void copyMessage() {
Toolkit.getDefaultToolkit()
.getSystemClipboard()
.setContents(new StringSelection(messageList.getSelectionModel().getSelectedItem().getText()), null);
}
@FXML
private void deleteMessage() {}
@FXML
private void forwardMessage() {}
@FXML
private void quoteMessage() {}
} }

View File

@ -1,5 +1,15 @@
.button, .list-cell { .button, .list-cell {
-fx-background-radius: 5em; -fx-background-radius: 5.0em;
}
.context-menu, .context-menu > * {
-fx-background-radius: 15px;
/*TODO: solution below does not work */
-fx-background-color: transparent;
}
.menu-item {
-fx-background-radius: 15.0px;
} }
.button:hover { .button:hover {
@ -34,12 +44,12 @@
.received-message { .received-message {
-fx-alignment: center-left; -fx-alignment: center-left;
-fx-background-radius: 4em; -fx-background-radius: 4.0em;
-fx-text-alignment: right; -fx-text-alignment: right;
} }
.own-message { .own-message {
-fx-alignment: center-right; -fx-alignment: center-right;
-fx-background-radius: 4em; -fx-background-radius: 4.0em;
-fx-text-alignment: left; -fx-text-alignment: left;
} }

View File

@ -18,11 +18,11 @@
-fx-background-color: lightgray; -fx-background-color: lightgray;
} }
.list-view, .list-cell, .text-area .content, .text-field, .password-field, .tooltip, .pane, .pane .content, .vbox, .titled-pane > .title, .titled-pane > *.content { .list-view, .list-cell, .text-area .content, .text-field, .password-field, .tooltip, .pane, .pane .content, .vbox, .titled-pane > .title, .titled-pane > *.content, .context-menu, .menu-item {
-fx-background-color: dimgray; -fx-background-color: dimgray;
} }
.list-cell:selected, .list-cell:selected > * { .list-cell:selected, .list-cell:selected > *, .menu-item:hover {
-fx-background-color: darkviolet; -fx-background-color: darkviolet;
} }

View File

@ -11,6 +11,6 @@
-fx-background-color: lightgreen; -fx-background-color: lightgreen;
} }
.own-message { .own-message , .menu-item {
-fx-background-color: lightgray; -fx-background-color: lightgray;
} }

View File

@ -2,8 +2,10 @@
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.ContextMenu?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?> <?import javafx.scene.control.ListView?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TextArea?> <?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.Tooltip?> <?import javafx.scene.control.Tooltip?>
<?import javafx.scene.layout.ColumnConstraints?> <?import javafx.scene.layout.ColumnConstraints?>
@ -50,7 +52,17 @@
</GridPane.margin> </GridPane.margin>
<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" />
</padding></ListView> </padding>
<contextMenu>
<ContextMenu anchorLocation="CONTENT_TOP_LEFT">
<items>
<MenuItem mnemonicParsing="false" text="Copy" onAction="#copyMessage"/>
<MenuItem mnemonicParsing="false" text="Delete" onAction="#deleteMessage"/>
<MenuItem mnemonicParsing="false" text="Forward" onAction="#forwardMessage"/>
<MenuItem mnemonicParsing="false" text="Quote" onAction="#quoteMessage"/>
</items>
</ContextMenu>
</contextMenu></ListView>
<Button fx:id="postButton" defaultButton="true" disable="true" mnemonicParsing="true" onAction="#postMessage" 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="#postMessage" prefHeight="10.0" prefWidth="65.0" text="_Post" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER">
<GridPane.margin> <GridPane.margin>
<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" />