Factor out GUI code.
This commit is contained in:
parent
fd9d47f0c0
commit
fd3c8fb204
2
build.rs
2
build.rs
@ -13,7 +13,7 @@ fn main() {
|
|||||||
.qt_module("Xml")
|
.qt_module("Xml")
|
||||||
.qml_module(QmlModule {
|
.qml_module(QmlModule {
|
||||||
uri: "clide.module",
|
uri: "clide.module",
|
||||||
rust_files: &["src/colors.rs", "src/filesystem.rs"],
|
rust_files: &["src/gui/colors.rs", "src/gui/filesystem.rs"],
|
||||||
qml_files: &[
|
qml_files: &[
|
||||||
"qml/main.qml",
|
"qml/main.qml",
|
||||||
"qml/ClideAboutWindow.qml",
|
"qml/ClideAboutWindow.qml",
|
||||||
|
|||||||
27
src/gui.rs
Normal file
27
src/gui.rs
Normal file
@ -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<dyn Error>> {
|
||||||
|
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(())
|
||||||
|
}
|
||||||
28
src/main.rs
28
src/main.rs
@ -1,34 +1,10 @@
|
|||||||
// TODO: Header
|
// TODO: Header
|
||||||
|
|
||||||
use cxx_qt_lib::QString;
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
pub mod colors;
|
pub mod gui;
|
||||||
pub mod filesystem;
|
|
||||||
|
|
||||||
fn run_gui(root_path: std::path::PathBuf) -> Result<(), Box<dyn Error>> {
|
|
||||||
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(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn run_tui(root_path: std::path::PathBuf) -> Result<(), Box<dyn Error>> {
|
fn run_tui(root_path: std::path::PathBuf) -> Result<(), Box<dyn Error>> {
|
||||||
println!("Starting the TUI editor at {:?}", root_path);
|
println!("Starting the TUI editor at {:?}", root_path);
|
||||||
@ -67,7 +43,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match args.gui {
|
match args.gui {
|
||||||
true => run_gui(root_path),
|
true => gui::run(root_path),
|
||||||
false => match args.tui {
|
false => match args.tui {
|
||||||
// Open the TUI editor if requested, otherwise use the QML GUI by default.
|
// Open the TUI editor if requested, otherwise use the QML GUI by default.
|
||||||
true => run_tui(root_path),
|
true => run_tui(root_path),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user