This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
variables.js
298 lines (249 loc) · 9.63 KB
/
variables.js
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
define(function(require, exports, module) {
main.consumes = [
"DebugPanel", "ui", "util", "debugger", "callstack", "panels", "layout"
];
main.provides = ["variables"];
return main;
function main(options, imports, register) {
var DebugPanel = imports.DebugPanel;
var ui = imports.ui;
var callstack = imports.callstack;
var debug = imports.debugger;
var util = imports.util;
var layout = imports.layout;
var panels = imports.panels;
var markup = require("text!./variables.xml");
var Tree = require("ace_tree/tree");
var TreeData = require("./variablesdp");
var TreeEditor = require("ace_tree/edit");
/***** Initialization *****/
var plugin = new DebugPanel("Ajax.org", main.consumes, {
caption: "Local Variables",
index: 300
});
var emit = plugin.getEmitter();
var activeFrame, dbg, cached = {};
var model, datagrid; // UI Elements
var loaded = false;
function load() {
if (loaded) return false;
loaded = true;
model = new TreeData();
model.emptyMessage = "No variables to display";
model.columns = [{
caption: "Variable",
value: "name",
defaultValue: "Scope",
width: "40%",
icon: true,
type: "tree"
}, {
caption: "Value",
value: "value",
width: "60%",
editor: "textbox"
}, {
caption: "Type",
value: "type",
width: "55"
}];
model.loadChildren = function(node, callback) {
emit("expand", {
node: node,
expand: callback
});
};
// Set and clear the dbg variable
debug.on("attach", function(e) {
dbg = e.implementation;
});
debug.on("detach", function(e) {
dbg = null;
});
debug.on("stateChange", function(e) {
plugin[e.action]();
});
callstack.on("scopeUpdate", function(e) {
updateScope(e.scope, e.variables);
});
callstack.on("framesLoad", function(e) {
// Clear the cached states of the variable datagrid
clearCache();
});
// When clicking on a frame in the call stack show it
// in the variables datagrid
callstack.on("frameActivate", function(e) {
// @todo reload the clicked frame recursively + keep state
loadFrame(e.frame);
}, plugin);
// Variables
plugin.on("expand", function(e) {
if (e.node.tagName == "variable") {
if (!e.node.children) return e.expand();
dbg.getProperties(e.node, function(err, properties) {
if (err) return console.error(err);
//updateVariable(e.node, properties);
e.expand();
});
}
// Local scope
// else if (e.scope.type == 1) {
// //updateScope(e.scope);
// e.expand();
// }
// Other scopes
else if (e.node.tagName == "scope") {
dbg.getScope(model.frame/*debug.activeFrame*/, e.node, function(err, vars) {
if (err) return console.error(err);
//updateScope(e.node, vars);
e.expand();
});
}
}, plugin);
}
var drawn;
function draw(options) {
if (drawn) return;
drawn = true;
// Create UI elements
ui.insertMarkup(options.aml, markup, plugin);
var datagridEl = plugin.getElement("datagrid");
datagrid = new Tree(datagridEl.$ext);
datagrid.setTheme({ cssClass: "blackdg" });
datagrid.setOption("maxLines", 200);
layout.on("eachTheme", function(e) {
var height = parseInt(ui.getStyleRule(".blackdg .row", "height"), 10) || 24;
// model.rowHeightInner = height - 1;
model.rowHeight = height;
if (e.changed) datagrid.resize(true);
});
datagrid.setDataProvider(model);
datagrid.edit = new TreeEditor(datagrid);
panels.on("afterAnimate", function(e) {
if (panels.isActive("debugger"))
datagrid && datagrid.resize();
});
datagridEl.on("contextmenu", function() {
return false;
});
datagrid.on("rename", function(e) {
var node = e.node;
var value = e.value;
var variable = node;
var oldValue = variable.value;
model.setAttribute(variable, "value", value);
function undo() {
model.setAttribute(variable, "value", oldValue);
}
// Set new value
dbg.setVariable(variable, value, debug.activeFrame, function(err) {
if (err)
return undo();
// Reload properties of the variable
dbg.getProperties(variable.parent, function() {
updateVariable(variable.parent);
emit("variableEdit", {
value: value,
oldValue: oldValue,
node: node,
variable: variable,
frame: activeFrame,
});
});
});
});
datagrid.on("beforeRename", function(e) {
if (!plugin.enabled)
return e.preventDefault();
if (!dbg.features.updateScopeVariables)
return e.preventDefault();
// Don't allow setting the value of scopes
if (e.node.tagName == "scope")
return e.preventDefault();
// Don't allow setting "this"
if (e.node.name == "this")
return e.preventDefault();
});
}
/***** Methods *****/
function loadFrame(frame) {
if (frame == activeFrame)
return;
model.frame = frame;
if (!frame) {
model.setRoot({});
}
else {
if (cached[frame.id])
model.setRoot(cached[frame.id]);
else {
model.setRoot([].concat(frame.variables, frame.scopes).filter(Boolean));
cached[frame.id] = model.root;
}
}
activeFrame = frame;
}
function updateNode(node, variable, oldVar) {
var isOpen = node.isOpen;
model.close(node, null, false);
if (isOpen)
model.open(node, null, false);
else
model._signal("change", node);
}
function updateScope(scope, variables) {
updateNode(scope);
}
function updateVariable(variable, properties, node) {
updateNode(variable);
}
function clearCache() {
cached = {};
}
/***** Lifecycle *****/
plugin.on("load", function() {
load();
plugin.once("draw", draw);
});
plugin.on("enable", function() {
drawn && datagrid.enable();
});
plugin.on("disable", function() {
drawn && datagrid.disable();
});
plugin.on("unload", function() {
loaded = false;
drawn = false;
});
/***** Register and define API *****/
/**
* The local variables and scopes panel for the
* {@link debugger Cloud9 debugger}.
*
* This panel displays the local variables and scopes to the user. A
* user can expand variables and scopes to inspect properties and
* variables and edit them.
*
* @singleton
* @extends DebugPanel
**/
plugin.freezePublicAPI({
/**
* @ignore
*/
get model() { return model; },
/**
* Sets the frame that the variables and scopes are displayed for.
* @param {debugger.Frame} frame The frame to display the variables and scopes from.
*/
loadFrame: loadFrame,
/**
* Clears the variable/scope cache
*/
clearCache: clearCache
});
register(null, {
variables: plugin
});
}
});