From 3784db6b4594c3373e02937398dbad10d0fe052d Mon Sep 17 00:00:00 2001 From: Rex Chan Date: Fri, 9 Mar 2018 12:37:53 -0800 Subject: [PATCH] Added Context Menu to default editor --- .../FileClasses/Helper/DataCell.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/StellarisDK/FileClasses/Helper/DataCell.java b/src/StellarisDK/FileClasses/Helper/DataCell.java index 51d0c2c..195dd84 100644 --- a/src/StellarisDK/FileClasses/Helper/DataCell.java +++ b/src/StellarisDK/FileClasses/Helper/DataCell.java @@ -2,10 +2,7 @@ import com.sun.javafx.scene.control.skin.LabeledText; import javafx.scene.Node; -import javafx.scene.control.ContextMenu; -import javafx.scene.control.TextField; -import javafx.scene.control.TreeCell; -import javafx.scene.control.TreeItem; +import javafx.scene.control.*; import javafx.scene.input.ClipboardContent; import javafx.scene.input.Dragboard; import javafx.scene.input.KeyCode; @@ -88,6 +85,8 @@ public DataCell() { System.out.println(getItem()); } }); + + setCM(); } @Override @@ -155,8 +154,20 @@ protected void updateItem(T item, boolean empty) { private void setCM() { ContextMenu contextMenu = new ContextMenu(); + MenuItem createNew = new MenuItem("New.."); + createNew.setOnAction(event -> { + getTreeItem().getChildren().add(new TreeItem("Click to Edit..")); + }); + MenuItem edit = new MenuItem("Rename"); + edit.setOnAction(event -> startEdit()); + MenuItem delete = new MenuItem("Delete"); + delete.setOnAction(event -> { + if(getTreeItem().getParent() != null) + getTreeItem().getParent().getChildren().remove(getTreeItem()); + }); + contextMenu.getItems().addAll(createNew, edit, delete); setContextMenu(contextMenu); } } \ No newline at end of file