From d5eff1a256fd53b9161e8957be5bafc15d584d34 Mon Sep 17 00:00:00 2001 From: vrubelroman Date: Fri, 27 Nov 2026 14:24:36 +0300 Subject: [PATCH] =?UTF-8?q?library:=20task=2042=20review=20=E2=80=94=20cur?= =?UTF-8?q?sor=20frame=20on=20the=20row's=20fill,=20copied=20base=20at=20t?= =?UTF-8?q?he=20end=20of=20the=20shelf,=20write=20error=20in=20the=20condi?= =?UTF-8?q?tions=20line,=20CP=5FBATCH=5FCANCEL=5FAFTER?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/desktop/src/app.rs | 7 ++++- apps/desktop/src/large_db.rs | 40 ++++++++++++++++++++------- apps/desktop/src/library.rs | 22 +++++++++++++++ apps/desktop/src/settings.rs | 29 +++++++++++++++++++ docs/design/tasks-42-43-2026-11-27.md | 19 ++++++------- 5 files changed, 96 insertions(+), 21 deletions(-) diff --git a/apps/desktop/src/app.rs b/apps/desktop/src/app.rs index 794bd73..5abbe63 100644 --- a/apps/desktop/src/app.rs +++ b/apps/desktop/src/app.rs @@ -1948,7 +1948,9 @@ impl App { match end { BatchEnd::Done { target, report } => { let name = own_db::base_name(&target); - self.settings.touch_database(&target); + // At the end of the shelf: the cards stay where they are; «Open» brings it + // to the front. + self.settings.add_database_last(&target); self.settings_dirty = true; self.toast_for(ctx, crate::batch_copy::summary(&name, &report), 8.0); self.toast_open_db = Some(target); @@ -1984,6 +1986,7 @@ impl App { ], ), }; + self.library.set_batch_error(&source, text.clone()); self.toast_for(ctx, text, 8.0); } } @@ -4599,6 +4602,8 @@ impl eframe::App for App { if let Some(path) = open_copy { self.toast = None; self.toast_open_db = None; + self.settings.touch_database(&path); + self.settings_dirty = true; self.library.select_db(&path, &ctx); } #[cfg(not(web))] diff --git a/apps/desktop/src/large_db.rs b/apps/desktop/src/large_db.rs index a6b32ec..08973b1 100644 --- a/apps/desktop/src/large_db.rs +++ b/apps/desktop/src/large_db.rs @@ -330,6 +330,8 @@ pub struct LargeView { pub batch: Option, /// «Cancel» of that copy was clicked. pub cancel_batch: bool, + /// Why the last copy wrote nothing: said in red where its progress was, until `×`. + pub batch_error: Option, scroll_to_selected: bool, scroll_to_top: bool, focus_player: bool, @@ -454,6 +456,7 @@ impl LargeView { hidden: None, batch: None, cancel_batch: false, + batch_error: None, scroll_to_selected: false, scroll_to_top: false, focus_player: false, @@ -1345,6 +1348,8 @@ impl LargeView { let chosen = self.marked.len(); let hidden = if chosen >= 2 { self.hidden_marked() } else { 0 }; let batch = self.batch.clone(); + let batch_error = self.batch_error.clone(); + let mut close_error = false; let mut clear_marked = false; let mut cancel_batch = false; ui.horizontal(|ui| { @@ -1383,10 +1388,23 @@ impl LargeView { } } // The choice, or the copy being written, in the same place (§42.3). - if batch.is_some() || chosen >= 2 { + if batch.is_some() || batch_error.is_some() || chosen >= 2 { ui.add_space(SLOT_GAP); } - if let Some(b) = &batch { + if let (None, Some(e)) = (&batch, &batch_error) { + if crate::widgets::small_close_button(ui).clicked() { + close_error = true; + } + let width = (ui.available_width() - 140.0).max(80.0); + ui.scope(|ui| { + ui.set_max_width(width); + ui.add( + egui::Label::new(RichText::new(e).color(ui.visuals().error_fg_color)) + .truncate(), + ) + .on_hover_text(e); + }); + } else if let Some(b) = &batch { if b.cancelling { ui.spinner(); ui.label(RichText::new(tr("Cancelling…")).weak()); @@ -1479,6 +1497,9 @@ impl LargeView { if clear_marked { self.mark_cursor_only(); } + if close_error { + self.batch_error = None; + } if cancel_batch { self.cancel_batch = true; } @@ -2390,6 +2411,7 @@ impl LargeView { ); let frame_color = ui.visuals().selection.stroke.color; let table_clip = ui.clip_rect().intersect(ui.max_rect()); + let spacing = ui.spacing().item_spacing; let mut table = TableBuilder::new(ui) .id_salt(("game table", layout)) .striped(true) @@ -2457,6 +2479,8 @@ impl LargeView { let r = db.row(index); let is_marked = marked.contains(index); row.set_selected(is_marked); + // Where the row's cells are: the cursor's frame follows the row's fill. + let mut cells = egui::Rect::NOTHING; let key = viewed::key(db.identity(index)); let seen = viewed.contains(key); let elo = |e: u16| if e > 0 { e.to_string() } else { String::new() }; @@ -2469,6 +2493,7 @@ impl LargeView { }; for (label, key_, _) in &columns { row.col(|ui| { + cells = cells.union(ui.max_rect()); let cell = match (*label, *key_) { (l, None) if l == tr("Move") => { let Some(m) = found else { return }; @@ -2550,7 +2575,7 @@ impl LargeView { // The cursor among several chosen rows, or on a row not chosen: a frame // (a shape, not a colour; §42.4). if selected == Some(index) && (many || !is_marked) { - ui_painter_frame(&resp, frame_color, table_clip); + ui_painter_frame(&resp, cells.expand2(spacing / 2.0), frame_color, table_clip); } let resp = if about.is_empty() { resp } else { resp.on_hover_text(about.join(" · ")) }; if resp.secondary_clicked() { @@ -2871,17 +2896,12 @@ fn batch_items(ui: &mut Ui, n: usize, writing: Option<&str>) -> Option Option { + let job = self.batch.as_ref()?; + // `CP_BATCH_CANCEL_AFTER=`: «Cancel» pressed that long after the start (checks, + // screenshots of the cancelling). + let cancel_after = std::env::var("CP_BATCH_CANCEL_AFTER") + .ok() + .and_then(|ms| ms.parse::().ok()); + if let Some(ms) = cancel_after + && !job.cancelling + && ctx.input(|i| i.time) - job.work.started >= ms / 1000.0 + { + self.cancel_batch(); + } let job = self.batch.as_ref()?; let Some(result) = job.work.poll() else { let status = large_db::BatchStatus { diff --git a/apps/desktop/src/settings.rs b/apps/desktop/src/settings.rs index e69d746..1475b41 100644 --- a/apps/desktop/src/settings.rs +++ b/apps/desktop/src/settings.rs @@ -324,6 +324,16 @@ impl Settings { /// Puts the database first on the shelf; a database there already by another path /// to the same file (a link) keeps its path. Returns the path on the shelf. + /// Puts `path` at the end of the shelf, unless it is there: a database made in the + /// background appears without moving the cards (task 42). + pub fn add_database_last(&mut self, path: &Path) { + let real = |p: &Path| std::fs::canonicalize(p).ok(); + let same = |p: &PathBuf| p == path || real(p).is_some_and(|r| Some(r) == real(path)); + if !self.databases.iter().any(same) { + self.databases.push(path.to_path_buf()); + } + } + pub fn touch_database(&mut self, path: &Path) -> PathBuf { let real = |p: &Path| std::fs::canonicalize(p).ok(); let same = |p: &PathBuf| p == path || real(p).is_some_and(|r| Some(r) == real(path)); @@ -359,6 +369,25 @@ pub fn write_atomic(path: &Path, bytes: &[u8]) -> std::io::Result<()> { mod tests { use super::*; + /// A database made in the background goes to the end; opening it brings it first. + #[test] + fn a_copied_database_goes_to_the_end_of_the_shelf() { + let mut s = Settings::default(); + s.databases = vec![PathBuf::from("/a.pgn"), PathBuf::from("/b.pgn")]; + s.add_database_last(Path::new("/new.pgn")); + s.add_database_last(Path::new("/a.pgn")); + assert_eq!( + s.databases, + [ + PathBuf::from("/a.pgn"), + PathBuf::from("/b.pgn"), + PathBuf::from("/new.pgn") + ] + ); + s.touch_database(Path::new("/new.pgn")); + assert_eq!(s.databases[0], PathBuf::from("/new.pgn")); + } + /// A database put on the shelf again by a link to its file stays itself, once. #[cfg(unix)] #[test] diff --git a/docs/design/tasks-42-43-2026-11-27.md b/docs/design/tasks-42-43-2026-11-27.md index 3c1fab2..a2f7edf 100644 --- a/docs/design/tasks-42-43-2026-11-27.md +++ b/docs/design/tasks-42-43-2026-11-27.md @@ -262,35 +262,34 @@ |---|---|---| | счётчик | Выбрано: {n} | Selected: {n} | | счётчик со скрытыми | Выбрано: {n} ({k} скрыто фильтром) | Selected: {n} ({k} hidden by the filter) | -| ссылка | Снять | Clear | +| ссылка (сводит выделение к строке курсора, как Esc; ключ `Deselect`, т. к. «Clear» уже переведено «Очистить») | Снять | Deselect | | подсказка ссылки | Снять выделение (Esc) | Clear the selection (Esc) | | подсказка счётчика со скрытыми | Скрытые фильтром партии тоже будут скопированы. Снять выделение — Esc | Games hidden by the filter will be copied too. Esc clears the selection | | меню, заголовок | Выбрано партий: {n} | Games selected: {n} | | меню | Новая база из выбранных… | New database from selected… | -| меню | Добавить выбранные в базу… | Add selected to database… | -| меню | Выделить все | Select all | -| меню | Снять выделение | Clear selection | +| меню | Выделить все (Ctrl+A) | Select all (Ctrl+A) | +| меню | Снять выделение (Esc) | Clear selection (Esc) | | пункт неактивен | Идёт запись в «{name}» — дождитесь окончания | Writing to «{name}» — wait until it finishes | -| диалог, заголовок | Добавить в базу: {games} | Add to database: {games} | -| диалог, подзаголовок | из «{src}» · порядок как в таблице: {sort} | from «{src}» · in the table's order: {sort} | -| диалог, скрытые | из них {k} сейчас скрыты фильтром | {k} of them are hidden by the filter now | +| диалог «Новая база», скрытые | из них {k} сейчас скрыты фильтром | {k} of them are hidden by the filter now | | диалог, много | Много партий: запись может занять несколько минут, её можно отменить | Many games: writing may take a few minutes; you can cancel it | -| строки баз неактивны (если вне минимума) | Пока только в новую базу | Only into a new database for now | | новая база, подзаголовок | Из выбранных: {games} из «{src}» | From the selection: {games} from «{src}» | | новая база, кнопка | Создать и скопировать | Create and copy | | прогресс | Запись в «{name}»: {i} из {n} | Writing to «{name}»: {i} of {n} | -| прогресс, кнопка | Отменить | Cancel | +| прогресс, ссылка (общий ключ `Cancel`) | Отмена | Cancel | | отмена идёт | Отмена… | Cancelling… | | итог | {name}: скопировано {n}, пропущено {m} | {name}: copied {n}, skipped {m} | | итог, причины | {name}: скопировано {n}, пропущено {m} — дубли {d}, не прочитано {u} (№ {list}) | {name}: copied {n}, skipped {m} — duplicates {d}, unreadable {u} (No. {list}) | | итог, кнопка | Открыть | Open | | отменено, новая | Копирование отменено: база «{name}» не создана | Copying cancelled: «{name}» was not created | -| отменено, своя | Копирование отменено: база «{name}» не изменена | Copying cancelled: «{name}» is unchanged | | ошибка | Не удалось записать «{name}»: {reason}. Ничего не записано | Could not write «{name}»: {reason}. Nothing was written | | источник изменился | База «{src}» изменилась во время копирования. Ничего не записано | «{src}» changed while copying. Nothing was written | | выделение снято | Выделение снято: файл базы изменился | Selection cleared: the database file changed | | Delete при N≥2 | Удалять можно по одной партии: снимите выделение (Esc) | Games are deleted one at a time: clear the selection (Esc) | +Принято при реализации (минимум владельца, 2026-11-27): пакет только в новую базу — пакетного режима +диалога «Добавить в базу», строк «Добавить выбранные…» и «Пока только в новую базу» нет; Ctrl+Shift+S при +N ≥ 2 сразу открывает «Новая база». Ошибка записи — красная строка с `×` на месте прогресса и тост. + Числа — с группировкой, как в «найдено 4 221 из 11 743 083» (`grouped`). «{games}» — `i18n::games(n)`.