REBOL [ Title: "Standard actions spec editor" Purpose: { Editing the function specs for the standard actions. } Author: "Gabriele Santilli" EMail: giesse@rebol.it File: %spec-editor.r License: { Copyright (C) 2003 Gabriele Santilli This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. http://www.gnu.org/copyleft/gpl.html } Date: 31-Aug-2004 Version: 1.4.0 ; majorv.minorv.status ; status: 0: unfinished; 1: testing; 2: stable History: [ 12-Aug-2004 1.1.0 "History start" 12-Aug-2004 1.2.0 "Navigation implemented" 31-Aug-2004 1.3.0 "Added buttons" 31-Aug-2004 1.4.0 "Editing implemented" ] ] build-list-faces: func [pane /local txt arr pos] [ txt: make-face/size/spec 'text 150x18 [ font: make font [name: "Verdana" align: 'center] action: func [face value] [set-spot face/user-data face/font/color: first face/font/colors show win] ] pos: 20x20 layout [at pos + 66x0 arr: arrow 18x18 [set-spot list-faces/16/user-data - 31 show win]] append pane arr pos: pos + 0x19 loop 15 [append pane make-face/offset txt pos pos: pos + 0x19] append pane make-face/size/offset/spec txt 150x24 pos [font: make font [size: 18] color: snow action: none] pos: pos + 0x25 loop 15 [append pane make-face/offset txt pos pos: pos + 0x19] layout [at pos + 66x0 arr: arrow down 18x18 [set-spot list-faces/16/user-data + 31 show win]] append pane arr pane ] apply-list: func [list-faces list spot] [ repeat i 31 [ list-faces/:i/text: any [pick list spot - 16 + i ""] list-faces/:i/user-data: spot - 16 + i ] ] win: make system/view/vid/vid-face [size: offset: 0x0 pane: [ ]] list-faces: copy/part next build-list-faces win/pane 31 data: load %../libs/standard-actions.r list: [ ] foreach [name spec] data [append list form name] set-spot: func [spot /only] [ if not only [ save-changes ] apply-list list-faces list max min spot length? list 1 build-edit-faces editor pick data 2 * list-faces/16/user-data ] pos: -2 + second get in last win/pane 'offset pos: pos * 0x1 + 170x0 append win/pane get in layout [ across at pos btn red "Remove" [ value: list-faces/16/user-data remove at list value remove/part at data value * 2 - 1 2 set-spot/only value show win ] btn "Save" [save-changes save %../libs/standard-actions.r data] ] 'pane win/size/x: 800 win/size/y: pos/y + 40 sz: 0x0 sz/x: win/size/x - 40 - 150 sz/y: pos/y - 25 editor: insert insert tail win/pane make-face/spec/size/offset 'box [color: snow] sz 170x20 make-face/size/offset 'field 150x24 sz/x + 19 * 1x0 + 0x21 build-edit-faces: func [pane spec /local lay val ind] [ clear pane lay: compose [across origin 175x25 size (sz - 10x10)] ind: 0 pane/-1/text: copy "" parse spec [ opt [set val string! (append lay compose [text (val) return])] opt [set val block! (pane/-1/text: mold/only val)] any [ set val refinement! (ind: 15 append lay compose [text (mold val)]) opt [set val string! (append lay compose [text (val)])] (append lay 'return) | set val word! (append lay compose [pad (ind) text (form val)]) opt [set val block! (append lay compose [field (mold/only val)])] opt [set val string! (append lay compose [text (val)])] (append lay 'return) ] ] lay: layout lay insert pane lay/pane ] save-changes: has [spec pos] [ spec: pick data 2 * list-faces/16/user-data pos: editor parse spec [opt [string! (pos: next pos)] opt block! spec:] either empty? editor/-1/text [ if block? spec/-1 [spec: remove back spec] ] [ either block? spec/-1 [ spec/-1: to block! editor/-1/text ] [ spec: insert/only spec to block! editor/-1/text ] ] parse spec [ any [ refinement! (pos: next pos) opt [string! (pos: next pos)] | word! (pos: next pos) opt [spec: block! (spec/1: to block! pos/1/text pos: next pos)] opt [string! (pos: next pos)] ] ] ] set-spot/only 16 view center-face win