| @@ -15,10 +15,9 @@ use std::{ |
| 15 | 15 | |
| 16 | 16 | use gpui_kit::component::{ |
| 17 | 17 | ActiveTheme as _, Icon, IconName, WindowExt as _, |
| 18 | | - button::ButtonVariant, |
| 19 | 18 | h_flex, |
| 20 | | - input::{Input, InputEvent, InputState}, |
| 21 | | - menu::{ContextMenuExt as _, DropdownMenu as _, PopupMenu, PopupMenuItem}, |
| 19 | + input::{InputEvent, InputState}, |
| 20 | + menu::{DropdownMenu as _, PopupMenu, PopupMenuItem}, |
| 22 | 21 | notification::Notification, |
| 23 | 22 | v_flex, |
| 24 | 23 | }; |
| @@ -27,27 +26,39 @@ use gpui_kit::*; |
| 27 | 26 | |
| 28 | 27 | use crate::browser; |
| 29 | 28 | use crate::claude::PermissionMode; |
| 30 | | - use crate::clock; |
| 31 | 29 | use crate::git::{self, GitInfo}; |
| 32 | 30 | use crate::models::{Catalog, ModelEntry, Provider, split_key}; |
| 33 | | - use crate::session::{NewSession, Reasoning, Session, SessionStatus, from_millis, to_millis}; |
| 31 | + use crate::session::{NewSession, Reasoning, Session, from_millis, to_millis}; |
| 34 | 32 | use crate::settings::{self, BackgroundActivity, ProjectOrder, WorkspaceMode}; |
| 35 | 33 | use crate::store::{self, AppState, SavedProject}; |
| 36 | | - use crate::ui::browser::{BrowserPanel, BrowserPanelEvent, BrowserWatch}; |
| 34 | + use crate::ui::browser::{BrowserPanel, BrowserPanelEvent}; |
| 37 | 35 | use crate::ui::chat::{ChatEvent, ChatView, display_path}; |
| 38 | 36 | use crate::ui::folder_browser::{self, FolderBrowser, FolderBrowserEvent}; |
| 39 | 37 | use crate::ui::icons::Lucide; |
| 40 | | - use crate::ui::metal::{self, Led, MetalButton, MetalStyled as _, Palette}; |
| 41 | | - use crate::ui::pickers; |
| 38 | + use crate::ui::metal::{self, MetalButton, MetalStyled as _, Palette}; |
| 42 | 39 | use crate::ui::settings::{SettingsEvent, SettingsView}; |
| 43 | 40 | use crate::worktree::{self, Worktree, WorktreePlan}; |
| 44 | | - use crate::{FocusSearch, NewThread, OpenProject, OpenSettings, ToggleBrowser, ToggleProjectPanel, ToggleSidebar}; |
| 41 | + use crate::{ |
| 42 | + CopyThreadReference, CycleAppearance, FocusSearch, NewThread, NewThreadLocal, NewThreadWithoutProject, NextThread, |
| 43 | + OpenProject, OpenSettings, OpenUsage, PinThread, PreviousThread, SelectTheme, SettleThread, ToggleBrowser, |
| 44 | + ToggleCommandPalette, ToggleProjectPanel, ToggleRightPanel, ToggleSidebar, UndoThreadAction, |
| 45 | + }; |
| 45 | 46 | |
| 47 | + mod actions; |
| 48 | + mod header; |
| 49 | + mod palette; |
| 46 | 50 | mod remote; |
| 51 | + mod sidebar; |
| 47 | 52 | |
| 53 | + use actions::UndoEntry; |
| 54 | + use palette::CommandPalette; |
| 48 | 55 | use remote::RemoteState; |
| 49 | 56 | |
| 50 | 57 | pub(crate) const SIDEBAR_WIDTH: f32 = 280.; |
| 58 | + /// The narrowest the thread sidebar drags to, and how much room it leaves |
| 59 | + /// the conversation. |
| 60 | + const SIDEBAR_MIN_WIDTH: f32 = 208.; |
| 61 | + const MAIN_MIN_WIDTH: f32 = 640.; |
| 51 | 62 | const PANEL_WIDTH: f32 = 292.; |
| 52 | 63 | /// Below this window width the project panel stays out of the conversation's way. |
| 53 | 64 | const PANEL_MIN_WINDOW: f32 = 1120.; |
| @@ -55,6 +66,8 @@ const PANEL_MIN_WINDOW: f32 = 1120.; |
| 55 | 66 | pub(crate) const SHEET_INSET: f32 = 8.; |
| 56 | 67 | pub(crate) const SHEET_RADIUS: f32 = 24.; |
| 57 | 68 | const TICK: Duration = Duration::from_secs(2); |
| 69 | + /// How long Ctrl is held before the Ctrl+1–9 hints show. |
| 70 | + const JUMP_HINT_DELAY: Duration = Duration::from_millis(200); |
| 58 | 71 | const GIT_POLL: Duration = Duration::from_secs(4); |
| 59 | 72 | const HOUSEKEEPING: Duration = Duration::from_secs(15); |
| 60 | 73 | const PR_CHECK: Duration = Duration::from_secs(300); |
| @@ -126,11 +139,35 @@ struct Project { |
| 126 | 139 | git: Option<GitInfo>, |
| 127 | 140 | /// The remote connection it's on, by id; `None` on this device. |
| 128 | 141 | environment: Option<String>, |
| 142 | + /// The repository it's in (its common directory) and its path inside |
| 143 | + /// the checkout, for grouping projects in the legacy sidebar. |
| 144 | + repo: Option<(PathBuf, PathBuf)>, |
| 129 | 145 | } |
| 130 | 146 | |
| 131 | 147 | /// A thread in the sidebar: its project's index and the session. |
| 132 | 148 | type ThreadEntry = (usize, Entity<Session>); |
| 133 | 149 | |
| 150 | + /// Names a project across changes to the list: its path, and the remote |
| 151 | + /// connection it's on (`None` for this device). |
| 152 | + pub(crate) type ProjectKey = (PathBuf, Option<String>); |
| 153 | + |
| 154 | + /// A thread title being edited in place, in the sidebar or the chat header. |
| 155 | + struct InlineRename { |
| 156 | + session: Entity<Session>, |
| 157 | + input: Entity<InputState>, |
| 158 | + /// In the sidebar row, rather than the chat header. |
| 159 | + sidebar: bool, |
| 160 | + _subscription: Subscription, |
| 161 | + } |
| 162 | + |
| 163 | + /// A menu opened from code rather than a right click: the chat header's |
| 164 | + /// thread menu, the project scope picker's settings, and the like. |
| 165 | + struct OverlayMenu { |
| 166 | + menu: Entity<PopupMenu>, |
| 167 | + position: Point<Pixels>, |
| 168 | + _dismiss: Subscription, |
| 169 | + } |
| 170 | + |
| 134 | 171 | /// A settled thread, as the settings' archive lists it. |
| 135 | 172 | pub struct SettledThread { |
| 136 | 173 | pub session: Entity<Session>, |
| @@ -156,6 +193,8 @@ struct Activity { |
| 156 | 193 | } |
| 157 | 194 | |
| 158 | 195 | pub struct Workspace { |
| 196 | + /// The row whose hover card stays hidden while its menu is open. |
| 197 | + hover_card_hidden: Option<EntityId>, |
| 159 | 198 | projects: Vec<Project>, |
| 160 | 199 | chats: HashMap<EntityId, Entity<ChatView>>, |
| 161 | 200 | /// Each thread's browser panel, made the first time it's opened. |
| @@ -172,8 +211,38 @@ pub struct Workspace { |
| 172 | 211 | settled_open: bool, |
| 173 | 212 | snoozed_open: bool, |
| 174 | 213 | working_open: bool, |
| 175 | | - /// Projects folded away in the grouped thread list. |
| 214 | + /// How many settled threads the Settled shelf lists before "Show N more". |
| 215 | + settled_shown: usize, |
| 216 | + /// Projects folded away in the legacy sidebar. |
| 176 | 217 | collapsed_projects: HashSet<PathBuf>, |
| 218 | + /// Projects whose full thread list the legacy sidebar shows ("Show more"). |
| 219 | + expanded_projects: HashSet<PathBuf>, |
| 220 | + /// The project the sidebar is filtered to; `None` shows all projects. |
| 221 | + project_scope: Option<ProjectKey>, |
| 222 | + /// The project scope picker, while open, with its search field. |
| 223 | + scope_picker: Option<(Entity<InputState>, Subscription)>, |
| 224 | + /// Threads picked with Ctrl+click or Shift+click, in the order picked. |
| 225 | + selection: Vec<EntityId>, |
| 226 | + /// Where a Shift+click range starts. |
| 227 | + selection_anchor: Option<EntityId>, |
| 228 | + /// The highlighted row of the sidebar's search results. |
| 229 | + search_highlight: usize, |
| 230 | + renaming: Option<InlineRename>, |
| 231 | + overlay_menu: Option<OverlayMenu>, |
| 232 | + /// The command palette, while open. |
| 233 | + palette: Option<(Entity<CommandPalette>, Subscription)>, |
| 234 | + /// Actions the undo notice can take back, oldest first. |
| 235 | + undo: Vec<UndoEntry>, |
| 236 | + undo_generation: u64, |
| 237 | + undo_timer: Task<()>, |
| 238 | + /// When Ctrl went down, for showing the Ctrl+1–9 jump hints after a beat. |
| 239 | + ctrl_held: Option<Instant>, |
| 240 | + jump_hints: bool, |
| 241 | + /// A title click waiting to see whether it becomes a double-click. |
| 242 | + title_click: Task<()>, |
| 243 | + /// The thread sidebar's width, and whether its edge is being dragged. |
| 244 | + sidebar_width: f32, |
| 245 | + resizing_sidebar: bool, |
| 177 | 246 | editors: Rc<Vec<EditorApp>>, |
| 178 | 247 | editor: usize, |
| 179 | 248 | hostname: SharedString, |
| @@ -184,6 +253,10 @@ pub struct Workspace { |
| 184 | 253 | activity: HashMap<EntityId, Activity>, |
| 185 | 254 | /// The thread whose settle button waits for its confirming click. |
| 186 | 255 | settle_armed: Option<(EntityId, Instant)>, |
| 256 | + /// The legacy row whose Archive button waits for its Confirm click. |
| 257 | + archive_armed: Option<(EntityId, Instant)>, |
| 258 | + /// Where the chat header's title sits, to open its menu under it. |
| 259 | + title_bounds: Rc<std::cell::Cell<Bounds<Pixels>>>, |
| 187 | 260 | /// Threads changed since they were last saved. |
| 188 | 261 | dirty: HashSet<EntityId>, |
| 189 | 262 | /// `state.json` as last written. |
| @@ -235,10 +308,13 @@ impl Workspace { |
| 235 | 308 | cx.notify(); |
| 236 | 309 | } |
| 237 | 310 | }), |
| 238 | | - cx.subscribe(&search, |_, _, event: &InputEvent, cx| { |
| 239 | | - if matches!(event, InputEvent::Change) { |
| 311 | + cx.subscribe_in(&search, window, |this, _, event: &InputEvent, window, cx| match event { |
| 312 | + InputEvent::Change => { |
| 313 | + this.search_highlight = 0; |
| 240 | 314 | cx.notify(); |
| 241 | 315 | } |
| 316 | + InputEvent::PressEnter { .. } => this.open_search_result(window, cx), |
| 317 | + _ => {} |
| 242 | 318 | }), |
| 243 | 319 | ]; |
| 244 | 320 | let ticker = cx.spawn_in(window, async move |this, cx| { |
| @@ -264,6 +340,7 @@ impl Workspace { |
| 264 | 340 | let editor = editors.iter().position(|app| Some(app.name) == saved_editor.as_deref()).unwrap_or(0); |
| 265 | 341 | let now = Instant::now(); |
| 266 | 342 | let mut workspace = Self { |
| 343 | + hover_card_hidden: None, |
| 267 | 344 | projects: Vec::new(), |
| 268 | 345 | chats: HashMap::new(), |
| 269 | 346 | browsers: HashMap::new(), |
| @@ -277,7 +354,25 @@ impl Workspace { |
| 277 | 354 | settled_open: false, |
| 278 | 355 | snoozed_open: false, |
| 279 | 356 | working_open: false, |
| 357 | + settled_shown: sidebar::SETTLED_PAGE, |
| 280 | 358 | collapsed_projects: HashSet::new(), |
| 359 | + expanded_projects: HashSet::new(), |
| 360 | + project_scope: None, |
| 361 | + scope_picker: None, |
| 362 | + selection: Vec::new(), |
| 363 | + selection_anchor: None, |
| 364 | + search_highlight: 0, |
| 365 | + renaming: None, |
| 366 | + overlay_menu: None, |
| 367 | + palette: None, |
| 368 | + undo: Vec::new(), |
| 369 | + undo_generation: 0, |
| 370 | + undo_timer: Task::ready(()), |
| 371 | + ctrl_held: None, |
| 372 | + jump_hints: false, |
| 373 | + title_click: Task::ready(()), |
| 374 | + sidebar_width: SIDEBAR_WIDTH, |
| 375 | + resizing_sidebar: false, |
| 281 | 376 | editors: Rc::new(editors), |
| 282 | 377 | editor, |
| 283 | 378 | hostname: hostname().into(), |
| @@ -286,6 +381,8 @@ impl Workspace { |
| 286 | 381 | folder_browser: None, |
| 287 | 382 | activity: HashMap::new(), |
| 288 | 383 | settle_armed: None, |
| 384 | + archive_armed: None, |
| 385 | + title_bounds: Rc::default(), |
| 289 | 386 | dirty: HashSet::new(), |
| 290 | 387 | saved_state: String::new(), |
| 291 | 388 | worktree_git: HashMap::new(), |
| @@ -329,6 +426,11 @@ impl Workspace { |
| 329 | 426 | /// open. |
| 330 | 427 | fn restore(&mut self, window: &mut Window, cx: &mut Context<Self>) -> Option<ThreadEntry> { |
| 331 | 428 | let state = store::load_state(); |
| 429 | + self.working_open = state.working_expanded; |
| 430 | + self.snoozed_open = state.snoozed_expanded; |
| 431 | + self.settled_open = state.settled_expanded; |
| 432 | + self.collapsed_projects = state.collapsed_projects.iter().cloned().collect(); |
| 433 | + self.sidebar_width = state.sidebar_width.unwrap_or(SIDEBAR_WIDTH).max(SIDEBAR_MIN_WIDTH); |
| 332 | 434 | for project in &state.projects { |
| 333 | 435 | let name = Some(project.name.as_str()).filter(|name| !name.is_empty()); |
| 334 | 436 | let ix = self.ensure_project(project.path.clone(), name); |
| @@ -352,6 +454,10 @@ impl Workspace { |
| 352 | 454 | session.update(cx, |session, cx| session.send_message(CONTINUE_AFTER_RESTART.into(), Vec::new(), cx)); |
| 353 | 455 | } |
| 354 | 456 | } |
| 457 | + self.project_scope = state |
| 458 | + .project_scope |
| 459 | + .filter(|path| self.projects.iter().any(|project| project.environment.is_none() && &project.path == path)) |
| 460 | + .map(|path| (path, None)); |
| 355 | 461 | self.saved_state = serde_json::to_string(&self.app_state(cx)).unwrap_or_default(); |
| 356 | 462 | active |
| 357 | 463 | } |
| @@ -370,6 +476,16 @@ impl Workspace { |
| 370 | 476 | }) |
| 371 | 477 | .collect(), |
| 372 | 478 | active: self.active.as_ref().map(|session| session.read(cx).id.clone()), |
| 479 | + project_scope: self.project_scope.as_ref().filter(|(_, env)| env.is_none()).map(|(path, _)| path.clone()), |
| 480 | + working_expanded: self.working_open, |
| 481 | + snoozed_expanded: self.snoozed_open, |
| 482 | + settled_expanded: self.settled_open, |
| 483 | + collapsed_projects: { |
| 484 | + let mut paths: Vec<PathBuf> = self.collapsed_projects.iter().cloned().collect(); |
| 485 | + paths.sort(); |
| 486 | + paths |
| 487 | + }, |
| 488 | + sidebar_width: Some(self.sidebar_width.round()).filter(|width| *width != SIDEBAR_WIDTH), |
| 373 | 489 | } |
| 374 | 490 | } |
| 375 | 491 | |
| @@ -446,6 +562,17 @@ impl Workspace { |
| 446 | 562 | self.settle_armed = None; |
| 447 | 563 | cx.notify(); |
| 448 | 564 | } |
| 565 | + if let Some((_, armed)) = self.archive_armed |
| 566 | + && armed.elapsed() >= SETTLE_ARMED |
| 567 | + { |
| 568 | + self.archive_armed = None; |
| 569 | + cx.notify(); |
| 570 | + } |
| 571 | + // Working threads show how long they've worked. |
| 572 | + let working = self.projects.iter().flat_map(|project| &project.sessions).any(|session| session.read(cx).is_working()); |
| 573 | + if working && self.sidebar_open { |
| 574 | + cx.notify(); |
| 575 | + } |
| 449 | 576 | // Repaint about once a minute so thread ages stay current. |
| 450 | 577 | if self.last_repaint.elapsed() >= Duration::from_secs(60) { |
| 451 | 578 | self.last_repaint = Instant::now(); |
| @@ -526,14 +653,16 @@ impl Workspace { |
| 526 | 653 | state.resume_at.is_some_and(|at| at <= now) && !state.is_working(), |
| 527 | 654 | settle_inactive |
| 528 | 655 | && idle |
| 656 | + && state.auto_settle |
| 529 | 657 | && !state.settled |
| 658 | + && !state.archived |
| 530 | 659 | && !state.pinned |
| 531 | 660 | && state.resume_at.is_none() |
| 532 | 661 | && now.duration_since(state.updated).unwrap_or_default() >= inactive, |
| 533 | 662 | ) |
| 534 | 663 | }; |
| 535 | 664 | if wake { |
| 536 | | - session.update(cx, |session, cx| session.snooze(None, cx)); |
| 665 | + session.update(cx, |session, cx| session.wake(cx)); |
| 537 | 666 | } |
| 538 | 667 | if resume { |
| 539 | 668 | session.update(cx, |session, cx| { |
| @@ -580,6 +709,7 @@ impl Workspace { |
| 580 | 709 | let _ = session.update(cx, |session, cx| { |
| 581 | 710 | let was_open = session.pull_request.as_ref().is_none_or(|before| before.is_open()); |
| 582 | 711 | let settle = was_open |
| 712 | + && session.auto_settle |
| 583 | 713 | && !session.is_working() |
| 584 | 714 | && match pull_request.state.as_str() { |
| 585 | 715 | "MERGED" => merged_settles, |
| @@ -810,6 +940,11 @@ impl Workspace { |
| 810 | 940 | return; |
| 811 | 941 | } |
| 812 | 942 | let failed = state.ended_with_error(); |
| 943 | + let is_open = self.active.as_ref() == Some(&session) && !self.settings_open && window.is_window_active(); |
| 944 | + if before.working && !now.working && !is_open && !state.unread { |
| 945 | + session.update(cx, |session, cx| session.set_unread(true, cx)); |
| 946 | + } |
| 947 | + let state = session.read(cx); |
| 813 | 948 | let event = if now.attention && !before.attention { |
| 814 | 949 | "Waiting for you" |
| 815 | 950 | } else if before.working && !now.working { |
| @@ -925,7 +1060,9 @@ impl Workspace { |
| 925 | 1060 | .unwrap_or_else(|| path.display().to_string()) |
| 926 | 1061 | }); |
| 927 | 1062 | let git = git::read_info(&path); |
| 1063 | + let repo = git.as_ref().and_then(|_| git::repository_of(&path)); |
| 928 | 1064 | self.projects.push(Project { |
| 1065 | + repo, |
| 929 | 1066 | path, |
| 930 | 1067 | initials: initials(&name).into(), |
| 931 | 1068 | tint: tint_for(&name), |
| @@ -944,6 +1081,7 @@ impl Workspace { |
| 944 | 1081 | match settings::get(|settings| settings.project_order) { |
| 945 | 1082 | ProjectOrder::Name => order.sort_by_key(|&ix| self.projects[ix].name.to_lowercase()), |
| 946 | 1083 | ProjectOrder::Added => order.sort_by_key(|&ix| std::cmp::Reverse(self.projects[ix].added)), |
| 1084 | + ProjectOrder::Manual => {} |
| 947 | 1085 | ProjectOrder::LastMessage => order.sort_by_key(|&ix| { |
| 948 | 1086 | let project = &self.projects[ix]; |
| 949 | 1087 | let last = project |
| @@ -967,138 +1105,237 @@ impl Workspace { |
| 967 | 1105 | cx: &mut Context<Self>, |
| 968 | 1106 | ) { |
| 969 | 1107 | self.active_project = project_ix; |
| 970 | | - session.update(cx, |session, _| session.subscribe_remote()); |
| 1108 | + session.update(cx, |session, cx| { |
| 1109 | + session.subscribe_remote(); |
| 1110 | + session.mark_seen(cx); |
| 1111 | + }); |
| 971 | 1112 | if let Some(chat) = self.chats.get(&session.entity_id()).cloned() { |
| 972 | 1113 | chat.update(cx, |chat, cx| chat.focus_composer(window, cx)); |
| 973 | 1114 | } |
| 974 | | - self.active = Some(session); |
| 1115 | + // Opening a thread drops the multi-select, as in T3 Code. |
| 1116 | + self.selection.clear(); |
| 1117 | + let previous = self.active.replace(session.clone()); |
| 1118 | + if let Some(previous) = previous.filter(|previous| previous != &session) { |
| 1119 | + self.prune_empty_draft(&previous, cx); |
| 1120 | + } |
| 1121 | + if self.renaming.as_ref().is_some_and(|rename| !rename.sidebar) { |
| 1122 | + self.renaming = None; |
| 1123 | + } |
| 975 | 1124 | self.last_git = Instant::now() - GIT_POLL; |
| 976 | 1125 | cx.notify(); |
| 977 | 1126 | } |
| 978 | 1127 | |
| 979 | | - fn settle_thread(&mut self, session: Entity<Session>, cx: &mut Context<Self>) { |
| 980 | | - self.settle_armed = None; |
| 981 | | - session.update(cx, |session, cx| session.settle(cx)); |
| 982 | | - cx.notify(); |
| 1128 | + /// Forgets a new thread left without anything sent or typed, as T3 drops |
| 1129 | + /// an empty draft once you move on. |
| 1130 | + fn prune_empty_draft(&mut self, session: &Entity<Session>, cx: &mut Context<Self>) { |
| 1131 | + if !session.read(cx).is_blank() || session.read(cx).is_remote() { |
| 1132 | + return; |
| 1133 | + } |
| 1134 | + let empty = self |
| 1135 | + .chats |
| 1136 | + .get(&session.entity_id()) |
| 1137 | + .is_none_or(|chat| { |
| 1138 | + let (text, attachments) = chat.read(cx).draft(cx); |
| 1139 | + text.trim().is_empty() && attachments == 0 |
| 1140 | + }); |
| 1141 | + if empty && let Some(ix) = self.project_of(session) { |
| 1142 | + self.remove_thread(ix, session, cx); |
| 1143 | + } |
| 983 | 1144 | } |
| 984 | 1145 | |
| 985 | | - /// The settle button on a thread card: settles at once, or arms itself |
| 986 | | - /// for a confirming second click. |
| 987 | | - fn press_settle(&mut self, session: Entity<Session>, cx: &mut Context<Self>) { |
| 1146 | + /// The key naming a project. |
| 1147 | + fn project_key(&self, ix: usize) -> ProjectKey { |
| 1148 | + let project = &self.projects[ix]; |
| 1149 | + (project.path.clone(), project.environment.clone()) |
| 1150 | + } |
| 1151 | + |
| 1152 | + fn project_by_key(&self, key: &ProjectKey) -> Option<usize> { |
| 1153 | + self.projects.iter().position(|project| project.path == key.0 && project.environment == key.1) |
| 1154 | + } |
| 1155 | + |
| 1156 | + /// Takes a thread out of its project without stopping it, so the undo |
| 1157 | + /// notice can put it back. |
| 1158 | + fn detach_thread(&mut self, project_ix: usize, session: &Entity<Session>, cx: &mut Context<Self>) { |
| 988 | 1159 | let id = session.entity_id(); |
| 989 | | - let armed = self.settle_armed.is_some_and(|(armed, at)| armed == id && at.elapsed() < SETTLE_ARMED); |
| 990 | | - if settings::get(|settings| settings.confirm_settle) && !armed { |
| 991 | | - self.settle_armed = Some((id, Instant::now())); |
| 992 | | - cx.notify(); |
| 993 | | - } else { |
| 994 | | - self.settle_thread(session, cx); |
| 1160 | + self.chats.remove(&id); |
| 1161 | + self.observers.remove(&id); |
| 1162 | + self.activity.remove(&id); |
| 1163 | + if let Some(project) = self.projects.get_mut(project_ix) { |
| 1164 | + project.sessions.retain(|candidate| candidate.entity_id() != id); |
| 995 | 1165 | } |
| 1166 | + cx.notify(); |
| 996 | 1167 | } |
| 997 | 1168 | |
| 998 | | - /// Deletes a thread, asking first when Delete confirmation is on. |
| 999 | | - fn request_delete(&mut self, session: Entity<Session>, window: &mut Window, cx: &mut Context<Self>) { |
| 1000 | | - if !settings::get(|settings| settings.confirm_delete) { |
| 1001 | | - self.forget_thread(session, window, cx); |
| 1169 | + /// Puts a detached thread back where it was. |
| 1170 | + fn reattach_thread( |
| 1171 | + &mut self, |
| 1172 | + key: &ProjectKey, |
| 1173 | + session: Entity<Session>, |
| 1174 | + chat: Entity<ChatView>, |
| 1175 | + window: &mut Window, |
| 1176 | + cx: &mut Context<Self>, |
| 1177 | + ) { |
| 1178 | + let Some(project_ix) = self.project_by_key(key) else { |
| 1179 | + session.update(cx, |session, _| session.shutdown()); |
| 1002 | 1180 | return; |
| 1003 | | - } |
| 1004 | | - let title = session.read(cx).title.clone(); |
| 1181 | + }; |
| 1182 | + self.observers.insert( |
| 1183 | + session.entity_id(), |
| 1184 | + vec![cx.observe_in(&session, window, Self::on_session_changed), cx.subscribe_in(&chat, window, Self::on_chat_event)], |
| 1185 | + ); |
| 1186 | + self.chats.insert(session.entity_id(), chat); |
| 1187 | + self.projects[project_ix].sessions.push(session); |
| 1188 | + cx.notify(); |
| 1189 | + } |
| 1190 | + |
| 1191 | + /// Opens a menu at a point in the window, as a right click would. |
| 1192 | + fn open_menu( |
| 1193 | + &mut self, |
| 1194 | + position: Point<Pixels>, |
| 1195 | + window: &mut Window, |
| 1196 | + cx: &mut Context<Self>, |
| 1197 | + build: impl FnOnce(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu + 'static, |
| 1198 | + ) { |
| 1199 | + // The menus read the workspace as they build, so build once this |
| 1200 | + // update is over. |
| 1005 | 1201 | let workspace = cx.weak_entity(); |
| 1006 | | - window.open_alert_dialog(cx, move |alert, _, _| { |
| 1007 | | - let workspace = workspace.clone(); |
| 1008 | | - let session = session.clone(); |
| 1009 | | - alert |
| 1010 | | - .title("Delete thread?") |
| 1011 | | - .description(format!("\u{201c}{title}\u{201d} and its chat history will be deleted.")) |
| 1012 | | - .ok_text("Delete") |
| 1013 | | - .ok_variant(ButtonVariant::Danger) |
| 1014 | | - .show_cancel(true) |
| 1015 | | - .on_ok(move |_, window, cx| { |
| 1016 | | - let _ = workspace.update(cx, |this, cx| this.forget_thread(session.clone(), window, cx)); |
| 1017 | | - true |
| 1018 | | - }) |
| 1202 | + window.defer(cx, move |window, cx| { |
| 1203 | + let menu = PopupMenu::build(window, cx, build); |
| 1204 | + menu.focus_handle(cx).focus(window, cx); |
| 1205 | + let _ = workspace.update(cx, |this, cx| { |
| 1206 | + let dismiss = cx.subscribe_in(&menu, window, |this, _, _: &DismissEvent, window, cx| { |
| 1207 | + this.overlay_menu = None; |
| 1208 | + // Hand focus back, so the shortcuts keep working. |
| 1209 | + match this.active.as_ref().and_then(|session| this.chats.get(&session.entity_id())) { |
| 1210 | + Some(chat) if this.renaming.is_none() => chat.update(cx, |chat, cx| chat.focus_composer(window, cx)), |
| 1211 | + _ if this.renaming.is_none() => this.focus_handle.focus(window, cx), |
| 1212 | + _ => {} |
| 1213 | + } |
| 1214 | + cx.notify(); |
| 1215 | + }); |
| 1216 | + this.overlay_menu = Some(OverlayMenu { menu, position, _dismiss: dismiss }); |
| 1217 | + cx.notify(); |
| 1218 | + }); |
| 1019 | 1219 | }); |
| 1020 | 1220 | } |
| 1021 | 1221 | |
| 1022 | | - /// Pins or unpins a thread, asking before unpinning when set to. |
| 1023 | | - fn toggle_pin(&mut self, session: Entity<Session>, window: &mut Window, cx: &mut Context<Self>) { |
| 1024 | | - let pinned = session.read(cx).pinned; |
| 1025 | | - if !pinned || !settings::get(|settings| settings.confirm_unpin) { |
| 1026 | | - session.update(cx, |session, cx| session.set_pinned(!pinned, cx)); |
| 1027 | | - return; |
| 1222 | + /// Edits a thread's title in place: in its sidebar row, or in the chat |
| 1223 | + /// header. Enter or leaving the field saves, Esc cancels. |
| 1224 | + fn start_rename(&mut self, session: Entity<Session>, sidebar: bool, window: &mut Window, cx: &mut Context<Self>) { |
| 1225 | + // A row that isn't showing can't host the field; the header can. |
| 1226 | + let sidebar = sidebar && self.sidebar_open && !self.settings_open; |
| 1227 | + if !sidebar && self.active.as_ref() != Some(&session) { |
| 1228 | + if let Some(ix) = self.project_of(&session) { |
| 1229 | + self.select(ix, session.clone(), window, cx); |
| 1230 | + } |
| 1028 | 1231 | } |
| 1029 | | - let title = session.read(cx).title.clone(); |
| 1030 | | - window.open_alert_dialog(cx, move |alert, _, _| { |
| 1031 | | - let session = session.clone(); |
| 1032 | | - alert |
| 1033 | | - .title("Unpin thread?") |
| 1034 | | - .description(format!("\u{201c}{title}\u{201d} moves back among the other threads.")) |
| 1035 | | - .ok_text("Unpin") |
| 1036 | | - .show_cancel(true) |
| 1037 | | - .on_ok(move |_, _, cx| { |
| 1038 | | - session.update(cx, |session, cx| session.set_pinned(false, cx)); |
| 1039 | | - true |
| 1040 | | - }) |
| 1232 | + let title = session.read(cx).title.to_string(); |
| 1233 | + let input = cx.new(|cx| InputState::new(window, cx).default_value(title)); |
| 1234 | + input.update(cx, |input, cx| { |
| 1235 | + input.focus(window, cx); |
| 1236 | + input.select_all(window, cx); |
| 1041 | 1237 | }); |
| 1238 | + let subscription = cx.subscribe_in(&input, window, |this, _, event: &InputEvent, window, cx| match event { |
| 1239 | + InputEvent::PressEnter { .. } | InputEvent::Blur => this.commit_rename(window, cx), |
| 1240 | + _ => {} |
| 1241 | + }); |
| 1242 | + self.renaming = Some(InlineRename { session, input, sidebar, _subscription: subscription }); |
| 1243 | + cx.notify(); |
| 1042 | 1244 | } |
| 1043 | 1245 | |
| 1044 | | - fn rename_thread(&mut self, session: Entity<Session>, window: &mut Window, cx: &mut Context<Self>) { |
| 1045 | | - let title = session.read(cx).title.to_string(); |
| 1046 | | - let input = cx.new(|cx| InputState::new(window, cx).default_value(title)); |
| 1047 | | - input.update(cx, |input, cx| input.focus(window, cx)); |
| 1048 | | - let rename = { |
| 1049 | | - let input = input.clone(); |
| 1050 | | - let session = session.clone(); |
| 1051 | | - move |window: &mut Window, cx: &mut App| { |
| 1052 | | - let title = input.read(cx).value().to_string(); |
| 1053 | | - session.update(cx, |session, cx| session.rename(title, cx)); |
| 1054 | | - window.close_dialog(cx); |
| 1055 | | - } |
| 1246 | + fn commit_rename(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 1247 | + let Some(rename) = self.renaming.take() else { return }; |
| 1248 | + let title = rename.input.read(cx).value().trim().to_string(); |
| 1249 | + if title.is_empty() { |
| 1250 | + window.push_notification(Notification::warning("Thread title cannot be empty"), cx); |
| 1251 | + } else if title != rename.session.read(cx).title.as_ref() { |
| 1252 | + rename.session.update(cx, |session, cx| session.rename(title, cx)); |
| 1253 | + } |
| 1254 | + cx.notify(); |
| 1255 | + } |
| 1256 | + |
| 1257 | + fn cancel_rename(&mut self, cx: &mut Context<Self>) { |
| 1258 | + if self.renaming.take().is_some() { |
| 1259 | + cx.notify(); |
| 1260 | + } |
| 1261 | + } |
| 1262 | + |
| 1263 | + /// Opens the previous or next thread in the sidebar (Ctrl+Shift+[ and ]). |
| 1264 | + fn step_thread(&mut self, delta: isize, window: &mut Window, cx: &mut Context<Self>) { |
| 1265 | + let rows = self.visible_rows(cx); |
| 1266 | + if rows.is_empty() { |
| 1267 | + return; |
| 1268 | + } |
| 1269 | + let current = self.active.as_ref().and_then(|active| rows.iter().position(|(_, row)| row == active)); |
| 1270 | + let next = match current { |
| 1271 | + Some(ix) => (ix as isize + delta).rem_euclid(rows.len() as isize) as usize, |
| 1272 | + None if delta < 0 => rows.len() - 1, |
| 1273 | + None => 0, |
| 1056 | 1274 | }; |
| 1057 | | - let on_enter = rename.clone(); |
| 1058 | | - let subscription = cx.subscribe_in(&input, window, move |_, _, event: &InputEvent, window, cx| { |
| 1059 | | - if matches!(event, InputEvent::PressEnter { .. }) { |
| 1060 | | - on_enter(window, cx); |
| 1275 | + let (project, session) = rows[next].clone(); |
| 1276 | + self.select(project, session, window, cx); |
| 1277 | + } |
| 1278 | + |
| 1279 | + /// Ctrl+1–9 open the sidebar's first nine threads. |
| 1280 | + fn jump_with_key(&mut self, event: &KeyDownEvent, window: &mut Window, cx: &mut Context<Self>) { |
| 1281 | + let keystroke = &event.keystroke; |
| 1282 | + let modifiers = &keystroke.modifiers; |
| 1283 | + if !modifiers.control || modifiers.shift || modifiers.alt || modifiers.platform || self.palette.is_some() { |
| 1284 | + return; |
| 1285 | + } |
| 1286 | + let Some(digit) = keystroke.key.parse::<usize>().ok().filter(|digit| (1..=9).contains(digit)) else { return }; |
| 1287 | + if let Some((project, session)) = self.visible_rows(cx).get(digit - 1).cloned() { |
| 1288 | + cx.stop_propagation(); |
| 1289 | + self.jump_hints = false; |
| 1290 | + self.select(project, session, window, cx); |
| 1291 | + } |
| 1292 | + } |
| 1293 | + |
| 1294 | + /// Shows the jump hints once Ctrl has been held for a beat. |
| 1295 | + fn modifiers_changed(&mut self, event: &ModifiersChangedEvent, window: &mut Window, cx: &mut Context<Self>) { |
| 1296 | + let held = event.modifiers.control && !event.modifiers.shift && !event.modifiers.alt; |
| 1297 | + if !held { |
| 1298 | + self.ctrl_held = None; |
| 1299 | + if self.jump_hints { |
| 1300 | + self.jump_hints = false; |
| 1301 | + cx.notify(); |
| 1061 | 1302 | } |
| 1062 | | - }); |
| 1063 | | - let rename = Rc::new(rename); |
| 1064 | | - window.open_dialog(cx, move |dialog, _, cx| { |
| 1065 | | - let p = metal::palette(cx); |
| 1066 | | - let rename = rename.clone(); |
| 1067 | | - dialog |
| 1068 | | - .title("Rename thread") |
| 1069 | | - .w(px(420.)) |
| 1070 | | - .child( |
| 1071 | | - h_flex() |
| 1072 | | - .h(px(36.)) |
| 1073 | | - .px(px(11.)) |
| 1074 | | - .rounded(px(12.)) |
| 1075 | | - .well(p) |
| 1076 | | - .text_size(px(13.5)) |
| 1077 | | - .child(div().flex_1().child(Input::new(&input).appearance(false))), |
| 1078 | | - ) |
| 1079 | | - .footer( |
| 1080 | | - h_flex() |
| 1081 | | - .w_full() |
| 1082 | | - .justify_end() |
| 1083 | | - .gap(px(8.)) |
| 1084 | | - .child( |
| 1085 | | - MetalButton::new("rename-cancel") |
| 1086 | | - .ghost() |
| 1087 | | - .compact() |
| 1088 | | - .label("Cancel") |
| 1089 | | - .on_click(|_, window, cx| window.close_dialog(cx)), |
| 1090 | | - ) |
| 1091 | | - .child( |
| 1092 | | - MetalButton::new("rename-save") |
| 1093 | | - .primary() |
| 1094 | | - .compact() |
| 1095 | | - .label("Rename") |
| 1096 | | - .on_click(move |_, window, cx| rename(window, cx)), |
| 1097 | | - ), |
| 1098 | | - ) |
| 1099 | | - }); |
| 1100 | | - // The subscription lives as long as the dialog might. |
| 1101 | | - self._subscriptions.push(subscription); |
| 1303 | + return; |
| 1304 | + } |
| 1305 | + if self.ctrl_held.is_some() { |
| 1306 | + return; |
| 1307 | + } |
| 1308 | + let since = Instant::now(); |
| 1309 | + self.ctrl_held = Some(since); |
| 1310 | + cx.spawn_in(window, async move |this, cx| { |
| 1311 | + cx.background_executor().timer(JUMP_HINT_DELAY).await; |
| 1312 | + let _ = this.update(cx, |this, cx| { |
| 1313 | + if this.ctrl_held == Some(since) { |
| 1314 | + this.jump_hints = true; |
| 1315 | + cx.notify(); |
| 1316 | + } |
| 1317 | + }); |
| 1318 | + }) |
| 1319 | + .detach(); |
| 1320 | + } |
| 1321 | + |
| 1322 | + /// Opens a settings page by its name in the settings view (`Usage`). |
| 1323 | + fn open_settings_page(&mut self, page: &str, window: &mut Window, cx: &mut Context<Self>) { |
| 1324 | + self.open_settings(window, cx); |
| 1325 | + self.settings_view.update(cx, |view, cx| view.open_page(page, cx)); |
| 1326 | + } |
| 1327 | + |
| 1328 | + /// The settle button on a thread card: settles at once, or arms itself |
| 1329 | + /// for a confirming second click when Settle confirmation is on. |
| 1330 | + fn press_settle(&mut self, session: Entity<Session>, window: &mut Window, cx: &mut Context<Self>) { |
| 1331 | + let id = session.entity_id(); |
| 1332 | + let armed = self.settle_armed.is_some_and(|(armed, at)| armed == id && at.elapsed() < SETTLE_ARMED); |
| 1333 | + if settings::get(|settings| settings.confirm_settle) && !armed { |
| 1334 | + self.settle_armed = Some((id, Instant::now())); |
| 1335 | + cx.notify(); |
| 1336 | + } else { |
| 1337 | + self.settle_threads(vec![session], window, cx); |
| 1338 | + } |
| 1102 | 1339 | } |
| 1103 | 1340 | |
| 1104 | 1341 | fn delete_thread( |
| @@ -1112,21 +1349,51 @@ impl Workspace { |
| 1112 | 1349 | let state = session.read(cx); |
| 1113 | 1350 | (state.id.clone(), state.worktree.clone(), state.is_remote()) |
| 1114 | 1351 | }; |
| 1352 | + // Like T3 Code, a worktree goes too only when no other thread uses it, |
| 1353 | + // and only once the user says so. |
| 1354 | + let entity_id = session.entity_id(); |
| 1355 | + let worktree = worktree.filter(|worktree| { |
| 1356 | + worktree.root.exists() |
| 1357 | + && !self.projects.iter().flat_map(|project| &project.sessions).any(|other| { |
| 1358 | + other.entity_id() != entity_id |
| 1359 | + && other.read(cx).worktree.as_ref().is_some_and(|other| other.root == worktree.root) |
| 1360 | + }) |
| 1361 | + }); |
| 1115 | 1362 | self.remove_thread(project_ix, &session, cx); |
| 1116 | 1363 | if remote { |
| 1117 | 1364 | session.read(cx).forget_remote(); |
| 1118 | 1365 | } else { |
| 1119 | 1366 | cx.background_executor() |
| 1120 | | - .spawn(async move { |
| 1121 | | - store::delete_thread(&id); |
| 1122 | | - browser::stop(&browser::session_name(&id)); |
| 1123 | | - if let Some(worktree) = worktree { |
| 1124 | | - let _ = worktree::remove(&worktree); |
| 1125 | | - } |
| 1126 | | - }) |
| 1127 | | - .detach(); |
| 1367 | + .spawn(async move { |
| 1368 | + store::delete_thread(&id); |
| 1369 | + browser::stop(&browser::session_name(&id)); |
| 1370 | + }) |
| 1371 | + .detach(); |
| 1372 | + if let Some(worktree) = worktree { |
| 1373 | + let name = worktree.root.file_name().map(|name| name.to_string_lossy().to_string()).unwrap_or_default(); |
| 1374 | + let message = |
| 1375 | + format!("This thread is the only one linked to this worktree:\n{name}\n\nDelete the worktree too?"); |
| 1376 | + // After the dialog that asked to delete the thread has closed. |
| 1377 | + window.defer(cx, move |window, cx| actions::confirm(&message, true, window, cx, move |window, cx| { |
| 1378 | + let worktree = worktree.clone(); |
| 1379 | + let name = name.clone(); |
| 1380 | + let task = cx.background_executor().spawn(async move { worktree::remove_force(&worktree) }); |
| 1381 | + window |
| 1382 | + .spawn(cx, async move |cx| { |
| 1383 | + if let Err(err) = task.await { |
| 1384 | + let _ = cx.update(|window, cx| { |
| 1385 | + window.push_notification( |
| 1386 | + Notification::error(format!("Could not remove {name}. {err}")) |
| 1387 | + .title("Failed to delete worktree"), |
| 1388 | + cx, |
| 1389 | + ); |
| 1390 | + }); |
| 1391 | + } |
| 1392 | + }) |
| 1393 | + .detach(); |
| 1394 | + })); |
| 1395 | + } |
| 1128 | 1396 | } |
| 1129 | | - let entity_id = session.entity_id(); |
| 1130 | 1397 | if self.active.as_ref().is_some_and(|active| active.entity_id() == entity_id) { |
| 1131 | 1398 | self.active = None; |
| 1132 | 1399 | if let Some((ix, next)) = self.threads(cx).0.into_iter().next() { |
| @@ -1327,13 +1594,14 @@ impl Workspace { |
| 1327 | 1594 | cx.notify(); |
| 1328 | 1595 | } |
| 1329 | 1596 | |
| 1330 | | - /// Every settled thread, most recently active first. |
| 1597 | + /// Every archived thread, most recently active first, for Settings → |
| 1598 | + /// Archive. (Settled threads stay in the sidebar's Settled shelf.) |
| 1331 | 1599 | pub fn settled_threads(&self, cx: &App) -> Vec<SettledThread> { |
| 1332 | 1600 | let mut threads: Vec<_> = self |
| 1333 | 1601 | .projects |
| 1334 | 1602 | .iter() |
| 1335 | 1603 | .flat_map(|project| project.sessions.iter().map(move |session| (project, session))) |
| 1336 | | - .filter(|(_, session)| session.read(cx).settled) |
| 1604 | + .filter(|(_, session)| session.read(cx).archived) |
| 1337 | 1605 | .collect(); |
| 1338 | 1606 | threads.sort_by_key(|(_, session)| std::cmp::Reverse(session.read(cx).updated)); |
| 1339 | 1607 | threads |
| @@ -1356,7 +1624,10 @@ impl Workspace { |
| 1356 | 1624 | /// Brings a settled thread back and opens it. |
| 1357 | 1625 | pub fn restore_thread(&mut self, session: Entity<Session>, window: &mut Window, cx: &mut Context<Self>) { |
| 1358 | 1626 | let Some(ix) = self.project_of(&session) else { return }; |
| 1359 | | - session.update(cx, |session, cx| session.unsettle(cx)); |
| 1627 | + session.update(cx, |session, cx| { |
| 1628 | + session.set_archived(false, cx); |
| 1629 | + session.unsettle(cx); |
| 1630 | + }); |
| 1360 | 1631 | self.select(ix, session, window, cx); |
| 1361 | 1632 | self.close_settings(window, cx); |
| 1362 | 1633 | } |
| @@ -1367,619 +1638,6 @@ impl Workspace { |
| 1367 | 1638 | } |
| 1368 | 1639 | } |
| 1369 | 1640 | |
| 1370 | | - // ---- sidebar -------------------------------------------------------- |
| 1371 | | - |
| 1372 | | - fn render_sidebar_header(&self, cx: &mut Context<Self>) -> impl IntoElement { |
| 1373 | | - let p = metal::palette(cx); |
| 1374 | | - h_flex() |
| 1375 | | - .flex_none() |
| 1376 | | - .h(px(52.)) |
| 1377 | | - .pl(px(10.)) |
| 1378 | | - .pr(px(12.)) |
| 1379 | | - .gap(px(8.)) |
| 1380 | | - .child( |
| 1381 | | - MetalButton::new("hide-sidebar") |
| 1382 | | - .ghost() |
| 1383 | | - .mini() |
| 1384 | | - .icon(Lucide::PanelLeftClose) |
| 1385 | | - .tooltip("Hide sidebar (Ctrl+B)") |
| 1386 | | - .on_click(cx.listener(|this, _, _, cx| { |
| 1387 | | - this.sidebar_open = false; |
| 1388 | | - cx.notify(); |
| 1389 | | - })), |
| 1390 | | - ) |
| 1391 | | - .child(Icon::default().data(metal::LOGO_SVG).size(px(18.)).text_color(p.ink)) |
| 1392 | | - .child(div().text_size(px(15.)).font_weight(FontWeight::SEMIBOLD).child("Vectrum")) |
| 1393 | | - .child(metal::tag("Code", p)) |
| 1394 | | - } |
| 1395 | | - |
| 1396 | | - fn render_sidebar_toolbar(&self, cx: &mut Context<Self>) -> impl IntoElement { |
| 1397 | | - let p = metal::palette(cx); |
| 1398 | | - let projects: Vec<(usize, SharedString)> = self |
| 1399 | | - .ordered_projects(cx) |
| 1400 | | - .into_iter() |
| 1401 | | - .map(|ix| { |
| 1402 | | - let project = &self.projects[ix]; |
| 1403 | | - let name = match &project.environment { |
| 1404 | | - Some(env) => format!("{} · {}", project.name, self.environment_name(env)).into(), |
| 1405 | | - None => project.name.clone(), |
| 1406 | | - }; |
| 1407 | | - (ix, name) |
| 1408 | | - }) |
| 1409 | | - .collect(); |
| 1410 | | - let workspace = cx.entity().downgrade(); |
| 1411 | | - |
| 1412 | | - h_flex() |
| 1413 | | - .flex_none() |
| 1414 | | - .px(px(12.)) |
| 1415 | | - .gap(px(4.)) |
| 1416 | | - .child( |
| 1417 | | - h_flex() |
| 1418 | | - .flex_1() |
| 1419 | | - .min_w_0() |
| 1420 | | - .h(px(36.)) |
| 1421 | | - .pl(px(11.)) |
| 1422 | | - .pr(px(8.)) |
| 1423 | | - .gap(px(8.)) |
| 1424 | | - .rounded(px(14.)) |
| 1425 | | - .well(p) |
| 1426 | | - .text_size(px(13.)) |
| 1427 | | - .text_color(p.ink) |
| 1428 | | - .child(Icon::new(IconName::Search).size(px(14.)).text_color(p.field_ink)) |
| 1429 | | - .child(div().flex_1().min_w_0().child(Input::new(&self.search).appearance(false))), |
| 1430 | | - ) |
| 1431 | | - .child( |
| 1432 | | - MetalButton::new("project-menu") |
| 1433 | | - .ghost() |
| 1434 | | - .mini() |
| 1435 | | - .icon(Lucide::FolderPlus) |
| 1436 | | - .dropdown_menu(move |mut menu, _, _| { |
| 1437 | | - for (ix, name) in projects.clone() { |
| 1438 | | - let workspace = workspace.clone(); |
| 1439 | | - menu = menu.item(PopupMenuItem::new(format!("New thread in {name}")).on_click( |
| 1440 | | - move |_, window, cx| { |
| 1441 | | - let _ = workspace.update(cx, |this, cx| this.new_thread(ix, window, cx)); |
| 1442 | | - }, |
| 1443 | | - )); |
| 1444 | | - } |
| 1445 | | - let workspace = workspace.clone(); |
| 1446 | | - menu.separator().item(PopupMenuItem::new("Add project folder…").on_click( |
| 1447 | | - move |_, window, cx| { |
| 1448 | | - let _ = workspace.update(cx, |this, cx| this.prompt_for_project(window, cx)); |
| 1449 | | - }, |
| 1450 | | - )) |
| 1451 | | - }), |
| 1452 | | - ) |
| 1453 | | - .child( |
| 1454 | | - MetalButton::new("new-thread") |
| 1455 | | - .ghost() |
| 1456 | | - .mini() |
| 1457 | | - .icon(Lucide::SquarePen) |
| 1458 | | - .tooltip("New thread (Ctrl+N)") |
| 1459 | | - .on_click(cx.listener(|this, _, window, cx| { |
| 1460 | | - if this.projects.is_empty() { |
| 1461 | | - this.prompt_for_project(window, cx); |
| 1462 | | - } else { |
| 1463 | | - this.new_thread(this.active_project, window, cx); |
| 1464 | | - } |
| 1465 | | - })), |
| 1466 | | - ) |
| 1467 | | - } |
| 1468 | | - |
| 1469 | | - /// The right-click menu of a thread card. |
| 1470 | | - fn thread_menu( |
| 1471 | | - workspace: WeakEntity<Self>, |
| 1472 | | - session: Entity<Session>, |
| 1473 | | - menu: PopupMenu, |
| 1474 | | - window: &mut Window, |
| 1475 | | - cx: &mut Context<PopupMenu>, |
| 1476 | | - ) -> PopupMenu { |
| 1477 | | - let state = session.read(cx); |
| 1478 | | - let (pinned, settled, snoozed) = (state.pinned, state.settled, state.is_snoozed()); |
| 1479 | | - let action = |run: fn(&mut Workspace, Entity<Session>, &mut Window, &mut Context<Workspace>)| { |
| 1480 | | - let workspace = workspace.clone(); |
| 1481 | | - let session = session.clone(); |
| 1482 | | - move |_: &ClickEvent, window: &mut Window, cx: &mut App| { |
| 1483 | | - let _ = workspace.update(cx, |this, cx| run(this, session.clone(), window, cx)); |
| 1484 | | - } |
| 1485 | | - }; |
| 1486 | | - let snooze_session = session.clone(); |
| 1487 | | - let mut menu = menu |
| 1488 | | - .min_w(px(200.)) |
| 1489 | | - .item( |
| 1490 | | - PopupMenuItem::new(if pinned { "Unpin" } else { "Pin to top" }) |
| 1491 | | - .icon(Icon::new(if pinned { Lucide::PinOff } else { Lucide::Pin })) |
| 1492 | | - .on_click(action(|this, session, window, cx| this.toggle_pin(session, window, cx))), |
| 1493 | | - ) |
| 1494 | | - .item( |
| 1495 | | - PopupMenuItem::new("Rename…") |
| 1496 | | - .icon(Icon::new(Lucide::Pencil)) |
| 1497 | | - .on_click(action(|this, session, window, cx| this.rename_thread(session, window, cx))), |
| 1498 | | - ); |
| 1499 | | - if !settled { |
| 1500 | | - menu = menu.submenu_with_icon(Some(Icon::new(Lucide::AlarmClock)), "Snooze", window, cx, move |mut menu, _, _| { |
| 1501 | | - let snooze = |until: fn() -> SystemTime| { |
| 1502 | | - let session = snooze_session.clone(); |
| 1503 | | - move |_: &ClickEvent, _: &mut Window, cx: &mut App| { |
| 1504 | | - session.update(cx, |session, cx| session.snooze(Some(until()), cx)); |
| 1505 | | - } |
| 1506 | | - }; |
| 1507 | | - menu = menu |
| 1508 | | - .min_w(px(220.)) |
| 1509 | | - .item(PopupMenuItem::new("For an hour").on_click(snooze(|| SystemTime::now() + Duration::from_secs(3_600)))) |
| 1510 | | - .item(PopupMenuItem::new("For three hours").on_click(snooze(|| SystemTime::now() + Duration::from_secs(10_800)))) |
| 1511 | | - .item(PopupMenuItem::new(format!("Until tomorrow, {}", clock::clock(clock::at_hour(1, 9)))).on_click(snooze(|| clock::at_hour(1, 9)))) |
| 1512 | | - .item(PopupMenuItem::new(format!("Until next week, {}", clock::clock(clock::at_hour(7, 9)))).on_click(snooze(|| clock::at_hour(7, 9)))); |
| 1513 | | - menu |
| 1514 | | - }); |
| 1515 | | - if snoozed { |
| 1516 | | - let session = session.clone(); |
| 1517 | | - menu = menu.item(PopupMenuItem::new("Wake up now").icon(Icon::new(Lucide::AlarmClockOff)).on_click( |
| 1518 | | - move |_, _, cx| session.update(cx, |session, cx| session.snooze(None, cx)), |
| 1519 | | - )); |
| 1520 | | - } |
| 1521 | | - } |
| 1522 | | - menu = menu.separator(); |
| 1523 | | - menu = if settled { |
| 1524 | | - menu.item( |
| 1525 | | - PopupMenuItem::new("Restore") |
| 1526 | | - .icon(Icon::new(Lucide::ArchiveRestore)) |
| 1527 | | - .on_click(action(|this, session, window, cx| this.restore_thread(session, window, cx))), |
| 1528 | | - ) |
| 1529 | | - } else { |
| 1530 | | - menu.item( |
| 1531 | | - PopupMenuItem::new("Settle") |
| 1532 | | - .icon(Icon::new(Lucide::Archive)) |
| 1533 | | - .on_click(action(|this, session, _, cx| this.settle_thread(session, cx))), |
| 1534 | | - ) |
| 1535 | | - }; |
| 1536 | | - menu.item( |
| 1537 | | - PopupMenuItem::new("Delete…") |
| 1538 | | - .icon(Icon::new(Lucide::Trash)) |
| 1539 | | - .on_click(action(|this, session, window, cx| this.request_delete(session, window, cx))), |
| 1540 | | - ) |
| 1541 | | - } |
| 1542 | | - |
| 1543 | | - fn render_thread_card( |
| 1544 | | - &self, |
| 1545 | | - project_ix: usize, |
| 1546 | | - session: &Entity<Session>, |
| 1547 | | - cx: &mut Context<Self>, |
| 1548 | | - ) -> AnyElement { |
| 1549 | | - let p = metal::palette(cx); |
| 1550 | | - let project = &self.projects[project_ix]; |
| 1551 | | - let state = session.read(cx); |
| 1552 | | - let id = session.entity_id(); |
| 1553 | | - let selected = self.active.as_ref().is_some_and(|active| active.entity_id() == id); |
| 1554 | | - let (led, pulse) = if state.settled { |
| 1555 | | - (Led::Off, false) |
| 1556 | | - } else if state.needs_attention() { |
| 1557 | | - (Led::Waiting, true) |
| 1558 | | - } else if state.limited_until().is_some() { |
| 1559 | | - (Led::Waiting, false) |
| 1560 | | - } else { |
| 1561 | | - match state.status { |
| 1562 | | - SessionStatus::Working => (Led::Live, true), |
| 1563 | | - // Idle, but a background task will wake Claude. |
| 1564 | | - SessionStatus::Idle if !state.background_tasks.is_empty() => (Led::Live, true), |
| 1565 | | - SessionStatus::Idle => (Led::Live, false), |
| 1566 | | - SessionStatus::Starting => (Led::Off, false), |
| 1567 | | - SessionStatus::Exited => (Led::Failed, false), |
| 1568 | | - } |
| 1569 | | - }; |
| 1570 | | - let branch = match &state.worktree { |
| 1571 | | - Some(worktree) => Some(worktree.branch.clone()), |
| 1572 | | - None => project.git.as_ref().and_then(|git| git.branch.clone()), |
| 1573 | | - }; |
| 1574 | | - let in_worktree = state.worktree.is_some() || state.pending_worktree.is_some(); |
| 1575 | | - let host = project.environment.as_deref().map(|env| self.environment_name(env)); |
| 1576 | | - let settled = state.settled; |
| 1577 | | - let pinned = state.pinned; |
| 1578 | | - let snoozed_until = state.snoozed_until.filter(|_| state.is_snoozed()); |
| 1579 | | - let group = SharedString::from(format!("thread-{id}")); |
| 1580 | | - let select_session = session.clone(); |
| 1581 | | - let action_session = session.clone(); |
| 1582 | | - let pin_session = session.clone(); |
| 1583 | | - let compact = settings::get(|settings| settings.compact_threads); |
| 1584 | | - let armed = self.settle_armed.is_some_and(|(armed, at)| armed == id && at.elapsed() < SETTLE_ARMED); |
| 1585 | | - |
| 1586 | | - let settle_or_delete = if settled { |
| 1587 | | - MetalButton::new(("delete-thread", id.as_u64() as usize)) |
| 1588 | | - .ghost() |
| 1589 | | - .mini() |
| 1590 | | - .icon(IconName::Close) |
| 1591 | | - .tooltip("Delete thread") |
| 1592 | | - .on_click(cx.listener(move |this, _, window, cx| { |
| 1593 | | - cx.stop_propagation(); |
| 1594 | | - this.request_delete(action_session.clone(), window, cx) |
| 1595 | | - })) |
| 1596 | | - } else if armed { |
| 1597 | | - MetalButton::new(("settle-thread", id.as_u64() as usize)) |
| 1598 | | - .danger() |
| 1599 | | - .mini() |
| 1600 | | - .icon(IconName::Check) |
| 1601 | | - .tooltip("Click again to settle") |
| 1602 | | - .on_click(cx.listener(move |this, _, _, cx| { |
| 1603 | | - cx.stop_propagation(); |
| 1604 | | - this.press_settle(action_session.clone(), cx) |
| 1605 | | - })) |
| 1606 | | - } else { |
| 1607 | | - MetalButton::new(("settle-thread", id.as_u64() as usize)) |
| 1608 | | - .ghost() |
| 1609 | | - .mini() |
| 1610 | | - .icon(Lucide::Archive) |
| 1611 | | - .tooltip("Settle: stop the agent and file the thread away") |
| 1612 | | - .on_click(cx.listener(move |this, _, _, cx| { |
| 1613 | | - cx.stop_propagation(); |
| 1614 | | - this.press_settle(action_session.clone(), cx) |
| 1615 | | - })) |
| 1616 | | - }; |
| 1617 | | - let pin_button = MetalButton::new(("pin-thread", id.as_u64() as usize)) |
| 1618 | | - .ghost() |
| 1619 | | - .mini() |
| 1620 | | - .icon(if pinned { Lucide::PinOff } else { Lucide::Pin }) |
| 1621 | | - .tooltip(if pinned { "Unpin" } else { "Pin to top" }) |
| 1622 | | - .on_click(cx.listener(move |this, _, window, cx| { |
| 1623 | | - cx.stop_propagation(); |
| 1624 | | - this.toggle_pin(pin_session.clone(), window, cx) |
| 1625 | | - })); |
| 1626 | | - let actions = h_flex() |
| 1627 | | - .gap(px(1.)) |
| 1628 | | - .when(!armed, |this| this.invisible().group_hover(group.clone(), |this| this.visible())) |
| 1629 | | - .when(!settled, |this| this.child(pin_button)) |
| 1630 | | - .child(settle_or_delete); |
| 1631 | | - let led = metal::led(("thread-led", id.as_u64() as usize), led, pulse, p); |
| 1632 | | - let title = h_flex() |
| 1633 | | - .min_w_0() |
| 1634 | | - .gap(px(5.)) |
| 1635 | | - .when(pinned, |this| this.child(Icon::new(Lucide::Pin).size(px(11.)).text_color(p.ink3).flex_none())) |
| 1636 | | - .child( |
| 1637 | | - div() |
| 1638 | | - .min_w_0() |
| 1639 | | - .truncate() |
| 1640 | | - .text_size(px(13.5)) |
| 1641 | | - .font_weight(FontWeight::SEMIBOLD) |
| 1642 | | - .text_color(if selected || !settled { p.ink } else { p.ink2 }) |
| 1643 | | - .child(state.title.clone()), |
| 1644 | | - ); |
| 1645 | | - let age = div() |
| 1646 | | - .flex_none() |
| 1647 | | - .font_family(metal::MONO) |
| 1648 | | - .text_size(px(10.5)) |
| 1649 | | - .text_color(p.ink3) |
| 1650 | | - .child(match snoozed_until { |
| 1651 | | - Some(until) => clock::when(until), |
| 1652 | | - None => relative_time(state.updated), |
| 1653 | | - }); |
| 1654 | | - |
| 1655 | | - let workspace = cx.weak_entity(); |
| 1656 | | - let menu_session = session.clone(); |
| 1657 | | - let card = v_flex() |
| 1658 | | - .id(("thread", id.as_u64() as usize)) |
| 1659 | | - .group(group) |
| 1660 | | - .px(px(12.)) |
| 1661 | | - .py(px(if compact { 5. } else { 9. })) |
| 1662 | | - .gap(px(4.)) |
| 1663 | | - .rounded(px(if compact { 12. } else { 14. })) |
| 1664 | | - .cursor_pointer() |
| 1665 | | - .map(|this| { |
| 1666 | | - if selected { |
| 1667 | | - this.raised(p) |
| 1668 | | - } else { |
| 1669 | | - this.hover(|style| style.bg(p.row_hover)) |
| 1670 | | - } |
| 1671 | | - }) |
| 1672 | | - .on_click(cx.listener(move |this, _, window, cx| { |
| 1673 | | - this.select(project_ix, select_session.clone(), window, cx) |
| 1674 | | - })); |
| 1675 | | - |
| 1676 | | - let card = if compact { |
| 1677 | | - card.child( |
| 1678 | | - h_flex() |
| 1679 | | - .h(px(22.)) |
| 1680 | | - .gap(px(7.)) |
| 1681 | | - .child(metal::badge(project.initials.clone(), project.tint, p)) |
| 1682 | | - .child(title.flex_1().text_size(px(13.)).font_weight(FontWeight::MEDIUM)) |
| 1683 | | - .child(actions) |
| 1684 | | - .child(age) |
| 1685 | | - .child(led), |
| 1686 | | - ) |
| 1687 | | - } else { |
| 1688 | | - card.child( |
| 1689 | | - h_flex() |
| 1690 | | - .gap(px(7.)) |
| 1691 | | - .child(metal::badge(project.initials.clone(), project.tint, p)) |
| 1692 | | - .child( |
| 1693 | | - div() |
| 1694 | | - .flex_1() |
| 1695 | | - .min_w_0() |
| 1696 | | - .truncate() |
| 1697 | | - .text_size(px(12.)) |
| 1698 | | - .font_weight(FontWeight::MEDIUM) |
| 1699 | | - .text_color(p.ink3) |
| 1700 | | - .child(project.name.clone()), |
| 1701 | | - ) |
| 1702 | | - .when_some(host, |this, host| this.child(metal::tag(host, p))) |
| 1703 | | - .when(snoozed_until.is_some(), |this| { |
| 1704 | | - this.child(Icon::new(Lucide::AlarmClock).size(px(11.)).text_color(p.ink3)) |
| 1705 | | - }) |
| 1706 | | - .child(age), |
| 1707 | | - ) |
| 1708 | | - .child(title) |
| 1709 | | - .child( |
| 1710 | | - h_flex() |
| 1711 | | - .h(px(18.)) |
| 1712 | | - .gap(px(6.)) |
| 1713 | | - .text_color(p.ink3) |
| 1714 | | - .when_some(branch, |this, branch| { |
| 1715 | | - this.child(Icon::new(if in_worktree { Lucide::FolderGit2 } else { Lucide::GitBranch }).size(px(11.))) |
| 1716 | | - .child( |
| 1717 | | - div() |
| 1718 | | - .min_w_0() |
| 1719 | | - .truncate() |
| 1720 | | - .font_family(metal::MONO) |
| 1721 | | - .text_size(px(10.5)) |
| 1722 | | - .child(branch), |
| 1723 | | - ) |
| 1724 | | - }) |
| 1725 | | - .child(div().flex_1()) |
| 1726 | | - .child(pickers::provider_icon(state.provider, px(11.), p)) |
| 1727 | | - .child(actions) |
| 1728 | | - .child(led), |
| 1729 | | - ) |
| 1730 | | - }; |
| 1731 | | - card.context_menu(move |menu, window, cx| { |
| 1732 | | - Self::thread_menu(workspace.clone(), menu_session.clone(), menu, window, cx) |
| 1733 | | - }) |
| 1734 | | - .into_any_element() |
| 1735 | | - } |
| 1736 | | - |
| 1737 | | - /// A foldable section header in the thread list: `Settled (3) ——— ›`. |
| 1738 | | - fn render_fold( |
| 1739 | | - &self, |
| 1740 | | - id: &'static str, |
| 1741 | | - label: String, |
| 1742 | | - open: bool, |
| 1743 | | - toggle: fn(&mut Self), |
| 1744 | | - cx: &mut Context<Self>, |
| 1745 | | - ) -> AnyElement { |
| 1746 | | - let p = metal::palette(cx); |
| 1747 | | - h_flex() |
| 1748 | | - .id(id) |
| 1749 | | - .mt(px(10.)) |
| 1750 | | - .h(px(30.)) |
| 1751 | | - .px(px(12.)) |
| 1752 | | - .gap(px(8.)) |
| 1753 | | - .rounded(px(10.)) |
| 1754 | | - .cursor_pointer() |
| 1755 | | - .text_size(px(12.5)) |
| 1756 | | - .font_weight(FontWeight::MEDIUM) |
| 1757 | | - .text_color(p.ink3) |
| 1758 | | - .hover(|style| style.bg(p.row_hover).text_color(p.ink)) |
| 1759 | | - .on_click(cx.listener(move |this, _, _, cx| { |
| 1760 | | - toggle(this); |
| 1761 | | - cx.notify(); |
| 1762 | | - })) |
| 1763 | | - .child(label) |
| 1764 | | - .child(div().flex_1().h(px(1.)).bg(p.rule)) |
| 1765 | | - .child(Icon::new(if open { IconName::ChevronDown } else { IconName::ChevronRight }).size(px(12.))) |
| 1766 | | - .into_any_element() |
| 1767 | | - } |
| 1768 | | - |
| 1769 | | - /// A project's header in the grouped thread list. |
| 1770 | | - fn render_project_header(&self, ix: usize, count: usize, cx: &mut Context<Self>) -> AnyElement { |
| 1771 | | - let p = metal::palette(cx); |
| 1772 | | - let project = &self.projects[ix]; |
| 1773 | | - let collapsed = self.collapsed_projects.contains(&project.path); |
| 1774 | | - let path = project.path.clone(); |
| 1775 | | - h_flex() |
| 1776 | | - .id(("project-group", ix)) |
| 1777 | | - .group(SharedString::from(format!("project-group-{ix}"))) |
| 1778 | | - .mt(px(8.)) |
| 1779 | | - .h(px(30.)) |
| 1780 | | - .pl(px(10.)) |
| 1781 | | - .pr(px(4.)) |
| 1782 | | - .gap(px(7.)) |
| 1783 | | - .rounded(px(10.)) |
| 1784 | | - .cursor_pointer() |
| 1785 | | - .hover(|style| style.bg(p.row_hover)) |
| 1786 | | - .on_click(cx.listener(move |this, _, _, cx| { |
| 1787 | | - if !this.collapsed_projects.remove(&path) { |
| 1788 | | - this.collapsed_projects.insert(path.clone()); |
| 1789 | | - } |
| 1790 | | - cx.notify(); |
| 1791 | | - })) |
| 1792 | | - .child(Icon::new(if collapsed { IconName::ChevronRight } else { IconName::ChevronDown }).size(px(12.)).text_color(p.ink3)) |
| 1793 | | - .child(metal::badge(project.initials.clone(), project.tint, p)) |
| 1794 | | - .child( |
| 1795 | | - div() |
| 1796 | | - .flex_1() |
| 1797 | | - .min_w_0() |
| 1798 | | - .truncate() |
| 1799 | | - .text_size(px(12.5)) |
| 1800 | | - .font_weight(FontWeight::SEMIBOLD) |
| 1801 | | - .text_color(p.ink2) |
| 1802 | | - .child(project.name.clone()), |
| 1803 | | - ) |
| 1804 | | - .child(div().font_family(metal::MONO).text_size(px(10.5)).text_color(p.ink3).child(count.to_string())) |
| 1805 | | - .child( |
| 1806 | | - div().invisible().group_hover(SharedString::from(format!("project-group-{ix}")), |this| this.visible()).child( |
| 1807 | | - MetalButton::new(("project-new-thread", ix)) |
| 1808 | | - .ghost() |
| 1809 | | - .mini() |
| 1810 | | - .icon(Lucide::SquarePen) |
| 1811 | | - .tooltip(format!("New thread in {}", project.name)) |
| 1812 | | - .on_click(cx.listener(move |this, _, window, cx| { |
| 1813 | | - cx.stop_propagation(); |
| 1814 | | - this.new_thread(ix, window, cx); |
| 1815 | | - })), |
| 1816 | | - ), |
| 1817 | | - ) |
| 1818 | | - .into_any_element() |
| 1819 | | - } |
| 1820 | | - |
| 1821 | | - fn render_thread_list(&self, cx: &mut Context<Self>) -> impl IntoElement { |
| 1822 | | - let p = metal::palette(cx); |
| 1823 | | - let (open, settled) = self.threads(cx); |
| 1824 | | - let searching = !self.search.read(cx).value().trim().is_empty(); |
| 1825 | | - let (group, working_section) = settings::get(|settings| (settings.group_by_project, settings.working_section)); |
| 1826 | | - |
| 1827 | | - // Pinned threads stay on top; snoozed ones wait below; working ones |
| 1828 | | - // fold away (when set to) until they need the user. |
| 1829 | | - let mut pinned = Vec::new(); |
| 1830 | | - let mut snoozed = Vec::new(); |
| 1831 | | - let mut working = Vec::new(); |
| 1832 | | - let mut rest = Vec::new(); |
| 1833 | | - for entry in open { |
| 1834 | | - let state = entry.1.read(cx); |
| 1835 | | - if state.is_snoozed() { |
| 1836 | | - snoozed.push(entry); |
| 1837 | | - } else if state.pinned { |
| 1838 | | - pinned.push(entry); |
| 1839 | | - } else if working_section && state.is_working() && !state.needs_attention() { |
| 1840 | | - working.push(entry); |
| 1841 | | - } else { |
| 1842 | | - rest.push(entry); |
| 1843 | | - } |
| 1844 | | - } |
| 1845 | | - let is_empty = pinned.is_empty() && snoozed.is_empty() && working.is_empty() && rest.is_empty() && settled.is_empty(); |
| 1846 | | - let mut children: Vec<AnyElement> = Vec::new(); |
| 1847 | | - if !pinned.is_empty() { |
| 1848 | | - children.push( |
| 1849 | | - div() |
| 1850 | | - .px(px(12.)) |
| 1851 | | - .pt(px(2.)) |
| 1852 | | - .pb(px(4.)) |
| 1853 | | - .child(metal::engraved(format!("Pinned · {}", pinned.len()), p)) |
| 1854 | | - .into_any_element(), |
| 1855 | | - ); |
| 1856 | | - children.extend(pinned.iter().map(|(ix, session)| self.render_thread_card(*ix, session, cx))); |
| 1857 | | - if !rest.is_empty() || !working.is_empty() { |
| 1858 | | - children.push(div().px(px(12.)).py(px(6.)).child(metal::rule(p)).into_any_element()); |
| 1859 | | - } |
| 1860 | | - } |
| 1861 | | - if !working.is_empty() { |
| 1862 | | - let open = self.working_open || searching; |
| 1863 | | - children.push(self.render_fold( |
| 1864 | | - "working-toggle", |
| 1865 | | - format!("Working ({})", working.len()), |
| 1866 | | - open, |
| 1867 | | - |this| this.working_open = !this.working_open, |
| 1868 | | - cx, |
| 1869 | | - )); |
| 1870 | | - if open { |
| 1871 | | - children.extend(working.iter().map(|(ix, session)| self.render_thread_card(*ix, session, cx))); |
| 1872 | | - } |
| 1873 | | - } |
| 1874 | | - if group { |
| 1875 | | - for ix in self.ordered_projects(cx) { |
| 1876 | | - let threads: Vec<_> = rest.iter().filter(|(project, _)| *project == ix).collect(); |
| 1877 | | - if threads.is_empty() { |
| 1878 | | - continue; |
| 1879 | | - } |
| 1880 | | - children.push(self.render_project_header(ix, threads.len(), cx)); |
| 1881 | | - if searching || !self.collapsed_projects.contains(&self.projects[ix].path) { |
| 1882 | | - children.extend(threads.into_iter().map(|(ix, session)| self.render_thread_card(*ix, session, cx))); |
| 1883 | | - } |
| 1884 | | - } |
| 1885 | | - } else { |
| 1886 | | - children.extend(rest.iter().map(|(ix, session)| self.render_thread_card(*ix, session, cx))); |
| 1887 | | - } |
| 1888 | | - for (id, label, threads, open, toggle) in [ |
| 1889 | | - ( |
| 1890 | | - "snoozed-toggle", |
| 1891 | | - "Snoozed", |
| 1892 | | - snoozed, |
| 1893 | | - self.snoozed_open || searching, |
| 1894 | | - (|this: &mut Self| this.snoozed_open = !this.snoozed_open) as fn(&mut Self), |
| 1895 | | - ), |
| 1896 | | - ( |
| 1897 | | - "settled-toggle", |
| 1898 | | - "Settled", |
| 1899 | | - settled, |
| 1900 | | - self.settled_open || searching, |
| 1901 | | - |this: &mut Self| this.settled_open = !this.settled_open, |
| 1902 | | - ), |
| 1903 | | - ] { |
| 1904 | | - if threads.is_empty() { |
| 1905 | | - continue; |
| 1906 | | - } |
| 1907 | | - children.push(self.render_fold(id, format!("{label} ({})", threads.len()), open, toggle, cx)); |
| 1908 | | - if open { |
| 1909 | | - children.extend(threads.iter().map(|(ix, session)| self.render_thread_card(*ix, session, cx))); |
| 1910 | | - } |
| 1911 | | - } |
| 1912 | | - |
| 1913 | | - v_flex() |
| 1914 | | - .id("threads") |
| 1915 | | - .flex_1() |
| 1916 | | - .min_h_0() |
| 1917 | | - .overflow_y_scroll() |
| 1918 | | - .px(px(8.)) |
| 1919 | | - .pt(px(12.)) |
| 1920 | | - .pb(px(12.)) |
| 1921 | | - .gap(px(3.)) |
| 1922 | | - .when(is_empty, |this| { |
| 1923 | | - this.child( |
| 1924 | | - div() |
| 1925 | | - .px(px(12.)) |
| 1926 | | - .py(px(8.)) |
| 1927 | | - .text_size(px(12.5)) |
| 1928 | | - .text_color(p.ink3) |
| 1929 | | - .child(if searching { "No threads match." } else { "No threads yet." }), |
| 1930 | | - ) |
| 1931 | | - }) |
| 1932 | | - .children(children) |
| 1933 | | - } |
| 1934 | | - |
| 1935 | | - fn render_sidebar_footer(&self, cx: &mut Context<Self>) -> impl IntoElement { |
| 1936 | | - let p = metal::palette(cx); |
| 1937 | | - let catalog = Catalog::global(cx); |
| 1938 | | - let claude = catalog.first_of(Provider::Claude); |
| 1939 | | - let account = claude.and_then(|state| state.account.clone()); |
| 1940 | | - let checking = claude.is_some_and(|state| state.checking || state.checked.is_none()); |
| 1941 | | - let workspace = cx.entity().downgrade(); |
| 1942 | | - |
| 1943 | | - h_flex() |
| 1944 | | - .flex_none() |
| 1945 | | - .h(px(48.)) |
| 1946 | | - .px(px(12.)) |
| 1947 | | - .gap(px(8.)) |
| 1948 | | - .child( |
| 1949 | | - MetalButton::new("settings") |
| 1950 | | - .ghost() |
| 1951 | | - .compact() |
| 1952 | | - .icon(IconName::Settings2) |
| 1953 | | - .label("Settings") |
| 1954 | | - .tooltip("Settings (Ctrl+,)") |
| 1955 | | - .on_click(move |_, window, cx| { |
| 1956 | | - let _ = workspace.update(cx, |this, cx| this.open_settings(window, cx)); |
| 1957 | | - }), |
| 1958 | | - ) |
| 1959 | | - .child(div().flex_1()) |
| 1960 | | - .child( |
| 1961 | | - div() |
| 1962 | | - .min_w_0() |
| 1963 | | - .truncate() |
| 1964 | | - .font_family(metal::MONO) |
| 1965 | | - .text_size(px(10.5)) |
| 1966 | | - .text_color(p.ink3) |
| 1967 | | - .child(account.clone().unwrap_or_else(|| if checking { "Connecting…" } else { "Not signed in" }.into())), |
| 1968 | | - ) |
| 1969 | | - .child(metal::led("account-led", if account.is_some() { Led::Live } else { Led::Off }, false, p)) |
| 1970 | | - } |
| 1971 | | - |
| 1972 | | - fn render_sidebar(&self, cx: &mut Context<Self>) -> impl IntoElement { |
| 1973 | | - v_flex() |
| 1974 | | - .w(px(SIDEBAR_WIDTH)) |
| 1975 | | - .h_full() |
| 1976 | | - .flex_none() |
| 1977 | | - .child(self.render_sidebar_header(cx)) |
| 1978 | | - .child(self.render_sidebar_toolbar(cx)) |
| 1979 | | - .child(self.render_thread_list(cx)) |
| 1980 | | - .child(self.render_sidebar_footer(cx)) |
| 1981 | | - } |
| 1982 | | - |
| 1983 | 1641 | fn toggle_project_panel(&mut self, cx: &mut Context<Self>) { |
| 1984 | 1642 | // With the browser in its place, the project panel comes back. |
| 1985 | 1643 | if self.browser_open { |
| @@ -2023,92 +1681,6 @@ impl Workspace { |
| 2023 | 1681 | panel |
| 2024 | 1682 | } |
| 2025 | 1683 | |
| 2026 | | - /// The browser button, lit when the open thread's browser runs while |
| 2027 | | - /// the panel is closed, as when the agent opens a page. |
| 2028 | | - fn render_browser_toggle(&self, cx: &mut Context<Self>) -> impl IntoElement { |
| 2029 | | - let p = metal::palette(cx); |
| 2030 | | - let live = !self.browser_open |
| 2031 | | - && self.active.as_ref().is_some_and(|session| BrowserWatch::is_live(&session.read(cx).id, cx)); |
| 2032 | | - div() |
| 2033 | | - .relative() |
| 2034 | | - .child( |
| 2035 | | - MetalButton::new("toggle-browser") |
| 2036 | | - .ghost() |
| 2037 | | - .mini() |
| 2038 | | - .icon(IconName::Globe) |
| 2039 | | - .tooltip("Browser (Ctrl+Shift+E)") |
| 2040 | | - .on_click(cx.listener(|this, _, _, cx| { |
| 2041 | | - this.browser_open = !this.browser_open; |
| 2042 | | - cx.notify(); |
| 2043 | | - })), |
| 2044 | | - ) |
| 2045 | | - .when(live, |this| { |
| 2046 | | - this.child(div().absolute().top(px(1.)).right(px(1.)).child(metal::led("browser-live", Led::Live, false, p))) |
| 2047 | | - }) |
| 2048 | | - } |
| 2049 | | - |
| 2050 | | - fn render_top_bar(&self, panel_visible: bool, cx: &mut Context<Self>) -> impl IntoElement { |
| 2051 | | - let p = metal::palette(cx); |
| 2052 | | - let project = self.active_project(); |
| 2053 | | - let title = self.active.as_ref().map(|session| session.read(cx).title.clone()); |
| 2054 | | - |
| 2055 | | - v_flex() |
| 2056 | | - .flex_none() |
| 2057 | | - .child( |
| 2058 | | - h_flex() |
| 2059 | | - .h(px(52.)) |
| 2060 | | - .pl(px(if self.sidebar_open { 20. } else { 12. })) |
| 2061 | | - .pr(px(12.)) |
| 2062 | | - .gap(px(10.)) |
| 2063 | | - .when(!self.sidebar_open, |this| { |
| 2064 | | - this.child( |
| 2065 | | - MetalButton::new("show-sidebar") |
| 2066 | | - .ghost() |
| 2067 | | - .mini() |
| 2068 | | - .icon(Lucide::PanelLeftOpen) |
| 2069 | | - .tooltip("Show sidebar (Ctrl+B)") |
| 2070 | | - .on_click(cx.listener(|this, _, _, cx| { |
| 2071 | | - this.sidebar_open = true; |
| 2072 | | - cx.notify(); |
| 2073 | | - })), |
| 2074 | | - ) |
| 2075 | | - }) |
| 2076 | | - .when_some(project, |this, project| { |
| 2077 | | - this.child(metal::badge(project.initials.clone(), project.tint, p)).child( |
| 2078 | | - div() |
| 2079 | | - .flex_none() |
| 2080 | | - .text_size(px(14.)) |
| 2081 | | - .font_weight(FontWeight::MEDIUM) |
| 2082 | | - .text_color(p.ink2) |
| 2083 | | - .child(project.name.clone()), |
| 2084 | | - ) |
| 2085 | | - }) |
| 2086 | | - .when_some(title, |this, title| { |
| 2087 | | - this.child(div().text_size(px(14.)).text_color(p.ink3).child("/")).child( |
| 2088 | | - div() |
| 2089 | | - .flex_1() |
| 2090 | | - .min_w_0() |
| 2091 | | - .truncate() |
| 2092 | | - .text_size(px(14.)) |
| 2093 | | - .font_weight(FontWeight::SEMIBOLD) |
| 2094 | | - .text_color(p.ink) |
| 2095 | | - .child(title), |
| 2096 | | - ) |
| 2097 | | - }) |
| 2098 | | - .child(div().flex_1()) |
| 2099 | | - .child(self.render_browser_toggle(cx)) |
| 2100 | | - .child( |
| 2101 | | - MetalButton::new("toggle-panel") |
| 2102 | | - .ghost() |
| 2103 | | - .mini() |
| 2104 | | - .icon(if panel_visible { Lucide::PanelRightClose } else { Lucide::PanelRightOpen }) |
| 2105 | | - .tooltip("Project panel (Ctrl+Shift+B)") |
| 2106 | | - .on_click(cx.listener(|this, _, _, cx| this.toggle_project_panel(cx))), |
| 2107 | | - ), |
| 2108 | | - ) |
| 2109 | | - .child(metal::rule(p)) |
| 2110 | | - } |
| 2111 | | - |
| 2112 | 1684 | /// One row of the project panel: an icon, a label and an optional trailer. |
| 2113 | 1685 | fn panel_row(icon: impl Into<Icon>, label: impl Into<SharedString>, p: &Palette) -> Div { |
| 2114 | 1686 | h_flex() |
| @@ -2450,12 +2022,69 @@ impl Render for Workspace { |
| 2450 | 2022 | .text_color(p.ink) |
| 2451 | 2023 | .font_family(cx.theme().font_family.clone()) |
| 2452 | 2024 | .on_action(cx.listener(|this, _: &NewThread, window, cx| { |
| 2453 | | - if this.projects.is_empty() { |
| 2454 | | - this.prompt_for_project(window, cx); |
| 2025 | + // T3's chat.new: the project picker once there's a choice. |
| 2026 | + if this.legacy_sidebar() { |
| 2027 | + this.new_thread_button(true, window, cx); |
| 2455 | 2028 | } else { |
| 2456 | | - this.new_thread(this.active_project, window, cx); |
| 2029 | + this.new_thread_button(false, window, cx); |
| 2030 | + } |
| 2031 | + })) |
| 2032 | + .on_action(cx.listener(|this, _: &NewThreadLocal, window, cx| this.new_thread_button(true, window, cx))) |
| 2033 | + .on_action(cx.listener(|this, _: &NewThreadWithoutProject, window, cx| { |
| 2034 | + this.new_thread_without_project(window, cx) |
| 2035 | + })) |
| 2036 | + .on_action(cx.listener(|this, _: &ToggleCommandPalette, window, cx| this.toggle_palette(window, cx))) |
| 2037 | + .on_action(cx.listener(|this, _: &PreviousThread, window, cx| this.step_thread(-1, window, cx))) |
| 2038 | + .on_action(cx.listener(|this, _: &NextThread, window, cx| this.step_thread(1, window, cx))) |
| 2039 | + .on_action(cx.listener(|this, _: &SettleThread, window, cx| { |
| 2040 | + if let Some(session) = this.active.clone().filter(|session| !session.read(cx).is_blank()) { |
| 2041 | + this.toggle_settled(session, window, cx); |
| 2042 | + } |
| 2043 | + })) |
| 2044 | + .on_action(cx.listener(|this, _: &PinThread, window, cx| { |
| 2045 | + if let Some(session) = this.active.clone().filter(|session| !session.read(cx).is_blank()) { |
| 2046 | + this.toggle_pin(session, window, cx); |
| 2457 | 2047 | } |
| 2458 | 2048 | })) |
| 2049 | + .on_action(cx.listener(|this, _: &UndoThreadAction, window, cx| { |
| 2050 | + if !this.undo_latest(window, cx) { |
| 2051 | + cx.propagate(); |
| 2052 | + } |
| 2053 | + })) |
| 2054 | + .on_action(cx.listener(|this, _: &CopyThreadReference, window, cx| { |
| 2055 | + if let Some(session) = this.active.clone().filter(|session| !session.read(cx).is_blank()) { |
| 2056 | + Self::copy_thread_reference(&session, window, cx); |
| 2057 | + } |
| 2058 | + })) |
| 2059 | + .on_action(cx.listener(|this, _: &OpenUsage, window, cx| this.open_settings_page("Usage", window, cx))) |
| 2060 | + .on_action(cx.listener(|this, _: &ToggleRightPanel, _, cx| { |
| 2061 | + this.browser_open = !this.browser_open; |
| 2062 | + cx.notify(); |
| 2063 | + })) |
| 2064 | + .on_action(cx.listener(|this, _: &SelectTheme, window, cx| { |
| 2065 | + this.open_palette(palette::PaletteView::Themes, window, cx) |
| 2066 | + })) |
| 2067 | + .on_action(cx.listener(|this, _: &CycleAppearance, window, cx| this.cycle_appearance(window, cx))) |
| 2068 | + .on_key_down(cx.listener(|this, event: &KeyDownEvent, window, cx| this.jump_with_key(event, window, cx))) |
| 2069 | + // Dragging the sidebar's edge. |
| 2070 | + .when(self.resizing_sidebar, |this| { |
| 2071 | + this.cursor_col_resize() |
| 2072 | + .on_mouse_move(cx.listener(|this, event: &MouseMoveEvent, window, cx| { |
| 2073 | + let max = (window.viewport_size().width.as_f32() - MAIN_MIN_WIDTH).max(SIDEBAR_MIN_WIDTH); |
| 2074 | + this.sidebar_width = event.position.x.as_f32().clamp(SIDEBAR_MIN_WIDTH, max); |
| 2075 | + cx.notify(); |
| 2076 | + })) |
| 2077 | + .on_mouse_up( |
| 2078 | + MouseButton::Left, |
| 2079 | + cx.listener(|this, _, _, cx| { |
| 2080 | + this.resizing_sidebar = false; |
| 2081 | + cx.notify(); |
| 2082 | + }), |
| 2083 | + ) |
| 2084 | + }) |
| 2085 | + .on_modifiers_changed(cx.listener(|this, event: &ModifiersChangedEvent, window, cx| { |
| 2086 | + this.modifiers_changed(event, window, cx) |
| 2087 | + })) |
| 2459 | 2088 | .on_action(cx.listener(|this, _: &OpenProject, window, cx| { |
| 2460 | 2089 | this.prompt_for_project(window, cx) |
| 2461 | 2090 | })) |
| @@ -2482,7 +2111,7 @@ impl Render for Workspace { |
| 2482 | 2111 | } |
| 2483 | 2112 | })) |
| 2484 | 2113 | .when(self.settings_open, |this| this.child(self.settings_view.clone())) |
| 2485 | | - .when(!self.settings_open && self.sidebar_open, |this| this.child(self.render_sidebar(cx))) |
| 2114 | + .when(!self.settings_open && self.sidebar_open, |this| this.child(self.render_sidebar(window, cx))) |
| 2486 | 2115 | .when(!self.settings_open, |this| this.child( |
| 2487 | 2116 | div() |
| 2488 | 2117 | .flex_1() |
| @@ -2511,6 +2140,37 @@ impl Render for Workspace { |
| 2511 | 2140 | ), |
| 2512 | 2141 | ), |
| 2513 | 2142 | )) |
| 2143 | + // The command palette floats over everything; a click beside it closes it. |
| 2144 | + .when_some(self.palette.as_ref().map(|(palette, _)| palette.clone()), |this, palette| { |
| 2145 | + this.child( |
| 2146 | + div() |
| 2147 | + .absolute() |
| 2148 | + .inset_0() |
| 2149 | + .flex() |
| 2150 | + .flex_col() |
| 2151 | + .items_center() |
| 2152 | + .pt(window.viewport_size().height * 0.12) |
| 2153 | + .px(px(16.)) |
| 2154 | + .bg(black().opacity(if p.dark { 0.4 } else { 0.16 })) |
| 2155 | + .occlude() |
| 2156 | + .on_mouse_down( |
| 2157 | + MouseButton::Left, |
| 2158 | + cx.listener(|this, _, window, cx| this.close_palette(window, cx)), |
| 2159 | + ) |
| 2160 | + .child(div().on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation()).child(palette)), |
| 2161 | + ) |
| 2162 | + }) |
| 2163 | + .when_some(self.overlay_menu.as_ref(), |this, overlay| { |
| 2164 | + this.child( |
| 2165 | + deferred( |
| 2166 | + anchored() |
| 2167 | + .position(overlay.position) |
| 2168 | + .snap_to_window_with_margin(px(8.)) |
| 2169 | + .child(overlay.menu.clone()), |
| 2170 | + ) |
| 2171 | + .with_priority(2), |
| 2172 | + ) |
| 2173 | + }) |
| 2514 | 2174 | // The Add project browser floats over everything; a click beside it cancels. |
| 2515 | 2175 | .when_some(self.folder_browser.as_ref().map(|(browser, _)| browser.clone()), |this, browser| { |
| 2516 | 2176 | this.child( |