diff --git a/core/src/main/java/dk/gtz/graphedit/view/DraggableTabController.java b/core/src/main/java/dk/gtz/graphedit/view/DraggableTabController.java index e21eca82..4b9df07f 100644 --- a/core/src/main/java/dk/gtz/graphedit/view/DraggableTabController.java +++ b/core/src/main/java/dk/gtz/graphedit/view/DraggableTabController.java @@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory; import atlantafx.base.theme.Styles; +import dk.yalibs.yadi.DI; import javafx.collections.ListChangeListener; import javafx.geometry.Point2D; import javafx.geometry.Pos; @@ -14,8 +15,12 @@ import javafx.scene.Scene; import javafx.scene.control.Control; import javafx.scene.control.Label; +import javafx.scene.control.MenuBar; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; +import javafx.scene.input.KeyEvent; +import javafx.scene.input.MouseEvent; +import javafx.scene.layout.BorderPane; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; @@ -59,7 +64,7 @@ private record InsertData(int index, TabPane insertPane) {} * normal tabs and DrragableTabs mixed will cause issues! * @param text the text to appear on the tag label. */ - public DraggableTabController(String text) { + public DraggableTabController(String text, ModelEditorController editor) { nameLabel = new Label(text); setGraphic(nameLabel); detachable = true; @@ -123,6 +128,7 @@ public DraggableTabController(String text) { if(!detachable) return; var newStage = new Stage(); + var topPane = new BorderPane(); var pane = new TabPane(); pane.getStyleClass().add(TabPane.STYLE_CLASS_FLOATING); tabPanes.add(pane); @@ -133,8 +139,13 @@ public DraggableTabController(String text) { if(pane.getTabs().isEmpty()) newStage.hide(); }); - var spawnScene = new Scene(pane); + topPane.setCenter(pane); + topPane.setTop(DI.get(MenuBar.class)); + var spawnScene = new Scene(topPane); spawnScene.getStylesheets().add(getClass().getResource("/css/styles.css").toExternalForm()); + spawnScene.addEventHandler(KeyEvent.ANY, e -> editor.onKeyEvent(e)); + spawnScene.addEventHandler(MouseEvent.ANY, e -> editor.onMouseEvent(e)); + // TODO: add closed event, and actually close the buffer newStage.setScene(spawnScene); newStage.initStyle(StageStyle.UTILITY); newStage.setX(t.getScreenX()); diff --git a/core/src/main/java/dk/gtz/graphedit/view/EditorController.java b/core/src/main/java/dk/gtz/graphedit/view/EditorController.java index d70ad791..8d88899c 100644 --- a/core/src/main/java/dk/gtz/graphedit/view/EditorController.java +++ b/core/src/main/java/dk/gtz/graphedit/view/EditorController.java @@ -20,8 +20,10 @@ import javafx.application.Platform; import javafx.fxml.FXML; import javafx.scene.control.Menu; +import javafx.scene.control.MenuBar; import javafx.scene.control.MenuItem; import javafx.scene.control.RadioMenuItem; +import javafx.scene.control.SeparatorMenuItem; import javafx.scene.control.ToggleGroup; import javafx.scene.layout.BorderPane; import javafx.scene.layout.Region; @@ -43,6 +45,8 @@ public class EditorController { @FXML private BorderPane bottomBorderPane; @FXML + private MenuBar menubar; + @FXML private Menu runTargetsMenu; @FXML private Menu importFileMenu; @@ -80,6 +84,25 @@ private void initProjectMenu() { var project = DI.get(ViewModelProject.class); updateRunTargets(); project.runTargets().addListener((e,o,n) -> updateRunTargets()); + DI.add(MenuBar.class, () -> { + var newMenubar = new MenuBar(); + newMenubar.setUseSystemMenuBar(menubar.isUseSystemMenuBar()); + for(var menu : menubar.getMenus()) { + var newMenu = new Menu(menu.getText()); + for(var item : menu.getItems()) { + if(item instanceof MenuItem) { + var newItem = new MenuItem(item.getText()); + newItem.setOnAction(item.getOnAction()); + newItem.setAccelerator(item.getAccelerator()); + newMenu.getItems().add(newItem); + } + if(item instanceof SeparatorMenuItem) + newMenu.getItems().add(new SeparatorMenuItem()); + } + newMenubar.getMenus().add(newMenu); + } + return newMenubar; + }); } private void updateRunTargets() { diff --git a/core/src/main/java/dk/gtz/graphedit/view/EditorTabPaneController.java b/core/src/main/java/dk/gtz/graphedit/view/EditorTabPaneController.java index e4944df0..cf5eaa5d 100644 --- a/core/src/main/java/dk/gtz/graphedit/view/EditorTabPaneController.java +++ b/core/src/main/java/dk/gtz/graphedit/view/EditorTabPaneController.java @@ -63,7 +63,8 @@ private void initTabpaneBufferContainer() { var tabTitle = changedKey; if(changedVal.metadata().containsKey("name")) tabTitle = changedVal.metadata().get("name"); - var tab = new DraggableTabController(tabTitle); + var editorController = new ModelEditorController(changedKey, changedVal, MetadataUtils.getSyntaxFactory(changedVal.metadata())); + var tab = new DraggableTabController(tabTitle, editorController); var lastSavedModel = new SimpleObjectProperty<>(changedVal.toModel()); var lastSavedModelSyntax = new SimpleObjectProperty<>(MetadataUtils.getSyntaxFactory(changedVal.getSyntaxName().get())); changedVal.addView(tab); @@ -89,7 +90,6 @@ private void initTabpaneBufferContainer() { if(changedVal.getViews().isEmpty()) DI.get(IBufferContainer.class).close(changedKey); }); - var editorController = new ModelEditorController(changedKey, changedVal, MetadataUtils.getSyntaxFactory(changedVal.metadata())); tab.addEditor(editorController); tabpane.getTabs().add(tab); tabControllerMapping.put(tab, editorController); diff --git a/core/src/main/java/dk/gtz/graphedit/view/ModelEditorController.java b/core/src/main/java/dk/gtz/graphedit/view/ModelEditorController.java index 81f3fa67..327f8184 100644 --- a/core/src/main/java/dk/gtz/graphedit/view/ModelEditorController.java +++ b/core/src/main/java/dk/gtz/graphedit/view/ModelEditorController.java @@ -217,7 +217,7 @@ public void onMouseEvent(MouseEvent e) { * Propogate the provided key event to the appropriate tool. * @param e The key event to handle. */ - public void onKeyEvent(KeyEvent e) { + public void onKeyEvent(KeyEvent e) { // TODO: onKeyEvent and the rest of the family should be an interface // TODO: the "isTargetDrawpane" field solution is hacky and doesnt work in detached tabs. It should be fixed, see https://github.com/sillydan1/graphedit/issues/17 var isTargetDrawpane = e.getTarget() == getParent().getParent(); var keyEvent = new ViewportKeyEvent(e, drawGroupTransform, isTargetDrawpane, syntaxFactory, resource.syntax(), bufferKey, settings); diff --git a/core/src/main/resources/dk/gtz/graphedit/view/Editor.fxml b/core/src/main/resources/dk/gtz/graphedit/view/Editor.fxml index 00eb6f74..5f7364f0 100644 --- a/core/src/main/resources/dk/gtz/graphedit/view/Editor.fxml +++ b/core/src/main/resources/dk/gtz/graphedit/view/Editor.fxml @@ -10,7 +10,7 @@ - +