summaryrefslogtreecommitdiff
path: root/swat2/scripting/client/regedit.js
blob: 555ba9fb90118074b233c3eefa73458f06b78628 (plain)
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
/*
	client side js functions for registry editing

	Copyright Andrew Tridgell 2005
	released under the GNU GPL Version 3 or later
*/


/*
  callback from the key enumeration call
*/
function __folder_keys(fParent, list) 
{
	var i;
	if (fParent.working == 1) {
		fParent.working = 0;
		fParent.removeAll();
	}
	for (i=0;i<list.length;i++) {
		var fChild;
		fChild = new QxTreeFolder(list[i]);
		fParent.add(fChild);
		fChild.binding = fParent.binding;
		if (fParent.reg_path == '\\') {
			fChild.reg_path = list[i];
		} else {
			fChild.reg_path = fParent.reg_path + '\\' + list[i];
		}
		fChild.working = 1;
		fChild.add(new QxTreeFolder('Working ...'));
		fChild.addEventListener("click", function() { 
			var el = this; __folder_click(el); 
		});
	}
	fParent.setOpen(1);
}

/*
  callback from the key enumeration call
*/
function __folder_values(fParent, list) 
{
	var i;
	if (list.length == 0) {
		return;
	}
	if (fParent.working == 1) {
		fParent.working = 0;
		fParent.removeAll();
	}
	for (i=0;i<list.length;i++) {
		var fChild;
		fChild = new QxTreeFile(list[i].name);
		fChild.parent = fParent;
		fChild.details = list[i];
		fParent.add(fChild);
	}
	fParent.setOpen(1);
}

/*
  called when someone clicks on a folder
*/
function __folder_click(node) 
{
	if (!node.populated) {
		node.populated = true;
		server_call_url("/scripting/server/regedit.esp", 'enum_keys', 
				function(list) { __folder_keys(node, list); }, 
				node.binding, node.reg_path);
		server_call_url("/scripting/server/regedit.esp", 'enum_values', 
				function(list) { __folder_values(node, list); }, 
				node.binding, node.reg_path);
	}
}

/* return a registry tree for the given server */
function __registry_tree(binding) 
{
	var tree = new QxTree("registry: " + binding);
	tree.binding = binding;
	tree.reg_path = "\\";
	tree.populated = false;
	with(tree) {
		setBackgroundColor(255);
		setBorder(QxBorder.presets.inset);
		setOverflow("scroll");
		setStyleProperty("padding", "2px");
		setWidth("50%");
		setHeight("90%");
		setTop("10%");
	}
	tree.addEventListener("click", function() { 
		var el = this; __folder_click(el); 
	});
	return tree;
}

/*
  the table of values
*/
function __values_table()
{
	var headings = new Array("Name", "Type", "Size", "Value");
	var table = document.createElement('table');
	table.border = "1";
	var body = document.createElement('tbody');
	table.appendChild(body);
	var th = document.createElement('th');
	for (var i=0;i<headings.length;i++) {
		var td = document.createElement('td');
		td.appendChild(document.createTextNode(headings[i]));
		th.appendChild(td);
	}
	body.appendChild(th);
	return table;
}

/*
  create a registry editing widget and return it as a object
*/
function regedit_widget(binding) 
{
	var fieldSet = new QxFieldSet();

	fieldSet.binding = binding;

	with(fieldSet) {
		setWidth("100%");
		setHeight("100%");
	};

	var gl = new QxGridLayout("auto,auto,auto,auto,auto", "50%,50%");
	gl.setEdge(0);
	gl.setCellPaddingTop(3);
	gl.setCellPaddingBottom(3);

	var t = __registry_tree(fieldSet.binding);

	function change_binding(e) {
		fieldSet.binding = e.getNewValue();
		srv_printf("changed binding to %s\\n", fieldSet.binding);
		gl.remove(t);
		t = __registry_tree(fieldSet.binding);
		gl.add(t, { row : 2, col : 1 });
	}

	var b = new QxTextField(fieldSet.binding);
	b.addEventListener("changeText", change_binding);

	var values = new __values_table();

	gl.add(b,      { row : 1, col : 1 });
	gl.add(t,      { row : 2, col : 1 });
//	gl.add(values, { row : 2, col : 2 });
	
	fieldSet.add(gl);

	return fieldSet;
};