Wire download row controls
This commit is contained in:
@@ -19,7 +19,7 @@ impl ElyShell {
|
|||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> AnyElement {
|
) -> AnyElement {
|
||||||
match tab.url().as_str() {
|
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://history" => self.render_history_page(snapshot, cx),
|
||||||
"ely://archive" => self.render_archive_page(snapshot, cx),
|
"ely://archive" => self.render_archive_page(snapshot, cx),
|
||||||
_ => render_default_page(tab),
|
_ => render_default_page(tab),
|
||||||
|
|||||||
@@ -5,14 +5,23 @@ use ely_domain::{
|
|||||||
};
|
};
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
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};
|
use super::{ElyShell, render_canvas_surface};
|
||||||
|
|
||||||
impl ElyShell {
|
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(
|
render_canvas_surface(
|
||||||
div()
|
div()
|
||||||
.size_full()
|
.size_full()
|
||||||
@@ -66,120 +75,219 @@ 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(
|
||||||
if snapshot.download_entries.is_empty() {
|
&mut self,
|
||||||
return div()
|
snapshot: &BrowserSnapshot,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) -> AnyElement {
|
||||||
|
if snapshot.download_entries.is_empty() {
|
||||||
|
return div()
|
||||||
|
.flex_1()
|
||||||
|
.border_t_1()
|
||||||
|
.border_color(rgb(colors::HAIRLINE))
|
||||||
|
.pt_5()
|
||||||
|
.text_sm()
|
||||||
|
.text_color(rgb(colors::MUTED))
|
||||||
|
.child("Downloads are empty for this Profile.")
|
||||||
|
.into_any_element();
|
||||||
|
}
|
||||||
|
|
||||||
|
div()
|
||||||
.flex_1()
|
.flex_1()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.overflow_y_scrollbar()
|
||||||
.border_t_1()
|
.border_t_1()
|
||||||
.border_color(rgb(colors::HAIRLINE))
|
.border_color(rgb(colors::HAIRLINE))
|
||||||
.pt_5()
|
.children(
|
||||||
.text_sm()
|
snapshot
|
||||||
.text_color(rgb(colors::MUTED))
|
.download_entries
|
||||||
.child("Downloads are empty for this Profile.")
|
.iter()
|
||||||
.into_any_element();
|
.rev()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(index, entry)| self.render_download_row(index, entry, cx)),
|
||||||
|
)
|
||||||
|
.into_any_element()
|
||||||
}
|
}
|
||||||
|
|
||||||
div()
|
fn render_download_row(
|
||||||
.flex_1()
|
&mut self,
|
||||||
.flex()
|
index: usize,
|
||||||
.flex_col()
|
entry: &DownloadEntry,
|
||||||
.overflow_y_scrollbar()
|
cx: &mut Context<Self>,
|
||||||
.border_t_1()
|
) -> AnyElement {
|
||||||
.border_color(rgb(colors::HAIRLINE))
|
div()
|
||||||
.children(
|
.id(SharedString::from(format!("download-{index}")))
|
||||||
snapshot
|
.py_3()
|
||||||
.download_entries
|
.border_b_1()
|
||||||
.iter()
|
.border_color(rgb(colors::HAIRLINE))
|
||||||
.rev()
|
.flex()
|
||||||
.enumerate()
|
.items_center()
|
||||||
.map(|(index, entry)| render_download_row(index, entry)),
|
.justify_between()
|
||||||
)
|
.gap_4()
|
||||||
.into_any_element()
|
.child(
|
||||||
}
|
div()
|
||||||
|
.min_w_0()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.gap_3()
|
||||||
|
.child(div().text_color(rgb(colors::MUTED)).child(IconName::File))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.min_w_0()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_1()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_sm()
|
||||||
|
.font_semibold()
|
||||||
|
.truncate()
|
||||||
|
.text_color(rgb(colors::INK))
|
||||||
|
.child(entry.file_name().to_string()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.truncate()
|
||||||
|
.text_color(rgb(colors::MUTED))
|
||||||
|
.child(entry.source_url().display_url()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.gap_2()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(rgb(colors::MUTED))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.min_w_0()
|
||||||
|
.truncate()
|
||||||
|
.child(download_destination_label(entry.destination())),
|
||||||
|
)
|
||||||
|
.when(entry.security().requires_prompt(), |this| {
|
||||||
|
this.child(render_security_prompt(entry.security()))
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.justify_end()
|
||||||
|
.gap_3()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.min_w(px(92.0))
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.items_end()
|
||||||
|
.gap_1()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.font_semibold()
|
||||||
|
.text_color(rgb(colors::BODY))
|
||||||
|
.child(download_state_label(entry.state())),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(rgb(colors::MUTED))
|
||||||
|
.child(download_size_label(entry)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(self.render_download_actions(index, entry, cx)),
|
||||||
|
)
|
||||||
|
.into_any_element()
|
||||||
|
}
|
||||||
|
|
||||||
fn render_download_row(index: usize, entry: &DownloadEntry) -> AnyElement {
|
fn render_download_actions(
|
||||||
div()
|
&mut self,
|
||||||
.id(SharedString::from(format!("download-{index}")))
|
index: usize,
|
||||||
.py_3()
|
entry: &DownloadEntry,
|
||||||
.border_b_1()
|
cx: &mut Context<Self>,
|
||||||
.border_color(rgb(colors::HAIRLINE))
|
) -> AnyElement {
|
||||||
.flex()
|
div()
|
||||||
.items_center()
|
.w(px(64.0))
|
||||||
.justify_between()
|
.flex()
|
||||||
.gap_4()
|
.items_center()
|
||||||
.child(
|
.justify_end()
|
||||||
div()
|
.gap_1()
|
||||||
.min_w_0()
|
.when(matches!(entry.state(), DownloadState::InProgress), |this| {
|
||||||
.flex()
|
let pause_id = entry.id().clone();
|
||||||
.items_center()
|
let cancel_id = entry.id().clone();
|
||||||
.gap_3()
|
|
||||||
.child(div().text_color(rgb(colors::MUTED)).child(IconName::File))
|
this.child(
|
||||||
.child(
|
download_action_button("pause", index, IconName::Minus, "Pause Download")
|
||||||
div()
|
.on_click(cx.listener(move |shell, _, _, cx| {
|
||||||
.min_w_0()
|
shell.pause_download(&pause_id, cx);
|
||||||
.flex()
|
}))
|
||||||
.flex_col()
|
.into_any_element(),
|
||||||
.gap_1()
|
|
||||||
.child(
|
|
||||||
div()
|
|
||||||
.text_sm()
|
|
||||||
.font_semibold()
|
|
||||||
.truncate()
|
|
||||||
.text_color(rgb(colors::INK))
|
|
||||||
.child(entry.file_name().to_string()),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
div()
|
|
||||||
.text_xs()
|
|
||||||
.truncate()
|
|
||||||
.text_color(rgb(colors::MUTED))
|
|
||||||
.child(entry.source_url().display_url()),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
div()
|
|
||||||
.flex()
|
|
||||||
.items_center()
|
|
||||||
.gap_2()
|
|
||||||
.text_xs()
|
|
||||||
.text_color(rgb(colors::MUTED))
|
|
||||||
.child(
|
|
||||||
div()
|
|
||||||
.min_w_0()
|
|
||||||
.truncate()
|
|
||||||
.child(download_destination_label(entry.destination())),
|
|
||||||
)
|
|
||||||
.when(entry.security().requires_prompt(), |this| {
|
|
||||||
this.child(render_security_prompt(entry.security()))
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
div()
|
|
||||||
.flex()
|
|
||||||
.flex_col()
|
|
||||||
.items_end()
|
|
||||||
.gap_1()
|
|
||||||
.child(
|
|
||||||
div()
|
|
||||||
.text_xs()
|
|
||||||
.font_semibold()
|
|
||||||
.text_color(rgb(colors::BODY))
|
|
||||||
.child(download_state_label(entry.state())),
|
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
div()
|
download_action_button("cancel", index, IconName::Close, "Cancel Download")
|
||||||
.text_xs()
|
.on_click(cx.listener(move |shell, _, _, cx| {
|
||||||
.text_color(rgb(colors::MUTED))
|
shell.cancel_download(&cancel_id, cx);
|
||||||
.child(download_size_label(entry)),
|
}))
|
||||||
),
|
.into_any_element(),
|
||||||
)
|
)
|
||||||
.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 {
|
fn download_state_label(state: &DownloadState) -> &'static str {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ mod internal_pages;
|
|||||||
mod render;
|
mod render;
|
||||||
|
|
||||||
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
|
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::{App, AppContext, Context, Entity, FocusHandle, Focusable, Subscription, Window};
|
||||||
use gpui_component::input::{InputEvent, InputState, SelectAll};
|
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(
|
fn on_close_current_tab(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: &CloseCurrentTab,
|
_: &CloseCurrentTab,
|
||||||
|
|||||||
Reference in New Issue
Block a user