From: Aleksander Ɓukasz Date: Tue, 11 Jun 2013 09:56:27 +0000 (+0200) Subject: Refactor X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/529d397b436dfefad66aabf7c1d56847d3c9cd56?ds=inline;hp=e923d179bfd4a70dc7df8e128063ed2a3284fc4f Refactor --- diff --git a/modules/documentCanvas/documentCanvas.js b/modules/documentCanvas/documentCanvas.js index 05fbcdd..8f3a3c6 100644 --- a/modules/documentCanvas/documentCanvas.js +++ b/modules/documentCanvas/documentCanvas.js @@ -245,7 +245,8 @@ return function(sandbox) { view.dimNode(wlxmlNode); }, selectNode: function(wlxmlNode) { - view.selectNode(wlxmlNode, {moveCarret: true}); + if(!wlxmlNode.is(view.currentNode)) + view.selectNode(wlxmlNode, {moveCarret: true}); }, toggleGrid: function(toggle) { view.toggleGrid(toggle); diff --git a/modules/documentCanvas/wlxmlNode.js b/modules/documentCanvas/wlxmlNode.js index f5ada52..6bd0c35 100644 --- a/modules/documentCanvas/wlxmlNode.js +++ b/modules/documentCanvas/wlxmlNode.js @@ -29,6 +29,9 @@ var Node = function(domNode) { list.push(new Node($(this))); }); return $(list); + }, + is: function(wlxmlNode) { + return wlxmlNode && (wlxmlNode.id === this.id); } } diff --git a/modules/nodeBreadCrumbs/nodeBreadCrumbs.js b/modules/nodeBreadCrumbs/nodeBreadCrumbs.js index cefe7b4..517f45b 100644 --- a/modules/nodeBreadCrumbs/nodeBreadCrumbs.js +++ b/modules/nodeBreadCrumbs/nodeBreadCrumbs.js @@ -31,6 +31,7 @@ return function(sandbox) { setNode: function(node) { this.dom.empty(); var nodes = this.nodes = {}; + this.currentNode = node; this.nodes[node.id] = node; var parents = node.parents(); parents.each(function() { @@ -53,7 +54,11 @@ return function(sandbox) { return { start: function() { sandbox.publish('ready'); }, getView: function() { return view.dom; }, - setNode: function(node) { view.setNode(node); }, + setNode: function(wlxmlNode) { + if(!wlxmlNode.is(view.currentNode)) { + view.setNode(wlxmlNode); + } + }, highlightNode: function(id) { view.highlightNode(id); }, dimNode: function(id) { view.dimNode(id); } } diff --git a/modules/nodeFamilyTree/nodeFamilyTree.js b/modules/nodeFamilyTree/nodeFamilyTree.js index 3c78bd1..7415b2d 100644 --- a/modules/nodeFamilyTree/nodeFamilyTree.js +++ b/modules/nodeFamilyTree/nodeFamilyTree.js @@ -31,6 +31,7 @@ return function(sandbox) { setNode: function(node) { console.log('familyTree sets node'); var nodes = this.nodes = {}; + this.currentNode = node; var parentNode = node.parent(); var parent = undefined; @@ -65,8 +66,9 @@ return function(sandbox) { start: function() { sandbox.publish('ready'); }, - setNode: function(node) { - view.setNode(node); + setNode: function(wlxmlNode) { + if(!wlxmlNode.is(view.currentNode)) + view.setNode(wlxmlNode); }, getView: function() { return view.dom; diff --git a/modules/rng/rng.js b/modules/rng/rng.js index 5edc7ac..6f65c19 100644 --- a/modules/rng/rng.js +++ b/modules/rng/rng.js @@ -25,6 +25,13 @@ return function(sandbox) { if(!origin || moduleName != origin) sandbox.getModule(moduleName).dimNode(wlxmlNode) }); + }, + selectNode: function(wlxmlNode, origin) { + sandbox.getModule('documentCanvas').selectNode(wlxmlNode); + sandbox.getModule('nodePane').setNode(wlxmlNode); + sandbox.getModule('nodeFamilyTree').setNode(wlxmlNode); + sandbox.getModule('nodeBreadCrumbs').setNode(wlxmlNode); + } } @@ -101,10 +108,8 @@ return function(sandbox) { views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView()); }, - nodeSelected: function(node) { - sandbox.getModule('nodePane').setNode(node); - sandbox.getModule('nodeFamilyTree').setNode(node); - sandbox.getModule('nodeBreadCrumbs').setNode(node); + nodeSelected: function(wlxmlNode) { + commands.selectNode(wlxmlNode); }, contentChanged: function() { @@ -148,7 +153,7 @@ return function(sandbox) { commands.dimDocumentNode(wlxmlNode, 'nodeFamilyTree'); }, nodeSelected: function(wlxmlNode) { - sandbox.getModule('documentCanvas').selectNode(wlxmlNode); + commands.selectNode(wlxmlNode); } }; @@ -179,7 +184,7 @@ return function(sandbox) { commands.dimDocumentNode(wlxmlNode, 'nodeBreadCrumbs'); }, nodeSelected: function(wlxmlNode) { - sandbox.getModule('documentCanvas').selectNode(wlxmlNode); + commands.selectNode(wlxmlNode); } }