From adb90eff3323aa780f9a0879572e3cf3b9f0b969 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Tue, 21 Feb 2012 13:04:58 -0800 Subject: - file picker - select file on double click - check cloud availability before IO operations [open file, new file, Save, Save As]. Canceling operation if cloud was unavailable, as per team's agreement. Signed-off-by: Ananya Sen --- js/controllers/document-controller.js | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 9a063280..505daaba 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -58,6 +58,7 @@ 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("executeSaveAs", this, false); this.eventManager.addEventListener("recordStyleChanged", this, false); @@ -100,33 +101,47 @@ var DocumentController = exports.DocumentController = Montage.create(Component, handleExecuteFileOpen: { value: function(event) { var pickerSettings = event._event.settings || {}; - pickerSettings.callback = this.openFileWithURI.bind(this); - pickerSettings.pickerMode = "read"; - pickerSettings.inFileMode = true; - this.application.ninja.filePickerController.showFilePicker(pickerSettings); + if (this.application.ninja.coreIoApi.cloudAvailable()) { + pickerSettings.callback = this.openFileWithURI.bind(this); + pickerSettings.pickerMode = "read"; + pickerSettings.inFileMode = true; + this.application.ninja.filePickerController.showFilePicker(pickerSettings); + } } }, handleExecuteNewFile: { value: function(event) { var newFileSettings = event._event.settings || {}; - newFileSettings.callback = this.createNewFile.bind(this); - this.application.ninja.newFileController.showNewFileDialog(newFileSettings); + if (this.application.ninja.coreIoApi.cloudAvailable()) { + newFileSettings.callback = this.createNewFile.bind(this); + this.application.ninja.newFileController.showNewFileDialog(newFileSettings); + } } }, - - //////////////////////////////////////////////////////////////////// //TODO: Check for appropiate structures handleExecuteSave: { value: function(event) { - if(!!this.activeDocument){ + if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ //Text and HTML document classes should return the same save object for fileSave this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); } } }, //////////////////////////////////////////////////////////////////// + handleExecuteSaveAs: { + value: function(event) { + var saveAsSettings = event._event.settings || {}; + if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ + saveAsSettings.fileName = this.activeDocument.name; + saveAsSettings.folderUri = this.activeDocument.uri.substring(0, this.activeDocument.uri.lastIndexOf("/")); + //add callback + this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings); + } + } + }, + // fileSaveResult: { value: function (result) { -- cgit v1.2.3 From 86996190d6a4dd59343d4ce482a9c0e6ef0f1eac Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Tue, 21 Feb 2012 15:53:37 -0800 Subject: added null check for matchedRules in styles-controller.js, to fix js error on reopening and edited html document Signed-off-by: Ananya Sen --- js/controllers/styles-controller.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'js/controllers') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 885d710f..31beb6d0 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -317,7 +317,11 @@ var stylesController = exports.StylesController = Montage.create(Component, { isInlineStyle : true, style : element.style }; - + + if((typeof matchedRules === "undefined") || (matchedRules === null)){ + return null; + } + ///// Now splice it into the matched rules ///// By inserting the inline style at the beginning, ///// we keep the correct order of specificity -- cgit v1.2.3 From 539fb19b2327a9f6fb39403e27c29a8f8d733198 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Tue, 21 Feb 2012 16:46:24 -0800 Subject: edit by Eric G.: catch the error instead of doing the null check for the stale element Signed-off-by: Ananya Sen --- js/controllers/styles-controller.js | 46 +++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 31beb6d0..662816f5 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -318,10 +318,6 @@ var stylesController = exports.StylesController = Montage.create(Component, { style : element.style }; - if((typeof matchedRules === "undefined") || (matchedRules === null)){ - return null; - } - ///// Now splice it into the matched rules ///// By inserting the inline style at the beginning, ///// we keep the correct order of specificity @@ -576,37 +572,36 @@ var stylesController = exports.StylesController = Montage.create(Component, { win = element.ownerDocument.defaultView, self = this; - if(!win) { - return null; - } - if(!omitPseudos) { pseudos.concat(['link', 'visited', 'active', 'hover', 'focus', 'first-letter', 'first-line', 'first-child', 'before', 'after', 'lang', 'target']); } - pseudos.forEach(function(pseudo) { - rules = rules.concat(nj.toArray(win.getMatchedCSSRules(element, pseudo)).filter(function(rule) { - //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet, - //// or only use rules for other stylesheets + try { + pseudos.forEach(function(pseudo) { + rules = rules.concat(nj.toArray(win.getMatchedCSSRules(element, pseudo)).filter(function(rule) { + //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet, + //// or only use rules for other stylesheets - var sheetId = (rule.parentStyleSheet) ? rule.parentStyleSheet.ownerNode.id : null, - isStageStyleSheet = sheetId === this.CONST.STAGE_SHEET_ID; + var sheetId = (rule.parentStyleSheet) ? rule.parentStyleSheet.ownerNode.id : null, + isStageStyleSheet = sheetId === this.CONST.STAGE_SHEET_ID; - ///// filter out (return false) depending on flag - if(useStageStyleSheet && !isStageStyleSheet) { return false; } - if(!useStageStyleSheet && isStageStyleSheet) { return false; } + ///// filter out (return false) depending on flag + if(useStageStyleSheet && !isStageStyleSheet) { return false; } + if(!useStageStyleSheet && isStageStyleSheet) { return false; } - ///// Non-filter code - just assigning specificity to the rule - if(!rule[this.CONST.SPECIFICITY_KEY]) { - rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText); - } + ///// Non-filter code - just assigning specificity to the rule + if(!rule[this.CONST.SPECIFICITY_KEY]) { + rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText); + } - return true; - - }, this)); - }, this); + return true; + }, this)); + }, this); + } catch(ERROR) { + console.warn('StylesController::getMatchingRules - Un-attached element queried.'); + } ///// Function for sorting by specificity values function sorter(ruleA, ruleB) { var a, b, order, sheetAIndex, sheetBIndex, ruleAIndex, ruleBIndex; @@ -985,6 +980,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// Pass "true" to method to return an override object, which ///// has the rule to override, and whether the !important flag is needed dominantRule = this.getDominantRuleForElement(element, property, true, isStageElement); + } ///// Did we find a dominant rule? -- cgit v1.2.3 From 9aa442da1ac9fd3212b37fa63a36090af47b6808 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Tue, 21 Feb 2012 17:41:55 -0800 Subject: fix bug when closing the first document tab Signed-off-by: Ananya Sen --- js/controllers/document-controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/controllers') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 505daaba..7470bae2 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -309,7 +309,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, if(this.activeDocument.uuid === id && this._documents.length > 0) {//closing the active document tab var nextDocumentIndex = -1 ; if((this._documents.length > 0) && (closeDocumentIndex === 0)){ - nextDocumentIndex = 1; + nextDocumentIndex = 0; }else if((this._documents.length > 0) && (closeDocumentIndex > 0)){ nextDocumentIndex = closeDocumentIndex - 1; } -- cgit v1.2.3 From 8974ecd564563a991ff96f9cb6d47da172174242 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 22 Feb 2012 00:49:47 -0800 Subject: local storage integration and versioning - Fixed the splitters Signed-off-by: Valerio Virgillito --- js/controllers/local-storage-controller.js | 51 +++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 11 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/local-storage-controller.js b/js/controllers/local-storage-controller.js index 6963b245..ea763cff 100755 --- a/js/controllers/local-storage-controller.js +++ b/js/controllers/local-storage-controller.js @@ -7,7 +7,46 @@ 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; -exports.LocalStorage = Montage.create( Montage, { +exports.LocalStorage = Montage.create( Component, { + + canStore: { + value: null + }, + + deserializedFromTemplate: { + value: function() { + this.canStore = window.localStorage; + this.application.localStorage = this; + + // Redefine setItem and getItem if local storage is not available. + if(!this.canStore) { + this._getItem = function() { + console.log("Local Storage is not supported on your browser"); + return ""; + }; + + this._setItem = function() { + console.log("Local Storage is not supported on your browser"); + return false; + } + } + } + }, + + _getItem: { + value: function(key) { + var value = window.localStorage.getItem("ninja-" + key); + if(value !== null) value = JSON.parse(value); + + return value; + } + }, + + _setItem: { + value: function(key, value) { + window.localStorage.setItem("ninja-" + key, JSON.stringify(value)); + } + }, getItem: { value: function(item) { @@ -22,16 +61,6 @@ exports.LocalStorage = Montage.create( Montage, { return null; } - /* - if (window.localStorage) { - this.getItem = function(item) { - return window.localStorage.getItem(item); - }(item); - } else { - alert("Local Storage is not supported on your browser"); - - } - */ } }, -- cgit v1.2.3 From 593b2c954cf507bcb61d27f18d63b1406e7364c4 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 22 Feb 2012 22:47:25 -0800 Subject: Cleaning up and commenting CSS IO --- js/controllers/document-controller.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'js/controllers') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 48e33267..a6f600cc 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -59,6 +59,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.eventManager.addEventListener("executeNewFile", this, false); this.eventManager.addEventListener("executeSave", this, false); this.eventManager.addEventListener("executeSaveAs", this, false); + this.eventManager.addEventListener("executeSaveAll", this, false); this.eventManager.addEventListener("recordStyleChanged", this, false); @@ -129,6 +130,16 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } } }, + //////////////////////////////////////////////////////////////////// + //TODO: Check for appropiate structures + handleExecuteSaveAll: { + value: function(event) { + if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ + //Text and HTML document classes should return the same save object for fileSave + this.application.ninja.ioMediator.fileSave(this.activeDocument.saveAll(), this.fileSaveResult.bind(this)); + } + } + }, //////////////////////////////////////////////////////////////////// handleExecuteSaveAs: { value: function(event) { -- cgit v1.2.3 From 950bb79b1907e4f97735bed1430401dfd797fb0d Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 22 Feb 2012 23:28:49 -0800 Subject: App mode checking fix Added a way to check for the app to be served over http/https to prevent from adding webRequest events on app load. --- js/controllers/document-controller.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 77ae67a1..3a77ed5f 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -86,9 +86,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, // handleAppLoaded: { value: function() { - //Adding an intercept to resources loaded to ensure user assets load from cloud simulator - if (window.chrome.app.isInstalled) { - chrome.webRequest.onBeforeRequest.addListener(this.handleWebRequest.bind(this), {urls: [""]}, ["blocking"]); + //Checking for app not to be loaded via http/https to add app only listener + if (window.location.protocol !== 'http:' && window.location.protocol !== 'https:') { + //Adding an intercept to resources loaded to ensure user assets load from cloud simulator + chrome.webRequest.onBeforeRequest.addListener(this.handleWebRequest.bind(this), {urls: [""]}, ["blocking"]); } } }, -- cgit v1.2.3 From 7283884c39df537694b21419a3ea9e3ca7793b4b Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 23 Feb 2012 13:43:35 -0800 Subject: switch html document - re-initialize draw-utils and snap-manager on opening a document and while switching documents Signed-off-by: Ananya Sen --- js/controllers/document-controller.js | 6 +++--- js/controllers/elements/element-controller.js | 6 +++++- js/controllers/selection-controller.js | 9 +++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 48e33267..f323ed99 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -321,7 +321,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, // Event Detail: Contains the current ActiveDocument _onOpenDocument: { value: function(doc){ - //var data = DocumentManager.activeDocument; + this.application.ninja.currentDocument = doc; this._hideCurrentDocument(); this.application.ninja.stage.stageView.hideOtherDocuments(doc.uuid); @@ -405,7 +405,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function() { if(this.activeDocument) { if(this.activeDocument.currentView === "design"){ - this.application.ninja.stage.saveScroll(); + this.activeDocument.saveAppState(); this.activeDocument.container.parentNode.style["display"] = "none"; this.application.ninja.stage.hideCanvas(true); this.application.ninja.stage.stageView.hideRulers(); @@ -422,7 +422,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.restoreScroll(); + this.activeDocument.restoreAppState(); this.application.ninja.stage.hideCanvas(false); this.application.ninja.stage.stageView.showRulers(); }else{ diff --git a/js/controllers/elements/element-controller.js b/js/controllers/elements/element-controller.js index ac14def4..d6f2bc56 100755 --- a/js/controllers/elements/element-controller.js +++ b/js/controllers/elements/element-controller.js @@ -27,7 +27,11 @@ var ElementController = exports.ElementController = Montage.create(NJComponent, getProperty: { value: function(el, prop, fallbackOnComputed, isStageElement) { - return this.application.ninja.stylesController.getElementStyle(el, prop, fallbackOnComputed, isStageElement); + if(el.nodeType !== 3){ + return this.application.ninja.stylesController.getElementStyle(el, prop, fallbackOnComputed, isStageElement); + }else{ + return null; + } } }, diff --git a/js/controllers/selection-controller.js b/js/controllers/selection-controller.js index d69b53e0..f50762f3 100755 --- a/js/controllers/selection-controller.js +++ b/js/controllers/selection-controller.js @@ -58,6 +58,7 @@ exports.SelectionController = Montage.create(Component, { handleOpenDocument: { value: function() { // Handle initializing the selection array here. + this.initWithDocument([]); } }, @@ -70,6 +71,14 @@ exports.SelectionController = Montage.create(Component, { if(currentSelectionArray.length >= 1) { this._selectedItems = currentSelectionArray; this._isDocument = false; + + + + this.application.ninja.selectedElements = currentSelectionArray; + NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument} ); + + + } } -- cgit v1.2.3 From 23b4bbd13345ecd5c00fda60b995a7fb2aab317c Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 23 Feb 2012 15:08:21 -0800 Subject: Fixing document mode check --- js/controllers/document-controller.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 3a77ed5f..d5d0cf42 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -86,8 +86,12 @@ var DocumentController = exports.DocumentController = Montage.create(Component, // handleAppLoaded: { value: function() { - //Checking for app not to be loaded via http/https to add app only listener - if (window.location.protocol !== 'http:' && window.location.protocol !== 'https:') { + //Checking for app to be loaded through extension + var check; + if (chrome && chrome.app) { + check = chrome.app.getDetails(); + } + if (check !== null) { //Adding an intercept to resources loaded to ensure user assets load from cloud simulator chrome.webRequest.onBeforeRequest.addListener(this.handleWebRequest.bind(this), {urls: [""]}, ["blocking"]); } -- cgit v1.2.3 From 85d59d57ea556b114c5cad9b2ec67ccc27119380 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 24 Feb 2012 12:05:16 -0800 Subject: - added flag for timeline to identify new file flow - added switchDocument event for timeline Signed-off-by: Ananya Sen --- js/controllers/document-controller.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'js/controllers') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index e221df68..714d1404 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -195,6 +195,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value:function(doc){ var response = doc || null;//default just for testing if(!!response && response.success && (response.status!== 500) && !!response.uri){ + this.creatingNewFile = true;//flag for timeline to identify new file flow this.application.ninja.ioMediator.fileOpen(response.uri, this.openFileCallback.bind(this)); }else if(!!response && !response.success){ //Todo: restrict directory path to the sandbox, in the dialog itself @@ -222,6 +223,11 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value:function(response){ //TODO: Add UI to handle error codes, shouldn't be alert windows if(!!response && (response.status === 204)) { + + if((typeof this.creatingNewFile === 'undefined') || (this.creatingNewFile !== true)){//not from new file flow + this.creatingNewFile = false; + } + //Sending full response object this.openDocument(response); } else if (!!response && (response.status === 404)){ -- cgit v1.2.3 From f97080989ee988c1e613915c2d246dc17b104b3b Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Fri, 24 Feb 2012 13:27:33 -0800 Subject: clearing the old local setting and using the new version/prefix local settings. Signed-off-by: Valerio Virgillito --- js/controllers/local-storage-controller.js | 42 +++++++----------------------- 1 file changed, 10 insertions(+), 32 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/local-storage-controller.js b/js/controllers/local-storage-controller.js index ea763cff..1388f3e5 100755 --- a/js/controllers/local-storage-controller.js +++ b/js/controllers/local-storage-controller.js @@ -20,20 +20,25 @@ exports.LocalStorage = Montage.create( Component, { // Redefine setItem and getItem if local storage is not available. if(!this.canStore) { - this._getItem = function() { + this.getItem = function() { console.log("Local Storage is not supported on your browser"); return ""; }; - this._setItem = function() { + this.setItem = function() { console.log("Local Storage is not supported on your browser"); return false; } } + + // Temporary clear the local storage if we find the version key + if(window.localStorage.version) { + window.localStorage.clear(); + } } }, - _getItem: { + getItem: { value: function(key) { var value = window.localStorage.getItem("ninja-" + key); if(value !== null) value = JSON.parse(value); @@ -42,38 +47,11 @@ exports.LocalStorage = Montage.create( Component, { } }, - _setItem: { + setItem: { value: function(key, value) { window.localStorage.setItem("ninja-" + key, JSON.stringify(value)); - } - }, - - getItem: { - value: function(item) { - var item; - if (window.localStorage) { - item = window.localStorage.getItem(item); - if(item !== null) return JSON.parse(item) - return null; - } else { - alert("Local Storage is not supported on your browser"); - return null; - } - - } - }, - - setItem: { - value: function(item, value) { - if (window.localStorage) { - window.localStorage.setItem(item, JSON.stringify(value)); - return true; - } else { - alert("Local Storage is not supported on your browser"); - return false; - } + return value; } } - }); \ No newline at end of file -- cgit v1.2.3 From b056b4bef5982466d80d72e5cbb31e63087990e1 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 24 Feb 2012 15:30:55 -0800 Subject: - added closeDocument event for timeline - minor bug fixes Signed-off-by: Ananya Sen --- js/controllers/document-controller.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'js/controllers') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 714d1404..02031922 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -338,6 +338,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.application.ninja.stage.hideCanvas(true); } + + NJevent("closeDocument", doc.uri); + + doc=null; } }, -- cgit v1.2.3