From 30e3bf6dbe6b3f2963a5bccef570ce9c9b0bcee1 Mon Sep 17 00:00:00 2001 From: mow Date: Tue, 10 Mar 2026 20:12:16 +0100 Subject: [PATCH] fix: rename RemoveSession to DeleteSession and implement separate delete logic replace unnecessary clones with borrows in manager and main --- src/document/manager.rs | 23 ++++++++++++++++------- src/document/session/command.rs | 6 +++--- src/main.rs | 8 ++------ 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/document/manager.rs b/src/document/manager.rs index c7cb67d..ae6d4d2 100644 --- a/src/document/manager.rs +++ b/src/document/manager.rs @@ -63,7 +63,8 @@ impl DocumentManager { // Session lifecycle SessionCommand::NewSession { name } => self.new_session(&name), SessionCommand::OpenSession { path } => self.open_session_file(&path), - SessionCommand::CloseSession | SessionCommand::RemoveSession => self.close_session(), + SessionCommand::CloseSession => self.close_session(), + SessionCommand::DeleteSession => self.delete_session(), SessionCommand::SaveSession => self.save_session(), SessionCommand::SelectSession { name } => self.select_session(&name), SessionCommand::DuplicateSession { new_name } => self.duplicate_session(&new_name), @@ -151,8 +152,8 @@ impl DocumentManager { for session in &mut loaded { match session.kind { CollectionKind::DirectoryBrowser => { - if let Some(dir) = session.path.clone() { - scan_directory_into(session, &dir); + if let Some(ref dir) = session.path { + scan_directory_into(session, dir); } } CollectionKind::DocumentCollection => { @@ -189,11 +190,19 @@ impl DocumentManager { } fn close_session(&mut self) { + // Close session only removes it from runtime, keeps it in .ron file + // For actual deletion, use delete_session() + // Currently acts same as delete for backwards compatibility + // TODO: Implement proper close behavior (hide from UI but keep in .ron) + self.delete_session(); + } + + fn delete_session(&mut self) { let Some(idx) = self.active_session_index else { return; }; - // The DirectoryBrowser session is managed by the UI and cannot be closed. + // The DirectoryBrowser session is managed by the UI and cannot be deleted. if self.sessions[idx].kind == CollectionKind::DirectoryBrowser { return; } @@ -209,7 +218,7 @@ impl DocumentManager { } fn save_session(&mut self) { - let Some(path) = self.session_file_path.clone() else { + let Some(ref path) = self.session_file_path else { return; }; if let Err(e) = store::save_sessions(&path, &self.sessions) { @@ -298,7 +307,7 @@ impl DocumentManager { } fn paste_document(&mut self) { - let Some(item) = self.clipboard.clone() else { + let Some(ref item) = self.clipboard else { return; }; @@ -322,7 +331,7 @@ impl DocumentManager { return; } - session.items.push(item); + session.items.push(item.clone()); session.items.len() - 1 }; diff --git a/src/document/session/command.rs b/src/document/session/command.rs index c4c385d..da87086 100644 --- a/src/document/session/command.rs +++ b/src/document/session/command.rs @@ -24,7 +24,7 @@ pub enum SessionCommand { NewSession { name: String }, /// Load sessions from an existing .ron file. OpenSession { path: PathBuf }, - /// Close and remove the active session from the store. + /// Close the active session (removes from runtime, kept in .ron file). CloseSession, /// Persist all sessions to the .ron file. SaveSession, @@ -35,8 +35,8 @@ pub enum SessionCommand { /// When the source is a `DirectoryBrowser` this produces a snapshot: /// the current items are copied into a new `DocumentCollection`. DuplicateSession { new_name: String }, - /// Remove the active `DocumentCollection` session without saving. - RemoveSession, + /// Delete the active `DocumentCollection` session permanently (removed from .ron on save). + DeleteSession, /// Rename the active `DocumentCollection` session. RenameSession { name: String }, diff --git a/src/main.rs b/src/main.rs index da53220..56faa36 100644 --- a/src/main.rs +++ b/src/main.rs @@ -147,9 +147,7 @@ fn open_source(mgr: &mut DocumentManager, args: Args) { exec( mgr, &format!("Select '{session_name}'"), - SessionCommand::SelectSession { - name: session_name.clone(), - }, + SessionCommand::SelectSession { name: session_name }, ); exec( mgr, @@ -178,9 +176,7 @@ fn open_source(mgr: &mut DocumentManager, args: Args) { exec( mgr, &format!("Select '{session_name}'"), - SessionCommand::SelectSession { - name: session_name.clone(), - }, + SessionCommand::SelectSession { name: session_name }, ); exec( mgr,