Pass 1 refactor saveToDisk function

dev
Michael Ball 2015-11-12 05:07:21 -08:00
rodzic 995d3da58d
commit d73ae50328
1 zmienionych plików z 18 dodań i 17 usunięć

35
gui.js
Wyświetl plik

@ -2993,33 +2993,34 @@ IDE_Morph.prototype.rawSaveProject = function (name) {
// Use the a[download] method to save a project without intervention // Use the a[download] method to save a project without intervention
IDE_Morph.prototype.saveProjectToDisk = function () { IDE_Morph.prototype.saveProjectToDisk = function () {
var data, var menu, str, dataPrefix;
link = document.createElement('a'); dataPrefix = 'data:text/xml,';
if (Process.prototype.isCatchingErrors) { if (Process.prototype.isCatchingErrors) {
try { try {
data = this.serializer.serialize(this.stage); menu = this.showMessage('Exporting');
link.setAttribute('href', 'data:text/xml,' + data); str = this.serializer.serialize(this.stage)
link.setAttribute('download', this.projectName + '.xml'); this.setURL('#open:' + dataPrefix + encodeURIComponent(str));
document.body.appendChild(link); this.saveXMLAs(str, name);
link.click(); menu.destroy();
document.body.removeChild(link); this.showMessage('Exported!', 1);
} catch (err) { } catch (err) {
this.showMessage('Saving failed: ' + err); this.showMessage('Export failed: ' + err);
} }
} else { } else {
data = this.serializer.serialize(this.stage); menu = this.showMessage('Exporting');
link.setAttribute('href', 'data:text/xml,' + data); str = this.serializer.serialize(this.stage)
link.setAttribute('download', this.projectName + '.xml'); this.setURL('#open:' + dataPrefix + encodeURIComponent(str));
document.body.appendChild(link); this.saveXMLAs(str, name);
link.click(); menu.destroy();
document.body.removeChild(link); this.showMessage('Exported!', 1);
} }
}; };
// Save a project as a file to the user's computer // Export project XML to a new browser window.
IDE_Morph.prototype.exportProject = function (name, plain) { IDE_Morph.prototype.exportProject = function (name, plain) {
var menu, str, dataPrefix; var menu, str, dataPrefix;
// saveXMLAs(x, x, true) tries to open a new tab.
if (name) { if (name) {
this.setProjectName(name); this.setProjectName(name);
dataPrefix = 'data:text/' + plain ? 'plain,' : 'xml,'; dataPrefix = 'data:text/' + plain ? 'plain,' : 'xml,';
@ -3038,7 +3039,7 @@ IDE_Morph.prototype.exportProject = function (name, plain) {
menu = this.showMessage('Exporting'); menu = this.showMessage('Exporting');
str = this.serializer.serialize(this.stage) str = this.serializer.serialize(this.stage)
this.setURL('#open:' + dataPrefix + encodeURIComponent(str)); this.setURL('#open:' + dataPrefix + encodeURIComponent(str));
this.saveXMLAs(str, name); this.saveXMLAs(str, name, true);
menu.destroy(); menu.destroy();
this.showMessage('Exported!', 1); this.showMessage('Exported!', 1);
} }