Rebol Programming/request

USAGE:

edit
REQUEST str /offset xy /ok /only /confirm /type icon /timeout time 

DESCRIPTION:

edit

Requests an answer to a simple question.

REQUEST is a function value.

ARGUMENTS

edit
  • str -- (Type: string block object none)

REFINEMENTS

edit
  • /offset
    • xy -- (Type: any)
  • /ok
  • /only
  • /confirm
  • /type
    • icon -- Valid values are: alert, help (default), info, stop (Type: word)
  • /timeout
    • time -- (Type: any)

SOURCE CODE

edit
request: func [
    "Requests an answer to a simple question." 
    str [string! block! object! none!] 
    /offset xy 
    /ok 
    /only 
    /confirm 
    /type icon [word!] {Valid values are: alert, help (default), info, stop} 
    /timeout time 
    /local lay result msg y n c width f img rtn y-key n-key
][
    rtn: func [value] [result: value hide-popup] 
    icon: any [icon all [none? icon any [ok timeout] 'info] 'help] 
    lay: either all [object? str in str 'type str/type = 'face] [str] [
        if none? str [str: "What is your choice?"] 
        set [y n c] ["Yes" "No" "Cancel"] 
        if confirm [c: none] 
        if ok [y: "OK" n: c: none] 
        if only [y: n: c: none] 
        if block? str [
            str: reduce str 
            set [str y n c] str 
            foreach n [str y n c] [
                if all [found? get n not string? get n] [set n form get n]
            ]
        ] 
        width: any [all [200 >= length? str 280] to-integer (length? str) - 200 / 50 * 20 + 280] 
        layout [f: text bold to-pair reduce [width 1000] str] 
        img: switch/default :icon [
            info [info.gif] 
            alert [exclamation.gif] 
            stop [stop.gif]
        ] [help.gif] 
        result: copy [
            across 
            at 0x0 
            origin 15x10 
            image img 
            pad 0x12 
            guide 
            msg: text bold black copy str to-pair reduce [width -1] return 
            pad 4x12
        ] 
        y-key: pick "^My" found? ok 
        n-key: pick "^[n" found? confirm 
        append result pick [
            [key #"o" [rtn yes] key #" " [rtn yes]] 
            [key #"n" [rtn no] key #"c" [rtn none]]
        ] found? ok 
        if y [append result [btn-enter 60 y y-key [rtn yes]]] 
        if n [append result [btn 60 silver n n-key [rtn no]]] 
        if c [append result [btn-cancel 60 c escape [rtn none]]] 
        layout result
    ] 
    result: none 
    either offset [inform/offset/timeout lay xy time] [inform/timeout lay time] 
    result
]