!**************************************************************************************************!
! Purpose: test the GCONTROL FILE function
!
! Arguments: None
!
! @bug      NXM-910 GCONTROL: FILE does not accept /FLAGS=NOPATH
! @since    NeXtMidas 2.5.0
! @author:  J. Hallam
!**************************************************************************************************!
startmacro

switch INTERACTIVE interAct GET DEF=TRUE

! save off AUX.DAT and switch to DAT with all the test files
call setDatDir
res origDatAux "^{aux.dat}"
invoke nm_root nxm.sys.lib.Shell.getNmRoot()
if nm_root EQS "classpath:" then
  res aux.dat "^{nm_root}/^{datDirSlash}/"
else
  res aux.dat "^{nm_root}^{datDirSlash}/"
endif

if interAct then

  pipe init

    panel/msgid=MAIN/setup/controls=gc

    gcontrol label macro "MACRO" alwaysOpen
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemcolors {PASS=GREEN,FAIL=RED}

    gcontrol label test "TESTS" open
      ! DAT only, NOPATH
      set flags "EXT"
      gcontrol/title TEXT instructions1 "INSTRUCTIONS - DAT & ^flags" "" 24 3
        gcontrol FILE FILE_DAT_NOPATH "File Chooser: DAT only, ^flags" &
             world.prm "*.tmp|prm" "DAT" 60 10 /FLAGS="^flags"
        set instruct "Files in DAT aux should be listed and world.prm should be shown as the current file. &
                      Click on world.prm  and then select 'fftdemo.prm' in [DAT only] file chooser. &
                      NOTE: only one of NOPATH,AUXPATH or AUXQUAL applies, in that order of precedence."
        set gc.instructions1.value "^instruct"

      ! DAT only, AUX in front instead of path, and extension.
      set flags "AUXID|EXT"
      gcontrol/title TEXT instructions2 "INSTRUCTIONS - DAT & ^flags" "" 24 2
        gcontrol FILE FILE_DAT_AUXPATH "File Chooser: DAT only, ^flags" &
             world.prm "*.tmp|prm" "DAT" 40 10 /FLAGS="^flags" ! 3.7.2 smaller width so single column
        set instruct "Same as above, but result should be DAT/fftdemo.prm "
        set gc.instructions2.value "^instruct"
 
      ! DAT only, extension and AUX qualifier
      set flags "EXT|QUAL"
      gcontrol/title TEXT instructions3 "INSTRUCTIONS - DAT & ^flags" "" 24 2
        gcontrol FILE FILE_DAT_AUXQUAL "File Chooser: DAT only, ^flags" &
             world.prm "*.tmp|prm" "DAT" 40 10 /FLAGS="^flags" ! 3.7.2 smaller width so single column
        set instruct "Same as above, but result should be fftdemo.prm{AUX=DAT} "
        set gc.instructions3.value "^instruct"

      ! DAT only, NO PATH and NO extension
      set flags "NONE"
      gcontrol/title TEXT instructions4 "INSTRUCTIONS - DAT & ^flags" "" 24 2
        gcontrol FILE FILE_DAT_NOPATH_NOEXT "File Chooser: DAT only, ^flags" &
             world.prm "*.tmp|prm" "DAT" 60 10 /FLAGS="^flags"
        set instruct "Same as NOPATH, but result should be fftdemo "
        set gc.instructions4.value "^instruct"

  pipe off
endif

res aux.dat "^origDatAux"  ! restore original AUX.DAT

endmacro

!**************************************************************************************************!
procedure processMessage m:msg

  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: user indicated" msg.data eqs "PASS"
    pipe stop

  elseif msg.name eqss "FILE"  then 
    if msg.name EQS "FILE_DAT_NOPATH" then
      assert/text="^reg.main.name: select fftdemo.prm" msg.data eqs "fftdemo.prm"
    elseif msg.name EQS "FILE_DAT_AUXPATH" then
      assert/text="^reg.main.name: select fftdemo.prm" msg.data eqs "DAT/fftdemo.prm"
    elseif msg.name EQS "FILE_DAT_AUXQUAL" then
      assert/text="^reg.main.name: select fftdemo.prm" msg.data eqs "fftdemo.prm{AUX=DAT}"
    elseif msg.name EQS "FILE_DAT_NOPATH_NOEXT" then
      assert/text="^reg.main.name: select fftdemo.prm" msg.data eqs "fftdemo"
    else
      say "^reg.main.name: unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
    endif
  else
    ! do nothing
    say "^reg.main.name: unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif

return

!******************************************************************************!
! Set the dat directory
!******************************************************************************!
procedure setDatDir
  invoke nxmMajor env.nmversion.subString(0,1)
  invoke major java.lang.Integer.valueOf(nxmMajor)
  if major GE 4 then
    invoke s:datDir           nxm.sys.test.DatLocator.getDatDirLocation()
    invoke s:datDirSlash      nxm.sys.test.DatLocator.getDatDirSlashLocation()
    invoke z:sysDatFull       nxm.sys.test.DatLocator.sysDatFull()
    invoke z:sysTestDatExists nxm.sys.test.DatLocator.sysTestDatExists()
  else
    set s:datDir           "nxm.sys.dat"
    set s:datDirSlash      "nxm/sys/dat"
    set z:sysDatFull       true
    set z:sysTestDatExists false
  endif
return
