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
|
// Session lifecycle
|
||||||
SessionCommand::NewSession { name } => self.new_session(&name),
|
SessionCommand::NewSession { name } => self.new_session(&name),
|
||||||
SessionCommand::OpenSession { path } => self.open_session_file(&path),
|
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::SaveSession => self.save_session(),
|
||||||
SessionCommand::SelectSession { name } => self.select_session(&name),
|
SessionCommand::SelectSession { name } => self.select_session(&name),
|
||||||
SessionCommand::DuplicateSession { new_name } => self.duplicate_session(&new_name),
|
SessionCommand::DuplicateSession { new_name } => self.duplicate_session(&new_name),
|
||||||
|
|
@ -151,8 +152,8 @@ impl DocumentManager {
|
||||||
for session in &mut loaded {
|
for session in &mut loaded {
|
||||||
match session.kind {
|
match session.kind {
|
||||||
CollectionKind::DirectoryBrowser => {
|
CollectionKind::DirectoryBrowser => {
|
||||||
if let Some(dir) = session.path.clone() {
|
if let Some(ref dir) = session.path {
|
||||||
scan_directory_into(session, &dir);
|
scan_directory_into(session, dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CollectionKind::DocumentCollection => {
|
CollectionKind::DocumentCollection => {
|
||||||
|
|
@ -189,11 +190,19 @@ impl DocumentManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close_session(&mut self) {
|
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 {
|
let Some(idx) = self.active_session_index else {
|
||||||
return;
|
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 {
|
if self.sessions[idx].kind == CollectionKind::DirectoryBrowser {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -209,7 +218,7 @@ impl DocumentManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_session(&mut self) {
|
fn save_session(&mut self) {
|
||||||
let Some(path) = self.session_file_path.clone() else {
|
let Some(ref path) = self.session_file_path else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
if let Err(e) = store::save_sessions(&path, &self.sessions) {
|
if let Err(e) = store::save_sessions(&path, &self.sessions) {
|
||||||
|
|
@ -298,7 +307,7 @@ impl DocumentManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paste_document(&mut self) {
|
fn paste_document(&mut self) {
|
||||||
let Some(item) = self.clipboard.clone() else {
|
let Some(ref item) = self.clipboard else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -322,7 +331,7 @@ impl DocumentManager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
session.items.push(item);
|
session.items.push(item.clone());
|
||||||
session.items.len() - 1
|
session.items.len() - 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ pub enum SessionCommand {
|
||||||
NewSession { name: String },
|
NewSession { name: String },
|
||||||
/// Load sessions from an existing .ron file.
|
/// Load sessions from an existing .ron file.
|
||||||
OpenSession { path: PathBuf },
|
OpenSession { path: PathBuf },
|
||||||
/// Close and remove the active session from the store.
|
/// Close the active session (removes from runtime, kept in .ron file).
|
||||||
CloseSession,
|
CloseSession,
|
||||||
/// Persist all sessions to the .ron file.
|
/// Persist all sessions to the .ron file.
|
||||||
SaveSession,
|
SaveSession,
|
||||||
|
|
@ -35,8 +35,8 @@ pub enum SessionCommand {
|
||||||
/// When the source is a `DirectoryBrowser` this produces a snapshot:
|
/// When the source is a `DirectoryBrowser` this produces a snapshot:
|
||||||
/// the current items are copied into a new `DocumentCollection`.
|
/// the current items are copied into a new `DocumentCollection`.
|
||||||
DuplicateSession { new_name: String },
|
DuplicateSession { new_name: String },
|
||||||
/// Remove the active `DocumentCollection` session without saving.
|
/// Delete the active `DocumentCollection` session permanently (removed from .ron on save).
|
||||||
RemoveSession,
|
DeleteSession,
|
||||||
/// Rename the active `DocumentCollection` session.
|
/// Rename the active `DocumentCollection` session.
|
||||||
RenameSession { name: String },
|
RenameSession { name: String },
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -147,9 +147,7 @@ fn open_source(mgr: &mut DocumentManager, args: Args) {
|
||||||
exec(
|
exec(
|
||||||
mgr,
|
mgr,
|
||||||
&format!("Select '{session_name}'"),
|
&format!("Select '{session_name}'"),
|
||||||
SessionCommand::SelectSession {
|
SessionCommand::SelectSession { name: session_name },
|
||||||
name: session_name.clone(),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
exec(
|
exec(
|
||||||
mgr,
|
mgr,
|
||||||
|
|
@ -178,9 +176,7 @@ fn open_source(mgr: &mut DocumentManager, args: Args) {
|
||||||
exec(
|
exec(
|
||||||
mgr,
|
mgr,
|
||||||
&format!("Select '{session_name}'"),
|
&format!("Select '{session_name}'"),
|
||||||
SessionCommand::SelectSession {
|
SessionCommand::SelectSession { name: session_name },
|
||||||
name: session_name.clone(),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
exec(
|
exec(
|
||||||
mgr,
|
mgr,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue