documentCanvas fix: node now dims correctly
[fnpeditor.git] / modules / rng / rng.js
index fec264e..5edc7ac 100644 (file)
@@ -13,6 +13,22 @@ return function(sandbox) {
         views.mainTabs.addTab(title, slug, view);\r
     }\r
     \r
+    var commands = {\r
+        highlightDocumentNode: function(wlxmlNode, origin) {\r
+            ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {\r
+                if(!origin || moduleName != origin)\r
+                    sandbox.getModule(moduleName).highlightNode(wlxmlNode)\r
+            });\r
+        },\r
+        dimDocumentNode: function(wlxmlNode, origin) {\r
+            ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {\r
+                if(!origin || moduleName != origin)\r
+                    sandbox.getModule(moduleName).dimNode(wlxmlNode)\r
+            });\r
+        }\r
+    }\r
+    \r
+\r
     var views = {\r
         mainLayout: new layout.Layout(mainLayoutTemplate),\r
         mainTabs: (new tabs.View()).render(),\r
@@ -22,13 +38,11 @@ return function(sandbox) {
     }\r
     \r
     views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView());\r
-    addMainTab('rng2 test', 'rng2test', views.visualEditing.getAsView());\r
+    addMainTab('Edytor', 'editor', views.visualEditing.getAsView());\r
     \r
     sandbox.getDOM().append(views.mainLayout.getAsView());\r
     \r
     views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView());\r
-    \r
-    \r
 \r
     \r
     /* Events handling */\r
@@ -42,19 +56,11 @@ return function(sandbox) {
         }\r
     };\r
     \r
-    eventHandlers.visualEditor = {\r
-        ready: function() {\r
-            sandbox.getModule('visualEditor').setDocument(sandbox.getModule('data').getDocument());\r
-            addMainTab(gettext('Visual'), 'visual', sandbox.getModule('visualEditor').getView());\r
-            \r
-        }\r
-    };\r
-    \r
     eventHandlers.data = {\r
         ready: function() {\r
             views.mainLayout.setView('mainView', views.mainTabs.getAsView());\r
             \r
-            _.each(['visualEditor', 'sourceEditor', 'documentCanvas', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'mainBar', 'indicator'], function(moduleName) {\r
+            _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator'], function(moduleName) {\r
                 sandbox.getModule(moduleName).start();\r
             });\r
         },\r
@@ -72,13 +78,6 @@ return function(sandbox) {
         }\r
     }\r
     \r
-    eventHandlers.rng2 = {\r
-        ready: function() {\r
-           addMainTab('rng2 test', 'rng2test', sandbox.getModule('rng2').getView());\r
-           \r
-        }\r
-    }\r
-    \r
     eventHandlers.mainBar = {\r
         ready: function() {\r
             views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());\r
@@ -105,18 +104,19 @@ return function(sandbox) {
         nodeSelected: function(node) {\r
             sandbox.getModule('nodePane').setNode(node);\r
             sandbox.getModule('nodeFamilyTree').setNode(node);\r
+            sandbox.getModule('nodeBreadCrumbs').setNode(node);\r
         },\r
         \r
         contentChanged: function() {\r
         \r
         },\r
         \r
-        nodeHovered: function(node) {\r
-            \r
+        nodeHovered: function(wlxmlNode) {\r
+            commands.highlightDocumentNode(wlxmlNode);\r
         },\r
         \r
-        nodeBlured: function(node) {\r
-        \r
+        nodeBlured: function(wlxmlNode) {\r
+            commands.dimDocumentNode(wlxmlNode);\r
         }\r
     };\r
 \r
@@ -141,15 +141,46 @@ return function(sandbox) {
         ready: function() {\r
             views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());\r
         },\r
-        nodeEntered: function(id) {\r
-            sandbox.getModule('documentCanvas').highlightNode(id);\r
+        nodeEntered: function(wlxmlNode) {\r
+            commands.highlightDocumentNode(wlxmlNode, 'nodeFamilyTree');\r
+        },\r
+        nodeLeft: function(wlxmlNode) {\r
+            commands.dimDocumentNode(wlxmlNode, 'nodeFamilyTree');\r
+        },\r
+        nodeSelected: function(wlxmlNode) {\r
+            sandbox.getModule('documentCanvas').selectNode(wlxmlNode);\r
+        }\r
+    };\r
+    \r
+    eventHandlers.documentToolbar = {\r
+        ready: function() {\r
+            views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView());\r
         },\r
-        nodeLeft: function(id) {\r
-            sandbox.getModule('documentCanvas').dimNode(id);\r
+        toggleGrid: function(toggle) {\r
+            sandbox.getModule('documentCanvas').toggleGrid(toggle);\r
         },\r
-        nodeSelected: function(id) {\r
-            sandbox.getModule('documentCanvas').selectNode(id);\r
+        newNodeRequested: function(wlxmlTag, wlxmlClass) {\r
+            if(window.getSelection().isCollapsed) {\r
+                sandbox.getModule('documentCanvas').insertNewNode(wlxmlTag, wlxmlClass);\r
+            } else {\r
+                sandbox.getModule('documentCanvas').wrapSelectionWithNewNode(wlxmlTag, wlxmlClass);\r
+            }\r
         }\r
+    };\r
+    \r
+    eventHandlers.nodeBreadCrumbs = {\r
+        ready: function() {\r
+            views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());\r
+        },\r
+        nodeHighlighted: function(wlxmlNode) {\r
+            commands.highlightDocumentNode(wlxmlNode, 'nodeBreadCrumbs');\r
+        },\r
+        nodeDimmed: function(wlxmlNode) {\r
+            commands.dimDocumentNode(wlxmlNode, 'nodeBreadCrumbs');\r
+        },\r
+        nodeSelected: function(wlxmlNode) {\r
+            sandbox.getModule('documentCanvas').selectNode(wlxmlNode);\r
+        }        \r
     }\r
     \r
     /* api */\r