WIP
This commit is contained in:
parent
6a4957588d
commit
5ba880bc7e
@ -29,4 +29,3 @@ ApplicationWindow {
|
|||||||
ClideProjectView {
|
ClideProjectView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
src/gui.rs
13
src/gui.rs
@ -1,4 +1,6 @@
|
|||||||
use cxx_qt_lib::QString;
|
use crate::gui::filesystem::FS_STATE;
|
||||||
|
use crate::gui::filesystem::qobject::FileSystem;
|
||||||
|
use cxx_qt_lib::{QModelIndex, QQmlEngine, QString};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
pub mod colors;
|
pub mod colors;
|
||||||
@ -12,6 +14,15 @@ pub fn run(root_path: std::path::PathBuf) -> Result<(), Box<dyn Error>> {
|
|||||||
let mut app = QGuiApplication::new();
|
let mut app = QGuiApplication::new();
|
||||||
let mut engine = QQmlApplicationEngine::new();
|
let mut engine = QQmlApplicationEngine::new();
|
||||||
|
|
||||||
|
// let clide_fs = FileSystemImpl {
|
||||||
|
// file_path: QString::from(root_path.to_str().unwrap()),
|
||||||
|
// root_index: QModelIndex::default(),
|
||||||
|
// };
|
||||||
|
unsafe {
|
||||||
|
let mut fs_state = FS_STATE.take_fs();
|
||||||
|
fs_state.file_path = QString::from(root_path.to_str().unwrap());
|
||||||
|
};
|
||||||
|
|
||||||
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/"));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,32 +10,33 @@ pub mod qobject {
|
|||||||
type QFileSystemModel;
|
type QFileSystemModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[auto_cxx_name]
|
||||||
|
#[auto_rust_name]
|
||||||
unsafe extern "RustQt" {
|
unsafe extern "RustQt" {
|
||||||
// Export QML Types from Rust
|
// Export QML Types from Rust
|
||||||
#[qobject]
|
#[qobject]
|
||||||
#[base = QFileSystemModel]
|
#[base = QFileSystemModel]
|
||||||
#[qml_element]
|
#[qml_element]
|
||||||
#[qml_singleton]
|
#[qml_singleton]
|
||||||
#[qproperty(QString, file_path, cxx_name = "filePath")]
|
#[qproperty(QString, file_path]
|
||||||
#[qproperty(QModelIndex, root_index, cxx_name = "rootIndex")]
|
#[qproperty(QModelIndex, root_index]
|
||||||
type FileSystem = super::FileSystemImpl;
|
type FileSystem = super::FileSystemImpl;
|
||||||
|
|
||||||
#[inherit]
|
#[inherit]
|
||||||
#[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;
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
#[cxx_override]
|
#[cxx_override]
|
||||||
#[cxx_name = "columnCount"]
|
|
||||||
fn column_count(self: &FileSystem, _index: &QModelIndex) -> i32;
|
fn column_count(self: &FileSystem, _index: &QModelIndex) -> i32;
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
#[cxx_name = "readFile"]
|
|
||||||
fn read_file(self: &FileSystem, path: &QString) -> QString;
|
fn read_file(self: &FileSystem, path: &QString) -> QString;
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
#[cxx_name = "setDirectory"]
|
|
||||||
fn set_directory(self: Pin<&mut FileSystem>, path: &QString) -> QModelIndex;
|
fn set_directory(self: Pin<&mut FileSystem>, path: &QString) -> QModelIndex;
|
||||||
|
|
||||||
|
#[qinvokable]
|
||||||
|
fn take_fs(self: &mut) -> FileSystem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +45,7 @@ use dirs;
|
|||||||
use log::warn;
|
use log::warn;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
|
use std::ptr::replace;
|
||||||
use syntect::easy::HighlightFile;
|
use syntect::easy::HighlightFile;
|
||||||
use syntect::highlighting::ThemeSet;
|
use syntect::highlighting::ThemeSet;
|
||||||
use syntect::html::{
|
use syntect::html::{
|
||||||
@ -51,10 +53,24 @@ use syntect::html::{
|
|||||||
};
|
};
|
||||||
use syntect::parsing::SyntaxSet;
|
use syntect::parsing::SyntaxSet;
|
||||||
|
|
||||||
// TODO: Impleent a provider for QFileSystemModel::setIconProvider for icons.
|
/// Singleton holding filesystem state.
|
||||||
|
pub struct FileSystemState {
|
||||||
|
pub fs: Option<FileSystemImpl>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FileSystemState {
|
||||||
|
pub unsafe fn take_fs(&mut self) -> FileSystemImpl {
|
||||||
|
let fs = replace(&mut self.fs, None);
|
||||||
|
fs.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub static mut FS_STATE : FileSystemState = FileSystemState { fs: Some(FileSystemImpl::default()) };
|
||||||
|
|
||||||
|
// TODO: Implement a provider for QFileSystemModel::setIconProvider for icons.
|
||||||
pub struct FileSystemImpl {
|
pub struct FileSystemImpl {
|
||||||
file_path: QString,
|
pub file_path: QString,
|
||||||
root_index: QModelIndex,
|
pub root_index: QModelIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default is explicit to make the editor open this source file initially.
|
// Default is explicit to make the editor open this source file initially.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user