Skip to content

Commit 07aec73

Browse files
committed
Present error messages as toasts
Rather than just dumping then in the command line, add a ToastOverlay and every error during application load will be rendered as a toast in the toast overlay.
1 parent 6219efa commit 07aec73

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

data/ui/main_window.blp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ template $CarteroWindow: Adw.ApplicationWindow {
5252
Label main_label {}
5353
}
5454

55-
Adw.TabBar tabs {
56-
view: tabview;
57-
}
55+
Adw.ToastOverlay toaster {
56+
Adw.TabBar tabs {
57+
view: tabview;
58+
}
5859

59-
Adw.TabView tabview {}
60+
Adw.TabView tabview {}
61+
}
6062
};
6163
}
6264
}

src/win.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ mod imp {
6767

6868
#[template_child]
6969
pub collections: TemplateChild<Sidebar>,
70+
71+
#[template_child]
72+
toaster: TemplateChild<adw::ToastOverlay>,
7073
}
7174

7275
#[gtk::template_callbacks]
@@ -89,6 +92,11 @@ mod imp {
8992
Some(page)
9093
}
9194

95+
fn toast_error(&self, error: CarteroError) {
96+
let toast = adw::Toast::new(&error.to_string());
97+
self.toaster.add_toast(toast);
98+
}
99+
92100
pub fn add_new_endpoint(&self, ep: Option<Endpoint>) {
93101
// Take the tour in order to get a reference to the application settings.
94102
let obj = self.obj();
@@ -167,10 +175,7 @@ mod imp {
167175
let _ = settings.set("last-directory-open-collection", parent_dir);
168176

169177
match open_collection(&path) {
170-
Ok(col) => {
171-
println!("You are opening {}", col.title());
172-
self.finish_open_collection(&path)
173-
}
178+
Ok(_) => self.finish_open_collection(&path),
174179
Err(e) => Err(e),
175180
}
176181
}
@@ -259,8 +264,7 @@ mod imp {
259264
.activate(glib::clone!(@weak self as window => move |_, _, _| {
260265
glib::spawn_future_local(glib::clone!(@weak window => async move {
261266
if let Err(e) = window.trigger_new_collection().await {
262-
let error_msg = format!("{}", e);
263-
println!("{:?}", error_msg);
267+
window.toast_error(e);
264268
}
265269
}));
266270
}))
@@ -270,8 +274,7 @@ mod imp {
270274
.activate(glib::clone!(@weak self as window => move |_, _, _| {
271275
glib::spawn_future_local(glib::clone!(@weak window => async move {
272276
if let Err(e) = window.trigger_open_collection().await {
273-
let error_msg = format!("{}", e);
274-
println!("{:?}", error_msg);
277+
window.toast_error(e);
275278
}
276279
}));
277280
}))

0 commit comments

Comments
 (0)