From d47a99d637e7776a1fe09abd91515b4bcb9585e7 Mon Sep 17 00:00:00 2001 From: delvh Date: Mon, 22 Jun 2020 22:51:10 +0200 Subject: [PATCH] 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. --- .../envoy/client/ui/controller/ChatScene.java | 20 +++++++++++++++++++ src/main/resources/css/base.css | 16 ++++++++++++--- src/main/resources/css/dark.css | 4 ++-- src/main/resources/css/light.css | 2 +- src/main/resources/fxml/ChatScene.fxml | 14 ++++++++++++- 5 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index 992895c..31c2431 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -1,5 +1,7 @@ package envoy.client.ui.controller; +import java.awt.Toolkit; +import java.awt.datatransfer.StringSelection; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; @@ -310,4 +312,22 @@ public final class ChatScene { * @since Envoy Client v0.1-beta */ 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() {} } diff --git a/src/main/resources/css/base.css b/src/main/resources/css/base.css index ff81b44..35094f4 100644 --- a/src/main/resources/css/base.css +++ b/src/main/resources/css/base.css @@ -1,5 +1,15 @@ .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 { @@ -34,12 +44,12 @@ .received-message { -fx-alignment: center-left; - -fx-background-radius: 4em; + -fx-background-radius: 4.0em; -fx-text-alignment: right; } .own-message { -fx-alignment: center-right; - -fx-background-radius: 4em; + -fx-background-radius: 4.0em; -fx-text-alignment: left; } diff --git a/src/main/resources/css/dark.css b/src/main/resources/css/dark.css index becc265..75e3bc0 100644 --- a/src/main/resources/css/dark.css +++ b/src/main/resources/css/dark.css @@ -18,11 +18,11 @@ -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; } -.list-cell:selected, .list-cell:selected > * { +.list-cell:selected, .list-cell:selected > *, .menu-item:hover { -fx-background-color: darkviolet; } diff --git a/src/main/resources/css/light.css b/src/main/resources/css/light.css index 3362540..96942fd 100644 --- a/src/main/resources/css/light.css +++ b/src/main/resources/css/light.css @@ -11,6 +11,6 @@ -fx-background-color: lightgreen; } -.own-message { +.own-message , .menu-item { -fx-background-color: lightgray; } diff --git a/src/main/resources/fxml/ChatScene.fxml b/src/main/resources/fxml/ChatScene.fxml index 9d95fba..4d7d4f6 100644 --- a/src/main/resources/fxml/ChatScene.fxml +++ b/src/main/resources/fxml/ChatScene.fxml @@ -2,8 +2,10 @@ + + @@ -50,7 +52,17 @@ - + + + + + + + + + + +