Added undo-history warning when opening file using File API, fixing rest of issue 459

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1475 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2010-03-26 18:55:49 +00:00
parent 508c72e5a7
commit cbd34c3cfb
1 changed files with 19 additions and 7 deletions

View File

@ -59,6 +59,7 @@
'layerHasThatName':"Layer already has that name", 'layerHasThatName':"Layer already has that name",
'QmoveElemsToLayer':"Move selected elements to layer '%s'?", 'QmoveElemsToLayer':"Move selected elements to layer '%s'?",
'QwantToClear':'Do you want to clear the drawing?\nThis will also erase your undo history!', 'QwantToClear':'Do you want to clear the drawing?\nThis will also erase your undo history!',
'QwantToOpen':'Do you want to open a new file?\nThis will also erase your undo history!',
'QerrorsRevertToSource':'There were parsing errors in your SVG source.\nRevert back to original SVG source?', 'QerrorsRevertToSource':'There were parsing errors in your SVG source.\nRevert back to original SVG source?',
'QignoreSourceChanges':'Ignore changes made to SVG source?', 'QignoreSourceChanges':'Ignore changes made to SVG source?',
'featNotSupported':'Feature not supported', 'featNotSupported':'Feature not supported',
@ -3019,14 +3020,25 @@
// get the text contents of the file and send it to the canvas // get the text contents of the file and send it to the canvas
if (window.FileReader) { if (window.FileReader) {
var inp = $('<input type="file">').change(function() { var inp = $('<input type="file">').change(function() {
var f = this;
var openFile = function(ok) {
if(!ok) return;
svgCanvas.clear();
if(f.files.length==1) {
var reader = new FileReader();
reader.onloadend = function(e) {
svgCanvas.setSvgString(e.target.result);
updateCanvas();
};
reader.readAsText(f.files[0]);
}
}
$('#main_menu').hide(); $('#main_menu').hide();
if(this.files.length==1) { if(svgCanvas.getHistoryPosition() === 0) {
var reader = new FileReader(); openFile(true);
reader.onloadend = function(e) { } else {
svgCanvas.setSvgString(e.target.result); $.confirm(uiStrings.QwantToOpen, openFile);
updateCanvas();
};
reader.readAsText(this.files[0]);
} }
}); });
$("#tool_open").show().prepend(inp); $("#tool_open").show().prepend(inp);