gui #17

Open
shaunrd0 wants to merge 11 commits from gui into main
3 changed files with 35 additions and 39 deletions
Showing only changes of commit 4cc43916cb - Show all commits

View File

@ -68,7 +68,12 @@ SplitView {
height: navigationView.height
// Path to the directory opened in the file explorer.
originalRootDirectory: root.projectDir
rootDirectory: root.projectDir
onRootDirectoryChanged: {
console.log(clideTreeView.rootDirectory)
breadCrumb.text = clideTreeView.rootDirectory
}
}
}
}

View File

@ -14,25 +14,21 @@ TreeView {
property int lastIndex: -1
required property string rootDirectory
required property string originalRootDirectory
property string rootDirectory
signal fileClicked(string filePath)
rootIndex: FileSystem.rootIndex
rootIndex: FileSystem.setDirectory(fileSystemTreeView.rootDirectory)
leftMargin: 5
boundsBehavior: Flickable.StopAtBounds
boundsMovement: Flickable.StopAtBounds
clip: true
Component.onCompleted: {
FileSystem.rootIndex = FileSystem.setDirectory(fileSystemTreeView.rootDirectory)
}
// The delegate represents a single entry in the filesystem.
delegate: TreeViewDelegate {
id: treeDelegate
indentation: 6
indentation: 8
implicitWidth: fileSystemTreeView.width > 0 ? fileSystemTreeView.width : 250
implicitHeight: 25
@ -125,7 +121,6 @@ TreeView {
fileSystemTreeView.fileClicked(treeDelegate.filePath)
break;
case Qt.RightButton:
if (treeDelegate.hasChildren)
contextMenu.popup();
break;
}
@ -136,16 +131,17 @@ TreeView {
id: contextMenu
Action {
text: qsTr("Set as root index")
enabled: treeDelegate.hasChildren
onTriggered: {
console.log("Setting directory: " + treeDelegate.filePath)
FileSystem.rootIndex = FileSystem.setDirectory(treeDelegate.filePath)
console.log("Setting new root directory: " + treeDelegate.filePath)
fileSystemTreeView.rootDirectory = treeDelegate.filePath
}
}
Action {
text: qsTr("Reset root index")
onTriggered: {
console.log("Reset root index")
FileSystem.rootIndex = FileSystem.setDirectory(fileSystemTreeView.rootDirectory)
console.log("Resetting root directory: " + fileSystemTreeView.originalRootDirectory)
fileSystemTreeView.rootDirectory = fileSystemTreeView.originalRootDirectory
}
}
}

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()
let homedir = dirs::home_dir()
.expect("Failed to get home directory")
.as_path()
.to_str()
.unwrap()
.to_string(),
))
.to_string();
self.set_root_path(&QString::from(homedir))
}
}
}