Possibly fixed issue 99 and issue 108 by setting up an external handler function. Moved Opera references to seperate file and reprocessed thinker.li's patch to also use a use separate file
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@468 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
c6df21abfc
commit
baf9f75982
|
@ -20,6 +20,8 @@
|
||||||
<!--script type="text/javascript" src="svgcanvas.min.js"></script-->
|
<!--script type="text/javascript" src="svgcanvas.min.js"></script-->
|
||||||
<script type="text/javascript" src="svg-editor.js"></script>
|
<script type="text/javascript" src="svg-editor.js"></script>
|
||||||
<!--script type="text/javascript" src="svg-editor.min.js"></script-->
|
<!--script type="text/javascript" src="svg-editor.min.js"></script-->
|
||||||
|
|
||||||
|
<!-- Add script with custom handlers here -->
|
||||||
<title>SVG-edit demo</title>
|
<title>SVG-edit demo</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -42,7 +44,7 @@
|
||||||
<div>
|
<div>
|
||||||
<img class="tool_sep" src="images/sep.png" alt="|"/>
|
<img class="tool_sep" src="images/sep.png" alt="|"/>
|
||||||
<img class="tool_button" id="tool_clear" src="images/clear.png" title="New Image [N]" alt="Clear" />
|
<img class="tool_button" id="tool_clear" src="images/clear.png" title="New Image [N]" alt="Clear" />
|
||||||
<img style="display:none" eeclass="tool_button" id="tool_open" src="images/open.png" title="Open Image [O]" alt="Open"/>
|
<img style="display:none" class="tool_button" id="tool_open" src="images/open.png" title="Open Image [O]" alt="Open"/>
|
||||||
<img class="tool_button" id="tool_save" src="images/save.png" title="Save Image [S]" alt="Save"/>
|
<img class="tool_button" id="tool_save" src="images/save.png" title="Save Image [S]" alt="Save"/>
|
||||||
<img class="tool_button" id="tool_source" src="images/source.png" title="Edit Source [U]" alt="Source"/>
|
<img class="tool_button" id="tool_source" src="images/source.png" title="Edit Source [U]" alt="Source"/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -286,9 +288,5 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
$(document).ready(svg_edit_setup);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -36,35 +36,7 @@ function svg_edit_setup() {
|
||||||
// with a gradient will appear black in Firefox, etc. See bug 308590
|
// with a gradient will appear black in Firefox, etc. See bug 308590
|
||||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=308590
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=308590
|
||||||
var saveHandler = function(window,svg) {
|
var saveHandler = function(window,svg) {
|
||||||
if(window.opera && window.opera.io && window.opera.io.filesystem)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
window.opera.io.filesystem.browseForSave(
|
|
||||||
new Date().getTime(), /* mountpoint name */
|
|
||||||
"", /* default location */
|
|
||||||
function(file) {
|
|
||||||
try {
|
|
||||||
if (file) {
|
|
||||||
var fstream = file.open(file, "w");
|
|
||||||
fstream.write(svg, "UTF-8");
|
|
||||||
fstream.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(e) {
|
|
||||||
console.log("Write to file failed.");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
false /* not persistent */
|
|
||||||
);
|
|
||||||
}
|
|
||||||
catch(e) {
|
|
||||||
console.log("Save file failed.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
window.open("data:image/svg+xml;base64," + Utils.encode64(svg));
|
window.open("data:image/svg+xml;base64," + Utils.encode64(svg));
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// called when we've selected a different element
|
// called when we've selected a different element
|
||||||
|
@ -924,13 +896,20 @@ function svg_edit_setup() {
|
||||||
$('#stroke_width').SpinButton({ min: 1, max: 99, step: 1, callback: changeStrokeWidth });
|
$('#stroke_width').SpinButton({ min: 1, max: 99, step: 1, callback: changeStrokeWidth });
|
||||||
$('#angle').SpinButton({ min: -180, max: 180, step: 5, callback: changeRotationAngle });
|
$('#angle').SpinButton({ min: -180, max: 180, step: 5, callback: changeRotationAngle });
|
||||||
|
|
||||||
// if Opera and in widget form, enable the Open button
|
svgCanvas.setCustomHandlers = function(opts) {
|
||||||
if (window.opera) {
|
if(opts.open) {
|
||||||
opera.postError('opera.io=' + opera.io);
|
|
||||||
if(opera && opera.io && opera.io.filesystem) {
|
|
||||||
$('#tool_open').show();
|
$('#tool_open').show();
|
||||||
|
svgCanvas.bind("opened", opts.open);
|
||||||
|
}
|
||||||
|
if(opts.save) {
|
||||||
|
svgCanvas.bind("saved", opts.save);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return svgCanvas;
|
return svgCanvas;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This happens when the page is loaded
|
||||||
|
$(function() {
|
||||||
|
svgCanvas = svg_edit_setup();
|
||||||
|
});
|
||||||
|
|
|
@ -1985,38 +1985,9 @@ function SvgCanvas(c)
|
||||||
|
|
||||||
// public functions
|
// public functions
|
||||||
|
|
||||||
this.open = function() {
|
this.open = function(str) {
|
||||||
if(window.opera && window.opera.io && window.opera.io.filesystem)
|
// Nothing by default, handled by optional widget/extention
|
||||||
{
|
call("opened", str);
|
||||||
try {
|
|
||||||
window.opera.io.filesystem.browseForFile(
|
|
||||||
new Date().getTime(), /* mountpoint name */
|
|
||||||
"", /* default location */
|
|
||||||
function(file) {
|
|
||||||
try {
|
|
||||||
if (file) {
|
|
||||||
fstream = file.open(file, "r");
|
|
||||||
var output = "";
|
|
||||||
while (!fstream.eof) {
|
|
||||||
output += fstream.readLine("UTF-16");
|
|
||||||
}
|
|
||||||
|
|
||||||
canvas.setSvgString(output); /* 'this' is bound to the filestream object here */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(e) {
|
|
||||||
console.log("Reading file failed.");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
false, /* not persistent */
|
|
||||||
false, /* no multiple selections */
|
|
||||||
"*.svg" /* file extension filter */
|
|
||||||
);
|
|
||||||
}
|
|
||||||
catch(e) {
|
|
||||||
console.log("Open file failed.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.save = function() {
|
this.save = function() {
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/sh
|
||||||
|
DST="content/editor"
|
||||||
|
if [ -e "${DST}" ]; then
|
||||||
|
rm -rf "${DST}"
|
||||||
|
fi
|
||||||
|
cp -R ../editor content/
|
||||||
|
SVNS=`find content/editor -name '.svn'`
|
||||||
|
rm -rf ${SVNS}
|
|
@ -1,6 +1,5 @@
|
||||||
function start_svg_edit() {
|
function start_svg_edit() {
|
||||||
var url = "chrome://SVG-edit/content/editor/svg-editor.html";
|
var url = "chrome://SVG-edit/content/editor/svg-editor.html";
|
||||||
var browser = document.getElementById("content");
|
|
||||||
|
|
||||||
window.openDialog(url, "SVG Editor",
|
window.openDialog(url, "SVG Editor",
|
||||||
"width=1024,height=700,menubar=no,toolbar=no");
|
"width=1024,height=700,menubar=no,toolbar=no");
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
// Note: This JavaScript file must be included as the last script on the main HTML editor page to override the open/close handlers
|
||||||
|
$(function() {
|
||||||
|
if(!window.Components) return;
|
||||||
|
|
||||||
|
function moz_file_picker(readflag) {
|
||||||
|
var fp = window.Components.classes["@mozilla.org/filepicker;1"].
|
||||||
|
createInstance(Components.interfaces.nsIFilePicker);
|
||||||
|
if(readflag)
|
||||||
|
fp.init(window, "Pick a SVG file", fp.modeOpen);
|
||||||
|
else
|
||||||
|
fp.init(window, "Pick a SVG file", fp.modeSave);
|
||||||
|
fp.defaultExtension = "*.svg";
|
||||||
|
fp.show();
|
||||||
|
return fp.file;
|
||||||
|
}
|
||||||
|
|
||||||
|
svgCanvas.setCustomHandlers({
|
||||||
|
'open':function() {
|
||||||
|
try {
|
||||||
|
netscape.security.PrivilegeManager.
|
||||||
|
enablePrivilege("UniversalXPConnect");
|
||||||
|
var file = moz_file_picker(true);
|
||||||
|
if(!file)
|
||||||
|
return(null);
|
||||||
|
|
||||||
|
var inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
|
||||||
|
inputStream.init(file, 0x01, 00004, null);
|
||||||
|
var sInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
|
||||||
|
sInputStream.init(inputStream);
|
||||||
|
canvas.setSvgString(sInputStream.
|
||||||
|
read(sInputStream.available()));
|
||||||
|
} catch(e) {
|
||||||
|
console.log("Exception while attempting to load" + e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'save':function(svg) {
|
||||||
|
try {
|
||||||
|
var file = moz_file_picker(false);
|
||||||
|
if(!file)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!file.exists())
|
||||||
|
file.create(0, 0664);
|
||||||
|
|
||||||
|
var out = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
|
||||||
|
out.init(file, 0x20 | 0x02, 00004,null);
|
||||||
|
out.write(str, str.length);
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
} catch(e) {
|
||||||
|
alert(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
./build.sh
|
||||||
|
zip -r ../svg-edit.xpi *
|
|
@ -0,0 +1,62 @@
|
||||||
|
// Note: This JavaScript file must be included as the last script on the main HTML editor page to override the open/close handlers
|
||||||
|
$(function() {
|
||||||
|
if(window.opera && window.opera.io && window.opera.io.filesystem) {
|
||||||
|
svgCanvas.setCustomHandlers({
|
||||||
|
'open':function() {
|
||||||
|
try {
|
||||||
|
window.opera.io.filesystem.browseForFile(
|
||||||
|
new Date().getTime(), /* mountpoint name */
|
||||||
|
"", /* default location */
|
||||||
|
function(file) {
|
||||||
|
try {
|
||||||
|
if (file) {
|
||||||
|
fstream = file.open(file, "r");
|
||||||
|
var output = "";
|
||||||
|
while (!fstream.eof) {
|
||||||
|
output += fstream.readLine("UTF-16");
|
||||||
|
}
|
||||||
|
|
||||||
|
svgCanvas.setSvgString(output); /* 'this' is bound to the filestream object here */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
console.log("Reading file failed.");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
false, /* not persistent */
|
||||||
|
false, /* no multiple selections */
|
||||||
|
"*.svg" /* file extension filter */
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
console.log("Open file failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
'save':function(svg) {
|
||||||
|
try {
|
||||||
|
window.opera.io.filesystem.browseForSave(
|
||||||
|
new Date().getTime(), /* mountpoint name */
|
||||||
|
"", /* default location */
|
||||||
|
function(file) {
|
||||||
|
try {
|
||||||
|
if (file) {
|
||||||
|
var fstream = file.open(file, "w");
|
||||||
|
fstream.write(svg, "UTF-8");
|
||||||
|
fstream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
console.log("Write to file failed.");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
false /* not persistent */
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
console.log("Save file failed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in New Issue