Pass application context to GUI. (#11)
This commit was merged in pull request #11.
This commit is contained in:
13
src/gui.rs
13
src/gui.rs
@@ -1,18 +1,25 @@
|
||||
use crate::AppContext;
|
||||
use anyhow::Result;
|
||||
use cxx_qt_lib::QString;
|
||||
use cxx_qt_lib::{QMapPair, QMapPair_QString_QVariant, QString, QVariant};
|
||||
use log::trace;
|
||||
|
||||
pub mod colors;
|
||||
pub mod filesystem;
|
||||
|
||||
pub fn run(root_path: std::path::PathBuf) -> Result<()> {
|
||||
trace!(target:"gui::run()", "Starting the GUI editor at {root_path:?}");
|
||||
pub fn run(app_context: AppContext) -> Result<()> {
|
||||
trace!(target:"gui::run()", "Starting the GUI editor at {:?}", app_context.path);
|
||||
|
||||
use cxx_qt_lib::{QGuiApplication, QQmlApplicationEngine, QUrl};
|
||||
|
||||
let mut app = QGuiApplication::new();
|
||||
let mut engine = QQmlApplicationEngine::new();
|
||||
|
||||
// Set QML property for the directory provided to the CLI.
|
||||
let path = QString::from(app_context.path.to_string_lossy().to_string());
|
||||
let mut map = QMapPair_QString_QVariant::default();
|
||||
map.insert(QString::from("appContextPath"), QVariant::from(&path));
|
||||
engine.as_mut().unwrap().set_initial_properties(&map);
|
||||
|
||||
if let Some(engine) = engine.as_mut() {
|
||||
engine.add_import_path(&QString::from("qml/"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user