From 0a769756547acb93346d8e1b4126931a78845255 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 30 May 2012 17:45:38 -0700 Subject: opening code view documents Signed-off-by: Valerio Virgillito --- js/controllers/code-editor-controller.js | 47 ++++++++++++++++------ js/controllers/document-controller.js | 67 ++++++++++---------------------- js/ninja.reel/ninja.html | 5 ++- js/ninja.reel/ninja.js | 6 ++- 4 files changed, 64 insertions(+), 61 deletions(-) diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index e7163bd8..d0b1f179 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -9,11 +9,34 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component; -var CodeEditorController = exports.CodeEditorController = Montage.create(Component, { +exports.CodeEditorController = Montage.create(Component, { hasTemplate: { value: false }, + _currentDocument: { + value : null + }, + + currentDocument : { + get : function() { + return this._currentDocument; + }, + set : function(value) { + if (value === this._currentDocument) { + return; + } + + this._currentDocument = value; + + if(!value) { + + } else if(this._currentDocument.currentView === "code") { + this.applySettings(); + } + } + }, + _codeEditor : { value:null }, @@ -213,22 +236,22 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone autoFormatSelection:{ value: function(){ - var range = this.getSelectedRange(this.application.ninja.documentController.activeDocument.model.views.code.editor); - this.application.ninja.documentController.activeDocument.model.views.code.editor.autoFormatRange(range.from, range.to); + var range = this.getSelectedRange(this.currentDocument.model.views.code.editor); + this.currentDocument.model.views.code.editor.autoFormatRange(range.from, range.to); } }, commentSelection:{ value: function(isComment){ - var range = this.getSelectedRange(this.application.ninja.documentController.activeDocument.model.views.code.editor); - this.application.ninja.documentController.activeDocument.model.views.code.editor.commentRange(isComment, range.from, range.to); + var range = this.getSelectedRange(this.currentDocument.model.views.code.editor); + this.currentDocument.model.views.code.editor.commentRange(isComment, range.from, range.to); } }, handleThemeSelection:{ value: function(){ - this.application.ninja.documentController.activeDocument.model.views.code.editor.setOption("theme", this.editorTheme); - this.application.ninja.documentController.activeDocument.model.views.code.applyTheme("cm-s-"+this.editorTheme); + this.currentDocument.model.views.code.editor.setOption("theme", this.editorTheme); + this.currentDocument.model.views.code.applyTheme("cm-s-"+this.editorTheme); } }, @@ -236,10 +259,10 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone value:function(value){ var originalFont=13,originalLineHeight=16; this._zoomFactor = value; - this.application.ninja.documentController.activeDocument.model.views.code.textViewContainer.style.fontSize = ""+((value/100)*originalFont)+"px"; - this.application.ninja.documentController.activeDocument.model.views.code.textViewContainer.style.cursor = "text"; - this.application.ninja.documentController.activeDocument.model.views.code.textViewContainer.querySelector(".CodeMirror").style.lineHeight = ""+((value/100)*originalLineHeight)+"px"; - this.application.ninja.documentController.activeDocument.model.views.code.editor.refresh();//refresh editor display for xoom + this.currentDocument.model.views.code.textViewContainer.style.fontSize = ""+((value/100)*originalFont)+"px"; + this.currentDocument.model.views.code.textViewContainer.style.cursor = "text"; + this.currentDocument.model.views.code.textViewContainer.querySelector(".CodeMirror").style.lineHeight = ""+((value/100)*originalLineHeight)+"px"; + this.currentDocument.model.views.code.editor.refresh();//refresh editor display for xoom } }, @@ -248,7 +271,7 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone //set theme this.handleThemeSelection(); //check autocomplete support - this.handleCodeCompletionSupport(this.application.ninja.documentController.activeDocument.model.file.extension); + this.handleCodeCompletionSupport(this.currentDocument.model.file.extension); //set zoom this.handleZoom(this._zoomFactor); } diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 4f122b3b..e059e7e1 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -18,6 +18,14 @@ exports.DocumentController = Montage.create(Component, { value: false }, + iframeContainer: { + value: null + }, + + codeContainer: { + value: null + }, + documents: { value: [] }, @@ -42,13 +50,15 @@ exports.DocumentController = Montage.create(Component, { this._currentDocument = value; if(!value) { - - } else { + document.getElementById("iframeContainer").style.display = "block"; + document.getElementById("codeViewContainer").style.display = "block"; + } else if(this._currentDocument.currentView === "design") { + this._currentDocument.model.currentView.show(); + } else { + document.getElementById("iframeContainer").style.display = "none"; this._currentDocument.model.currentView.show(); } - - } }, @@ -64,7 +74,13 @@ exports.DocumentController = Montage.create(Component, { this.eventManager.addEventListener("executeFileCloseAll", this, false); } }, - + + didCreate: { + value: function() { + this.iframeContainer = document.getElementById("iframeContainer"); + this.codeContainer = document.getElementById("codeViewContainer"); + } + }, //TODO: Ensure these APIs are not needed redirectRequests: { @@ -333,47 +349,6 @@ exports.DocumentController = Montage.create(Component, { } }, - onCloseFile: { - value: function(doc) { - var previousFocusedDocument; - -// this._documents.splice(this._documents.indexOf(doc), 1); - this.application.ninja.docController.removeObjects(this._documents.indexOf(doc)); - - if(this._documents.length > 0) { - previousFocusedDocument = this._documents[this._documents.length - 1]; - this.activeDocument = previousFocusedDocument; - this.switchDocuments(this.activeDocument, previousFocusedDocument, false); - } else { - this.activeDocument = null; - this.application.ninja.stage.hideRulers(); - - this.application.ninja.stage.hideCanvas(true); - } - - //TODO: Use references for those instead of calling getElementById - if(this._documents.length === 0){ - document.getElementById("iframeContainer").style.display="block"; - document.getElementById("codeViewContainer").style.display="block"; - } - - NJevent("closeDocument", doc.model.file.uri); - - //TODO: Delete object here - } - }, - - _onOpenTextDocument: { - value: function(doc) { - - // Main DIFFERENCE -- - // TODO: Implement Code View here - //document.getElementById("iframeContainer").style.display = "none"; - //this.application.ninja.codeEditorController.applySettings(); - - } - }, - switchDocuments: { value: function(currentDocument, newDocument, didCreate) { diff --git a/js/ninja.reel/ninja.html b/js/ninja.reel/ninja.html index ab4eed84..d9bebc36 100755 --- a/js/ninja.reel/ninja.html +++ b/js/ninja.reel/ninja.html @@ -345,7 +345,10 @@ }, "codeEditorController": { - "prototype": "js/controllers/code-editor-controller" + "prototype": "js/controllers/code-editor-controller", + "bindings": { + "currentDocument": {"<-": "@documentList.selectedObjects.0"} + } }, "owner": { diff --git a/js/ninja.reel/ninja.js b/js/ninja.reel/ninja.js index 987c32fd..3c60bb41 100755 --- a/js/ninja.reel/ninja.js +++ b/js/ninja.reel/ninja.js @@ -306,8 +306,10 @@ exports.Ninja = Montage.create(Component, { // TODO: Remove this when integrating the next montage this.documentList.selectedObjects = [doc]; - // TODO: Bind directly to the model of the document in components instead of this property - this.currentSelectedContainer = doc.model.documentRoot; + if(doc.currentView === "design") { + // TODO: Bind directly to the model of the document in components instead of this property + this.currentSelectedContainer = doc.model.documentRoot; + } // if(this.currentDocument.model.documentRoot) { // this.currentSelectedContainer = this.currentDocument.model.documentRoot; -- cgit v1.2.3