Rebol Programming/request

From Wikibooks, open books for an open world
< Rebol Programming
Jump to navigation Jump to search

USAGE:[edit | edit source]

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

DESCRIPTION:[edit | edit source]

Requests an answer to a simple question.

REQUEST is a function value.

ARGUMENTS[edit | edit source]

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

REFINEMENTS[edit | edit source]

  • /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 | edit source]

request: func [
    "Requests an answer to a simple question." 
    str [string! block! object! none!] 
    /offset xy 
    /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 [
            at 0x0 
            origin 15x10 
            image img 
            pad 0x12 
            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]