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,45 +56,71 @@ 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 import_button = gtk::Button::builder().label("Import a Database").build();
|
||||||
|
|
||||||
|
let handle_file_selection = Rc::new(Box::new({
|
||||||
let s = s.clone();
|
let s = s.clone();
|
||||||
|
let on_selected = on_selected.clone();
|
||||||
|
move |file_id: Result<gio::File, glib::Error>| match file_id {
|
||||||
|
Ok(file_id) => match file_id.path() {
|
||||||
|
Some(path) => {
|
||||||
|
s.imp().label.set_text(path.to_str().unwrap());
|
||||||
|
on_selected(path.clone());
|
||||||
|
*s.imp().path.borrow_mut() = Some(path);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
*s.imp().path.borrow_mut() = None;
|
||||||
|
s.imp().label.set_text("No database selected");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(err) => println!("file opening failed: {}", err),
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
import_button.connect_clicked({
|
||||||
|
let handle_file_selection = handle_file_selection.clone();
|
||||||
move |_| {
|
move |_| {
|
||||||
let no_window: Option<>k::Window> = None;
|
let no_window: Option<>k::Window> = None;
|
||||||
let not_cancellable: Option<&gio::Cancellable> = None;
|
let not_cancellable: Option<&gio::Cancellable> = None;
|
||||||
let s = s.clone();
|
let handle_file_selection = handle_file_selection.clone();
|
||||||
let on_selected = on_selected.clone();
|
gtk::FileDialog::builder().build().open(
|
||||||
gtk::FileDialog::builder().build().save(
|
|
||||||
no_window,
|
no_window,
|
||||||
not_cancellable,
|
not_cancellable,
|
||||||
move |file_id| match file_id {
|
move |file_id| handle_file_selection(file_id),
|
||||||
Ok(file_id) => match file_id.path() {
|
|
||||||
Some(path) => {
|
|
||||||
s.imp().label.set_text(path.to_str().unwrap());
|
|
||||||
on_selected(path.clone());
|
|
||||||
*s.imp().path.borrow_mut() = Some(path);
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
*s.imp().path.borrow_mut() = None;
|
|
||||||
s.imp().label.set_text("No database selected");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(err) => println!("file opening failed: {}", err),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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