This repository has been archived by the owner on Jan 14, 2021. It is now read-only.
/
event.go
169 lines (151 loc) · 4.75 KB
/
event.go
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
package blockly
import "github.com/gopherjs/gopherjs/js"
type EventId string
// Event --
// on the blockly side, events are raised with Blockly.Events.fire.
// there is no node "hierarchy" -- all listeners get all events.
type Event struct {
*js.Object // Blockly.Events.Abstract;
Type EventId `js:"type"`
BlockId string `js:"blockId"`
WorkspaceId string `js:"workspaceId"`
Group string `js:"group"`
RecordUndo bool `js:"recordUndo"`
}
func decodeEvent(obj *js.Object) (ret interface{}) {
evt := &Event{Object: obj}
switch evt.Type {
case "create":
ret = &BlockCreate{Event: evt}
case "delete":
ret = &BlockDelete{Event: evt}
case "change":
ret = &BlockChange{Event: evt}
case "move":
ret = &BlockMove{Event: evt}
case "var_create":
ret = &VarCreate{Event: evt}
case "var_delete":
ret = &VarDelete{Event: evt}
case "var_rename":
ret = &VarRename{Event: evt}
case "ui":
ret = &UiChange{Event: evt}
case "comment_create":
ret = &CommentChange{Event: evt}
case "comment_delete":
ret = &CommentDelete{Event: evt}
case "comment_change":
ret = &CommentChange{Event: evt}
case "comment_move":
ret = &CommentMove{Event: evt}
default:
ret = evt
}
return
}
// toJson
// fromJson(json js.M) {}
// isNull()
// run(foward bool)
// getEventWorkspace_()
// triggered after the block has been added to the workspace; the block object can be found via the event's blockId
type BlockCreate struct {
*Event
// xml *js.Object An XML tree defining the new block and any connected child blocks.
Ids *js.Object `js:"ids"` // An array containing the UUIDs of the new block and any connected child blocks.
}
type BlockDelete struct {
*Event
// oldXml *js.Object An XML tree defining the deleted block and any connected child blocks.
Ids *js.Object `js:"ids"` // An array containing the UUIDs of the deleted block and any connected child blocks.
}
// BlockChange -- when the status of a block has changed.
// ( note, changes to inputs are reported by BlockMove. )
type BlockChange struct {
*Event
// Element events include:
// collapsed - .collapsed status changed ( via setCollapsed )
// comment - comment text changed ( via setCommentText )
// disabled - disabled status changed ( via setDisabled )
// field - when checkbox, colour, dropdown, text input, variable, etc. ( via setValue )
// inline - inputs inline changed ( via setInputsInline )
// mutation - "a procedure definition changes its parameters". or workspaceChanged, -- via Blockly.Procedures.mutatateCallers.
Element string `js:"element"`
// Name of element affected
Name string `js:"name"`
OldValue *js.Object `js:"oldValue"`
NewValue *js.Object `js:"newValue"`
}
// BlockMove -- event when a block has been dragged/dropped into a new slot.
// for why this uses methods instead of properties see https://github.com/gopherjs/gopherjs/issues/617
type BlockMove struct {
*Event
// NewCoordinate *js.Object `js:"newCoordinate"` // X and Y coordinates if it is a top level block. Undefined if it has a parent.
// OldCoordinate *js.Object `js:"oldCoordinate"` // X and Y coordinates if it was a top level block. Undefined if it had a parent.
}
// NextParentId - UUID of new parent block. Empty if it is a top level block.
func (evt *BlockMove) NextParentId() (ret string) {
if p := evt.Get("newParentId"); p.Bool() {
ret = p.String()
}
return
}
// PrevParentId - UUID of old parent block. Empty if it was a top level block.
func (evt *BlockMove) PrevParentId() (ret string) {
if p := evt.Get("oldParentId"); p.Bool() {
ret = p.String()
}
return
}
// NextInputName - Input in new parent ( if any ). Empty if it's the parent's next block.
func (evt *BlockMove) NextInputName() (ret string) {
if p := evt.Get("newInputName"); p.Bool() {
ret = p.String()
}
return
}
// PrevInputName - Input in old parent ( if any ). Empty if it's the parent's next block.
func (evt *BlockMove) PrevInputName() (ret string) {
if p := evt.Get("oldInputName"); p.Bool() {
ret = p.String()
}
return
}
type CommentCreate struct {
*Event
}
type CommentDelete struct {
*Event
}
type CommentChange struct {
*Event
}
type CommentMove struct {
*Event
}
type VarCreate struct {
*Event
VarId string `js:"varId"`
VarName string `js:"varName"`
VarType string `js:"varType"`
}
type VarDelete struct {
*Event
VarId string `js:"varId"`
VarName string `js:"varName"`
VarType string `js:"varType"`
}
type VarRename struct {
*Event
VarId string `js:"varId"`
OldName string `js:"oldName"`
NewName string `js:"newName"`
}
// ex. warningOpen ( showing or hding the warning bubble ), mutatorOpen, commentOpen, (block) click, (block) selected.
type UiChange struct {
*Event
Element string `js:"element"`
OldValue *js.Object `js:"oldValue"`
NewValue *js.Object `js:"newValue"`
}