fix: rename RemoveSession to DeleteSession and implement separate delete logic
replace unnecessary clones with borrows in manager and main
This commit is contained in:
parent
1a0b8c49aa
commit
30e3bf6dbe
3 changed files with 21 additions and 16 deletions
|
|
@ -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
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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 },
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue