aboutsummaryrefslogtreecommitdiff
path: root/js/controllers
diff options
context:
space:
mode:
authorJose Antonio Marquez Russo2012-02-22 14:18:39 -0800
committerJose Antonio Marquez Russo2012-02-22 14:18:39 -0800
commite150cea29af96c4d57e3f6cd2ecda0a3c86f366d (patch)
treef3410214d1049514322127cf8256fee2ab7f420c /js/controllers
parent5da4627fe899c03e885d10a77a5e33bb15875504 (diff)
parentdbf0ca5637a3bca87c21c65ada47f8a4d794f78c (diff)
downloadninja-e150cea29af96c4d57e3f6cd2ecda0a3c86f366d.tar.gz
Merge pull request #16 from ananyasen/FileIO
FileIO branch pull request
Diffstat (limited to 'js/controllers')
-rwxr-xr-xjs/controllers/document-controller.js41
-rwxr-xr-xjs/controllers/styles-controller.js44
2 files changed, 50 insertions, 35 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index 7491ef9f..48e33267 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -58,6 +58,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
58 this.eventManager.addEventListener("executeFileOpen", this, false); 58 this.eventManager.addEventListener("executeFileOpen", this, false);
59 this.eventManager.addEventListener("executeNewFile", this, false); 59 this.eventManager.addEventListener("executeNewFile", this, false);
60 this.eventManager.addEventListener("executeSave", this, false); 60 this.eventManager.addEventListener("executeSave", this, false);
61 this.eventManager.addEventListener("executeSaveAs", this, false);
61 62
62 this.eventManager.addEventListener("recordStyleChanged", this, false); 63 this.eventManager.addEventListener("recordStyleChanged", this, false);
63 64
@@ -100,33 +101,47 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
100 handleExecuteFileOpen: { 101 handleExecuteFileOpen: {
101 value: function(event) { 102 value: function(event) {
102 var pickerSettings = event._event.settings || {}; 103 var pickerSettings = event._event.settings || {};
103 pickerSettings.callback = this.openFileWithURI.bind(this); 104 if (this.application.ninja.coreIoApi.cloudAvailable()) {
104 pickerSettings.pickerMode = "read"; 105 pickerSettings.callback = this.openFileWithURI.bind(this);
105 pickerSettings.inFileMode = true; 106 pickerSettings.pickerMode = "read";
106 this.application.ninja.filePickerController.showFilePicker(pickerSettings); 107 pickerSettings.inFileMode = true;
108 this.application.ninja.filePickerController.showFilePicker(pickerSettings);
109 }
107 } 110 }
108 }, 111 },
109 112
110 handleExecuteNewFile: { 113 handleExecuteNewFile: {
111 value: function(event) { 114 value: function(event) {
112 var newFileSettings = event._event.settings || {}; 115 var newFileSettings = event._event.settings || {};
113 newFileSettings.callback = this.createNewFile.bind(this); 116 if (this.application.ninja.coreIoApi.cloudAvailable()) {
114 this.application.ninja.newFileController.showNewFileDialog(newFileSettings); 117 newFileSettings.callback = this.createNewFile.bind(this);
118 this.application.ninja.newFileController.showNewFileDialog(newFileSettings);
119 }
115 } 120 }
116 }, 121 },
117
118
119 //////////////////////////////////////////////////////////////////// 122 ////////////////////////////////////////////////////////////////////
120 //TODO: Check for appropiate structures 123 //TODO: Check for appropiate structures
121 handleExecuteSave: { 124 handleExecuteSave: {
122 value: function(event) { 125 value: function(event) {
123 if(!!this.activeDocument){ 126 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
124 //Text and HTML document classes should return the same save object for fileSave 127 //Text and HTML document classes should return the same save object for fileSave
125 this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); 128 this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this));
126 } 129 }
127 } 130 }
128 }, 131 },
129 //////////////////////////////////////////////////////////////////// 132 ////////////////////////////////////////////////////////////////////
133 handleExecuteSaveAs: {
134 value: function(event) {
135 var saveAsSettings = event._event.settings || {};
136 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
137 saveAsSettings.fileName = this.activeDocument.name;
138 saveAsSettings.folderUri = this.activeDocument.uri.substring(0, this.activeDocument.uri.lastIndexOf("/"));
139 //add callback
140 this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings);
141 }
142 }
143 },
144
130 // 145 //
131 fileSaveResult: { 146 fileSaveResult: {
132 value: function (result) { 147 value: function (result) {
@@ -285,7 +300,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
285 if(this.activeDocument.uuid === id && this._documents.length > 0) {//closing the active document tab 300 if(this.activeDocument.uuid === id && this._documents.length > 0) {//closing the active document tab
286 var nextDocumentIndex = -1 ; 301 var nextDocumentIndex = -1 ;
287 if((this._documents.length > 0) && (closeDocumentIndex === 0)){ 302 if((this._documents.length > 0) && (closeDocumentIndex === 0)){
288 nextDocumentIndex = 1; 303 nextDocumentIndex = 0;
289 }else if((this._documents.length > 0) && (closeDocumentIndex > 0)){ 304 }else if((this._documents.length > 0) && (closeDocumentIndex > 0)){
290 nextDocumentIndex = closeDocumentIndex - 1; 305 nextDocumentIndex = closeDocumentIndex - 1;
291 } 306 }
diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js
index 885d710f..662816f5 100755
--- a/js/controllers/styles-controller.js
+++ b/js/controllers/styles-controller.js
@@ -317,7 +317,7 @@ var stylesController = exports.StylesController = Montage.create(Component, {
317 isInlineStyle : true, 317 isInlineStyle : true,
318 style : element.style 318 style : element.style
319 }; 319 };
320 320
321 ///// Now splice it into the matched rules 321 ///// Now splice it into the matched rules
322 ///// By inserting the inline style at the beginning, 322 ///// By inserting the inline style at the beginning,
323 ///// we keep the correct order of specificity 323 ///// we keep the correct order of specificity
@@ -572,37 +572,36 @@ var stylesController = exports.StylesController = Montage.create(Component, {
572 win = element.ownerDocument.defaultView, 572 win = element.ownerDocument.defaultView,
573 self = this; 573 self = this;
574 574
575 if(!win) {
576 return null;
577 }
578
579 if(!omitPseudos) { 575 if(!omitPseudos) {
580 pseudos.concat(['link', 'visited', 'active', 'hover', 'focus', 'first-letter', 576 pseudos.concat(['link', 'visited', 'active', 'hover', 'focus', 'first-letter',
581 'first-line', 'first-child', 'before', 'after', 'lang', 'target']); 577 'first-line', 'first-child', 'before', 'after', 'lang', 'target']);
582 } 578 }
583 579
584 pseudos.forEach(function(pseudo) { 580 try {
585 rules = rules.concat(nj.toArray(win.getMatchedCSSRules(element, pseudo)).filter(function(rule) { 581 pseudos.forEach(function(pseudo) {
586 //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet, 582 rules = rules.concat(nj.toArray(win.getMatchedCSSRules(element, pseudo)).filter(function(rule) {
587 //// or only use rules for other stylesheets 583 //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet,
588 584 //// or only use rules for other stylesheets
589 var sheetId = (rule.parentStyleSheet) ? rule.parentStyleSheet.ownerNode.id : null,
590 isStageStyleSheet = sheetId === this.CONST.STAGE_SHEET_ID;
591 585
592 ///// filter out (return false) depending on flag 586 var sheetId = (rule.parentStyleSheet) ? rule.parentStyleSheet.ownerNode.id : null,
593 if(useStageStyleSheet && !isStageStyleSheet) { return false; } 587 isStageStyleSheet = sheetId === this.CONST.STAGE_SHEET_ID;
594 if(!useStageStyleSheet && isStageStyleSheet) { return false; }
595 588
596 ///// Non-filter code - just assigning specificity to the rule 589 ///// filter out (return false) depending on flag
597 if(!rule[this.CONST.SPECIFICITY_KEY]) { 590 if(useStageStyleSheet && !isStageStyleSheet) { return false; }
598 rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText); 591 if(!useStageStyleSheet && isStageStyleSheet) { return false; }
599 }
600 592
601 return true; 593 ///// Non-filter code - just assigning specificity to the rule
594 if(!rule[this.CONST.SPECIFICITY_KEY]) {
595 rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText);
596 }
602 597
603 }, this)); 598 return true;
604 }, this);
605 599
600 }, this));
601 }, this);
602 } catch(ERROR) {
603 console.warn('StylesController::getMatchingRules - Un-attached element queried.');
604 }
606 ///// Function for sorting by specificity values 605 ///// Function for sorting by specificity values
607 function sorter(ruleA, ruleB) { 606 function sorter(ruleA, ruleB) {
608 var a, b, order, sheetAIndex, sheetBIndex, ruleAIndex, ruleBIndex; 607 var a, b, order, sheetAIndex, sheetBIndex, ruleAIndex, ruleBIndex;
@@ -981,6 +980,7 @@ var stylesController = exports.StylesController = Montage.create(Component, {
981 ///// Pass "true" to method to return an override object, which 980 ///// Pass "true" to method to return an override object, which
982 ///// has the rule to override, and whether the !important flag is needed 981 ///// has the rule to override, and whether the !important flag is needed
983 dominantRule = this.getDominantRuleForElement(element, property, true, isStageElement); 982 dominantRule = this.getDominantRuleForElement(element, property, true, isStageElement);
983
984 } 984 }
985 985
986 ///// Did we find a dominant rule? 986 ///// Did we find a dominant rule?