diff --git a/qml/ClideTreeView.qml b/qml/ClideTreeView.qml index 84c5484..47480c7 100644 --- a/qml/ClideTreeView.qml +++ b/qml/ClideTreeView.qml @@ -23,14 +23,16 @@ Rectangle { property int lastIndex: -1 - model: FileSystemSortProxyModel + model: FileSystemSortProxyModel { + id: fs + } anchors.fill: parent boundsBehavior: Flickable.StopAtBounds boundsMovement: Flickable.StopAtBounds clip: true Component.onCompleted: { - FileSystem.setDirectory(root.rootDirectory) + fs.setDirectory(root.rootDirectory) fileSystemTreeView.expandRecursively(0, -1) } @@ -123,13 +125,13 @@ Rectangle { text: qsTr("Set as root index") onTriggered: { console.log("Setting directory: " + treeDelegate.filePath) - FileSystem.setDirectory(treeDelegate.filePath) + FileSystemSortProxyModel.setDirectory(treeDelegate.filePath) } } Action { text: qsTr("Reset root index") onTriggered: { - FileSystem.setDirectory("") + FileSystemSortProxyModel.setDirectory("") } } } diff --git a/src/gui/filesystem.rs b/src/gui/filesystem.rs index 4d7d097..92cbb02 100644 --- a/src/gui/filesystem.rs +++ b/src/gui/filesystem.rs @@ -7,6 +7,7 @@ use dirs; use log::warn; use std::io::BufRead; use std::{fs}; +use std::pin::Pin; use syntect::easy::HighlightFile; use syntect::highlighting::ThemeSet; use syntect::html::{ @@ -68,6 +69,10 @@ pub mod qobject { source_row: i32, source_parent: &QModelIndex, ) -> bool; + + #[qinvokable] + #[cxx_name = "setDirectory"] + fn set_directory(self: Pin<&mut FileSystemSortProxyModel>, path: &QString) -> QModelIndex; } // Custom initialization logic. @@ -76,14 +81,6 @@ pub mod qobject { // Export QFileSystemModel functions from Rust // https://doc.qt.io/qt-6/qfilesystemmodel.html unsafe extern "RustQt" { - #[inherit] - fn index( - self: Pin<&mut FileSystem>, - row: i32, - col: i32, - parent: &QModelIndex, - ) -> QModelIndex; - #[inherit] #[cxx_name = "setRootPath"] fn set_root_path(self: Pin<&mut FileSystem>, path: &QString) -> QModelIndex; @@ -96,10 +93,10 @@ pub mod qobject { #[qinvokable] #[cxx_name = "readFile"] fn read_file(self: &FileSystem, path: &QString) -> QString; - - #[qinvokable] - #[cxx_name = "setDirectory"] - fn set_directory(self: Pin<&mut FileSystem>, path: &QString) -> QModelIndex; + // + // #[qinvokable] + // #[cxx_name = "setDirectory"] + // fn set_directory(self: Pin<&mut FileSystem>, path: &QString) -> QModelIndex; } } @@ -118,7 +115,32 @@ impl Default for FileSystemSortProxyModelImpl { impl qobject::FileSystemSortProxyModel { pub const fn filter_accepts_row(&self, _source_row: i32, _source_parent: &QModelIndex) -> bool { - true + false + } + + fn read_file(&self, path: &QString) -> QString { + if let Some(inner) = unsafe { self.inner().as_ref() } { + let pinned_inner = unsafe { Pin::new_unchecked(inner) }; + return pinned_inner.read_file(path) + } else { + panic!("Can't get inner()") + } + QString::default() + } + + // There will never be more than one column. + fn column_count(&self, _index: &QModelIndex) -> i32 { + 1 + } + + fn set_directory(self: Pin<&mut Self>, path: &QString) -> QModelIndex { + if let Some(inner) = unsafe { self.inner().as_mut() } { + let pinned_inner = unsafe { Pin::new_unchecked(inner) }; + return pinned_inner.set_directory(path) + } else { + panic!("Can't get inner()") + } + QModelIndex::default() } }