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/base-document.js | 0 js/io/document/document-controller.js | 166 +++++++++++++++++++++++++++------- js/io/document/html-document.js | 0 js/io/document/text-document.js | 15 +-- 4 files changed, 137 insertions(+), 44 deletions(-) mode change 100644 => 100755 js/io/document/base-document.js mode change 100644 => 100755 js/io/document/document-controller.js mode change 100644 => 100755 js/io/document/html-document.js mode change 100644 => 100755 js/io/document/text-document.js (limited to 'js/io/document') diff --git a/js/io/document/base-document.js b/js/io/document/base-document.js old mode 100644 new mode 100755 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 diff --git a/js/io/document/html-document.js b/js/io/document/html-document.js old mode 100644 new mode 100755 diff --git a/js/io/document/text-document.js b/js/io/document/text-document.js old mode 100644 new mode 100755 index 3506891a..599d311c --- a/js/io/document/text-document.js +++ b/js/io/document/text-document.js @@ -17,16 +17,8 @@ var TextDocument = exports.TextDocument = Montage.create(baseDocumentModule.Base } }, - _textArea: { value: null, enumerable: false }, - - // Temporary Save the source _source: { value: null, enumerable: false}, - textArea: { - get: function() { return this._textArea;}, - set: function(value) { this._textArea = value; } - }, - source: { get: function() { return this._source;}, set: function(value) { this._source = value;} @@ -53,10 +45,11 @@ var TextDocument = exports.TextDocument = Montage.create(baseDocumentModule.Base // PUBLIC METHODS initialize: { value: function(doc, uuid, textArea, callback) { - this.init(doc.name, doc.uri, doc.type, textArea, uuid, callback); - this.textArea = textArea.firstChild; + this.init(doc.name, doc.uri, doc.type, textArea, uuid); + this.currentView = "code"; - this._loadContent(); + this.textArea = textArea; +// this._loadContent(); } }, -- 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') 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') 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') 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 d26a13de2aca25c36cb35f85604de1ac2b9befbb Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 1 Feb 2012 14:37:30 -0800 Subject: Simple button native widget test. Added a controller, pi and panel code. Signed-off-by: Valerio Virgillito --- js/io/document/html-document.js | 47 ++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 19 deletions(-) (limited to 'js/io/document') diff --git a/js/io/document/html-document.js b/js/io/document/html-document.js index c44dfe75..a8e06c69 100644 --- a/js/io/document/html-document.js +++ b/js/io/document/html-document.js @@ -27,6 +27,7 @@ var HTMLDocument = exports.HTMLDocument = Montage.create(baseDocumentModule.Base _initialUserDocument: { value: null, enumerable: false }, _htmlSource: {value: "", enumerable: false}, _glData: {value: null, enumerable: false }, + _userComponents: { value: {}, enumarable: false}, _elementCounter: { value: 1, enumerable: false }, _snapping : { value: true, enumerable: false }, @@ -108,23 +109,11 @@ var HTMLDocument = exports.HTMLDocument = Montage.create(baseDocumentModule.Base } }, - _userComponentSet: { - value: {}, - writable: true, - enumerable:true + userComponents: { + get: function() { + return this._userComponents; + } }, - -// userComponentSet:{ -// enumerable: true, -// get: function() { -// return this._userComponentSet; -// }, -// set: function(value) { -// this._userComponentSet = value; -// this._drawUserComponentsOnOpen(); -// } -// }, -// // _drawUserComponentsOnOpen:{ // value:function(){ // for(var i in this._userComponentSet){ @@ -191,6 +180,29 @@ var HTMLDocument = exports.HTMLDocument = Montage.create(baseDocumentModule.Base set: function(value) { this._zoomFactor = value; } }, + /** + * Add a reference to a component instance to the userComponents hash using the + * element UUID + */ + setComponentInstance: { + value: function(instance, el) { + this.userComponents[el.uuid] = instance; + } + }, + + /** + * Returns the component instance obj from the element + */ + getComponentFromElement: { + value: function(el) { + if(el) { + if(el.uuid) return this.userComponents[el.uuid]; + } else { + return null; + } + } + }, + //****************************************// // PUBLIC METHODS initialize: { @@ -353,9 +365,6 @@ var HTMLDocument = exports.HTMLDocument = Montage.create(baseDocumentModule.Base this.callback(this); } }.bind(this), 50); - - // TODO - Not sure where this goes - this._userComponentSet = {}; } else { this._styles = this._document.styleSheets[this._document.styleSheets.length - 1]; this._stylesheets = this._document.styleSheets; // Entire stlyesheets array -- 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/base-document.js | 13 ++++++++++++- js/io/document/document-controller.js | 36 +++++++++++++++++++---------------- js/io/document/text-document.js | 4 ++-- 3 files changed, 34 insertions(+), 19 deletions(-) (limited to 'js/io/document') diff --git a/js/io/document/base-document.js b/js/io/document/base-document.js index 44f54f78..af96c851 100755 --- a/js/io/document/base-document.js +++ b/js/io/document/base-document.js @@ -12,6 +12,7 @@ var BaseDocument = exports.BaseDocument = Montage.create(Montage, { /** Private Members **/ _name: { value: null, enumerable: false }, _uri: { value: null, enumerable: false }, + _externalUri: {value: null, enumerable:false}, _documentType: { value: null, enumerable: false }, _container: {value: null, enumerable: false }, _uuid: { value: null, enumerable: false }, @@ -31,6 +32,11 @@ var BaseDocument = exports.BaseDocument = Montage.create(Montage, { set: function(value) { this._uri = value; } }, + externalUri: { + get: function() { return this._externalUri; }, + set: function(value) { this._externalUri = value; } + }, + documentType: { get: function() { return this._documentType; }, set: function(value) { this._documentType = value; } @@ -68,13 +74,18 @@ var BaseDocument = exports.BaseDocument = Montage.create(Montage, { /** Base Methods **/ init: { - value: function(name, uri, type, container, uuid, callback) { + value: function(name, uri, type, container, uuid, callback, externalUri) { this.name = name; this.uri = uri; this.documentType = type; this.container = container; this.uuid = uuid; this.callback = callback; + if(!!externalUri){ + this.externalUri = externalUri; + this.container.setAttribute("data-uri", externalUri); + } + } }, 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); + } } }, diff --git a/js/io/document/text-document.js b/js/io/document/text-document.js index 599d311c..a9081cb5 100755 --- a/js/io/document/text-document.js +++ b/js/io/document/text-document.js @@ -45,10 +45,10 @@ var TextDocument = exports.TextDocument = Montage.create(baseDocumentModule.Base // PUBLIC METHODS initialize: { value: function(doc, uuid, textArea, callback) { - this.init(doc.name, doc.uri, doc.type, textArea, uuid); - + this.init(doc.name, doc.uri, doc.type, textArea, uuid, null, doc.externalUri); this.currentView = "code"; this.textArea = textArea; + // this._loadContent(); } }, -- 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/base-document.js | 8 +----- js/io/document/document-controller.js | 54 ++++++++++++----------------------- js/io/document/html-document.js | 12 ++++++++ js/io/document/text-document.js | 10 +++++-- 4 files changed, 39 insertions(+), 45 deletions(-) (limited to 'js/io/document') diff --git a/js/io/document/base-document.js b/js/io/document/base-document.js index af96c851..d3601de5 100755 --- a/js/io/document/base-document.js +++ b/js/io/document/base-document.js @@ -12,7 +12,6 @@ var BaseDocument = exports.BaseDocument = Montage.create(Montage, { /** Private Members **/ _name: { value: null, enumerable: false }, _uri: { value: null, enumerable: false }, - _externalUri: {value: null, enumerable:false}, _documentType: { value: null, enumerable: false }, _container: {value: null, enumerable: false }, _uuid: { value: null, enumerable: false }, @@ -74,18 +73,13 @@ var BaseDocument = exports.BaseDocument = Montage.create(Montage, { /** Base Methods **/ init: { - value: function(name, uri, type, container, uuid, callback, externalUri) { + value: function(name, uri, type, container, uuid, callback) { this.name = name; this.uri = uri; this.documentType = type; this.container = container; this.uuid = uuid; this.callback = callback; - if(!!externalUri){ - this.externalUri = externalUri; - this.container.setAttribute("data-uri", externalUri); - } - } }, 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 diff --git a/js/io/document/html-document.js b/js/io/document/html-document.js index c44dfe75..fc7dd05b 100755 --- a/js/io/document/html-document.js +++ b/js/io/document/html-document.js @@ -36,6 +36,13 @@ var HTMLDocument = exports.HTMLDocument = Montage.create(baseDocumentModule.Base _zoomFactor: { value: 100, enumerable: false }, + _codeEditor: { + value: { + "editor": { value: null, enumerable: false }, + "hline": { value: null, enumerable: false } + } + }, + // PUBLIC MEMBERS cssLoadInterval: { value: null, enumerable: false }, @@ -44,6 +51,11 @@ var HTMLDocument = exports.HTMLDocument = Montage.create(baseDocumentModule.Base */ // GETTERS / SETTERS + editor: { + get: function() { return this._codeEditor.editor; }, + set: function(value) { this._codeEditor.editor = value} + }, + selectionExclude: { get: function() { return this._selectionExclude; }, set: function(value) { this._selectionExclude = value; } diff --git a/js/io/document/text-document.js b/js/io/document/text-document.js index a9081cb5..156aaacb 100755 --- a/js/io/document/text-document.js +++ b/js/io/document/text-document.js @@ -17,6 +17,8 @@ var TextDocument = exports.TextDocument = Montage.create(baseDocumentModule.Base } }, + _textArea: {value: null, enumerable: false }, + _source: { value: null, enumerable: false}, source: { @@ -31,6 +33,10 @@ var TextDocument = exports.TextDocument = Montage.create(baseDocumentModule.Base // GETTERS / SETTERS + textArea: { + get: function() { return this._textArea; }, + set: function(value) { this._textArea = value; } + }, editor: { get: function() { return this._codeEditor.editor; }, set: function(value) { this._codeEditor.editor = value} @@ -44,8 +50,8 @@ var TextDocument = exports.TextDocument = Montage.create(baseDocumentModule.Base // PUBLIC METHODS initialize: { - value: function(doc, uuid, textArea, callback) { - this.init(doc.name, doc.uri, doc.type, textArea, uuid, null, doc.externalUri); + value: function(doc, uuid, textArea, container, callback) { + this.init(doc.name, doc.uri, doc.type, container, uuid); this.currentView = "code"; this.textArea = textArea; -- 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') 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') 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') 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/base-document.js | 7 +++++- js/io/document/document-controller.js | 41 ++++++++++++++++++++++++++++++----- js/io/document/html-document.js | 28 ++++++++++++++++++++++++ js/io/document/text-document.js | 16 ++++++++++++++ 4 files changed, 86 insertions(+), 6 deletions(-) (limited to 'js/io/document') diff --git a/js/io/document/base-document.js b/js/io/document/base-document.js index d3601de5..ecc92447 100755 --- a/js/io/document/base-document.js +++ b/js/io/document/base-document.js @@ -87,7 +87,12 @@ var BaseDocument = exports.BaseDocument = Montage.create(Montage, { value: function() { // Have the XHR here? } - } + }, + save:{ + value:function(){ + //base function - to be overridden + } + } }); \ No newline at end of file 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); + } } } }, diff --git a/js/io/document/html-document.js b/js/io/document/html-document.js index fc7dd05b..24d4e7e4 100755 --- a/js/io/document/html-document.js +++ b/js/io/document/html-document.js @@ -43,9 +43,16 @@ var HTMLDocument = exports.HTMLDocument = Montage.create(baseDocumentModule.Base } }, + // PUBLIC MEMBERS cssLoadInterval: { value: null, enumerable: false }, + codeViewDocument:{ + writable: true, + enumerable: true, + value:null + }, + /* * PUBLIC API */ @@ -432,5 +439,26 @@ var HTMLDocument = exports.HTMLDocument = Montage.create(baseDocumentModule.Base */ } } + }, + + /** + * public method + * parameter: + * removeCodeMirrorDivFlag - for code view, tell to remove the codemirror div after saving + */ + save:{ + value:function(removeCodeMirrorDivFlag){ + if(this.currentView === "design"){ + //generate html and save + }else if((this.currentView === "code") && (this.codeViewDocument !== null)){ + if(removeCodeMirrorDivFlag === true){ + this.codeViewDocument.save(true); + }else{ + this.codeViewDocument.save(); + } + //persist to filesystem + } + + } } }); \ No newline at end of file diff --git a/js/io/document/text-document.js b/js/io/document/text-document.js index 156aaacb..a768779f 100755 --- a/js/io/document/text-document.js +++ b/js/io/document/text-document.js @@ -85,6 +85,22 @@ var TextDocument = exports.TextDocument = Montage.create(baseDocumentModule.Base xhr.send(''); } + }, + + /** + * public method + * parameter: + * removeCodeMirrorDivFlag - for code view, tell to remove the codemirror div after saving + */ + save:{ + value:function(removeCodeMirrorDivFlag){ + this.editor.save(); + if(removeCodeMirrorDivFlag === true){ + var codemirrorDiv = this.textArea.parentNode.querySelector(".CodeMirror"); + if(!!codemirrorDiv){codemirrorDiv.parentNode.removeChild(codemirrorDiv);} + } + //persist to filesystem + } } }); \ No newline at end of file -- 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 ++++++++++++++--------------------- js/io/document/html-document.js | 5 +++-- 2 files changed, 20 insertions(+), 27 deletions(-) (limited to 'js/io/document') 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 diff --git a/js/io/document/html-document.js b/js/io/document/html-document.js index 24d4e7e4..da1bbe4a 100755 --- a/js/io/document/html-document.js +++ b/js/io/document/html-document.js @@ -216,8 +216,9 @@ var HTMLDocument = exports.HTMLDocument = Montage.create(baseDocumentModule.Base value: function(doc, uuid, iframe, callback) { // Shell mode is not used anymore //if(!window.IsInShellMode()) { - - this.init("index-cloud", this._cloudTemplateUri, doc.type, iframe, uuid, callback); + if(!doc.name){doc.name = "index-cloud"}; + if(!doc.uri){doc.uri = this._cloudTemplateUri}; + this.init(doc.name, doc.uri, doc.type, iframe, uuid, callback); /* } else { var tmpurl = doc.uri.split('\\'); -- 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/base-document.js | 5 ----- js/io/document/document-controller.js | 34 ++++++++-------------------------- js/io/document/html-document.js | 23 ++++++++++++++--------- js/io/document/text-document.js | 1 + 4 files changed, 23 insertions(+), 40 deletions(-) (limited to 'js/io/document') diff --git a/js/io/document/base-document.js b/js/io/document/base-document.js index ecc92447..918b51ad 100755 --- a/js/io/document/base-document.js +++ b/js/io/document/base-document.js @@ -31,11 +31,6 @@ var BaseDocument = exports.BaseDocument = Montage.create(Montage, { set: function(value) { this._uri = value; } }, - externalUri: { - get: function() { return this._externalUri; }, - set: function(value) { this._externalUri = value; } - }, - documentType: { get: function() { return this._documentType; }, set: function(value) { this._documentType = value; } 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(); } } } diff --git a/js/io/document/html-document.js b/js/io/document/html-document.js index da1bbe4a..8e1eb614 100755 --- a/js/io/document/html-document.js +++ b/js/io/document/html-document.js @@ -449,17 +449,22 @@ var HTMLDocument = exports.HTMLDocument = Montage.create(baseDocumentModule.Base */ save:{ value:function(removeCodeMirrorDivFlag){ - if(this.currentView === "design"){ - //generate html and save - }else if((this.currentView === "code") && (this.codeViewDocument !== null)){ - if(removeCodeMirrorDivFlag === true){ - this.codeViewDocument.save(true); - }else{ - this.codeViewDocument.save(); + try{ + if(this.currentView === "design"){ + //generate html and save + }else if((this.currentView === "code") && (this.codeViewDocument !== null)){ + if(removeCodeMirrorDivFlag === true){ + this.codeViewDocument.save(true); + }else{ + this.codeViewDocument.save(); + } + //persist to filesystem } - //persist to filesystem + this.dirtyFlag=false; + }catch(e){ + console.log("Error while saving "+this.uri); + console.log(e.stack); } - } } }); \ No newline at end of file diff --git a/js/io/document/text-document.js b/js/io/document/text-document.js index a768779f..683c513c 100755 --- a/js/io/document/text-document.js +++ b/js/io/document/text-document.js @@ -95,6 +95,7 @@ var TextDocument = exports.TextDocument = Montage.create(baseDocumentModule.Base save:{ value:function(removeCodeMirrorDivFlag){ this.editor.save(); + this.dirtyFlag=false; if(removeCodeMirrorDivFlag === true){ var codemirrorDiv = this.textArea.parentNode.querySelector(".CodeMirror"); if(!!codemirrorDiv){codemirrorDiv.parentNode.removeChild(codemirrorDiv);} -- 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 +++++++++++++------ js/io/document/text-document.js | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'js/io/document') 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);