-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup-scrolled-editor.r
424 lines (346 loc) · 10.9 KB
/
group-scrolled-editor.r
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
REBOL [
; -- Core Header attributes --
title: "Glass scrolled editor"
file: %group-scrolled-editor.r
version: 1.0.0
date: 2013-9-18
author: "Maxim Olivier-Adlhoch"
purpose: {a group setup as a source code editor all setup with scrollers.}
web: http://www.revault.org/modules/group-scrolled-editor.rmrk
source-encoding: "Windows-1252"
note: {slim Library Manager is Required to use this module.}
; -- slim - Library Manager --
slim-name: 'group-scrolled-editor
slim-version: 1.2.1
slim-prefix: none
slim-update: http://www.revault.org/downloads/modules/group-scrolled-editor.r
; -- Licensing details --
copyright: "Copyright © 2013 Maxim Olivier-Adlhoch"
license-type: "Apache License v2.0"
license: {Copyright © 2013 Maxim Olivier-Adlhoch
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.}
;- / history
history: {
v1.0.0 - 2013-09-18
-License changed to Apache v2}
;- \ history
;- / documentation
documentation: {
Combines a simple list with vertical and horizontal scrollers.
If you provide some options in the specification, a label a filter field may appear.
The main aspects of all inner marbles are stored in the aspects (refered to, not linked).
the main advantage is that the list and scroller themselves are pre-linked for you.
So all you have to do is put items in the list, and the scoller will adjust.
Put in some text in the filter, and everything updates.
}
;- \ documentation
]
slim/register [
;- LIBS
glob-lib: slim/open/expose 'glob none [!glob]
liquid-lib: slim/open/expose 'liquid none [
!plug
liquify*: liquify
content*: content
fill*: fill
pipe*: pipe
link*: link
unlink*: unlink
detach*: detach
attach*: attach
]
sl: slim/open/expose 'sillica none [
master-stylesheet
alloc-marble
regroup-specification
list-stylesheet
collect-style
relative-marble?
prim-bevel
prim-x
prim-label
on-event
]
epoxy-lib: slim/open/expose 'epoxy none [!box-intersection]
group-lib: slim/open 'group none
slim/open/expose 'bulk none [
make-bulk
]
;- .
;-----------------------------------------------------------------------------------------------------------
;
;- !SCROLLED-LIST[ ]
;
;-----------------------------------------------------------------------------------------------------------
!group-scrolled-editor: make group-lib/!group [
;---------------------
;- aspects[ ]
;
; groups implements their own interface, and xfer to their internals, if required.
;
; note that some aspects are directly shared with their internals...
; i.e. we just put a second reference to the internal plug here.
;---------------------
aspects: make aspects [
;--------------------------
;- text:
;
; the text to put or extract from the editor, this is BRIDGED to the internal line version.
;--------------------------
text: none
;--------------------------
;- line-offset:
;
; the index of the first visible line
;--------------------------
line-offset: none
;--------------------------
;- column-offset:
;
; index of first visible character.
;--------------------------
column-offset: none
]
;- material[ ]
material: make material [
border-size: 0x0
]
;--------------------------
;- editor-marble:
;
; store a reference to the editor itself within the group, for easy reference after
;--------------------------
editor-marble: none
;--------------------------
;- vscroller-marble:
;
; store a reference to the vscroller itself within the group, for easy reference after
;--------------------------
vscroller-marble: none
;--------------------------
;- hscroller-marble:
;
; store a reference to the hscroller itself within the group, for easy reference after
;--------------------------
hscroller-marble: none
;--------------------------
;- content-specification:
; this stores the spec block we execute on setup.
;
; note that because it's declared here (within the marble) all words are bound to the
; marble automatically, so assignments work.
;
; it is handled normally by a row frame.
;
; note that the dialect for the group itself, is completely redefined for each group.
;
; remember that the group itself is a frame, so you can set its looks, and layout mode normally.
;--------------------------
content-specification: [
column tight [
editor-marble: script-editor
hscroller-marble: scroller
]
column tight [
row tight [
vscroller-marble: scroller
]
pad 20x20
]
]
;--------------------------
;- spacing-on-collect:
;
; we don't want any space between group elements
;--------------------------
spacing-on-collect: 0x0
;--------------------------
;- layout-method:
; group is a frame... make it a column or a row
;--------------------------
layout-method: 'ROW
;------------------------------------------------------------------------------
;- valve []
;------------------------------------------------------------------------------
valve: make valve [
;--------------------------
;- style-name:
;
; this is the name used by default in stylesheets. (collect-cstyle())
;--------------------------
style-name: 'scrolled-editor
;--------------------------
;- bg-glob-class:
;- fg-glob-class:
;
; no need for any globs. just sizing fastening and automated liquification of grouped marbles.
;
; you can add globs to show up in front or behind the grouped content.
;
; for a reference on how to use the
;--------------------------
bg-glob-class: none
fg-glob-class: none
;-----------------
;- setup-style()
;
; build up the style on the fly (creating default values, for example).
;-----------------
setup-style: func [
group
][
vin [{!scrolled-list/setup-style()}]
vout
]
;-----------------
;- group-specify()
;
; low-level group dialect
;
; to increase the
;-----------------
group-specify: func [
group [object!]
spec [block!]
stylesheet [block! none!] "required so stylesheet propagates in marbles we create"
/local data block-count blk
][
vin [{!scrolled-list/group-specify()}]
block-count: 0
vprobe spec
vprint "-----------"
parse spec [
any [
;here: set data skip (probe data ) :here
set data string! (
vprint "text !!!"
v?? data
;ask "!"
fill* group/aspects/text data
)
| set data tuple! (
vprint "text COLOR!"
set-aspect editor-marble 'color data
)
| [ 'with copy data block!] (
vprint "SPECIFIED A WITH BLOCK"
do bind/copy data group
)
; keyboard events
| set data block! (
vprint "Setting up keyboard action handling"
on-event group/editor-marble 'text-entry data
vprobe group/editor-marble/actions
)
| 'stiff (
fill* group/editor-marble/material/fill-weight 0x0
;group/stiffness: 'xy
;fill* group/material/fill-weight 0x0
)
; | 'stiff-x (
; group/stiffness: 'x
; ;fill* group/material/fill-weight 0x0
;
; )
; | 'stiff-y (
; group/stiffness: 'y
; ;fill* group/material/fill-weight 0x0
;
; )
; ; remove the label from this group, we don't need it
; | 'no-label (
; ;probe "Will remove label"
; ;probe type? group/label-marble
; group/valve/gl-discard group group/label-marble
; ;group/valve/gl-fasten group
;
; ;halt
; )
; ; set list data or pick action
; | set data block! (
; ;print "!!!!"
; ;probe first group/list-marble/valve
; ;print "----"
; ;fill* group/aspects/items make-bulk/records/properties 3 data [ label-column: 1]
; ;group/list-marble/valve/specify group/list-marble reduce [data] stylesheet
;
;
; block-count: block-count + 1
; switch block-count [
; 1 [
; ; lists support 3 columns, one being label, another options and the last being data.
; ; options will change how the item is displayed (bold, strikethru, color, etc).
; fill* group/aspects/items make-bulk/records/properties 3 data [ label-column: 1]
; ]
; 2 [
; if object? get in group 'actions [
; group/list-marble/actions: make group/list-marble/actions [
; list-picked: make function! [event] bind/copy data group
; ]
; ]
; ]
; ]
;
; )
| set data pair! (
;vprint "PAIRS!!!"
;v?? data
fill* group/editor-marble/material/min-dimension data
)
| skip
]
]
vprint "-----------"
;----
; if there aren't any items given at this point, create an empty one...
; this allows us to simply append to the system later.
unless string? content* group/aspects/text [
vprint "NO TEXT... initializing to an empty text"
;fill* group/aspects/text copy ""
]
vout
group
]
;-----------------
;- fasten()
;-----------------
fasten: funcl [
group
][
vin [{!scrolled-list/fasten()}]
;--------------------------------
; shortcuts for simpler coding
;--------------------------------
edtr: group/editor-marble
mtrl: edtr/material
spct: edtr/aspects
hscrl: group/hscroller-marble
vscrl: group/vscroller-marble
vprint content edtr/aspects/text
vprint content group/aspects/text
;pipe* edtr/aspects/text group/aspects/text
group/aspects/text: edtr/aspects/text
;--------------------------------
; link-up the text scrollbars
;--------------------------------
link/reset hscrl/aspects/maximum mtrl/longest-line
link/reset hscrl/aspects/visible mtrl/visible-length
attach/to spct/left-off hscrl/aspects/value 'value
fill vscrl/aspects/value 0
link/reset vscrl/aspects/maximum mtrl/number-of-lines
link/reset vscrl/aspects/visible mtrl/visible-lines
attach/to spct/top-off vscrl/aspects/value 'value ; bridged value!
fill vscrl/aspects/value 0
vout
]
]
]
]