Give the collections sidebar its own Slint global
AppWindow carried the sidebar's tree, its row menu, renaming, drag and drop between rows, the trash row, and the membership sheet as ~40 properties and callbacks on the root component, in the pattern CH-1 describes and the develop screen's globals (Adjustments, Framing, Steps, ...) already replaced. Collections.* in collections.slint now holds that state, declared next to the MembershipRow struct it and the membership sheet both use; Rust reaches it through window.global::<Collections>() instead of window.set_/get_/on_/invoke_ on the root. collection-selected, collection-select, and collection-offline-menu stay on AppWindow: library_ui.rs invokes collection-select directly and registers collection-offline-menu's handler, and lib.rs reads collection-selected for back-navigation, so moving them would have meant editing library_ui.rs, which another change on this branch is splitting into a module directory. collections-visible stays too — it is lib.rs's panel-layout state, seeded from the saved layout before the sidebar exists, and collections_ui never touches it. Everything prefixed library- (the grid's drag, selection and keyword state that the sidebar's Rust also wires for cross-feature gestures like filing a selection into a collection) stays on the window as well, since it belongs to the library screen, not the sidebar.
This commit is contained in:
@@ -13,7 +13,7 @@ use dr_catalog::Catalog;
|
||||
use dr_types::{CollectionId, ImageId};
|
||||
use slint::{ComponentHandle, Model as _};
|
||||
|
||||
use crate::AppWindow;
|
||||
use crate::{AppWindow, Collections};
|
||||
|
||||
use super::controller::{
|
||||
decide_delete, decide_release, CollectionsController, DeleteStep, Release,
|
||||
@@ -58,7 +58,7 @@ pub(super) fn wire_tree_navigation(
|
||||
} else if id == 0 {
|
||||
String::new()
|
||||
} else {
|
||||
let rows = w.get_collection_rows();
|
||||
let rows = w.global::<Collections>().get_collection_rows();
|
||||
(0..rows.row_count())
|
||||
.filter_map(|i| rows.row_data(i))
|
||||
.find(|r| r.id == id)
|
||||
@@ -66,7 +66,8 @@ pub(super) fn wire_tree_navigation(
|
||||
.unwrap_or_default()
|
||||
};
|
||||
w.set_collection_selected(id);
|
||||
w.set_collection_scope_label(label.into());
|
||||
w.global::<Collections>()
|
||||
.set_collection_scope_label(label.into());
|
||||
sync_reorderable(&w);
|
||||
reload();
|
||||
});
|
||||
@@ -76,20 +77,22 @@ pub(super) fn wire_tree_navigation(
|
||||
let weak = window.as_weak();
|
||||
let ctl = ctl.clone();
|
||||
let catalog = catalog.clone();
|
||||
window.on_collection_toggle(move |id| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let id = CollectionId(id as u64);
|
||||
{
|
||||
let mut collapsed = ctl.collapsed.borrow_mut();
|
||||
if !collapsed.remove(&id) {
|
||||
collapsed.insert(id);
|
||||
window
|
||||
.global::<Collections>()
|
||||
.on_collection_toggle(move |id| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let id = CollectionId(id as u64);
|
||||
{
|
||||
let mut collapsed = ctl.collapsed.borrow_mut();
|
||||
if !collapsed.remove(&id) {
|
||||
collapsed.insert(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
let borrow = catalog.borrow();
|
||||
if let Some(cat) = borrow.as_ref() {
|
||||
refresh_tree(&w, &ctl, cat);
|
||||
}
|
||||
});
|
||||
let borrow = catalog.borrow();
|
||||
if let Some(cat) = borrow.as_ref() {
|
||||
refresh_tree(&w, &ctl, cat);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,11 +106,12 @@ pub(super) fn wire_create(
|
||||
let weak = window.as_weak();
|
||||
let ctl = ctl.clone();
|
||||
let catalog = catalog.clone();
|
||||
window.on_collection_new(move || {
|
||||
window.global::<Collections>().on_collection_new(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let borrow = catalog.borrow();
|
||||
let Some(cat) = borrow.as_ref() else {
|
||||
w.set_collection_error("Open a library first.".into());
|
||||
w.global::<Collections>()
|
||||
.set_collection_error("Open a library first.".into());
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -133,76 +137,88 @@ pub(super) fn wire_rename(
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let ctl = ctl.clone();
|
||||
window.on_collection_rename_start(move |id| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
// `F2` arrives with whatever the sidebar has selected, which may be
|
||||
// "All photographs" (0) or the trash (-1). Neither has a name to
|
||||
// change, so the key does nothing rather than opening a field on a
|
||||
// row that is not a collection.
|
||||
if id <= 0 {
|
||||
return;
|
||||
}
|
||||
let id = CollectionId(id as u64);
|
||||
window
|
||||
.global::<Collections>()
|
||||
.on_collection_rename_start(move |id| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
// `F2` arrives with whatever the sidebar has selected, which may be
|
||||
// "All photographs" (0) or the trash (-1). Neither has a name to
|
||||
// change, so the key does nothing rather than opening a field on a
|
||||
// row that is not a collection.
|
||||
if id <= 0 {
|
||||
return;
|
||||
}
|
||||
let id = CollectionId(id as u64);
|
||||
|
||||
// A saved filter is renameable like any other — its *membership* is
|
||||
// computed, its name is not — so there is no kind check here.
|
||||
*ctl.renaming.borrow_mut() = Some(id);
|
||||
w.set_collection_renaming(id.0 as i32);
|
||||
w.set_collection_error(slint::SharedString::new());
|
||||
});
|
||||
// A saved filter is renameable like any other — its *membership* is
|
||||
// computed, its name is not — so there is no kind check here.
|
||||
*ctl.renaming.borrow_mut() = Some(id);
|
||||
w.global::<Collections>()
|
||||
.set_collection_renaming(id.0 as i32);
|
||||
w.global::<Collections>()
|
||||
.set_collection_error(slint::SharedString::new());
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let ctl = ctl.clone();
|
||||
let catalog = catalog.clone();
|
||||
window.on_collection_rename_commit(move |id, name| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let id = CollectionId(id as u64);
|
||||
window
|
||||
.global::<Collections>()
|
||||
.on_collection_rename_commit(move |id, name| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let id = CollectionId(id as u64);
|
||||
|
||||
// The field reports a commit when it loses focus as well as on
|
||||
// Enter, so a second one can arrive for a rename already closed —
|
||||
// Enter commits, and the focus the field then gives up commits
|
||||
// again. Ignored rather than reapplied: the second would bump the
|
||||
// revision for no change and beat a real edit on another device.
|
||||
if *ctl.renaming.borrow() != Some(id) {
|
||||
return;
|
||||
}
|
||||
// The field reports a commit when it loses focus as well as on
|
||||
// Enter, so a second one can arrive for a rename already closed —
|
||||
// Enter commits, and the focus the field then gives up commits
|
||||
// again. Ignored rather than reapplied: the second would bump the
|
||||
// revision for no change and beat a real edit on another device.
|
||||
if *ctl.renaming.borrow() != Some(id) {
|
||||
return;
|
||||
}
|
||||
|
||||
let borrow = catalog.borrow();
|
||||
let Some(cat) = borrow.as_ref() else { return };
|
||||
let borrow = catalog.borrow();
|
||||
let Some(cat) = borrow.as_ref() else { return };
|
||||
|
||||
match apply_rename(cat.connection(), id, name.as_str()) {
|
||||
Ok(Rename::Applied(name)) => {
|
||||
close_rename(&w, &ctl);
|
||||
w.set_collection_error(slint::SharedString::new());
|
||||
refresh_tree(&w, &ctl, cat);
|
||||
// The header names the collection being shown, so a rename
|
||||
// of the current scope has to reach it too.
|
||||
if *ctl.scope.borrow() == Some(id) {
|
||||
w.set_collection_scope_label(name.as_str().into());
|
||||
match apply_rename(cat.connection(), id, name.as_str()) {
|
||||
Ok(Rename::Applied(name)) => {
|
||||
close_rename(&w, &ctl);
|
||||
w.global::<Collections>()
|
||||
.set_collection_error(slint::SharedString::new());
|
||||
refresh_tree(&w, &ctl, cat);
|
||||
// The header names the collection being shown, so a rename
|
||||
// of the current scope has to reach it too.
|
||||
if *ctl.scope.borrow() == Some(id) {
|
||||
w.global::<Collections>()
|
||||
.set_collection_scope_label(name.as_str().into());
|
||||
}
|
||||
log::info!("renamed collection {} to {name}", id.0);
|
||||
}
|
||||
Ok(Rename::Unchanged) => close_rename(&w, &ctl),
|
||||
Err(e) => {
|
||||
// The field stays open on what the user typed. Closing it
|
||||
// would drop their text and leave the old name showing,
|
||||
// with only a line of red to explain where it went.
|
||||
w.global::<Collections>()
|
||||
.set_collection_error(format!("renaming: {e}").into());
|
||||
}
|
||||
log::info!("renamed collection {} to {name}", id.0);
|
||||
}
|
||||
Ok(Rename::Unchanged) => close_rename(&w, &ctl),
|
||||
Err(e) => {
|
||||
// The field stays open on what the user typed. Closing it
|
||||
// would drop their text and leave the old name showing,
|
||||
// with only a line of red to explain where it went.
|
||||
w.set_collection_error(format!("renaming: {e}").into());
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let ctl = ctl.clone();
|
||||
window.on_collection_rename_cancel(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
close_rename(&w, &ctl);
|
||||
w.set_collection_error(slint::SharedString::new());
|
||||
});
|
||||
window
|
||||
.global::<Collections>()
|
||||
.on_collection_rename_cancel(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
close_rename(&w, &ctl);
|
||||
w.global::<Collections>()
|
||||
.set_collection_error(slint::SharedString::new());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +253,8 @@ pub(super) fn wire_remove(
|
||||
|
||||
match coll::remove_images(cat.connection(), scope, &chosen) {
|
||||
Ok(n) => {
|
||||
w.set_collection_error(slint::SharedString::new());
|
||||
w.global::<Collections>()
|
||||
.set_collection_error(slint::SharedString::new());
|
||||
// Named explicitly as a membership change: the images are
|
||||
// still in the library, and a user who reads this as a
|
||||
// delete will not trust the feature again.
|
||||
@@ -249,7 +266,9 @@ pub(super) fn wire_remove(
|
||||
sync_badges(&w, cat, &visible());
|
||||
reload();
|
||||
}
|
||||
Err(e) => w.set_collection_error(format!("removing: {e}").into()),
|
||||
Err(e) => w
|
||||
.global::<Collections>()
|
||||
.set_collection_error(format!("removing: {e}").into()),
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -276,44 +295,47 @@ pub(super) fn wire_row_drag(
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let ctl = ctl.clone();
|
||||
window.on_collection_row_press(move |id, down| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let id = CollectionId(id as u64);
|
||||
window
|
||||
.global::<Collections>()
|
||||
.on_collection_row_press(move |id, down| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let id = CollectionId(id as u64);
|
||||
|
||||
if !down {
|
||||
// Let go. A drag that began has already been dealt with by the
|
||||
// drop; a hold that did not move is a request for the menu.
|
||||
*ctl.row_hold_timer.borrow_mut() = None;
|
||||
let held = ctl.lifted.borrow_mut().take();
|
||||
let dragged = ctl.drag_began.replace(false);
|
||||
w.set_collection_lifted(0);
|
||||
if let Release::OpenMenu(held) = decide_release(held, dragged) {
|
||||
w.invoke_collection_menu(held.0 as i32);
|
||||
if !down {
|
||||
// Let go. A drag that began has already been dealt with by the
|
||||
// drop; a hold that did not move is a request for the menu.
|
||||
*ctl.row_hold_timer.borrow_mut() = None;
|
||||
let held = ctl.lifted.borrow_mut().take();
|
||||
let dragged = ctl.drag_began.replace(false);
|
||||
w.global::<Collections>().set_collection_lifted(0);
|
||||
if let Release::OpenMenu(held) = decide_release(held, dragged) {
|
||||
w.global::<Collections>()
|
||||
.invoke_collection_menu(held.0 as i32);
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// A drag of this row, if one follows, carries this collection.
|
||||
ctl.note_row_press(id);
|
||||
ctl.drag_began.set(false);
|
||||
// A drag of this row, if one follows, carries this collection.
|
||||
ctl.note_row_press(id);
|
||||
ctl.drag_began.set(false);
|
||||
|
||||
let timer = slint::Timer::default();
|
||||
let weak = w.as_weak();
|
||||
let ctl_cb = ctl.clone();
|
||||
timer.start(
|
||||
slint::TimerMode::SingleShot,
|
||||
std::time::Duration::from_millis(HOLD_DELAY_MS),
|
||||
move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
// Picked up, not yet acted on. The menu waits for the
|
||||
// release, because opening it here would put a sheet over
|
||||
// the tree the user may be about to drag this row across.
|
||||
*ctl_cb.lifted.borrow_mut() = Some(id);
|
||||
w.set_collection_lifted(id.0 as i32);
|
||||
},
|
||||
);
|
||||
*ctl.row_hold_timer.borrow_mut() = Some(timer);
|
||||
});
|
||||
let timer = slint::Timer::default();
|
||||
let weak = w.as_weak();
|
||||
let ctl_cb = ctl.clone();
|
||||
timer.start(
|
||||
slint::TimerMode::SingleShot,
|
||||
std::time::Duration::from_millis(HOLD_DELAY_MS),
|
||||
move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
// Picked up, not yet acted on. The menu waits for the
|
||||
// release, because opening it here would put a sheet over
|
||||
// the tree the user may be about to drag this row across.
|
||||
*ctl_cb.lifted.borrow_mut() = Some(id);
|
||||
w.global::<Collections>().set_collection_lifted(id.0 as i32);
|
||||
},
|
||||
);
|
||||
*ctl.row_hold_timer.borrow_mut() = Some(timer);
|
||||
});
|
||||
}
|
||||
|
||||
// TRACES: FR-CAT-7 | FR-UI-4
|
||||
@@ -326,40 +348,44 @@ pub(super) fn wire_row_drag(
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let ctl = ctl.clone();
|
||||
window.on_collection_drag_active(move |id, active| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let id = CollectionId(id as u64);
|
||||
window
|
||||
.global::<Collections>()
|
||||
.on_collection_drag_active(move |id, active| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let id = CollectionId(id as u64);
|
||||
|
||||
if !active {
|
||||
w.set_collection_root_drop_allowed(false);
|
||||
w.set_collection_lifted(0);
|
||||
*ctl.lifted.borrow_mut() = None;
|
||||
return;
|
||||
}
|
||||
if !active {
|
||||
w.global::<Collections>()
|
||||
.set_collection_root_drop_allowed(false);
|
||||
w.global::<Collections>().set_collection_lifted(0);
|
||||
*ctl.lifted.borrow_mut() = None;
|
||||
return;
|
||||
}
|
||||
|
||||
// The hold may not have fired — a pointer drag needs no hold — so
|
||||
// the pick-up is recorded here as well as there, and the row lifts
|
||||
// either way.
|
||||
ctl.drag_began.set(true);
|
||||
ctl.note_row_press(id);
|
||||
*ctl.lifted.borrow_mut() = Some(id);
|
||||
w.set_collection_lifted(id.0 as i32);
|
||||
// The hold has been spent on a drag; nothing may fire behind it.
|
||||
*ctl.row_hold_timer.borrow_mut() = None;
|
||||
// The hold may not have fired — a pointer drag needs no hold — so
|
||||
// the pick-up is recorded here as well as there, and the row lifts
|
||||
// either way.
|
||||
ctl.drag_began.set(true);
|
||||
ctl.note_row_press(id);
|
||||
*ctl.lifted.borrow_mut() = Some(id);
|
||||
w.global::<Collections>().set_collection_lifted(id.0 as i32);
|
||||
// The hold has been spent on a drag; nothing may fire behind it.
|
||||
*ctl.row_hold_timer.borrow_mut() = None;
|
||||
|
||||
// Only a nested collection has a top level to be returned to, and
|
||||
// only a collection drag — never photographs — means anything
|
||||
// there at all.
|
||||
let carrying_images = !ctl.dragging.borrow().is_empty();
|
||||
let nested = ctl
|
||||
.row_ids
|
||||
.borrow()
|
||||
.iter()
|
||||
.position(|&c| c == id)
|
||||
.and_then(|row| ctl.row_nested.borrow().get(row).copied())
|
||||
.unwrap_or(false);
|
||||
w.set_collection_root_drop_allowed(nested && !carrying_images);
|
||||
});
|
||||
// Only a nested collection has a top level to be returned to, and
|
||||
// only a collection drag — never photographs — means anything
|
||||
// there at all.
|
||||
let carrying_images = !ctl.dragging.borrow().is_empty();
|
||||
let nested = ctl
|
||||
.row_ids
|
||||
.borrow()
|
||||
.iter()
|
||||
.position(|&c| c == id)
|
||||
.and_then(|row| ctl.row_nested.borrow().get(row).copied())
|
||||
.unwrap_or(false);
|
||||
w.global::<Collections>()
|
||||
.set_collection_root_drop_allowed(nested && !carrying_images);
|
||||
});
|
||||
}
|
||||
|
||||
// TRACES: FR-CAT-7
|
||||
@@ -375,30 +401,35 @@ pub(super) fn wire_row_drag(
|
||||
let weak = window.as_weak();
|
||||
let ctl = ctl.clone();
|
||||
let catalog = catalog.clone();
|
||||
window.on_collection_dropped_on_root(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let source = ctl.dragging_collection.borrow_mut().take();
|
||||
let Some(source) = source else { return };
|
||||
// Photographs cannot land here. Guarded as well as refused in
|
||||
// `can-drop`, so a payload that somehow arrives does nothing
|
||||
// rather than reparenting whatever row was last pressed.
|
||||
if !ctl.dragging.borrow().is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let borrow = catalog.borrow();
|
||||
let Some(cat) = borrow.as_ref() else { return };
|
||||
let moved = coll::set_parent(cat.connection(), source, None);
|
||||
match moved {
|
||||
Ok(()) => {
|
||||
w.set_collection_error(slint::SharedString::new());
|
||||
w.set_library_status("Moved to the top level".into());
|
||||
refresh_tree(&w, &ctl, cat);
|
||||
log::info!("promoted collection {} by drag", source.0);
|
||||
window
|
||||
.global::<Collections>()
|
||||
.on_collection_dropped_on_root(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let source = ctl.dragging_collection.borrow_mut().take();
|
||||
let Some(source) = source else { return };
|
||||
// Photographs cannot land here. Guarded as well as refused in
|
||||
// `can-drop`, so a payload that somehow arrives does nothing
|
||||
// rather than reparenting whatever row was last pressed.
|
||||
if !ctl.dragging.borrow().is_empty() {
|
||||
return;
|
||||
}
|
||||
Err(e) => w.set_collection_error(format!("moving collection: {e}").into()),
|
||||
}
|
||||
});
|
||||
|
||||
let borrow = catalog.borrow();
|
||||
let Some(cat) = borrow.as_ref() else { return };
|
||||
let moved = coll::set_parent(cat.connection(), source, None);
|
||||
match moved {
|
||||
Ok(()) => {
|
||||
w.global::<Collections>()
|
||||
.set_collection_error(slint::SharedString::new());
|
||||
w.set_library_status("Moved to the top level".into());
|
||||
refresh_tree(&w, &ctl, cat);
|
||||
log::info!("promoted collection {} by drag", source.0);
|
||||
}
|
||||
Err(e) => w
|
||||
.global::<Collections>()
|
||||
.set_collection_error(format!("moving collection: {e}").into()),
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,12 +452,14 @@ pub(super) fn wire_row_menu(
|
||||
let weak = window.as_weak();
|
||||
let ctl = ctl.clone();
|
||||
let catalog = catalog.clone();
|
||||
window.on_collection_menu(move |id| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let borrow = catalog.borrow();
|
||||
let Some(cat) = borrow.as_ref() else { return };
|
||||
open_row_menu(&w, &ctl, cat, CollectionId(id as u64));
|
||||
});
|
||||
window
|
||||
.global::<Collections>()
|
||||
.on_collection_menu(move |id| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let borrow = catalog.borrow();
|
||||
let Some(cat) = borrow.as_ref() else { return };
|
||||
open_row_menu(&w, &ctl, cat, CollectionId(id as u64));
|
||||
});
|
||||
}
|
||||
|
||||
// Rename, from the menu into the row's own inline field.
|
||||
@@ -440,15 +473,18 @@ pub(super) fn wire_row_menu(
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let ctl = ctl.clone();
|
||||
window.on_collection_menu_rename(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let Some(id) = *ctl.menu_for.borrow() else {
|
||||
return;
|
||||
};
|
||||
close_row_menu(&w, &ctl);
|
||||
*ctl.renaming.borrow_mut() = Some(id);
|
||||
w.set_collection_renaming(id.0 as i32);
|
||||
});
|
||||
window
|
||||
.global::<Collections>()
|
||||
.on_collection_menu_rename(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let Some(id) = *ctl.menu_for.borrow() else {
|
||||
return;
|
||||
};
|
||||
close_row_menu(&w, &ctl);
|
||||
*ctl.renaming.borrow_mut() = Some(id);
|
||||
w.global::<Collections>()
|
||||
.set_collection_renaming(id.0 as i32);
|
||||
});
|
||||
}
|
||||
|
||||
// A new collection nested inside this one.
|
||||
@@ -460,16 +496,18 @@ pub(super) fn wire_row_menu(
|
||||
let weak = window.as_weak();
|
||||
let ctl = ctl.clone();
|
||||
let catalog = catalog.clone();
|
||||
window.on_collection_menu_new_child(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let Some(parent) = *ctl.menu_for.borrow() else {
|
||||
return;
|
||||
};
|
||||
let borrow = catalog.borrow();
|
||||
let Some(cat) = borrow.as_ref() else { return };
|
||||
close_row_menu(&w, &ctl);
|
||||
create_child(&w, &ctl, cat, Some(parent));
|
||||
});
|
||||
window
|
||||
.global::<Collections>()
|
||||
.on_collection_menu_new_child(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let Some(parent) = *ctl.menu_for.borrow() else {
|
||||
return;
|
||||
};
|
||||
let borrow = catalog.borrow();
|
||||
let Some(cat) = borrow.as_ref() else { return };
|
||||
close_row_menu(&w, &ctl);
|
||||
create_child(&w, &ctl, cat, Some(parent));
|
||||
});
|
||||
}
|
||||
|
||||
// TRACES: FR-CAT-7
|
||||
@@ -485,28 +523,33 @@ pub(super) fn wire_row_menu(
|
||||
let weak = window.as_weak();
|
||||
let ctl = ctl.clone();
|
||||
let catalog = catalog.clone();
|
||||
window.on_collection_menu_promote(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let Some(id) = *ctl.menu_for.borrow() else {
|
||||
return;
|
||||
};
|
||||
let borrow = catalog.borrow();
|
||||
let Some(cat) = borrow.as_ref() else { return };
|
||||
window
|
||||
.global::<Collections>()
|
||||
.on_collection_menu_promote(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let Some(id) = *ctl.menu_for.borrow() else {
|
||||
return;
|
||||
};
|
||||
let borrow = catalog.borrow();
|
||||
let Some(cat) = borrow.as_ref() else { return };
|
||||
|
||||
match coll::set_parent(cat.connection(), id, None) {
|
||||
Ok(()) => {
|
||||
w.set_collection_error(slint::SharedString::new());
|
||||
w.set_library_status("Moved to the top level".into());
|
||||
close_row_menu(&w, &ctl);
|
||||
refresh_tree(&w, &ctl, cat);
|
||||
log::info!("promoted collection {} to the top level", id.0);
|
||||
match coll::set_parent(cat.connection(), id, None) {
|
||||
Ok(()) => {
|
||||
w.global::<Collections>()
|
||||
.set_collection_error(slint::SharedString::new());
|
||||
w.set_library_status("Moved to the top level".into());
|
||||
close_row_menu(&w, &ctl);
|
||||
refresh_tree(&w, &ctl, cat);
|
||||
log::info!("promoted collection {} to the top level", id.0);
|
||||
}
|
||||
// Left open on failure, showing the collection it failed on:
|
||||
// closing would leave a red line referring to a row the user
|
||||
// can no longer tell was the one they aimed at.
|
||||
Err(e) => w
|
||||
.global::<Collections>()
|
||||
.set_collection_error(format!("moving collection: {e}").into()),
|
||||
}
|
||||
// Left open on failure, showing the collection it failed on:
|
||||
// closing would leave a red line referring to a row the user
|
||||
// can no longer tell was the one they aimed at.
|
||||
Err(e) => w.set_collection_error(format!("moving collection: {e}").into()),
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// TRACES: FR-NC-6a
|
||||
@@ -518,14 +561,16 @@ pub(super) fn wire_row_menu(
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let ctl = ctl.clone();
|
||||
window.on_collection_menu_offline(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let Some(id) = *ctl.menu_for.borrow() else {
|
||||
return;
|
||||
};
|
||||
close_row_menu(&w, &ctl);
|
||||
w.invoke_collection_offline_menu(id.0 as i32);
|
||||
});
|
||||
window
|
||||
.global::<Collections>()
|
||||
.on_collection_menu_offline(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let Some(id) = *ctl.menu_for.borrow() else {
|
||||
return;
|
||||
};
|
||||
close_row_menu(&w, &ctl);
|
||||
w.invoke_collection_offline_menu(id.0 as i32);
|
||||
});
|
||||
}
|
||||
|
||||
// TRACES: FR-CAT-7
|
||||
@@ -536,66 +581,75 @@ pub(super) fn wire_row_menu(
|
||||
let catalog = catalog.clone();
|
||||
let reload = on_scope_changed.clone();
|
||||
let visible = visible_ids.clone();
|
||||
window.on_collection_menu_delete(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let Some(id) = *ctl.menu_for.borrow() else {
|
||||
return;
|
||||
};
|
||||
let borrow = catalog.borrow();
|
||||
let Some(cat) = borrow.as_ref() else { return };
|
||||
window
|
||||
.global::<Collections>()
|
||||
.on_collection_menu_delete(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let Some(id) = *ctl.menu_for.borrow() else {
|
||||
return;
|
||||
};
|
||||
let borrow = catalog.borrow();
|
||||
let Some(cat) = borrow.as_ref() else { return };
|
||||
|
||||
let (holds, children) = direct_holdings(cat.connection(), id).unwrap_or((0, 0));
|
||||
if decide_delete(holds, children, ctl.menu_confirming.get()) == DeleteStep::Confirm {
|
||||
// Asked once. The sheet swaps its other actions for the
|
||||
// warning, so the second press cannot be a mis-aimed first one.
|
||||
ctl.menu_confirming.set(true);
|
||||
w.set_collection_menu_confirming(true);
|
||||
w.set_collection_menu_delete_label("Delete anyway".into());
|
||||
return;
|
||||
}
|
||||
let (holds, children) = direct_holdings(cat.connection(), id).unwrap_or((0, 0));
|
||||
if decide_delete(holds, children, ctl.menu_confirming.get()) == DeleteStep::Confirm
|
||||
{
|
||||
// Asked once. The sheet swaps its other actions for the
|
||||
// warning, so the second press cannot be a mis-aimed first one.
|
||||
ctl.menu_confirming.set(true);
|
||||
w.global::<Collections>()
|
||||
.set_collection_menu_confirming(true);
|
||||
w.global::<Collections>()
|
||||
.set_collection_menu_delete_label("Delete anyway".into());
|
||||
return;
|
||||
}
|
||||
|
||||
// Hoisted out of the `match` rather than called in the scrutinee:
|
||||
// the borrow `cat` comes from lives as long as the match does, and
|
||||
// the arm below has to release it before rereading the grid.
|
||||
let deleted = coll::delete(cat.connection(), id);
|
||||
match deleted {
|
||||
Ok(()) => {
|
||||
w.set_collection_error(slint::SharedString::new());
|
||||
close_row_menu(&w, &ctl);
|
||||
// Hoisted out of the `match` rather than called in the scrutinee:
|
||||
// the borrow `cat` comes from lives as long as the match does, and
|
||||
// the arm below has to release it before rereading the grid.
|
||||
let deleted = coll::delete(cat.connection(), id);
|
||||
match deleted {
|
||||
Ok(()) => {
|
||||
w.global::<Collections>()
|
||||
.set_collection_error(slint::SharedString::new());
|
||||
close_row_menu(&w, &ctl);
|
||||
|
||||
// The grid was showing what no longer exists.
|
||||
let was_scope = *ctl.scope.borrow() == Some(id);
|
||||
if was_scope {
|
||||
*ctl.scope.borrow_mut() = None;
|
||||
w.set_collection_selected(0);
|
||||
w.set_collection_scope_label(slint::SharedString::new());
|
||||
}
|
||||
refresh_tree(&w, &ctl, cat);
|
||||
// Named as a membership change, as the removal button is:
|
||||
// a user who reads this as a delete of their photographs
|
||||
// will not trust the feature again.
|
||||
w.set_library_status(if holds > 0 {
|
||||
format!(
|
||||
// The grid was showing what no longer exists.
|
||||
let was_scope = *ctl.scope.borrow() == Some(id);
|
||||
if was_scope {
|
||||
*ctl.scope.borrow_mut() = None;
|
||||
w.set_collection_selected(0);
|
||||
w.global::<Collections>()
|
||||
.set_collection_scope_label(slint::SharedString::new());
|
||||
}
|
||||
refresh_tree(&w, &ctl, cat);
|
||||
// Named as a membership change, as the removal button is:
|
||||
// a user who reads this as a delete of their photographs
|
||||
// will not trust the feature again.
|
||||
w.set_library_status(if holds > 0 {
|
||||
format!(
|
||||
"Deleted the collection; its {holds} photograph(s) stay in the library"
|
||||
)
|
||||
.into()
|
||||
} else {
|
||||
slint::SharedString::from("Deleted the collection")
|
||||
});
|
||||
log::info!("deleted collection {}", id.0);
|
||||
.into()
|
||||
} else {
|
||||
slint::SharedString::from("Deleted the collection")
|
||||
});
|
||||
log::info!("deleted collection {}", id.0);
|
||||
|
||||
// The badge on every visible cell just lost a collection,
|
||||
// and a scope that has gone needs the grid rereading.
|
||||
let cells = visible();
|
||||
sync_badges(&w, cat, &cells);
|
||||
drop(borrow);
|
||||
if was_scope {
|
||||
reload();
|
||||
// The badge on every visible cell just lost a collection,
|
||||
// and a scope that has gone needs the grid rereading.
|
||||
let cells = visible();
|
||||
sync_badges(&w, cat, &cells);
|
||||
drop(borrow);
|
||||
if was_scope {
|
||||
reload();
|
||||
}
|
||||
}
|
||||
Err(e) => w
|
||||
.global::<Collections>()
|
||||
.set_collection_error(format!("deleting: {e}").into()),
|
||||
}
|
||||
Err(e) => w.set_collection_error(format!("deleting: {e}").into()),
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Dismiss. A pending confirmation is backed out of one step rather than
|
||||
@@ -605,16 +659,20 @@ pub(super) fn wire_row_menu(
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let ctl = ctl.clone();
|
||||
window.on_collection_menu_dismiss(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
if ctl.menu_confirming.get() {
|
||||
ctl.menu_confirming.set(false);
|
||||
w.set_collection_menu_confirming(false);
|
||||
w.set_collection_menu_delete_label("Delete".into());
|
||||
return;
|
||||
}
|
||||
close_row_menu(&w, &ctl);
|
||||
});
|
||||
window
|
||||
.global::<Collections>()
|
||||
.on_collection_menu_dismiss(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
if ctl.menu_confirming.get() {
|
||||
ctl.menu_confirming.set(false);
|
||||
w.global::<Collections>()
|
||||
.set_collection_menu_confirming(false);
|
||||
w.global::<Collections>()
|
||||
.set_collection_menu_delete_label("Delete".into());
|
||||
return;
|
||||
}
|
||||
close_row_menu(&w, &ctl);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -635,7 +693,7 @@ pub(super) fn wire_membership(
|
||||
let borrow = catalog.borrow();
|
||||
let Some(cat) = borrow.as_ref() else { return };
|
||||
refresh_membership(&w, &ctl, cat);
|
||||
w.set_membership_open(true);
|
||||
w.global::<Collections>().set_membership_open(true);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -645,54 +703,62 @@ pub(super) fn wire_membership(
|
||||
let catalog = catalog.clone();
|
||||
let visible = visible_ids.clone();
|
||||
let reload = on_scope_changed.clone();
|
||||
window.on_membership_remove(move |id| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let target = CollectionId(id as u64);
|
||||
let chosen = ctl.selected();
|
||||
if chosen.is_empty() {
|
||||
return;
|
||||
}
|
||||
let borrow = catalog.borrow();
|
||||
let Some(cat) = borrow.as_ref() else { return };
|
||||
|
||||
// Hoisted for the same reason the delete above is: the arm
|
||||
// releases the catalog borrow before it rereads the grid.
|
||||
let removed = coll::remove_images(cat.connection(), target, &chosen);
|
||||
match removed {
|
||||
Ok(n) => {
|
||||
w.set_collection_error(slint::SharedString::new());
|
||||
// The same wording the scoped button uses, and for the same
|
||||
// reason: this is a membership change, not a delete.
|
||||
w.set_library_status(
|
||||
format!("Removed {n} from that collection; still in the library").into(),
|
||||
);
|
||||
// The sheet stays open. Taking photographs out of several
|
||||
// collections is one job, and a sheet that closed after
|
||||
// each would have to be reopened — with the selection
|
||||
// still live — to finish it.
|
||||
refresh_membership(&w, &ctl, cat);
|
||||
refresh_tree(&w, &ctl, cat);
|
||||
let cells = visible();
|
||||
sync_badges(&w, cat, &cells);
|
||||
// Only the collection on screen changes what the grid
|
||||
// holds. Removing from another one leaves the grid right,
|
||||
// and rereading it would scroll the user's place away.
|
||||
let showing = *ctl.scope.borrow() == Some(target);
|
||||
drop(borrow);
|
||||
if showing {
|
||||
reload();
|
||||
}
|
||||
window
|
||||
.global::<Collections>()
|
||||
.on_membership_remove(move |id| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
let target = CollectionId(id as u64);
|
||||
let chosen = ctl.selected();
|
||||
if chosen.is_empty() {
|
||||
return;
|
||||
}
|
||||
Err(e) => w.set_collection_error(format!("removing: {e}").into()),
|
||||
}
|
||||
});
|
||||
let borrow = catalog.borrow();
|
||||
let Some(cat) = borrow.as_ref() else { return };
|
||||
|
||||
// Hoisted for the same reason the delete above is: the arm
|
||||
// releases the catalog borrow before it rereads the grid.
|
||||
let removed = coll::remove_images(cat.connection(), target, &chosen);
|
||||
match removed {
|
||||
Ok(n) => {
|
||||
w.global::<Collections>()
|
||||
.set_collection_error(slint::SharedString::new());
|
||||
// The same wording the scoped button uses, and for the same
|
||||
// reason: this is a membership change, not a delete.
|
||||
w.set_library_status(
|
||||
format!("Removed {n} from that collection; still in the library")
|
||||
.into(),
|
||||
);
|
||||
// The sheet stays open. Taking photographs out of several
|
||||
// collections is one job, and a sheet that closed after
|
||||
// each would have to be reopened — with the selection
|
||||
// still live — to finish it.
|
||||
refresh_membership(&w, &ctl, cat);
|
||||
refresh_tree(&w, &ctl, cat);
|
||||
let cells = visible();
|
||||
sync_badges(&w, cat, &cells);
|
||||
// Only the collection on screen changes what the grid
|
||||
// holds. Removing from another one leaves the grid right,
|
||||
// and rereading it would scroll the user's place away.
|
||||
let showing = *ctl.scope.borrow() == Some(target);
|
||||
drop(borrow);
|
||||
if showing {
|
||||
reload();
|
||||
}
|
||||
}
|
||||
Err(e) => w
|
||||
.global::<Collections>()
|
||||
.set_collection_error(format!("removing: {e}").into()),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
window.on_membership_dismiss(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
w.set_membership_open(false);
|
||||
});
|
||||
window
|
||||
.global::<Collections>()
|
||||
.on_membership_dismiss(move || {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
w.global::<Collections>().set_membership_open(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user