Skip to content

Commit d841aa8

Browse files
committed
Revamp the client interface naming and other details.
The main change is to make the interface less implementation-defined, so the UI decisions are left for the UI code, not baked into the naming. This also adds some of changes needed for #1209, but does not implement it.
1 parent 2011346 commit d841aa8

File tree

5 files changed

+77
-47
lines changed

5 files changed

+77
-47
lines changed

docs/ClientInterface.md

+36-20
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ running in.
2424
These are messages that are sent by the program to its parent frame, to be
2525
handled by the UI:
2626

27-
### `{type: 'message', msgType: t, str: s}`
27+
### `{type: 'consoleOut', msgType: t, str: s}`
2828

2929
This indicates output can be displayed in an information console. Programs
3030
redirect stdout, stderr, and debug output to this. The `type` attribute
@@ -34,47 +34,63 @@ is one of `log`, `warning`, or `error`.
3434

3535
This indicates that the program has started running.
3636

37-
### `{type: 'showCanvas'}
37+
### `{type: 'showGraphics'}
3838

3939
This indicates that the program needs to be visible. Until this message
4040
is sent, the UI may hide the frame where the program is running, assuming
4141
that it will not display anything.
4242

43-
### `{type: 'initDebug'}`
43+
### `{type: 'debugReady'}`
4444

4545
This indicates that the program is ready to handle messages from the
4646
inspection debugger.
4747

48-
### `{type: 'openTreeDialog', nodeId: id, fullPic: pic}`
48+
### `{type: 'debugActive', fullPic: pic}`
4949

5050
This indicates that the program has paused and is ready to communicate
51-
with the inspection debugger. The `nodeId` attribute gives the id of
52-
the node in the expression tree that should be selected. If present,
53-
the `fullPic` attribute gives the entire expression tree. (See the
54-
later section for the structure of the expression tree.)
51+
with the inspection debugger. The `fullPic` attribute gives the current
52+
expression tree. (See the later section for the structure of the
53+
expression tree.)
5554

56-
This may be called many times during a pause. The first time, it
57-
always includes the `fullPic` attribute. After that, `fullPic` may be
58-
omitted for performance, and should be assumed to be the same as the
59-
last call.
60-
61-
### `{type: 'destroyTreeDialog'}`
55+
### `{type: 'debugFinished'}`
6256

6357
This indicates that the program has stopped cooperating with the
6458
inspection debugger, and continued running. The UI may wish to stop
6559
displaying debugger controls.
6660

61+
### `{type: 'nodeClicked', nodeId: id}`
62+
63+
This indicates that a node was clicked on the program output while
64+
debugging was active. The UI can respond as it chooses.
65+
66+
If id is -1, this indicates that the click wasn't on any node.
67+
68+
### `{type: 'nodeHovered', nodeId: id}`
69+
70+
This indicates that a node was hovered over with the pointer on the
71+
program output while debugging was active. The UI can respond as it
72+
chooses.
73+
74+
If id is -1, this indicates that the pointer is no longer hovering
75+
over any node.
76+
6777
## Messages from UI to program
6878

6979
These are messages that are sent by the UI to the program, to
7080
influence its behavior.
7181

72-
### `{type: 'canvasShown'}`
82+
### `{type: 'graphicsShown'}`
7383

7484
This informs the program that its frame is now visible. It may want to
7585
respond by continuing to run behavior that assumes it is visible.
7686

77-
### `{type: 'highlight', nodeId: id}`
87+
### `{type: 'debugSelect', nodeId: id}`
88+
89+
This instructs the program to select the portion of the picture
90+
corresponding to the `nodeId` attribute. If the `nodeId` attribute is
91+
-1, then the selection should be cancelled.
92+
93+
### `{type: 'debugHighlight', nodeId: id}`
7894

7995
This instructs the program to highlight in its output the portion of
8096
the picture corresponding to the `nodeId` attribute. If the `nodeId`
@@ -84,11 +100,11 @@ attribute is -1, then the highlight should be cancelled.
84100

85101
This instructs the program to enter debug mode, freezing its normal
86102
functions and interacting with the debugger. The program will respond
87-
by immediately sending a `openTreeDialog` message back, containing a
88-
`fullPic` attribute as well as `nodeId`.
103+
by immediately sending a `debugActive` message back with the current
104+
expression tree.
89105

90-
### `{type: 'cancelDebug'}`
106+
### `{type: 'stopDebug'}`
91107

92108
This instructs the program to leave debug mode and resume its normal
93109
functions. The program will acknowledge that it has done so by sending
94-
a `destroyTreeDialog` message.
110+
a `debugFinished` message.

web/js/codeworld.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ function formatSource() {
815815

816816
function stopRun() {
817817
if (window.debugActive) {
818-
document.getElementById('runner').contentWindow.postMessage({type: 'cancelDebug'}, '*');
818+
document.getElementById('runner').contentWindow.postMessage({type: 'stopDebug'}, '*');
819819
destroyTreeDialog();
820820
}
821821
window.cancelCompile();
@@ -834,32 +834,32 @@ window.addEventListener('message', event => {
834834
showRequiredChecksInDialog(msg);
835835
}, 500);
836836
}
837-
} else if (event.data.type === 'showCanvas') {
837+
} else if (event.data.type === 'showGraphics') {
838838
const runner = document.getElementById('runner');
839839
runner.style.display = '';
840840
runner.focus();
841841
runner.contentWindow.focus();
842-
runner.contentWindow.postMessage({type: 'canvasShown'}, '*');
843-
} else if (event.data.type === 'message') {
842+
runner.contentWindow.postMessage({type: 'graphicsShown'}, '*');
843+
} else if (event.data.type === 'consoleOut') {
844844
if (event.data.str !== '') printMessage(event.data.msgType, event.data.str);
845845
if (event.data.msgType === 'error') markFailed();
846846
} else if (event.data.type === 'updateUI') {
847847
updateUI();
848-
} else if (event.data.type === 'initDebug') {
848+
} else if (event.data.type === 'debugReady') {
849849
window.debugAvailable = true;
850850
updateUI();
851-
} else if (event.data.type === 'openTreeDialog') {
851+
} else if (event.data.type === 'debugActive') {
852852
window.debugActive = true;
853853
updateUI();
854-
} else if (event.data.type === 'destroyTreeDialog') {
854+
} else if (event.data.type === 'debugFinished') {
855855
window.debugActive = false;
856856
updateUI();
857857
}
858858
});
859859

860860
function inspect() {
861861
if (window.debugActive) {
862-
document.getElementById('runner').contentWindow.postMessage({type: 'cancelDebug'}, '*');
862+
document.getElementById('runner').contentWindow.postMessage({type: 'stopDebug'}, '*');
863863
} else {
864864
document.getElementById('runner').contentWindow.postMessage({type: 'startDebug'}, '*');
865865
}

web/js/debugmode.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@
5959
});
6060

6161
debugHighlightShape(true, nodeId);
62+
parent.postMessage({type: 'nodeHovered', nodeId: nodeId}, '*');
6263
}
6364
});
6465

6566
canvas.addEventListener('mouseout', evt => {
6667
if (active) {
6768
debugHighlightShape(true, -1);
69+
parent.postMessage({type: 'nodeHovered', nodeId: -1}, '*');
6870
}
6971
});
7072

@@ -75,14 +77,12 @@
7577
y: evt.clientY
7678
});
7779

78-
if (nodeId >= 0) {
79-
parent.postMessage({type: 'openTreeDialog', nodeId: nodeId}, '*');
80-
}
80+
parent.postMessage({type: 'nodeClicked', nodeId: nodeId}, '*');
8181
}
8282
});
8383

8484
if (parent) {
85-
parent.postMessage({type: 'initDebug'}, '*');
85+
parent.postMessage({type: 'debugReady'}, '*');
8686
}
8787
}
8888
}
@@ -93,23 +93,27 @@
9393
debugSetActive(true);
9494
debugHighlightShape(true, -1);
9595

96-
parent.postMessage({type: 'openTreeDialog', fullPic: debugGetPicture(), nodeId: 0}, '*');
96+
parent.postMessage({type: 'debugActive', fullPic: debugGetPicture()}, '*');
9797
}
9898

9999
function stopDebug() {
100100
active = false;
101101
debugSetActive(false);
102102
debugHighlightShape(true, -1);
103103

104-
parent.postMessage({type: 'destroyTreeDialog'}, '*');
104+
parent.postMessage({type: 'debugFinished'}, '*');
105105
}
106106

107107
window.addEventListener('message', event => {
108108
if (!event.data.type) return;
109109

110-
if (event.data.type === 'highlight') {
110+
if (event.data.type === 'debugHighlight') {
111111
if (active) debugHighlightShape(true, event.data.nodeId);
112-
} else if (event.data.type === 'cancelDebug') {
112+
} else if (event.data.type === 'debugSelect') {
113+
if (active) {
114+
// For now, do nothing. Selection is not implemented.
115+
}
116+
} else if (event.data.type === 'stopDebug') {
113117
stopDebug();
114118
} else if (event.data.type === 'startDebug') {
115119
startDebug();

web/js/run.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ window.hasObservableOutput = false;
2626
window.addEventListener('message', event => {
2727
if (!event.data.type) return;
2828

29-
if (event.data.type === 'canvasShown') {
29+
if (event.data.type === 'graphicsShown') {
3030
window.dispatchEvent(new Event('resize'));
3131
}
3232
});
@@ -52,7 +52,7 @@ function addMessage(type, str) {
5252
}
5353

5454
if (window.parent) {
55-
window.parent.postMessage({type: 'message', msgType: type, str: str}, '*');
55+
window.parent.postMessage({type: 'consoleOut', msgType: type, str: str}, '*');
5656
return;
5757
}
5858
} catch (e) {
@@ -81,7 +81,7 @@ function showCanvas() {
8181
return;
8282
}
8383

84-
window.parent.postMessage({type: 'showCanvas'}, '*');
84+
window.parent.postMessage({type: 'showGraphics'}, '*');
8585
} catch (e) {
8686
// Ignore, and assume the canvas is already shown.
8787
}

web/js/treedialog.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,17 @@
191191

192192
function highlight(nodeId) {
193193
const runner = document.getElementById('runner');
194-
runner.contentWindow.postMessage({type: 'highlight', nodeId: nodeId}, '*');
194+
runner.contentWindow.postMessage({type: 'debugHighlight', nodeId: nodeId}, '*');
195+
}
196+
197+
function select(nodeId) {
198+
const runner = document.getElementById('runner');
199+
runner.contentWindow.postMessage({type: 'debugSelect', nodeId: nodeId}, '*');
195200
}
196201

197202
function cancelDebug() {
198203
const runner = document.getElementById('runner');
199-
runner.contentWindow.postMessage({type: 'cancelDebug'}, '*');
204+
runner.contentWindow.postMessage({type: 'stopDebug'}, '*');
200205
}
201206

202207
function initTreeDialog(pic) {
@@ -223,11 +228,13 @@
223228
}
224229
window.initTreeDialog = initTreeDialog;
225230

226-
function openTreeDialog(id) {
231+
function selectNode(id) {
227232
if (!open) {
228233
openDialog();
229234
}
230235

236+
focus(id);
237+
231238
const picture = getPicNode(id);
232239
currentPic = picture;
233240

@@ -237,7 +244,6 @@
237244

238245
dialog.dialog('option', 'title', picture.name);
239246
}
240-
window.openTreeDialog = openTreeDialog;
241247

242248
function closeTreeDialog() {
243249
closeDialog();
@@ -260,10 +266,14 @@
260266
window.addEventListener('message', event => {
261267
if (!event.data.type) return;
262268

263-
if (event.data.type === 'openTreeDialog') {
264-
if (event.data.fullPic) initTreeDialog(event.data.fullPic);
265-
openTreeDialog(event.data.nodeId);
266-
} else if (event.data.type === 'destroyTreeDialog') {
269+
if (event.data.type === 'debugActive') {
270+
initTreeDialog(event.data.fullPic);
271+
selectNode(0);
272+
} if (event.data.type === 'nodeClicked') {
273+
selectNode(event.data.nodeId);
274+
} if (event.data.type === 'nodeHovered') {
275+
// For now, do nothing.
276+
} else if (event.data.type === 'debugFinished') {
267277
destroyTreeDialog();
268278
}
269279
});

0 commit comments

Comments
 (0)