trebol-dev 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/app/app.trb CHANGED
@@ -16,7 +16,13 @@ import %props.trb
16
16
  import %samples.trb
17
17
  import %history.trb
18
18
  import %move.trb
19
+ import %machines.trb
20
+ import %machine-edits.trb
21
+ import %machine-moves.trb
22
+ import %machine-places.trb
23
+ import %fragments.trb
19
24
  import %trebol-code.js
25
+ import %machine-graph.js
20
26
 
21
27
  files: copy []
22
28
  path: none ; the file being designed, from the project's folder
@@ -116,7 +122,8 @@ write-text: function [t [string!]] [
116
122
  change-text t
117
123
  ]
118
124
 
119
- edit: function [t [string! none!]] [if t [write-text t]]
125
+ ; the places of the machines' states stay last in the file, whatever an edit wrote after them
126
+ edit: function [t [string! none!]] [if t [write-text places-last t]]
120
127
 
121
128
  undo-change: function [] [if all [hist t: undo-text hist text] [change-text t]]
122
129
  redo-change: function [] [if all [hist t: redo-text hist text] [change-text t]]
@@ -202,6 +209,7 @@ redraw: function [] [
202
209
  problems/hidden: true
203
210
  props/hidden: true
204
211
  nothing-chosen/hidden: false
212
+ redraw-machines
205
213
  exit
206
214
  ]
207
215
  fs: shown-faces d
@@ -222,9 +230,11 @@ redraw: function [] [
222
230
  rejoin [length? problems/data either 1 = length? problems/data [" problem"] [" problems"]]
223
231
  ]
224
232
  show-props
233
+ redraw-machines
225
234
  ]
226
235
 
227
236
  show-props: function [] [
237
+ if editing = "Machines" [props/hidden: true exit]
228
238
  f: the-face
229
239
  props/hidden: not f
230
240
  nothing-chosen/hidden: to logic! f
@@ -255,130 +265,8 @@ fill-props: function [] [
255
265
  ]
256
266
  ]
257
267
 
258
- ; what a control of the properties did: the k-th option (a group of entries), or 0 for the
259
- ; texts, what it follows and handlers
260
- prop-act: function [k [integer!] what [word!] value] [
261
- g: either k > 0 [pick prop-entries k] [none]
262
- if what = 'check [return either g [prop-check g value] [true]]
263
- unless f: the-face [exit]
264
- e: all [g first g]
265
- ; typing goes on in the control: the panel is laid out again only for a choice or a removal
266
- if find [values code text hint is calc react event action label screen-name screen-title screen-args piece-label] what [set 'keep-props true]
267
- ; a picked icon shows in the panel: laid out again
268
- t: switch what [
269
- flag [either value [set-option d f e none] [remove-option d f e]]
270
- choice [set-option d f e reduce [to word! value]]
271
- icon [prop-values f g mold to issue! form value]
272
- custom [either value/2 [set-option/rule d f e none value/1] [remove-option/rule d f e value/1]]
273
- values [prop-values f g value]
274
- code [
275
- either empty? trim copy value [remove-option d f e] [
276
- b: attempt [load value]
277
- either block? b [set-option d f e reduce [b]] [none]
278
- ]
279
- ]
280
- remove [
281
- either e/how = 'custom [
282
- ; every rule of a program the face has goes
283
- foreach w custom-rule-words [
284
- if option-of/rule face-parts d f e w [write-text remove-option/rule d f e w f: the-face]
285
- ]
286
- none
287
- ] [
288
- q: group-part face-parts d f g
289
- either q [remove-option d f q/2] [none]
290
- ]
291
- ]
292
- text [set-face-text d f value]
293
- hint [set-hint d f value]
294
- is calc react [
295
- b: attempt [load value]
296
- set-reaction d f what either all [block? b not empty? b] [b] [none]
297
- ]
298
- label [
299
- w: all [string? value not empty? trim copy value attempt [load value]]
300
- case [
301
- none? w [set-face-label d f none]
302
- word? w [set-face-label d f w]
303
- true [none]
304
- ]
305
- ]
306
- global [set-face-global d f value]
307
- screen-name [w: attempt [load value] either word? w [set-screen d f 'name w] [none]]
308
- screen-title [set-screen d f 'title value]
309
- screen-args [
310
- w: attempt [load/all value]
311
- either all [block? w parse w [any word!]] [set-screen d f 'args w] [none]
312
- ]
313
- add-screen [add-screen d f]
314
- piece-label [set-piece-label d f value]
315
- add-piece [add-piece d f value]
316
- action [
317
- b: all [string? value not empty? trim copy value attempt [load value]]
318
- set-action d f either all [block? b not empty? b] [b] [none]
319
- ]
320
- event [
321
- b: all [string? value/2 not empty? trim copy value/2 attempt [load value/2]]
322
- either block? b [set-event d f value/1 b] [remove-event d f value/1]
323
- ]
324
- ]
325
- either t [edit t] [set 'keep-props false]
326
- ]
327
-
328
- ; what is typed for an option, as the values of the entry of its group that takes them, or none
329
- typed-as: function [g [block!] value [string!]] [
330
- vals: attempt [load/all value]
331
- unless block? vals [return none]
332
- foreach e g [
333
- case [
334
- find [name label] e/how [if all [1 = length? vals word? first vals] [return reduce [e vals]]]
335
- ; a block is typed as it is shown: [1 2 1]
336
- e/how = 'block [if all [1 = length? vals block? first vals] [return reduce [e vals]]]
337
- true [
338
- vs: vals
339
- ; a text is typed as it is shown, with or without its quotes
340
- if all [find e/args 'text not string? first vals] [vs: reduce [value]]
341
- if all [(length? vs) = length? e/args args-take? e/args vs] [return reduce [e vs]]
342
- ]
343
- ]
344
- ]
345
- none
346
- ]
347
-
348
- args-take?: function [args [block!] vals [block!]] [
349
- repeat i length? args [
350
- a: pick args i v: pick vals i
351
- ok: case [
352
- a = 'text [any [string? :v map? :v lit-word? :v]]
353
- 'one-of = first a [all [word? :v to logic! find either word? a/2 [get a/2] [a/2] v]]
354
- true [
355
- rule: copy []
356
- foreach t a [unless empty? rule [append rule '|] append rule t]
357
- parse reduce [:v] rule
358
- ]
359
- ]
360
- unless ok [return false]
361
- ]
362
- true
363
- ]
364
-
365
- prop-check: function [g [block!] value] [
366
- if any [not string? value empty? trim copy value typed-as g value] [return true]
367
- m: copy ""
368
- foreach e g [unless empty? m [append m " or "] append m type-of-args e]
369
- rejoin ["it takes " m]
370
- ]
371
-
372
- ; values typed for an option: written when they are what it takes, taken out when emptied
373
- prop-values: function [f g [block!] value [string!]] [
374
- q: group-part face-parts d f g
375
- if empty? trim copy value [return either q [remove-option d f q/2] [none]]
376
- unless t: typed-as g value [return none]
377
- e: t/1 vals: t/2
378
- if e/how = 'name [return set-face-name d f first vals]
379
- ; written in another of its ways: in place of it
380
- either all [q not same? q/2 e] [set-option/over d f e vals q/1] [set-option d f e vals]
381
- ]
268
+ ; what the controls of the properties do (shares these words)
269
+ do %props-act.trb
382
270
 
383
271
  ; the loaded block that holds a box's faces
384
272
  ; a screens face shows one screen: the one the chosen face is on, or its first; tabs and steps
@@ -425,6 +313,7 @@ pick-face: function [f [object!]] [
425
313
  ; the cursor put in the code: the innermost face written around it
426
314
  caret-at: function [at [integer!]] [
427
315
  unless d [exit]
316
+ if editing = "Machines" [machine-caret at exit]
428
317
  best: none
429
318
  n: 0
430
319
  foreach f shown-faces d [
@@ -438,7 +327,8 @@ caret-at: function [at [integer!]] [
438
327
 
439
328
  ; Design, Split or Code: what the middle shows
440
329
  show-mode: function [m] [
441
- preview-pane/hidden: m = "Code"
330
+ preview-pane/hidden: any [m = "Code" editing = "Machines"]
331
+ machine-pane/hidden: any [m = "Code" editing <> "Machines"]
442
332
  code-pane/hidden: m = "Design"
443
333
  centre/cols: either m = "Split" [[1 1]] [[1]]
444
334
  ]
@@ -503,6 +393,12 @@ add-face: function [item [word!]] [
503
393
  if all [at not problem pick shown-faces d at] [choose-face at]
504
394
  ]
505
395
 
396
+ ; the machines of the file: their structure, properties and code (shares these words)
397
+ do %machines-view.trb
398
+ do %fragments-view.trb
399
+ do %machine-try.trb
400
+ do %machine-canvas.trb
401
+
506
402
  ; the Add menu comes from the palette
507
403
  view compose/deep/only [
508
404
  width fill
@@ -512,6 +408,7 @@ view compose/deep/only [
512
408
  title "Trebol designer"
513
409
  global project-name: text muted ""
514
410
  global file-choice: choice "File" [] on-change [if value [open-file value]]
411
+ global editing-f: radio "Edit" ["Screens" "Machines"] segmented on-change [show-editing value]
515
412
  ]
516
413
  global mode-f: radio mode "View" ["Design" "Split" "Code"] segmented on-change [show-mode value]
517
414
  row middle [
@@ -528,6 +425,14 @@ view compose/deep/only [
528
425
  global structure: tree [name] reorder drop on-select [choose-face row/id]
529
426
  on-reorder [reorder event/parent event/from event/to]
530
427
  on-drop [drop-face event/dropped event/parent event/index]
428
+ global machine-side: column hidden [
429
+ row [
430
+ button #plus "New machine" small [machine-add 'machine]
431
+ button #plus "New fragment" small [machine-add 'fragment]
432
+ ]
433
+ global machine-none: text muted "This file makes no machines yet. Its states and ways are made on the drawing."
434
+ global machine-tree: tree [name] on-select [pick-machine row/id]
435
+ ]
531
436
  ]
532
437
  global centre: grid fit [1 1] [
533
438
  global preview-pane: panel "Preview" [
@@ -539,6 +444,15 @@ view compose/deep/only [
539
444
  ]
540
445
  global problems: table [at "Where" message "Problem"] hidden
541
446
  ]
447
+ global machine-pane: panel "Drawing" hidden [
448
+ global machine-drawing: widget <tb-machine-graph> fit [graph: none selected: none editing: none trying: false]
449
+ on-pick [pick-machine event/detail] on-add [canvas-add event/detail] on-connect [canvas-connect event/detail]
450
+ on-grow [canvas-grow event/detail] on-rename [canvas-rename event/detail] on-remove [canvas-remove event/detail]
451
+ on-initial [canvas-initial event/detail] on-move [canvas-move event/detail] on-place [canvas-placed event/detail]
452
+ on-undo [undo-change] on-redo [redo-change] on-try [try-machine] on-restart [try-machine] on-stop [stop-try none]
453
+ on-open [toggle-open event/detail] on-fragment [open-fragment event/detail]
454
+ global machine-problems: table [at "Where" message "Problem"] hidden
455
+ ]
542
456
  global code-pane: panel "Code" pad 2 [
543
457
  global problem-text: text danger hidden ""
544
458
  global code-view: widget <trebol-code> fit [words: code-words mark: none] on-change [write-text value]
@@ -547,6 +461,15 @@ view compose/deep/only [
547
461
  ]
548
462
  panel "Properties" pad 4 [
549
463
  global nothing-chosen: text muted "Choose a face in the structure, the preview or the code."
464
+ global machine-props: column hidden []
465
+ global try-panel: column hidden [
466
+ text small muted "Send it an event: the buttons of those no way out takes now cannot be used."
467
+ global try-buttons: row []
468
+ global try-fields: field "Event fields" "the fields the next event carries: count: 3"
469
+ text small muted "Data"
470
+ global try-data: code ""
471
+ global try-history: column []
472
+ ]
550
473
  global props: column hidden [
551
474
  global face-kind: code ""
552
475
  global face-chain: text small muted ""
@@ -566,5 +489,6 @@ view compose/deep/only [
566
489
 
567
490
  mode-f/value: "Split"
568
491
  props-tab/value: "Options"
492
+ editing-f/value: "Screens"
569
493
  device-f/value: "Desktop"
570
494
  read-files