+ function addMainTab(title, slug, view) {\r
+ views.mainTabs.addTab(title, slug, view);\r
+ }\r
+ \r
+ var dirty = {\r
+ sourceEditor: false,\r
+ documentCanvas: false,\r
+ metadataEditor: false,\r
+ };\r
+ \r
+ var synchronizeTab = function(slug) {\r
+ function tabIsDirty(slug) {\r
+ if(slug === 'editor' && (dirty.documentCanvas || dirty.metadataEditor))\r
+ return true;\r
+ if(slug === 'sourceEditor' && dirty.sourceEditor)\r
+ return true;\r
+ return false;\r
+ }\r
+ \r
+ if(tabIsDirty(slug)) {\r
+ var reason, doc;\r
+ if(slug === 'sourceEditor') {\r
+ doc = sandbox.getModule('sourceEditor').getDocument();\r
+ reason = 'source_edit';\r
+ dirty.sourceEditor = false;\r
+ }\r
+ if(slug === 'editor') {\r
+ var doc = dirty.documentCanvas ? sandbox.getModule('documentCanvas').getDocument() : sandbox.getModule('data').getDocument();\r
+ if(dirty.metadataEditor) {\r
+ doc = sandbox.getModule('metadataEditor').attachMetadata(doc);\r
+ }\r
+ reason = 'edit';\r
+ dirty.documentCanvas = dirty.metadataEditor = false;\r
+ }\r
+ sandbox.getModule('data').commitDocument(doc, reason);\r
+ }\r
+ }\r
+ \r
+ var commands = {\r
+ highlightDocumentNode: function(canvasNode, origin) {\r
+ ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {\r
+ if(!origin || moduleName != origin)\r
+ sandbox.getModule(moduleName).highlightNode(canvasNode)\r
+ });\r
+ },\r
+ dimDocumentNode: function(canvasNode, origin) {\r
+ ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {\r
+ if(!origin || moduleName != origin)\r
+ sandbox.getModule(moduleName).dimNode(canvasNode)\r
+ });\r
+ },\r
+ selectNode: function(canvasNode, origin) {\r
+ sandbox.getModule('documentCanvas').selectNode(canvasNode);\r
+ sandbox.getModule('nodePane').setNode(canvasNode);\r
+ sandbox.getModule('nodeFamilyTree').setNode(canvasNode);\r
+ sandbox.getModule('nodeBreadCrumbs').setNode(canvasNode);\r
+ \r
+ },\r
+ resetDocument: function(document, reason) {\r
+ var modules = [];\r
+ if(reason === 'source_edit')\r
+ modules = ['documentCanvas', 'metadataEditor'];\r
+ else if (reason === 'edit')\r
+ modules = ['sourceEditor'];\r
+ else if (reason === 'revert')\r
+ modules = ['documentCanvas', 'metadataEditor', 'sourceEditor'];\r
+ \r
+ modules.forEach(function(moduleName) {\r
+ sandbox.getModule(moduleName).setDocument(document);\r
+ });\r
+ }\r
+ }\r