Add project and branch chat controls

This commit is contained in:
Georg Bauer
2026-07-27 19:20:57 +02:00
parent 7d865df20f
commit aebfe7aeb6
6 changed files with 289 additions and 2 deletions

View File

@@ -66,6 +66,7 @@ pub(crate) struct App {
/// Unsaved sessions, keyed by project. A draft only becomes a `sessions` row
/// when its first chat turn is stored, so empty ones vanish on restart.
drafts: HashMap<i32, String>,
git_states: HashMap<i32, GitState>,
#[cfg(target_os = "macos")]
background_chats: HashMap<i32, ChatSnapshot>,
/// Session whose quick-actions menu is open.
@@ -195,6 +196,25 @@ struct ChatSnapshot {
skip_compaction_once: bool,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub(super) struct ProjectChoice {
id: i32,
name: String,
}
impl std::fmt::Display for ProjectChoice {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str(&self.name)
}
}
#[derive(Clone, Debug)]
pub(super) struct GitState {
pub(super) current: Option<String>,
pub(super) label: String,
pub(super) branches: Vec<String>,
}
#[cfg(target_os = "macos")]
impl ChatSnapshot {
fn needs_poll(&self) -> bool {
@@ -379,6 +399,8 @@ pub(crate) enum Message {
ToggleProject(i32),
DeleteProject(i32),
CreateSession(i32),
DraftProjectChanged(i32),
SwitchGitBranch(String),
DiscardSession(i32),
SelectSession(i32, i32),
RequestDeleteSession(i32),
@@ -456,6 +478,7 @@ impl App {
selected_project: last_project,
selected_session: None,
drafts,
git_states: HashMap::new(),
#[cfg(target_os = "macos")]
background_chats: HashMap::new(),
session_menu: None,
@@ -588,6 +611,7 @@ impl App {
selected_project: None,
selected_session: None,
drafts: HashMap::new(),
git_states: HashMap::new(),
#[cfg(target_os = "macos")]
background_chats: HashMap::new(),
session_menu: None,
@@ -906,6 +930,9 @@ impl App {
}
}
Message::WindowOpened(id) => {
if id == self.main_window {
self.refresh_git_state();
}
#[cfg(target_os = "macos")]
if id == self.main_window && self._native_menu.is_none() {
match crate::native_menu::install() {
@@ -1597,6 +1624,7 @@ impl App {
self.background_chats.remove(&session_id);
}
self.drafts.remove(&project_id);
self.git_states.remove(&project_id);
if self.config.interface.last_project_id == Some(project_id) {
self.config.interface.last_project_id = None;
let _ = self.config.save(&config_path());
@@ -1626,6 +1654,8 @@ impl App {
return focus_composer();
}
}
Message::DraftProjectChanged(project_id) => self.move_draft_to_project(project_id),
Message::SwitchGitBranch(branch) => self.switch_git_branch(&branch),
Message::DiscardSession(project_id) => self.discard_session(project_id),
Message::OpenSessionMenu(session_id) => {
self.session_rename = None;