Confirm clearing active downloads

This commit is contained in:
2026-05-07 22:01:20 -04:00
parent 72b43974c3
commit 6e00e44224
2 changed files with 103 additions and 3 deletions
@@ -58,9 +58,35 @@ impl ElyShell {
.flex_col()
.items_end()
.gap_1()
.child(div().text_xs().text_color(rgb(colors::MUTED)).child(
format!("{} downloads", snapshot.download_entries.len()),
))
.child(
div()
.flex()
.items_center()
.gap_2()
.child(
div().text_xs().text_color(rgb(colors::MUTED)).child(
format!(
"{} downloads",
snapshot.download_entries.len()
),
),
)
.when(!snapshot.download_entries.is_empty(), |this| {
this.child(
Button::new("clear-downloads")
.ghost()
.xsmall()
.icon(IconName::Delete)
.tooltip("Clear Downloads")
.on_click(cx.listener(|shell, _, _, cx| {
shell
.request_clear_active_profile_downloads(
cx,
);
})),
)
}),
)
.child(
div()
.flex()
@@ -78,10 +104,63 @@ impl ElyShell {
.when_some(self.download_file_error.clone(), |this, message| {
this.child(render_download_file_error(message))
})
.when(
self.download_clear_confirmation && !snapshot.download_entries.is_empty(),
|this| this.child(self.render_download_clear_confirmation(snapshot, cx)),
)
.child(self.render_downloads_list(snapshot, cx)),
)
}
fn render_download_clear_confirmation(
&mut self,
snapshot: &BrowserSnapshot,
cx: &mut Context<Self>,
) -> AnyElement {
div()
.rounded_md()
.border_1()
.border_color(rgb(colors::HAIRLINE))
.px_3()
.py_2()
.flex()
.items_center()
.justify_between()
.gap_3()
.child(div().min_w_0().text_xs().text_color(rgb(colors::BODY)).truncate().child(
format!(
"Clear {} downloads for {}?",
snapshot.download_entries.len(),
snapshot.active_profile_name
),
))
.child(
div()
.flex()
.items_center()
.gap_2()
.child(
Button::new("cancel-clear-downloads")
.ghost()
.xsmall()
.label("Cancel")
.on_click(cx.listener(|shell, _, _, cx| {
shell.cancel_clear_active_profile_downloads(cx);
})),
)
.child(
Button::new("confirm-clear-downloads")
.danger()
.xsmall()
.label("Clear")
.on_click(cx.listener(|shell, _, _, cx| {
shell.clear_active_profile_downloads(cx);
})),
),
)
.into_any_element()
}
fn render_downloads_list(
&mut self,
snapshot: &BrowserSnapshot,
+21
View File
@@ -23,6 +23,7 @@ pub struct ElyShell {
command_input: Entity<InputState>,
last_intent: Option<CommandIntent>,
download_file_error: Option<String>,
download_clear_confirmation: bool,
_command_subscription: Subscription,
}
@@ -79,6 +80,7 @@ impl ElyShell {
command_input,
last_intent: None,
download_file_error: None,
download_clear_confirmation: false,
_command_subscription: command_subscription,
}
}
@@ -249,6 +251,25 @@ impl ElyShell {
}
}
fn request_clear_active_profile_downloads(&mut self, cx: &mut Context<Self>) {
self.download_clear_confirmation = true;
cx.notify();
}
fn cancel_clear_active_profile_downloads(&mut self, cx: &mut Context<Self>) {
self.download_clear_confirmation = false;
cx.notify();
}
fn clear_active_profile_downloads(&mut self, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state {
core.clear_downloads_for_active_profile();
}
self.download_clear_confirmation = false;
self.download_file_error = None;
cx.notify();
}
fn open_download_file(&mut self, download_id: &DownloadId, cx: &mut Context<Self>) {
self.run_download_file_action(download_id, DownloadFileAction::Open, cx);
}