diff --git a/build.rs b/build.rs index 1e369a2..87a98ba 100644 --- a/build.rs +++ b/build.rs @@ -13,7 +13,7 @@ fn main() { .qt_module("Xml") .qml_module(QmlModule { uri: "clide.module", - rust_files: &["src/colors.rs", "src/filesystem.rs"], + rust_files: &["src/gui/colors.rs", "src/gui/filesystem.rs"], qml_files: &[ "qml/main.qml", "qml/ClideAboutWindow.qml", diff --git a/src/gui.rs b/src/gui.rs new file mode 100644 index 0000000..62c6172 --- /dev/null +++ b/src/gui.rs @@ -0,0 +1,27 @@ +use cxx_qt_lib::QString; +use std::error::Error; + +pub mod colors; +pub mod filesystem; + +pub fn run(root_path: std::path::PathBuf) -> Result<(), Box> { + println!("Starting the GUI editor at {:?}", root_path); + + use cxx_qt_lib::{QGuiApplication, QQmlApplicationEngine, QUrl}; + + let mut app = QGuiApplication::new(); + let mut engine = QQmlApplicationEngine::new(); + + if let Some(engine) = engine.as_mut() { + engine.add_import_path(&QString::from("qml/")); + } + if let Some(engine) = engine.as_mut() { + engine.load(&QUrl::from("qml/main.qml")); + } + + if let Some(app) = app.as_mut() { + app.exec(); + } + + Ok(()) +} diff --git a/src/colors.rs b/src/gui/colors.rs similarity index 100% rename from src/colors.rs rename to src/gui/colors.rs diff --git a/src/filesystem.rs b/src/gui/filesystem.rs similarity index 100% rename from src/filesystem.rs rename to src/gui/filesystem.rs diff --git a/src/main.rs b/src/main.rs index d9c8474..c62f3b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,34 +1,10 @@ // TODO: Header -use cxx_qt_lib::QString; use std::error::Error; use std::process::{Command, Stdio}; use structopt::StructOpt; -pub mod colors; -pub mod filesystem; - -fn run_gui(root_path: std::path::PathBuf) -> Result<(), Box> { - println!("Starting the GUI editor at {:?}", root_path); - - use cxx_qt_lib::{QGuiApplication, QQmlApplicationEngine, QUrl}; - - let mut app = QGuiApplication::new(); - let mut engine = QQmlApplicationEngine::new(); - - if let Some(engine) = engine.as_mut() { - engine.add_import_path(&QString::from("qml/")); - } - if let Some(engine) = engine.as_mut() { - engine.load(&QUrl::from("qml/main.qml")); - } - - if let Some(app) = app.as_mut() { - app.exec(); - } - - Ok(()) -} +pub mod gui; fn run_tui(root_path: std::path::PathBuf) -> Result<(), Box> { println!("Starting the TUI editor at {:?}", root_path); @@ -67,7 +43,7 @@ fn main() -> Result<(), Box> { }; match args.gui { - true => run_gui(root_path), + true => gui::run(root_path), false => match args.tui { // Open the TUI editor if requested, otherwise use the QML GUI by default. true => run_tui(root_path),