Update breadcrumbs when root directory changes.

This commit is contained in:
2026-02-01 18:23:44 -05:00
parent a5bed9ed2c
commit 4cc43916cb
3 changed files with 35 additions and 39 deletions

View File

@@ -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))
}
}
}