From 2cc8e58f6bb9f64a7473e62aecd013fa55167231 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 21 May 2012 16:42:26 -0700 Subject: - added opening multiple code and design view documents - switching between multiple code and design view documents - Note: closing of documents, when multiple documents are open, is not yet implemented Signed-off-by: Ananya Sen --- .../layout/document-entry.reel/document-entry.js | 2 +- js/controllers/document-controller.js | 105 +++++++++++++-------- js/document/models/text.js | 4 +- js/document/views/code.js | 54 +++-------- js/stage/stage-view.reel/stage-view.js | 14 --- js/stage/stage.reel/stage.js | 44 ++++++++- 6 files changed, 124 insertions(+), 99 deletions(-) diff --git a/js/components/layout/document-entry.reel/document-entry.js b/js/components/layout/document-entry.reel/document-entry.js index 50b3624c..24c7737c 100755 --- a/js/components/layout/document-entry.reel/document-entry.js +++ b/js/components/layout/document-entry.reel/document-entry.js @@ -122,7 +122,7 @@ exports.DocumentEntry = Montage.create(Component, { this.application.ninja.documentController.closeFile(this.application.ninja.documentController._findDocumentByUUID(this._uuid)); } else { if(!this.active) { - this.application.ninja.documentController.switchDocuments(this.application.ninja.currentDocument, this.application.ninja.documentController._findDocumentByUUID(this._uuid)); + this.application.ninja.documentController.switchDocuments(this.application.ninja.documentController.activeDocument, this.application.ninja.documentController._findDocumentByUUID(this._uuid)); } } } diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 814a30e1..26c3ebaa 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -52,10 +52,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, if(!!this._activeDocument){ if(this._documents.indexOf(doc) === -1) this._documents.push(doc); this._activeDocument.isActive = true; - - if(!!this._activeDocument.editor){ - this._activeDocument.editor.focus(); - } } } }, @@ -312,10 +308,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.activeDocument.uri = fileUri; //save a new file //use the ioMediator.fileSaveAll when implemented - this.activeDocument._userDocument.name=filename; - this.activeDocument._userDocument.root=destination; - this.activeDocument._userDocument.uri=fileUri; - this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); + this.activeDocument.model.file.name=filename; + this.activeDocument.model.file.uri=fileUri; + this.activeDocument.model.save(); // } }, @@ -408,7 +403,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this._activeDocument = null; - this.application.ninja.stage.stageView.hideRulers(); + this.application.ninja.stage.hideRulers(); // document.getElementById("iframeContainer").style.display="block"; @@ -471,7 +466,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, // Show the rulers // TODO: Move this indo design view - this.application.ninja.stage.stageView.showRulers(); + this.application.ninja.stage.showRulers(); // Show the canvas this.application.ninja.stage.hideCanvas(false); @@ -489,53 +484,81 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, + + _onOpenTextDocument: { + value: function(doc) { + var currentDocument=null; + if(this.activeDocument) { + // There is a document currently opened + currentDocument = this.activeDocument; + } + + this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe + this.activeDocument = doc; + document.getElementById("iframeContainer").style.display = "none"; + this.application.ninja.codeEditorController.applySettings(); + this.switchDocuments(currentDocument, doc, true); + } + }, + switchDocuments: { value: function(currentDocument, newDocument, didCreate) { - if(currentDocument) { + if(currentDocument && currentDocument.currentView === "design") { currentDocument.serializeDocument(); - this.application.ninja.selectionController._selectionContainer = null; currentDocument.model.views.design.propertiesPanel.clear(); - currentDocument.model.views.design.hide(); } - this.application.ninja.stage.clearAllCanvas(); + if(currentDocument) { + currentDocument.model.currentView.hide(); + currentDocument.model.isActive = false; + } + if(currentDocument && newDocument && (currentDocument.model.parentContainer !== newDocument.model.parentContainer)){ + currentDocument.model.parentContainer.style["display"] = "none"; + } - if(didCreate) { - newDocument.model.views.design.iframe.style.opacity = 1; - NJevent("onOpenDocument", newDocument); - } else { - this.activeDocument = newDocument; - newDocument.model.views.design.show(); - newDocument.deserializeDocument(); - NJevent("onSwitchDocument"); + if(newDocument && newDocument.currentView === "code"){ + this.application.ninja.stage.showCodeViewBar(true); + this.application.ninja.stage.collapseAllPanels(); + this.application.ninja.stage.hideCanvas(true); + this.application.ninja.stage.hideRulers(); + + newDocument.model.views.code.editor.focus(); + + }else if(currentDocument && newDocument && newDocument.currentView === "design"){ + this.application.ninja.stage.showCodeViewBar(false); + this.application.ninja.stage.restoreAllPanels(); + this.application.ninja.stage.hideCanvas(false); + this.application.ninja.stage.showRulers(); } - } - }, + this.application.ninja.stage.clearAllCanvas(); - _onOpenTextDocument: { - value: function(doc) { - if(this.activeDocument) { + if(didCreate) { + newDocument.model.currentView.show(); + newDocument.model.parentContainer.style["display"] = "block"; + if(newDocument.currentView === "design") { + newDocument.model.views.design.iframe.style.opacity = 1; + NJevent("onOpenDocument", newDocument); + } + } + else { + this.activeDocument = newDocument; - if(this.activeDocument.currentView === "design"){ - this.activeDocument.saveAppState(); - this.activeDocument.parentContainer.style["display"] = "none"; - this.application.ninja.stage.hideCanvas(true); - this.application.ninja.stage.stageView.hideRulers(); + newDocument.model.currentView.show(); + if(currentDocument && newDocument && (currentDocument.model.parentContainer !== newDocument.model.parentContainer)){ + newDocument.model.parentContainer.style["display"] = "block"; } - this.activeDocument.container.style["display"] = "none"; + if(newDocument.currentView === "design") { + newDocument.deserializeDocument(); + NJevent("onSwitchDocument"); + }else{ + newDocument.model.isActive = true; + this.application.ninja.codeEditorController.applySettings();//should be called after activeDocument is updated + } } - - this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe - this.activeDocument = doc; - //hide the iframe when switching to code view - document.getElementById("iframeContainer").style.display = "none"; - doc.model.views.code.showCodeViewBar(true); - this.application.ninja.codeEditorController.applySettings(); - doc.model.views.code.collapseAllPanels(); } }, diff --git a/js/document/models/text.js b/js/document/models/text.js index fe02953c..d1252b7d 100755 --- a/js/document/models/text.js +++ b/js/document/models/text.js @@ -60,8 +60,8 @@ exports.TextDocumentModel = Montage.create(BaseDocumentModel, { } // this.parentContainer.removeChild(this.views.code.textViewContainer); - this.views.code.restoreAllPanels(); - this.views.code.showCodeViewBar(false); + this.application.ninja.stage.showCodeViewBar(false); + this.application.ninja.stage.restoreAllPanels(); this.views.code = null; // diff --git a/js/document/views/code.js b/js/document/views/code.js index 711479a8..66d1c702 100755 --- a/js/document/views/code.js +++ b/js/document/views/code.js @@ -140,56 +140,30 @@ var CodeDocumentView = exports.CodeDocumentView = Montage.create(BaseDocumentVie }, //////////////////////////////////////////////////////////////////// // - - showRulers:{ - value:function(){ - this.application.ninja.rulerTop.style.display = "block"; - this.application.ninja.rulerLeft.style.display = "block"; - } - }, - hideRulers:{ - value:function(){ - this.application.ninja.rulerTop.style.display = "none"; - this.application.ninja.rulerLeft.style.display = "none"; - } - }, - showCodeViewBar:{ - value:function(isCodeView){ - if(isCodeView === true) { - this.application.ninja.editorViewOptions.element.style.display = "block"; - this.application.ninja.documentBar.element.style.display = "none"; - } else { - this.application.ninja.documentBar.element.style.display = "block"; - this.application.ninja.editorViewOptions.element.style.display = "none"; - } - } - }, - - collapseAllPanels:{ - value:function(){ - this.application.ninja.panelSplitter.collapse(); - this.application.ninja.timelineSplitter.collapse(); - this.application.ninja.toolsSplitter.collapse(); - this.application.ninja.optionsSplitter.collapse(); + show: { + value: function (callback) { + this.textViewContainer.style.display = "block"; + // + if (callback) callback(); } }, - restoreAllPanels:{ - value:function(){ - this.application.ninja.panelSplitter.restore(); - this.application.ninja.timelineSplitter.restore(); - this.application.ninja.toolsSplitter.restore(); - this.application.ninja.optionsSplitter.restore(); + //////////////////////////////////////////////////////////////////// + // + hide: { + value: function (callback) { + this.textViewContainer.style.display = "none"; + // + if (callback) callback(); } }, - + //////////////////////////////////////////////////////////////////// + // applyTheme:{ value:function(themeClass){ //Todo: change for bucket structure of documents this.textViewContainer.className = "codeViewContainer "+themeClass; } } - - //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// }); diff --git a/js/stage/stage-view.reel/stage-view.js b/js/stage/stage-view.reel/stage-view.js index 139fa032..2c129ee2 100755 --- a/js/stage/stage-view.reel/stage-view.js +++ b/js/stage/stage-view.reel/stage-view.js @@ -58,19 +58,5 @@ exports.StageView = Montage.create(Component, { NJevent("switchDocument"); } - }, - - showRulers:{ - value:function(){ - this.application.ninja.rulerTop.style.display = "block"; - this.application.ninja.rulerLeft.style.display = "block"; - } - }, - hideRulers:{ - value:function(){ - this.application.ninja.rulerTop.style.display = "none"; - this.application.ninja.rulerLeft.style.display = "none"; - } } - }); \ No newline at end of file diff --git a/js/stage/stage.reel/stage.js b/js/stage/stage.reel/stage.js index 73d3aaf4..f768f03a 100755 --- a/js/stage/stage.reel/stage.js +++ b/js/stage/stage.reel/stage.js @@ -1012,5 +1012,47 @@ exports.Stage = Montage.create(Component, { this._iframeContainer.scrollTop = this.application.ninja.documentController.activeDocument.savedTopScroll; this._scrollTop = this.application.ninja.documentController.activeDocument.savedTopScroll; } - } + }, + + showRulers:{ + value:function(){ + this.application.ninja.rulerTop.style.display = "block"; + this.application.ninja.rulerLeft.style.display = "block"; + } + }, + hideRulers:{ + value:function(){ + this.application.ninja.rulerTop.style.display = "none"; + this.application.ninja.rulerLeft.style.display = "none"; + } + }, + showCodeViewBar:{ + value:function(isCodeView){ + if(isCodeView === true) { + this.application.ninja.editorViewOptions.element.style.display = "block"; + this.application.ninja.documentBar.element.style.display = "none"; + } else { + this.application.ninja.documentBar.element.style.display = "block"; + this.application.ninja.editorViewOptions.element.style.display = "none"; + } + } + }, + + collapseAllPanels:{ + value:function(){ + this.application.ninja.panelSplitter.collapse(); + this.application.ninja.timelineSplitter.collapse(); + this.application.ninja.toolsSplitter.collapse(); + this.application.ninja.optionsSplitter.collapse(); + } + }, + restoreAllPanels:{ + value:function(){ + this.application.ninja.panelSplitter.restore(); + this.application.ninja.timelineSplitter.restore(); + this.application.ninja.toolsSplitter.restore(); + this.application.ninja.optionsSplitter.restore(); + } + } + }); \ No newline at end of file -- cgit v1.2.3