From 98ac31079a2eb013ef24afa17ebd0f350bbbf1c7 Mon Sep 17 00:00:00 2001 From: pax Date: Thu, 9 Apr 2026 17:06:35 -0500 Subject: [PATCH] bookmarks: route Save As action through save_post_file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- booru_viewer/gui/bookmarks.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/booru_viewer/gui/bookmarks.py b/booru_viewer/gui/bookmarks.py index 2e2861a..3a98fbd 100644 --- a/booru_viewer/gui/bookmarks.py +++ b/booru_viewer/gui/bookmarks.py @@ -389,11 +389,22 @@ class BookmarksView(QWidget): QDesktopServices.openUrl(QUrl.fromLocalFile(fav.cached_path)) elif action == save_as: 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) - 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: - import shutil - shutil.copy2(src, dest) + dest_path = Path(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: from ..core.cache import delete_from_library # delete_from_library walks every library folder by post id