chore: remove trivial single-use helper functions
Rust / build (macos-latest, stable) (push) Canceled after 0s
Rust / build (ubuntu-latest, stable) (push) Canceled after 0s
Rust / build (windows-latest, stable) (push) Canceled after 0s

This commit is contained in:
2026-10-06 10:20:28 +07:00
parent a4df8e5731
commit cd72b25626
14 changed files with 58 additions and 130 deletions
-15
View File
@@ -40,11 +40,6 @@ impl SkinShared {
pub(crate) fn resizing_dock(&self) -> &Cell<Option<DockPlacement>> { pub(crate) fn resizing_dock(&self) -> &Cell<Option<DockPlacement>> {
&self.resizing_dock &self.resizing_dock
} }
/// Redraw the area after a setting changed. The skin is not an entity, so nothing else would.
pub(crate) fn notify(&self, cx: &mut App) {
_ = self.area.update(cx, |_, cx| cx.notify());
}
} }
/// The Signed appearance for a [`DockArea`]. /// The Signed appearance for a [`DockArea`].
@@ -74,16 +69,6 @@ impl SignedDockSkin {
pub(crate) fn shared(&self) -> &Rc<SkinShared> { pub(crate) fn shared(&self) -> &Rc<SkinShared> {
&self.shared &self.shared
} }
/// Whether tab bars offer the affordance that collapses a neighbouring dock.
pub fn is_toggle_button_visible(&self) -> bool {
self.shared.is_toggle_button_visible()
}
pub fn set_toggle_button_visible(&self, visible: bool, cx: &mut App) {
self.shared.toggle_button_visible.set(visible);
self.shared.notify(cx);
}
} }
/// Payload a dock's resize handle drags. /// Payload a dock's resize handle drags.
-13
View File
@@ -25,19 +25,6 @@ pub fn add_center_panel(
area.add_panel_view(panel, DockPlacement::Center, None, window, cx); area.add_panel_view(panel, DockPlacement::Center, None, window, cx);
} }
/// Add an already-wrapped panel handle to the bottom dock of `area`.
///
/// Used for sub-views that hang under the center, such as the inbox's Unread
/// and Archived lists.
pub fn add_bottom_panel(
area: &mut DockArea,
panel: Arc<dyn PanelView>,
window: &mut Window,
cx: &mut Context<DockArea>,
) {
area.add_panel_view(panel, DockPlacement::Bottom, None, window, cx);
}
/// The fixed height of the tab bar, which doubles as the window title bar. /// The fixed height of the tab bar, which doubles as the window title bar.
pub const TAB_BAR_HEIGHT: Pixels = px(44.); pub const TAB_BAR_HEIGHT: Pixels = px(44.);
+3 -6
View File
@@ -71,11 +71,6 @@ impl Render for DragPanelPreview {
} }
} }
/// The zoom affordance for the group's displayed panel, if it offers one.
fn zoom_control(group: &TabGroupContext, cx: &App) -> Option<PanelControl> {
panel_zoom_control(group.active_panel()?, cx)
}
/// The zoom affordance `panel` offers, if any. /// The zoom affordance `panel` offers, if any.
/// ///
/// The panel must offer a control and be zoomable, base refuses a zoom otherwise. /// The panel must offer a control and be zoomable, base refuses a zoom otherwise.
@@ -542,7 +537,9 @@ impl SignedTabGroupSkin {
impl TabGroupRenderer for SignedTabGroupSkin { impl TabGroupRenderer for SignedTabGroupSkin {
fn frame(&self, group: &TabGroupContext, _: &mut Window, cx: &mut App) -> Stateful<Div> { fn frame(&self, group: &TabGroupContext, _: &mut Window, cx: &mut App) -> Stateful<Div> {
let control = zoom_control(group, cx); let control = group
.active_panel()
.and_then(|panel| panel_zoom_control(panel, cx));
// An emptied group draws nothing, so no bare tab bar is left behind. // An emptied group draws nothing, so no bare tab bar is left behind.
if group.panels().is_empty() { if group.panels().is_empty() {
return div().id("tab-panel"); return div().id("tab-panel");
+1 -5
View File
@@ -109,14 +109,10 @@ pub struct LocalReposSettings {
pub scan_paths: Vec<PathBuf>, pub scan_paths: Vec<PathBuf>,
} }
fn default_scan_paths() -> Vec<PathBuf> {
vec![paths::desktop_dir(), paths::documents_dir()]
}
impl Default for LocalReposSettings { impl Default for LocalReposSettings {
fn default() -> Self { fn default() -> Self {
Self { Self {
scan_paths: default_scan_paths(), scan_paths: vec![paths::desktop_dir(), paths::documents_dir()],
} }
} }
} }
+2 -5
View File
@@ -40,16 +40,13 @@ pub fn is_repo_kind(kind: Kind) -> bool {
|| ACTIVITY_KINDS.contains(&kind) || ACTIVITY_KINDS.contains(&kind)
} }
fn tag_value<'a>(event: &'a Event, name: &str) -> Option<&'a str> { fn tag_kind(event: &Event, name: &str) -> Option<Kind> {
event event
.tags .tags
.iter() .iter()
.find(|tag| tag.kind() == name) .find(|tag| tag.kind() == name)
.and_then(|tag| tag.content()) .and_then(|tag| tag.content())
} .and_then(|value| value.parse::<Kind>().ok())
fn tag_kind(event: &Event, name: &str) -> Option<Kind> {
tag_value(event, name)?.parse::<Kind>().ok()
} }
pub struct Filters; pub struct Filters;
+6 -6
View File
@@ -253,7 +253,12 @@ impl PatchParser {
kind, kind,
old: old_no, old: old_no,
new: new_no, new: new_no,
text: Self::line_text(text), text: text
.strip_suffix('\n')
.unwrap_or(text)
.strip_suffix('\r')
.unwrap_or(text)
.to_owned(),
}); });
} }
@@ -265,11 +270,6 @@ impl PatchParser {
lines, lines,
} }
} }
fn line_text(text: &str) -> String {
let text = text.strip_suffix('\n').unwrap_or(text);
text.strip_suffix('\r').unwrap_or(text).to_owned()
}
} }
// A `git format-patch` mbox message, split on its `From <40-hex> <date>` envelope. // A `git format-patch` mbox message, split on its `From <40-hex> <date>` envelope.
+6 -3
View File
@@ -903,6 +903,7 @@ impl Backend {
} }
fn sync_inbox(&mut self, cx: &mut Context<Self>) { fn sync_inbox(&mut self, cx: &mut Context<Self>) {
let repo_store = RepoListStore::global(cx);
let client = self.client.clone(); let client = self.client.clone();
let me = self.current_user; let me = self.current_user;
@@ -910,7 +911,7 @@ impl Backend {
self.subscribe_bootstrap(Filters::notifications(me), cx); self.subscribe_bootstrap(Filters::notifications(me), cx);
self.subscribe_bootstrap(vec![Filters::authored_activity(me)], cx); self.subscribe_bootstrap(vec![Filters::authored_activity(me)], cx);
let relays: HashSet<RelayUrl> = RepoListStore::global(cx) let relays: HashSet<RelayUrl> = repo_store
.read(cx) .read(cx)
.announcements_of(&me) .announcements_of(&me)
.into_iter() .into_iter()
@@ -944,9 +945,11 @@ impl Backend {
this.signer.swap_inner(new_signer); this.signer.swap_inner(new_signer);
this.current_user = Some(public_key); this.current_user = Some(public_key);
this.passphrase_required = false; this.passphrase_required = false;
this.bootstrap_user(public_key, cx); this.bootstrap_user(public_key, cx);
cx.emit(BackendEvent::SignerChanged);
this.sync_inbox(cx); this.sync_inbox(cx);
cx.emit(BackendEvent::SignerChanged);
cx.notify(); cx.notify();
})?; })?;
} }
@@ -974,7 +977,7 @@ impl Backend {
let client = self.client.clone(); let client = self.client.clone();
cx.spawn(async move |_this, _cx| { cx.background_spawn(async move {
let connected: Result<(), Error> = async { let connected: Result<(), Error> = async {
for url in relays.iter() { for url in relays.iter() {
client.add_relay(url).and_connect().await?; client.add_relay(url).and_connect().await?;
+8 -9
View File
@@ -72,14 +72,6 @@ fn grasp_list_servers(event: &Event) -> Vec<RelayUrl> {
.collect() .collect()
} }
fn latest_grasp_list_servers(events: Vec<Event>) -> Vec<RelayUrl> {
events
.into_iter()
.max_by_key(|event| event.created_at)
.map(|event| grasp_list_servers(&event))
.unwrap_or_default()
}
pub async fn user_grasp_list_servers( pub async fn user_grasp_list_servers(
client: &Client, client: &Client,
user: PublicKey, user: PublicKey,
@@ -90,5 +82,12 @@ pub async fn user_grasp_list_servers(
.await? .await?
.into_iter() .into_iter()
.collect(); .collect();
Ok(latest_grasp_list_servers(events))
let latest = events
.into_iter()
.max_by_key(|event| event.created_at)
.map(|event| grasp_list_servers(&event))
.unwrap_or_default();
Ok(latest)
} }
+1 -1
View File
@@ -405,7 +405,7 @@ impl RepoStore {
utils::sort_newest_first(&mut issues); utils::sort_newest_first(&mut issues);
utils::sort_newest_first(&mut patches); utils::sort_newest_first(&mut patches);
utils::sort_newest_first(&mut pull_requests); utils::sort_newest_first(&mut pull_requests);
utils::sort_oldest_first(&mut comments); comments.sort_by_key(|comment| comment.created_at);
let maintainers = announcement let maintainers = announcement
.as_ref() .as_ref()
+1 -1
View File
@@ -6,4 +6,4 @@ mod time;
pub use pubkey::shorten_pubkey; pub use pubkey::shorten_pubkey;
pub use repo_url::same_repo_url; pub use repo_url::same_repo_url;
pub use text::{flatten_whitespace, middle_truncate}; pub use text::{flatten_whitespace, middle_truncate};
pub use time::{latest, relative_time, relative_time_secs, sort_newest_first, sort_oldest_first}; pub use time::{latest, relative_time, relative_time_secs, sort_newest_first};
-4
View File
@@ -8,10 +8,6 @@ pub fn sort_newest_first(events: &mut [Event]) {
}); });
} }
pub fn sort_oldest_first(events: &mut [Event]) {
events.sort_by_key(|e| e.created_at);
}
pub fn latest<I>(events: I) -> Option<Event> pub fn latest<I>(events: I) -> Option<Event>
where where
I: IntoIterator<Item = Event>, I: IntoIterator<Item = Event>,
+7 -16
View File
@@ -169,21 +169,6 @@ impl RepoListView {
cx.notify(); cx.notify();
} }
fn open_repo(
&mut self,
announcement: &Announcement,
window: &mut Window,
cx: &mut Context<Self>,
) {
open_repo_panel(
&self.dock_area,
&announcement.addr(),
Some(announcement),
window,
cx,
);
}
fn render_card( fn render_card(
&self, &self,
ix: usize, ix: usize,
@@ -311,7 +296,13 @@ impl RepoListView {
.on_click(cx.listener({ .on_click(cx.listener({
let announcement = announcement.clone(); let announcement = announcement.clone();
move |this, _ev, window, cx| { move |this, _ev, window, cx| {
this.open_repo(&announcement, window, cx); open_repo_panel(
&this.dock_area,
&announcement.addr(),
Some(&announcement),
window,
cx,
);
} }
})) }))
.into_any_element() .into_any_element()
@@ -10,7 +10,6 @@ use gpui_component::form::{field, v_form};
use gpui_component::input::{Input, InputState, Textarea}; use gpui_component::input::{Input, InputState, Textarea};
use gpui_component::{Disableable, IconName, WindowExt, h_flex}; use gpui_component::{Disableable, IconName, WindowExt, h_flex};
use settings::SettingsStore; use settings::SettingsStore;
use signed_core::Announcement;
use signed_state::{Backend, CheckoutsStore}; use signed_state::{Backend, CheckoutsStore};
use super::super::open_repo_panel; use super::super::open_repo_panel;
@@ -232,7 +231,13 @@ fn create_repository(
store.record(local_path.clone(), announcement.addr(), cx); store.record(local_path.clone(), announcement.addr(), cx);
}); });
cx.open_with_system(&local_path); cx.open_with_system(&local_path);
open_repo(dock_area, announcement, window, cx); open_repo_panel(
&dock_area,
&announcement.addr(),
Some(&announcement),
window,
cx,
);
}) })
.ok(); .ok();
} }
@@ -245,18 +250,3 @@ fn create_repository(
}) })
.detach(); .detach();
} }
fn open_repo(
dock_area: WeakEntity<DockArea>,
announcement: Announcement,
window: &mut Window,
cx: &mut App,
) {
open_repo_panel(
&dock_area,
&announcement.addr(),
Some(&announcement),
window,
cx,
);
}
+16 -29
View File
@@ -238,25 +238,6 @@ impl SidebarPanel {
onboarding_dialog::open(name_input, pass_input, repass_input, state, window, cx); onboarding_dialog::open(name_input, pass_input, repass_input, state, window, cx);
} }
fn open_create_repo(&mut self, window: &mut Window, cx: &mut Context<Self>) {
create_repo_dialog::open(self.dock_area.clone(), window, cx);
}
fn open_repo(
&mut self,
announcement: &Announcement,
window: &mut Window,
cx: &mut Context<Self>,
) {
open_repo_panel(
&self.dock_area,
&announcement.addr(),
Some(announcement),
window,
&mut *cx,
);
}
/// The detail view offers to publish it to NIP-34. /// The detail view offers to publish it to NIP-34.
fn open_local_repo( fn open_local_repo(
&mut self, &mut self,
@@ -370,7 +351,11 @@ impl SidebarPanel {
.small() .small()
.ghost() .ghost()
.on_click(cx.listener(|this, _ev, window, cx| { .on_click(cx.listener(|this, _ev, window, cx| {
this.open_create_repo(window, cx); create_repo_dialog::open(
this.dock_area.clone(),
window,
cx,
);
})), })),
), ),
), ),
@@ -470,9 +455,15 @@ impl SidebarPanel {
); );
} }
row.on_click( row.on_click(cx.listener(move |this, _ev, window, cx| {
cx.listener(move |this, _ev, window, cx| this.open_repo(&announcement, window, cx)), open_repo_panel(
) &this.dock_area,
&announcement.addr(),
Some(&announcement),
window,
&mut *cx,
);
}))
} }
fn render_local_row( fn render_local_row(
@@ -524,10 +515,6 @@ impl SidebarPanel {
})) }))
} }
fn open_import(&mut self, window: &mut Window, cx: &mut Context<Self>) {
import_dialog::open(window, cx);
}
/// The user avatar and name, wired into the titlebar drag area. /// The user avatar and name, wired into the titlebar drag area.
fn render_user( fn render_user(
&self, &self,
@@ -619,8 +606,8 @@ impl SidebarPanel {
.hover(|this| this.bg(gpui::white().opacity(0.2))) .hover(|this| this.bg(gpui::white().opacity(0.2)))
.active(|this| this.bg(gpui::white().opacity(0.4))) .active(|this| this.bg(gpui::white().opacity(0.4)))
.child(div().text_sm().child("Import identity")) .child(div().text_sm().child("Import identity"))
.on_click(cx.listener(|this, _ev, window, cx| { .on_click(cx.listener(|_this, _ev, window, cx| {
this.open_import(window, cx) import_dialog::open(window, cx)
})), })),
), ),
), ),