bookmarks: route Save As action through save_post_file

Sixth and final Phase 2 site migration. The bookmarks context-menu
Save As action now mirrors main_window._save_as: render the template
to populate the dialog default name, then route the actual save
through save_post_file with explicit_name set to whatever the user
typed. Same behavior change as the browse-side Save As — Save As
into saved_dir() now registers library_meta where v0.2.3 didn't.

After this commit the eight save sites in main_window.py and
bookmarks.py all share one implementation. The net diff of Phase 1 +
Phase 2 (excluding the Phase 0 scaffolding) is a deletion in
main_window.py + bookmarks.py even after adding library_save.py,
which is the test for whether the refactor was the right call.
This commit is contained in:
pax 2026-04-09 17:06:35 -05:00
parent d05a9cd368
commit 98ac31079a

View File

@ -389,11 +389,22 @@ class BookmarksView(QWidget):
QDesktopServices.openUrl(QUrl.fromLocalFile(fav.cached_path)) QDesktopServices.openUrl(QUrl.fromLocalFile(fav.cached_path))
elif action == save_as: elif action == save_as:
if fav.cached_path and Path(fav.cached_path).exists(): if fav.cached_path and Path(fav.cached_path).exists():
from ..core.config import render_filename_template
from ..core.library_save import save_post_file
src = Path(fav.cached_path) src = Path(fav.cached_path)
dest = save_file(self, "Save Image", f"post_{fav.post_id}{src.suffix}", f"Images (*{src.suffix})") post = self._bookmark_to_post(fav)
template = self._db.get_setting("library_filename_template")
default_name = render_filename_template(template, post, src.suffix)
dest = save_file(self, "Save Image", default_name, f"Images (*{src.suffix})")
if dest: if dest:
import shutil dest_path = Path(dest)
shutil.copy2(src, dest) try:
save_post_file(
src, post, dest_path.parent, self._db,
explicit_name=dest_path.name,
)
except Exception as e:
log.warning(f"Bookmark Save As #{fav.post_id} failed: {e}")
elif action == unsave_lib: elif action == unsave_lib:
from ..core.cache import delete_from_library from ..core.cache import delete_from_library
# delete_from_library walks every library folder by post id # delete_from_library walks every library folder by post id