Rebol [
    Title: "Home Launcher"
    File: %home-launch.r ; <- this filename needs to be correct for self-editing to work
    Date: 3-Aug-2007
    Version: 1.0.9
    Needs: [view]
    Author: "Anton Rolls"
    Language: 'English
    Purpose: {}
    ToDo: {
    - special button style for scripts?, action does script, alt-action edits the script
    - bug: (with window moving?) can't click buttons
    - try to get mouse move coordinates relative to screen-face
      - modify screen-face/feel (see Ladislav's mail)
    - separate prefs file for the actions (self-modify source for prefs?)
    - implement the lockout idea for the window moving, see util/my-request-file.r
    }
    History: [
        1.0.0 [15-Nov-2001 {First version forked from idatam-launch.r} "Anton"]
        1.0.1 [21-Nov-2001 {rebol starts in default directory,
            experimenting with window moving} "Anton"]
        1.0.2 [30-Nov-2001 {clean up, catching errors} "Anton"]
        1.0.3 [15-Feb-2002 {refactoring, more rebol-like, added form-call} "Anton"]
        1.0.4 [29-Mar-2002 {grabbed button style from idm/idatam-links.r} "Anton"]
        1.0.5 [2-Apr-2002 {added clean-path to form-call, so this-script shrank} "Anton"]
        1.0.6 [18-Nov-2004 {} "Anton"]
        1.0.7 [12-Jan-2006 {site determination from reboltech, added informative error message when can't
            load script-button.r} "Anton"]
        1.0.8 [10-Feb-2007 {fixed bug of missing call to STYLIZE-SCRIPT-BUTTON} "Anton"]
        1.0.9 [3-Aug-2007 {including EDIT from site/os/windows/edit.r instead of defining it here} "Anton"]
    ]
    Notes: {}
]

site: select load-thru http://www.rebol.net/reb/index.r [folder "Anton"]
clear find site %index.r
do load-thru site/library/include.r

include [
    site/gui/script-button.r [stylize-script-button]
    site/os/windows/edit.r [edit]
]
stylize-script-button

this-script: system/script/header/file ;join system/script/path system/script/header/file
rebol.exe: system/options/boot
explorer.exe: "%SystemRoot%\explorer.exe"
;;editor.exe: %/d/Anton/Dev/EditPlus/EditPlus.exe

form-call: func ["helper function for constructing command lines"
    exe [file! string!]
    file [file! string!]
][
    reform [
        either file? exe [to-local-file clean-path exe][exe]
        either file? file [to-local-file clean-path file][file]
    ]
]

explore: func [arg][call form-call explorer.exe arg]
;;edit: func [arg][call form-call editor.exe arg]
run-script: func [arg][call form-call rebol.exe arg]

my-style: stylize [
    button: button 84x44 feel [
        over: func [face action event][
            if all [face/font face/font/colors][
                face/font/color: pick face/font/colors not action
                show face
                face/font/color: first face/font/colors
            ]
            action-field/text: either get in face 'action [
                replace/all mold second get in face 'action newline ""
            ][""]
            alt-action-field/text: either get in face 'alt-action [
                replace/all mold second get in face 'alt-action newline ""
            ][""]
            show [action-field alt-action-field]
        ]
    ]
    field: field 150.150.130 170.170.130; more pleasant colours
]

view/new/options/offset lay: layout [
    styles script-button-style
    styles my-style
    origin 8x8
    backdrop blue effect [gradcol 0x1 80.80.80 0.0.0]
    across
    at 8x8
    button "Projects" [call "notepad D:\Anton\Dev\Projects.txt"]
    button "Edit" [edit ""]
    button "Browse" [browse ""]
    button "Explore" [explore ""]
    button "Command" [call "cmd.exe"]
    return
    button "Forte" [call "D:\Anton\Dev\Java\Forte\bin\runidew.exe"]
    button "InstallShield" [call "D:\Anton\Dev\Java\InstallShield\IEMP401\ismp.exe"]
    button "Outlook" [call "D:\Program Files\Office\Office\OUTLOOK.EXE"]
    return
    ; start in default directory, not current
    button "Rebol" [run-script join {--do "change-dir } [mold view-root {"}]]
    button "Rebol Desktop" [call form-call rebol.exe { -cs --do "desktop"}]
    button "explore rebol/view" [explore system/options/home]
    button "/a/rebol-view" [explore %/a/rebol-view/]
    button "Remind" [run-script path-thru site/util/remind-client.r][edit path-thru site/util/remind-client.r]
    return
    button "Rebsite" [run-script view-root/local/util/rebsite.r]
    button "Rebsearch" [run-script path-thru site/freezer/rebsearch/rebsearch.r]
    button "Clean Recent" [do view-root/clean-recent.r][edit view-root/clean-recent.r]
    button "No White Web Proxy" [run-script view-root/local/web/no-white-web-proxy1.0.4.r][edit view-root/local/web/no-white-web-proxy1.0.4.r]
    button "Quick Remind" [run-script view-root/local/util/quick-remind.r][edit view-root/local/util/quick-remind.r]
    return
    button green / 2 "Edit me" [edit this-script]
    button red / 2 "Refresh" #"^R" [run-script this-script unview]
    button red / 3 * 2 "Quit" [unview/only lay]
    return
    action-field: field 500 return
    alt-action-field: field 500
] [no-title] 76x10

comment {

; modify the window feel for window dragging

lay/feel: make lay/feel [
    start-offset: none
    start-pos: none
    detect: func [face event][
        ;print [event/type event/offset]
        switch event/type [
            down [
                start-offset: event/offset
                start-pos: face/offset
            ]
            move [
                if all [
                    ;not lock-out
                    start-offset
                ][
                    ;face/offset: start-pos + event/offset - start-offset
                    ;new-pos: start-pos + event/offset - start-offset
                    ;;start-pos: start-pos + event/offset - start-offset
                    ;show face
                    ;lock-out: true
                    ;return
                ]
            ]
            up [
                face/offset: start-pos + event/offset - start-offset
                show face
                start-offset: none
                return
            ]
            offset [
                ;if start-offset [face/offset: start-pos + event/offset - start-offset]
                ;show face
                ;return
            ]
        ]
        
        either all [
            event/type = 'key
            face: find-key-face face event/key
        ][
            if get in face 'action [do-face face event/key]
            none
        ][
            event
        ]
    ]
    redraw: func [face action position][
        ;print [action position]
    ]
]

; need to bind event in somehow - use Ladislav's suggestion
; modify screen-face/feel
detect: get in system/view/screen-face/feel 'detect
spec: third :detect
body: second :detect

insert body [
    print [event/type event/offset]
]

new-detect: func (load mold spec) body
system/view/screen-face/feel: make system/view/screen-face/feel [
    detect: func load mold spec body
]

{
probe spec
system/view/screen-face/feel: make system/view/screen-face/feel reduce [
    ;detect: func (load mold spec) body
    detect: func (load mold third get in system/view/screen-face/feel 'detect)
    ;second get in system/view/screen-face/feel 'detect
    body
]
}

lock-out: false
new-pos: none
{
move-event-trap-func: insert-event-func func [face event][
    if event/type = 'move [
        ; perform the move
        probe event/offset
        ;face/offset: new-pos
        ;show lay
        ;lock-out: false
    ]

    event
]
}

;probe lay/feel
}

selected-button: 1
count: 0
foreach p lay/pane [
    if 'button = get in p 'style [
        count: count + 1
        
    ]
]


;lay/saved-area: true ; possible speed increase

while [error? err: try [wait none]][
    view/new layout [
        title "That didn't work"
        area 500x250 mold disarm err
    ]
]

;remove-event-func :move-event-trap-func