Set up the welcome screen and open the database #125
|
@ -0,0 +1,21 @@
|
||||||
|
.welcome {
|
||||||
|
margin: 64px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.welcome-title {
|
||||||
|
font-size: larger;
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.welcome-content {
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.welcome-footer {
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-row {
|
||||||
|
margin: 8px 0px 8px 0px;
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
|
|
@ -80,13 +80,13 @@ impl WelcomeView {
|
||||||
{
|
{
|
||||||
let s: Self = Object::builder().build();
|
let s: Self = Object::builder().build();
|
||||||
s.set_orientation(gtk::Orientation::Vertical);
|
s.set_orientation(gtk::Orientation::Vertical);
|
||||||
s.set_css_classes(&["modal"]);
|
s.set_css_classes(&["welcome"]);
|
||||||
|
|
||||||
// Replace this with the welcome screen that we set up in the fitnesstrax/unconfigured-page
|
// Replace this with the welcome screen that we set up in the fitnesstrax/unconfigured-page
|
||||||
// branch.
|
// branch.
|
||||||
let title = gtk::Label::builder()
|
let title = gtk::Label::builder()
|
||||||
.label("Welcome to FitnessTrax")
|
.label("Welcome to FitnessTrax")
|
||||||
.css_classes(["modal-title"])
|
.css_classes(["welcome-title"])
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let content = gtk::Box::builder()
|
let content = gtk::Box::builder()
|
||||||
|
|
|
@ -56,26 +56,23 @@ impl FileChooserRow {
|
||||||
{
|
{
|
||||||
let s: Self = Object::builder().build();
|
let s: Self = Object::builder().build();
|
||||||
|
|
||||||
|
s.set_css_classes(&["dialog-row", "card"]);
|
||||||
s.set_orientation(gtk::Orientation::Horizontal);
|
s.set_orientation(gtk::Orientation::Horizontal);
|
||||||
|
s.set_spacing(8);
|
||||||
|
|
||||||
// The database selection row should be a box that shows a default database path, along with a
|
// The database selection row should be a box that shows a default database path, along with a
|
||||||
// button that triggers a file chooser dialog. Once the dialog returns, the box should be
|
// button that triggers a file chooser dialog. Once the dialog returns, the box should be
|
||||||
// updated to reflect the chosen path.
|
// updated to reflect the chosen path.
|
||||||
s.imp().label.set_text("No database selected");
|
s.imp().label.set_text("No database selected");
|
||||||
|
|
||||||
let db_file_chooser_button = gtk::Button::builder().label("Select Database").build();
|
|
||||||
let on_selected = Rc::new(Box::new(on_selected));
|
let on_selected = Rc::new(Box::new(on_selected));
|
||||||
db_file_chooser_button.connect_clicked({
|
|
||||||
let s = s.clone();
|
let import_button = gtk::Button::builder().label("Import a Database").build();
|
||||||
move |_| {
|
|
||||||
let no_window: Option<>k::Window> = None;
|
let handle_file_selection = Rc::new(Box::new({
|
||||||
let not_cancellable: Option<&gio::Cancellable> = None;
|
|
||||||
let s = s.clone();
|
let s = s.clone();
|
||||||
let on_selected = on_selected.clone();
|
let on_selected = on_selected.clone();
|
||||||
gtk::FileDialog::builder().build().save(
|
move |file_id: Result<gio::File, glib::Error>| match file_id {
|
||||||
no_window,
|
|
||||||
not_cancellable,
|
|
||||||
move |file_id| match file_id {
|
|
||||||
Ok(file_id) => match file_id.path() {
|
Ok(file_id) => match file_id.path() {
|
||||||
Some(path) => {
|
Some(path) => {
|
||||||
s.imp().label.set_text(path.to_str().unwrap());
|
s.imp().label.set_text(path.to_str().unwrap());
|
||||||
|
@ -88,13 +85,42 @@ impl FileChooserRow {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(err) => println!("file opening failed: {}", err),
|
Err(err) => println!("file opening failed: {}", err),
|
||||||
},
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
import_button.connect_clicked({
|
||||||
|
let handle_file_selection = handle_file_selection.clone();
|
||||||
|
move |_| {
|
||||||
|
let no_window: Option<>k::Window> = None;
|
||||||
|
let not_cancellable: Option<&gio::Cancellable> = None;
|
||||||
|
let handle_file_selection = handle_file_selection.clone();
|
||||||
|
gtk::FileDialog::builder().build().open(
|
||||||
|
no_window,
|
||||||
|
not_cancellable,
|
||||||
|
move |file_id| handle_file_selection(file_id),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let new_button = gtk::Button::builder().label("Create Database").build();
|
||||||
|
new_button.connect_clicked({
|
||||||
|
let handle_file_selection = handle_file_selection.clone();
|
||||||
|
move |_| {
|
||||||
|
let no_window: Option<>k::Window> = None;
|
||||||
|
let not_cancellable: Option<&gio::Cancellable> = None;
|
||||||
|
let handle_file_selection = handle_file_selection.clone();
|
||||||
|
gtk::FileDialog::builder().build().save(
|
||||||
|
no_window,
|
||||||
|
not_cancellable,
|
||||||
|
move |file_id| handle_file_selection(file_id),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
s.imp().label.set_halign(gtk::Align::Start);
|
||||||
s.append(&s.imp().label);
|
s.append(&s.imp().label);
|
||||||
s.append(&db_file_chooser_button);
|
s.append(&import_button);
|
||||||
|
s.append(&new_button);
|
||||||
|
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue