forked from c9/cloud9
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathext.js
More file actions
211 lines (176 loc) · 6.25 KB
/
Copy pathext.js
File metadata and controls
211 lines (176 loc) · 6.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/**
* Extension manager for the Ajax.org Cloud IDE
*
* Modules that extend the functionality of the editing environment
* - Add menubuttons/menus
* - Add items to menus (optional show/hide toggle)
* - Add toolbar (optional show/hide toggle)
* - Add buttons to toolbar (optional show/hide toggle)
* - Add custom non-file tree items
* - Register an editor to the application for file extensions
* - Add features to existing editors
* - Add AML elements
* - Add layout modes
*
* @copyright 2010, Ajax.org B.V.
* @license GPLv3 <http://www.gnu.org/licenses/gpl.txt>
*/
require.def("core/ext", ["core/ide", "core/util"], function(ide, util) {
var ext;
return ext = {
//Extension types
GENERAL : 1,
defLength : 1,
extHandlers : {
1 : {
register : function(oExtension){
if (!oExtension.hook)
ext.initExtension(oExtension);
},
unregister : function(oExtension){}
}
},
extensions : [],
extLut : {},
commandsLut : {},
typeLut : {
1 : "General"
},
currentLayoutMode : null,
addType : function(defName, regHandler, unregHandler){
this[defName.toUpperCase()] = ++this.defLength;
this.extHandlers[this.defLength] = {
register : regHandler,
unregister : unregHandler
};
this.typeLut[this.defLength] = defName;
},
register : function(path, oExtension, force){
if (oExtension.registered)
return oExtension;
if (!mdlExt.queryNode("plugin[@path='" + path + "']"))
mdlExt.appendXml('<plugin type="' + this.typeLut[oExtension.type]
+ '" name="' + (oExtension.name || "") + '" path="' + path
+ '" dev="' + (oExtension.dev || "") + '" enabled="1" />');
else
mdlExt.setQueryValue("plugin[@path='" + path + "']/@enabled", 1);
if (oExtension.commands) {
for (var cmd in oExtension.commands)
oExtension.commands[cmd].ext = path;
apf.extend(this.commandsLut, oExtension.commands);
}
//Don't init general extensions that cannot live alone
if (!force && oExtension.type == this.GENERAL && !oExtension.alone) {
oExtension.path = path;
return oExtension;
}
oExtension.registered = true;
oExtension.path = path;
this.extHandlers[oExtension.type].register(oExtension);
this.extLut[path] = oExtension;
this.extensions.push(oExtension);
if (oExtension.hook)
oExtension.hook();
return oExtension;
},
unregister : function(oExtension, silent){
//Check exts that depend on oExtension
var using = oExtension.using;
if (using) {
var inUseBy = [];
for (var use, i = 0, l = using.length; i < l; i++) {
if ((use = using[i]).registered)
inUseBy.push(use.path);
}
if (inUseBy.length) {
//@todo move this to outside this function
if (!silent)
util.alert(
"Could not disable extension",
"Extension is still in use",
"This extension cannot be disabled, because it is still in use by the following extensions:<br /><br />"
+ " - " + inUseBy.join("<br /> - ")
+ "<br /><br /> Please disable those extensions first.");
return;
}
}
delete oExtension.registered;
this.extensions.remove(oExtension);
delete this.extLut[oExtension.path];
//Check commands to clean up
var commands = oExtension.commands;
if (commands) {
for (var cmd in commands) {
if (this.commandsLut[cmd])
delete this.commandsLut[cmd];
}
}
//Check deps to clean up
var deps = oExtension.deps;
if (deps) {
for (var dep, i = 0, l = deps.length; i < l; i++) {
dep = deps[i];
if (dep.registered && dep.type == this.GENERAL && !oExtension.alone)
this.unregister(dep, true);
}
}
this.extHandlers[oExtension.type].unregister(oExtension);
mdlExt.setQueryValue("plugin[@path='" + oExtension.path + "']/@enabled", 0);
if (oExtension.inited) {
oExtension.destroy();
delete oExtension.inited;
}
},
initExtension : function(oExtension, amlParent){
if (oExtension.inited)
return;
//Load markup
var markup = oExtension.markup;
if (markup) {
apf.document.body.insertMarkup(markup);
}
var deps = oExtension.deps;
if (deps) {
deps.each(function(dep){
if (!dep.registered)
ext.register(dep.path, dep, true);
(dep.using || (dep.using = [])).pushUnique(oExtension);
});
}
if (this.currentKeybindings) {
var name = oExtension.path.substr(oExtension.path.lastIndexOf("/") + 1),
keyBindings = this.currentKeybindings[name];
if (keyBindings)
oExtension.currentKeybindings = keyBindings;
}
oExtension.init(amlParent);
oExtension.inited = true;
ide.dispatchEvent("init." + oExtension.path, {
ext : oExtension
});
},
execCommand: function(cmd, data) {
cmd = (cmd || "").trim();
var oCmd = this.commandsLut[cmd];
if (!oCmd || !oCmd.ext)
return;
var oExt = require(oCmd.ext);
if (oExt && typeof oExt[cmd] == "function")
return oExt[cmd](data);
},
setLayoutMode : function(mode){
return;
if (this.currentLayoutMode)
this.currentLayoutMode.disable();
var module = this.extLut[mode];
if (!module) {
this.currentLayoutMode = null;
return false;
}
if (!module.inited)
this.initExtension(module);
module.enable();
this.currentLayoutMode = module;
}
};
});