Confirm clearing active downloads
This commit is contained in:
@@ -58,9 +58,35 @@ impl ElyShell {
|
|||||||
.flex_col()
|
.flex_col()
|
||||||
.items_end()
|
.items_end()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.child(div().text_xs().text_color(rgb(colors::MUTED)).child(
|
.child(
|
||||||
format!("{} downloads", snapshot.download_entries.len()),
|
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(
|
.child(
|
||||||
div()
|
div()
|
||||||
.flex()
|
.flex()
|
||||||
@@ -78,10 +104,63 @@ impl ElyShell {
|
|||||||
.when_some(self.download_file_error.clone(), |this, message| {
|
.when_some(self.download_file_error.clone(), |this, message| {
|
||||||
this.child(render_download_file_error(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)),
|
.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(
|
fn render_downloads_list(
|
||||||
&mut self,
|
&mut self,
|
||||||
snapshot: &BrowserSnapshot,
|
snapshot: &BrowserSnapshot,
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ pub struct ElyShell {
|
|||||||
command_input: Entity<InputState>,
|
command_input: Entity<InputState>,
|
||||||
last_intent: Option<CommandIntent>,
|
last_intent: Option<CommandIntent>,
|
||||||
download_file_error: Option<String>,
|
download_file_error: Option<String>,
|
||||||
|
download_clear_confirmation: bool,
|
||||||
_command_subscription: Subscription,
|
_command_subscription: Subscription,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +80,7 @@ impl ElyShell {
|
|||||||
command_input,
|
command_input,
|
||||||
last_intent: None,
|
last_intent: None,
|
||||||
download_file_error: None,
|
download_file_error: None,
|
||||||
|
download_clear_confirmation: false,
|
||||||
_command_subscription: command_subscription,
|
_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>) {
|
fn open_download_file(&mut self, download_id: &DownloadId, cx: &mut Context<Self>) {
|
||||||
self.run_download_file_action(download_id, DownloadFileAction::Open, cx);
|
self.run_download_file_action(download_id, DownloadFileAction::Open, cx);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user