Wire download row controls
This commit is contained in:
@@ -19,7 +19,7 @@ impl ElyShell {
|
||||
cx: &mut Context<Self>,
|
||||
) -> AnyElement {
|
||||
match tab.url().as_str() {
|
||||
"ely://downloads" => self.render_downloads_page(snapshot),
|
||||
"ely://downloads" => self.render_downloads_page(snapshot, cx),
|
||||
"ely://history" => self.render_history_page(snapshot, cx),
|
||||
"ely://archive" => self.render_archive_page(snapshot, cx),
|
||||
_ => render_default_page(tab),
|
||||
|
||||
@@ -5,14 +5,23 @@ use ely_domain::{
|
||||
};
|
||||
use gpui::prelude::FluentBuilder;
|
||||
use gpui::{
|
||||
AnyElement, InteractiveElement, IntoElement, ParentElement, SharedString, Styled, div, px, rgb,
|
||||
AnyElement, Context, InteractiveElement, IntoElement, ParentElement, SharedString, Styled, div,
|
||||
px, rgb,
|
||||
};
|
||||
use gpui_component::{
|
||||
IconName, Sizable, StyledExt,
|
||||
button::{Button, ButtonVariants},
|
||||
scroll::ScrollableElement,
|
||||
};
|
||||
use gpui_component::{IconName, StyledExt, scroll::ScrollableElement};
|
||||
|
||||
use super::{ElyShell, render_canvas_surface};
|
||||
|
||||
impl ElyShell {
|
||||
pub(super) fn render_downloads_page(&mut self, snapshot: &BrowserSnapshot) -> AnyElement {
|
||||
pub(super) fn render_downloads_page(
|
||||
&mut self,
|
||||
snapshot: &BrowserSnapshot,
|
||||
cx: &mut Context<Self>,
|
||||
) -> AnyElement {
|
||||
render_canvas_surface(
|
||||
div()
|
||||
.size_full()
|
||||
@@ -66,12 +75,15 @@ impl ElyShell {
|
||||
),
|
||||
),
|
||||
)
|
||||
.child(render_downloads_list(snapshot)),
|
||||
.child(self.render_downloads_list(snapshot, cx)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn render_downloads_list(snapshot: &BrowserSnapshot) -> AnyElement {
|
||||
fn render_downloads_list(
|
||||
&mut self,
|
||||
snapshot: &BrowserSnapshot,
|
||||
cx: &mut Context<Self>,
|
||||
) -> AnyElement {
|
||||
if snapshot.download_entries.is_empty() {
|
||||
return div()
|
||||
.flex_1()
|
||||
@@ -97,12 +109,17 @@ fn render_downloads_list(snapshot: &BrowserSnapshot) -> AnyElement {
|
||||
.iter()
|
||||
.rev()
|
||||
.enumerate()
|
||||
.map(|(index, entry)| render_download_row(index, entry)),
|
||||
.map(|(index, entry)| self.render_download_row(index, entry, cx)),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
}
|
||||
|
||||
fn render_download_row(index: usize, entry: &DownloadEntry) -> AnyElement {
|
||||
fn render_download_row(
|
||||
&mut self,
|
||||
index: usize,
|
||||
entry: &DownloadEntry,
|
||||
cx: &mut Context<Self>,
|
||||
) -> AnyElement {
|
||||
div()
|
||||
.id(SharedString::from(format!("download-{index}")))
|
||||
.py_3()
|
||||
@@ -161,6 +178,13 @@ fn render_download_row(index: usize, entry: &DownloadEntry) -> AnyElement {
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
.items_center()
|
||||
.justify_end()
|
||||
.gap_3()
|
||||
.child(
|
||||
div()
|
||||
.min_w(px(92.0))
|
||||
.flex()
|
||||
.flex_col()
|
||||
.items_end()
|
||||
@@ -179,7 +203,91 @@ fn render_download_row(index: usize, entry: &DownloadEntry) -> AnyElement {
|
||||
.child(download_size_label(entry)),
|
||||
),
|
||||
)
|
||||
.child(self.render_download_actions(index, entry, cx)),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
fn render_download_actions(
|
||||
&mut self,
|
||||
index: usize,
|
||||
entry: &DownloadEntry,
|
||||
cx: &mut Context<Self>,
|
||||
) -> AnyElement {
|
||||
div()
|
||||
.w(px(64.0))
|
||||
.flex()
|
||||
.items_center()
|
||||
.justify_end()
|
||||
.gap_1()
|
||||
.when(matches!(entry.state(), DownloadState::InProgress), |this| {
|
||||
let pause_id = entry.id().clone();
|
||||
let cancel_id = entry.id().clone();
|
||||
|
||||
this.child(
|
||||
download_action_button("pause", index, IconName::Minus, "Pause Download")
|
||||
.on_click(cx.listener(move |shell, _, _, cx| {
|
||||
shell.pause_download(&pause_id, cx);
|
||||
}))
|
||||
.into_any_element(),
|
||||
)
|
||||
.child(
|
||||
download_action_button("cancel", index, IconName::Close, "Cancel Download")
|
||||
.on_click(cx.listener(move |shell, _, _, cx| {
|
||||
shell.cancel_download(&cancel_id, cx);
|
||||
}))
|
||||
.into_any_element(),
|
||||
)
|
||||
})
|
||||
.when(matches!(entry.state(), DownloadState::Paused), |this| {
|
||||
let resume_id = entry.id().clone();
|
||||
let cancel_id = entry.id().clone();
|
||||
|
||||
this.child(
|
||||
download_action_button(
|
||||
"resume",
|
||||
index,
|
||||
IconName::ArrowRight,
|
||||
"Resume Download",
|
||||
)
|
||||
.on_click(cx.listener(move |shell, _, _, cx| {
|
||||
shell.resume_download(&resume_id, cx);
|
||||
}))
|
||||
.into_any_element(),
|
||||
)
|
||||
.child(
|
||||
download_action_button("cancel", index, IconName::Close, "Cancel Download")
|
||||
.on_click(cx.listener(move |shell, _, _, cx| {
|
||||
shell.cancel_download(&cancel_id, cx);
|
||||
}))
|
||||
.into_any_element(),
|
||||
)
|
||||
})
|
||||
.when(
|
||||
matches!(entry.state(), DownloadState::Cancelled | DownloadState::Failed),
|
||||
|this| {
|
||||
let retry_id = entry.id().clone();
|
||||
|
||||
this.child(
|
||||
download_action_button("retry", index, IconName::Undo2, "Retry Download")
|
||||
.on_click(cx.listener(move |shell, _, _, cx| {
|
||||
shell.retry_download(&retry_id, cx);
|
||||
}))
|
||||
.into_any_element(),
|
||||
)
|
||||
},
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
}
|
||||
|
||||
fn download_action_button(
|
||||
action: &'static str,
|
||||
index: usize,
|
||||
icon: IconName,
|
||||
tooltip: &'static str,
|
||||
) -> Button {
|
||||
Button::new((action, index)).ghost().xsmall().icon(icon).tooltip(tooltip)
|
||||
}
|
||||
|
||||
fn download_state_label(state: &DownloadState) -> &'static str {
|
||||
|
||||
@@ -2,7 +2,7 @@ mod internal_pages;
|
||||
mod render;
|
||||
|
||||
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
|
||||
use ely_domain::{CommandIntent, SpaceId, TabId, UrlText};
|
||||
use ely_domain::{CommandIntent, DownloadId, SpaceId, TabId, UrlText};
|
||||
use gpui::{App, AppContext, Context, Entity, FocusHandle, Focusable, Subscription, Window};
|
||||
use gpui_component::input::{InputEvent, InputState, SelectAll};
|
||||
|
||||
@@ -215,6 +215,38 @@ impl ElyShell {
|
||||
}
|
||||
}
|
||||
|
||||
fn pause_download(&mut self, download_id: &DownloadId, cx: &mut Context<Self>) {
|
||||
if let ShellState::Ready(core) = &mut self.state
|
||||
&& core.pause_download(download_id).is_ok()
|
||||
{
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
fn resume_download(&mut self, download_id: &DownloadId, cx: &mut Context<Self>) {
|
||||
if let ShellState::Ready(core) = &mut self.state
|
||||
&& core.resume_download(download_id).is_ok()
|
||||
{
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
fn cancel_download(&mut self, download_id: &DownloadId, cx: &mut Context<Self>) {
|
||||
if let ShellState::Ready(core) = &mut self.state
|
||||
&& core.cancel_download(download_id).is_ok()
|
||||
{
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
fn retry_download(&mut self, download_id: &DownloadId, cx: &mut Context<Self>) {
|
||||
if let ShellState::Ready(core) = &mut self.state
|
||||
&& core.retry_download(download_id).is_ok()
|
||||
{
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
fn on_close_current_tab(
|
||||
&mut self,
|
||||
_: &CloseCurrentTab,
|
||||
|
||||
Reference in New Issue
Block a user