Pass application context to GUI. #11

Merged
shaunrd0 merged 9 commits from app-context into main 2026-01-31 04:25:16 +00:00
6 changed files with 31 additions and 14 deletions
Showing only changes of commit ec5a369b84 - Show all commits

View File

@ -58,7 +58,7 @@ ApplicationWindow {
+ "<p>Project notes <a href=\"http://knoats.com\">knoats.com</a></p>" + "<p>Project notes <a href=\"http://knoats.com\">knoats.com</a></p>"
+ "<p>This project is developed at <a href=\"http://git.shaunreed.com/shaunrd0/clide\">git.shaunreed.com</a></p>" + "<p>This project is developed at <a href=\"http://git.shaunreed.com/shaunrd0/clide\">git.shaunreed.com</a></p>"
+ "<p><a href=\"https://github.com/KDAB/cxx-qt\">KDAB CXX-Qt repository</a></p>" + "<p><a href=\"https://github.com/KDAB/cxx-qt\">KDAB CXX-Qt repository</a></p>"
+ "<p>Copyright (C) 2025 Shaun Reed, all rights reserved.</p>") + "<p>Copyright (C) 2026 Shaun Reed, all rights reserved.</p>")
color: RustColors.editor_text color: RustColors.editor_text
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
readOnly: true readOnly: true

View File

@ -13,7 +13,7 @@ SplitView {
// The path to the file to show in the text editor. // The path to the file to show in the text editor.
// This is updated by a signal caught within ClideProjectView. // This is updated by a signal caught within ClideProjectView.
// Initialized by the Default trait for the Rust QML singleton FileSystem. // Initialized by the Default trait for the Rust QML singleton FileSystem.
required property string filePath; required property string filePath
// Customized handle to drag between the Editor and the Console. // Customized handle to drag between the Editor and the Console.
handle: Rectangle { handle: Rectangle {

View File

@ -7,8 +7,8 @@ import clide.module 1.0
SplitView { SplitView {
id: root id: root
// Path to the file selected in the tree view. // Path to the directory of the project opened in clide.
default property string selectedFilePath: FileSystem.filePath; required property string projectDir
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true
@ -43,13 +43,18 @@ SplitView {
anchors.fill: parent anchors.fill: parent
ClideTreeView { ClideTreeView {
id: clideTreeView id: clideTreeView
onFileClicked: path => root.selectedFilePath = path onFileClicked: path => root.projectDir = path
// Path to the directory opened in the file explorer.
rootDirectory: root.projectDir
} }
} }
} }
ClideEditor { ClideEditor {
SplitView.fillWidth: true SplitView.fillWidth: true
// Initialize using the Default trait in Rust QML singleton FileSystem.
filePath: root.selectedFilePath // Provide a path to the file currently open in the text editor.
// Initialized using the Default trait in Rust QML singleton FileSystem.
filePath: FileSystem.filePath
} }
} }

View File

@ -8,13 +8,14 @@ Rectangle {
id: root id: root
color: RustColors.explorer_background color: RustColors.explorer_background
required property string rootDirectory
signal fileClicked(string filePath) signal fileClicked(string filePath)
TreeView { TreeView {
id: fileSystemTreeView id: fileSystemTreeView
anchors.margins: 15 anchors.margins: 15
// rootIndex: FileSystem.rootIndex
property int lastIndex: -1 property int lastIndex: -1
model: FileSystem model: FileSystem
@ -24,8 +25,8 @@ Rectangle {
clip: true clip: true
Component.onCompleted: { Component.onCompleted: {
FileSystem.setDirectory(FileSystem.filePath) FileSystem.setDirectory(root.rootDirectory)
fileSystemTreeView.expandRecursively(0, 4) fileSystemTreeView.expandRecursively(0, -1)
} }
// The delegate represents a single entry in the filesystem. // The delegate represents a single entry in the filesystem.
@ -42,9 +43,7 @@ Rectangle {
indicator: Image { indicator: Image {
id: directoryIcon id: directoryIcon
x: treeDelegate.leftMargin + (treeDelegate.depth * treeDelegate.indentation) function setSourceImage() {
anchors.verticalCenter: parent.verticalCenter
source: {
let folderOpen = "data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 576 512\"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d=\"M88.7 223.8L0 375.8 0 96C0 60.7 28.7 32 64 32l117.5 0c17 0 33.3 6.7 45.3 18.7l26.5 26.5c12 12 28.3 18.7 45.3 18.7L416 96c35.3 0 64 28.7 64 64l0 32-336 0c-22.8 0-43.8 12.1-55.3 31.8zm27.6 16.1C122.1 230 132.6 224 144 224l400 0c11.5 0 22 6.1 27.7 16.1s5.7 22.2-.1 32.1l-112 192C453.9 474 443.4 480 432 480L32 480c-11.5 0-22-6.1-27.7-16.1s-5.7-22.2 .1-32.1l112-192z\"/></svg>"; let folderOpen = "data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 576 512\"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d=\"M88.7 223.8L0 375.8 0 96C0 60.7 28.7 32 64 32l117.5 0c17 0 33.3 6.7 45.3 18.7l26.5 26.5c12 12 28.3 18.7 45.3 18.7L416 96c35.3 0 64 28.7 64 64l0 32-336 0c-22.8 0-43.8 12.1-55.3 31.8zm27.6 16.1C122.1 230 132.6 224 144 224l400 0c11.5 0 22 6.1 27.7 16.1s5.7 22.2-.1 32.1l-112 192C453.9 474 443.4 480 432 480L32 480c-11.5 0-22-6.1-27.7-16.1s-5.7-22.2 .1-32.1l112-192z\"/></svg>";
let folderClosed = "data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 512 512\"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d=\"M64 480H448c35.3 0 64-28.7 64-64V160c0-35.3-28.7-64-64-64H288c-10.1 0-19.6-4.7-25.6-12.8L243.2 57.6C231.1 41.5 212.1 32 192 32H64C28.7 32 0 60.7 0 96V416c0 35.3 28.7 64 64 64z\"/></svg>"; let folderClosed = "data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 512 512\"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d=\"M64 480H448c35.3 0 64-28.7 64-64V160c0-35.3-28.7-64-64-64H288c-10.1 0-19.6-4.7-25.6-12.8L243.2 57.6C231.1 41.5 212.1 32 192 32H64C28.7 32 0 60.7 0 96V416c0 35.3 28.7 64 64 64z\"/></svg>";
let file = "data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 384 512\"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d=\"M0 64C0 28.7 28.7 0 64 0L224 0l0 128c0 17.7 14.3 32 32 32l128 0 0 288c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 64zm384 64l-128 0L256 0 384 128z\"/></svg>"; let file = "data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 384 512\"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d=\"M0 64C0 28.7 28.7 0 64 0L224 0l0 128c0 17.7 14.3 32 32 32l128 0 0 288c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 64zm384 64l-128 0L256 0 384 128z\"/></svg>";
@ -56,6 +55,10 @@ Rectangle {
return file return file
} }
} }
x: treeDelegate.leftMargin + (treeDelegate.depth * treeDelegate.indentation)
anchors.verticalCenter: parent.verticalCenter
source: setSourceImage()
sourceSize.width: 15 sourceSize.width: 15
sourceSize.height: 15 sourceSize.height: 15
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit

View File

@ -13,6 +13,8 @@ ApplicationWindow {
visible: true visible: true
width: 1200 width: 1200
required property string appContextPath
menuBar: ClideMenuBar { menuBar: ClideMenuBar {
} }
@ -27,6 +29,7 @@ ApplicationWindow {
title: qsTr("Error") title: qsTr("Error")
} }
ClideProjectView { ClideProjectView {
projectDir: appWindow.appContextPath
} }
} }

View File

@ -1,6 +1,6 @@
use crate::AppContext; use crate::AppContext;
use anyhow::Result; use anyhow::Result;
use cxx_qt_lib::QString; use cxx_qt_lib::{QMapPair, QMapPair_QString_QVariant, QString, QVariant};
use log::trace; use log::trace;
pub mod colors; pub mod colors;
@ -14,6 +14,12 @@ pub fn run(app_context: AppContext) -> Result<()> {
let mut app = QGuiApplication::new(); let mut app = QGuiApplication::new();
let mut engine = QQmlApplicationEngine::new(); let mut engine = QQmlApplicationEngine::new();
// Set QML property for the directory provided to the CLI.
let path = QString::from(app_context.path.to_string_lossy().to_string());
let mut map = QMapPair_QString_QVariant::default();
map.insert(QString::from("appContextPath"), QVariant::from(&path));
engine.as_mut().unwrap().set_initial_properties(&map);
if let Some(engine) = engine.as_mut() { if let Some(engine) = engine.as_mut() {
engine.add_import_path(&QString::from("qml/")); engine.add_import_path(&QString::from("qml/"));
} }