Improve accumulator preview interactions

This commit is contained in:
2026-06-25 10:01:09 +02:00
parent 1a3068fc77
commit 1340c32732
3 changed files with 331 additions and 45 deletions
+32 -19
View File
@@ -238,17 +238,20 @@ def _accumulator_status(key: str, store: list[dict[str, Any]]) -> str:
return f"key={key}; entries={len(store)}; image_entries={len(images)}; formats={shape_text}"
def accumulator_list_entries(store_key: str) -> dict[str, Any]:
def accumulator_list_entries(store_key: str, preview_limit: int = 0) -> dict[str, Any]:
key = str(store_key or "").strip()
if not key:
raise ValueError("store_key is required for accumulator preview actions")
store = _ACCUMULATOR_STORES.setdefault(key, [])
return {
result = {
"store_key": key,
"entries": _entry_infos(store),
"count": len(store),
"status": _accumulator_status(key, store),
}
if int(preview_limit) > 0:
result["images"] = _preview_image_results(store, preview_limit, None, None)
return result
def accumulator_delete_entries(
@@ -256,6 +259,7 @@ def accumulator_delete_entries(
entry_id: str = "",
index: int = 0,
clear: bool = False,
preview_limit: int = 0,
) -> dict[str, Any]:
key = str(store_key or "").strip()
if not key:
@@ -278,7 +282,7 @@ def accumulator_delete_entries(
removed = 1
else:
raise ValueError("entry_id or 1-based index is required")
result = accumulator_list_entries(key)
result = accumulator_list_entries(key, preview_limit=preview_limit)
result["removed"] = removed
return result
@@ -288,13 +292,15 @@ def accumulator_move_entry(
entry_id: str = "",
index: int = 0,
direction: str = "up",
target_index: int = 0,
preview_limit: int = 0,
) -> dict[str, Any]:
key = str(store_key or "").strip()
if not key:
raise ValueError("store_key is required for accumulator preview actions")
store = _ACCUMULATOR_STORES.setdefault(key, [])
if not store:
result = accumulator_list_entries(key)
result = accumulator_list_entries(key, preview_limit=preview_limit)
result["moved"] = False
return result
zero_index = -1
@@ -311,26 +317,33 @@ def accumulator_move_entry(
else:
raise ValueError("entry_id or 1-based index is required")
if zero_index < 0:
result = accumulator_list_entries(key)
result = accumulator_list_entries(key, preview_limit=preview_limit)
result["moved"] = False
return result
direction = str(direction or "up").strip().lower()
if direction == "top":
target_index = 0
elif direction == "bottom":
target_index = len(store) - 1
elif direction == "down":
target_index = min(len(store) - 1, zero_index + 1)
else:
target_index = max(0, zero_index - 1)
moved = target_index != zero_index
if moved:
requested_target = int(target_index)
if requested_target > 0:
entry = store.pop(zero_index)
store.insert(target_index, entry)
result = accumulator_list_entries(key)
target_zero_index = max(0, min(len(store), requested_target - 1))
store.insert(target_zero_index, entry)
moved = target_zero_index != zero_index
else:
direction = str(direction or "up").strip().lower()
if direction == "top":
target_zero_index = 0
elif direction == "bottom":
target_zero_index = len(store) - 1
elif direction == "down":
target_zero_index = min(len(store) - 1, zero_index + 1)
else:
target_zero_index = max(0, zero_index - 1)
moved = target_zero_index != zero_index
if moved:
entry = store.pop(zero_index)
store.insert(target_zero_index, entry)
result = accumulator_list_entries(key, preview_limit=preview_limit)
result["moved"] = moved
result["from_index"] = zero_index + 1
result["to_index"] = target_index + 1
result["to_index"] = target_zero_index + 1
return result