diff --git a/Plans/03 File browsing/S011-file-op-actions.md b/Plans/03 File browsing/S011-file-op-actions.md index 849bac6..7965be5 100644 --- a/Plans/03 File browsing/S011-file-op-actions.md +++ b/Plans/03 File browsing/S011-file-op-actions.md @@ -10,12 +10,12 @@ Users can copy path, copy, cut, paste, rename, create folders, trash, delete, an crates/tunal-core/src/ops/ (job API); crates/tunal/src/folder/, src/shell/; crates/tunal/ui/components/{menu,dialog,toast}.slint. ## Steps -- [ ] Action registry: id, label, glyph, shortcut, enabled(selection, location capabilities); used by toolbar, shortcuts and a fixed default context menu (made editable in S013). -- [ ] Internal clipboard: copy/cut/paste (cut items dimmed), Copy path (Ctrl+Shift+C) as text on the system clipboard. -- [ ] Inline rename (F2, base name preselected) and new folder (Ctrl+Shift+N) inline. -- [ ] Trash (Del), delete permanently (Shift+Del, confirm dialog), restore/delete/empty in `trash:///`. -- [ ] Jobs bridge: progress toasts with cancel, conflict dialog (both sides' size/date, apply to all), partial-failure error list. -- [ ] PROGRESS entry, INDEX line, commit `S011: …` +- [x] Action registry: id, label, glyph, shortcut, enabled(selection, location capabilities); used by toolbar, shortcuts and a fixed default context menu (made editable in S013). +- [x] Internal clipboard: copy/cut/paste (cut items dimmed), Copy path (Ctrl+Shift+C) as text on the system clipboard. +- [x] Inline rename (F2, base name preselected) and new folder (Ctrl+Shift+N) inline. +- [x] Trash (Del), delete permanently (Shift+Del, confirm dialog), restore/delete/empty in `trash:///`. +- [x] Jobs bridge: progress toasts with cancel, conflict dialog (both sides' size/date, apply to all), partial-failure error list. +- [x] PROGRESS entry, INDEX line, commit `S011: …` ## End criteria - `cargo build --workspace`, `cargo clippy --workspace --all-targets -- -D warnings` and `cargo fmt --check` pass. diff --git a/Plans/INDEX.md b/Plans/INDEX.md index 679deab..bbfeec5 100644 --- a/Plans/INDEX.md +++ b/Plans/INDEX.md @@ -22,7 +22,7 @@ Tracker: https://claude.ai/artifact/4X8YCk3cQjUGyuyCqGuU7v - [x] [S008 — Folder model and details view](03%20File%20browsing/S008-folder-model-details.md) · Opus medium - [x] [S009 — Icon grid view and list motion](03%20File%20browsing/S009-grid-and-list-motion.md) · Opus high - [x] [S010 — Tabs, split view, breadcrumbs, history and places](03%20File%20browsing/S010-navigation-shell.md) · Opus medium -- [ ] [S011 — File operation actions](03%20File%20browsing/S011-file-op-actions.md) · Sonnet high +- [x] [S011 — File operation actions](03%20File%20browsing/S011-file-op-actions.md) · Sonnet high - [ ] [S012 — Properties, Open and Open with](03%20File%20browsing/S012-properties-open-with.md) · Sonnet medium - [ ] [S013 — Settings dialog and editable context menus](03%20File%20browsing/S013-settings-context-menus.md) · Sonnet high - [ ] [S014 — In-app drag and drop](03%20File%20browsing/S014-in-app-dnd.md) · Opus medium diff --git a/crates/tunal/src/actions.rs b/crates/tunal/src/actions.rs new file mode 100644 index 0000000..867b999 --- /dev/null +++ b/crates/tunal/src/actions.rs @@ -0,0 +1,574 @@ +//! File actions: one registry (id, label, glyph, shortcut, when enabled) behind the toolbar +//! menu, the keyboard and the context menu, plus the internal clipboard and what each action +//! does. Long work goes to the jobs bridge. + +use std::cell::RefCell; +use std::rc::{Rc, Weak}; + +use slint::platform::Key; +use slint::{ComponentHandle, Model, ModelRc, VecModel}; +use tunal_core::ops::{self, JobKind}; +use tunal_core::{Locations, Uri}; + +use crate::jobs_bridge::Bridge; +use crate::shell::Shell; +use crate::shell::pane::Pane; +use crate::{MainWindow, MenuEntry, MenuItem}; + +/// Every action, by stable id (the context menu editor refers to these). +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Action { + Cut, + Copy, + Paste, + CopyPath, + Rename, + NewFolder, + Trash, + Delete, + Restore, + EmptyTrash, +} + +enum Shortcut { + Char(char), + Key(Key), +} + +impl Action { + pub const ALL: [Action; 10] = [ + Self::Cut, + Self::Copy, + Self::Paste, + Self::CopyPath, + Self::Rename, + Self::NewFolder, + Self::Trash, + Self::Delete, + Self::Restore, + Self::EmptyTrash, + ]; + + #[expect( + dead_code, + reason = "the context menu editor (S013) refers to actions by id" + )] + pub fn id(self) -> &'static str { + match self { + Self::Cut => "cut", + Self::Copy => "copy", + Self::Paste => "paste", + Self::CopyPath => "copy-path", + Self::Rename => "rename", + Self::NewFolder => "new-folder", + Self::Trash => "trash", + Self::Delete => "delete", + Self::Restore => "restore", + Self::EmptyTrash => "empty-trash", + } + } + + pub fn label(self) -> &'static str { + match self { + Self::Cut => "Cut", + Self::Copy => "Copy", + Self::Paste => "Paste", + Self::CopyPath => "Copy path", + Self::Rename => "Rename", + Self::NewFolder => "New folder", + Self::Trash => "Move to Trash", + Self::Delete => "Delete permanently", + Self::Restore => "Restore", + Self::EmptyTrash => "Empty Trash", + } + } + + /// Material Symbols codepoint. + pub fn glyph(self) -> &'static str { + match self { + Self::Cut => "\u{f08b}", + Self::Copy => "\u{e14d}", + Self::Paste => "\u{e14f}", + Self::CopyPath => "\u{e157}", + Self::Rename => "\u{e3c9}", + Self::NewFolder => "\u{e2cc}", + Self::Trash => "\u{e872}", + Self::Delete => "\u{e92b}", + Self::Restore => "\u{e938}", + Self::EmptyTrash => "\u{e16c}", + } + } + + /// `(key, shift)`; every shortcut but F2 and Delete holds Ctrl. + fn shortcut(self) -> Option<(Shortcut, bool)> { + Some(match self { + Self::Cut => (Shortcut::Char('x'), false), + Self::Copy => (Shortcut::Char('c'), false), + Self::Paste => (Shortcut::Char('v'), false), + Self::CopyPath => (Shortcut::Char('c'), true), + Self::Rename => (Shortcut::Key(Key::F2), false), + Self::NewFolder => (Shortcut::Char('n'), true), + Self::Trash => (Shortcut::Key(Key::Delete), false), + Self::Delete => (Shortcut::Key(Key::Delete), true), + Self::Restore | Self::EmptyTrash => return None, + }) + } + + fn shortcut_text(self) -> String { + match self.shortcut() { + None => String::new(), + Some((Shortcut::Char(c), shift)) => { + format!( + "Ctrl+{}{}", + if shift { "Shift+" } else { "" }, + c.to_ascii_uppercase() + ) + } + Some((Shortcut::Key(key), shift)) => { + let name = if key == Key::F2 { "F2" } else { "Del" }; + format!("{}{name}", if shift { "Shift+" } else { "" }) + } + } + } + + fn matches(self, text: &str, ctrl: bool, shift: bool) -> bool { + let Some((key, wants_shift)) = self.shortcut() else { + return false; + }; + let (wants_ctrl, hit) = match key { + Shortcut::Char(c) => (true, text.eq_ignore_ascii_case(c.encode_utf8(&mut [0; 4]))), + Shortcut::Key(key) => (false, text == String::from(char::from(key))), + }; + hit && ctrl == wants_ctrl && shift == wants_shift + } + + pub fn enabled(self, ctx: &Context) -> bool { + let files = !ctx.in_trash; + match self { + Self::Cut => files && ctx.selected > 0 && ctx.writable, + Self::Copy => ctx.selected > 0, + Self::Paste => files && ctx.paste && ctx.writable, + Self::CopyPath => true, + Self::Rename => files && ctx.selected == 1 && ctx.writable, + Self::NewFolder => files && ctx.writable, + Self::Trash => files && ctx.selected > 0 && ctx.can_trash, + Self::Delete => ctx.selected > 0 && (ctx.writable || ctx.in_trash), + Self::Restore => ctx.in_trash && ctx.selected > 0, + Self::EmptyTrash => ctx.in_trash, + } + } +} + +/// What decides which actions apply. +pub struct Context { + /// Selected entries (the cursor entry when none is selected). + pub selected: usize, + pub in_trash: bool, + pub writable: bool, + pub can_trash: bool, + /// The clipboard holds something to paste. + pub paste: bool, +} + +/// The default context menu: `None` is a separator. +fn menu_layout(in_trash: bool) -> Vec> { + if in_trash { + return vec![ + Some(Action::Restore), + Some(Action::Copy), + Some(Action::CopyPath), + None, + Some(Action::Delete), + Some(Action::EmptyTrash), + ]; + } + vec![ + Some(Action::Cut), + Some(Action::Copy), + Some(Action::Paste), + None, + Some(Action::CopyPath), + Some(Action::Rename), + Some(Action::NewFolder), + None, + Some(Action::Trash), + Some(Action::Delete), + ] +} + +#[derive(Default)] +struct Clipboard { + uris: Vec, + cut: bool, +} + +pub struct Actions { + me: Weak, + ui: slint::Weak, + shell: Weak, + locations: Locations, + bridge: Rc, + clipboard: RefCell, + /// The actions of the open context menu, by item (separators are `None`). + menu: RefCell>>, +} + +impl Actions { + pub fn attach(ui: &MainWindow, shell: &Rc, locations: Locations) -> Rc { + let bridge = Bridge::attach(ui, locations.clone()); + let actions = Rc::new_cyclic(|me| Self { + me: me.clone(), + ui: ui.as_weak(), + shell: Rc::downgrade(shell), + locations, + bridge, + clipboard: RefCell::new(Clipboard::default()), + menu: RefCell::new(Vec::new()), + }); + let me = actions.me.clone(); + let shell_weak = Rc::downgrade(shell); + actions.bridge.set_on_finished(move || { + if let (Some(me), Some(shell)) = (me.upgrade(), shell_weak.upgrade()) { + me.refresh_unwatched(&shell); + } + }); + actions.bind(ui); + actions + } + + /// The items on the clipboard to be moved. + pub fn cut_uris(&self) -> Vec { + let clipboard = self.clipboard.borrow(); + if clipboard.cut { + clipboard.uris.clone() + } else { + Vec::new() + } + } + + fn shell(&self) -> Option> { + self.shell.upgrade() + } + + fn context(&self, pane: &Pane) -> Context { + let caps = pane + .dir() + .and_then(|d| self.locations.resolve(&d).ok()) + .map(|l| l.capabilities()) + .unwrap_or_default(); + Context { + selected: pane.model.selected_uris().len(), + in_trash: pane.dir().is_some_and(|d| d.scheme() == tunal_core::TRASH), + writable: caps.write, + can_trash: caps.trash, + paste: !self.clipboard.borrow().uris.is_empty(), + } + } + + // ---- menus and keys ----------------------------------------------------------------- + + fn menu_items(&self, pane: &Pane) -> Vec { + let ctx = self.context(pane); + let layout = menu_layout(ctx.in_trash); + let items = layout + .iter() + .map(|entry| match entry { + Some(action) => MenuItem { + text: action.label().into(), + icon: action.glyph().into(), + shortcut: action.shortcut_text().into(), + disabled: !action.enabled(&ctx), + separator: false, + submenu: ModelRc::new(VecModel::::default()), + }, + None => MenuItem { + text: Default::default(), + icon: Default::default(), + shortcut: Default::default(), + disabled: false, + separator: true, + submenu: ModelRc::new(VecModel::::default()), + }, + }) + .collect(); + *self.menu.borrow_mut() = layout; + items + } + + /// Opens the menu for the active pane; a right click on a row not in the selection + /// selects that row first. + fn open_menu(&self, pane: usize, row: i32, x: f32, y: f32) { + let Some(shell) = self.shell() else { + return; + }; + shell.activate_pane(pane); + let Some(p) = shell.active() else { + return; + }; + if let Some(r) = usize::try_from(row).ok() + && p.model + .row_data(r) + .is_some_and(|d| !d.selected && !d.header) + { + p.model.click(r, false, false); + } + let items = self.menu_items(&p); + if let Some(ui) = self.ui.upgrade() { + ui.set_context_menu_items(ModelRc::new(VecModel::from(items))); + ui.invoke_open_context_menu(x, y); + } + } + + fn menu_activated(&self, index: usize) { + let action = self.menu.borrow().get(index).copied().flatten(); + if let Some(action) = action { + self.run(action); + } + } + + /// A key the window saw: true when it was an enabled action's shortcut. + fn key(&self, text: &str, ctrl: bool, shift: bool, alt: bool) -> bool { + if alt || self.bridge.modal() { + return false; + } + let Some(pane) = self.shell().and_then(|s| s.active()) else { + return false; + }; + if pane.model.editing().is_some() { + return false; + } + let ctx = self.context(&pane); + let Some(action) = Action::ALL + .into_iter() + .find(|a| a.matches(text, ctrl, shift) && a.enabled(&ctx)) + else { + return false; + }; + self.run(action); + true + } + + // ---- actions ------------------------------------------------------------------------ + + pub fn run(&self, action: Action) { + let Some(shell) = self.shell() else { + return; + }; + let Some(pane) = shell.active() else { + return; + }; + let Some(dir) = pane.dir() else { + return; + }; + let uris = pane.model.selected_uris(); + match action { + Action::Copy => self.set_clipboard(&shell, uris, false), + Action::Cut => self.set_clipboard(&shell, uris, true), + Action::Paste => self.paste(&shell, dir), + Action::CopyPath => self.copy_path(&uris, &dir), + Action::Rename => { + // The name field takes the focus: don't hand it back to the view. + pane.model.begin_edit(); + return; + } + Action::NewFolder => self.new_folder(&pane, dir), + Action::Trash => self.bridge.submit(JobKind::Trash(uris)), + Action::Restore => self.bridge.submit(JobKind::Restore(uris)), + Action::Delete => { + let n = uris.len(); + let body = format!( + "{} will be deleted for good. This can't be undone.", + if n == 1 { + "This item".to_string() + } else { + format!("These {n} items") + } + ); + let me = self.me.clone(); + self.bridge + .confirm("Delete permanently?", &body, "Delete", move || { + if let Some(me) = me.upgrade() { + me.bridge.submit(JobKind::Delete(uris)); + } + }); + } + Action::EmptyTrash => { + let me = self.me.clone(); + self.bridge.confirm( + "Empty Trash?", + "Everything in the Trash will be deleted for good.", + "Empty Trash", + move || { + if let Some(me) = me.upgrade() { + me.bridge.submit(JobKind::EmptyTrash); + } + }, + ); + } + } + shell.focus_active(); + } + + fn set_clipboard(&self, shell: &Shell, uris: Vec, cut: bool) { + if uris.is_empty() { + return; + } + *self.clipboard.borrow_mut() = Clipboard { + uris: uris.clone(), + cut, + }; + self.show_cut(shell); + } + + /// Dims the cut items in every pane (none when the clipboard holds a copy). + fn show_cut(&self, shell: &Shell) { + let clipboard = self.clipboard.borrow(); + let cut: &[Uri] = if clipboard.cut { &clipboard.uris } else { &[] }; + for pane in shell.panes() { + pane.model.set_cut(cut); + } + } + + fn paste(&self, shell: &Shell, dest: Uri) { + let (sources, cut) = { + let clipboard = self.clipboard.borrow(); + (clipboard.uris.clone(), clipboard.cut) + }; + if sources.is_empty() { + return; + } + if cut { + *self.clipboard.borrow_mut() = Clipboard::default(); + self.show_cut(shell); + self.bridge.submit(JobKind::Move { sources, dest }); + } else { + self.bridge.submit(JobKind::Copy { sources, dest }); + } + } + + /// The selected paths (or the folder's) as text, one per line. + fn copy_path(&self, uris: &[Uri], dir: &Uri) { + let text = |uri: &Uri| match uri.to_path() { + Some(path) => path.to_string_lossy().into_owned(), + None => uri.to_string(), + }; + let lines: Vec = if uris.is_empty() { + vec![text(dir)] + } else { + uris.iter().map(text).collect() + }; + if let Some(ui) = self.ui.upgrade() { + ui.invoke_copy_text(lines.join("\n").into()); + } + self.bridge.notify(if lines.len() == 1 { + "Path copied".to_string() + } else { + format!("{} paths copied", lines.len()) + }); + } + + /// Makes `New folder` (numbered when taken) and starts editing its name once it shows. + fn new_folder(&self, pane: &Pane, dir: Uri) { + let mut name = b"New folder".to_vec(); + let mut n = 2; + while pane.model.has_name(&name) { + name = ops::numbered(b"New folder", n); + n += 1; + } + pane.model.select_when_shown(name.clone(), true); + self.bridge.submit(JobKind::Mkdir(dir.join(&name))); + } + + /// The edited name of the entry in `pane` was accepted. + fn renamed(&self, pane: usize, text: &str) { + let Some(p) = self.shell().and_then(|s| s.pane_at(pane)) else { + return; + }; + let (Some(name), Some(dir)) = (p.model.editing(), p.dir()) else { + return; + }; + p.model.end_edit(); + if let Some(shell) = self.shell() { + shell.focus_active(); + } + let new = text.as_bytes(); + if new == tunal_core::display_name(&name).as_bytes() || new.is_empty() { + return; + } + if new == b"." || new == b".." || new.contains(&b'/') || new.contains(&0) { + self.bridge + .notify("A name can't be “.”, “..” or contain “/”"); + return; + } + if p.model.has_name(new) { + self.bridge + .notify(format!("“{text}” already exists in this folder")); + return; + } + p.model.select_when_shown(new.to_vec(), false); + self.bridge.submit(JobKind::Rename { + from: dir.join(&name), + to: dir.join(new), + }); + } + + fn rename_cancelled(&self, pane: usize) { + if let Some(p) = self.shell().and_then(|s| s.pane_at(pane)) { + p.model.end_edit(); + } + if let Some(shell) = self.shell() { + shell.focus_active(); + } + } + + /// After a job: panes whose location can't watch (the Trash) list again. + fn refresh_unwatched(&self, shell: &Shell) { + for pane in shell.panes() { + let watches = pane + .dir() + .and_then(|d| self.locations.resolve(&d).ok()) + .is_some_and(|l| l.capabilities().watch); + if !watches { + pane.model.refresh(); + } + } + } + + fn bind(&self, ui: &MainWindow) { + let me = self.me.clone(); + ui.on_action_key(move |text, ctrl, shift, alt| { + me.upgrade().is_some_and(|a| a.key(&text, ctrl, shift, alt)) + }); + let me = self.me.clone(); + ui.on_context_menu_requested(move |pane, row, x, y| { + if let Some(a) = me.upgrade() { + a.open_menu(pane.max(0) as usize, row, x, y); + } + }); + let me = self.me.clone(); + ui.on_actions_menu_requested(move |x, y| { + if let Some(a) = me.upgrade() { + let active = a.shell().map_or(0, |s| s.active_index()); + a.open_menu(active, -1, x, y); + } + }); + let me = self.me.clone(); + ui.on_context_menu_activated(move |i| { + if let Some(a) = me.upgrade() { + a.menu_activated(i.max(0) as usize); + } + }); + let me = self.me.clone(); + ui.on_row_renamed(move |pane, _row, text| { + if let Some(a) = me.upgrade() { + a.renamed(pane.max(0) as usize, &text); + } + }); + let me = self.me.clone(); + ui.on_rename_cancelled(move |pane| { + if let Some(a) = me.upgrade() { + a.rename_cancelled(pane.max(0) as usize); + } + }); + } +} diff --git a/crates/tunal/src/folder/mod.rs b/crates/tunal/src/folder/mod.rs index 60a236d..55695b7 100644 --- a/crates/tunal/src/folder/mod.rs +++ b/crates/tunal/src/folder/mod.rs @@ -93,6 +93,17 @@ struct State { columns: usize, travel: Travel, travel_epoch: i32, + /// Items on the clipboard to be moved, drawn dimmed. + cut: HashSet, + /// The entry whose name is being edited in its row. + edit: Option>, + /// An entry still to appear (created or renamed): selected, and edited if asked, once shown. + pending: Option, +} + +struct Pending { + name: Vec, + edit: bool, } type Listener = Box; @@ -134,6 +145,9 @@ impl FolderModel { columns: 1, travel: Travel::None, travel_epoch: 0, + cut: HashSet::new(), + edit: None, + pending: None, }), notify: ModelNotify::default(), locations, @@ -199,6 +213,8 @@ impl FolderModel { s.selected.clear(); s.cursor = None; s.anchor = None; + s.edit = None; + s.pending = None; s.settings.filter.clear(); s.playlist_path = None; if let SortKey::Playlist(_) = s.settings.key { @@ -361,6 +377,22 @@ impl FolderModel { motion: s.epoch, travel: s.travel, travel_epoch: s.travel_epoch, + edit_row: s + .edit + .as_ref() + .and_then(|n| s.row_of.get(n)) + .map_or(-1, |&row| match s.settings.mode { + ViewMode::Details => row as i32, + // The grid scrolls by line. + ViewMode::Grid => motion::grid(&headers(&s), &[], s.columns) + .0 + .iter() + .position(|l| { + !l.header && (l.start..l.start + l.count).contains(&(row as i32)) + }) + .map_or(-1, |l| l as i32), + }), + edit_select: s.edit.as_ref().map_or(0, |n| base_len(&s, n)) as i32, } } @@ -650,6 +682,10 @@ impl FolderModel { let mut s = self.state.borrow_mut(); let before: HashSet> = s.selected.iter().chain(&s.cursor).cloned().collect(); f(&mut s); + // Moving the cursor away ends a name edit. + if s.edit.is_some() && s.edit != s.cursor { + s.edit = None; + } let after: HashSet> = s.selected.iter().chain(&s.cursor).cloned().collect(); let rows: Vec = before .symmetric_difference(&after) @@ -709,6 +745,118 @@ impl FolderModel { self.select(|s| s.selected.clear()); } + /// Selected entries, in the order shown (the cursor entry when nothing is selected). + pub fn selected_uris(&self) -> Vec { + let s = self.state.borrow(); + let Some(dir) = &s.dir else { + return Vec::new(); + }; + let names: Vec<&Vec> = if s.selected.is_empty() { + s.cursor.iter().collect() + } else { + s.rows + .iter() + .filter_map(|r| match r { + Row::Item(i) => Some(&s.items[*i].entry.name), + _ => None, + }) + .filter(|n| s.selected.contains(*n)) + .collect() + }; + names.into_iter().map(|n| dir.join(n)).collect() + } + + /// The items to draw dimmed: those on the clipboard to be moved. + pub fn set_cut(&self, uris: &[Uri]) { + let mut s = self.state.borrow_mut(); + let cut: HashSet = uris.iter().cloned().collect(); + if s.cut == cut { + return; + } + let dir = s.dir.clone(); + let rows: Vec = s + .rows + .iter() + .enumerate() + .filter_map(|(r, row)| match (row, &dir) { + (Row::Item(i), Some(d)) => { + let uri = d.join(&s.items[*i].entry.name); + (s.cut.contains(&uri) != cut.contains(&uri)).then_some(r) + } + _ => None, + }) + .collect(); + s.cut = cut; + drop(s); + for row in rows { + self.notify.row_changed(row); + } + } + + /// True when an entry with this exact name is in the folder. + pub fn has_name(&self, name: &[u8]) -> bool { + self.state.borrow().by_name.contains_key(name) + } + + /// Edits the name of the cursor entry in its row; false when there is none. + pub fn begin_edit(&self) -> bool { + let name = { + let s = self.state.borrow(); + s.cursor + .clone() + .filter(|n| s.row_of.contains_key(n)) + .or_else(|| s.selected.iter().next().cloned()) + }; + let Some(name) = name else { + return false; + }; + self.select(|s| { + s.selected = HashSet::from([name.clone()]); + s.anchor = Some(name.clone()); + s.cursor = Some(name.clone()); + s.edit = Some(name); + }); + self.emit(); + true + } + + pub fn end_edit(&self) { + let row = { + let mut s = self.state.borrow_mut(); + let name = s.edit.take(); + name.and_then(|n| s.row_of.get(&n).copied()) + }; + if let Some(row) = row { + self.notify.row_changed(row); + } + self.emit(); + } + + /// The entry being edited. + pub fn editing(&self) -> Option> { + self.state.borrow().edit.clone() + } + + /// Selects `name` once it shows up in the folder, and edits its name there if `edit`. + pub fn select_when_shown(&self, name: Vec, edit: bool) { + self.state.borrow_mut().pending = Some(Pending { name, edit }); + } + + /// Lists the folder again (locations that can't watch, the trash). + pub fn refresh(&self) { + let Some(dir) = self.dir() else { + return; + }; + let (selected, cursor) = { + let s = self.state.borrow(); + (s.selected.clone(), s.cursor.clone()) + }; + self.open(dir); + let mut s = self.state.borrow_mut(); + s.selected = selected; + s.cursor = cursor; + } + /// Keyboard move of the cursor; `page` is rows (details) or lines (grid) per page. /// Returns the line to show: the cursor row, or the grid line holding it (-1 for none). pub fn navigate(&self, key: NavKey, shift: bool, page: usize) -> i32 { @@ -951,6 +1099,41 @@ fn rebuild(s: &mut State) { if s.cursor.as_ref().is_some_and(|c| !row_of.contains_key(c)) { s.cursor = None; } + if s.edit.as_ref().is_some_and(|n| !s.row_of.contains_key(n)) { + s.edit = None; + } + if let Some(Pending { name, edit }) = s.pending.take_if(|p| s.row_of.contains_key(&p.name)) { + s.selected = HashSet::from([name.clone()]); + s.cursor = Some(name.clone()); + s.anchor = Some(name.clone()); + if edit { + s.edit = Some(name); + } + } +} + +/// Bytes of the display name before its extension (`.tar.gz` counts as one), or all of it +/// for a folder or a name without one: what editing a name preselects. +fn base_len(s: &State, name: &[u8]) -> usize { + let Some(&i) = s.by_name.get(name) else { + return 0; + }; + let item = &s.items[i]; + let text = item.entry.display_name.as_str(); + if item.is_dir { + return text.len(); + } + match text.rfind('.') { + Some(dot) if dot > 0 => { + let stem = &text[..dot]; + if stem.len() > 4 && stem.ends_with(".tar") { + stem.len() - 4 + } else { + dot + } + } + _ => text.len(), + } } /// Recomputes `row_of` from `rows`. @@ -1006,6 +1189,11 @@ fn row_data(s: &State, row: usize) -> Option { modified: entry.mtime.map(format::date).unwrap_or_default().into(), selected: s.selected.contains(&entry.name), cursor: s.cursor.as_ref() == Some(&entry.name), + dimmed: !s.cut.is_empty() + && s.dir + .as_ref() + .is_some_and(|d| s.cut.contains(&d.join(&entry.name))), + editing: s.edit.as_ref() == Some(&entry.name), ..Default::default() } } diff --git a/crates/tunal/src/jobs_bridge.rs b/crates/tunal/src/jobs_bridge.rs new file mode 100644 index 0000000..50ee283 --- /dev/null +++ b/crates/tunal/src/jobs_bridge.rs @@ -0,0 +1,530 @@ +//! Runs file operations for the window: progress toasts with cancel, the conflict dialog, +//! item errors with retry/skip/abort and the list of failures after a job. +//! +//! Jobs run on `tunal_core::ops::Jobs` threads; their events come back to the UI thread +//! here. Dialogs are asked one at a time, in the order the jobs raised them. + +use std::cell::RefCell; +use std::collections::{HashMap, VecDeque}; +use std::rc::{Rc, Weak}; +use std::time::Duration; + +use slint::{ComponentHandle, Model, ModelRc, Timer, VecModel}; +use tunal_core::ops::{ + ConflictAction, ConflictChoice, ConflictRequest, ErrorAction, ErrorRequest, JobEvent, + JobHandle, JobId, JobKind, Jobs, Phase, Progress, Report, +}; +use tunal_core::{Locations, Uri}; + +use crate::folder::format; +use crate::{ButtonKind, ConflictInfo, DialogAction, MainWindow, ToastData, ToastProgress}; + +/// A job that is still running after this long gets a progress toast; shorter ones don't flash. +const TOAST_DELAY: Duration = Duration::from_millis(300); + +thread_local! { + static BRIDGE: RefCell> = const { RefCell::new(Weak::new()) }; +} + +/// What the user is asked, one at a time. +enum Prompt { + Conflict(Box), + Error(ErrorRequest), + Failures { + title: String, + lines: Vec, + }, + Confirm { + title: String, + body: String, + action: String, + then: Box, + }, +} + +struct JobInfo { + handle: JobHandle, + kind: JobKind, +} + +#[derive(Default)] +struct State { + jobs: HashMap, + /// Job of each toast, parallel to the toast model (none for plain messages). + toast_jobs: Vec>, + queue: VecDeque, + active: Option, +} + +pub struct Bridge { + ui: slint::Weak, + jobs: Jobs, + toasts: Rc>, + state: RefCell, + /// Called after every finished job (panes that can't watch list again). + on_finished: RefCell>, + /// Keeps the delayed-toast timers alive. + timers: RefCell>, +} + +impl Bridge { + pub fn attach(ui: &MainWindow, locations: Locations) -> Rc { + let jobs = Jobs::new(locations, |id, event| { + let _ = slint::invoke_from_event_loop(move || { + if let Some(bridge) = BRIDGE.with(|b| b.borrow().upgrade()) { + bridge.event(id, event); + } + }); + }); + let bridge = Rc::new(Self { + ui: ui.as_weak(), + jobs, + toasts: Rc::new(VecModel::default()), + state: RefCell::new(State::default()), + on_finished: RefCell::new(Box::new(|| {})), + timers: RefCell::new(Vec::new()), + }); + BRIDGE.with(|b| *b.borrow_mut() = Rc::downgrade(&bridge)); + ui.set_toasts(ModelRc::from(bridge.toasts.clone())); + bridge.bind(ui); + bridge + } + + pub fn set_on_finished(&self, f: impl Fn() + 'static) { + *self.on_finished.borrow_mut() = Box::new(f); + } + + /// True while a dialog is open: the window's shortcuts stay quiet. + pub fn modal(&self) -> bool { + self.state.borrow().active.is_some() + } + + /// Queues a job; a toast follows if it runs long. + pub fn submit(&self, kind: JobKind) { + let handle = self.jobs.submit(kind.clone()); + let id = handle.id(); + self.state + .borrow_mut() + .jobs + .insert(id, JobInfo { handle, kind }); + let timer = Timer::default(); + timer.start(slint::TimerMode::SingleShot, TOAST_DELAY, move || { + if let Some(bridge) = BRIDGE.with(|b| b.borrow().upgrade()) { + bridge.show_progress(id); + } + }); + self.timers.borrow_mut().push(timer); + } + + /// A short message toast. + pub fn notify(&self, message: impl Into) { + self.state.borrow_mut().toast_jobs.push(None); + self.toasts.push(ToastData { + message: message.into().into(), + action: Default::default(), + cancellable: false, + progress_kind: ToastProgress::None, + progress: 0.0, + closing: false, + }); + } + + /// Asks `title` / `body`; `then` runs if the user confirms with `action`. + pub fn confirm(&self, title: &str, body: &str, action: &str, then: impl FnOnce() + 'static) { + self.prompt(Prompt::Confirm { + title: title.into(), + body: body.into(), + action: action.into(), + then: Box::new(then), + }); + } + + // ---- toasts ------------------------------------------------------------------------- + + fn toast_of(&self, job: JobId) -> Option { + self.state + .borrow() + .toast_jobs + .iter() + .position(|j| *j == Some(job)) + } + + fn progress_toast(&self, job: JobId, progress: &Progress) -> Option { + let state = self.state.borrow(); + let info = state.jobs.get(&job)?; + let (message, determinate) = match progress.phase { + Phase::Queued | Phase::Scanning => (format!("Preparing: {}", verb(&info.kind)), false), + Phase::Running | Phase::Finished => (describe(&info.kind), true), + }; + let fraction = if progress.total_bytes > 0 { + progress.done_bytes as f32 / progress.total_bytes as f32 + } else if progress.total_files > 0 { + progress.done_files as f32 / progress.total_files as f32 + } else { + 0.0 + }; + Some(ToastData { + message: message.into(), + action: Default::default(), + cancellable: true, + progress_kind: if determinate && progress.total_files > 0 { + ToastProgress::Determinate + } else { + ToastProgress::Indeterminate + }, + progress: fraction, + closing: false, + }) + } + + fn show_progress(&self, job: JobId) { + let Some(handle) = self.state.borrow().jobs.get(&job).map(|i| i.handle.clone()) else { + return; + }; + if self.toast_of(job).is_some() { + return; + } + let Some(data) = self.progress_toast(job, &handle.progress()) else { + return; + }; + self.state.borrow_mut().toast_jobs.push(Some(job)); + self.toasts.push(data); + } + + fn close_toast(&self, index: usize) { + if let Some(mut data) = self.toasts.row_data(index) { + data.closing = true; + self.toasts.set_row_data(index, data); + } + } + + fn toast_removed(&self, index: usize) { + if index < self.toasts.row_count() { + self.toasts.remove(index); + self.state.borrow_mut().toast_jobs.remove(index); + } + } + + fn toast_cancelled(&self, index: usize) { + let state = self.state.borrow(); + if let Some(info) = state + .toast_jobs + .get(index) + .copied() + .flatten() + .and_then(|job| state.jobs.get(&job)) + { + info.handle.cancel(); + } + } + + // ---- job events --------------------------------------------------------------------- + + fn event(&self, job: JobId, event: JobEvent) { + match event { + JobEvent::Progress(progress) => { + if let Some(i) = self.toast_of(job) + && let Some(data) = self.progress_toast(job, &progress) + { + self.toasts.set_row_data(i, data); + } + } + JobEvent::Conflict(request) => self.prompt(Prompt::Conflict(request)), + JobEvent::Error(request) => self.prompt(Prompt::Error(request)), + JobEvent::Finished(report) => self.finished(job, report), + } + } + + fn finished(&self, job: JobId, report: Report) { + if let Some(i) = self.toast_of(job) { + self.close_toast(i); + self.state.borrow_mut().toast_jobs[i] = None; + } + let Some(info) = self.state.borrow_mut().jobs.remove(&job) else { + return; + }; + if report.cancelled { + self.notify("Cancelled"); + } else if report.failures.is_empty() && !is_quick(&info.kind) { + self.notify(summary(&info.kind)); + } + if !report.failures.is_empty() { + let lines = report + .failures + .iter() + .map(|(uri, error)| format!("{}: {error}", name_of(uri))) + .collect(); + self.prompt(Prompt::Failures { + title: format!( + "{} couldn't be done for {} {}", + verb(&info.kind), + report.failures.len(), + if report.failures.len() == 1 { + "item" + } else { + "items" + } + ), + lines, + }); + } + (self.on_finished.borrow())(); + } + + // ---- dialogs ------------------------------------------------------------------------ + + fn prompt(&self, prompt: Prompt) { + let busy = { + let mut state = self.state.borrow_mut(); + state.queue.push_back(prompt); + state.active.is_some() + }; + if !busy { + self.next_prompt(); + } + } + + fn next_prompt(&self) { + let Some(ui) = self.ui.upgrade() else { + return; + }; + let Some(prompt) = self.state.borrow_mut().queue.pop_front() else { + return; + }; + match &prompt { + Prompt::Conflict(request) => { + ui.set_conflict(conflict_info(request)); + ui.invoke_show_conflict(); + } + Prompt::Confirm { + title, + body, + action, + .. + } => { + ui.set_confirm_title(title.into()); + ui.set_confirm_body(body.into()); + ui.set_confirm_action(action.into()); + ui.invoke_show_confirm(); + } + Prompt::Error(request) => { + // S016: when `request.needs_elevation()`, offer "Try as administrator" here. + let action = |text: &str| DialogAction { + text: text.into(), + kind: ButtonKind::Text, + }; + let mut body = format!("{}: {}.", name_of(&request.uri), request.error); + if request.needs_elevation() { + body.push_str(" Administrator rights are needed."); + } + ui.set_errors_title("Couldn't finish".into()); + ui.set_errors_body(body.into()); + ui.set_errors_lines(ModelRc::new(VecModel::default())); + ui.set_errors_actions(ModelRc::new(VecModel::from(vec![ + action("Abort"), + action("Skip all"), + action("Skip"), + DialogAction { + text: "Retry".into(), + kind: ButtonKind::Filled, + }, + ]))); + ui.set_errors_default(2); + ui.invoke_show_errors(); + } + Prompt::Failures { title, lines } => { + ui.set_errors_title(title.into()); + ui.set_errors_body("These were skipped:".into()); + ui.set_errors_lines(ModelRc::new(VecModel::from( + lines + .iter() + .map(|l| l.into()) + .collect::>(), + ))); + ui.set_errors_actions(ModelRc::new(VecModel::from(vec![DialogAction { + text: "OK".into(), + kind: ButtonKind::Filled, + }]))); + ui.set_errors_default(0); + ui.invoke_show_errors(); + } + } + self.state.borrow_mut().active = Some(prompt); + } + + /// The active prompt is answered: takes it and shows the next one. + fn finish_prompt(&self) -> Option { + let prompt = self.state.borrow_mut().active.take(); + self.next_prompt(); + prompt + } + + fn conflict_chosen(&self, choice: i32, all: bool) { + if let Some(ui) = self.ui.upgrade() { + ui.invoke_close_conflict(); + } + let Some(Prompt::Conflict(request)) = self.finish_prompt() else { + return; + }; + let action = match choice { + 1 => ConflictAction::AutoRename, + 2 => ConflictAction::Overwrite, + _ => ConflictAction::Skip, + }; + request.reply.send(ConflictChoice { + action, + apply_to_all: all, + }); + } + + fn confirm_answered(&self, yes: bool) { + if let Some(ui) = self.ui.upgrade() { + ui.invoke_close_confirm(); + } + if let Some(Prompt::Confirm { then, .. }) = self.finish_prompt() + && yes + { + then(); + } + } + + fn errors_answered(&self, index: i32) { + if let Some(ui) = self.ui.upgrade() { + ui.invoke_close_errors(); + } + if let Some(Prompt::Error(request)) = self.finish_prompt() { + request.reply.send(match index { + 0 => ErrorAction::Abort, + 1 => ErrorAction::SkipAll, + 3 => ErrorAction::Retry, + _ => ErrorAction::Skip, + }); + } + } + + fn bind(&self, ui: &MainWindow) { + let weak = || BRIDGE.with(|b| b.borrow().upgrade()); + ui.on_toast_cancelled(move |i| { + if let Some(b) = weak() { + b.toast_cancelled(i.max(0) as usize); + } + }); + ui.on_toast_removed(move |i| { + if let Some(b) = weak() { + b.toast_removed(i.max(0) as usize); + } + }); + ui.on_conflict_chosen(move |choice, all| { + if let Some(b) = weak() { + b.conflict_chosen(choice, all); + } + }); + ui.on_confirm_answered(move |yes| { + if let Some(b) = weak() { + b.confirm_answered(yes); + } + }); + ui.on_errors_answered(move |i| { + if let Some(b) = weak() { + b.errors_answered(i); + } + }); + } +} + +fn is_quick(kind: &JobKind) -> bool { + matches!(kind, JobKind::Mkdir(_) | JobKind::Rename { .. }) +} + +fn name_of(uri: &Uri) -> String { + uri.file_name() + .map(tunal_core::display_name) + .unwrap_or_else(|| uri.to_string()) +} + +fn items(n: usize) -> String { + if n == 1 { + "1 item".into() + } else { + format!("{n} items") + } +} + +fn count(kind: &JobKind) -> usize { + match kind { + JobKind::Copy { sources, .. } + | JobKind::Move { sources, .. } + | JobKind::Link { sources, .. } => sources.len(), + JobKind::Delete(uris) | JobKind::Trash(uris) | JobKind::Restore(uris) => uris.len(), + JobKind::EmptyTrash | JobKind::Mkdir(_) | JobKind::Rename { .. } => 1, + } +} + +/// `Copy`, `Move to Trash`: the action in the title of a failure list. +fn verb(kind: &JobKind) -> &'static str { + match kind { + JobKind::Copy { .. } => "Copy", + JobKind::Move { .. } => "Move", + JobKind::Delete(_) => "Delete", + JobKind::Trash(_) => "Move to Trash", + JobKind::Restore(_) => "Restore", + JobKind::EmptyTrash => "Empty Trash", + JobKind::Mkdir(_) => "New folder", + JobKind::Rename { .. } => "Rename", + JobKind::Link { .. } => "Link", + } +} + +/// The toast while a job runs: `Copying 3 items`. +fn describe(kind: &JobKind) -> String { + let n = items(count(kind)); + match kind { + JobKind::Copy { .. } => format!("Copying {n}"), + JobKind::Move { .. } => format!("Moving {n}"), + JobKind::Delete(_) => format!("Deleting {n}"), + JobKind::Trash(_) => format!("Moving {n} to Trash"), + JobKind::Restore(_) => format!("Restoring {n}"), + JobKind::EmptyTrash => "Emptying Trash".into(), + JobKind::Mkdir(_) => "Creating folder".into(), + JobKind::Rename { .. } => "Renaming".into(), + JobKind::Link { .. } => format!("Linking {n}"), + } +} + +/// The toast when a job is done: `Copied 3 items`. +fn summary(kind: &JobKind) -> String { + let n = items(count(kind)); + match kind { + JobKind::Copy { .. } => format!("Copied {n}"), + JobKind::Move { .. } => format!("Moved {n}"), + JobKind::Delete(_) => format!("Deleted {n}"), + JobKind::Trash(_) => format!("Moved {n} to Trash"), + JobKind::Restore(_) => format!("Restored {n}"), + JobKind::EmptyTrash => "Trash emptied".into(), + JobKind::Mkdir(_) => "Folder created".into(), + JobKind::Rename { .. } => "Renamed".into(), + JobKind::Link { .. } => format!("Linked {n}"), + } +} + +fn conflict_info(request: &ConflictRequest) -> ConflictInfo { + let side = |entry: &tunal_core::Entry| { + let size = if entry.kind.is_dir() { + "Folder".to_string() + } else { + format::size(entry.size) + }; + let date = entry.mtime.map(format::date).unwrap_or_default(); + (size, date) + }; + let (source_size, source_date) = side(&request.source_entry); + let (target_size, target_date) = side(&request.target_entry); + ConflictInfo { + name: name_of(&request.target).into(), + folder: request.target_entry.kind.is_dir() && request.source_entry.kind.is_dir(), + source_size: source_size.into(), + source_date: source_date.into(), + target_size: target_size.into(), + target_date: target_date.into(), + } +} diff --git a/crates/tunal/src/main.rs b/crates/tunal/src/main.rs index df0eb33..5e8bbae 100644 --- a/crates/tunal/src/main.rs +++ b/crates/tunal/src/main.rs @@ -1,6 +1,8 @@ +mod actions; mod config; mod folder; mod icons; +mod jobs_bridge; mod screenshot; mod shell; mod theme_bridge; diff --git a/crates/tunal/src/shell/mod.rs b/crates/tunal/src/shell/mod.rs index 0aadf7e..6b93aac 100644 --- a/crates/tunal/src/shell/mod.rs +++ b/crates/tunal/src/shell/mod.rs @@ -1,11 +1,11 @@ //! The navigation shell: tabs of one or two panes, history, the breadcrumb, the places //! sidebar and the status bar, bound to the `MainWindow`. -mod pane; +pub(crate) mod pane; mod path; pub mod places; -use std::cell::{Cell, RefCell}; +use std::cell::{Cell, OnceCell, RefCell}; use std::rc::{Rc, Weak}; use std::sync::Arc; use std::sync::atomic::{AtomicU64, Ordering}; @@ -13,6 +13,7 @@ use std::sync::atomic::{AtomicU64, Ordering}; use slint::{ComponentHandle, Model, ModelRc, VecModel}; use tunal_core::{Locations, Uri}; +use crate::actions::Actions; use crate::config::{self, Session, TabSession}; use crate::folder::format; use crate::{ @@ -51,6 +52,8 @@ pub struct Shell { menu_target: Cell>, /// Bumped per completion request; older results are dropped. completion: Arc, + /// The file actions; set once the shell exists. + actions: OnceCell>, } impl Shell { @@ -76,7 +79,11 @@ impl Shell { places: RefCell::new(Places::load()), menu_target: Cell::new(None), completion: Arc::new(AtomicU64::new(0)), + actions: OnceCell::new(), }); + let _ = shell + .actions + .set(Actions::attach(ui, &shell, shell.locations.clone())); ui.set_tabs(ModelRc::from(shell.tab_rows.clone())); ui.set_panes(ModelRc::from(shell.pane_rows.clone())); let settings: config::Settings = config::load("settings"); @@ -161,6 +168,9 @@ impl Shell { shell.pane_changed(id); } }); + if let Some(actions) = self.actions.get() { + pane.model.set_cut(&actions.cut_uris()); + } pane.go(uri); pane } @@ -287,17 +297,33 @@ impl Shell { // ---- panes -------------------------------------------------------------------------- - fn active(&self) -> Option> { + pub(crate) fn active(&self) -> Option> { let tabs = self.tabs.borrow(); let tab = tabs.get(self.current.get())?; tab.panes.get(tab.active).cloned() } - fn pane_at(&self, index: usize) -> Option> { + pub(crate) fn pane_at(&self, index: usize) -> Option> { let tabs = self.tabs.borrow(); tabs.get(self.current.get())?.panes.get(index).cloned() } + /// Every pane of every tab. + pub(crate) fn panes(&self) -> Vec> { + let tabs = self.tabs.borrow(); + tabs.iter().flat_map(|t| t.panes.iter().cloned()).collect() + } + + /// Index of the active pane in the current tab. + pub(crate) fn active_index(&self) -> usize { + let tabs = self.tabs.borrow(); + tabs.get(self.current.get()).map_or(0, |t| t.active) + } + + pub(crate) fn activate_pane(&self, index: usize) { + self.set_active_pane(index); + } + fn set_active_pane(&self, index: usize) { let changed = { let mut tabs = self.tabs.borrow_mut(); @@ -461,7 +487,7 @@ impl Shell { } } - fn focus_active(&self) { + pub(crate) fn focus_active(&self) { if let Some(ui) = self.ui.upgrade() { ui.set_focus_request(ui.get_focus_request().wrapping_add(1)); } diff --git a/crates/tunal/ui/app.slint b/crates/tunal/ui/app.slint index e2ffa5b..86677d8 100644 --- a/crates/tunal/ui/app.slint +++ b/crates/tunal/ui/app.slint @@ -13,9 +13,14 @@ import { Crumb, Completion, CompletionList } from "shell/breadcrumb.slint"; import { Pane, PaneData } from "shell/pane.slint"; import { Sidebar, SidebarSection, PlaceItem } from "shell/sidebar.slint"; import { StatusBar } from "shell/status-bar.slint"; +import { ToastStack, ToastData, ToastProgress } from "components/toast.slint"; +import { DialogAction } from "components/dialog.slint"; +import { ConflictDialog, ConflictInfo } from "dialogs/conflict.slint"; +import { ConfirmDialog } from "dialogs/confirm.slint"; +import { ErrorsDialog } from "dialogs/errors.slint"; export { Theme, MotionPrefs, MenuItem, MenuEntry, DetailRow, FolderState, FolderStatus, Grouping, NavKey, SortColumn, Travel, ViewMode, GridRow } -export { TabData, PaneData, Crumb, Completion, SidebarSection, PlaceItem } +export { ButtonKind, TabData, PaneData, Crumb, Completion, SidebarSection, PlaceItem, ToastData, ToastProgress, DialogAction, ConflictInfo } export { Gallery, GalleryPage } from "gallery.slint"; // The window: sidebar, tab bar, toolbar with the breadcrumb, the panes of the current tab @@ -64,6 +69,34 @@ export component MainWindow inherits Window { in property <[MenuItem]> sort-menu; callback sort-menu-activated(int, int); + // File actions (actions.rs): the keys, the context menu, inline rename, jobs. + // Called for every key the window sees with Ctrl, or a function or Delete key; true when + // it was an action's shortcut. + callback action-key(string, bool, bool, bool) -> bool; + in property <[MenuItem]> context-menu-items; + // A right click in pane `i` on row (-1: none) at window coordinates. + callback context-menu-requested(int, int, length, length); + callback actions-menu-requested(length, length); + callback context-menu-activated(int); + callback row-renamed(int, int, string); + callback rename-cancelled(int); + in property <[ToastData]> toasts; + callback toast-cancelled(int); + callback toast-removed(int); + in property conflict; + callback conflict-chosen(int, bool); + in property confirm-title; + in property confirm-body; + in property confirm-action; + callback confirm-answered(bool); + in property errors-title; + in property errors-body; + in property <[string]> errors-lines; + in property <[DialogAction]> errors-actions; + // The button Enter and Escape press. + in property errors-default; + callback errors-answered(int); + // Navigation of the active pane. in property can-back; in property can-forward; @@ -104,12 +137,61 @@ export component MainWindow inherits Window { rename-dialog.show(); } + public function open-context-menu(x: length, y: length) { + context-popup.open-at(x, y); + } + + public function show-conflict() { + conflict-dialog.apply-all = false; + conflict-dialog.show(); + } + + public function close-conflict() { + conflict-dialog.close(); + } + + public function show-confirm() { + confirm-dialog.show(); + } + + public function close-confirm() { + confirm-dialog.close(); + } + + public function show-errors() { + errors-dialog.show(); + } + + public function close-errors() { + errors-dialog.close(); + } + + // Puts `text` on the system clipboard. + public function copy-text(text: string) { + clip.text = text; + clip.select-all(); + clip.copy(); + } + public function edit-path() { toolbar.edit-path(); } + // Holds the text `copy-text` puts on the clipboard. + clip := TextInput { + visible: false; + width: 0; + height: 0; + } + shortcuts := FocusScope { capture-key-pressed(event) => { + // Text fields (breadcrumb, rename) keep their own editing keys; Rust checks the rest. + if !toolbar.editing + && (event.modifiers.control || event.text == Key.F2 || event.text == Key.Delete) + && root.action-key(event.text, event.modifiers.control, event.modifiers.shift, event.modifiers.alt) { + return accept; + } if event.modifiers.control && !event.modifiers.alt { if event.text == Key.Tab || event.text == Key.Backtab { root.cycle-tab(event.modifiers.shift || event.text == Key.Backtab); @@ -228,6 +310,9 @@ export component MainWindow inherits Window { toggle-split => { root.toggle-split(); } + actions(x, y) => { + root.actions-menu-requested(x, y); + } toggle-sidebar => { root.toggle-sidebar(); } @@ -311,6 +396,15 @@ export component MainWindow inherits Window { motion-settled => { root.motion-settled(i); } + row-renamed(row, text) => { + root.row-renamed(i, row, text); + } + rename-cancelled => { + root.rename-cancelled(i); + } + context-menu(row, x, y) => { + root.context-menu-requested(i, row, x, y); + } } } @@ -352,6 +446,19 @@ export component MainWindow inherits Window { } } + context-popup := Menu { + width: 100%; + height: 100%; + items: root.context-menu-items; + leading-icons: true; + activated(index, sub) => { + root.context-menu-activated(index); + } + closed => { + root.focus-pane(); + } + } + place-popup := Menu { width: 100%; height: 100%; @@ -385,4 +492,50 @@ export component MainWindow inherits Window { label: "Name"; } } + + conflict-dialog := ConflictDialog { + width: 100%; + height: 100%; + info: root.conflict; + chosen(choice, all) => { + root.conflict-chosen(choice, all); + } + } + + confirm-dialog := ConfirmDialog { + width: 100%; + height: 100%; + title: root.confirm-title; + body: root.confirm-body; + action-text: root.confirm-action; + answered(yes) => { + root.confirm-answered(yes); + } + } + + errors-dialog := ErrorsDialog { + width: 100%; + height: 100%; + title: root.errors-title; + body: root.errors-body; + lines: root.errors-lines; + actions: root.errors-actions; + default-action: root.errors-default; + cancel-action: root.errors-default; + answered(i) => { + root.errors-answered(i); + } + } + + ToastStack { + width: 100%; + height: 100%; + toasts: root.toasts; + cancelled(i) => { + root.toast-cancelled(i); + } + removed(i) => { + root.toast-removed(i); + } + } } diff --git a/crates/tunal/ui/components/icon.slint b/crates/tunal/ui/components/icon.slint index 0847786..3ba56a9 100644 --- a/crates/tunal/ui/components/icon.slint +++ b/crates/tunal/ui/components/icon.slint @@ -51,4 +51,6 @@ export global Icons { out property bookmark-add: "\u{e598}"; out property expand-more: "\u{e5cf}"; out property side-navigation: "\u{e9e2}"; + out property more-vert: "\u{e5d4}"; + out property create-new-folder: "\u{e2cc}"; } diff --git a/crates/tunal/ui/components/list-row.slint b/crates/tunal/ui/components/list-row.slint index fa7f597..4412dd6 100644 --- a/crates/tunal/ui/components/list-row.slint +++ b/crates/tunal/ui/components/list-row.slint @@ -2,6 +2,7 @@ import { Theme } from "../theme.slint"; import { Motion } from "../motion.slint"; import { Icon } from "icon.slint"; import { StateLayer } from "state-layer.slint"; +import { RenameField } from "rename-field.slint"; // One row of a list: leading icon, title, optional supporting line, and a trailing slot for // the row's children. Selection grows a tonal fill from the centre. @@ -13,6 +14,11 @@ export component ListRow inherits StateLayer { in property title; in property supporting; in property selected; + // Shows the title as an edit field (see RenameField); `edit-select` bytes are preselected. + in property editing; + in property edit-select; + callback renamed(text: string); + callback rename-cancelled(); property title-color: !root.enabled ? Theme.on-surface.with-alpha(Theme.disabled-content) : root.selected ? Theme.on-secondary-container @@ -78,7 +84,18 @@ export component ListRow inherits StateLayer { alignment: center; horizontal-stretch: 1; - Text { + if root.editing: RenameField { + text: root.title; + select-end: root.edit-select; + accepted(text) => { + root.renamed(text); + } + cancelled => { + root.rename-cancelled(); + } + } + + if !root.editing: Text { text: root.title; color: root.title-color; font-size: Theme.body-medium.size; diff --git a/crates/tunal/ui/components/rename-field.slint b/crates/tunal/ui/components/rename-field.slint new file mode 100644 index 0000000..a680f0a --- /dev/null +++ b/crates/tunal/ui/components/rename-field.slint @@ -0,0 +1,71 @@ +import { Theme } from "../theme.slint"; +import { Motion } from "../motion.slint"; + +// A name edited in place of its label: a framed text input that takes the focus when it +// appears, with the first `select-end` bytes (the name without its extension) selected. +// Enter accepts, Escape cancels; the owner removes the field either way (clicking another +// row ends the edit from Rust). +export component RenameField inherits Rectangle { + in property text; + in property select-end; + in property alignment: left; + callback accepted(text: string); + callback cancelled(); + + property finished; + + function finish(accept: bool) { + if !root.finished { + root.finished = true; + if accept { + root.accepted(input.text); + } else { + root.cancelled(); + } + } + } + + min-height: input.preferred-height + 2 * Theme.space-1; + background: Theme.surface; + border-radius: Theme.corner-xs; + border-width: Theme.focus-ring-width; + border-color: Theme.primary; + clip: true; + + init => { + input.focus(); + input.set-selection-offsets(0, root.select-end); + } + + FocusScope { + width: 100%; + height: 100%; + + key-pressed(event) => { + if event.text == Key.Escape { + root.finish(false); + return accept; + } + reject + } + + input := TextInput { + x: Theme.space-2; + width: parent.width - 2 * Theme.space-2; + height: parent.height; + vertical-alignment: center; + text: root.text; + color: Theme.on-surface; + selection-background-color: Theme.primary-container; + selection-foreground-color: Theme.on-primary-container; + font-size: Theme.body-medium.size; + font-weight: Theme.body-medium.weight; + horizontal-alignment: root.alignment; + single-line: true; + accessible-label: "Name"; + accepted => { + root.finish(true); + } + } + } +} diff --git a/crates/tunal/ui/components/state-layer.slint b/crates/tunal/ui/components/state-layer.slint index 6dec2ab..411f49b 100644 --- a/crates/tunal/ui/components/state-layer.slint +++ b/crates/tunal/ui/components/state-layer.slint @@ -40,6 +40,7 @@ export component StateLayer inherits Rectangle { callback pointer(PointerEvent); callback moved(); out property mouse-x: touch.mouse-x; + out property mouse-y: touch.mouse-y; out property pressed-x: touch.pressed-x; property keyboard-focus; diff --git a/crates/tunal/ui/dialogs/confirm.slint b/crates/tunal/ui/dialogs/confirm.slint new file mode 100644 index 0000000..2568054 --- /dev/null +++ b/crates/tunal/ui/dialogs/confirm.slint @@ -0,0 +1,15 @@ +import { Dialog } from "../components/dialog.slint"; +import { ButtonKind } from "../components/button.slint"; + +// Asks before something that can't be undone. `answered(true)` runs it; Esc cancels. +export component ConfirmDialog inherits Dialog { + in property action-text: "Delete"; + callback answered(bool); + + actions: [{ text: "Cancel", kind: ButtonKind.text }, { text: root.action-text, kind: ButtonKind.filled }]; + default-action: 0; + cancel-action: 0; + action(i) => { + root.answered(i == 1); + } +} diff --git a/crates/tunal/ui/dialogs/conflict.slint b/crates/tunal/ui/dialogs/conflict.slint new file mode 100644 index 0000000..64ab318 --- /dev/null +++ b/crates/tunal/ui/dialogs/conflict.slint @@ -0,0 +1,99 @@ +import { Theme } from "../theme.slint"; +import { Dialog } from "../components/dialog.slint"; +import { ButtonKind } from "../components/button.slint"; +import { Switch } from "../components/switch.slint"; + +// The two sides of a name clash, formatted by Rust. +export struct ConflictInfo { + name: string, + folder: bool, + source-size: string, + source-date: string, + target-size: string, + target-date: string, +} + +component Side inherits VerticalLayout { + in property title; + in property size; + in property date; + + spacing: Theme.space-1; + horizontal-stretch: 1; + + Text { + text: root.title; + color: Theme.primary; + font-size: Theme.label-medium.size; + font-weight: Theme.label-medium.weight; + } + + Text { + text: root.size; + color: Theme.on-surface; + font-size: Theme.body-medium.size; + font-weight: Theme.body-medium.weight; + } + + Text { + text: root.date; + color: Theme.on-surface-variant; + font-size: Theme.body-small.size; + font-weight: Theme.body-small.weight; + } +} + +// Asked when a copy, move or restore finds the name taken. `chosen(0|1|2, all)`: skip, +// keep both (the new item gets a numbered name), replace. +export component ConflictDialog inherits Dialog { + in property info; + in-out property apply-all; + callback chosen(int, bool); + + title: root.info.folder ? "Folder already exists" : "File already exists"; + body: "“" + root.info.name + "” is already in the destination."; + dialog-width: 440px; + actions: [ + { text: "Skip", kind: ButtonKind.text }, + { text: "Keep both", kind: ButtonKind.tonal }, + { text: root.info.folder ? "Merge" : "Replace", kind: ButtonKind.filled }, + ]; + default-action: 1; + cancel-action: 0; + action(i) => { + root.chosen(i, root.apply-all); + } + + HorizontalLayout { + spacing: Theme.space-4; + + Side { + title: "Existing"; + size: root.info.target-size; + date: root.info.target-date; + } + + Side { + title: "New"; + size: root.info.source-size; + date: root.info.source-date; + } + } + + HorizontalLayout { + spacing: Theme.space-3; + + all := Switch { + checked <=> root.apply-all; + accessible-label: "Do this for all conflicts"; + } + + Text { + text: "Do this for all conflicts"; + color: Theme.on-surface; + font-size: Theme.body-medium.size; + font-weight: Theme.body-medium.weight; + vertical-alignment: center; + } + } +} diff --git a/crates/tunal/ui/dialogs/errors.slint b/crates/tunal/ui/dialogs/errors.slint new file mode 100644 index 0000000..8f24ed0 --- /dev/null +++ b/crates/tunal/ui/dialogs/errors.slint @@ -0,0 +1,30 @@ +import { ListView } from "std-widgets.slint"; +import { Theme } from "../theme.slint"; +import { Dialog } from "../components/dialog.slint"; + +// One item that failed, or a list of them after a job: `lines` shows below the body. The +// owner sets `actions` (retry/skip/abort while a job waits, OK for the final list) and +// `answered(i)` reports the button. +export component ErrorsDialog inherits Dialog { + in property <[string]> lines; + callback answered(int); + + dialog-width: 480px; + action(i) => { + root.answered(i); + } + + if root.lines.length > 0: ListView { + height: min(root.lines.length, 6) * 24px; + + for line in root.lines: Text { + height: 24px; + text: line; + color: Theme.on-surface-variant; + font-size: Theme.body-small.size; + font-weight: Theme.body-small.weight; + vertical-alignment: center; + overflow: elide; + } + } +} diff --git a/crates/tunal/ui/shell/pane.slint b/crates/tunal/ui/shell/pane.slint index 3678680..417d151 100644 --- a/crates/tunal/ui/shell/pane.slint +++ b/crates/tunal/ui/shell/pane.slint @@ -38,9 +38,15 @@ export component Pane inherits Rectangle { callback navigate(NavKey, bool, int) -> int; callback columns-changed(int); callback motion-settled(); + callback row-renamed(int, string); + callback rename-cancelled(); + callback context-menu(int, length, length); + // The view keeps the focus away from a name being edited. public function focus-view() { - details.focus-view(); + if root.data.folder.edit-row < 0 { + details.focus-view(); + } } property header-height: root.split ? 32px : 0; @@ -56,6 +62,12 @@ export component Pane inherits Rectangle { root.activated(); root.focus-view(); } + pointer-event(event) => { + if event.button == PointerEventButton.right && event.kind == PointerEventKind.down { + root.activated(); + root.context-menu(-1, self.absolute-position.x + self.mouse-x, self.absolute-position.y + self.mouse-y); + } + } VerticalLayout { if root.split: Rectangle { @@ -101,6 +113,16 @@ export component Pane inherits Rectangle { motion-settled => { root.motion-settled(); } + row-renamed(row, text) => { + root.row-renamed(row, text); + } + rename-cancelled => { + root.rename-cancelled(); + } + context-menu(row, x, y) => { + root.activated(); + root.context-menu(row, x, y); + } sort-by(column) => { root.activated(); root.sort-by(column); diff --git a/crates/tunal/ui/shell/toolbar.slint b/crates/tunal/ui/shell/toolbar.slint index b2dd370..18e5eb4 100644 --- a/crates/tunal/ui/shell/toolbar.slint +++ b/crates/tunal/ui/shell/toolbar.slint @@ -34,6 +34,8 @@ export component Toolbar inherits Rectangle { callback path-edited(string); callback path-accepted(string); callback path-reverted(); + // The actions menu button was pressed; window coordinates of its bottom right. + callback actions(length, length); public function edit-path() { crumb.edit(); @@ -135,6 +137,17 @@ export component Toolbar inherits Rectangle { } } + VerticalLayout { + alignment: center; + IconButton { + icon: Icons.more-vert; + tooltip: "File actions"; + clicked => { + root.actions(self.absolute-position.x + self.width, self.absolute-position.y + self.height); + } + } + } + VerticalLayout { alignment: center; IconButton { diff --git a/crates/tunal/ui/views/details-view.slint b/crates/tunal/ui/views/details-view.slint index 84f97f0..8c1d4aa 100644 --- a/crates/tunal/ui/views/details-view.slint +++ b/crates/tunal/ui/views/details-view.slint @@ -27,6 +27,10 @@ export struct DetailRow { modified: string, selected: bool, cursor: bool, + // On the clipboard to be moved. + dimmed: bool, + // Its name is being edited in place. + editing: bool, // List motion, relative to the row's slot: it moves from `from` to `to` (details: rows, // `from-y` only; grid: cells, cell lines and header lines), and grows in or collapses out. // A leaving row is a copy of a removed one, kept until the change ends. @@ -60,6 +64,10 @@ export struct FolderState { travel: Travel, // Bumped when a folder opens with a direction of travel. travel-epoch: int, + // The row whose name is being edited (-1 for none) and how many bytes of it, from the + // start, are preselected (the name without its extension). + edit-row: int, + edit-select: int, } // Column widths shared by the header and the rows. @@ -378,6 +386,11 @@ export component DetailsView inherits Rectangle { callback clear-selection(); // Moves the cursor; returns the line to show (the cursor row), or -1. callback navigate(NavKey, bool, int) -> int; + // The edited name of a row, accepted or given up. + callback row-renamed(int, string); + callback rename-cancelled(); + // A right click on a row (-1 for none) at window coordinates. + callback context-menu(int, length, length); // Narrow views drop the Type column so names keep their room. property compact: root.width < 640px; @@ -400,6 +413,14 @@ export component DetailsView inherits Rectangle { } } + property shown-edit: -1; + changed state => { + if root.state.edit-row != root.shown-edit { + root.shown-edit = root.state.edit-row; + root.reveal(root.state.edit-row); + } + } + background: Theme.surface; forward-focus: keys; @@ -567,7 +588,21 @@ export component DetailsView inherits Rectangle { badge: row.badge; title: row.name; selected: row.selected; + editing: row.editing; + edit-select: root.state.edit-select; + opacity: row.dimmed ? Theme.disabled-content : 1; force-state: row.cursor && keys.has-focus ? ForceState.focused : ForceState.none; + renamed(text) => { + root.row-renamed(i, text); + } + rename-cancelled => { + root.rename-cancelled(); + } + pointer(event) => { + if event.button == PointerEventButton.right && event.kind == PointerEventKind.down { + root.context-menu(i, self.absolute-position.x + self.mouse-x, self.absolute-position.y + self.mouse-y); + } + } clicked => { keys.focus(); root.row-clicked(i, self.modifiers.control, self.modifiers.shift); diff --git a/crates/tunal/ui/views/grid-view.slint b/crates/tunal/ui/views/grid-view.slint index 96f6aa6..207a5b2 100644 --- a/crates/tunal/ui/views/grid-view.slint +++ b/crates/tunal/ui/views/grid-view.slint @@ -3,6 +3,7 @@ import { Theme } from "../theme.slint"; import { Motion } from "../motion.slint"; import { Icon, Icons } from "../components/icon.slint"; import { ForceState, StateLayer } from "../components/state-layer.slint"; +import { RenameField } from "../components/rename-field.slint"; import { IconButton } from "../components/icon-button.slint"; import { Columns, DetailRow, FilterChip, FolderKeys, FolderMessages, FolderState, HeaderCell, NavKey, @@ -33,6 +34,9 @@ global Grid { component GridCell inherits StateLayer { in property entry; in property cursor-ring; + in property edit-select; + callback renamed(text: string); + callback rename-cancelled(); property content: root.entry.selected ? Theme.on-secondary-container : Theme.on-surface-variant; @@ -89,7 +93,20 @@ component GridCell inherits StateLayer { } } - Text { + if root.entry.editing: RenameField { + height: 2 * Theme.body-small.line-height; + text: root.entry.name; + select-end: root.edit-select; + alignment: center; + accepted(text) => { + root.renamed(text); + } + cancelled => { + root.rename-cancelled(); + } + } + + if !root.entry.editing: Text { height: 2 * Theme.body-small.line-height; text: root.entry.name; color: root.entry.selected ? Theme.on-secondary-container : Theme.on-surface; @@ -127,6 +144,9 @@ export component GridView inherits Rectangle { callback navigate(NavKey, bool, int) -> int; // The number of columns that fit, on every change of it. callback columns-changed(int); + callback row-renamed(int, string); + callback rename-cancelled(); + callback context-menu(int, length, length); out property columns: max(1, floor((list.visible-width - 2 * Columns.inset) / Grid.min-cell-width)); property cell-width: (list.visible-width - 2 * Columns.inset) / root.columns; @@ -161,6 +181,14 @@ export component GridView inherits Rectangle { } } + property shown-edit: -1; + changed state => { + if root.state.edit-row != root.shown-edit { + root.shown-edit = root.state.edit-row; + root.reveal(root.state.edit-row); + } + } + background: Theme.surface; forward-focus: keys; @@ -308,6 +336,19 @@ export component GridView inherits Rectangle { height: parent.height - 2 * Grid.gap; entry: parent.entry; cursor-ring: parent.entry.cursor && keys.has-focus; + edit-select: root.state.edit-select; + opacity: parent.entry.dimmed ? Theme.disabled-content : 1; + renamed(text) => { + root.row-renamed(parent.index, text); + } + rename-cancelled => { + root.rename-cancelled(); + } + pointer(event) => { + if event.button == PointerEventButton.right && event.kind == PointerEventKind.down { + root.context-menu(parent.index, self.absolute-position.x + self.mouse-x, self.absolute-position.y + self.mouse-y); + } + } clicked => { keys.focus(); root.row-clicked(parent.index, self.modifiers.control, self.modifiers.shift); diff --git a/crates/tunal/ui/views/view-switch.slint b/crates/tunal/ui/views/view-switch.slint index db41b6b..8a35133 100644 --- a/crates/tunal/ui/views/view-switch.slint +++ b/crates/tunal/ui/views/view-switch.slint @@ -103,6 +103,9 @@ export component FolderView inherits Rectangle { callback clear-selection(); callback navigate(NavKey, bool, int) -> int; callback columns-changed(int); + callback row-renamed(int, string); + callback rename-cancelled(); + callback context-menu(int, length, length); // The list change of `state.motion` has ended: leaving rows can go. callback motion-settled(); @@ -180,6 +183,15 @@ export component FolderView inherits Rectangle { navigate(key, shift, page) => { root.navigate(key, shift, page) } + row-renamed(row, text) => { + root.row-renamed(row, text); + } + rename-cancelled => { + root.rename-cancelled(); + } + context-menu(row, x, y) => { + root.context-menu(row, x, y); + } } grid := GridView { @@ -222,6 +234,15 @@ export component FolderView inherits Rectangle { navigate(key, shift, page) => { root.navigate(key, shift, page) } + row-renamed(row, text) => { + root.row-renamed(row, text); + } + rename-cancelled => { + root.rename-cancelled(); + } + context-menu(row, x, y) => { + root.context-menu(row, x, y); + } columns-changed(n) => { root.columns-changed(n); } diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md index 4e675c3..6f7eedc 100644 --- a/docs/PROGRESS.md +++ b/docs/PROGRESS.md @@ -108,5 +108,12 @@ One entry per session, newest last, ≤ 15 lines: done, verified how, not done, - Not done: no real device (S036). Workspace-wide clippy/fmt currently fail only in S011's in-progress `crates/tunal/src/{smoke,actions,jobs_bridge}.rs`. Events only decoded, not acted on. I touched `crates/tunal-devices/src/lib.rs` (one `pub mod mtp;` line) and added `examples/`, outside `src/mtp/**`. - Later: MTP class Cancel request (0x64) for aborting a running transfer; GetObjectPropsSupported checks; event-driven refresh (ObjectAdded/Removed) in S026. +## S011 — File operation actions +- Done: `actions.rs` registry `Action` (id, label, glyph, shortcut, `enabled(&Context)`), used by the key hook (`action-key`), the context menu (right click on a row or the empty area; default layout, Trash has its own) and the toolbar's ⋮ menu. **Action ids**: `cut` Ctrl+X, `copy` Ctrl+C, `paste` Ctrl+V, `copy-path` Ctrl+Shift+C (system clipboard through a hidden `TextInput`), `rename` F2, `new-folder` Ctrl+Shift+N, `trash` Del, `delete` Shift+Del (confirm), `restore`, `empty-trash` (confirm). Internal clipboard (`Clipboard { uris, cut }`; cut items dimmed in every pane through `FolderModel::set_cut`). +- Inline rename: `DetailRow.editing`, `FolderState.edit-row/edit-select`, `components/rename-field.slint` (base name preselected, Enter accepts, Esc cancels, moving the cursor ends it); new folder is made at once as `New folder (N)` and its name edited when it shows (`FolderModel::select_when_shown`). `jobs_bridge.rs` `Bridge`: progress toast after 300 ms (determinate, cancel), summary toast, conflict dialog (`dialogs/conflict.slint`: both sides' size/date, apply to all, Skip/Keep both/Replace or Merge), item error dialog (Retry/Skip/Skip all/Abort, Esc = Skip; marked `// S016` for the elevation hook), failure list after a job, confirm dialog; prompts queue one at a time; panes whose location can't watch (the Trash) list again after each job (`FolderModel::refresh`). +- Verified: workspace build, clippy -D warnings, fmt --check, literal grep empty. Temporary uncommitted harness (own event-loop platform on the software renderer, scratch dir, `XDG_DATA_HOME` in the scratchpad), real window callbacks: copy + paste onto a name → conflict dialog screenshot, Keep both → `file (2).txt`; cut dims; F2 → field screenshot, rename on disk; Ctrl+Shift+N → `New folder`, named; Del → Trash; `trash:///` screenshot and menu, Restore → back at its place; Shift+Del → confirm, delete on disk. +- Not done: no live window (pointer right click, Esc in the field, real typing, toast cancel, drag); Rename choice in the conflict dialog (only Skip/Keep both/Replace); the error dialog and failure list were not shown (no failing job triggered); system clipboard copy of files for other apps and drag and drop are later plans; a watch event while a name is edited rebuilds the field (typed text is lost). +- Later: accept on blur needs a way to tell focus loss from a row rebuild (rows rebuild on every pane change); Undo toast; a numbered-rename field in the conflict dialog; reveal row after paste. + ## Later -