Skip to content

Commit fa1a50b

Browse files
authored
Replace blocking prompt() with themed MBDialog helper (sugarlabs#5844)
This PR replaces the native, blocking window.prompt() in the file saving flow with a custom, asynchronous dialog component. The new MBDialog matches the application's widget styling and supports theme-aware CSS variables.
1 parent 12b7612 commit fa1a50b

File tree

4 files changed

+357
-14
lines changed

4 files changed

+357
-14
lines changed

css/activities.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ body:not(.dark) #helpfulSearchDiv {
135135
font-weight: bold;
136136
cursor: pointer;
137137
transition: background-color 0.2s ease;
138-
background-color: #f1f1f1;
138+
background-color: #e0e0e0;
139139
color: black;
140140
}
141141

@@ -2197,4 +2197,4 @@ table {
21972197
padding: 0 10px;
21982198
box-sizing: border-box;
21992199
}
2200-
}
2200+
}

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
});
108108
</script>
109109
<script src="lib/astring.min.js" defer></script>
110+
<script src="js/utils/mb-dialog.js" defer></script>
110111
<script src="lib/acorn.min.js" defer></script>
111112
<script src="env.js"></script>
112113

js/SaveInterface.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,27 @@ class SaveInterface {
156156

157157
/**
158158
* Download a file to the user's computer.
159+
* Uses MBDialog prompt when available to collect a filename with a modal UI.
159160
* @param {string} extension - The file extension (including the dot).
160161
* @param {string} dataurl - The base64 data url of the file.
161162
* @param {string} defaultfilename - The default filename to be used.
162163
* @returns {void}
163164
*/
164165
download(extension, dataurl, defaultfilename) {
165166
let filename = null;
167+
const finishDownload = name => {
168+
if (name === null) {
169+
// eslint-disable-next-line no-console
170+
console.debug("save cancelled");
171+
return;
172+
}
173+
174+
if (fileExt(name) !== extension) {
175+
name += "." + extension;
176+
}
177+
178+
this.downloadURL(name, dataurl);
179+
};
166180
if (defaultfilename === undefined || defaultfilename === null) {
167181
if (this.activity.PlanetInterface === undefined) {
168182
defaultfilename = STR_MY_PROJECT;
@@ -176,8 +190,17 @@ class SaveInterface {
176190

177191
if (window.isElectron === true) {
178192
filename = defaultfilename;
193+
} else if (window.MBDialog && typeof window.MBDialog.prompt === "function") {
194+
window.MBDialog.prompt({
195+
title: _("Save file"),
196+
message: _("Filename:"),
197+
defaultValue: defaultfilename,
198+
okText: _("Save"),
199+
cancelText: _("Cancel")
200+
}).then(result => finishDownload(result));
201+
return;
179202
} else {
180-
filename = prompt("Filename:", defaultfilename);
203+
filename = prompt(_("Filename:"), defaultfilename);
181204
}
182205
} else {
183206
if (fileExt(defaultfilename) !== extension) {
@@ -188,17 +211,7 @@ class SaveInterface {
188211

189212
// eslint-disable-next-line no-console
190213
console.debug("saving to " + filename);
191-
if (filename === null) {
192-
// eslint-disable-next-line no-console
193-
console.debug("save cancelled");
194-
return;
195-
}
196-
197-
if (fileExt(filename) !== extension) {
198-
filename += "." + extension;
199-
}
200-
201-
this.downloadURL(filename, dataurl);
214+
finishDownload(filename);
202215
}
203216

204217
/**

0 commit comments

Comments
 (0)