From 3a754133dbc138390503341fd2e9beba3e43aa4b Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Fri, 27 Jan 2012 12:05:17 -0800 Subject: Merged old FileIO --- js/io/document/document-controller.js | 166 +++++++++++++++++++++++++++------- 1 file changed, 133 insertions(+), 33 deletions(-) mode change 100644 => 100755 js/io/document/document-controller.js (limited to 'js/io/document/document-controller.js') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js old mode 100644 new mode 100755 index 99177de0..6f363bc7 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -12,26 +12,35 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot @requires js/document/text-document */ -// TODO : Fix deps from Montage V4 Archi - var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component, - Uuid = require("montage/core/uuid").Uuid; + Uuid = require("montage/core/uuid").Uuid, + fileSystem = require("js/io/system/filesystem").FileSystem; var HTMLDocument = require("js/io/document/html-document").HTMLDocument; var TextDocument = require("js/io/document/text-document").TextDocument; var DocumentController = exports.DocumentController = Montage.create(Component, { - hasTemplate: { value: false }, + hasTemplate: { + value: false + }, + + _documents: { + value: [] + }, - _documents: { value: [] }, - _documentsHash: { value: {} }, _activeDocument: { value: null }, _iframeCounter: { value: 1, enumerable: false }, _iframeHolder: { value: null, enumerable: false }, _textHolder: { value: null, enumerable: false }, _codeMirrorCounter: {value: 1, enumerable: false}, + tmpSourceForTesting: { + value: "function CodeMirror(place, givenOptions) {" + + "// Determine effective options based on given values and defaults." + + "var options = {}, defaults = CodeMirror.defaults; }" + }, + _codeEditor: { value: { "editor": { @@ -50,33 +59,21 @@ var DocumentController = exports.DocumentController = Montage.create(Component, return this._activeDocument; }, set: function(doc) { - if(this._activeDocument) { - if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") { - // TODO selection should use the document own selectionModel - //this._activeDocument.selectionModel = selectionManagerModule.selectionManager._selectedItems; - } - - this._activeDocument.isActive = false; - } + if(this._activeDocument) this._activeDocument.isActive = false; - if(this._documents.indexOf(doc) === -1) { - //this._documentsHash[doc.uuid] = this._documents.push(doc) - 1; - this._documents.push(doc); - } + if(this._documents.indexOf(doc) === -1) this._documents.push(doc); this._activeDocument = doc; this._activeDocument.isActive = true; - if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") { - // TODO selection should use the document own selectionModel - //selectionManagerModule.selectionManager._selectedItems = this._activeDocument.selectionModel; - } } }, deserializedFromTemplate: { value: function() { this.eventManager.addEventListener("appLoaded", this, false); + + this.eventManager.addEventListener("executeFileOpen", this, false); } }, @@ -86,28 +83,126 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, + handleExecuteFileOpen: { + value: function(event) { + var pickerSettings = event._event.settings || {}; + pickerSettings.callback = this.openFileWithURI; + pickerSettings.callbackScope = this; + this.application.ninja.filePickerController.showFilePicker(pickerSettings); + + //this.openDocument({"type": "js", "source": this.tmpSourceForTesting}); + } + }, + + openFileWithURI: { + value: function(uriArrayObj) { + var uri = "", fileContent = "", response=null; + if(!!uriArrayObj && !!uriArrayObj.uri && (uriArrayObj.uri.length > 0)){ + uri = uriArrayObj.uri[0]; + } + console.log("URI is: ", uri); + + // Get file from Jose Code with a callback to here + if(!!uri){ + response = fileSystem.shellApiHandler.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}); + } + + } + }, + + openProjectWithURI: { + value: function(uri) { + console.log("URI is: ", uri); + + // Get project from Jose Code with a callback to here + } + }, + /** Open a Document **/ openDocument: { value: function(doc) { - var d; + var newDoc; if(!doc) return false; - try { + // try { if (doc.type === 'html' || doc.type === 'htm') { - d = Montage.create(HTMLDocument); - d.initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument); + newDoc = Montage.create(HTMLDocument); + newDoc.initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument); } else { - d = Montage.create(TextDocument); - d.initialize(doc, Uuid.generate(), this._createTextAreaElement(), this._onOpenTextDocument); + newDoc = Montage.create(TextDocument, { + "source": { value: doc.source } + }); + newDoc.initialize(doc, Uuid.generate(), this._createTextAreaElement()); + + // Tmp this will be filled with the real content + newDoc.textArea.innerHTML = doc.source; //this.tmpSourceForTesting; + + this.textDocumentOpened(newDoc); + } - } catch (err) { - console.log("Could not open Document ", err); - } + // } catch (err) { + // console.log("Could not open Document ", err); + // } } }, + // Document has been loaded into the Iframe. Dispatch the event. + // Event Detail: Contains the current ActiveDocument + _onOpenDocument: { + value: function(doc){ + + DocumentController.activeDocument = doc; + + NJevent("onOpenDocument", doc); + + } + }, + + textDocumentOpened: { + value: function(doc) { + + this.activeDocument = doc; + + this.application.ninja.stage.stageView.createTextView(doc); + + /* + DocumentManager._hideCurrentDocument(); + stageManagerModule.stageManager._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe + DocumentManager.activeDocument = doc; + + var type; + + switch(doc.documentType) { + case "css" : + type = "css"; + break; + case "js" : + type = "javascript"; + break; + } + + DocumentManager._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"); + } + }); + DocumentManager._codeEditor.hline = DocumentManager._codeEditor.editor.setLineClass(0, "activeline"); + */ + + } + }, + closeDocument: { value: function(id) { var doc = this._findDocumentByUUID(id); @@ -168,6 +263,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, + // Document has been loaded into the Iframe. Dispatch the event. // Event Detail: Contains the current ActiveDocument _onOpenDocument: { @@ -185,6 +281,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, + _onOpenTextDocument: { value: function(doc) { DocumentManager._hideCurrentDocument(); @@ -306,7 +403,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, - _createTextAreaElement: { + /** + * Creates a text area which will contain the content of the opened text document. + */ +_createTextAreaElement: { value: function() { var codeMirrorDiv = document.createElement("div"); codeMirrorDiv.id = "codeMirror_" + (this._codeMirrorCounter++); @@ -323,4 +423,4 @@ var DocumentController = exports.DocumentController = Montage.create(Component, return codeMirrorDiv; } } -}); +}); \ No newline at end of file -- cgit v1.2.3 From 8c78a98410116f7a0fc03a75f40ac16027b8fc51 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 30 Jan 2012 14:32:29 -0800 Subject: moved fix to open js and css files in code view , from gerrit to github Signed-off-by: Ananya Sen --- js/io/document/document-controller.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js/io/document/document-controller.js') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index 6f363bc7..53575a21 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -417,10 +417,10 @@ _createTextAreaElement: { codeMirrorDiv.appendChild(textArea); - if(!this._textHolder) this._textHolder = document.getElementById("codeViewContainer"); - this._textHolder.appendChild(codeMirrorDiv); +// if(!this._textHolder) this._textHolder = document.getElementById("codeViewContainer"); +// this._textHolder.appendChild(codeMirrorDiv); - return codeMirrorDiv; + return textArea; } } }); \ No newline at end of file -- cgit v1.2.3 From 1fd16ce7052853719ec27527157f38b2fc87b077 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 30 Jan 2012 14:45:22 -0800 Subject: calling coreioapi.js directly since filesystem.js will be deleted Signed-off-by: Ananya Sen --- js/io/document/document-controller.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/io/document/document-controller.js') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index 53575a21..7cf7f409 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -15,7 +15,7 @@ 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/filesystem").FileSystem; + 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; @@ -104,7 +104,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, // Get file from Jose Code with a callback to here if(!!uri){ - response = fileSystem.shellApiHandler.openFile({"uri":uri}); + response = fileSystem.openFile({"uri":uri}); if((response.success === true) && ((response.status === 200) || (response.status === 304))){ fileContent = response.content; } -- cgit v1.2.3 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 --- js/io/document/document-controller.js | 46 +++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'js/io/document/document-controller.js') 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); -- cgit v1.2.3 From 8504b61aefb25fdab931f02c4568916d2bf8345c Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 2 Feb 2012 00:52:44 -0800 Subject: changes to open multiple code view tabs and switch between the code views, added nj-skinned css class for the buttons in file picker, new file dialog and save as dialog Signed-off-by: Ananya Sen --- js/io/document/document-controller.js | 36 +++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'js/io/document/document-controller.js') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index bba7e0e7..7fe94c12 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -99,9 +99,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component, if(!!uriArrayObj && !!uriArrayObj.uri && (uriArrayObj.uri.length > 0)){ uri = uriArrayObj.uri[0]; } - console.log("URI is: ", uri); + //console.log("URI is: ", uri); - // Get file from Jose Code with a callback to here if(!!uri){ response = this.application.ninja.coreIoApi.openFile({"uri":uri}); if((response.success === true) && ((response.status === 200) || (response.status === 304))){ @@ -113,7 +112,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, if(uri.indexOf('.') != -1){ fileType = uri.substr(uri.lastIndexOf('.') + 1); } - this.openDocument({"type": ""+fileType, "name": ""+filename, "source": fileContent}); + this.openDocument({"type": ""+fileType, "name": ""+filename, "source": fileContent, "externalUri": uri}); } } @@ -124,7 +123,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function(uri) { console.log("URI is: ", uri); - // Get project from Jose Code with a callback to here } }, @@ -158,18 +156,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, - // Document has been loaded into the Iframe. Dispatch the event. - // Event Detail: Contains the current ActiveDocument - _onOpenDocument: { - value: function(doc){ - - DocumentController.activeDocument = doc; - - NJevent("onOpenDocument", doc); - - } - }, - textDocumentOpened: { value: function(doc) { @@ -209,13 +195,31 @@ var DocumentController = exports.DocumentController = Montage.create(Component, closeDocument: { value: function(id) { + + //if file dirty then save + var doc = this._findDocumentByUUID(id); this._removeDocumentView(doc.container); this._documents.splice(this._findIndexByUUID(id), 1); if(this.activeDocument.uuid === id && this._documents.length > 0) { + + var closeDocumentIndex = this._findIndexByUUID(id); + var nextDocumentIndex = -1 ; + if((this._documents.length > 0) && (closeDocumentIndex === 0)){ + nextDocumentIndex = 1; + }else if((this._documents.length > 0) && (closeDocumentIndex > 0)){ + nextDocumentIndex = closeDocumentIndex - 1; + } + + //remove the codemirror div if this is for a code view + /////test + + ////end- test + this.switchDocument(this._documents[0].uuid); + } } }, -- cgit v1.2.3 From 87e247e74040b5e80ff40003d233d5317881102a Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 2 Feb 2012 03:30:54 -0800 Subject: fixed code view container, and switching code view Signed-off-by: Ananya Sen --- js/io/document/document-controller.js | 54 ++++++++++++----------------------- 1 file changed, 18 insertions(+), 36 deletions(-) (limited to 'js/io/document/document-controller.js') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index 7fe94c12..9be40ccc 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -112,7 +112,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, if(uri.indexOf('.') != -1){ fileType = uri.substr(uri.lastIndexOf('.') + 1); } - this.openDocument({"type": ""+fileType, "name": ""+filename, "source": fileContent, "externalUri": uri}); + this.openDocument({"type": ""+fileType, "name": ""+filename, "source": fileContent, "uri": uri}); } } @@ -141,7 +141,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, newDoc = Montage.create(TextDocument, { "source": { value: doc.source } }); - newDoc.initialize(doc, Uuid.generate(), this._createTextAreaElement()); + var docUuid = Uuid.generate(); + var textArea = this.application.ninja.stage.stageView.createTextAreaElement(docUuid); + newDoc.initialize(doc, docUuid, textArea, textArea.parentNode); // Tmp this will be filled with the real content newDoc.textArea.innerHTML = doc.source; //this.tmpSourceForTesting; @@ -254,19 +256,20 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } else { this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe - var codeview = this._createTextAreaElement(); - this._textHolder.style.display = "block"; - codeview.firstChild.innerHTML = this.activeDocument.iframe.contentWindow.document.body.parentNode.innerHTML; - - this._codeEditor.editor = CodeMirror.fromTextArea(codeview.firstChild, { - lineNumbers: true, - mode: "htmlmixed", - onCursorActivity: function() { - DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.hline, null); - DocumentController._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.editor.getCursor().line, "activeline"); - } - }); - this._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(0, "activeline"); + + var codeview = this.activeDocument.container; + //this._textHolder.style.display = "block"; + //codeview.firstChild.innerHTML = this.activeDocument.iframe.contentWindow.document.body.parentNode.innerHTML; + +// this._codeEditor.editor = CodeMirror.fromTextArea(codeview.firstChild, { +// lineNumbers: true, +// mode: "htmlmixed", +// onCursorActivity: function() { +// DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.hline, null); +// DocumentController._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.editor.getCursor().line, "activeline"); +// } +// }); +// this._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(0, "activeline"); } } }, @@ -409,26 +412,5 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function() { return "userDocument_" + (this._iframeCounter++); } - }, - - /** - * Creates a text area which will contain the content of the opened text document. - */ -_createTextAreaElement: { - value: function() { - var codeMirrorDiv = document.createElement("div"); - codeMirrorDiv.id = "codeMirror_" + (this._codeMirrorCounter++); - - var textArea = document.createElement("textarea"); - textArea.id = "code"; - textArea.name = "code"; - - //codeMirrorDiv.appendChild(textArea); - -// if(!this._textHolder) this._textHolder = document.getElementById("codeViewContainer"); -// this._textHolder.appendChild(codeMirrorDiv); - - return textArea; - } } }); \ No newline at end of file -- cgit v1.2.3 From 0e595c4e11ce9b44eff157de8616ed15fcd5d6fc Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 2 Feb 2012 12:37:29 -0800 Subject: refactoring some file names and locations, change made to maintain only one codemirror div. Signed-off-by: Ananya Sen --- js/io/document/document-controller.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'js/io/document/document-controller.js') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index 9be40ccc..8ce43dcc 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -244,6 +244,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, switchViews: { value: function() { + + //save file if dirty + this.application.ninja.stage.saveScroll(); this._hideCurrentDocument(); -- cgit v1.2.3 From 6890662caba94598675679f40dbb725301c93e98 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 2 Feb 2012 17:45:22 -0800 Subject: integrated new file dialog with the template descriptor.json and document-controller.js Signed-off-by: Ananya Sen --- js/io/document/document-controller.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'js/io/document/document-controller.js') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index 8ce43dcc..dd62b40b 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -71,8 +71,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component, deserializedFromTemplate: { value: function() { this.eventManager.addEventListener("appLoaded", this, false); - this.eventManager.addEventListener("executeFileOpen", this, false); + this.eventManager.addEventListener("executeNewFile", this, false); } }, @@ -93,6 +93,21 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, + handleExecuteNewFile: { + value: function(event) { + var newFileSettings = event._event.settings || {}; + newFileSettings.callback = this.createNewFile; + newFileSettings.callbackScope = this; + this.application.ninja.newFileController.showNewFileDialog(newFileSettings); + } + }, + + createNewFile:{ + value:function(newFileObj){ + //console.log(newFileObj); + } + }, + openFileWithURI: { value: function(uriArrayObj) { var uri = "", fileContent = "", response=null, filename="", fileType="js"; -- cgit v1.2.3 From 79b0173eeca079dec42ff1480182656dbe3af44f Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 3 Feb 2012 09:49:23 -0800 Subject: removed usage of NJUtils.js as it is being deleted. Signed-off-by: Ananya Sen --- js/io/document/document-controller.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'js/io/document/document-controller.js') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index dd62b40b..7cc0eeeb 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -15,7 +15,6 @@ 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, - nj= require("js/lib/NJUtils.js").NJUtils, HTMLDocument = require("js/io/document/html-document").HTMLDocument, TextDocument = require("js/io/document/text-document").TextDocument; @@ -123,7 +122,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } //console.log("$$$ "+uri+"\n content = \n\n\n"+ fileContent+"\n\n\n"); - filename = nj.getFileNameFromPath(uri); + filename = this.getFileNameFromPath(uri); if(uri.indexOf('.') != -1){ fileType = uri.substr(uri.lastIndexOf('.') + 1); } @@ -430,5 +429,14 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function() { return "userDocument_" + (this._iframeCounter++); } - } + }, + + ///// 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); + } + } }); \ No newline at end of file -- cgit v1.2.3 From 1daf146c849a0a8dbd2b61b14218c9a39bdee3a7 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 3 Feb 2012 17:22:48 -0800 Subject: added editor tab save while switching code view tabs, integrated new file dialog with io mediator to open the new file in a new tab Signed-off-by: Ananya Sen --- js/io/document/document-controller.js | 41 ++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'js/io/document/document-controller.js') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index 7cc0eeeb..b900dee4 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -103,7 +103,32 @@ var DocumentController = exports.DocumentController = Montage.create(Component, createNewFile:{ value:function(newFileObj){ - //console.log(newFileObj); + //console.log(newFileObj);//contains the template uri and the new file uri + if(!newFileObj) return; + this.application.ninja.ioMediator.fileNew(newFileObj.newFilePath, newFileObj.fileTemplateUri, this.openNewFile, this); + + if((newFileObj.fileExtension !== ".html") && (newFileObj.fileExtension !== ".htm")){//open code view + + }else{ + //open design view + } + } + }, + + /** + * Public method + * doc contains: + * type : file type, like js, css, etc + * name : file name + * source : file content + * uri : file uri + */ + openNewFile:{ + value:function(doc){ + if(!doc){ + doc = {"type": "js", "name": "filename", "source": "test file content", "uri": "/fs/fsd/"} ; + } + this.openDocument(doc); } }, @@ -160,7 +185,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, newDoc.initialize(doc, docUuid, textArea, textArea.parentNode); // Tmp this will be filled with the real content - newDoc.textArea.innerHTML = doc.source; //this.tmpSourceForTesting; + newDoc.textArea.value = doc.source; //this.tmpSourceForTesting; this.textDocumentOpened(newDoc); @@ -175,7 +200,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, textDocumentOpened: { value: function(doc) { - this.activeDocument = doc; + this.application.ninja.stage.stageView.createTextView(doc); @@ -377,7 +402,10 @@ 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.currentView === "design" || this.activeDocument.currentView === "design"){ + this.activeDocument.container.parentNode.style["display"] = "none"; + this.application.ninja.stage.hideCanvas(true); + } } } }, @@ -386,7 +414,10 @@ 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.currentView === "design" || this.activeDocument.currentView === "design"){ + this.activeDocument.container.parentNode.style["display"] = "block"; + this.application.ninja.stage.hideCanvas(false); + } } } }, -- cgit v1.2.3 From 45cfffd9261ab1aa714554c584f0d0d8fe627c91 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 3 Feb 2012 18:04:26 -0800 Subject: allow to open html file in design view, integrated file open with io mediator Signed-off-by: Ananya Sen --- js/io/document/document-controller.js | 42 ++++++++++++++--------------------- 1 file changed, 17 insertions(+), 25 deletions(-) (limited to 'js/io/document/document-controller.js') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index b900dee4..ca6b4533 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -105,7 +105,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value:function(newFileObj){ //console.log(newFileObj);//contains the template uri and the new file uri if(!newFileObj) return; - this.application.ninja.ioMediator.fileNew(newFileObj.newFilePath, newFileObj.fileTemplateUri, this.openNewFile, this); + this.application.ninja.ioMediator.fileNew(newFileObj.newFilePath, newFileObj.fileTemplateUri, {"operation":this.openNewFileCallback, "thisScope":this}); if((newFileObj.fileExtension !== ".html") && (newFileObj.fileExtension !== ".htm")){//open code view @@ -123,7 +123,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, * source : file content * uri : file uri */ - openNewFile:{ + openNewFileCallback:{ value:function(doc){ if(!doc){ doc = {"type": "js", "name": "filename", "source": "test file content", "uri": "/fs/fsd/"} ; @@ -140,20 +140,21 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } //console.log("URI is: ", uri); - if(!!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"); - filename = this.getFileNameFromPath(uri); - if(uri.indexOf('.') != -1){ - fileType = uri.substr(uri.lastIndexOf('.') + 1); - } - this.openDocument({"type": ""+fileType, "name": ""+filename, "source": fileContent, "uri": uri}); - } + this.application.ninja.ioMediator.fileOpen({"uri":uri}, {"operation":this.openFileCallback, "thisScope":this}); + } + }, + /** + * Public method + * doc contains: + * type : file type, like js, css, etc + * name : file name + * source : file content + * uri : file uri + */ + openFileCallback:{ + value:function(doc){ + this.openDocument(doc); } }, @@ -460,14 +461,5 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function() { return "userDocument_" + (this._iframeCounter++); } - }, - - ///// 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); - } - } + } }); \ No newline at end of file -- cgit v1.2.3 From 272c5f74f4ce76fec9cbe360817bf23639307d3a Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Sun, 5 Feb 2012 19:20:37 -0800 Subject: changes to show document dirty indicator on editing code view, and to remove dirty indicator on save. Signed-off-by: Ananya Sen --- js/io/document/document-controller.js | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) (limited to 'js/io/document/document-controller.js') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index ca6b4533..51575a24 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -239,45 +239,25 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function(id) { //if file dirty then save + if(this.activeDocument.dirtyFlag === true){ + this.activeDocument.save(true); + this.activeDocument.dirtyFlag=false; + } var doc = this._findDocumentByUUID(id); this._removeDocumentView(doc.container); + var closeDocumentIndex = this._findIndexByUUID(id); this._documents.splice(this._findIndexByUUID(id), 1); if(this.activeDocument.uuid === id && this._documents.length > 0) { - - var closeDocumentIndex = this._findIndexByUUID(id); var nextDocumentIndex = -1 ; if((this._documents.length > 0) && (closeDocumentIndex === 0)){ nextDocumentIndex = 1; }else if((this._documents.length > 0) && (closeDocumentIndex > 0)){ nextDocumentIndex = closeDocumentIndex - 1; } - - //remove the codemirror div if this is for a code view - /////test - - ////end- test - - this.switchDocument(this._documents[0].uuid); - - } - } - }, - - switchDocument: { - value: function(id) { - this._hideCurrentDocument(); - this.activeDocument = this._findDocumentByUUID(id); - - this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe - this._showCurrentDocument(); - - if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") { - this.application.ninja.stage._scrollFlag = true; // TODO HACK to prevent type error on Hide/Show Iframe - // TODO dispatch event here -// appDelegateModule.MyAppDelegate.onSetActiveDocument(); + this.application.ninja.stage.stageView.switchDocument(this._documents[nextDocumentIndex]); } } }, @@ -406,6 +386,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, if(this.activeDocument.currentView === "design" || this.activeDocument.currentView === "design"){ this.activeDocument.container.parentNode.style["display"] = "none"; this.application.ninja.stage.hideCanvas(true); + this.application.ninja.stage.stageView.hideRulers(); } } } @@ -418,6 +399,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, if(this.activeDocument.currentView === "design" || this.activeDocument.currentView === "design"){ this.activeDocument.container.parentNode.style["display"] = "block"; this.application.ninja.stage.hideCanvas(false); + this.application.ninja.stage.stageView.showRulers(); } } } -- cgit v1.2.3 From 729bc48212d7244539c99ca206be673eed011115 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 6 Feb 2012 16:07:46 -0800 Subject: integrated save for the document tabs, detect codemirror history to show document dirty indicator. Signed-off-by: Ananya Sen --- js/io/document/document-controller.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'js/io/document/document-controller.js') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index 51575a24..1a5d6058 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -72,6 +72,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.eventManager.addEventListener("appLoaded", this, false); this.eventManager.addEventListener("executeFileOpen", this, false); this.eventManager.addEventListener("executeNewFile", this, false); + this.eventManager.addEventListener("executeSave", this, false); } }, @@ -87,8 +88,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, pickerSettings.callback = this.openFileWithURI; pickerSettings.callbackScope = this; this.application.ninja.filePickerController.showFilePicker(pickerSettings); - - //this.openDocument({"type": "js", "source": this.tmpSourceForTesting}); } }, @@ -101,6 +100,12 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, + handleExecuteSave: { + value: function(event) { + this.activeDocument.save(); + } + }, + createNewFile:{ value:function(newFileObj){ //console.log(newFileObj);//contains the template uri and the new file uri @@ -240,7 +245,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, //if file dirty then save if(this.activeDocument.dirtyFlag === true){ - this.activeDocument.save(true); + this.activeDocument.save(true /*remove the codemirror div after saving*/); this.activeDocument.dirtyFlag=false; } @@ -382,12 +387,13 @@ var DocumentController = exports.DocumentController = Montage.create(Component, _hideCurrentDocument: { value: function() { if(this.activeDocument) { - this.activeDocument.container.style["display"] = "none"; - if(this.activeDocument.currentView === "design" || this.activeDocument.currentView === "design"){ + if(this.activeDocument.currentView === "design"){ + this.application.ninja.stage.saveStageScroll(); this.activeDocument.container.parentNode.style["display"] = "none"; this.application.ninja.stage.hideCanvas(true); this.application.ninja.stage.stageView.hideRulers(); } + this.activeDocument.container.style["display"] = "none"; } } }, @@ -396,8 +402,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function() { if(this.activeDocument) { this.activeDocument.container.style["display"] = "block"; - if(this.activeDocument.currentView === "design" || this.activeDocument.currentView === "design"){ + if(this.activeDocument.currentView === "design"){ this.activeDocument.container.parentNode.style["display"] = "block"; + this.application.ninja.stage.applySavedScroll(); this.application.ninja.stage.hideCanvas(false); this.application.ninja.stage.stageView.showRulers(); } -- cgit v1.2.3 From 36b2e540f06cef3887e7d0fea60527fee51e2a40 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Wed, 8 Feb 2012 15:36:53 -0800 Subject: fixed undo/redo for each code view document, changed new file integration with io mediator Signed-off-by: Ananya Sen --- js/io/document/document-controller.js | 75 +++++++---------------------------- 1 file changed, 15 insertions(+), 60 deletions(-) (limited to 'js/io/document/document-controller.js') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index 1a5d6058..e36181bf 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -39,19 +39,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, "var options = {}, defaults = CodeMirror.defaults; }" }, - _codeEditor: { - value: { - "editor": { - value: null, - enumerable: false - }, - "hline": { - value: null, - enumerable: false - } - } - }, - activeDocument: { get: function() { return this._activeDocument; @@ -64,6 +51,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this._activeDocument = doc; this._activeDocument.isActive = true; + if(!!this._activeDocument.editor){ + this._activeDocument.editor.focus(); + } + } }, @@ -73,6 +64,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.eventManager.addEventListener("executeFileOpen", this, false); this.eventManager.addEventListener("executeNewFile", this, false); this.eventManager.addEventListener("executeSave", this, false); + + this.eventManager.addEventListener("recordStyleChanged", this, false); } }, @@ -110,7 +103,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value:function(newFileObj){ //console.log(newFileObj);//contains the template uri and the new file uri if(!newFileObj) return; - this.application.ninja.ioMediator.fileNew(newFileObj.newFilePath, newFileObj.fileTemplateUri, {"operation":this.openNewFileCallback, "thisScope":this}); + this.application.ninja.ioMediator.fileNew(newFileObj.newFilePath, newFileObj.fileTemplateUri, this.openNewFileCallback.bind(this)); if((newFileObj.fileExtension !== ".html") && (newFileObj.fileExtension !== ".htm")){//open code view @@ -130,10 +123,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, */ openNewFileCallback:{ value:function(doc){ - if(!doc){ - doc = {"type": "js", "name": "filename", "source": "test file content", "uri": "/fs/fsd/"} ; + var response = doc || {"uri":"/Users/xhdq84/Documents/test.js", "success":true};//default just for testing + if(!!response && response.success && !!response.uri){ + this.application.ninja.ioMediator.fileOpen({"uri":response.uri}, this.openFileCallback.bind(this)); } - this.openDocument(doc); } }, @@ -145,7 +138,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } //console.log("URI is: ", uri); - this.application.ninja.ioMediator.fileOpen({"uri":uri}, {"operation":this.openFileCallback, "thisScope":this}); + this.application.ninja.ioMediator.fileOpen({"uri":uri}, this.openFileCallback.bind(this)); } }, @@ -242,11 +235,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component, closeDocument: { value: function(id) { - - //if file dirty then save if(this.activeDocument.dirtyFlag === true){ - this.activeDocument.save(true /*remove the codemirror div after saving*/); - this.activeDocument.dirtyFlag=false; + //if file dirty then alert user to save } var doc = this._findDocumentByUUID(id); @@ -267,42 +257,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, - switchViews: { - value: function() { - - //save file if dirty - - this.application.ninja.stage.saveScroll(); - this._hideCurrentDocument(); - - if(this.activeDocument.currentView === "design") { - this._textHolder.style.display = "none"; - this.activeDocument.container.style["display"] = "block"; - this.application.ninja.stage._scrollFlag = true; - //this._showCurrentDocument(); - this.application.ninja.stage.restoreScroll(); - - } else { - this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe - - var codeview = this.activeDocument.container; - //this._textHolder.style.display = "block"; - //codeview.firstChild.innerHTML = this.activeDocument.iframe.contentWindow.document.body.parentNode.innerHTML; - -// this._codeEditor.editor = CodeMirror.fromTextArea(codeview.firstChild, { -// lineNumbers: true, -// mode: "htmlmixed", -// onCursorActivity: function() { -// DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.hline, null); -// DocumentController._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.editor.getCursor().line, "activeline"); -// } -// }); -// this._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(0, "activeline"); - } - } - }, - - // Document has been loaded into the Iframe. Dispatch the event. // Event Detail: Contains the current ActiveDocument _onOpenDocument: { @@ -388,11 +342,12 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function() { if(this.activeDocument) { if(this.activeDocument.currentView === "design"){ - this.application.ninja.stage.saveStageScroll(); + this.application.ninja.stage.saveScroll(); this.activeDocument.container.parentNode.style["display"] = "none"; this.application.ninja.stage.hideCanvas(true); this.application.ninja.stage.stageView.hideRulers(); } + this.activeDocument.container.style["display"] = "none"; } } @@ -404,7 +359,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.activeDocument.container.style["display"] = "block"; if(this.activeDocument.currentView === "design"){ this.activeDocument.container.parentNode.style["display"] = "block"; - this.application.ninja.stage.applySavedScroll(); + this.application.ninja.stage.restoreScroll(); this.application.ninja.stage.hideCanvas(false); this.application.ninja.stage.stageView.showRulers(); } -- cgit v1.2.3 From 26bfb7a4cbf66c35e23eec46def045bd295be2e1 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Thu, 9 Feb 2012 21:21:29 -0800 Subject: disabling the auto open of a document on load. Temporary using the new project button to open a document. Signed-off-by: Valerio Virgillito --- js/io/document/document-controller.js | 43 +++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'js/io/document/document-controller.js') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index e36181bf..15f026a3 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -37,7 +37,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: "function CodeMirror(place, givenOptions) {" + "// Determine effective options based on given values and defaults." + "var options = {}, defaults = CodeMirror.defaults; }" - }, + }, activeDocument: { get: function() { @@ -45,7 +45,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, }, set: function(doc) { if(this._activeDocument) this._activeDocument.isActive = false; - + if(this._documents.indexOf(doc) === -1) this._documents.push(doc); this._activeDocument = doc; @@ -66,10 +66,19 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.eventManager.addEventListener("executeSave", this, false); this.eventManager.addEventListener("recordStyleChanged", this, false); + + // Temporary testing opening a new file after Ninja has loaded + this.eventManager.addEventListener("executeNewProject", this, false); } }, handleAppLoaded: { + value: function() { + //this.openDocument({"type": "html"}); + } + }, + + handleExecuteNewProject: { value: function() { this.openDocument({"type": "html"}); } @@ -107,9 +116,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, if((newFileObj.fileExtension !== ".html") && (newFileObj.fileExtension !== ".htm")){//open code view - }else{ + } else { //open design view - } + } } }, @@ -153,7 +162,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, openFileCallback:{ value:function(doc){ this.openDocument(doc); - } + } }, @@ -188,7 +197,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.textDocumentOpened(newDoc); - } + } // } catch (err) { // console.log("Could not open Document ", err); @@ -220,24 +229,24 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } DocumentManager._codeEditor.editor = CodeMirror.fromTextArea(doc.textArea, { - lineNumbers: true, + 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"); - } - }); + onCursorActivity: function() { + DocumentManager._codeEditor.editor.setLineClass(DocumentManager._codeEditor.hline, null); + DocumentManager._codeEditor.hline = DocumentManager._codeEditor.editor.setLineClass(DocumentManager._codeEditor.editor.getCursor().line, "activeline"); + } + }); DocumentManager._codeEditor.hline = DocumentManager._codeEditor.editor.setLineClass(0, "activeline"); */ - } + } }, closeDocument: { value: function(id) { if(this.activeDocument.dirtyFlag === true){ //if file dirty then alert user to save - } + } var doc = this._findDocumentByUUID(id); this._removeDocumentView(doc.container); @@ -362,9 +371,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.application.ninja.stage.restoreScroll(); this.application.ninja.stage.hideCanvas(false); this.application.ninja.stage.stageView.showRulers(); - } } } + } }, _removeDocumentView: { @@ -405,5 +414,5 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function() { return "userDocument_" + (this._iframeCounter++); } - } -}); \ No newline at end of file + } +}); -- cgit v1.2.3 From ad0ee69be3512325ede94738f23597086a141a3e Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 10 Feb 2012 01:55:30 -0800 Subject: file open and file new integrated again Signed-off-by: Ananya Sen --- js/io/document/document-controller.js | 57 +++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 10 deletions(-) (limited to 'js/io/document/document-controller.js') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index e36181bf..6f67b57c 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -78,8 +78,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, handleExecuteFileOpen: { value: function(event) { var pickerSettings = event._event.settings || {}; - pickerSettings.callback = this.openFileWithURI; - pickerSettings.callbackScope = this; + pickerSettings.callback = this.openFileWithURI.bind(this); + pickerSettings.pickerMode = "read"; + pickerSettings.inFileMode = true; this.application.ninja.filePickerController.showFilePicker(pickerSettings); } }, @@ -87,8 +88,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, handleExecuteNewFile: { value: function(event) { var newFileSettings = event._event.settings || {}; - newFileSettings.callback = this.createNewFile; - newFileSettings.callbackScope = this; + newFileSettings.callback = this.createNewFile.bind(this); this.application.ninja.newFileController.showNewFileDialog(newFileSettings); } }, @@ -123,9 +123,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, */ openNewFileCallback:{ value:functi