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 --- .../layout/document-entry.reel/document-entry.css | 1 + .../layout/document-entry.reel/document-entry.js | 23 +++++++++++++++ .../layout/documents-tab.reel/documents-tab.html | 5 ++++ 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 + js/ninja.reel/ninja.html | 2 ++ js/stage/stage-view.reel/stage-view.js | 25 ++++++++++++++++ 9 files changed, 79 insertions(+), 40 deletions(-) diff --git a/js/components/layout/document-entry.reel/document-entry.css b/js/components/layout/document-entry.reel/document-entry.css index ce173cd6..52d08d72 100755 --- a/js/components/layout/document-entry.reel/document-entry.css +++ b/js/components/layout/document-entry.reel/document-entry.css @@ -35,4 +35,5 @@ .documentEntry span.dirty:before{ content: "*"; + display:inline; } diff --git a/js/components/layout/document-entry.reel/document-entry.js b/js/components/layout/document-entry.reel/document-entry.js index 2a33548a..a1bed79b 100755 --- a/js/components/layout/document-entry.reel/document-entry.js +++ b/js/components/layout/document-entry.reel/document-entry.js @@ -77,6 +77,23 @@ exports.DocumentEntry = Montage.create(Component, { } }, + _dirtyFlag:{ + enumerable:false, + value:false + }, + dirtyFlag:{ + get: function() { + return this._dirtyFlag; + }, + set: function(value) { + var previousValue = this._dirtyFlag; + this._dirtyFlag = value; + + if (previousValue !== this._dirtyFlag) { + this.needsDraw = true; + } + } + }, prepareForDraw: { enumerable: false, @@ -92,6 +109,12 @@ exports.DocumentEntry = Montage.create(Component, { this.label.innerText = this._name ? this._name : ""; this._active ? this.element.classList.add("activeTab") : this.element.classList.remove("activeTab"); + + if(this.dirtyFlag === true){ + if(!this.label.classList.contains("dirty")){this.label.classList.add("dirty");} + }else{ + if(this.label.classList.contains("dirty")){this.label.classList.remove("dirty");} + } } }, diff --git a/js/components/layout/documents-tab.reel/documents-tab.html b/js/components/layout/documents-tab.reel/documents-tab.html index 94b2e46e..82ba8782 100755 --- a/js/components/layout/documents-tab.reel/documents-tab.html +++ b/js/components/layout/documents-tab.reel/documents-tab.html @@ -38,6 +38,11 @@ "boundObjectPropertyPath": "objectAtCurrentIteration.name", "oneway": true }, + "dirtyFlag": { + "boundObject": {"@": "repetition1"}, + "boundObjectPropertyPath": "objectAtCurrentIteration.dirtyFlag", + "oneway": true + }, "active": { "boundObject": {"@": "repetition1"}, "boundObjectPropertyPath": "objectAtCurrentIteration.isActive", 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);} diff --git a/js/ninja.reel/ninja.html b/js/ninja.reel/ninja.html index 37c269e0..6630f4a8 100755 --- a/js/ninja.reel/ninja.html +++ b/js/ninja.reel/ninja.html @@ -274,6 +274,8 @@ "name": "Ninja", "properties": { "element": {"#": "main"}, + "rulerTop": {"#": "rulerTop"}, + "rulerLeft": {"#": "rulerLeft"}, "appModel": {"@": "appModel"}, "toolsData": {"@": "toolsData1"}, "toolsList": {"@": "toolsList1"}, diff --git a/js/stage/stage-view.reel/stage-view.js b/js/stage/stage-view.reel/stage-view.js index cf7748fc..6f20b87b 100755 --- a/js/stage/stage-view.reel/stage-view.js +++ b/js/stage/stage-view.reel/stage-view.js @@ -95,9 +95,12 @@ exports.StageView = Montage.create(Component, { //fix hack document.getElementById("codeMirror_"+doc.uuid).style.display="block"; + var documentController = this.application.ninja.documentController; + doc.editor = CodeMirror.fromTextArea(doc.textArea, { lineNumbers: true, mode: type, + onChange: function(){doc.dirtyFlag=true;}, onCursorActivity: function() { //documentController._codeEditor.editor.setLineClass(documentController._codeEditor.hline, null); //documentController._codeEditor.hline = documentController._codeEditor.editor.setLineClass(documentController._codeEditor.editor.getCursor().line, "activeline"); @@ -128,6 +131,8 @@ exports.StageView = Montage.create(Component, { this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe this.application.ninja.documentController._showCurrentDocument(); + var documentController = this.application.ninja.documentController; + if(this.application.ninja.documentController.activeDocument.currentView === "code"){ var type; switch(doc.documentType) { @@ -143,6 +148,7 @@ exports.StageView = Montage.create(Component, { doc.editor = CodeMirror.fromTextArea(doc.textArea, { lineNumbers: true, mode: type, + onChange: function(){doc.dirtyFlag=true;}, onCursorActivity: function() { //documentController._codeEditor.editor.setLineClass(documentController._codeEditor.hline, null); //documentController._codeEditor.hline = documentController._codeEditor.editor.setLineClass(documentController._codeEditor.editor.getCursor().line, "activeline"); @@ -152,8 +158,15 @@ exports.StageView = Montage.create(Component, { //this.application.ninja.documentController._codeEditor.hline = this.application.ninja.documentController._codeEditor.editor.setLineClass(0, "activeline"); } + if(this.application.ninja.documentController.activeDocument.documentType === "htm" || this.application.ninja.documentController.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(); + } + } }, + refreshCodeDocument:{ value:function(doc){ @@ -198,5 +211,17 @@ exports.StageView = Montage.create(Component, { } }, this); } + }, + showRulers:{ + value:function(){ + this.application.ninja.rulerTop.style.display = "block"; + this.application.ninja.rulerLeft.style.display = "block"; + } + }, + hideRulers:{ + value:function(){ + this.application.ninja.rulerTop.style.display = "none"; + this.application.ninja.rulerLeft.style.display = "none"; + } } }); \ No newline at end of file -- cgit v1.2.3