; Installation script for ToolType

(set @user-level 2)

(transcript "Installing ToolType...")

(copylib
        (prompt "Install ReqTools library.")
        (help @copylib-help)
        (source "LIBS/ReqTools.library")
        (dest "libs:")
        (confirm)
)

( if (= (exists "ENV:EDITOR" (noreq)) 0)
    (set defed "C:ED %s")
    (set defed (getenv "EDITOR"))
)

(set editor
        (askstring
                (prompt "What editor do you want?")
                (help @askstring-help)
                (default defed)
        )
)

(set env
        (askbool
                (prompt "Do you want to also save the Editor config\n"
                        "in an environment variable 'ToolType'?")
                (help "It's up to YOU.")
                (choices "Yes" "No")
                (default 0)              ; 0 = no
        )
)

(set detach
        (askbool
                (prompt "Does your editor detach from the CLI?")
                (help "It's up to YOU.")
                (choices "Yes" "No")
                (default 0)              ; 0 = no
        )
)

(set appicon
        (askbool
                (prompt "Do you want ToolType to be started\n"
                        "as an App Icon?")
                (help "It's up to YOU.")
                (choices "Yes" "No")
                (default 0)              ; 0 = no
        )
)

(if (= appicon 1)                           ; conditional test
    (
        (set def_dir "SYS:WBStartup")
        (set iconx
                (asknumber
                        (prompt "X coordinate of AppIcon\n"
                                "'0' = float")
                        (help @asknumber-help)
                        (default 0)
                )
        )
        (set icony
                (asknumber
                        (prompt "Y coordinate of AppIcon\n"
                                "'0' = float")
                        (help @asknumber-help)
                        (default 0)
                )
        )
        (set iconname
                (askstring
                        (prompt "What do you want to call the AppIcon?")
                        (help @askstring-help)
                        (default "ToolType")
                )
        )
    )
    (
        (set def_dir "SYS:Utilities")
    )
)

(set sort
        (askchoice
                (prompt "How do you want to handle sorting?")
                (help @askchoice-help)
                (choices "Never Sort" "Ask me every time" "Always Sort" )
                (default 1)
        )
)

(set comt
        (askbool
                (prompt "Do you want the commented tooltypes placed\n"
                        "before the non commented when sorting?")
                (help "It's up to YOU.")
                (choices "Yes" "No")
                (default 0)              ; 0 = no
        )
)

(set conf
        (askbool
                (prompt "Do you want the confirm changes requester?")
                (help "It's up to YOU.")
                (choices "Yes" "No")
                (default 0)              ; 0 = no
        )
)

(tooltype
        (dest "ToolType")
        (settooltype "EDITOR" editor)
)


(if (= conf 1)                           ; conditional test
    (tooltype
            (dest "ToolType")
            (settooltype "CONFIRM" "")
    )
    (tooltype
            (dest "ToolType")
            (settooltype "(CONFIRM)" "")
    )
)

(if (= appicon 1)
    (
        (tooltype
                (dest "ToolType")
                (settooltype "APPICON" "")
        )
        (tooltype
                (dest "ToolType")
                (settooltype "ICONX" (cat iconx))
        )
        (tooltype
                (dest "ToolType")
                (settooltype "ICONY" (cat icony))
        )
        (tooltype
                (dest "ToolType")
                (settooltype "ICONNAME" iconname)
        )
    )
    (
        (tooltype
                (dest "ToolType")
                (settooltype "(APPICON)" "")
        )
        (tooltype
                (dest "ToolType")
                (settooltype "(ICONX)" "")
        )
        (tooltype
                (dest "ToolType")
                (settooltype "(ICONY)" "")
        )
        (tooltype
                (dest "ToolType")
                (settooltype "(ICONNAME)" "")
        )
    )
)

(if (= comt 1)                           ; conditional test
    (tooltype
            (dest "ToolType")
            (settooltype "COMMENT" "")
    )
    (tooltype
            (dest "ToolType")
            (settooltype "(COMMENT)" "")
    )
)

(if (= env 1)                           ; conditional test
   (
        (textfile
                (dest "ENV:ToolType")
                (append editor)
        )
        (textfile
                (dest "ENVARC:ToolType")
                (append editor)
        )
    )
)


(if (= detach 1)                           ; conditional test
    (tooltype
            (dest "ToolType")
            (settooltype "WAIT" "")
    )
    (tooltype
            (dest "ToolType")
            (settooltype "(WAIT)" "")
    )
)

(if (= sort 0)                           ; conditional test
    (tooltype
            (dest "ToolType")
            (settooltype "SORT" "FALSE")
    )
    (if (= sort 2)
        (tooltype
                (dest "ToolType")
                (settooltype "SORT" "TRUE")
        )
        (tooltype
                (dest "ToolType")
                (settooltype "SORT" "ASK")
        )
    )
)

(tooltype
        (dest "ToolType")
        (settooltype "(QUIET)" "")
)


(set destdir
        (askdir
                (prompt "Install ToolType where?")
                (help @askdir-help)
                (default def_dir)
        )
)

(copyfiles
        (source "ToolType")
        (infos)
        (dest destdir)
)

(set @default-dest destdir)

(message "\n\nIf you want to stop the copyright requester from\n"
         "appearing when starting from WorkBench,\n"
         " you need to uncomment the tooltype \"QUIET\"")

(exit)

