G4C     - 24/2/96 dck - GUI for Commands


; This GUI is similar to the Workbench "Execute command" GUI, but more.
; There is a textin gadget for entering commands, buttons for choosing
; files, changing the directory, and opening a newshell.

; More important, it can also send ARexx commands to the port shown
; in the other (bottom right) textin gadget (which can also be changed)

; On clicking the right mouse button an other GUI named "keyboard.g"
; is opened - It provides a letter pad to write commands using the
; mouse - not very useful, but pretty :)

; The subroutine for this may confuse you a little - don't worry.



WinBig 10 30 515 40 "Enter commands :"


; On loading, we set the default values of the variables & open window

xOnLoad
setvar gcMain ""      ; Our command line
setvar gcMode G4C     ; Mode to run the command
setvar gcPort Gui4Cli ; Name of default port (can also sendrexx to ourselves)
setvar kbdGadID 1     ; ID of TEXTIN gadget to edit with the keyboard.g GUI
GuiOpen cli.gc

; On opening we display the current directory in the titlebar (note large buffer)

xOnOpen
setwintitle cli.gc "$$CURRENT_DIR                                  "

; On quitting we delete the variables

xOnQuit
delvar gcMain
delvar gcMode
delvar gcPort
delvar gcEdit


;--------------------- On Right Mouse Button we open the keyboard.g GUI
; We must set 3 variables before opening it - read the GUI to understand

xOnRMB
setvar kbdGui cli.gc
if $kbdGadID < " "			; if 1st time
   setvar kbdGadID 1			; set gad to 1
endif
if $kbdGadID = 1
   setvar kbdBuffer gcMain		; set kbdBuffer according to gadID
else
   setvar kbdBuffer gcEdit
endif
GuiLoad GUIs:demos/keyboard.g
GuiOpen keyboard.g

xRADIO 494 8 kbdGadID 7             ; Radio buttons to choose edit target
RSTR "" 1
RSTR "" 2
if $kbdGadID = 1
   setvar kbdBuffer gcMain
else
   setvar kbdBuffer gcEdit
endif


;================================> Main text input gadget

xTEXTIN 10 5 480 14 "" gcMain "" 512
gadid 1
gosub cli.gc DoCommand

;========> Cycler for choosing ARexx/CLI/RUN modes

xCYCLER 10 20 80 14 "" gcMode
CSTR ARexx     G4C
CSTR CLI       CLI
CSTR RUN       RUN

;========> GO button (to execute the command)

xBUTTON 90 20 40 14 "GO!"
gadfont topaz.font 9 010
gosub cli.gc DoCommand

;========> Button for File requester for filenames (or commands)

xBUTTON 140 20 60 14 "Files.."
setvar gcFile ""
REQFILE -1 -1 300 -60 "Choose Files" MULTI gcFile ""
if $gcFile > ""
   appvar gcMain $gcFile
   update cli.gc 1 $gcMain
endif

;========> Button to open a shell

xBUTTON 200 20 60 14 Shell
CLI 'Newshell "con:0/150/640/100/NewShell/CLOSE"'

;========> Button to change directory

xBUTTON 260 20 60 14 CD
setvar gcDir ""
REQFILE -1 -1 300 -60 "Choose directory" DIR gcDir ""
if $gcDir > ""
   CD $gcDir
   SetWinTitle cli.gc "$gcDir                                        "
endif

;========> TEXTin gadget to get port name for sendrexx command

xTEXTIN 370 20 120 14 "Port" gcPort "Gui4Cli" 40
GadID 2

;========> ROUTINE to execute command

xROUTINE DoCommand
docase $gcMode
case  = G4C
        SendRexx $gcPort $gcMain
        break
case  = CLI
        CLI $gcMain
        break
case  = RUN
        RUN $gcMain
        break
endcase


