chore: remove trivial single-use helper functions
This commit is contained in:
@@ -40,11 +40,6 @@ impl SkinShared {
|
||||
pub(crate) fn resizing_dock(&self) -> &Cell<Option<DockPlacement>> {
|
||||
&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`].
|
||||
@@ -74,16 +69,6 @@ impl SignedDockSkin {
|
||||
pub(crate) fn shared(&self) -> &Rc<SkinShared> {
|
||||
&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.
|
||||
|
||||
@@ -25,19 +25,6 @@ pub fn add_center_panel(
|
||||
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.
|
||||
pub const TAB_BAR_HEIGHT: Pixels = px(44.);
|
||||
|
||||
|
||||
@@ -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 panel must offer a control and be zoomable, base refuses a zoom otherwise.
|
||||
@@ -542,7 +537,9 @@ impl SignedTabGroupSkin {
|
||||
|
||||
impl TabGroupRenderer for SignedTabGroupSkin {
|
||||
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.
|
||||
if group.panels().is_empty() {
|
||||
return div().id("tab-panel");
|
||||
|
||||
@@ -109,14 +109,10 @@ pub struct LocalReposSettings {
|
||||
pub scan_paths: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
fn default_scan_paths() -> Vec<PathBuf> {
|
||||
vec![paths::desktop_dir(), paths::documents_dir()]
|
||||
}
|
||||
|
||||
impl Default for LocalReposSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
scan_paths: default_scan_paths(),
|
||||
scan_paths: vec![paths::desktop_dir(), paths::documents_dir()],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,16 +40,13 @@ pub fn is_repo_kind(kind: Kind) -> bool {
|
||||
|| 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
|
||||
.tags
|
||||
.iter()
|
||||
.find(|tag| tag.kind() == name)
|
||||
.and_then(|tag| tag.content())
|
||||
}
|
||||
|
||||
fn tag_kind(event: &Event, name: &str) -> Option<Kind> {
|
||||
tag_value(event, name)?.parse::<Kind>().ok()
|
||||
.and_then(|value| value.parse::<Kind>().ok())
|
||||
}
|
||||
|
||||
pub struct Filters;
|
||||
|
||||
@@ -253,7 +253,12 @@ impl PatchParser {
|
||||
kind,
|
||||
old: old_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,
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
|
||||
@@ -903,6 +903,7 @@ impl Backend {
|
||||
}
|
||||
|
||||
fn sync_inbox(&mut self, cx: &mut Context<Self>) {
|
||||
let repo_store = RepoListStore::global(cx);
|
||||
let client = self.client.clone();
|
||||
let me = self.current_user;
|
||||
|
||||
@@ -910,7 +911,7 @@ impl Backend {
|
||||
self.subscribe_bootstrap(Filters::notifications(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)
|
||||
.announcements_of(&me)
|
||||
.into_iter()
|
||||
@@ -944,9 +945,11 @@ impl Backend {
|
||||
this.signer.swap_inner(new_signer);
|
||||
this.current_user = Some(public_key);
|
||||
this.passphrase_required = false;
|
||||
|
||||
this.bootstrap_user(public_key, cx);
|
||||
cx.emit(BackendEvent::SignerChanged);
|
||||
this.sync_inbox(cx);
|
||||
|
||||
cx.emit(BackendEvent::SignerChanged);
|
||||
cx.notify();
|
||||
})?;
|
||||
}
|
||||
@@ -974,7 +977,7 @@ impl Backend {
|
||||
|
||||
let client = self.client.clone();
|
||||
|
||||
cx.spawn(async move |_this, _cx| {
|
||||
cx.background_spawn(async move {
|
||||
let connected: Result<(), Error> = async {
|
||||
for url in relays.iter() {
|
||||
client.add_relay(url).and_connect().await?;
|
||||
|
||||
@@ -72,14 +72,6 @@ fn grasp_list_servers(event: &Event) -> Vec<RelayUrl> {
|
||||
.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(
|
||||
client: &Client,
|
||||
user: PublicKey,
|
||||
@@ -90,5 +82,12 @@ pub async fn user_grasp_list_servers(
|
||||
.await?
|
||||
.into_iter()
|
||||
.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)
|
||||
}
|
||||
|
||||
@@ -405,7 +405,7 @@ impl RepoStore {
|
||||
utils::sort_newest_first(&mut issues);
|
||||
utils::sort_newest_first(&mut patches);
|
||||
utils::sort_newest_first(&mut pull_requests);
|
||||
utils::sort_oldest_first(&mut comments);
|
||||
comments.sort_by_key(|comment| comment.created_at);
|
||||
|
||||
let maintainers = announcement
|
||||
.as_ref()
|
||||
|
||||
@@ -6,4 +6,4 @@ mod time;
|
||||
pub use pubkey::shorten_pubkey;
|
||||
pub use repo_url::same_repo_url;
|
||||
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};
|
||||
|
||||
@@ -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>
|
||||
where
|
||||
I: IntoIterator<Item = Event>,
|
||||
|
||||
@@ -169,21 +169,6 @@ impl RepoListView {
|
||||
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(
|
||||
&self,
|
||||
ix: usize,
|
||||
@@ -311,7 +296,13 @@ impl RepoListView {
|
||||
.on_click(cx.listener({
|
||||
let announcement = announcement.clone();
|
||||
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()
|
||||
|
||||
@@ -10,7 +10,6 @@ use gpui_component::form::{field, v_form};
|
||||
use gpui_component::input::{Input, InputState, Textarea};
|
||||
use gpui_component::{Disableable, IconName, WindowExt, h_flex};
|
||||
use settings::SettingsStore;
|
||||
use signed_core::Announcement;
|
||||
use signed_state::{Backend, CheckoutsStore};
|
||||
|
||||
use super::super::open_repo_panel;
|
||||
@@ -232,7 +231,13 @@ fn create_repository(
|
||||
store.record(local_path.clone(), announcement.addr(), cx);
|
||||
});
|
||||
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();
|
||||
}
|
||||
@@ -245,18 +250,3 @@ fn create_repository(
|
||||
})
|
||||
.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,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -238,25 +238,6 @@ impl SidebarPanel {
|
||||
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.
|
||||
fn open_local_repo(
|
||||
&mut self,
|
||||
@@ -370,7 +351,11 @@ impl SidebarPanel {
|
||||
.small()
|
||||
.ghost()
|
||||
.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(
|
||||
cx.listener(move |this, _ev, window, cx| this.open_repo(&announcement, window, cx)),
|
||||
)
|
||||
row.on_click(cx.listener(move |this, _ev, window, cx| {
|
||||
open_repo_panel(
|
||||
&this.dock_area,
|
||||
&announcement.addr(),
|
||||
Some(&announcement),
|
||||
window,
|
||||
&mut *cx,
|
||||
);
|
||||
}))
|
||||
}
|
||||
|
||||
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.
|
||||
fn render_user(
|
||||
&self,
|
||||
@@ -619,8 +606,8 @@ impl SidebarPanel {
|
||||
.hover(|this| this.bg(gpui::white().opacity(0.2)))
|
||||
.active(|this| this.bg(gpui::white().opacity(0.4)))
|
||||
.child(div().text_sm().child("Import identity"))
|
||||
.on_click(cx.listener(|this, _ev, window, cx| {
|
||||
this.open_import(window, cx)
|
||||
.on_click(cx.listener(|_this, _ev, window, cx| {
|
||||
import_dialog::open(window, cx)
|
||||
})),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user