changeset 381:29145d2affdb

Add function to change the name of the symbol
author wycc
date Sun, 05 Apr 2009 12:28:36 +0800
parents 9c70de05a0b6
children 83283a45ffbc
files inkscape/firefox/MBServer.py inkscape/firefox/content/inkscape.js inkscape/firefox/content/madbuilder.html inkscape/firefox/helper_mb.py
diffstat 4 files changed, 81 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/inkscape/firefox/MBServer.py	Sat Apr 04 06:16:27 2009 +0800
+++ b/inkscape/firefox/MBServer.py	Sun Apr 05 12:28:36 2009 +0800
@@ -242,6 +242,20 @@
 		if len(layer.scene) > 0 and nth > layer.scene[len(layer.scene)-1].end:
 			layer.scene[len(layer.scene)-1].end = nth
 
+	def findNodeById(self,root,id):
+		for n in root:
+			if n.attrib.get('id') == id:
+				return n
+			nn = self.findNodeById(n,id)
+			if nn is not None:
+				return nn
+		return None
+	def changeSymbol(self,id,newname):
+		node = self.findNodeById(self.document.getroot(),id)
+		if node is not None:
+			node.set('mbname',newname);
+
+
 	def setCurrentScene(self,nth):
 		self.current = nth
 		for layer in self.layer:
@@ -481,6 +495,12 @@
 			return etree.tostring(newdoc)
 		except:
 			return traceback.format_exc()
+	def soap_CHANGESYMBOL(self,id,newname):
+		try:
+			self.target.changeSymbol(id,newname)
+			return "OK"
+		except:
+			return traceback.format_exc()
 import os
 os.chdir('/usr/local/share/inkscape/extensions')
 
--- a/inkscape/firefox/content/inkscape.js	Sat Apr 04 06:16:27 2009 +0800
+++ b/inkscape/firefox/content/inkscape.js	Sun Apr 05 12:28:36 2009 +0800
@@ -228,6 +228,34 @@
 	this.isInProgress++;
 }
 
+Inkscape.prototype.changeSymbolName_cb = function(callback)
+{
+	var soapBody = new SOAPObject("CHANGESYMBOL");
+	var v1 = new SOAPObject("v1");
+	v1.attr('type','string');
+	v1.val(this.v1);
+	soapBody.appendChild(v1);
+	var v2 = new SOAPObject("v2");
+	v2.val(this.v2);
+	soapBody.appendChild(v2);
+	var sr = new SOAPRequest("CHANGESYMBOL", soapBody);
+	SOAPClient.Proxy = "http://localhost:19192/";
+	SOAPClient.SendRequest(sr, function (resp,arg) {arg.refreshDocument(resp);},this);
+	this.inProgress--;
+}
+
+Inkscape.prototype.changeSymbolName = function(id,newname,callback)
+{	
+	var soapBody = new SOAPObject("START");
+	this.callback = callback
+	var sr = new SOAPRequest("START", soapBody);
+	SOAPClient.Proxy = "http://localhost:19192/";
+	this.v1 = id;
+	this.v2 = newname;
+	SOAPClient.SendRequest(sr,function(resp,arg) {arg.changeSymbolName_cb(resp);},this);
+	this.isInProgress++;
+}
+
 /*
  *  This module is used to define a symbol for the MadButterfly. This function will search for symbol which is defined in the current select object. We will list all SVG elements 
  *  in the left side, multiple variables can be defined at one time. When any element is selected, the defined symbol will be listed in the right side. 
@@ -237,11 +265,23 @@
 Inkscape.prototype.MakeSymbol=function()
 {
 	function callback(mbsvg) {
-		this.loadSymbolScreen(mbsvg);
+		inkscape.loadSymbolScreen(mbsvg);
 	}
 	inkscape.fetchDocument(callback);
 }
 
+
+Inkscape.prototype.onChangeSymbolName=function()
+{
+	inkscape.changeSymbolName(inkscape.current_symbol, $('#newsymbolname').val());
+	symboldialog.dialog('close')
+}
+
+Inkscape.prototype.refreshSymbolPanel=function(node)
+{
+	inkscape.current_symbol = node.textContent;
+}
+
 Inkscape.prototype.loadSymbolScreen=function (mbsvg) {
 	// Swap the left side to be the SVG element tree.
 	var i,l;
@@ -261,10 +301,12 @@
 		json : jsonobj
 	    },
 	    callback : {
-	        ondblclk : function(NODE,TREE_OBJ) { this.refreshSymbolPanel(TREE_OBJ); TREE_OBJ.toggle_branch.call(TREE_OBJ, NODE); TREE_OBJ.select_branch.call(TREE_OBJ, NODE);}
+	        ondblclk : function(NODE,TREE_OBJ) { inkscape.refreshSymbolPanel(NODE); TREE_OBJ.toggle_branch.call(TREE_OBJ, NODE); TREE_OBJ.select_branch.call(TREE_OBJ, NODE);}
 	    }
 
   	});
+	var s = $('#changename');
+	s.click(this.onChangeSymbolName);
 	// Swap the right side to be the symbol editor screen.
 	symboldialog.show();
 }
@@ -276,8 +318,8 @@
 			           autoOpen:false,
 				   title:'Please select a file'});
 		symboldialog.hide();
-		symboldialog.append("<div id='symbollist'>");
-		symboldialog.append("<div id='symbol'>");
+		symboldialog.append("<div id='symbollist'/>");
+		symboldialog.append("<div id='symbol'><input type='text' id='newsymbolname'> <input type='submit' id='changename'></div> ");
 		});
 
 function MBSVG(file)
--- a/inkscape/firefox/content/madbuilder.html	Sat Apr 04 06:16:27 2009 +0800
+++ b/inkscape/firefox/content/madbuilder.html	Sun Apr 05 12:28:36 2009 +0800
@@ -125,6 +125,8 @@
 	Generating files<br>
 </div>
 
+<div id='symboldialog' />
+
 <script type="text/javascript" src="inkscape.js" >
 </script>
 </body>
--- a/inkscape/firefox/helper_mb.py	Sat Apr 04 06:16:27 2009 +0800
+++ b/inkscape/firefox/helper_mb.py	Sun Apr 05 12:28:36 2009 +0800
@@ -21,7 +21,6 @@
 		return d
 			
 	def quit(self,result,d):
-		print [result]
 		d.callback(result)
 		self.client = None
 	def soap_INSERTKEY(self,layer,n):
@@ -119,6 +118,16 @@
 		except:
 			traceback.print_exc()
 	
+	def soap_CHANGESYMBOL(self,id,name):
+		if self.client == None:
+			os.kill(self.pid,12)
+			time.sleep(1)
+			self.client = Client()
+		d = defer.Deferred()
+		print "send changesymbol"
+		self.client.CHANGESYMBOL(id,name).addCallback(self.generic_return,d).addErrback(self.generic_error,d)
+		return d
+
 class Client(object):
 	def __init__(self):
 		self.proxy = soap.Proxy('http://localhost:8080')	
@@ -135,6 +144,9 @@
 		return self.proxy.callRemote('EXTENDSCENE',layer,n)
 	def DELETESCENE(self,layer,n):
 		return self.proxy.callRemote('DELETESCENE',layer,n)
+	def CHANGESYMBOL(self,id,name):
+		print "send soap CHANGESYMBOL to to client"
+		return self.proxy.callRemote('CHANGESYMBOL',id,name)
 
 os.system("killall -9 inkscape-mb")
 try: