Skip to content

Commit 58bc72f

Browse files
committed
feat: introducing sqlshield-gui
1 parent 7180ac9 commit 58bc72f

8 files changed

Lines changed: 4784 additions & 233 deletions

File tree

Cargo.lock

Lines changed: 4629 additions & 233 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ resolver = "2"
33
members = [
44
"sqlshield",
55
"sqlshield-cli",
6+
"sqlshield-gui",
67
"sqlshield-py",
78
]
89

sqlshield-gui/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
/target/
4+
5+
# These are backup files generated by rustfmt
6+
**/*.rs.bk

sqlshield-gui/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "sqlshield-gui"
3+
version = "0.1.0"
4+
authors = ["David Freire <davidsmfreire@gmail.com>"]
5+
edition = "2021"
6+
build = "build.rs"
7+
8+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
9+
10+
[dependencies]
11+
slint = "1.4"
12+
sqlshield = { workspace = true }
13+
14+
[build-dependencies]
15+
slint-build = "1.4"

sqlshield-gui/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Slint Rust Template
2+
3+
A template for a Rust application that's using [Slint](https://slint.rs) for the user interface.
4+
5+
## About
6+
7+
This template helps you get started developing a Rust application with Slint as toolkit
8+
for the user interface. It demonstrates the integration between the `.slint` UI markup and
9+
Rust code, how to trigger react to callbacks, get and set properties and use basic widgets.
10+
11+
## Usage
12+
13+
1. Install Rust by following the [Rust Getting Started Guide](https://www.rust-lang.org/learn/get-started).
14+
Once this is done, you should have the ```rustc``` compiler and the ```cargo``` build system installed in your path.
15+
2. Install [`cargo-generate`](https://github.com/cargo-generate/cargo-generate)
16+
```
17+
cargo install cargo-generate
18+
```
19+
3. Set up a sample project with this template
20+
```
21+
cargo generate --git https://github.com/slint-ui/slint-rust-template --name my-project
22+
cd my-project
23+
```
24+
3. Build with cargo
25+
```
26+
cargo build
27+
```
28+
4. Run the application binary
29+
```
30+
cargo run
31+
```
32+
33+
We recommend using an IDE for development, along with our [LSP-based IDE integration for `.slint` files](https://github.com/slint-ui/slint/blob/master/tools/lsp/README.md). You can also load this project directly in [Visual Studio Code](https://code.visualstudio.com) and install our [Slint extension](https://marketplace.visualstudio.com/items?itemName=Slint.slint).
34+
35+
## Next Steps
36+
37+
We hope that this template helps you get started and you enjoy exploring making user interfaces with Slint. To learn more
38+
about the Slint APIs and the `.slint` markup language check out our [online documentation](https://slint.dev/docs).
39+
40+
Don't forget to edit this README to replace it by yours

sqlshield-gui/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
slint_build::compile("ui/appwindow.slint").unwrap();
3+
}

sqlshield-gui/src/main.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use sqlshield;
2+
3+
slint::include_modules!();
4+
use std::rc::Rc;
5+
6+
fn main() -> Result<(), slint::PlatformError> {
7+
let ui = AppWindow::new()?;
8+
9+
ui.on_request_text_edited({
10+
let ui_handle = ui.as_weak();
11+
move |text, text_type| {
12+
let ui = ui_handle.unwrap();
13+
if text_type == "queries" {
14+
ui.set_queries(text);
15+
// println!("queries -> {}", ui.get_queries());
16+
} else if text_type == "schema" {
17+
ui.set_schema(text);
18+
// println!("schema -> {}", ui.get_schema());
19+
}
20+
21+
let errors = match sqlshield::validate_query(
22+
ui.get_queries().to_string(),
23+
ui.get_schema().to_string(),
24+
) {
25+
Ok(errors) => errors,
26+
Err(err) => vec![err],
27+
};
28+
29+
let model: Rc<slint::VecModel<slint::StandardListViewItem>> =
30+
Rc::from(slint::VecModel::from(
31+
errors
32+
.into_iter()
33+
.map(|e| slint::StandardListViewItem::from(slint::SharedString::from(e)))
34+
.collect::<Vec<slint::StandardListViewItem>>(),
35+
));
36+
37+
ui.set_errors(slint::ModelRc::from(model));
38+
}
39+
});
40+
41+
ui.run()
42+
}

sqlshield-gui/ui/appwindow.slint

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Button, VerticalBox, HorizontalBox, TextEdit, StandardListView } from "std-widgets.slint";
2+
3+
export component AppWindow inherits Window {
4+
width: 1000px;
5+
height: 700px;
6+
7+
in-out property<string> queries: "";
8+
in-out property<string> schema: "";
9+
in property<[StandardListViewItem]> errors: [];
10+
callback request-text-edited(string, string);
11+
VerticalBox {
12+
HorizontalBox {
13+
width: 1000px;
14+
height: 500px;
15+
VerticalBox {
16+
Text {
17+
text: "Queries";
18+
}
19+
TextEdit {
20+
text: queries;
21+
edited(text) => {
22+
root.request-text-edited(text, "queries");
23+
}
24+
}
25+
}
26+
VerticalBox {
27+
Text {
28+
text: "Schema";
29+
}
30+
TextEdit {
31+
text: schema;
32+
edited(text) => {
33+
root.request-text-edited(text, "schema");
34+
}
35+
}
36+
}
37+
}
38+
HorizontalBox {
39+
Text {
40+
text: "Errors";
41+
}
42+
StandardListView {
43+
height: 200px;
44+
model: errors;
45+
}
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)