1
2
3 scenario deleting-sandboxes [
4 local-scope
5 trace-until 100/app
6 assume-screen 100/width, 15/height
7 assume-resources [
8 ]
9 env:&:environment <- new-programming-environment resources, screen, []
10
11 assume-console [
12 ¦ left-click 1, 80
13 ¦ type [divide-with-remainder 11, 3]
14 ¦ press F4
15 ¦ type [add 2, 2]
16 ¦ press F4
17 ]
18 event-loop screen, console, env, resources
19 screen-should-contain [
20 ¦ . run (F4) .
21 ¦ . ╎ .
22 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
23 ¦ . ╎0 edit copy delete .
24 ¦ . ╎add 2, 2 .
25 ¦ . ╎4 .
26 ¦ . ╎─────────────────────────────────────────────────.
27 ¦ . ╎1 edit copy delete .
28 ¦ . ╎divide-with-remainder 11, 3 .
29 ¦ . ╎3 .
30 ¦ . ╎2 .
31 ¦ . ╎─────────────────────────────────────────────────.
32 ¦ . ╎ .
33 ]
34
35 assume-console [
36 ¦ left-click 7, 85
37 ]
38 run [
39 ¦ event-loop screen, console, env, resources
40 ]
41 screen-should-contain [
42 ¦ . run (F4) .
43 ¦ . ╎ .
44 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
45 ¦ . ╎0 edit copy delete .
46 ¦ . ╎add 2, 2 .
47 ¦ . ╎4 .
48 ¦ . ╎─────────────────────────────────────────────────.
49 ¦ . ╎ .
50 ¦ . ╎ .
51 ]
52
53 assume-console [
54 ¦ left-click 3, 99
55 ]
56 run [
57 ¦ event-loop screen, console, env, resources
58 ]
59 screen-should-contain [
60 ¦ . run (F4) .
61 ¦ . ╎ .
62 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
63 ¦ . ╎ .
64 ¦ . ╎ .
65 ]
66 ]
67
68 after <global-touch> [
69
70 {
71 ¦ delete?:bool <- should-attempt-delete? click-row, click-column, env
72 ¦ break-unless delete?
73 ¦ delete?, env <- try-delete-sandbox click-row, env
74 ¦ break-unless delete?
75 ¦ screen <- render-sandbox-side screen, env, render
76 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env
77 ¦ loop +next-event
78 }
79 ]
80
81
82 def should-attempt-delete? click-row:num, click-column:num, env:&:environment -> result:bool [
83 local-scope
84 load-ingredients
85
86 click-sandbox-area?:bool <- click-on-sandbox-area? click-row, click-column, env
87 return-unless click-sandbox-area?, 0/false
88
89 first-sandbox:&:editor <- get *env, current-sandbox:offset
90 assert first-sandbox, [!!]
91 sandbox-left-margin:num <- get *first-sandbox, left:offset
92 sandbox-right-margin:num <- get *first-sandbox, right:offset
93 _, _, _, _, delete-button-left:num <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin
94 result <- within-range? click-column, delete-button-left, sandbox-right-margin
95 ]
96
97 def try-delete-sandbox click-row:num, env:&:environment -> clicked-on-delete-button?:bool, env:&:environment [
98 local-scope
99 load-ingredients
100
101 sandbox:&:sandbox <- find-sandbox env, click-row
102 return-unless sandbox, 0/false
103 clicked-on-delete-button? <- copy 1/true
104 env <- delete-sandbox env, sandbox
105 ]
106
107 def delete-sandbox env:&:environment, sandbox:&:sandbox -> env:&:environment [
108 local-scope
109 load-ingredients
110 curr-sandbox:&:sandbox <- get *env, sandbox:offset
111 first-sandbox?:bool <- equal curr-sandbox, sandbox
112 {
113 ¦
114 ¦ break-unless first-sandbox?
115 ¦ next-sandbox:&:sandbox <- get *curr-sandbox, next-sandbox:offset
116 ¦ *env <- put *env, sandbox:offset, next-sandbox
117 }
118 {
119 ¦
120 ¦ break-if first-sandbox?
121 ¦ prev-sandbox:&:sandbox <- copy curr-sandbox
122 ¦ curr-sandbox <- get *curr-sandbox, next-sandbox:offset
123 ¦ {
124 ¦ ¦ assert curr-sandbox, [sandbox not found! something is wrong.]
125 ¦ ¦ found?:bool <- equal curr-sandbox, sandbox
126 ¦ ¦ break-if found?
127 ¦ ¦ prev-sandbox <- copy curr-sandbox
128 ¦ ¦ curr-sandbox <- get *curr-sandbox, next-sandbox:offset
129 ¦ ¦ loop
130 ¦ }
131 ¦
132 ¦ next-sandbox:&:sandbox <- get *curr-sandbox, next-sandbox:offset
133 ¦ *prev-sandbox <- put *prev-sandbox, next-sandbox:offset, next-sandbox
134 }
135
136 sandbox-count:num <- get *env, number-of-sandboxes:offset
137 sandbox-count <- subtract sandbox-count, 1
138 *env <- put *env, number-of-sandboxes:offset, sandbox-count
139
140 {
141 ¦ break-if next-sandbox
142 ¦ render-from:num <- get *env, render-from:offset
143 ¦ reset-scroll?:bool <- equal render-from, sandbox-count
144 ¦ break-unless reset-scroll?
145 ¦ *env <- put *env, render-from:offset, -1
146 }
147 ]
148
149 scenario deleting-sandbox-after-scroll [
150 local-scope
151 trace-until 100/app
152 assume-screen 100/width, 10/height
153
154 assume-resources [
155 ]
156 env:&:environment <- new-programming-environment resources, screen, []
157 render-all screen, env, render
158
159 assume-console [
160 ¦ press ctrl-n
161 ¦ type [add 2, 2]
162 ¦ press F4
163 ¦ type [add 1, 1]
164 ¦ press F4
165 ¦ press page-down
166 ]
167 event-loop screen, console, env, resources
168 screen-should-contain [
169 ¦ . run (F4) .
170 ¦ . ╎─────────────────────────────────────────────────.
171 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete .
172 ¦ . ╎add 1, 1 .
173 ¦ . ╎2 .
174 ¦ . ╎─────────────────────────────────────────────────.
175 ¦ . ╎1 edit copy delete .
176 ]
177
178 assume-console [
179 ¦ left-click 6, 99
180 ]
181 run [
182 ¦ event-loop screen, console, env, resources
183 ]
184
185 screen-should-contain [
186 ¦ . run (F4) .
187 ¦ . ╎─────────────────────────────────────────────────.
188 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete .
189 ¦ . ╎add 1, 1 .
190 ¦ . ╎2 .
191 ¦ . ╎─────────────────────────────────────────────────.
192 ¦ . ╎ .
193 ]
194 ]
195
196 scenario deleting-top-sandbox-after-scroll [
197 local-scope
198 trace-until 100/app
199 assume-screen 100/width, 10/height
200
201 assume-resources [
202 ]
203 env:&:environment <- new-programming-environment resources, screen, []
204 render-all screen, env, render
205
206 assume-console [
207 ¦ press ctrl-n
208 ¦ type [add 2, 2]
209 ¦ press F4
210 ¦ type [add 1, 1]
211 ¦ press F4
212 ¦ press page-down
213 ]
214 event-loop screen, console, env, resources
215 screen-should-contain [
216 ¦ . run (F4) .
217 ¦ . ╎─────────────────────────────────────────────────.
218 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete .
219 ¦ . ╎add 1, 1 .
220 ¦ . ╎2 .
221 ¦ . ╎─────────────────────────────────────────────────.
222 ¦ . ╎1 edit copy delete .
223 ]
224
225 assume-console [
226 ¦ left-click 2, 99
227 ]
228 run [
229 ¦ event-loop screen, console, env, resources
230 ]
231
232 screen-should-contain [
233 ¦ . run (F4) .
234 ¦ . ╎─────────────────────────────────────────────────.
235 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete .
236 ¦ . ╎add 2, 2 .
237 ¦ . ╎4 .
238 ¦ . ╎─────────────────────────────────────────────────.
239 ¦ . ╎ .
240 ]
241 ]
242
243 scenario deleting-final-sandbox-after-scroll [
244 local-scope
245 trace-until 100/app
246 assume-screen 100/width, 10/height
247
248 assume-resources [
249 ]
250 env:&:environment <- new-programming-environment resources, screen, []
251 render-all screen, env, render
252
253 assume-console [
254 ¦ press ctrl-n
255 ¦ type [add 2, 2]
256 ¦ press F4
257 ¦ type [add 1, 1]
258 ¦ press F4
259 ¦ press page-down
260 ¦ press page-down
261 ]
262 event-loop screen, console, env, resources
263 screen-should-contain [
264 ¦ . run (F4) .
265 ¦ . ╎─────────────────────────────────────────────────.
266 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎1 edit copy delete .
267 ¦ . ╎add 2, 2 .
268 ¦ . ╎4 .
269 ¦ . ╎─────────────────────────────────────────────────.
270 ¦ . ╎ .
271 ]
272
273 assume-console [
274 ¦ left-click 2, 99
275 ]
276 run [
277 ¦ event-loop screen, console, env, resources
278 ]
279
280 screen-should-contain [
281 ¦ . run (F4) .
282 ¦ . ╎ .
283 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
284 ¦ . ╎0 edit copy delete .
285 ¦ . ╎add 1, 1 .
286 ¦ . ╎2 .
287 ¦ . ╎─────────────────────────────────────────────────.
288 ¦ . ╎ .
289 ]
290 ]
291
292 scenario deleting-updates-sandbox-count [
293 local-scope
294 trace-until 100/app
295 assume-screen 100/width, 10/height
296
297 assume-resources [
298 ]
299 env:&:environment <- new-programming-environment resources, screen, []
300 render-all screen, env, render
301
302 assume-console [
303 ¦ press ctrl-n
304 ¦ type [add 2, 2]
305 ¦ press F4
306 ¦ type [add 1, 1]
307 ¦ press F4
308 ]
309 event-loop screen, console, env, resources
310 screen-should-contain [
311 ¦ . run (F4) .
312 ¦ . ╎ .
313 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
314 ¦ . ╎0 edit copy delete .
315 ¦ . ╎add 1, 1 .
316 ¦ . ╎2 .
317 ¦ . ╎─────────────────────────────────────────────────.
318 ¦ . ╎1 edit copy delete .
319 ¦ . ╎add 2, 2 .
320 ¦ . ╎4 .
321 ]
322
323 assume-console [
324 ¦ left-click 3, 99
325 ¦ press page-down
326 ¦ press page-down
327 ]
328 run [
329 ¦ event-loop screen, console, env, resources
330 ]
331
332 screen-should-contain [
333 ¦ . run (F4) .
334 ¦ . ╎─────────────────────────────────────────────────.
335 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎0 edit copy delete .
336 ¦ . ╎add 2, 2 .
337 ¦ . ╎4 .
338 ¦ . ╎─────────────────────────────────────────────────.
339 ¦ . ╎ .
340 ]
341 ]