Compare commits

..

No commits in common. "db188ea75ab19516345e5d83afae07c08b172bb0" and "38db3d6780b25de87802490f44ccade3c7c578a7" have entirely different histories.

2 changed files with 9 additions and 44 deletions

View File

@ -25,8 +25,6 @@ use gtk::{subclass::prelude::*, STYLE_PROVIDER_PRIORITY_USER};
use std::{
cell::RefCell,
env,
path::PathBuf,
rc::Rc,
sync::{Arc, RwLock},
};
use ui::FileChooserRow;
@ -74,10 +72,7 @@ glib::wrapper! {
}
impl WelcomeView {
pub fn new<F>(on_save: F) -> Self
where
F: Fn(PathBuf) + 'static,
{
pub fn new() -> Self {
let s: Self = Object::builder().build();
s.set_orientation(gtk::Orientation::Vertical);
s.set_css_classes(&["modal"]);
@ -88,6 +83,7 @@ impl WelcomeView {
.label("Welcome to FitnessTrax")
.css_classes(["modal-title"])
.build();
s.append(&title);
let content = gtk::Box::builder()
.css_classes(["model-content"])
@ -95,34 +91,17 @@ impl WelcomeView {
.vexpand(true)
.build();
let save_button = gtk::Button::builder()
.label("Save Settings")
.sensitive(false)
.build();
content.append(&gtk::Label::new(Some("Welcome to FitnessTrax. The application has not yet been configured, so I will walk you through that. Let's start out by selecting your database.")));
// 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
// updated to reflect the chosen path.
let db_row = FileChooserRow::new({
let save_button = save_button.clone();
move |_| save_button.set_sensitive(true)
});
let db_row = FileChooserRow::new();
content.append(&gtk::Label::new(Some("Welcome to FitnessTrax. The application has not yet been configured, so I will walk you through that. Let's start out by selecting your database.")));
content.append(&db_row);
let on_save = Box::new(on_save);
save_button.connect_clicked({
move |_| {
if let Some(path) = db_row.path() {
on_save(path)
}
}
});
s.append(&title);
s.append(&content);
s.append(&save_button);
s.append(&gtk::Button::builder().label("Save Settings").build());
s
}
@ -188,7 +167,7 @@ impl AppWindow {
.build();
let current_view = if app.database.read().unwrap().is_none() {
WelcomeView::new(&|_| {}).upcast()
WelcomeView::new().upcast()
} else {
HistoricalView::new().upcast()
};

View File

@ -16,11 +16,7 @@ You should have received a copy of the GNU General Public License along with Fit
use glib::Object;
use gtk::{prelude::*, subclass::prelude::*};
use std::{
cell::RefCell,
path::{Path, PathBuf},
rc::Rc,
};
use std::{cell::RefCell, path::PathBuf};
pub struct FileChooserRowPrivate {
path: RefCell<Option<PathBuf>>,
@ -50,10 +46,7 @@ glib::wrapper! {
}
impl FileChooserRow {
pub fn new<F>(on_selected: F) -> Self
where
F: Fn(PathBuf) + 'static,
{
pub fn new() -> Self {
let s: Self = Object::builder().build();
s.set_orientation(gtk::Orientation::Horizontal);
@ -64,22 +57,19 @@ impl FileChooserRow {
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));
db_file_chooser_button.connect_clicked({
let s = s.clone();
move |_| {
let no_window: Option<&gtk::Window> = None;
let not_cancellable: Option<&gio::Cancellable> = None;
let s = s.clone();
let on_selected = on_selected.clone();
gtk::FileDialog::builder().build().save(
gtk::FileDialog::builder().build().open(
no_window,
not_cancellable,
move |file_id| 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 => {
@ -98,8 +88,4 @@ impl FileChooserRow {
s
}
pub fn path(&self) -> Option<PathBuf> {
self.imp().path.borrow().clone()
}
}