diff --git a/pom.xml b/pom.xml
index 1fb63cb1..ca4915bf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -205,6 +205,11 @@
google-cloud-bigtable-emulator
0.148.0
+
+ com.google.inject
+ guice
+ 5.1.0
+
org.openjfx
javafx-controls
@@ -264,11 +269,6 @@
4.7.0
test
-
- com.google.inject
- guice
- 5.1.0
-
org.controlsfx
controlsfx
diff --git a/src/main/java/com/erikmafo/btviewer/ui/querybox/QueryBoxController.java b/src/main/java/com/erikmafo/btviewer/ui/querybox/QueryBoxController.java
index e3dff1c5..b5d965eb 100644
--- a/src/main/java/com/erikmafo/btviewer/ui/querybox/QueryBoxController.java
+++ b/src/main/java/com/erikmafo/btviewer/ui/querybox/QueryBoxController.java
@@ -8,6 +8,7 @@
import com.erikmafo.btviewer.sql.SqlQuery;
import com.erikmafo.btviewer.ui.timer.TimerView;
import com.erikmafo.btviewer.ui.util.AlertUtil;
+import com.erikmafo.btviewer.ui.util.FontAwesomeUtil;
import com.erikmafo.btviewer.util.StringUtil;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
@@ -18,9 +19,14 @@
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
+import javafx.scene.control.ContextMenu;
+import javafx.scene.control.MenuItem;
import javafx.scene.control.ProgressBar;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
+import javafx.scene.input.MouseButton;
+import javafx.scene.input.MouseEvent;
+import org.controlsfx.glyphfont.FontAwesome;
import org.fxmisc.richtext.CodeArea;
import org.fxmisc.richtext.LineNumberFactory;
import org.jetbrains.annotations.NotNull;
@@ -67,6 +73,7 @@ public QueryBoxController(BigtableQueryService bigtableQueryService) {
public void initialize() {
progressBar.visibleProperty().bind(bigtableQueryService.runningProperty());
progressBar.progressProperty().bind(bigtableQueryService.progressProperty());
+ codeArea.setOnMousePressed(this::onMousePressed);
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));
codeArea.multiPlainChanges()
.successionEnds(Duration.ofMillis(100))
@@ -145,4 +152,48 @@ private BigtableTable createTable() {
}
private void onInstanceChanged() { queryResult.clear(); }
+
+ private void onMousePressed(@NotNull MouseEvent event) {
+ if (event.getButton() == MouseButton.SECONDARY) {
+ codeArea.setContextMenu(getOrCreateContextMenu());
+ } else {
+ codeArea.hideContextMenu();
+ }
+ }
+
+ @NotNull
+ private ContextMenu getOrCreateContextMenu() {
+ ContextMenu contextMenu = codeArea.getContextMenu();
+ if (contextMenu == null) {
+ contextMenu = new ContextMenu();
+ contextMenu.setAutoHide(true);
+ contextMenu.setHideOnEscape(true);
+ contextMenu.getItems().addAll(getCutMenuItem(), getCopyMenuItem(), getPastMenuItem());
+ }
+ return contextMenu;
+ }
+
+ @NotNull
+ private MenuItem getPastMenuItem() {
+ var paste = new MenuItem("Paste");
+ paste.setGraphic(FontAwesomeUtil.create(FontAwesome.Glyph.PASTE));
+ paste.setOnAction(e -> codeArea.paste());
+ return paste;
+ }
+
+ @NotNull
+ private MenuItem getCopyMenuItem() {
+ var copy = new MenuItem("Copy");
+ copy.setGraphic(FontAwesomeUtil.create(FontAwesome.Glyph.COPY));
+ copy.setOnAction(e -> codeArea.copy());
+ return copy;
+ }
+
+ @NotNull
+ private MenuItem getCutMenuItem() {
+ var cut = new MenuItem("Cut");
+ cut.setGraphic(FontAwesomeUtil.create(FontAwesome.Glyph.CUT));
+ cut.setOnAction(e -> codeArea.cut());
+ return cut;
+ }
}
diff --git a/src/main/java/com/erikmafo/btviewer/ui/util/FontAwesomeUtil.java b/src/main/java/com/erikmafo/btviewer/ui/util/FontAwesomeUtil.java
index 88babb71..83d128b5 100644
--- a/src/main/java/com/erikmafo/btviewer/ui/util/FontAwesomeUtil.java
+++ b/src/main/java/com/erikmafo/btviewer/ui/util/FontAwesomeUtil.java
@@ -8,6 +8,8 @@ public class FontAwesomeUtil {
private static final GlyphFont fontAwesome = GlyphFontRegistry.font("FontAwesome");
public static Glyph create(Enum> glyph) {
- return fontAwesome.create(glyph);
+ var glyphNode = fontAwesome.create(glyph);
+ glyphNode.setStyle("-fx-font-family: FontAwesome;");
+ return glyphNode;
}
}
diff --git a/src/main/resources/css/query_box.css b/src/main/resources/css/query_box.css
index 69b11887..f1f91fd9 100644
--- a/src/main/resources/css/query_box.css
+++ b/src/main/resources/css/query_box.css
@@ -1,5 +1,10 @@
@import "main.css";
+.code-area {
+ -fx-font-size: 14;
+ -fx-font-weight: 690;
+}
+
.keyword {
-fx-fill: blue;
-fx-font-weight: bold;
@@ -26,3 +31,7 @@
.paragraph-box:has-caret {
-fx-background-color: #f2f9fc;
}
+
+.controls {
+ -fx-padding: 5;
+}
\ No newline at end of file
diff --git a/src/main/resources/fxml/query_box.fxml b/src/main/resources/fxml/query_box.fxml
index a727b316..9ef4b6a5 100644
--- a/src/main/resources/fxml/query_box.fxml
+++ b/src/main/resources/fxml/query_box.fxml
@@ -7,13 +7,13 @@
-
-
-
+
+
-
+