Split pane chrome out of splits.rs into chrome::split_pane
splits.rs had grown to 551 lines after adding the design's pane header. Move the header renderer, the close glyph, the URL helpers, and the compact-canvas placeholder into chrome::split_pane so splits.rs is back to a 422-line action + render orchestrator and the new helpers stay under their own 150-line file. Behaviour preserved: the pane click still selects the tab, the close glyph still selects+closes, and pane_host/path/secure still derive from the same UrlText fields.
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
use ely_design_system::colors;
|
||||
use ely_domain::{BrowserTab, TabId};
|
||||
use gpui::{
|
||||
AnyElement, Context, FontWeight, InteractiveElement, IntoElement, ParentElement, SharedString,
|
||||
StatefulInteractiveElement, Styled, div, px, rgb, rgba,
|
||||
};
|
||||
use gpui_component::IconName;
|
||||
|
||||
use crate::shell::ElyShell;
|
||||
|
||||
pub(crate) fn render_split_pane_header(
|
||||
host: String,
|
||||
path: String,
|
||||
secure: bool,
|
||||
dot_color: u32,
|
||||
close_tab_id: TabId,
|
||||
cx: &mut Context<ElyShell>,
|
||||
) -> AnyElement {
|
||||
let lock_or_globe = if secure { IconName::Search } else { IconName::Globe };
|
||||
|
||||
div()
|
||||
.h(px(30.0))
|
||||
.px(px(10.0))
|
||||
.gap(px(8.0))
|
||||
.flex()
|
||||
.items_center()
|
||||
.flex_shrink_0()
|
||||
.border_b_1()
|
||||
.border_color(rgb(colors::HAIRLINE))
|
||||
.bg(rgb(0xf6f4ef))
|
||||
.child(div().size(px(8.0)).rounded_full().bg(rgb(dot_color)))
|
||||
.child(
|
||||
div()
|
||||
.text_color(rgb(colors::INK_3))
|
||||
.text_size(px(11.0))
|
||||
.child(lock_or_globe),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.text_size(px(11.0))
|
||||
.font_weight(FontWeight(500.0))
|
||||
.text_color(rgb(colors::INK))
|
||||
.child(host),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.truncate()
|
||||
.text_size(px(11.0))
|
||||
.text_color(rgb(colors::INK_4))
|
||||
.child(path),
|
||||
)
|
||||
.child(render_close_glyph(close_tab_id, cx))
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
fn render_close_glyph(close_tab_id: TabId, cx: &mut Context<ElyShell>) -> AnyElement {
|
||||
let id = format!("split-pane-close-{}", close_tab_id.as_str());
|
||||
div()
|
||||
.id(SharedString::from(id))
|
||||
.text_color(rgb(colors::INK_4))
|
||||
.text_size(px(11.0))
|
||||
.cursor_pointer()
|
||||
.hover(|style| style.text_color(rgb(colors::INK)))
|
||||
.on_click(cx.listener(move |shell, _, window, cx| {
|
||||
shell.select_tab(&close_tab_id, window, cx);
|
||||
shell.close_active_tab(window, cx);
|
||||
}))
|
||||
.child(IconName::Close)
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
pub(crate) fn pane_host_label(tab: &BrowserTab) -> String {
|
||||
tab.url()
|
||||
.host()
|
||||
.map(|host| host.to_string())
|
||||
.unwrap_or_else(|| tab.title().to_string())
|
||||
}
|
||||
|
||||
pub(crate) fn pane_path_label(tab: &BrowserTab) -> String {
|
||||
let url = tab.url().as_str();
|
||||
let path_start = url.find("://").map(|prefix| prefix + 3).unwrap_or(0);
|
||||
let from_path = &url[path_start..];
|
||||
match from_path.find('/') {
|
||||
Some(slash) => from_path[slash..].to_string(),
|
||||
None => String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn pane_url_is_secure(tab: &BrowserTab) -> bool {
|
||||
let url = tab.url().as_str();
|
||||
url.starts_with("https://") || url.starts_with("ely://")
|
||||
}
|
||||
|
||||
pub(crate) fn split_canvas_status(tab: &BrowserTab) -> String {
|
||||
if tab.url().as_str() == "ely://new-tab" {
|
||||
"Ready".to_string()
|
||||
} else {
|
||||
tab.display_url()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn render_compact_split_canvas(tab: &BrowserTab) -> AnyElement {
|
||||
div()
|
||||
.flex_1()
|
||||
.min_h_0()
|
||||
.p(px(8.0))
|
||||
.child(
|
||||
div()
|
||||
.size_full()
|
||||
.min_h_0()
|
||||
.rounded(px(10.0))
|
||||
.bg(rgba(colors::GLASS_2))
|
||||
.px(px(10.0))
|
||||
.py(px(8.0))
|
||||
.gap(px(8.0))
|
||||
.flex()
|
||||
.items_center()
|
||||
.child(div().text_color(rgb(colors::INK_4)).child(IconName::Globe))
|
||||
.child(
|
||||
div()
|
||||
.min_w_0()
|
||||
.flex()
|
||||
.flex_col()
|
||||
.child(
|
||||
div()
|
||||
.truncate()
|
||||
.text_size(px(13.0))
|
||||
.font_weight(FontWeight(500.0))
|
||||
.child(tab.title().to_string()),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.truncate()
|
||||
.text_size(px(11.0))
|
||||
.text_color(rgb(colors::INK_4))
|
||||
.child(split_canvas_status(tab)),
|
||||
),
|
||||
),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
Reference in New Issue
Block a user