From 4cc43916cbb55030a4df9482311b1180109d6f0e Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Sun, 1 Feb 2026 18:23:44 -0500 Subject: [PATCH] Update breadcrumbs when root directory changes. --- qml/ClideProjectView.qml | 5 +++++ qml/ClideTreeView.qml | 24 +++++++++------------ src/gui/filesystem.rs | 45 ++++++++++++++++++---------------------- 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/qml/ClideProjectView.qml b/qml/ClideProjectView.qml index a5a5c0c..4a324e5 100644 --- a/qml/ClideProjectView.qml +++ b/qml/ClideProjectView.qml @@ -68,7 +68,12 @@ SplitView { height: navigationView.height // Path to the directory opened in the file explorer. + originalRootDirectory: root.projectDir rootDirectory: root.projectDir + onRootDirectoryChanged: { + console.log(clideTreeView.rootDirectory) + breadCrumb.text = clideTreeView.rootDirectory + } } } } diff --git a/qml/ClideTreeView.qml b/qml/ClideTreeView.qml index ad0cd4d..1eb99dc 100644 --- a/qml/ClideTreeView.qml +++ b/qml/ClideTreeView.qml @@ -14,25 +14,21 @@ TreeView { property int lastIndex: -1 - required property string rootDirectory + required property string originalRootDirectory + property string rootDirectory signal fileClicked(string filePath) - - rootIndex: FileSystem.rootIndex + rootIndex: FileSystem.setDirectory(fileSystemTreeView.rootDirectory) leftMargin: 5 boundsBehavior: Flickable.StopAtBounds boundsMovement: Flickable.StopAtBounds clip: true - Component.onCompleted: { - FileSystem.rootIndex = FileSystem.setDirectory(fileSystemTreeView.rootDirectory) - } - // The delegate represents a single entry in the filesystem. delegate: TreeViewDelegate { id: treeDelegate - indentation: 6 + indentation: 8 implicitWidth: fileSystemTreeView.width > 0 ? fileSystemTreeView.width : 250 implicitHeight: 25 @@ -125,8 +121,7 @@ TreeView { fileSystemTreeView.fileClicked(treeDelegate.filePath) break; case Qt.RightButton: - if (treeDelegate.hasChildren) - contextMenu.popup(); + contextMenu.popup(); break; } } @@ -136,16 +131,17 @@ TreeView { id: contextMenu Action { text: qsTr("Set as root index") + enabled: treeDelegate.hasChildren onTriggered: { - console.log("Setting directory: " + treeDelegate.filePath) - FileSystem.rootIndex = FileSystem.setDirectory(treeDelegate.filePath) + console.log("Setting new root directory: " + treeDelegate.filePath) + fileSystemTreeView.rootDirectory = treeDelegate.filePath } } Action { text: qsTr("Reset root index") onTriggered: { - console.log("Reset root index") - FileSystem.rootIndex = FileSystem.setDirectory(fileSystemTreeView.rootDirectory) + console.log("Resetting root directory: " + fileSystemTreeView.originalRootDirectory) + fileSystemTreeView.rootDirectory = fileSystemTreeView.originalRootDirectory } } } diff --git a/src/gui/filesystem.rs b/src/gui/filesystem.rs index 09d7aa5..9d897b7 100644 --- a/src/gui/filesystem.rs +++ b/src/gui/filesystem.rs @@ -2,6 +2,19 @@ // // SPDX-License-Identifier: GNU General Public License v3.0 or later +use cxx_qt_lib::{QModelIndex, QString}; +use dirs; +use log::warn; +use std::fs; +use std::path::Path; +use syntect::easy::HighlightLines; +use syntect::highlighting::ThemeSet; +use syntect::html::{ + IncludeBackground, append_highlighted_html_for_styled_line, start_highlighted_html_snippet, +}; +use syntect::parsing::SyntaxSet; +use syntect::util::LinesWithEndings; + #[cxx_qt::bridge] pub mod qobject { unsafe extern "C++" { @@ -21,7 +34,6 @@ pub mod qobject { #[qml_element] #[qml_singleton] #[qproperty(QString, file_path, cxx_name = "filePath")] - #[qproperty(QModelIndex, root_index, cxx_name = "rootIndex")] type FileSystem = super::FileSystemImpl; #[inherit] @@ -43,24 +55,9 @@ pub mod qobject { } } -use cxx_qt_lib::{QModelIndex, QString}; -use dirs; -use log::warn; -use std::fs; -use std::io::BufRead; -use std::path::Path; -use syntect::easy::{HighlightFile, HighlightLines}; -use syntect::highlighting::ThemeSet; -use syntect::html::{ - IncludeBackground, append_highlighted_html_for_styled_line, start_highlighted_html_snippet, -}; -use syntect::parsing::SyntaxSet; -use syntect::util::LinesWithEndings; - // TODO: Implement a provider for QFileSystemModel::setIconProvider for icons. pub struct FileSystemImpl { file_path: QString, - root_index: QModelIndex, } // Default is explicit to make the editor open this source file initially. @@ -68,7 +65,6 @@ impl Default for FileSystemImpl { fn default() -> Self { Self { file_path: QString::from(file!()), - root_index: Default::default(), } } } @@ -134,14 +130,13 @@ impl qobject::FileSystem { self.set_root_path(path) } else { // If the initial directory can't be opened, attempt to find the home directory. - self.set_root_path(&QString::from( - dirs::home_dir() - .expect("Failed to get home directory") - .as_path() - .to_str() - .unwrap() - .to_string(), - )) + let homedir = dirs::home_dir() + .expect("Failed to get home directory") + .as_path() + .to_str() + .unwrap() + .to_string(); + self.set_root_path(&QString::from(homedir)) } } }