WIP
This commit is contained in:
parent
75889f2023
commit
886c36c66b
@ -23,14 +23,16 @@ Rectangle {
|
|||||||
|
|
||||||
property int lastIndex: -1
|
property int lastIndex: -1
|
||||||
|
|
||||||
model: FileSystemSortProxyModel
|
model: FileSystemSortProxyModel {
|
||||||
|
id: fs
|
||||||
|
}
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
boundsBehavior: Flickable.StopAtBounds
|
boundsBehavior: Flickable.StopAtBounds
|
||||||
boundsMovement: Flickable.StopAtBounds
|
boundsMovement: Flickable.StopAtBounds
|
||||||
clip: true
|
clip: true
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
FileSystem.setDirectory(root.rootDirectory)
|
fs.setDirectory(root.rootDirectory)
|
||||||
fileSystemTreeView.expandRecursively(0, -1)
|
fileSystemTreeView.expandRecursively(0, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,13 +125,13 @@ Rectangle {
|
|||||||
text: qsTr("Set as root index")
|
text: qsTr("Set as root index")
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
console.log("Setting directory: " + treeDelegate.filePath)
|
console.log("Setting directory: " + treeDelegate.filePath)
|
||||||
FileSystem.setDirectory(treeDelegate.filePath)
|
FileSystemSortProxyModel.setDirectory(treeDelegate.filePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Action {
|
Action {
|
||||||
text: qsTr("Reset root index")
|
text: qsTr("Reset root index")
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
FileSystem.setDirectory("")
|
FileSystemSortProxyModel.setDirectory("")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ use dirs;
|
|||||||
use log::warn;
|
use log::warn;
|
||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
use std::{fs};
|
use std::{fs};
|
||||||
|
use std::pin::Pin;
|
||||||
use syntect::easy::HighlightFile;
|
use syntect::easy::HighlightFile;
|
||||||
use syntect::highlighting::ThemeSet;
|
use syntect::highlighting::ThemeSet;
|
||||||
use syntect::html::{
|
use syntect::html::{
|
||||||
@ -68,6 +69,10 @@ pub mod qobject {
|
|||||||
source_row: i32,
|
source_row: i32,
|
||||||
source_parent: &QModelIndex,
|
source_parent: &QModelIndex,
|
||||||
) -> bool;
|
) -> bool;
|
||||||
|
|
||||||
|
#[qinvokable]
|
||||||
|
#[cxx_name = "setDirectory"]
|
||||||
|
fn set_directory(self: Pin<&mut FileSystemSortProxyModel>, path: &QString) -> QModelIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Custom initialization logic.
|
// Custom initialization logic.
|
||||||
@ -76,14 +81,6 @@ pub mod qobject {
|
|||||||
// Export QFileSystemModel functions from Rust
|
// Export QFileSystemModel functions from Rust
|
||||||
// https://doc.qt.io/qt-6/qfilesystemmodel.html
|
// https://doc.qt.io/qt-6/qfilesystemmodel.html
|
||||||
unsafe extern "RustQt" {
|
unsafe extern "RustQt" {
|
||||||
#[inherit]
|
|
||||||
fn index(
|
|
||||||
self: Pin<&mut FileSystem>,
|
|
||||||
row: i32,
|
|
||||||
col: i32,
|
|
||||||
parent: &QModelIndex,
|
|
||||||
) -> QModelIndex;
|
|
||||||
|
|
||||||
#[inherit]
|
#[inherit]
|
||||||
#[cxx_name = "setRootPath"]
|
#[cxx_name = "setRootPath"]
|
||||||
fn set_root_path(self: Pin<&mut FileSystem>, path: &QString) -> QModelIndex;
|
fn set_root_path(self: Pin<&mut FileSystem>, path: &QString) -> QModelIndex;
|
||||||
@ -96,10 +93,10 @@ pub mod qobject {
|
|||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
#[cxx_name = "readFile"]
|
#[cxx_name = "readFile"]
|
||||||
fn read_file(self: &FileSystem, path: &QString) -> QString;
|
fn read_file(self: &FileSystem, path: &QString) -> QString;
|
||||||
|
//
|
||||||
#[qinvokable]
|
// #[qinvokable]
|
||||||
#[cxx_name = "setDirectory"]
|
// #[cxx_name = "setDirectory"]
|
||||||
fn set_directory(self: Pin<&mut FileSystem>, path: &QString) -> QModelIndex;
|
// fn set_directory(self: Pin<&mut FileSystem>, path: &QString) -> QModelIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +115,32 @@ impl Default for FileSystemSortProxyModelImpl {
|
|||||||
|
|
||||||
impl qobject::FileSystemSortProxyModel {
|
impl qobject::FileSystemSortProxyModel {
|
||||||
pub const fn filter_accepts_row(&self, _source_row: i32, _source_parent: &QModelIndex) -> bool {
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user