From 6f2a65549752459b9438e682657448bc9443c94e Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Sat, 7 Feb 2026 12:59:44 -0500 Subject: [PATCH] Clean up context menus. --- build.rs | 2 + qml/ClideMenuBar.qml | 176 ++++++++++++------------------- qml/ClideProjectView.qml | 14 +-- qml/ClideTreeView.qml | 28 ++--- qml/Components/ClideMenu.qml | 13 +++ qml/Components/ClideMenuItem.qml | 18 ++++ qml/Components/qmldir | 2 + 7 files changed, 128 insertions(+), 125 deletions(-) create mode 100644 qml/Components/ClideMenu.qml create mode 100644 qml/Components/ClideMenuItem.qml diff --git a/build.rs b/build.rs index 8c91aa8..1eeab13 100644 --- a/build.rs +++ b/build.rs @@ -12,6 +12,8 @@ fn main() { "qml/ClideLogger.qml", "qml/Components/ClideScrollBar.qml", "qml/Components/ClideHandle.qml", + "qml/Components/ClideMenu.qml", + "qml/Components/ClideMenuItem.qml", "qml/Logger/Logger.qml", ])) // Link Qt's Network library diff --git a/qml/ClideMenuBar.qml b/qml/ClideMenuBar.qml index 9300f67..cfd9518 100644 --- a/qml/ClideMenuBar.qml +++ b/qml/ClideMenuBar.qml @@ -15,122 +15,111 @@ MenuBar { // // File Menu - Action { - id: actionNewProject - - text: qsTr("&New Project...") - } - Action { - id: actionOpen - - text: qsTr("&Open...") - } - Action { - id: actionSave - - text: qsTr("&Save") - } - Action { - id: actionExit - - text: qsTr("&Exit") - - onTriggered: Qt.quit() - } ClideMenu { title: qsTr("&File") ClideMenuItem { - action: actionNewProject + action: Action { + id: actionNewProject + + text: qsTr("&New Project...") + } } ClideMenuItem { - action: actionOpen + action: Action { + id: actionOpen + + text: qsTr("&Open...") + } onTriggered: FileSystem.setDirectory(FileSystem.filePath) } ClideMenuItem { - action: actionSave + action: Action { + id: actionSave + + text: qsTr("&Save") + } } MenuSeparator { background: Rectangle { border.color: color - color: RustColors.explorer_background + color: Qt.darker(RustColors.menubar, 1) implicitHeight: 3 implicitWidth: 200 } } ClideMenuItem { - action: actionExit + action: Action { + id: actionExit + + text: qsTr("&Exit") + + onTriggered: Qt.quit() + } } } // // Edit Menu - Action { - id: actionUndo - - text: qsTr("&Undo") - } - Action { - id: actionRedo - - text: qsTr("&Redo") - } - Action { - id: actionCut - - text: qsTr("&Cut") - } - Action { - id: actionCopy - - text: qsTr("&Copy") - } - Action { - id: actionPaste - - text: qsTr("&Paste") - } ClideMenu { title: qsTr("&Edit") ClideMenuItem { - action: actionUndo + action: Action { + id: actionUndo + + text: qsTr("&Undo") + } } ClideMenuItem { - action: actionRedo + action: Action { + id: actionRedo + + text: qsTr("&Redo") + } } ClideMenuItem { - action: actionCut + action: Action { + id: actionCut + + text: qsTr("&Cut") + } } ClideMenuItem { - action: actionCopy + action: Action { + id: actionCopy + + text: qsTr("&Copy") + } } ClideMenuItem { - action: actionPaste + action: Action { + id: actionPaste + + text: qsTr("&Paste") + } } } // // View Menu - Action { - id: actionToolWindows - - text: qsTr("&Tool Windows") - } - Action { - id: actionAppearance - - text: qsTr("&Appearance") - } ClideMenu { title: qsTr("&View") ClideMenuItem { - action: actionToolWindows + action: Action { + id: actionAppearance + + text: qsTr("&Appearance") + } } ClideMenuItem { - action: actionAppearance + action: Action { + id: actionToolWindows + + text: qsTr("&Tool Windows") + } } } @@ -140,52 +129,25 @@ MenuBar { id: clideAbout } - Action { - id: actionDocumentation - - text: qsTr("&Documentation") - } - Action { - id: actionAbout - - text: qsTr("&About") - - // Toggle the about window with the menu item is clicked. - onTriggered: clideAbout.visible = !clideAbout.visible - } ClideMenu { title: qsTr("&Help") ClideMenuItem { - action: actionDocumentation + action: Action { + id: actionDocumentation + + text: qsTr("&Documentation") + } } ClideMenuItem { - action: actionAbout - } - } + action: Action { + id: actionAbout - // Base settings for each Menu. - component ClideMenu: Menu { - background: Rectangle { - color: RustColors.explorer_background - border.color: Qt.darker(RustColors.menubar, 2) - implicitWidth: 100 - radius: 2 - } - } + text: qsTr("&About") - // Base settings for each MenuItem. - component ClideMenuItem: MenuItem { - id: root - - background: Rectangle { - color: root.hovered ? RustColors.hovered : RustColors.unhovered - radius: 1.0 - } - contentItem: IconLabel { - color: "black" - font.family: "Helvetica" - text: root.text + // Toggle the about window with the menu item is clicked. + onTriggered: clideAbout.visible = !clideAbout.visible + } } } } diff --git a/qml/ClideProjectView.qml b/qml/ClideProjectView.qml index 02066bb..0129d9a 100644 --- a/qml/ClideProjectView.qml +++ b/qml/ClideProjectView.qml @@ -69,15 +69,17 @@ SplitView { onSingleTapped: (eventPoint, button) => contextMenu.popup() } - Menu { + ClideMenu { id: contextMenu - Action { - text: qsTr("Reset root index") + ClideMenuItem { + action: Action { + text: qsTr("Reset root") - onTriggered: { - Logger.log("Resetting root directory: " + clideTreeView.originalRootDirectory); - clideTreeView.rootDirectory = clideTreeView.originalRootDirectory; + onTriggered: { + Logger.log("Resetting root directory: " + clideTreeView.originalRootDirectory); + clideTreeView.rootDirectory = clideTreeView.originalRootDirectory; + } } } } diff --git a/qml/ClideTreeView.qml b/qml/ClideTreeView.qml index 5ee67ef..6a7e6de 100644 --- a/qml/ClideTreeView.qml +++ b/qml/ClideTreeView.qml @@ -142,24 +142,28 @@ TreeView { } } } - Menu { + ClideMenu { id: contextMenu - Action { - enabled: treeDelegate.hasChildren - text: qsTr("Set as root index") + ClideMenuItem { + action: Action { + enabled: treeDelegate.hasChildren + text: qsTr("Set root") - onTriggered: { - Logger.debug("Setting new root directory: " + treeDelegate.filePath); - fileSystemTreeView.rootDirectory = treeDelegate.filePath; + onTriggered: { + Logger.debug("Setting new root directory: " + treeDelegate.filePath); + fileSystemTreeView.rootDirectory = treeDelegate.filePath; + } } } - Action { - text: qsTr("Reset root index") + ClideMenuItem { + action: Action { + text: qsTr("Reset root") - onTriggered: { - Logger.log("Resetting root directory: " + fileSystemTreeView.originalRootDirectory); - fileSystemTreeView.rootDirectory = fileSystemTreeView.originalRootDirectory; + onTriggered: { + Logger.log("Resetting root directory: " + fileSystemTreeView.originalRootDirectory); + fileSystemTreeView.rootDirectory = fileSystemTreeView.originalRootDirectory; + } } } } diff --git a/qml/Components/ClideMenu.qml b/qml/Components/ClideMenu.qml new file mode 100644 index 0000000..cc297a2 --- /dev/null +++ b/qml/Components/ClideMenu.qml @@ -0,0 +1,13 @@ +import QtQuick +import QtQuick.Controls.Basic + +import clide.module 1.0 + +Menu { + background: Rectangle { + border.color: Qt.darker(RustColors.menubar, 2) + color: RustColors.menubar + implicitWidth: 100 + radius: 2 + } +} diff --git a/qml/Components/ClideMenuItem.qml b/qml/Components/ClideMenuItem.qml new file mode 100644 index 0000000..4b859be --- /dev/null +++ b/qml/Components/ClideMenuItem.qml @@ -0,0 +1,18 @@ +import QtQuick +import QtQuick.Controls.Basic + +import clide.module 1.0 + +MenuItem { + id: root + + background: Rectangle { + color: root.hovered ? RustColors.hovered : RustColors.unhovered + radius: 1.0 + } + contentItem: IconLabel { + color: "black" + font.family: "Helvetica" + text: root.text + } +} diff --git a/qml/Components/qmldir b/qml/Components/qmldir index 7ff58ef..5a7b322 100644 --- a/qml/Components/qmldir +++ b/qml/Components/qmldir @@ -1,2 +1,4 @@ ClideScrollBar ClideScrollBar.qml ClideHandle ClideHandle.qml +ClideMenu ClideMenu.qml +ClideMenuItem ClideMenuItem.qml