From c8f446295a50b4677627bb6d4b57903d0a866f71 Mon Sep 17 00:00:00 2001 From: dnutiu Date: Sat, 13 Apr 2024 19:06:09 +0300 Subject: [PATCH] Define ApplicationMenuBar using FXML --- .../ui/controls/ApplicationMenuBar.kt | 36 ++++++++----------- .../ui/controls/application-menu-bar.fxml | 6 ++++ 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ApplicationMenuBar.kt b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ApplicationMenuBar.kt index 460f9ed..b6353bd 100644 --- a/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ApplicationMenuBar.kt +++ b/img-ui/src/main/kotlin/dev/nuculabs/imagetagger/ui/controls/ApplicationMenuBar.kt @@ -3,18 +3,16 @@ package dev.nuculabs.imagetagger.ui.controls import dev.nuculabs.imagetagger.ui.BasicServiceLocator import dev.nuculabs.imagetagger.ui.MainPageController import dev.nuculabs.imagetagger.ui.pages.AboutPage +import javafx.fxml.FXML import javafx.fxml.FXMLLoader import javafx.scene.control.Menu import javafx.scene.control.MenuBar -import javafx.scene.control.MenuItem import java.io.IOException /** * Used as the application menu bar. */ class ApplicationMenuBar : MenuBar() { - private val fileMenu = Menu("File") - private val aboutMenu = Menu("About") private val mainPageController: MainPageController by lazy { BasicServiceLocator.getInstance().mainPageController } @@ -32,29 +30,23 @@ class ApplicationMenuBar : MenuBar() { throw RuntimeException(exception) } - initialize() - } - - private fun initialize() { useSystemMenuBarProperty().set(false) - menus.addAll(fileMenu, aboutMenu) - setupFileMenu() - setupAboutMenu() } - private fun setupAboutMenu() { - val aboutMenuItem = MenuItem("About") - aboutMenuItem.setOnAction { - AboutPage.show() - } - aboutMenu.items.add(aboutMenuItem) + /** + * Calls the tag images functionality from the main controller. + * The controller is retrieved in a lazy-like fashion. + */ + @FXML + private fun fileMenuTagImages() { + mainPageController.onTagImagesButtonClick() } - private fun setupFileMenu() { - val tagImagesMenuItem = MenuItem("Tag Images") - tagImagesMenuItem.setOnAction { - mainPageController.onTagImagesButtonClick() - } - fileMenu.items.add(tagImagesMenuItem) + /** + * Shows the about dialog. + */ + @FXML + private fun aboutMenuShowAbout() { + AboutPage.show() } } \ No newline at end of file diff --git a/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/controls/application-menu-bar.fxml b/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/controls/application-menu-bar.fxml index e8fc2e9..51c1fbb 100644 --- a/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/controls/application-menu-bar.fxml +++ b/img-ui/src/main/resources/dev/nuculabs/imagetagger/ui/controls/application-menu-bar.fxml @@ -2,4 +2,10 @@ + + + + + + \ No newline at end of file