Cleanup code and add placeholders for error messages

dev
Michael Ball 2015-11-16 16:33:00 -08:00
rodzic 7976c60d1c
commit 65fd07e41a
2 zmienionych plików z 21 dodań i 19 usunięć

34
gui.js
Wyświetl plik

@ -3141,8 +3141,7 @@ IDE_Morph.prototype.exportScriptsPicture = function () {
y += padding;
y += each.height;
});
this.saveCanvasAs(pic, this.projectName, true);
this.saveCanvasAs(pic, this.ProjectName, true);
};
IDE_Morph.prototype.exportProjectSummary = function (useDropShadows) {
@ -3629,32 +3628,30 @@ IDE_Morph.prototype.setURL = function (str) {
}
};
/** Allow for downloading a file to a disk or open in a new tab.
This relies the FileSaver.js library which exports saveAs()
Two utility methods saveImageAs and saveXMLAs that should be used first.
1. Opening a new window uses standard URI encoding.
2. downloading a file uses Blobs.
- every other combo is unsupposed.
*/
IDE_Morph.prototype.saveFileAs = function (
contents,
fileType,
fileName,
newWindow // (optional) defaults to false.
) {
// TODO: Add confirmations
/** Allow for downloading a file to a disk or open in a new tab.
This relies the FileSaver.js library which exports saveAs()
Two utility methods saveImageAs and saveXMLAs should be used first.
1. Opening a new window uses standard URI encoding.
2. downloading a file uses Blobs.
- every other combo is unsupposed.
*/
var blobIsSupported = false,
fileExt,
dataURI, world, dlg, errorMessage;
dataURI, world, dlg;
// fileType is a <kind>/<ext>;<charset> format.
fileExt = '.' + fileType.split('/')[1].split(';')[0]
// Error Message Handling
world = this.world();
errorMessage = 'Longer Message is coming soon!';
// This is a workaround for a known Chrome crash with large URLs
function exhibitsChomeBug (contents) {
function exhibitsChomeBug(contents) {
var MAX_LENGTH = 2e6,
isChrome = navigator.userAgent.indexOf('Chrome') !== -1,
isTooLong = contents.length > MAX_LENGTH;
@ -3662,7 +3659,7 @@ IDE_Morph.prototype.saveFileAs = function (
return isChrome && isTooLong
};
function dataURItoBlob (text, mimeType) {
function dataURItoBlob(text, mimeType) {
var i,
data = text,
components = text.split(','),
@ -3691,11 +3688,12 @@ IDE_Morph.prototype.saveFileAs = function (
if (newWindow) {
dataURL = dataURLFormat(contents);
// Detect crashing errors and try to force a download
// Detect crashing errors - fallback to downloading if necessary
if (!exhibitsChomeBug(dataURL)) {
window.open(dataURL, '_blank');
window.open(dataURL, fileName);
} else {
this.showMessage('forcing a download');
// (recursively) call this defauling newWindow to false
this.showMessage('download to disk text');
this.saveFileAs(contents, fileType, fileName);
}
} else if (blobIsSupported) {
@ -3708,7 +3706,7 @@ IDE_Morph.prototype.saveFileAs = function (
} else {
// Error Case. TODO.
dlg = new DialogBoxMorph();
dlg.inform('Uh oh!', errorMessage, world);
dlg.inform('Uh oh!', 'unable to export text', world);
// btn = dlg.buttons.children[0];
dlg.fixLayout();
dlg.drawNew();

Wyświetl plik

@ -137,7 +137,11 @@ SnapTranslator.dict.en = {
+ 'a file on your computer by dropping it here\n',
'block deletion dialog text':
'Are you sure you want to delete this\n'
+ 'custom block and all its instances?'
+ 'custom block and all its instances?',
'download to disk text':
'This item could not be opened in a new tab.',
'unable to export text':
'This item could not be exported from Snap!.'
};
SnapTranslator.dict.de = {