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 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