From 34a91ac2cb894bf2e897525c689fefdf2da2c319 Mon Sep 17 00:00:00 2001 From: pmkrawczyk
- You can either select a file from your local file system or cached - files in the browser. + You can select a file from your local file system, cached files in the browser, + or select a file from Figlinq.
+ + + { }; }; +// window.saveFileDialogJS = async (title, initPath, selectionMode, promise) => { +// // by pass the selection +// const savePath = prompt(title || "Saving file as ", initPath); +// if (savePath) { +// downloadQueue[savePath] = 1; +// loader.style.display = "block"; +// await cjCall(promise, "resolve", "/files/" + savePath); +// } else { +// await cjCall(promise, "reject", "cancelled"); +// } +// }; + +// Get the save dialog element +const saveEl = document.getElementById("save-file-dialog"); +const saveDialog = new A11yDialog(saveEl); + window.saveFileDialogJS = async (title, initPath, selectionMode, promise) => { - // by pass the selection - const savePath = prompt(title || "Saving file as ", initPath); - if (savePath) { - downloadQueue[savePath] = 1; - loader.style.display = "block"; - await cjCall(promise, "resolve", "/files/" + savePath); - } else { - await cjCall(promise, "reject", "cancelled"); - } + document.getElementById("save-dialog-title").innerHTML = title || "Save File"; + saveDialog.show(); + let closed = false; + + // Handle dialog close (both overlay click and close button) + saveDialog.on("hide", function(dialogEl, event) { + if (!closed) { + closed = true; + cjCall(promise, "reject", "cancelled"); + } + }); + + // Download to computer option + document.getElementById("save-file-download").onclick = async () => { + if (!closed) { + const savePath = prompt("Enter filename:", initPath || "image.png"); + if (savePath) { + downloadQueue[savePath] = 1; + loader.style.display = "block"; + closed = true; + saveDialog.hide(); + await cjCall(promise, "resolve", "/files/" + savePath); + } + } + }; + + // Save to Figlinq option + document.getElementById("save-file-figlinq").onclick = () => { + if (!closed) { + closed = true; + saveDialog.hide(); + + const handleFiglinqSaveMessage = (event) => { + if (event.data && event.data.type === "figlinq-file-saved") { + window.removeEventListener("message", handleFiglinqSaveMessage); + cjCall(promise, "resolve", event.data.path || "/figlinq/saved"); + } else if (event.data && event.data.type === "figlinq-save-cancelled") { + window.removeEventListener("message", handleFiglinqSaveMessage); + cjCall(promise, "reject", "cancelled"); + } + }; + + window.addEventListener("message", handleFiglinqSaveMessage); + window.parent.postMessage( + { + action: "save-to-figlinq", + filename: initPath, + }, + "*" + ); + } + }; }; window.onFileOpened = (path, error) => { diff --git a/src/style.css b/src/style.css index f9458f7..32f6e0d 100644 --- a/src/style.css +++ b/src/style.css @@ -536,3 +536,88 @@ hr.solid { .menuBarClosing .subMenuItem.active > .subMenu { display: block !important; } + +.dialog-buttons { + display: flex; + gap: 10px; + justify-content: center; + margin-top: 20px; +} + +.dialog-button { + padding: 10px 20px; + border: none; + border-radius: 5px; + cursor: pointer; + font-size: 14px; + transition: background-color 0.2s; +} + +.dialog-button.primary { + background-color: #007cba; + color: white; +} + +.dialog-button.primary:hover { + background-color: #005a85; +} + +.dialog-button.secondary { + background-color: #6c757d; + color: white; +} + +.dialog-button.secondary:hover { + background-color: #5a6268; +} + +#save-dialog-message { + text-align: center; + margin-bottom: 10px; +} + +.dialog-close { + color: black; + position: absolute; + top: 10px; + right: 15px; + border: 0; + padding: 0; + background-color: transparent; + font-weight: bold; + font-size: 1.5em; + width: 1.2em; + height: 1.2em; + text-align: center; + cursor: pointer; + transition: 0.15s; + z-index: 10; +} + +.dialog-close:hover { + color: #666; +} + +/* Reduce top padding for dialog content */ +.dialog-content { + background-color: rgb(255, 255, 255); + z-index: 3; + position: fixed; + top: 50%; + left: 50%; + -webkit-transform: translate(-50%, -50%); + -ms-transform: translate(-50%, -50%); + transform: translate(-50%, -50%); + margin: 0; + padding: 15px 2em 2em 2em; /* Reduced top padding */ + max-width: 90%; + width: 400px; + border-radius: 5px; +} + +/* Ensure h3 has no top margin */ +.dialog-content h3 { + margin-top: 0; + margin-bottom: 15px; + font-size: 1.25em; +} \ No newline at end of file From eec1aad770c12af3201641265d99aec5b18c2e62 Mon Sep 17 00:00:00 2001 From: pmkrawczyk