From cd3e32bf4bb6e1ebedf01fe0b8208c1294a3a3ea Mon Sep 17 00:00:00 2001 From: pixelpaws Date: Tue, 23 Sep 2025 20:49:44 +0800 Subject: [PATCH] feat(context-menu): add example image download entry --- locales/de.json | 5 ++++ locales/en.json | 5 ++++ locales/es.json | 5 ++++ locales/fr.json | 5 ++++ locales/ja.json | 5 ++++ locales/ko.json | 5 ++++ locales/ru.json | 5 ++++ locales/zh-CN.json | 5 ++++ locales/zh-TW.json | 5 ++++ .../ContextMenu/GlobalContextMenu.js | 29 +++++++++++++++++++ templates/components/context_menu.html | 3 ++ 11 files changed, 77 insertions(+) diff --git a/locales/de.json b/locales/de.json index 6f00b0ac..c6c31b35 100644 --- a/locales/de.json +++ b/locales/de.json @@ -123,6 +123,11 @@ } }, "globalContextMenu": { + "downloadExampleImages": { + "label": "[TODO: Translate] Download example images", + "missingPath": "[TODO: Translate] Set a download location before downloading example images.", + "unavailable": "[TODO: Translate] Example image downloads aren't available yet. Try again after the page finishes loading." + }, "cleanupExampleImages": { "label": "Clean up example image folders", "success": "Moved {count} folder(s) to the deleted folder", diff --git a/locales/en.json b/locales/en.json index 13890105..608393f4 100644 --- a/locales/en.json +++ b/locales/en.json @@ -123,6 +123,11 @@ } }, "globalContextMenu": { + "downloadExampleImages": { + "label": "Download example images", + "missingPath": "Set a download location before downloading example images.", + "unavailable": "Example image downloads aren't available yet. Try again after the page finishes loading." + }, "cleanupExampleImages": { "label": "Clean up example image folders", "success": "Moved {count} folder(s) to the deleted folder", diff --git a/locales/es.json b/locales/es.json index fa32a89a..195af423 100644 --- a/locales/es.json +++ b/locales/es.json @@ -123,6 +123,11 @@ } }, "globalContextMenu": { + "downloadExampleImages": { + "label": "[TODO: Translate] Download example images", + "missingPath": "[TODO: Translate] Set a download location before downloading example images.", + "unavailable": "[TODO: Translate] Example image downloads aren't available yet. Try again after the page finishes loading." + }, "cleanupExampleImages": { "label": "Clean up example image folders", "success": "Moved {count} folder(s) to the deleted folder", diff --git a/locales/fr.json b/locales/fr.json index a4f7eeba..7da19b5b 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -123,6 +123,11 @@ } }, "globalContextMenu": { + "downloadExampleImages": { + "label": "[TODO: Translate] Download example images", + "missingPath": "[TODO: Translate] Set a download location before downloading example images.", + "unavailable": "[TODO: Translate] Example image downloads aren't available yet. Try again after the page finishes loading." + }, "cleanupExampleImages": { "label": "Clean up example image folders", "success": "Moved {count} folder(s) to the deleted folder", diff --git a/locales/ja.json b/locales/ja.json index 16c95020..9124d133 100644 --- a/locales/ja.json +++ b/locales/ja.json @@ -123,6 +123,11 @@ } }, "globalContextMenu": { + "downloadExampleImages": { + "label": "[TODO: Translate] Download example images", + "missingPath": "[TODO: Translate] Set a download location before downloading example images.", + "unavailable": "[TODO: Translate] Example image downloads aren't available yet. Try again after the page finishes loading." + }, "cleanupExampleImages": { "label": "Clean up example image folders", "success": "Moved {count} folder(s) to the deleted folder", diff --git a/locales/ko.json b/locales/ko.json index 28b4e0d6..db319db1 100644 --- a/locales/ko.json +++ b/locales/ko.json @@ -123,6 +123,11 @@ } }, "globalContextMenu": { + "downloadExampleImages": { + "label": "[TODO: Translate] Download example images", + "missingPath": "[TODO: Translate] Set a download location before downloading example images.", + "unavailable": "[TODO: Translate] Example image downloads aren't available yet. Try again after the page finishes loading." + }, "cleanupExampleImages": { "label": "Clean up example image folders", "success": "Moved {count} folder(s) to the deleted folder", diff --git a/locales/ru.json b/locales/ru.json index b07d77cd..ac33a1c1 100644 --- a/locales/ru.json +++ b/locales/ru.json @@ -123,6 +123,11 @@ } }, "globalContextMenu": { + "downloadExampleImages": { + "label": "[TODO: Translate] Download example images", + "missingPath": "[TODO: Translate] Set a download location before downloading example images.", + "unavailable": "[TODO: Translate] Example image downloads aren't available yet. Try again after the page finishes loading." + }, "cleanupExampleImages": { "label": "Clean up example image folders", "success": "Moved {count} folder(s) to the deleted folder", diff --git a/locales/zh-CN.json b/locales/zh-CN.json index 867c5c55..a54f9bdb 100644 --- a/locales/zh-CN.json +++ b/locales/zh-CN.json @@ -123,6 +123,11 @@ } }, "globalContextMenu": { + "downloadExampleImages": { + "label": "[TODO: Translate] Download example images", + "missingPath": "[TODO: Translate] Set a download location before downloading example images.", + "unavailable": "[TODO: Translate] Example image downloads aren't available yet. Try again after the page finishes loading." + }, "cleanupExampleImages": { "label": "Clean up example image folders", "success": "Moved {count} folder(s) to the deleted folder", diff --git a/locales/zh-TW.json b/locales/zh-TW.json index 9d285079..c18338a0 100644 --- a/locales/zh-TW.json +++ b/locales/zh-TW.json @@ -123,6 +123,11 @@ } }, "globalContextMenu": { + "downloadExampleImages": { + "label": "[TODO: Translate] Download example images", + "missingPath": "[TODO: Translate] Set a download location before downloading example images.", + "unavailable": "[TODO: Translate] Example image downloads aren't available yet. Try again after the page finishes loading." + }, "cleanupExampleImages": { "label": "Clean up example image folders", "success": "Moved {count} folder(s) to the deleted folder", diff --git a/static/js/components/ContextMenu/GlobalContextMenu.js b/static/js/components/ContextMenu/GlobalContextMenu.js index 58785aba..deeacff9 100644 --- a/static/js/components/ContextMenu/GlobalContextMenu.js +++ b/static/js/components/ContextMenu/GlobalContextMenu.js @@ -1,5 +1,6 @@ import { BaseContextMenu } from './BaseContextMenu.js'; import { showToast } from '../../utils/uiHelpers.js'; +import { state } from '../../state/index.js'; export class GlobalContextMenu extends BaseContextMenu { constructor() { @@ -19,12 +20,40 @@ export class GlobalContextMenu extends BaseContextMenu { console.error('Failed to trigger example images cleanup:', error); }); break; + case 'download-example-images': + this.downloadExampleImages(menuItem).catch((error) => { + console.error('Failed to trigger example images download:', error); + }); + break; default: console.warn(`Unhandled global context menu action: ${action}`); break; } } + async downloadExampleImages(menuItem) { + const exampleImagesManager = window.exampleImagesManager; + + if (!exampleImagesManager) { + showToast('globalContextMenu.downloadExampleImages.unavailable', {}, 'error'); + return; + } + + const downloadPath = state?.global?.settings?.example_images_path; + if (!downloadPath) { + showToast('globalContextMenu.downloadExampleImages.missingPath', {}, 'warning'); + return; + } + + menuItem?.classList.add('disabled'); + + try { + await exampleImagesManager.handleDownloadButton(); + } finally { + menuItem?.classList.remove('disabled'); + } + } + async cleanupExampleImagesFolders(menuItem) { if (this._cleanupInProgress) { return; diff --git a/templates/components/context_menu.html b/templates/components/context_menu.html index 3d96e6cc..a575e1a8 100644 --- a/templates/components/context_menu.html +++ b/templates/components/context_menu.html @@ -85,6 +85,9 @@
+
+ {{ t('globalContextMenu.downloadExampleImages.label') }} +
{{ t('globalContextMenu.cleanupExampleImages.label') }}