[REBOL] Re: Re(2): services.r
From: larry:ecotope at: 3-May-2001 12:12
Hi Anton
OK, as a public service, I will reveal one of my secret Jedi methods. :-)
This one is called "Use the Source!"
All of the desktop code is in ctx-viewtop which is initially a spec block
for an object (or context). When the desktop is invoked ctx-viewtop is
converted (if necessary) to an object. It is about 1000 lines of code.
You can make yourself a cheat-sheet as follows, will work with either block
or object
echo %viewtop.txt
print mold ctx-viewtop
echo none
With regard to services, look for the function show-services. You can show
it as follows if ctx-viewtop is an object. The conversion (if necessary)
should be done this way.
if block? ctx-viewtop [ctx-viewtop: context ctx-viewtop]
>> print mold get in ctx-viewtop 'show-services
func [file /local path services f x][
clear next dts-face/pane
x: dts-face/pane/1/size/x
path: full-path file
if all [services: load-index path services/icons] [
foreach icon services/icons [
if icon/type = 'service [
f: make-face dts-proto
f/text: icon/name
f/size: 200x20
f/line-list: none
f/action: compose/deep [
do-file (either word? icon/item [to-lit-word icon/item]
[icon/item]
)
(if icon/stats [reduce [icon/stats]])
]
f/size/x: 4 + first size-text f
x: x + 8
f/offset/x: x
x: x + f/size/x
append dts-face/pane f
]
]
]
dtm-services/pane: dts-face/pane
dtm-services/size: dts-face/size
dtm-services/size/x: x
show dtm-services
]
The line starting f/action: tells us the action that happens when we click
the item in the services bar. In this case, it will call the function
do-file on the argument.
>> print mold get in ctx-viewtop 'do-file
func [path stats /local orig][
if none? path [exit]
orig: path
if word? path [
switch path [
goto [goto-view]
help [help-view]
console [halt-view]
quit [quit]
]
exit
]
if email? path [emailer/to path exit]
if not any [url? path (first path) = #"/"] [path: full-path path]
either not read-binary path stats [
alert reform ["Missing file:" path]
] [
switch/default map-suffix to-file path [
rebol [start path]
text [editor path-thru path]
image [show-image path]
] [
either url? orig [browse orig] [browse path-thru path]
]
]
]
Reading the above code and a couple of quick experiments gave me the
information for my email below.
Happy Hacking
-Larry
PS The functions INIT-DESKTOP and CONNECT-VIEW are worth study.