trebol-dev 0.1.0 → 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
@@ -1,6 +1,7 @@
1
1
  Trebol [
2
2
  title: "Trebol designer"
3
3
  description: "Lays out the screens of a Trebol project and writes the code back, as you wrote it."
4
+ icon: %favicon.svg
4
5
  ]
5
6
 
6
7
  ; The designer of a project's screens. The file's text is the truth: every change, made on the
@@ -15,7 +16,13 @@ import %props.trb
15
16
  import %samples.trb
16
17
  import %history.trb
17
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
18
24
  import %trebol-code.js
25
+ import %machine-graph.js
19
26
 
20
27
  files: copy []
21
28
  path: none ; the file being designed, from the project's folder
@@ -115,7 +122,8 @@ write-text: function [t [string!]] [
115
122
  change-text t
116
123
  ]
117
124
 
118
- 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]]
119
127
 
120
128
  undo-change: function [] [if all [hist t: undo-text hist text] [change-text t]]
121
129
  redo-change: function [] [if all [hist t: redo-text hist text] [change-text t]]
@@ -201,6 +209,7 @@ redraw: function [] [
201
209
  problems/hidden: true
202
210
  props/hidden: true
203
211
  nothing-chosen/hidden: false
212
+ redraw-machines
204
213
  exit
205
214
  ]
206
215
  fs: shown-faces d
@@ -221,9 +230,11 @@ redraw: function [] [
221
230
  rejoin [length? problems/data either 1 = length? problems/data [" problem"] [" problems"]]
222
231
  ]
223
232
  show-props
233
+ redraw-machines
224
234
  ]
225
235
 
226
236
  show-props: function [] [
237
+ if editing = "Machines" [props/hidden: true exit]
227
238
  f: the-face
228
239
  props/hidden: not f
229
240
  nothing-chosen/hidden: to logic! f
@@ -254,130 +265,8 @@ fill-props: function [] [
254
265
  ]
255
266
  ]
256
267
 
257
- ; what a control of the properties did: the k-th option (a group of entries), or 0 for the
258
- ; texts, what it follows and handlers
259
- prop-act: function [k [integer!] what [word!] value] [
260
- g: either k > 0 [pick prop-entries k] [none]
261
- if what = 'check [return either g [prop-check g value] [true]]
262
- unless f: the-face [exit]
263
- e: all [g first g]
264
- ; typing goes on in the control: the panel is laid out again only for a choice or a removal
265
- 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]
266
- ; a picked icon shows in the panel: laid out again
267
- t: switch what [
268
- flag [either value [set-option d f e none] [remove-option d f e]]
269
- choice [set-option d f e reduce [to word! value]]
270
- icon [prop-values f g mold to issue! form value]
271
- custom [either value/2 [set-option/rule d f e none value/1] [remove-option/rule d f e value/1]]
272
- values [prop-values f g value]
273
- code [
274
- either empty? trim copy value [remove-option d f e] [
275
- b: attempt [load value]
276
- either block? b [set-option d f e reduce [b]] [none]
277
- ]
278
- ]
279
- remove [
280
- either e/how = 'custom [
281
- ; every rule of a program the face has goes
282
- foreach w custom-rule-words [
283
- if option-of/rule face-parts d f e w [write-text remove-option/rule d f e w f: the-face]
284
- ]
285
- none
286
- ] [
287
- q: group-part face-parts d f g
288
- either q [remove-option d f q/2] [none]
289
- ]
290
- ]
291
- text [set-face-text d f value]
292
- hint [set-hint d f value]
293
- is calc react [
294
- b: attempt [load value]
295
- set-reaction d f what either all [block? b not empty? b] [b] [none]
296
- ]
297
- label [
298
- w: all [string? value not empty? trim copy value attempt [load value]]
299
- case [
300
- none? w [set-face-label d f none]
301
- word? w [set-face-label d f w]
302
- true [none]
303
- ]
304
- ]
305
- global [set-face-global d f value]
306
- screen-name [w: attempt [load value] either word? w [set-screen d f 'name w] [none]]
307
- screen-title [set-screen d f 'title value]
308
- screen-args [
309
- w: attempt [load/all value]
310
- either all [block? w parse w [any word!]] [set-screen d f 'args w] [none]
311
- ]
312
- add-screen [add-screen d f]
313
- piece-label [set-piece-label d f value]
314
- add-piece [add-piece d f value]
315
- action [
316
- b: all [string? value not empty? trim copy value attempt [load value]]
317
- set-action d f either all [block? b not empty? b] [b] [none]
318
- ]
319
- event [
320
- b: all [string? value/2 not empty? trim copy value/2 attempt [load value/2]]
321
- either block? b [set-event d f value/1 b] [remove-event d f value/1]
322
- ]
323
- ]
324
- either t [edit t] [set 'keep-props false]
325
- ]
326
-
327
- ; what is typed for an option, as the values of the entry of its group that takes them, or none
328
- typed-as: function [g [block!] value [string!]] [
329
- vals: attempt [load/all value]
330
- unless block? vals [return none]
331
- foreach e g [
332
- case [
333
- find [name label] e/how [if all [1 = length? vals word? first vals] [return reduce [e vals]]]
334
- ; a block is typed as it is shown: [1 2 1]
335
- e/how = 'block [if all [1 = length? vals block? first vals] [return reduce [e vals]]]
336
- true [
337
- vs: vals
338
- ; a text is typed as it is shown, with or without its quotes
339
- if all [find e/args 'text not string? first vals] [vs: reduce [value]]
340
- if all [(length? vs) = length? e/args args-take? e/args vs] [return reduce [e vs]]
341
- ]
342
- ]
343
- ]
344
- none
345
- ]
346
-
347
- args-take?: function [args [block!] vals [block!]] [
348
- repeat i length? args [
349
- a: pick args i v: pick vals i
350
- ok: case [
351
- a = 'text [any [string? :v map? :v lit-word? :v]]
352
- 'one-of = first a [all [word? :v to logic! find either word? a/2 [get a/2] [a/2] v]]
353
- true [
354
- rule: copy []
355
- foreach t a [unless empty? rule [append rule '|] append rule t]
356
- parse reduce [:v] rule
357
- ]
358
- ]
359
- unless ok [return false]
360
- ]
361
- true
362
- ]
363
-
364
- prop-check: function [g [block!] value] [
365
- if any [not string? value empty? trim copy value typed-as g value] [return true]
366
- m: copy ""
367
- foreach e g [unless empty? m [append m " or "] append m type-of-args e]
368
- rejoin ["it takes " m]
369
- ]
370
-
371
- ; values typed for an option: written when they are what it takes, taken out when emptied
372
- prop-values: function [f g [block!] value [string!]] [
373
- q: group-part face-parts d f g
374
- if empty? trim copy value [return either q [remove-option d f q/2] [none]]
375
- unless t: typed-as g value [return none]
376
- e: t/1 vals: t/2
377
- if e/how = 'name [return set-face-name d f first vals]
378
- ; written in another of its ways: in place of it
379
- either all [q not same? q/2 e] [set-option/over d f e vals q/1] [set-option d f e vals]
380
- ]
268
+ ; what the controls of the properties do (shares these words)
269
+ do %props-act.trb
381
270
 
382
271
  ; the loaded block that holds a box's faces
383
272
  ; a screens face shows one screen: the one the chosen face is on, or its first; tabs and steps
@@ -424,6 +313,7 @@ pick-face: function [f [object!]] [
424
313
  ; the cursor put in the code: the innermost face written around it
425
314
  caret-at: function [at [integer!]] [
426
315
  unless d [exit]
316
+ if editing = "Machines" [machine-caret at exit]
427
317
  best: none
428
318
  n: 0
429
319
  foreach f shown-faces d [
@@ -437,7 +327,8 @@ caret-at: function [at [integer!]] [
437
327
 
438
328
  ; Design, Split or Code: what the middle shows
439
329
  show-mode: function [m] [
440
- preview-pane/hidden: m = "Code"
330
+ preview-pane/hidden: any [m = "Code" editing = "Machines"]
331
+ machine-pane/hidden: any [m = "Code" editing <> "Machines"]
441
332
  code-pane/hidden: m = "Design"
442
333
  centre/cols: either m = "Split" [[1 1]] [[1]]
443
334
  ]
@@ -502,6 +393,12 @@ add-face: function [item [word!]] [
502
393
  if all [at not problem pick shown-faces d at] [choose-face at]
503
394
  ]
504
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
+
505
402
  ; the Add menu comes from the palette
506
403
  view compose/deep/only [
507
404
  width fill
@@ -511,6 +408,7 @@ view compose/deep/only [
511
408
  title "Trebol designer"
512
409
  global project-name: text muted ""
513
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]
514
412
  ]
515
413
  global mode-f: radio mode "View" ["Design" "Split" "Code"] segmented on-change [show-mode value]
516
414
  row middle [
@@ -527,6 +425,14 @@ view compose/deep/only [
527
425
  global structure: tree [name] reorder drop on-select [choose-face row/id]
528
426
  on-reorder [reorder event/parent event/from event/to]
529
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
+ ]
530
436
  ]
531
437
  global centre: grid fit [1 1] [
532
438
  global preview-pane: panel "Preview" [
@@ -538,6 +444,15 @@ view compose/deep/only [
538
444
  ]
539
445
  global problems: table [at "Where" message "Problem"] hidden
540
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
+ ]
541
456
  global code-pane: panel "Code" pad 2 [
542
457
  global problem-text: text danger hidden ""
543
458
  global code-view: widget <trebol-code> fit [words: code-words mark: none] on-change [write-text value]
@@ -546,6 +461,15 @@ view compose/deep/only [
546
461
  ]
547
462
  panel "Properties" pad 4 [
548
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
+ ]
549
473
  global props: column hidden [
550
474
  global face-kind: code ""
551
475
  global face-chain: text small muted ""
@@ -565,5 +489,6 @@ view compose/deep/only [
565
489
 
566
490
  mode-f/value: "Split"
567
491
  props-tab/value: "Options"
492
+ editing-f/value: "Screens"
568
493
  device-f/value: "Desktop"
569
494
  read-files