Skip to content

Commit 1663806

Browse files
committed
Merge PR #2366: LRC-LIB-LIBFOLDERS: Synchronize Folder says a folder is up to date, with one Close
docs/parity-checklist.md: header and revision rows from both sides; LRC-LIB-LIBFOLDERS row takes both wording changes
2 parents 214c595 + 9116cc1 commit 1663806

7 files changed

Lines changed: 96 additions & 19 deletions

File tree

‎crates/ui-egui/src/panels/dialogs.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,7 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) {
13661366
Dialog::KeywordTag { .. } => "Save",
13671367
Dialog::RemoveFolder { .. } => "Remove",
13681368
Dialog::LightroomCatalog { .. } => "Import Lightroom Catalog…",
1369+
Dialog::SynchronizeFolder { .. } if informational => "Close",
13691370
Dialog::SynchronizeFolder { .. } => "Synchronize",
13701371
Dialog::SamModel { then: Some(_), .. } if sam_installed => "Continue",
13711372
Dialog::SamModel { .. } if sam_installed || sam_running || sam_nowhere => "",
@@ -2304,7 +2305,8 @@ pub fn confirm_style(dlg: &Dialog) -> ConfirmStyle {
23042305
}
23052306
}
23062307

2307-
/// A dialog that only shows something: one Close, nothing to confirm or cancel.
2308+
/// A dialog that only shows something: one Close, nothing to confirm or cancel. (Synchronize
2309+
/// Folder is one when its folder turned out up to date.)
23082310
fn only_shows(dlg: &Dialog) -> bool {
23092311
matches!(
23102312
dlg,
@@ -2315,5 +2317,5 @@ fn only_shows(dlg: &Dialog) -> bool {
23152317
| Dialog::AllMetadata { .. }
23162318
| Dialog::WhatsNew
23172319
| Dialog::ManageEffects { .. }
2318-
)
2320+
) || matches!(dlg, Dialog::SynchronizeFolder { counts: Some(c), .. } if c.up_to_date())
23192321
}

‎crates/ui-egui/src/state.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,14 @@ pub struct SyncCounts {
12611261
pub moved: usize,
12621262
}
12631263

1264+
impl SyncCounts {
1265+
/// The folder is there and the scan found nothing to bring in, relink, remove or read: the
1266+
/// dialog only says so (files it skipped are not changes).
1267+
pub fn up_to_date(&self) -> bool {
1268+
!self.offline && self.new + self.moved + self.missing + self.metadata == 0
1269+
}
1270+
}
1271+
12641272
impl Default for UiState {
12651273
fn default() -> Self {
12661274
UiState {

‎crates/ui-egui/src/sync.rs‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,36 +187,51 @@ pub fn body(app: &LightcraftApp, ui: &mut egui::Ui, dlg: &mut Dialog) {
187187
crate::widgets::register(ui.ctx(), widget, r.rect);
188188
};
189189
let count = |text: &str, n: usize| format!("{} ({n})", crate::i18n::tr(text));
190+
let dim = |ui: &mut egui::Ui, s: &str| ui.label(egui::RichText::new(s).color(t.text_dim));
191+
let skipped = |ui: &mut egui::Ui| {
192+
if c.duplicates > 0 {
193+
dim(ui, &count("Skipped: files already in the library elsewhere", c.duplicates));
194+
}
195+
if c.unreadable > 0 {
196+
dim(ui, &count("Skipped: files that can't be read", c.unreadable));
197+
}
198+
};
199+
if c.up_to_date() {
200+
// nothing to choose: the answer takes the choices' place, and the one button closes
201+
// (`only_shows`)
202+
ui.label(crate::i18n::tr("The library is up to date with this folder."));
203+
skipped(ui);
204+
return;
205+
}
190206
choice(ui, import_new, c.new, count("Import new photos", c.new), "syncImportNew");
191207
choice(ui, relink_moved, c.moved, count("Relink photos whose file was renamed or moved", c.moved), "syncRelinkMoved");
192208
choice(ui, remove_missing, c.missing, count("Remove missing photos from the library", c.missing), "syncRemoveMissing");
193209
choice(ui, read_metadata, c.metadata, count("Read metadata updates from XMP sidecars", c.metadata), "syncReadMetadata");
194210
ui.add_space(6.0);
195-
let dim = |ui: &mut egui::Ui, s: &str| ui.label(egui::RichText::new(s).color(t.text_dim));
196-
if c.new + c.moved + c.missing + c.metadata == 0 {
197-
dim(ui, crate::i18n::tr("The library is up to date with this folder."));
198-
}
199211
if c.missing > 0 {
200212
dim(ui, crate::i18n::tr("Missing photos move to Recently Deleted and can be restored; no file on disk is touched."));
201213
}
202214
if c.metadata > 0 {
203215
dim(ui, crate::i18n::tr("Reading a sidecar replaces the photo's rating, labels, metadata and edits with what it says."));
204216
}
205-
if c.duplicates > 0 {
206-
dim(ui, &count("Skipped: files already in the library elsewhere", c.duplicates));
207-
}
208-
if c.unreadable > 0 {
209-
dim(ui, &count("Skipped: files that can't be read", c.unreadable));
210-
}
217+
skipped(ui);
211218
}
212219

213220
/// Synchronize with the dialog's choices: the scan the dialog showed is handed to a worker
214221
/// thread at once ([`SyncRun`]); nothing is read from disk on the UI thread. A scan that went
215222
/// stale (the folder's photos changed meanwhile) is refused and made again, keeping the choices.
223+
/// A folder that is up to date has nothing to hand over: confirming it only closes the dialog.
216224
pub fn confirm(app: &mut LightcraftApp, dlg: &Dialog) -> Result<Value, String> {
217-
let Dialog::SynchronizeFolder { path, name, disk, counts: Some(_), import_new, relink_moved, remove_missing, read_metadata, .. } = dlg else {
225+
let Dialog::SynchronizeFolder { path, name, disk, counts: Some(counts), import_new, relink_moved, remove_missing, read_metadata, .. } = dlg
226+
else {
218227
return Err("the folder is still being scanned".into());
219228
};
229+
// (before the busy checks: nothing is imported or written, so a running import or
230+
// synchronize can't clash with it, and the dialog closes either way. Like every result the
231+
// dialog shows, it is the scan's: a file added since is found by the next Synchronize)
232+
if counts.up_to_date() {
233+
return Ok(json!({"upToDate": true}));
234+
}
220235
if app.sync_run.is_some() {
221236
return Err(crate::i18n::tr("A folder is already being synchronized").to_string());
222237
}

‎crates/ui-egui/src/tests_sync.rs‎

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
//! * Synchronize with the defaults imports the new photos and leaves missing ones alone.
1111
//! * Ticking "Remove missing photos" also moves those to Recently Deleted.
1212
//! * Cancel leaves the library as it was.
13+
//! * A folder that has nothing to bring in only says so: the dialog has one Close and no
14+
//! choices, and closing it starts nothing.
1315
//! * Synchronize hands the work to the background at once: the dialog closes, the app keeps
1416
//! answering, and the photos arrive over the next frames under a row in the activity stack, as one undo
1517
//! step.
@@ -62,12 +64,19 @@ fn write_png(path: &str, seed: u8) {
6264
/// The app with `trip/a.png` and `trip/b.png` imported, then `c.png` added and `b.png` deleted
6365
/// on disk behind its back.
6466
fn changed_folder(dir: &Scratch) -> Headless {
67+
imported_folder(dir, || {
68+
write_png(&dir.path("trip/c.png"), 3);
69+
std::fs::remove_file(dir.path("trip/b.png")).unwrap();
70+
})
71+
}
72+
73+
/// The app with `trip/a.png` and `trip/b.png` imported, and `then` done on disk after.
74+
fn imported_folder(dir: &Scratch, then: impl FnOnce()) -> Headless {
6575
write_png(&dir.path("trip/a.png"), 1);
6676
write_png(&dir.path("trip/b.png"), 2);
6777
let mut session = lightcraft_engine::Session::new().with_fs();
6878
session.execute("library.import", &json!({"paths": [dir.path("trip")]})).unwrap();
69-
write_png(&dir.path("trip/c.png"), 3);
70-
std::fs::remove_file(dir.path("trip/b.png")).unwrap();
79+
then();
7180
let app = LightcraftApp::new(session, Services { png: None, ..Default::default() });
7281
let mut h = Headless::new(app, [1400.0, 900.0], 1.0);
7382
let r = h.request("ui.set", json!({"view": "photoGrid", "leftPanel": true}), T);
@@ -182,6 +191,42 @@ fn cancel_leaves_the_library_as_it_was() {
182191
assert!(h.app.session.folder_changes.is_none(), "the scan is let go");
183192
}
184193

194+
fn shown(h: &Headless, widget: &str) -> bool {
195+
h.app.widgets.iter().any(|(w, _)| w == widget)
196+
}
197+
198+
#[test]
199+
fn a_folder_with_nothing_to_bring_in_is_only_reported() {
200+
let dir = Scratch::new("uptodate");
201+
let mut h = imported_folder(&dir, || {});
202+
open_and_scan(&mut h, &dir.path("trip"));
203+
h.step();
204+
assert!(shown(&h, "button:dialogOk"), "one button, to close it");
205+
for gone in ["button:dialogCancel", "syncImportNew", "syncRelinkMoved", "syncRemoveMissing", "syncReadMetadata"] {
206+
assert!(!shown(&h, gone), "nothing to choose: {gone}");
207+
}
208+
let r = h.request("ui.clickWidget", json!({"id": "button:dialogOk"}), T);
209+
assert_eq!(r["ok"], true, "{r}");
210+
assert!(h.step_until(T, |h| h.app.ui.dialog.is_none()), "the button closes it");
211+
assert!(h.app.sync_run.is_none() && h.app.session.activity.list().is_empty(), "and starts nothing");
212+
assert!(h.app.session.folder_changes.is_none(), "the scan is let go");
213+
assert_eq!(in_library(&h), vec!["a.png", "b.png"]);
214+
}
215+
216+
#[test]
217+
fn confirming_a_folder_with_nothing_to_bring_in_starts_nothing() {
218+
let dir = Scratch::new("uptodate-agent");
219+
let mut h = imported_folder(&dir, || {});
220+
open_and_scan(&mut h, &dir.path("trip"));
221+
let r = h.request("ui.dialog.confirm", json!({}), T);
222+
assert_eq!(r["ok"], true, "{r}");
223+
assert_eq!(r["result"]["upToDate"], true, "{r}");
224+
assert!(h.app.ui.dialog.is_none());
225+
assert!(h.app.sync_run.is_none() && h.app.session.activity.list().is_empty(), "no job that does nothing");
226+
h.step();
227+
assert!(h.app.session.folder_changes.is_none(), "the scan is let go");
228+
}
229+
185230
#[test]
186231
fn an_agents_scan_is_kept_between_frames() {
187232
let dir = Scratch::new("agent");
@@ -250,7 +295,7 @@ fn a_synchronize_and_an_import_never_run_at_once() {
250295
path: dir.path("trip"),
251296
name: "trip".into(),
252297
disk: false,
253-
counts: Some(Default::default()),
298+
counts: Some(crate::state::SyncCounts { new: 1, ..Default::default() }),
254299
import_new: true,
255300
relink_moved: true,
256301
remove_missing: false,

‎docs/control-protocol.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ filmstrip is visible.
7676
| `ui.scroll` | `{dx, dy, cmd?, ctrl?, shift?, alt?}` | Wheel / two-finger scroll at the current pointer; pans over the image, modifier-scroll zooms |
7777
| `ui.zoom` | `{factor}` | Pinch zoom at the current pointer (positive scale multiplier; 1 = unchanged). Position it first with `ui.move` or `ui.hoverWidget` |
7878
| `ui.set` | partial UI state, e.g. `{"view": "detail"}` | Resulting UI state |
79-
| `ui.dialog.confirm` / `ui.dialog.cancel` | — | Close the open dialog |
79+
| `ui.dialog.confirm` / `ui.dialog.cancel` | — | Close the open dialog (confirm runs its action; Synchronize Folder on a folder that is up to date answers `{"upToDate": true}` and starts nothing) |
8080
| `ui.resize` | `{width, height}` | Resize the window |
8181
| `ui.zoomFactor` | `{factor}` | Set the interface scale (0.5–3; egui's zoom keys are off, Cmd+= / Cmd+- zoom the photo) |
8282
| `ui.screenshot` | `{path?, headless?}` | `{path, width, height}` once the frame (with finished renders) is captured. `headless: true` draws the UI on the CPU (no compositor needed); a windowed capture that gets no frame within 2 s falls back to headless automatically. While the loupe still waits for a render, `ui.widgets {filter: "loupe:rendering"}` lists its "Rendering…" pill; `loupe:renderFailed` is the pill saying a render failed behind a stand-in; Compare and Reference panes have their own (`compare:rendering:<pane>`, `compare:renderFailed:<pane>`) |

0 commit comments

Comments
 (0)