From 5715fd00f312877395d0feeb2ddc898b8f4b8403 Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Tue, 9 Aug 2016 16:42:41 -0700 Subject: [PATCH] proper share dialog --- scripts/system/html/ShareSnapshot.html | 78 ++++++++++++++++++++++++++ scripts/system/snapshot.js | 28 +++++++-- 2 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 scripts/system/html/ShareSnapshot.html diff --git a/scripts/system/html/ShareSnapshot.html b/scripts/system/html/ShareSnapshot.html new file mode 100644 index 0000000000..4691b7488c --- /dev/null +++ b/scripts/system/html/ShareSnapshot.html @@ -0,0 +1,78 @@ + + + Share + + + + + + + + +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+ + diff --git a/scripts/system/snapshot.js b/scripts/system/snapshot.js index 61345254be..84019e68cc 100644 --- a/scripts/system/snapshot.js +++ b/scripts/system/snapshot.js @@ -21,11 +21,27 @@ var button = toolBar.addButton({ }); function confirmShare(data) { - if (!Window.confirm("Share snapshot " + data.localPath + "?")) { // This dialog will be more elaborate... - return; + var dialog = new OverlayWebWindow('Snapshot', Script.resolvePath("html/ShareSnapshot.html"), 800, 300); + function onMessage(message) { + if (message == 'ready') { // The window can now receive data from us. + dialog.emitScriptEvent(data); // Send it. + return; + } // Rest is confirmation processing + dialog.webEventReceived.disconnect(onMessage); // I'm not certain that this is necessary. If it is, what do we do on normal close? + dialog.close(); + dialog.deleteLater(); + message = message.filter(function (picture) { return picture.share; }); + if (message.length) { + print('sharing', message.map(function (picture) { return picture.localPath; }).join(', ')); + message.forEach(function (data) { + Window.shareSnapshot(data.localPath); + }); + } else { + print('declined to share', JSON.stringify(data)); + } } - Window.snapshotShared.connect(snapshotShared); - Window.shareSnapshot(data.localPath); + dialog.webEventReceived.connect(onMessage); + dialog.raise(); } function snapshotShared(success) { @@ -74,12 +90,14 @@ function resetButtons(path, notify) { button.writeProperty("defaultState", 1); button.writeProperty("hoverState", 3); Window.snapshotTaken.disconnect(resetButtons); - confirmShare({localPath: path}); + confirmShare([{localPath: path}]); } button.clicked.connect(onClicked); +Window.snapshotShared.connect(snapshotShared); Script.scriptEnding.connect(function () { toolBar.removeButton("snapshot"); button.clicked.disconnect(onClicked); + Window.snapshotShared.disconnect(snapshotShared); });