Add ClideTreeView.

This commit is contained in:
2025-03-30 16:14:58 -04:00
parent 1546eb1028
commit b62dce631f
11 changed files with 433 additions and 12 deletions

View File

@@ -26,6 +26,8 @@ pub mod qobject {
#[qproperty(QColor, editor_highlight)]
#[qproperty(QColor, gutter)]
#[qproperty(QColor, explorer_background)]
#[qproperty(QColor, explorer_folder)]
#[qproperty(QColor, explorer_folder_open)]
type RustColors = super::RustColorsImpl;
}
}
@@ -50,6 +52,8 @@ pub struct RustColorsImpl {
editor_highlight: QColor,
gutter: QColor,
explorer_background: QColor,
explorer_folder: QColor,
explorer_folder_open: QColor,
}
impl Default for RustColorsImpl {
@@ -72,6 +76,8 @@ impl Default for RustColorsImpl {
editor_highlight: QColor::try_from("#ccced3").unwrap(),
gutter: QColor::try_from("#1e1f22").unwrap(),
explorer_background: QColor::try_from("#3c3f41").unwrap(),
explorer_folder: QColor::try_from("#FFF").unwrap(),
explorer_folder_open: QColor::try_from("#FFF").unwrap(),
}
}
}

View File

@@ -14,19 +14,31 @@ 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;
#[qinvokable]
#[cxx_name = "columnCount"]
pub fn column_count(self: &FileSystem, index: &QModelIndex) -> i32;
#[qinvokable]
#[cxx_name = "readFile"]
fn read_file(self: &FileSystem, path: &QString) -> QString;
// TODO: Remove if unused in QML.
#[qinvokable]
#[cxx_name = "setInitialDirectory"]
fn set_initial_directory(self: &FileSystem, path: &QString);
}
}
use cxx_qt_lib::{QModelIndex, QString};
use dirs;
use std::fs;
pub struct FileSystemImpl {
file_path: QString,
model_index: QModelIndex,
root_index: QModelIndex,
}
// Default is explicit to make the editor open this source file initially.
@@ -34,7 +46,7 @@ impl Default for FileSystemImpl {
fn default() -> Self {
Self {
file_path: QString::from(file!()),
model_index: Default::default(),
root_index: Default::default(),
}
}
}
@@ -50,4 +62,23 @@ impl qobject::FileSystem {
.expect(format!("Failed to read file {}", path).as_str()),
)
}
// There will never be more than one column.
pub fn column_count(&self, _index: &QModelIndex) -> i32 {
1
}
fn set_initial_directory(&self, path: &QString) {
if !path.is_empty()
&& fs::metadata(path.to_string())
.expect(format!("Failed to get metadata for file {}", path).as_str())
.is_file()
{
// Open the file
// setRootPa
} else {
// If the initial directory can't be opened, attempt to find the home directory.
// dirs::home_dir()
}
}
}