use std::sync::Arc; use gpui::{App, Entity, SharedString, WeakEntity, Window}; use ui::layout::panel::{Panel, PanelView}; use crate::app::AppRoot; /// Opens a repository in the main panel, reusing its tab when it is already open. pub fn open_primary( workspace: &WeakEntity, id: impl Into, build: F, window: &mut Window, cx: &mut App, ) where P: Panel + 'static, F: Fn(&mut Window, &mut App) -> Entity

+ 'static, { let id = id.into(); if workspace .read_with(cx, |app, cx| app.panel().read(cx).has(&id)) .unwrap_or(false) { if let Err(error) = workspace.update(cx, |app, cx| app.activate_main(&id, cx)) { log::warn!("failed to activate panel {id}: {error}"); } return; } let view: Arc = Arc::new(build(window, cx)); if let Err(error) = workspace.update(cx, |app, cx| app.open_main(id.clone(), view, cx)) { log::warn!("failed to open panel {id}: {error}"); } } /// Opens a detail tile beside the main panel, reusing it when it is already open. pub fn open_detail( workspace: &WeakEntity, id: impl Into, build: F, window: &mut Window, cx: &mut App, ) where P: Panel + 'static, F: Fn(&mut Window, &mut App) -> Entity

+ 'static, { let id = id.into(); if workspace .read_with(cx, |app, cx| app.panel().read(cx).has(&id)) .unwrap_or(false) { return; } let view: Arc = Arc::new(build(window, cx)); if let Err(error) = workspace.update(cx, |app, cx| app.open_detail(id.clone(), view, cx)) { log::warn!("failed to open panel {id}: {error}"); } }