From 553fce7721cacfd13b6013fdcdd0243c90083b5e Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Wed, 1 Feb 2012 11:59:11 -0800 Subject: fixed reference to coreioapi cleaning up opening code view tabs Signed-off-by: Ananya Sen --- .../layout/document-entry.reel/document-entry.js | 6 +- .../ui/FilePicker/file-picker-controller.js | 9 ++- js/io/document/document-controller.js | 46 +++++++------- js/io/system/coreioapi.js | 3 - js/io/utils/file-utils.js | 4 +- js/lib/NJUtils.js | 2 + js/stage/stage-view.reel/stage-view.js | 72 +++++++++++++++++++--- 7 files changed, 97 insertions(+), 45 deletions(-) diff --git a/js/components/layout/document-entry.reel/document-entry.js b/js/components/layout/document-entry.reel/document-entry.js index 6f265c91..1431e76f 100755 --- a/js/components/layout/document-entry.reel/document-entry.js +++ b/js/components/layout/document-entry.reel/document-entry.js @@ -81,7 +81,7 @@ exports.DocumentEntry = Montage.create(Component, { prepareForDraw: { enumerable: false, value: function() { - //this.element.addEventListener("click", this, false); + this.element.addEventListener("click", this, false); } }, @@ -98,10 +98,10 @@ exports.DocumentEntry = Montage.create(Component, { handleClick: { value: function(event) { if(event._event.target.nodeName === "IMG") { - documentManagerModule.DocumentManager.closeDocument(this._uuid); + this.application.ninja.documentController.closeDocument(this._uuid); } else { if(!this._document.isActive) { - documentManagerModule.DocumentManager.switchDocument(this._uuid); + this.application.ninja.stage.stageView.switchCodeView(this.application.ninja.documentController._findDocumentByUUID(this._uuid)); } } } diff --git a/js/components/ui/FilePicker/file-picker-controller.js b/js/components/ui/FilePicker/file-picker-controller.js index 635da3a2..e71d1460 100755 --- a/js/components/ui/FilePicker/file-picker-controller.js +++ b/js/components/ui/FilePicker/file-picker-controller.js @@ -8,7 +8,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot var Montage = require("montage/core/core").Montage, pickerNavigatorReel = require("js/components/ui/FilePicker/pickerNavigator.reel").PickerNavigator, filePickerModelModule = require("js/components/ui/FilePicker/file-picker-model"), - fileSystem = require("js/io/system/coreioapi").CoreIoApi, Popup = require("montage/ui/popup/popup.reel").Popup; //singleton with functions to create a new file picker instance and utilities to format or filter the model data @@ -101,7 +100,7 @@ var FilePickerController = exports.FilePickerController = Montage.create(require var aModel = filePickerModelModule.FilePickerModel.create(); var topLevelDirectories = null; - var driveData = fileSystem.getDirectoryContents({uri:"", recursive:false, returnType:"all"}); + var driveData = this.application.ninja.coreIoApi.getDirectoryContents({uri:"", recursive:false, returnType:"all"}); if(driveData.success){ topLevelDirectories = (JSON.parse(driveData.content)).children; }else{ @@ -244,7 +243,7 @@ var FilePickerController = exports.FilePickerController = Montage.create(require || !this._directoryContentCache[folderUri].children){ //get data using IO api try{ - var iodata = fileSystem.getDirectoryContents({uri:folderUri, recursive:false, returnType:"all"}); + var iodata = this.application.ninja.coreIoApi.getDirectoryContents({uri:folderUri, recursive:false, returnType:"all"}); //console.log("IO:getDirectoryContents:Response:\n"+"uri="+folderUri+"\n status="+iodata.status+"\n content= "+iodata.content); if(iodata.success && (iodata.status === 200) && (iodata.content !== null)){ folderContent = JSON.parse(iodata.content); @@ -456,7 +455,7 @@ var FilePickerController = exports.FilePickerController = Montage.create(require //check for directory staleness.... if stale query filesystem if((new Date()).getTime() > (this._directoryContentCache[folderUri].queriedTimeStamp + this.cacheStaleTime)){ try{ - var ifModifiedResponse = fileSystem.isDirectoryModified({uri:folderUri, recursive:false, returnType:"all"}, this._directoryContentCache[folderUri].queriedTimeStamp); + var ifModifiedResponse = this.application.ninja.coreIoApi.isDirectoryModified({uri:folderUri, recursive:false, returnType:"all"}, this._directoryContentCache[folderUri].queriedTimeStamp); //console.log("ifModifiedResponse"); //console.log(ifModifiedResponse); }catch(e){ @@ -468,7 +467,7 @@ var FilePickerController = exports.FilePickerController = Montage.create(require wasStale = true; //uri has changed. so update cache try{ - var iodata = fileSystem.getDirectoryContents({uri:folderUri, recursive:false, returnType:"all"}); + var iodata = this.application.ninja.coreIoApi.getDirectoryContents({uri:folderUri, recursive:false, returnType:"all"}); //console.log("IO:getDirectoryContents:Response:\n"+"uri="+folderUri+"\n status="+iodata.status+"\n content= "+iodata.content); if(iodata.success && (iodata.status === 200) && (iodata.content !== null)){ folderContent = JSON.parse(iodata.content); diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index 7cf7f409..bba7e0e7 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -15,10 +15,9 @@ 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, Uuid = require("montage/core/uuid").Uuid, - fileSystem = require("js/io/system/coreioapi").CoreIoApi; - -var HTMLDocument = require("js/io/document/html-document").HTMLDocument; -var TextDocument = require("js/io/document/text-document").TextDocument; + nj= require("js/lib/NJUtils.js").NJUtils, + HTMLDocument = require("js/io/document/html-document").HTMLDocument, + TextDocument = require("js/io/document/text-document").TextDocument; var DocumentController = exports.DocumentController = Montage.create(Component, { hasTemplate: { @@ -96,7 +95,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, openFileWithURI: { value: function(uriArrayObj) { - var uri = "", fileContent = "", response=null; + var uri = "", fileContent = "", response=null, filename="", fileType="js"; if(!!uriArrayObj && !!uriArrayObj.uri && (uriArrayObj.uri.length > 0)){ uri = uriArrayObj.uri[0]; } @@ -104,18 +103,23 @@ var DocumentController = exports.DocumentController = Montage.create(Component, // Get file from Jose Code with a callback to here if(!!uri){ - response = fileSystem.openFile({"uri":uri}); + response = this.application.ninja.coreIoApi.openFile({"uri":uri}); if((response.success === true) && ((response.status === 200) || (response.status === 304))){ fileContent = response.content; } - console.log("$$$ "+uri+"\n content = \n\n\n"+ fileContent+"\n\n\n"); - this.openDocument({"type": "js", "name": "tmp.js", "source": fileContent}); + //console.log("$$$ "+uri+"\n content = \n\n\n"+ fileContent+"\n\n\n"); + filename = nj.getFileNameFromPath(uri); + if(uri.indexOf('.') != -1){ + fileType = uri.substr(uri.lastIndexOf('.') + 1); + } + this.openDocument({"type": ""+fileType, "name": ""+filename, "source": fileContent}); } } }, + openProjectWithURI: { value: function(uri) { console.log("URI is: ", uri); @@ -211,7 +215,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this._documents.splice(this._findIndexByUUID(id), 1); if(this.activeDocument.uuid === id && this._documents.length > 0) { - this.switchDocument(this._documents[0].uuid) + this.switchDocument(this._documents[0].uuid); } } }, @@ -254,11 +258,11 @@ var DocumentController = exports.DocumentController = Montage.create(Component, lineNumbers: true, mode: "htmlmixed", onCursorActivity: function() { - DocumentManager._codeEditor.editor.setLineClass(DocumentManager._codeEditor.hline, null); - DocumentManager._codeEditor.hline = DocumentManager._codeEditor.editor.setLineClass(DocumentManager._codeEditor.editor.getCursor().line, "activeline"); + DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.hline, null); + DocumentController._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.editor.getCursor().line, "activeline"); } }); - this._codeEditor.hline = DocumentManager._codeEditor.editor.setLineClass(0, "activeline"); + this._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(0, "activeline"); } } }, @@ -284,9 +288,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, _onOpenTextDocument: { value: function(doc) { - DocumentManager._hideCurrentDocument(); + this._hideCurrentDocument(); this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe - DocumentManager.activeDocument = doc; + this.activeDocument = doc; var type; @@ -299,15 +303,15 @@ var DocumentController = exports.DocumentController = Montage.create(Component, break; } - DocumentManager._codeEditor.editor = CodeMirror.fromTextArea(doc.textArea, { + DocumentController._codeEditor.editor = CodeMirror.fromTextArea(doc.textArea, { lineNumbers: true, mode: type, onCursorActivity: function() { - DocumentManager._codeEditor.editor.setLineClass(DocumentManager._codeEditor.hline, null); - DocumentManager._codeEditor.hline = DocumentManager._codeEditor.editor.setLineClass(DocumentManager._codeEditor.editor.getCursor().line, "activeline"); + DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.hline, null); + DocumentController._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.editor.getCursor().line, "activeline"); } }); - DocumentManager._codeEditor.hline = DocumentManager._codeEditor.editor.setLineClass(0, "activeline"); + DocumentController._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(0, "activeline"); } }, @@ -349,7 +353,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function() { if(this.activeDocument) { this.activeDocument.container.style["display"] = "none"; - if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") this.application.ninja.stage.toggleCanvas(); + //if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") this.application.ninja.stage.toggleCanvas(); } } }, @@ -358,7 +362,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function() { if(this.activeDocument) { this.activeDocument.container.style["display"] = "block"; - if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") this.application.ninja.stage.toggleCanvas(); + //if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") this.application.ninja.stage.toggleCanvas(); } } }, @@ -415,7 +419,7 @@ _createTextAreaElement: { textArea.id = "code"; textArea.name = "code"; - codeMirrorDiv.appendChild(textArea); + //codeMirrorDiv.appendChild(textArea); // if(!this._textHolder) this._textHolder = document.getElementById("codeViewContainer"); // this._textHolder.appendChild(codeMirrorDiv); diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index 5deeae73..43812b3c 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -134,9 +134,6 @@ exports.CoreIoApi = Montage.create(Component, { directoryServiceURL: { enumerable: false, get: function() { - if(!this.rootUrl){ - this.rootUrl = 'http://localhost:16380'; - } return String(this.rootUrl+this._directoryServiceURL); }, set: function(value) { diff --git a/js/io/utils/file-utils.js b/js/io/utils/file-utils.js index 0afdffc6..0a4d9687 100644 --- a/js/io/utils/file-utils.js +++ b/js/io/utils/file-utils.js @@ -4,8 +4,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -var fileSystem = require("js/io/system/coreioapi").CoreIoApi; - var FileUtils = exports.FileUtils = Object.create(Object.prototype, { /*** @@ -61,7 +59,7 @@ var FileUtils = exports.FileUtils = Object.create(Object.prototype, { uri = ""+folderUri+fileUri; - response = fileSystem.fileExists({"uri":uri}); + response = this.application.ninja.coreIoApi.fileExists({"uri":uri}); if(!!response && response.success && (response.status === 204)){ status = true; }else if(!!response && response.success && (response.status === 404)){ diff --git a/js/lib/NJUtils.js b/js/lib/NJUtils.js index d6548871..56c74b3b 100755 --- a/js/lib/NJUtils.js +++ b/js/lib/NJUtils.js @@ -206,6 +206,8 @@ exports.NJUtils = Object.create(Object.prototype, { ///// Return the last part of a path (e.g. filename) getFileNameFromPath : { value: function(path) { + path = path.replace(/[/\\]$/g,""); + path = path.replace(/\\/g,"/"); return path.substr(path.lastIndexOf('/') + 1); } } diff --git a/js/stage/stage-view.reel/stage-view.js b/js/stage/stage-view.reel/stage-view.js index 63fe88ba..727c16eb 100755 --- a/js/stage/stage-view.reel/stage-view.js +++ b/js/stage/stage-view.reel/stage-view.js @@ -49,28 +49,80 @@ exports.StageView = Montage.create(Component, { // Temporary function to create a Codemirror text view createTextView: { value: function(doc) { -// DocumentManager._hideCurrentDocument(); + this.application.ninja.documentController._hideCurrentDocument(); this.application.ninja.currentDocument.container.parentNode.style["display"] = "none"; -// stageManagerModule.stageManager._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe -// DocumentManager.activeDocument = doc; + this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe + this.application.ninja.documentController.activeDocument = doc; this.element.appendChild(doc.textArea); + var type; + + switch(doc.documentType) { + case "css" : + type = "css"; + break; + case "js" : + type = "javascript"; + break; + } + + //remove any previous Codemirror div + var codemirrorDiv = this.element.querySelector(".CodeMirror"); + if(!!codemirrorDiv){ + codemirrorDiv.parentNode.removeChild(codemirrorDiv); + } var codeM = CodeMirror.fromTextArea(doc.textArea, { lineNumbers: true, - mode: "javascript" -// onCursorActivity: function() { -// DocumentManager._codeEditor.editor.setLineClass(DocumentManager._codeEditor.hline, null); -// DocumentManager._codeEditor.hline = DocumentManager._codeEditor.editor.setLineClass(DocumentManager._codeEditor.editor.getCursor().line, "activeline"); -// } + mode: type, + onCursorActivity: function() { + this.application.ninja.documentController._codeEditor.editor.setLineClass(this.application.ninja.documentController._codeEditor.hline, null); + this.application.ninja.documentController._codeEditor.hline = this.application.ninja.documentController._codeEditor.editor.setLineClass(this.application.ninja.documentController._codeEditor.editor.getCursor().line, "activeline"); + } }); -// DocumentManager._codeEditor.hline = DocumentManager._codeEditor.editor.setLineClass(0, "activeline"); + //this.application.ninja.documentController._codeEditor.hline = this.application.ninja.documentController._codeEditor.editor.setLineClass(0, "activeline"); + + this.application.ninja.stage.hideCanvas(true); + + } + }, + + switchCodeView:{ + value: function(doc){ + + this.application.ninja.documentController._hideCurrentDocument(); + + //remove any previous Codemirror div + var codemirrorDiv = this.element.querySelector(".CodeMirror"); + if(!!codemirrorDiv){ + codemirrorDiv.parentNode.removeChild(codemirrorDiv); + } + + var type; + + switch(doc.documentType) { + case "css" : + type = "css"; + break; + case "js" : + type = "javascript"; + break; + } + + var codeM = CodeMirror.fromTextArea(doc.textArea, { + lineNumbers: true, + mode: type, + onCursorActivity: function() { + this.application.ninja.documentController._codeEditor.editor.setLineClass(this.application.ninja.documentController._codeEditor.hline, null); + this.application.ninja.documentController._codeEditor.hline = this.application.ninja.documentController._codeEditor.editor.setLineClass(this.application.ninja.documentController._codeEditor.editor.getCursor().line, "activeline"); + } + }); - this.application.ninja.stage.hideCanvas(true); + //this.application.ninja.documentController._codeEditor.hline = this.application.ninja.documentController._codeEditor.editor.setLineClass(0, "activeline"); } } -- cgit v1.2.3