diff options
author | Pushkar Joshi | 2012-02-24 12:08:49 -0800 |
---|---|---|
committer | Pushkar Joshi | 2012-02-24 12:08:49 -0800 |
commit | 03ca7a5ed13c25faaa9100bb666e062fd15335e6 (patch) | |
tree | c51112223ceb9121cd595a60335eb2795215590f /js/controllers | |
parent | fcb12cc09eb3cd3b42bd215877ba18f449275b75 (diff) | |
parent | 053fc63a2950c7a5ee4ebf98033b64d474a3c46e (diff) | |
download | ninja-03ca7a5ed13c25faaa9100bb666e062fd15335e6.tar.gz |
Merge branch 'pentool' into brushtool
Conflicts:
imports/codemirror/mode/scheme/scheme.js
js/tools/BrushTool.js
Diffstat (limited to 'js/controllers')
16 files changed, 736 insertions, 23 deletions
diff --git a/js/controllers/color-controller.js b/js/controllers/color-controller.js index e3b15f1c..a6e41dd3 100644..100755 --- a/js/controllers/color-controller.js +++ b/js/controllers/color-controller.js | |||
@@ -322,7 +322,19 @@ exports.ColorController = Montage.create(Component, { | |||
322 | //Simple solid color | 322 | //Simple solid color |
323 | color = this.parseCssToColor(css); | 323 | color = this.parseCssToColor(css); |
324 | } | 324 | } |
325 | //Returning color object (or null if none) | 325 | // TODO - Hack for inconsistent color object -- some workflows set color.color and some color.value |
326 | if(color) | ||
327 | { | ||
328 | if(color.value && !color.color) | ||
329 | { | ||
330 | color.color = color.value; | ||
331 | } | ||
332 | else if(color.color && !color.value) | ||
333 | { | ||
334 | color.value = color.color; | ||
335 | } | ||
336 | } | ||
337 | //Returning color object (or null if none) | ||
326 | return color; | 338 | return color; |
327 | } | 339 | } |
328 | }, | 340 | }, |
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js new file mode 100755 index 00000000..1c9d9d59 --- /dev/null +++ b/js/controllers/document-controller.js | |||
@@ -0,0 +1,467 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | //////////////////////////////////////////////////////////////////////// | ||
8 | // | ||
9 | var Montage = require("montage/core/core").Montage, | ||
10 | Component = require("montage/ui/component").Component, | ||
11 | Uuid = require("montage/core/uuid").Uuid, | ||
12 | HTMLDocument = require("js/document/html-document").HTMLDocument, | ||
13 | TextDocument = require("js/document/text-document").TextDocument, | ||
14 | DocumentController; | ||
15 | //////////////////////////////////////////////////////////////////////// | ||
16 | // | ||
17 | var DocumentController = exports.DocumentController = Montage.create(Component, { | ||
18 | hasTemplate: { | ||
19 | value: false | ||
20 | }, | ||
21 | |||
22 | _documents: { | ||
23 | value: [] | ||
24 | }, | ||
25 | |||
26 | _hackRootFlag: { | ||
27 | value: false | ||
28 | }, | ||
29 | |||
30 | _activeDocument: { value: null }, | ||
31 | _iframeCounter: { value: 1, enumerable: false }, | ||
32 | _iframeHolder: { value: null, enumerable: false }, | ||
33 | _textHolder: { value: null, enumerable: false }, | ||
34 | _codeMirrorCounter: {value: 1, enumerable: false}, | ||
35 | |||
36 | activeDocument: { | ||
37 | get: function() { | ||
38 | return this._activeDocument; | ||
39 | }, | ||
40 | set: function(doc) { | ||
41 | if(!!this._activeDocument) this._activeDocument.isActive = false; | ||
42 | |||
43 | this._activeDocument = doc; | ||
44 | if(!!this._activeDocument){ | ||
45 | |||
46 | if(this._documents.indexOf(doc) === -1) this._documents.push(doc); | ||
47 | this._activeDocument.isActive = true; | ||
48 | if(!!this._activeDocument.editor){ | ||
49 | this._activeDocument.editor.focus(); | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | }, | ||
54 | |||
55 | deserializedFromTemplate: { | ||
56 | value: function() { | ||
57 | this.eventManager.addEventListener("appLoaded", this, false); | ||
58 | this.eventManager.addEventListener("executeFileOpen", this, false); | ||
59 | this.eventManager.addEventListener("executeNewFile", this, false); | ||
60 | this.eventManager.addEventListener("executeSave", this, false); | ||
61 | |||
62 | this.eventManager.addEventListener("recordStyleChanged", this, false); | ||
63 | |||
64 | } | ||
65 | }, | ||
66 | |||
67 | |||
68 | |||
69 | |||
70 | |||
71 | |||
72 | |||
73 | //////////////////////////////////////////////////////////////////// | ||
74 | // | ||
75 | handleWebRequest: { | ||
76 | value: function (request) { | ||
77 | if (this._hackRootFlag && request.url.indexOf('js/document/templates/montage-html') !== -1) { | ||
78 | //TODO: Optimize creating string | ||
79 | return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split('/')[request.url.split('/').length-1]}; | ||
80 | } | ||
81 | } | ||
82 | }, | ||
83 | //////////////////////////////////////////////////////////////////// | ||
84 | // | ||
85 | handleAppLoaded: { | ||
86 | value: function() { | ||
87 | //Checking for app to be loaded through extension | ||
88 | var check; | ||
89 | if (chrome && chrome.app) { | ||
90 | check = chrome.app.getDetails(); | ||
91 | } | ||
92 | if (check !== null) { | ||
93 | //Adding an intercept to resources loaded to ensure user assets load from cloud simulator | ||
94 | chrome.webRequest.onBeforeRequest.addListener(this.handleWebRequest.bind(this), {urls: ["<all_urls>"]}, ["blocking"]); | ||
95 | } | ||
96 | } | ||
97 | }, | ||
98 | //////////////////////////////////////////////////////////////////// | ||
99 | |||
100 | |||
101 | |||
102 | |||
103 | |||
104 | |||
105 | |||
106 | |||
107 | handleExecuteFileOpen: { | ||
108 | value: function(event) { | ||
109 | var pickerSettings = event._event.settings || {}; | ||
110 | pickerSettings.callback = this.openFileWithURI.bind(this); | ||
111 | pickerSettings.pickerMode = "read"; | ||
112 | pickerSettings.inFileMode = true; | ||
113 | this.application.ninja.filePickerController.showFilePicker(pickerSettings); | ||
114 | } | ||
115 | }, | ||
116 | |||
117 | handleExecuteNewFile: { | ||
118 | value: function(event) { | ||
119 | var newFileSettings = event._event.settings || {}; | ||
120 | newFileSettings.callback = this.createNewFile.bind(this); | ||
121 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); | ||
122 | } | ||
123 | }, | ||
124 | |||
125 | |||
126 | //////////////////////////////////////////////////////////////////// | ||
127 | //TODO: Check for appropiate structures | ||
128 | handleExecuteSave: { | ||
129 | value: function(event) { | ||
130 | if(!!this.activeDocument){ | ||
131 | //Text and HTML document classes should return the same save object for fileSave | ||
132 | this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); | ||
133 | } | ||
134 | } | ||
135 | }, | ||
136 | //////////////////////////////////////////////////////////////////// | ||
137 | // | ||
138 | fileSaveResult: { | ||
139 | value: function (result) { | ||
140 | if(result.status === 204){ | ||
141 | this.activeDocument.needsSave = false; | ||
142 | } | ||
143 | } | ||
144 | }, | ||
145 | |||
146 | createNewFile:{ | ||
147 | value:function(newFileObj){ | ||
148 | //console.log(newFileObj);//contains the template uri and the new file uri | ||
149 | if(!newFileObj) return; | ||
150 | this.application.ninja.ioMediator.fileNew(newFileObj.newFilePath, newFileObj.fileTemplateUri, this.openNewFileCallback.bind(this)); | ||
151 | |||
152 | if((newFileObj.fileExtension !== ".html") && (newFileObj.fileExtension !== ".htm")){//open code view | ||
153 | |||
154 | } else { | ||
155 | //open design view | ||
156 | } | ||
157 | } | ||
158 | }, | ||
159 | |||
160 | /** | ||
161 | * Public method | ||
162 | * doc contains: | ||
163 | * type : file type, like js, css, etc | ||
164 | * name : file name | ||
165 | * source : file content | ||
166 | * uri : file uri | ||
167 | */ | ||
168 | openNewFileCallback:{ | ||
169 | value:function(doc){ | ||
170 | var response = doc || null;//default just for testing | ||
171 | if(!!response && response.success && (response.status!== 5 |