From 31b094ee21102f99a4021d505bc3a28527c9e23d Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 30 May 2012 01:33:20 -0700 Subject: Fixing the close document. Signed-off-by: Valerio Virgillito --- .../layout/bread-crumb.reel/bread-crumb.js | 16 +---- .../layout/document-bar.reel/document-bar.js | 15 ----- .../layout/document-entry.reel/document-entry.js | 11 +--- js/controllers/document-controller.js | 72 +++------------------- js/controllers/selection-controller.js | 1 - js/ninja.reel/ninja.js | 8 +++ js/panels/Panel.reel/Panel.js | 7 ++- js/panels/PanelContainer.reel/PanelContainer.js | 12 ---- js/panels/css-panel/css-panel.reel/css-panel.html | 3 + js/panels/css-panel/css-panel.reel/css-panel.js | 18 ++++++ .../styles-view-container.js | 31 +++++++--- js/panels/properties.reel/properties.js | 11 +--- js/stage/layout.js | 6 +- js/stage/stage-deps.js | 7 ++- js/stage/stage.reel/stage.js | 14 ++--- 15 files changed, 88 insertions(+), 144 deletions(-) diff --git a/js/components/layout/bread-crumb.reel/bread-crumb.js b/js/components/layout/bread-crumb.reel/bread-crumb.js index 74e89ac1..ac131f2c 100755 --- a/js/components/layout/bread-crumb.reel/bread-crumb.js +++ b/js/components/layout/bread-crumb.reel/bread-crumb.js @@ -26,12 +26,12 @@ exports.Breadcrumb = Montage.create(Component, { this._currentDocument = value; - if(!this._currentDocument) { + if(!value) { this.disabled = true; + } else { + this.disabled = this._currentDocument.currentView !== "design"; } - this.disabled = this._currentDocument.currentView !== "design"; - } }, @@ -51,15 +51,6 @@ exports.Breadcrumb = Montage.create(Component, { } }, - handleCloseDocument: { - value: function(){ - if(!this.application.ninja.documentController.activeDocument && this.application.ninja.currentDocument.currentView !== "code") { - this.disabled = true; - this.application.ninja.currentSelectedContainer = (this.application.ninja.currentDocument ? this.application.ninja.currentDocument.model.documentRoot : null); - } - } - }, - _container:{ value:null }, @@ -82,7 +73,6 @@ exports.Breadcrumb = Montage.create(Component, { prepareForDraw: { value: function() { - this.eventManager.addEventListener("closeDocument", this, false); this.breadcrumbBt.addEventListener("action", this, false); } }, diff --git a/js/components/layout/document-bar.reel/document-bar.js b/js/components/layout/document-bar.reel/document-bar.js index 6a7b0f3f..90d3a207 100755 --- a/js/components/layout/document-bar.reel/document-bar.js +++ b/js/components/layout/document-bar.reel/document-bar.js @@ -105,7 +105,6 @@ exports.DocumentBar = Montage.create(Component, { prepareForDraw: { value: function() { - this.eventManager.addEventListener( "closeDocument", this, false); this.designView.addEventListener("click", this, false); this.codeView.addEventListener("click", this, false); @@ -135,19 +134,5 @@ exports.DocumentBar = Montage.create(Component, { this.currentView = event._event.target.id; this.application.ninja.documentController.stage.stageView.switchDesignDocViews(event._event.target.id);//switch between design view } - }, - - handleCloseDocument: { - value: function() { - if(!this.application.ninja.documentController.activeDocument) { - this.disabled = true; - } - } - }, - - handleOnDocumentChanged:{ - value:function(event){ - - } } }); diff --git a/js/components/layout/document-entry.reel/document-entry.js b/js/components/layout/document-entry.reel/document-entry.js index 34e307cb..94056007 100755 --- a/js/components/layout/document-entry.reel/document-entry.js +++ b/js/components/layout/document-entry.reel/document-entry.js @@ -9,10 +9,6 @@ var Component = require("montage/ui/component").Component; exports.DocumentEntry = Montage.create(Component, { - _uuid: { - value: null - }, - _document: { value: null }, @@ -23,16 +19,11 @@ exports.DocumentEntry = Montage.create(Component, { return this._document; }, set: function(value) { - if (this._document === value) { return; } this._document = value; - - if(value) { - this._uuid = value.uuid; - } } }, @@ -87,7 +78,7 @@ exports.DocumentEntry = Montage.create(Component, { handleCloseButtonAction: { value: function() { - //this.application.ninja.documentController.closeFile(this.application.ninja.documentController._findDocumentByUUID(this._uuid)); + this.application.ninja.documentController.closeFile(this.document); } } diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index eba950b9..4f122b3b 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -31,7 +31,7 @@ exports.DocumentController = Montage.create(Component, { return this._currentDocument; }, set : function(value) { - if (value === this._currentDocument || value.getProperty("currentView") !== "design") { + if (value === this._currentDocument) { return; } @@ -41,7 +41,13 @@ exports.DocumentController = Montage.create(Component, { this._currentDocument = value; - this._currentDocument.model.currentView.show(); + if(!value) { + + } else { + this._currentDocument.model.currentView.show(); + } + + } }, @@ -323,7 +329,7 @@ exports.DocumentController = Montage.create(Component, { closeFile: { value: function(document) { - document.closeDocument(this, this.onCloseFile); + document.closeDocument(this.application.ninja, this.application.ninja.closeFile); } }, @@ -357,39 +363,6 @@ exports.DocumentController = Montage.create(Component, { } }, - closeDocument: { - value: function(id) { - var doc = this._findDocumentByUUID(id); - - var closeDocumentIndex = this._findIndexByUUID(id); - this._documents.splice(this._findIndexByUUID(id), 1); - - if(this.activeDocument.uuid === id && this._documents.length > 0) {//closing the active document tab - var nextDocumentIndex = -1 ; - if((this._documents.length > 0) && (closeDocumentIndex === 0)){ - nextDocumentIndex = 0; - }else if((this._documents.length > 0) && (closeDocumentIndex > 0)){ - nextDocumentIndex = closeDocumentIndex - 1; - } - this.application.ninja.stage.stageView.switchDocument(this._documents[nextDocumentIndex]); - if(typeof doc.stopVideos !== "undefined"){doc.stopVideos();} - doc.container.parentNode.removeChild(doc.container); - }else if(this._documents.length === 0){ - // See above - }else{//closing inactive document tab - just clear DOM - if(typeof doc.pauseAndStopVideos !== "undefined"){ - doc.pauseAndStopVideos(); - } - doc.container.parentNode.removeChild(doc.container); - } - - NJevent("closeDocument", doc.uri); - - doc=null; - } - }, - - _onOpenTextDocument: { value: function(doc) { @@ -462,32 +435,5 @@ exports.DocumentController = Montage.create(Component, { } } } - }, - - /** - * VIEW Related Methods - */ - - // PRIVATE - _findDocumentByUUID: { - value: function(uuid) { - var len = this._documents.length; - for(var i = 0; i < len; i++) { - if(this._documents[i].uuid === uuid) return this._documents[i]; - } - - return false; - } - }, - - _findIndexByUUID: { - value: function(uuid) { - var len = this._documents.length; - for(var i = 0; i < len; i++) { - if(this._documents[i].uuid === uuid) return i; - } - - return false; - } } }); diff --git a/js/controllers/selection-controller.js b/js/controllers/selection-controller.js index 0d34ff25..848355da 100755 --- a/js/controllers/selection-controller.js +++ b/js/controllers/selection-controller.js @@ -45,7 +45,6 @@ exports.SelectionController = Montage.create(Component, { this.eventManager.addEventListener("elementReplaced", this, false); this.eventManager.addEventListener("selectAll", this, false); this.eventManager.addEventListener("switchDocument", this, false); - this.eventManager.addEventListener("closeDocument", this, false); } }, diff --git a/js/ninja.reel/ninja.js b/js/ninja.reel/ninja.js index 3659f1f8..987c32fd 100755 --- a/js/ninja.reel/ninja.js +++ b/js/ninja.reel/ninja.js @@ -322,6 +322,14 @@ exports.Ninja = Montage.create(Component, { } }, + closeFile: { + value: function(document) { + var doc = this.documentList.content[this.documentList.content.indexOf(document)]; + + this.documentList.removeObjects(doc); + } + }, + handleOnSwitchDocument: { value: function() { this.currentDocument = this.documentController.activeDocument; diff --git a/js/panels/Panel.reel/Panel.js b/js/panels/Panel.reel/Panel.js index 14b25c36..0c5f0b4b 100755 --- a/js/panels/Panel.reel/Panel.js +++ b/js/panels/Panel.reel/Panel.js @@ -120,7 +120,12 @@ exports.Panel = Montage.create(Component, { this.panelContent.content[0].controller.currentDocument = this._currentDocument; } - this.disabled = this._currentDocument.currentView !== "design"; + if(!value) { + this.disabled = true; + } else { + this.disabled = this._currentDocument.currentView !== "design"; + } + } }, diff --git a/js/panels/PanelContainer.reel/PanelContainer.js b/js/panels/PanelContainer.reel/PanelContainer.js index dc501a99..7cb03255 100755 --- a/js/panels/PanelContainer.reel/PanelContainer.js +++ b/js/panels/PanelContainer.reel/PanelContainer.js @@ -81,8 +81,6 @@ exports.PanelContainer = Montage.create(Component, { } this.application.localStorage.setItem("panels", this.currentPanelState); - - this.eventManager.addEventListener( "closeDocument", this, false); } }, @@ -104,16 +102,6 @@ exports.PanelContainer = Montage.create(Component, { } }, - handleCloseDocument: { - value: function(){ - if(!this.application.ninja.documentController.activeDocument) { - this.panels.forEach(function(obj) { - obj.disabled = true; - }); - } - } - }, - handleDropped: { value: function(e) { var draggedIndex, droppedIndex = 0, len = this.panels.length; diff --git a/js/panels/css-panel/css-panel.reel/css-panel.html b/js/panels/css-panel/css-panel.reel/css-panel.html index 42dca8a2..789635a0 100644 --- a/js/panels/css-panel/css-panel.reel/css-panel.html +++ b/js/panels/css-panel/css-panel.reel/css-panel.html @@ -31,6 +31,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot "properties": { "element": {"#": "styles-view-container" }, "selectionName": {"@": "selectionName" } + }, + "bindings": { + "currentDocument" : {"<-": "@owner.currentDocument" } } }, "selectionName" : { diff --git a/js/panels/css-panel/css-panel.reel/css-panel.js b/js/panels/css-panel/css-panel.reel/css-panel.js index a117787e..96d94b36 100644 --- a/js/panels/css-panel/css-panel.reel/css-panel.js +++ b/js/panels/css-panel/css-panel.reel/css-panel.js @@ -8,6 +8,24 @@ var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component; exports.CssPanel = Montage.create(Component, { + + _currentDocument: { + value : null + }, + + currentDocument : { + get : function() { + return this._currentDocument; + }, + set : function(value) { + if (value === this._currentDocument) { + return; + } + + this._currentDocument = value; + } + }, + prepareForDraw : { value: function() { } diff --git a/js/panels/css-panel/styles-view-container.reel/styles-view-container.js b/js/panels/css-panel/styles-view-container.reel/styles-view-container.js index 4a391421..157d99de 100644 --- a/js/panels/css-panel/styles-view-container.reel/styles-view-container.js +++ b/js/panels/css-panel/styles-view-container.reel/styles-view-container.js @@ -8,6 +8,29 @@ var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component; exports.StylesViewContainer = Montage.create(Component, { + + _currentDocument: { + value : null + }, + + currentDocument : { + get : function() { + return this._currentDocument; + }, + set : function(value) { + if (value === this._currentDocument) { + return; + } + + this._currentDocument = value; + + if(!value) { + this.hasStyles = false; + this.needsDraw = true; + } + } + }, + contentController : { value: null }, @@ -74,7 +97,6 @@ exports.StylesViewContainer = Montage.create(Component, { value: function() { this.eventManager.addEventListener('styleSheetsReady', this, false); this.eventManager.addEventListener('elementChange', this, false); - this.eventManager.addEventListener("closeDocument", this, false); } }, handleStyleSheetsReady: { @@ -150,13 +172,6 @@ exports.StylesViewContainer = Montage.create(Component, { } }, - handleCloseDocument: { - value: function(e) { - this.hasStyles = false; - this.needsDraw = true; - } - }, - draw : { value: function() { if(this.hasStyles) { diff --git a/js/panels/properties.reel/properties.js b/js/panels/properties.reel/properties.js index e99f58e9..4b663220 100755 --- a/js/panels/properties.reel/properties.js +++ b/js/panels/properties.reel/properties.js @@ -29,7 +29,9 @@ exports.Properties = Montage.create(Component, { this._currentDocument = value; - if(this._currentDocument.currentView === "design") { + if(!value) { + this.clear(); + } else if(this._currentDocument.currentView === "design") { // Save a reference of the pi inside the document view to be able to clear this._currentDocument.model.views.design.propertiesPanel = this; @@ -74,7 +76,6 @@ exports.Properties = Montage.create(Component, { value : function() { this.eventManager.addEventListener("elementChange", this, false); this.eventManager.addEventListener("selectionChange", this, false); - this.eventManager.addEventListener("closeDocument", this, false); // This will be a toggle option if(this.application.ninja.appData.PILiveUpdate) { @@ -91,12 +92,6 @@ exports.Properties = Montage.create(Component, { } }, - handleCloseDocument: { - value: function(){ - this.clear(); - } - }, - /** * Blur and Key up to handle change in the Element ID field. */ diff --git a/js/stage/layout.js b/js/stage/layout.js index 8b66150d..284968e4 100755 --- a/js/stage/layout.js +++ b/js/stage/layout.js @@ -33,13 +33,15 @@ exports.Layout = Montage.create(Component, { return this._currentDocument; }, set : function(value) { - if (value === this._currentDocument || value.getProperty("currentView") !== "design") { + if (value === this._currentDocument) {// || value.getProperty("currentView") !== "design") { return; } this._currentDocument = value; - if(this._currentDocument) { + if(!value) { + + } else if(this._currentDocument.currentView === "design") { this.elementsToDraw = this._currentDocument.model.documentRoot.childNodes; } } diff --git a/js/stage/stage-deps.js b/js/stage/stage-deps.js index 756844fd..f27254f9 100755 --- a/js/stage/stage-deps.js +++ b/js/stage/stage-deps.js @@ -25,13 +25,15 @@ exports.StageDeps = Montage.create(Component, { return this._currentDocument; }, set : function(value) { - if (value === this._currentDocument || value.getProperty("currentView") !== "design") { + if (value === this._currentDocument) {// || value.getProperty("currentView") !== "design") { return; } this._currentDocument = value; - if(this._currentDocument) { + if(!value) { + + } else if(this._currentDocument.currentView === "design") { workingPlane = [0,0,1,0]; snapManager._isCacheInvalid = true; @@ -39,6 +41,7 @@ exports.StageDeps = Montage.create(Component, { drawUtils.initializeFromDocument(); } + } }, diff --git a/js/stage/stage.reel/stage.js b/js/stage/stage.reel/stage.js index 82c4d652..da5a4f76 100755 --- a/js/stage/stage.reel/stage.js +++ b/js/stage/stage.reel/stage.js @@ -164,27 +164,23 @@ exports.Stage = Montage.create(Component, { return this._currentDocument; }, set : function(value) { - // TODO: WRONG! Fails when going from design to code view - if (value === this._currentDocument || value.getProperty("currentView") !== "design") { - console.log("Stage - current document not set since the same value of " + this._currentDocument + " and value " + value); + if (value === this._currentDocument) { return; } - if(!this._currentDocument) { + if(!this._currentDocument && value.currentView === "design") { this.showRulers(); this.hideCanvas(false); } this._currentDocument = value; - if(this._currentDocument.currentView === "design") { - this.clearAllCanvas(); - this.initWithDocument(false); - } - if(!value) { this.hideRulers(); this.hideCanvas(true); + } else if(this._currentDocument.currentView === "design") { + this.clearAllCanvas(); + this.initWithDocument(false); } } }, -- cgit v1.2.3