changeset 395:7c95f95f03fd

SVG-editor: reading data back from a given file principle implemented.
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Mon, 24 Aug 2009 18:08:26 +0200
parents 119c40c2ee96
children 42af39088fd4
files data/plugin/action/SVG-editor.py htdocs/svg-edit/CHANGES.current htdocs/svg-edit/editor/svg-editor.js
diffstat 3 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/action/SVG-editor.py	Mon Aug 24 00:35:25 2009 +0200
+++ b/data/plugin/action/SVG-editor.py	Mon Aug 24 18:08:26 2009 +0200
@@ -9,8 +9,7 @@
     @copyright: 2009 by MoinMoin:ReimarBauer
     @license: GNU GPL, see COPYING for details.
 """
-import base64
-from MoinMoin import config
+from MoinMoin import config, wikiutil
 from MoinMoin.action import AttachFile
 
 
@@ -20,7 +19,9 @@
     if AttachFile.exists(request, pagename, target):
         fpath = AttachFile.getFilename(request, pagename, target).encode(config.charset)
         filecontent = file(fpath, 'r').readlines()
-        filecontent = base64.b64encode('\n'.join(filecontent))
+        filecontent = ''.join(filecontent[1:])
+        filecontent = filecontent.encode('base_64')
+
     do = request.values.get('do', '')
     if do == 'save':
         filecontent = request.values.get('svg_data', '')
@@ -64,6 +65,9 @@
 <div id="workarea">
 <style id="styleoverrides" type="text/css"></style>
 <div id="svgcanvas"></div>
+<div id="svgdata">
+%(filecontent)s
+</div>
 </div>
 
 <div id="logo">
--- a/htdocs/svg-edit/CHANGES.current	Mon Aug 24 00:35:25 2009 +0200
+++ b/htdocs/svg-edit/CHANGES.current	Mon Aug 24 18:08:26 2009 +0200
@@ -10,9 +10,9 @@
    and go to the page after saving
 
 ToDo
- * reading a saved file back to the editor based on target
  * adjust coordinates for drawing tools (offset probably from relative)
  * fix wrong url for square and circle 
+ * add base 64 decoder to svg-editor.js
 
 SVG-edit is a lightweight, web-based, Javascript-driven SVG editor that works in any modern browser: initial version of svg-edit Revision r448 (http://code.google.com/p/svg-edit/) for moin-1.9 added
 
--- a/htdocs/svg-edit/editor/svg-editor.js	Mon Aug 24 00:35:25 2009 +0200
+++ b/htdocs/svg-edit/editor/svg-editor.js	Mon Aug 24 18:08:26 2009 +0200
@@ -10,15 +10,20 @@
 
 	var isMac = false; //(navigator.platform.indexOf("Mac") != -1);
 	var modKey = ""; //(isMac ? "meta+" : "ctrl+");
+    
+    var svg = document.getElementById("svgdata");
 	var svgCanvas = new SvgCanvas(document.getElementById("svgcanvas"));
-    // ToDo feed fielecontent into svgCanvas
-    var filecontent = '';
+    var filecontent =  svg.innerHTML;
+    // ToDo filecontent needs to be base64 decoded
     if (filecontent != '') {
-        var svg = filecontent;
-        svgCanvas.setSvgString(svg);
+        if (!svgCanvas.setSvgString(filecontent)) {
+            if( !confirm('There were parsing errors in your SVG source.\nRevert back to original SVG source?') ) {
+                return false;
+            }
+        }
+        svgCanvas.clearSelection();
     }
 
-
 	var setSelectMode = function() {
 		$('.tool_button_current').removeClass('tool_button_current').addClass('tool_button');
 		$('#tool_select').addClass('tool_button_current');