/*
  $VER: LhADir-handler 1.0 (14.5.95)
  Custom handler for LhADir.dopus5.
*/

options results
options failat 11

parse arg portname
parse var portname '.' portno
address value portname

if ~show('l','rexxsupport.library') then
   call addlib('rexxsupport.library',0,-30,0)

call openport('LhADir-handler'portno)

do forever
   if waitpkt('LhADir-handler'portno) then do
      packet=getpkt('LhADir-handler'portno)

      event=getarg(packet,0)
      handle=getarg(packet,1)
      name=getarg(packet,2)
      user=getarg(packet,3)

      if event='doubleclick' then do
         lister query handle entry '"'name'"' stem fileinfo.
         if fileinfo.type>0 then do  /* it's a dir */
            name=name'/'
            cmd='GETDIR'
            end
         else
            if pos(upper(right(name,4)),'.LHA.LZH.RUN')>0 then  /* archive in an archive */
               cmd='GETDIR'
            else
               cmd='DOUBLECLICK'
         address command 'Run >NIL: <NIL: rx DOpus5:arexx/LhADir.dopus5' cmd portname '"'name'"' handle
         end

      if event='inactive' then do
         lister query handle path
         winpath=result
         oldpath=getarg(packet,4)
         test=upper(winpath)
         if winpath=left(oldpath,length(winpath))&(pos('.LHA/',test)>0|pos('.LZH/',test)>0|pos('.RUN/',test)>0) then  /* user did parent */
            address command 'Run >NIL: <NIL: rx DOpus5:arexx/LhADir.dopus5 GETDIR' portname '""' handle
         else
            address command 'Delete >NIL: T:LhADir.list'handle 'QUIET'  /* remove temp file */
         end

      if event='drop' then do
         name=strip(name,'t')
         if right(name,1)=':' then
            lister read handle '"'name'"' force  /* user dropped a volume icon */
         end

      call reply(packet,0)
      end
   end
