%/*
       __ __ ___   Copyright (C) 1988-1991 IXI Limited.
       \ /  /  /
        /  /  /   IXI Limited, 62-74 Burleigh Street,
       /__/__/_\  Cambridge CB1 1OJ

       Program       : Rules
       Module        : System Rule File  ( english language )
       Version       : @(#) xdtsysinfo 6.21
%*/

%/****************************************************************************
 *									     *
 *     Copyright (c) 1991		   The Santa Cruz Operation, Inc.    *
 *									     *
 *     All rights reserved. No part of this program or publication may be    *
 *     reproduced, transmitted, transcribed, stored in a retrieval system,   *
 *     or translated into any language or computer language, in any form or  *
 *     by any means, electronic, mechanical, magnetic, optical, chemical,    *
 *     biological, or otherwise, without the prior written permission of:    *
 *									     *
 *		The Santa Cruz Operation, Inc	  (408) 425-7222	     *
 *		400 Encinal St, Santa Cruz, California 95060 USA	     *
 *									     *
 *****************************************************************************/

    SCO SCCS  : @(#) xdtsysinfo 8.6 92/10/29

%*/

%// INITIAL_ACTIONS
%// ***************

%/*
Controlling X.desktop 'System' processes
 3 dsh global vars 
    _xdt3i_up    :  '0' = xdt3info process NOT running
                    '1' = xdt3info process currently running
    _xpanel_pids :  '0' = xdtpanel process NOT running
                 :  otherwise holds PID's of xdtpanel and tellxdt 
                            processes sep by ':'
    Initial actions
        X.desktop normal start - Clr flags
    Rules
        xdt3info - _xdt3i_up is '1' - display error message
                 - otherwise start xdt3info and set _xdt3i_up
        xdtpanel - _xpanel_pids processes still running - error message
                 - otherwise startup panel procs and set 
                   PID's into _xpanel_pids
    Final Actions
        X.desktop normal closedown
            Kill xdtpanel processes
%*/

initial_actions
{
# Configuration Items
# ******************
#
# ---------------- Config these for each machine ----------------

# Tape device Name
#env TAPE_DRIVE '/dev/rmt/ctape0'     # NEVILLE
#env TAPE_DRIVE '/dev/rst8'       # CYCLOPS, BARHAM
#env TAPE_DRIVE '/dev/rmt/c0s0'       # ANSON
#env TAPE_DRIVE '/dev/rmt/0'          # EASTLEIGH
#env TAPE_DRIVE '/dev/rmt0'           # PLANET
#env TAPE_DRIVE '/dev/rmt0h'          # DURWELL, TINSLEY, ODIN
#env TAPE_DRIVE '/dev/rct/2s0'        # VENTURER (??)
 env TAPE_DRIVE '/dev/rct0'           # KIDWELLY
#env TAPE_DRIVE '/dev/UNKNOWN'        # <SYSNAME>

# Floppy disk device name
#env  DISK_DRIVE '/dev/rfd/fd0t00'      # NEVILLE  (Lo Density 720 Kb)
#env  DISK_DRIVE '/dev/rfd/fd0t01'      # NEVILLE  (Hi Density 1.44 MB)
#env  DISK_DRIVE '/dev/rfd0'            # CYCLOPS BARHAM
#env  DISK_DRIVE '/dev/f0q18dt'         # ANSON
#env  DISK_DRIVE '/dev/NONE'            # EASTLEIGH
#env  DISK_DRIVE '/dev/NONE'            # PLANET
#env  DISK_DRIVE '/dev/NONE'            # DURWELL, TINSLEY, ODIN
#env  DISK_DRIVE '/dev/NONE'            # VENTURER
 env  DISK_DRIVE '/dev/rfd096ds15'      # KIDWELLY
#env  DISK_DRIVE '/dev/UNKNOWN'         # <SYSNAME>

# 8mm tape drive
 env  EIGHT_MM_TAPE '/dev/UNKNOWN'      # <SYSNAME>'

# 5 1/4 disk device
#env  FIVE_DISK '/dev/UNKNOWN'          # <SYSNAME>'
 env  FIVE_DISK '/dev/rfd096ds15'       # KIDWELLY
#env  FIVE_DISK '/dev/rdsk/f0q15dt'     # ANSON

# CD device
 env CD_DRIVE '/dev/UNKNOWN'            # <SYSNAME>'

# The format command for a 3.5 disk
#env THREE_DISK_FORMAT 'fdformat'            # CYCLOPS BARHAM
 env THREE_DISK_FORMAT 'format '$DISK_DRIVE # <SYSNAME>'

# The format command for a 5.25 disk
 env FIVE_DISK_FORMAT 'format '$FIVE_DISK # <SYSNAME>'

# Switches for Processes obj (ps)
#    List all processes 
 env PS_SYSV  true      # ps -e = all procs, ps -u <username> = users procs
#env PS_SYSV  false     # BSDish uses ps -ax, ps -uax | grep <username>    

# Printer Command
env LPR_CMD     'lpr'   # Name of command to send request to lp spooler
                        # lp is SYSVish, lpr is BSDish

# Switches for diskfree (df) when we add the object 
# env DF_SWITCHES   '-k'    # EASTLEIGH

# ---------------- Config these depending on User Pref ----------------
# Env values set outside X.desktop will override these setups
# Lists are setup as 
#   Prog:NeedsXterm pairs e.g. ( vi:true xedit:false )

# Editor
# Use leftmost of these found in $PATH if $EDITOR not set
  editorlist=( 'scoedit:false' 'vi:true' 'xedit:false' 'emacs:true' ) 
# OR set explicitly here ( and whether needs xterm )
# env EDITOR 'vi:true'

# Pagers 
# Use leftmost of these found in $PATH if $VIEWER (or $PAGER) not set
  pagerlist=( 'less:true'  'pg:true' 'more:true' )  
# OR set explicitly here ( and whether needs xterm )
# env VIEWER 'more:true'

# Mailer
# Use leftmost of these found in $PATH if $MAILER not set
  mailerlist=('scomail:false' 'elm:true' 'mailx:true' 'mail:true')
# OR set explicitly here ( and whether needs xterm )
# env MAILER 'mail:true'

# ---------------- These should not need modification ----------------

# Magic to deal with resetting

  function reset
  {
    env _restarted true
    env _xdt3i_up '0'
    builtin reset
  }
  __restarted=($_restarted false)
  env _restarted $__restarted(1)

# Make sure the LANG environment variable is set 
  __lang=( $LANG C )
  env LANG $__lang(1)

# Make sure that the XDESKTOP environment variable is set
  __xdesktop=( $XDESKTOP /usr/lib/X11/XDesktop3 )
  env XDESKTOP $__xdesktop(1)

  __toolshed=( $TOOLSHED $XDESKTOP/$LANG.xdt/toolsheds )
  env TOOLSHED $__toolshed(1)

  # set USER if not set
  __user=( $USER `{ logname } )
  env USER $__user(1)

# Copy/Move functions should display a message if the copy/move may
# take some time.  Below is the variable which defines the size of a file.
# If the file being copied/moved is larger than this size a message is
# displayed.

  CopyMoveSize=500000

# ---------------- END OF CONFIGURATION SECTION ---------------- 


# Restart Handling
# ****************
if [ = $_restarted 'false' ]     # Normal startup
then 
    env _xpanel_pids '0'             # Clear dsh 'status' environ vars 
    env _xdt3i_up '0'
fi

#echo 'after reset chk: 
#         $_xpanel_pids= ' $_xpanel_pids '
#         $_xdt3i_up= ' $_xdt3i_up 


# System Variables
# ****************  

  OK=0 
  CANCELLED=2

# M013 Added dir state list (global var) to do stippling of dir View menu.
# Initialize with a dummy arg to workaround 'list intersect' behavior:
# Intersection of 'list a' with empty list is 'list a' rather than empty list.
# Empty lists are apparently reduced out of the equation before the intersection
# is done.
  :_dirview=(KEEP_LIST_FROM_BEING_EMPTY)

# System Functions
# ****************  

# o The function 'button' converts any trigger string ending in 1, 2
#   or 3 to the words first, second or third respectively.
# o Used when communicating with the user as the phrase 'the second button'
#   is preferable to 'the trigger s2'.
# o Returns the value in variable _button.

  function button {

# Only interested in the last character, so split the input into
# individual characters:

     ifs='' { _b=`( split $1)
     }

# $_b($#_b) gives the last value in the list variable $_b

     if [ == $_b($#_b) 1 ]
       then
	 _button=first
       elif [ == $_b($#_b) 2 ]
         then
	   _button=second
         elif [ == $_b($#_b) 3 ]
           then
	     _button=third
           else
	     _button=unknown
     fi

  }

# o The function 'filetype' returns the X.desktop file class string. (i.e.
#   the FWXM+0 type designation.)
# o Returns the value in list variable _type.

  function filetype {
    ifs='' { _type=`( split `( fileclass $1 ))
    }
# $_type(1) is the file type : File, Directory, Pipe, Character, etc...
# $_type(2) is the execute permission: eXecutable, Non-executable, etc...
# $_type(3) is the write permission: Writable, etc...
# $_type(4) is the ownership: M - owned by the user, O - owned by others
# $_type(5) is the symbolic link: + - it is, - it isn't
# $_type(6) is the variation class: 0 to 9
  }

# o The function 'time' returns the current system time
# o Returns the value in list variable _time.

  function time {
    ifs=' ' { __date=`{ date }
    }

# e.g. $__date(1) Fri
#      $__date(2) Mar
#      $__date(3) 15
#      $__date(4) 11:55:40
#      $__date(5) PST
#      $__date(6) 1991

    _time=$__date(4)
  }

# o The function 'set_desktop' copies the specified desktop into $HOME,
#   giving the user the option to overwrite it or not if it already exists.

function set_desktop
{
      copydt=0
      filetype $HOME/$1
      if [ == $_type(1) G ]
      then
         copydt=1
      else
         if yni -h setdesktop -t 'Set_Desktop' $1 'already exists in ' $HOME ': Overwrite it?'
         then
            copydt=1
         fi
      fi
      if [ -eq $copydt 1 ]
      then
         dt_admin=0; dt_power=0; discard_dt=0;
         filetype $HOME/Admin.dt
         if [ == $_type(1) F ]
         then
            dt_admin=1; discard_dt=1;
         fi
         filetype $HOME/Power.dt
         if [ == $_type(1) F ]   
         then
            dt_power=1; discard_dt=1;
         fi
         if [ -eq $discard_dt 1 ]
         then
            discard_dt=0;
            if yni -h setdesktop -t 'Set Desktop' $i 'This will discard your Admin/Power desktops in ' $HOME ' : Continue?'
            then 
               discard_dt=1;
            fi
         fi
         if [ -eq $discard_dt 1 ]   # need to remove existing Admin.dt/Power.dt
         then
            if [ -eq $dt_admin 1 ]
            then
               do_actions_of discard Admin.dt $HOME/trash
            fi
            if [ -eq $dt_power 1 ]
            then
               do_actions_of discard Power.dt $HOME/trash
            fi
            cp $XDESKTOP/$LANG.xdt/$1 $HOME
            chmod 644 $HOME/$1
            reset
         else                      # just copy it
            cp $XDESKTOP/$LANG.xdt/$1 $HOME
            chmod 644 $HOME/$1
         fi
      fi
}

# What to do if the user closes from the Window Manager button

# SCO session manager implementation

  function sigwmclose
  {
    filetype $thread_name(1)

    if [ == $_type(1) D ]
      then
        # M013 remove state info so next time dir is opened it is clean
	static_arg=$thread_name(1)
        remove_dir_view_states Names Details Time Size Show
        close_directory $thread_name(1)
        exit
    fi

    if [ != $main_desktop $thread_name(1) ]
      then
        if [ == $_type(3) W ]
          then
            close_desktop $thread_name(1)
          else
            close_desktop -N $thread_name(1)
        fi
        exit
    fi

    # shutdown if we got this far; closing last window
    die -i
  }


# What to do if we are asked to die:
#    we reach here if, (1) *ExitOnClose: Last and last desktop is closed
#                      (2) *ExitOnClose: Main and main desktop is closed

# SCO session manager implementation

  function sigshutdown
  {
	die -i
  }


# What kind of window did the action originate in?

  function what_window {
    filetype $1

    if [ != $_type(1) D ]
      then
	_window_type='Desktop'
      else
	_window_type='Directory'
    fi
  }

  function drop_on_me {
    _myself=false

    for icon in $dynamic_args
      do
	if [ == `( canonical $icon^/ ) `( canonical $static_arg^/ ) ]
	  then
	    _myself=true
	    break
	fi
      done
  }

  function get_type {
    icon=$dynamic_args($1) type=$d_obj_types($1)
  }

  # M013 routine to be called on close of any dir to make sure that the
  # view icon/names/details, sort:by_name/by_time/by_size, and dot file display
  # are removed from the global state variables

  function remove_dir_view_states
  {
    for i in $*
    do
      :_dirview=`(list subtract $:_dirview :: $static_arg^$i)
    done
  }

  # inserts a rule for the specified directory that hides its dot files.
  # The dynamic rule is named dot_$static_arg

  function hide_dot_files {
    if [ == $static_arg '/' ]
    then
      rdr dot_/
      idr dot_/ 'ic { /.* /F {pi=;} /.[a-z]* /D {pi=;}}'
    else
      rdr dot_^$static_arg
      idr dot_^$static_arg 'ic { '^$static_arg^'/.* /F {pi=;} '^$static_arg^'/.[a-z]* /D {pi=;}}'
    fi
    dot_state=hidden
  }

  # Do necessary checking etc to put up only a single xdt3info process
  # args are icons to display
  function handle_xdt3info {
    if [ == $_xdt3i_up '0' ] ; then       # Not running 
         env _xdt3i_up '1'                # flag it as up
         xdt3info -dtquit $*              # run in 'croak if xdt3 dies' mode 
         env _xdt3i_up '0'                # process died - flag it as down 
    else
        fyi -t xdt3info 'Properties window already Displayed
Drag and drop icon(s) onto it' 
    fi
  }

# Handle single display of panel process and set associated flags
function handle_panel {
        ifs=':'  { ppid=`(split $_xpanel_pids) }
        kill -sigdetect $ppid             # processes still alive
        if [ ! -eq $status 0 ] ; then     # No
            env _xpanel_pids '0'        
        fi

        if [ != $_xpanel_pids '0' ] ; then
            fyi 'A user preferences window is already open'
            # should raise xdtpanel wdw 
            exit
        fi

        # Start up panel
        { report -a -t 'User Preferences' -c 'OK' 'Reading User Preferences...'; sleep 10 } &
        # Start up panel
        {
            xdtpanel | tellxdt3 -
            env _xpanel_pids '0'   # process died - clear pid record
        } &
        p_thd=$last_background_action
        # wait till xdtpanel running so can store PID's
        until [ -gt $rp 0 ]
        do
            sleep 1
            ppid=`(query pid $p_thd)
            rp=$status
        done
        ofs=':' { t=`(join $ppid ) }
        env _xpanel_pids $t
}

# M028 Copy SCO.dt and autoconfigure Help and Trash icon placement
function create_initial_desktop
{
  # Attempt to ROUGHLY calculate positions; cannot be accurate since
  # size of menu and icon font are variable along with the icon label width
  # The constants below are estimates of the width between icons, the
  # height of the menubar, and the height between icons

  # Initialize
  screen_width=0; screen_height=0; icon_size=0;

  # get resources set with xrdb
  screen_width=`( get_resource xdt3.screen.width XDesktop3.Screen.Width )
  screen_height=`( get_resource xdt3.screen.height XDesktop3.Screen.Height )
  icon_size=`( get_resource xdt3.icon.size XDesktop3.Icon.Size )

  if [ == $screen_width 0 ]
  then
      # xrdb was not run; cannot calculate positions
      cp $XDESKTOP/$LANG.xdt/SCO.dt $HOME/Initial.dt
  else
      help_x=0
      trash_y=0
      case $screen_width
	  640 : help_x=9
		if [ == $screen_height 480 ]
		then
		    trash_y=6
		else
		    trash_y=4	# most likely 640x350
		fi
		;;
	  800 : help_x=10
		trash_y=4
		;;
	  1024 : help_x=12
		 trash_y=6
		 ;;
	  1280 : help_x=13
		 trash_y=8
		 ;;
      esac
      if [ != $help_x 0 ]
      then
          sed -e ''s/G7,0/G$help_x,0/'' -e ''s/G0,4/G0,$trash_y/'' < $XDESKTOP/$LANG.xdt/SCO.dt > $HOME/Initial.dt
      else
          cp $XDESKTOP/$LANG.xdt/SCO.dt $HOME/Initial.dt
      fi
  fi
}

function open_cmd
{
%// M011 Set dynamic args to just the selections in this window
      dynamic_args=`(query selections $thread_name(2));
      if [ -eq $#dynamic_args 0 ]
	then
	  dynamic_args=`( gti -t Open 'What would you like to open?' )
	  # M037 must specify /bin/sh otherwise you get deskshell sh
	  # Expand wildcards
	  dynamic_args=`{ /bin/sh -c 'echo $dynamic_args' }

          if [ != $status $OK ] || [ == $#dynamic_args 0 ]
            then
	      exit
	  fi

          d_obj_types=()

          for idx in `( sequence 1 1 $#dynamic_args )
            do
              filetype $dynamic_args($idx)

	      if [ == $_type(1) G ]
		then
		  d_obj_types=( $d_obj_types '-@' )
		else
		  d_obj_types=( $d_obj_types '-!' )
	      fi
            done
      fi

      if [ -gt $#dynamic_args 1 ]
	then
	  if yni -h open -t Open 'Do you wish to activate these icons one at a time?'
	    then
	      for idx in `( sequence 1 1 $#dynamic_args )
		do
		  get_type $idx
		  do_actions_of s1 $type $icon
		done

	      exit
	  fi
      fi

      for idx in `( sequence 1 1 $#dynamic_args )
        do
          get_type $idx
          actions_of s1 $type $icon	# M036
        done
}

function copy_cmd
{
      directory=`{ gti -h copying -t 'Copy to...' 'Enter the name of the directory you wish to copy to:' }

      if [ -ne $status 0 ] || [ == $#directory 0 ]
	then
	  exit
      fi

      if [ != $#directory 1 ]
	then
	  fyi -t 'Copy to...' 'You may not enter any spaces.'
	  exit
      fi

      filetype $directory

      if [ != $_type(1) D ]
	then
	  fyi -h copying -t 'Copy to...' 'The directory does not exist.'
	  exit
      fi

      if [ != $_type(3) W ]
	then
	  fyi -h prop -t 'Copy to...' 'You do not have permission to copy into this directory.'
	  exit
      fi

%// M011 Set dynamic args to just the selections in this window
      dynamic_args=`(query selections $thread_name(2));
      for idx in `( sequence 1 1 $#dynamic_args )
	do
	  get_type $idx
	  do_actions_of copy $type $icon $directory
	done
}

function move_cmd
{
      directory=`{ gti -h moving -t 'Move to...' -d $static_arg 'Enter the name of the directory you wish to move to:' }

      if [ -ne $status 0 ] || [ == $#directory 0 ]
	then
	  exit
      fi

      if [ != $#directory 1 ]
	then
	  fyi -t 'Move to...' 'You may not enter any spaces.'
	  exit
      fi

      filetype $directory

      if [ != $_type(1) D ]
	then
	  fyi -h moving -t 'Move to...' 'The directory does not exist.'
	  exit
      fi

      if [ != $_type(3) W ]
	then
	  fyi -h prop -t 'Move to...' 'You do not have permission to move into this directory.'
	  exit
      fi

%// M011 Set dynamic args to just the selections in this window
      dynamic_args=`(query selections $thread_name(2));
      for idx in `( sequence 1 1 $#dynamic_args )
	do
	  get_type $idx
	  do_actions_of move $type $icon $directory
	done
}

function discard_cmd
{
%// M011 Set dynamic args to just the selections in this window
      dynamic_args=`(query selections $thread_name(2));
      for idx in `( sequence 1 1 $#dynamic_args )
	do
            get_type $idx
	    do_actions_of discard $type $icon $HOME/trash
	done

# Change the trash can icon ?
      n_elements=`( contents_of $HOME/trash )

      if [ -gt $#n_elements 2 ]
      then
          variation_class 1 $HOME/trash
          check $HOME/trash
      else
          variation_class 0 $HOME/trash
          check $HOME/trash
      fi
}

function find_cmd
{
    names=`{ gti -t Find... 'Enter name of file to find:' }

    if [ != $status $OK ] || [ == $#names 0 ]
      then
	exit
    fi

%// M011 Set dynamic args to just the selections in this window
%// M017 Get just the selected directories
    dynamic_args=`(query selections $thread_name(2));
    sel_dirs=()
    for i in $dynamic_args
    do
      filetype $i
      if [ == $_type(1) D ]
      then
	sel_dirs=( $sel_dirs $i )
      fi
    done
    dynamic_args=$sel_dirs

    if [ != $#dynamic_args 0 ]
    then
   	dirs=$dynamic_args
    elif filetype $static_arg; [ == $_type(1) D ]
    then
%//     Have Find on directories default to that dir if no dirs selected
	dirs=$static_arg
    else
%//     Have Find on desktops default to $HOME if no dirs selected
	dirs=$HOME
    fi

%// report -a -t Find... 'Searching filing system...'

    touch $HOME/Find.dt
    open_desktop -h $HOME/Find.dt

    findcmd=( find $dirs -name $names(1) -print )
    namelist=( Searching 'for' $names(1) )

    for idx in `(sequence 2 1 $#names)
    do
      findcmd=( $findcmd -o -name $names($idx) -print )
      namelist=( $namelist $names($idx) )
    done

    report -a -t 'Find...' -c 'Cancel' $namelist

    if [ == $status $CANCELLED ]
      then
        close_desktop -N $HOME/Find.dt
        exit
    fi

    # do find
    files=`{ $findcmd >[2] /dev/null }

    if [ != $status $OK ]
      then
        report -a
        if yni -t Find... 'Find is unable to process named files.'
          then
            exit
        fi
    fi

    if [ == $#files 0 ]
      then
	report -a
	fyi -t Find... 'No files were found.'
	close_desktop -N $HOME/Find.dt
      else
        for file in $files
	  do
            get_out -l -! $file -d $HOME/Find.dt
	  done

	check -RD $HOME/Find.dt
	open_desktop $HOME/Find.dt
    fi
}

function do_trash
{
%// M015 trash.3 patch to avoid race condition with multiple selects
      if [ == $TRASHING 0 ]
      then
	env TRASHING 1
      else
	exit
      fi
      serial_file=$dynamic_args(1)^/.*.No
      if [ -eq $#serial_file 0 ]
      then
        trash='0'
      else
        ifs='.' { trash=`( split `( basename $serial_file ) ) }
        trash=`( basename $trash(1) )
      fi

%// M014 trash.2 patch for . and .. discard
      filetype $static_arg
      from_type=$_type(1)
      if [ == $from_type D ]
      then
	if [ == `( basename $static_arg ) '.' ]
	then
	  stat=`( dirname $static_arg )
	else
	  if [ == `( basename $static_arg ) '..' ]
	  then
	    stat=`( dirname `( dirname $static_arg ) )
	  else
	    stat=$static_arg
	  fi
	fi
      else
	stat=$static_arg
      fi
      bname=`( basename $stat )
      tname=$dynamic_args(1)^/$bname        # name of discarded item
                                            # in trash dir
      rname=`( dirname $stat )^'/'^$trash^'.rip' # name of discarded item
                                                 # in original directory
      filetype $tname

      if [ != $_type(1) G ]
      then
        if yni -t 'Trash: '$bname 'An item of this name has already been trashed.
Do you wish to irrecoverably delete the previously trashed item?'
        then
          if [ == $_type(1) D ]
          then
            rm -r `{ cat $tname/realname }
            rm -r $tname
            check -R $tname
          else
            rm `{ cat $tname }
            remove $tname
          fi
        else
          fyi -t Trash 'Trash action cancelled.'
%// M015 trash.3 patch to avoid race condition with multiple selects
          env TRASHING 0
          exit
        fi
      fi

%// M014 trash.2 patch for . and .. discard
      if [ == $from_type D ]
      then
	ifs='/' { here=`( split $stat ) }
	open_dirs=`( query open_directories )
	for item in $open_dirs
	do
	  ifs='/' { this_one=`( split $item ) }
	  if [ -gt $#this_one $#here ]
	  then
	    new=''
	    for i in `( sequence 1 1 $#here )
	    do
	      new=$new^'/'^$this_one($i)
	    done
	    if [ == $new $stat ]
	    then
	      cdw -e $item
	    fi
	  fi
	done
	cdw -e $stat
      else
	if [ == `( extension $stat ) '.dt' ] && [ != $main_desktop $stat ]
	then
	  cldt -e $stat
	fi
      fi

      rename $stat -b $trash^'.rip'
      check -R $stat
      vclass 1 $dynamic_args(1)
      check $dynamic_args(1)

      if [ == $from_type D ]
      then
        make_new_file -d $dynamic_args(1) -b $bname # make a new directory of
                                             # the basename in the trash
                                             # can
        echo $rname > $tname/realname
      else
        make_new_file $dynamic_args(1) -b $bname
        echo $rname > $tname
      fi

      # increment the value of $trash by 1
      trash=`( sequence $trash 1 '*' 2 )
      trash=$trash(2)

      if [ -eq $#serial_file 0 ]
      then
        make_new_file $dynamic_args(1) -b '.'^$trash^'.No'
      else
        rename $serial_file -b '.'^$trash^'.No'
      fi
%// M015 trash.3 patch to avoid race condition with multiple selects
      env TRASHING 0
}

# load rules installed by 3rd party applications
  dynamic_rule -e app_rules -f $XDESKTOP/$LANG.xdt/apprules/*

# Make sure that the EDITOR/VIEWER/MAILER environment variables are set 
# Note that ????NeedsXterm defaults to true

# Check for environment values already set 
  if [ ! -eq $#EDITOR 0 ]     # $EDITOR SET
  then
    # test if name:NeedsXterm pair
    ifs=':' { editor=`(split $EDITOR) }
    env EDITOR $editor(1)
    # check if EDITOR is in editorlist and set needxterm per entry
    needxterm=()
    binname=`( basename $EDITOR )
    for pair in $editorlist
    do
      ifs=':' { pairlist=`(split $pair ) } 
      if [ == $binname $pairlist(1) ]
      then
        needxterm=( $pairlist(2) )
	break		# found a match
      fi
    done
    tmp=( $editor(2) $needxterm true )   # true if editor(2) null & not in list
    env EditNeedsXterm $tmp(1)
  else
    # Editor not set, search path for favored programs
    for pair in $editorlist
    do
        for directory in $path  # search path for defaults 
        do
            ifs=':' { editor=`(split $pair ) } 
            filetype $directory/$editor(1)
	    if [ == $_type(1) F ] && [ == $_type(2) X ]
	    then
	        env EDITOR $editor(1)
                needxterm=( $editor(2) true )
	        env EditNeedsXterm $needxterm(1)
		break			# found prog
	    fi
	done
        if [ -gt $#EDITOR 0 ] ; then        # found prog 
            break;
        fi
    done
  fi

  Viewer=( $VIEWER $PAGER )   # viewer is $VIEWER if set else $PAGER     
  if [ ! -eq $#Viewer 0 ]     # $VIEWER SET
  then
    ifs=':' { viewer=`(split $Viewer) }
    env VIEWER $viewer(1)
    # check if VIEWER is in pagerlist and set needxterm per entry
    needxterm=()
    binname=`( basename $VIEWER )
    for pair in $pagerlist
    do
      ifs=':' { pairlist=`(split $pair ) } 
      if [ == $binname $pairlist(1) ]
      then
        needxterm=( $pairlist(2) )
	break		# found a match
      fi
    done
    tmp=( $viewer(2) $needxterm true )   # true if viewer(2) null & not in list
    env ViewNeedsXterm $tmp(1)
  else
    # Viewer not set, search path for favored programs
    for pair in $pagerlist
    do
        for directory in $path  # search path for defaults 
        do
            ifs=':' { viewer=`(split $pair ) }
            filetype $directory/$viewer(1)
	    if [ == $_type(1) F ] && [ == $_type(2) X ]
	    then
	        env VIEWER $viewer(1)
                needxterm=( $viewer(2) true )
	        env ViewNeedsXterm $needxterm(1)
		break			# found prog
	    fi
        done
        if [ -gt $#VIEWER 0 ] ; then        # found prog 
            break;
        fi
    done
  fi

  if [ ! -eq $#MAILER 0 ]     # MAILER set
  then
    ifs=':' { mailer=`(split $MAILER) }
    env MAILER $mailer(1)
    # check if MAILER is in mailerlist and set needxterm per entry
    needxterm=()
    binname=`( basename $MAILER )
    for pair in $mailerlist
    do
      ifs=':' { pairlist=`(split $pair ) } 
      if [ == $binname $pairlist(1) ]
      then
        needxterm=( $pairlist(2) )
	break		# found a match
      fi
    done
    tmp=( $mailer(2) $needxterm true )   # true if viewer(2) null & not in list
    env MailNeedsXterm $tmp(1)
  else
    # Mailer not set, search path for favored programs
    for pair in $mailerlist
    do
        for directory in $path  # search path for defaults 
        do
            ifs=':' { mailer=`(split $pair ) }
            filetype $directory/$mailer(1)
	    if [ == $_type(1) F ] && [ == $_type(2) X ]
	    then
	        env MAILER $mailer(1)
                needxterm=( $mailer(2) true )
	        env MailNeedsXterm $needxterm(1)
		break			# found prog
	    fi
        done
        if [ -gt $#MAILER 0 ] ; then        # found prog 
            break;
        fi
    done
  fi

# unset variables don't need anymore
  editorlist=(); pagerlist=(); mailerlist=()
  editor=(); viewer=(); mailer=(); Viewer=()
  directory=(); pair=(); pairlist=(); binname=()
  needxterm=(); tmp=()

# The trash can has two pictures (one for if it is empty and one for if there's
# something in it....  so set the right picture.

  __n_elements=`( contents_of $HOME/trash )

  if [ -gt $#__n_elements 2 ]
    then
      variation_class 1 $HOME/trash
      check $HOME/trash
  fi

  # check if user needs a trash dir
  filetype $HOME/trash 
  if [ != $_type(1) D ]
  then
      # check if trash exists but is not a dir
      if [ == $_type(1) F ]
      then
          # find a name to backup to
	  oldtrash=NULL
          for i in trash.bak trash- trash.sav trash.00 trash.01 trash.02
          do
	      filetype $HOME/$i
              if [ == $_type(1) G ]	# found a name to backup to
              then
		  oldtrash=$i
		  break
              fi
          done
	  if [ != $oldtrash NULL ]
	  then
              mv $HOME/trash $HOME/$oldtrash
              fyi -t 'Startup' 'The file ''trash'' has been backed up to the file '$HOME/$oldtrash
	  else
              fyi -t 'Startup' 'The file ''trash'' exists and cannot be backed up.%#10#Please rename or remove it before restarting'
	      exit
	  fi
      fi

      # waste dir exists; move that per xdt3newuser
      filetype $HOME/waste
      if [ == $_type(1) D ]
      then
          mv $HOME/waste $HOME/trash
      else
          mkdir $HOME/trash
      fi
      chmod 755 $HOME/trash
      cp $XDESKTOP/$LANG.xdt/xdtdirinfo.t $HOME/trash/.xdtdirinfo
      chmod 644 $HOME/trash/.xdtdirinfo
  fi

# Look for Admin.dt, Power.dt, General.dt then Initial.dt in $HOME
# Open the first one it finds and install it's rules globally.
# If none of these desktops exist, run create_initial_desktop

# Note: There is a difference in action when the user drops an icon on to a
# desktop icon if the desktop window is open or not, so make sure that every
# time we open or close a desktop we change the rule.

  dtlist=(Admin.dt Power.dt General.dt Initial.dt)
  for dtfile in $dtlist
  do
      filetype $HOME/$dtfile
      if [ != $_type(1) G ]         # found a desktop file
      then                          # => open it
         variation_class 1 $HOME/$dtfile
         change_environment $HOME/$dtfile
         break;                     # get out of this loop
      fi

      if [ == $dtfile $dtlist($#dtlist) ]    # reached end of the list
      then
	 # M026 startup code
	 newuser=true

         # check if upgrading from a previous version
	 filetype $HOME/xdtinitial.xde
	 if [ != $_type(1) G ]	# found an old .xde
	 then
	     if yni -t 'Upgrade' 'Confirm that you wish to upgrade from a previous release.%#10#Your previous rules file will be preserved in '$HOME/xdtinitial.xde
	     then
		 create_initial_desktop
	     else
		 mv $HOME/xdtinitial.xde $HOME/Initial.dt
	     fi
	 else
	     create_initial_desktop
	 fi
	 chmod 644 $HOME/Initial.dt

	 # make sure no perms or other problems took place
         filetype $HOME/Initial.dt
         if [ != $_type(1) G ]         # found Initial.dt
         then                          # => open it
            variation_class 1 $HOME/Initial.dt
            change_environment $HOME/Initial.dt
            break;                     # get out of this loop
         else
            fyi -t 'Error' 'Initial.dt not created in the home directory, exiting'
            die -i
         fi
      fi
  done
  dtlist=(); dtfile=()	# no longer needed so unset them to clear environment

  # new users need a new .xdtdirinfo even if they had a trash dir before
  if [ == $newuser true ]
  then
      cp $XDESKTOP/$LANG.xdt/xdtdirinfo.t $HOME/trash/.xdtdirinfo
      chmod 644 $HOME/trash/.xdtdirinfo
  fi

  # M056 Create a config file in the user's home dir
  filetype $HOME/XDesktop3
  if [ != $_type(1) F ]
  then
      xrdb -query | grep 'XDesktop3\*isRoot' > $HOME/XDesktop3
  fi

%// M015 trash.3 patch to avoid race condition with multiple selects
   env TRASHING 0

%/*  M025 disable this for now to avoid wait sprite every $MAIL_DELAY secs

   # M023 Change mail icon when new mail arrives; start a background thread
   {
     mailer_posn=( $MAIL_POSN $TOOLSHED/Accessories/Mail.obj )
     mail_delay=( $MAIL_DELAY 60 )

     # Enter an infinite loop
     while true;
     do
       # Check to see if there is any mail.
       mail -e

       # Check to see if mail was found
       if [ == $status 0 ]
       then
	 # Mail was found, so insert a dynamic rule to change the pixmap.
	 dynamic_rule MailRule 'ic { %$TOOLSHED$/Accessories/Mail.obj { picture=Mail1.px } }'

	 # Do a check to update the actual picture.
	 check $mailer_posn
       else
         # There is no mail, so make sure that the default
	 # rule is used.  I.e. ensure the dynamic rule is removed
	 remove_dynamic_rule MailRule

	 # Update the picture
	 check $mailer_posn
       fi

       sleep $mail_delay

     done
   }&
%*/
}


%// FINAL_ACTIONS
%// *************

final_actions
{
    # Stop xdtpanel if its up
    if [ != $_xpanel_pids '0' ]
    then
        ifs=':'  { ppid=`(split $_xpanel_pids) }
        kill -sigkill $ppid
    fi
    # No need to explicitly kill xdt3info as it shuts itself 
    # down when desktop ends or resets
}


%// ICON_RULES
%// **********

icon_rules
{
%// M003 Hide the following dirs

  /.. /D
  {
    picture=;
  }

  %$HOME$/.. /DX
  {
    picture=;
  }

  . /D
  {
    picture=;
  }

  %$HOME$ /DWX
  {
    title=%$USER$'s%#10#Directory;

%// can't discard the Home directory

    trigger_action: discard
    {
      fyi -h trash0 -t 'Icon: Home' 'You may not discard the home directory.'
    }

%// can't move the Home directory

    trigger_action: move
    {
      fyi -t 'Icon: Home' 'You may not move the home directory.'
    }
  }

%// old style trash bundle
  %$HOME$/trash/??:??:?? /F
  {
    picture=can.px;

    trigger_action: s1
    {
# Put the contents of the garbage bundle back

      tar xf $static_arg

      for file in `{ tar tf $static_arg }
        do
          ifs='/' { dirpath=`( split $file ) }

	  newdir='/'

          for dir in $dirpath
	    do
	      newdir=$newdir^$dir
	      check $newdir
	      newdir=$newdir^/
	    done
        done

      remove $static_arg

# Is the trash can empty?

      dir=`(dirname $static_arg)
#     n_elements=$static_arg/??:??:??
      n_elements=`( contents_of $dir )

      if [ -eq $#n_elements 0 ]
	then
	  variation_class 0 $dir
	  check $dir
      fi
    }

    trigger_action: s2
    {
# List the contents of the garbage bundle

      shell -n Trash tar tf $static_arg ';' xdtwait
    }

    trigger_action: s3
    {
# Put specified parts of the garbage bundle back

      files=`( gti -h trash0 -t Trash 'Enter the full names of the files to restore' )

      if [ -ne $status $OK ] || [ == $#files 0 ]
        then
          exit
      fi

      for file in $files
        do
          tar xf $static_arg $file
          check $file
        done
    }
  }

%// New style trash - empty
  trash /DWXM0
  {
%// M018 use SCO icon names
%// picture=empty_trash.px;
    picture=empty_t.px;

    trigger_action: s3
    {
      fyi -h trash0 -t Trash 'The trash can is already empty'
    }
  }

  trash /DWXM1
  {
%// M018 use SCO icon names
%// picture=trash.px;
    picture=Trash.px;
  }

%// New style trash - contains trash
  trash /DWXM
  {
    title=Trash;

%// The system rule file only has confirmation on emptying the trash can.

    trigger_action: s3
    {
      if yni -h 'trash0' -t Trash 'Confirm you wish to empty the trash can.'
      then
        oldtrash=%$HOME$/trash/??^':'^??^':'^??  # old style trash bundles
        if [ -ne $#oldtrash 0 ]
        then
            /bin/sh -c '
            for file in '$static_arg'/??:??:?? 
              do
                rm $file
                tellxdt3 -- check -R \''$file\''
              done'
      fi

      for item in %$HOME$/trash/[!.]*
      do
        filetype $item
        if [ == $_type(1) F ]      # File
        then
            rname=`{cat $item}  # get .rip filename
            remove $rname       # remove .rip file
            remove $item      # remove trash record
         elif [ == $_type(1) D ]
            rname=`{cat $item/realname} # get .rip filename
            /bin/rm -rf $rname          # remove .rip dir
             check -R $rname
            /bin/rm -rf $item           # remove trash record
             check -R $item
         fi
      done

# Now make sure picture shows empty trash can, if empty
          n_elements=`( query contents $static_arg )

          if [ -le $#n_elements 2 ]
            then
              # Zero the serial number
              rename -e $HOME/trash/.*.No -b .0.No
              variation_class 0 $static_arg
              check $static_arg
          fi
      fi
    }

%// Throw something away by dropping it on to the trash can.
    trigger_action: d*
    {
# Tell each icon to discard itself and where to discard it...

      for idx in `( sequence 1 1 $#dynamic_args )
      do
        do_actions_of discard $d_obj_types($idx) $dynamic_args($idx) $static_arg
      done

# Change the trash can icon

      n_elements=`( contents_of $static_arg )

      if [ -gt $#n_elements 2 ]
        then
          variation_class 1 $static_arg
          check $static_arg $static_arg
      fi
    }

    trigger_action: h3
    {
      popup trash_menu $static_arg -d $s_desktop
    }

    drop_in_action: d*
    {
      actions_of d1 -! $static_arg `( merge d_obj_types dynamic_args )
    }

%// You can't copy the trash can!

    trigger_action: copy
    {
      fyi -h copying -t 'Icon: Trash' 'You may not copy the trash can.'
    }

%// You can't discard the trash can!

    trigger_action: discard
    {
      fyi -h trash0 -t 'Icon: Trash' 'You may not discard the trash can.'
    }

%// You can't move the trash can!

    trigger_action: move
    {
      fyi -t 'Icon: Trash' 'You may not move the trash can.'
    }

%// You can't print the trash can!  

    trigger_action: print
    {
      fyi -h print -t 'Icon: Trash' 'You may not print the trash can.'
    }
  }

%// Discarded file
  *.rip /DF
  {
    picture=;
  }

  .. /D
  {
%// M003 Change to Parent Directory
    title=Parent (..)%#10#Directory;
%// M018 use SCO icon names
    picture=dirup.px;
  }

%// The applications cabinet, formerly known as the software initiative
%// directory (SID)

  %$XDESKTOP$/applications /DX
  {
%// M018 use SCO icon names
%// picture=supplies.px;
    picture=apps.px;
    title=Applications;
  }

  %$TOOLSHED$/Controls /DX
  {
    title=Controls;
    picture=controls.px;
  }

  %$TOOLSHED$/Accessories /DX
  {
    title=Accessories;
    picture=accesso.px
  }

%// A rule file directory.  Note that this will be over-ridden by any
%// higher priority rule for .* /D

  .xdtdir /DRX
  {
    trigger_action: s*
    {
      if [ == $EditNeedsXterm true ]
	then
          shell -n 'Edit '^`( basename $static_arg ) $EDITOR $static_arg/$LANG ';' xdtwait
	else
          $EDITOR $static_arg/$LANG
      fi
    }
  }

%// The same rules for the system rule directory

  xdtsysinfo /DRX
  {
    trigger_action: s*
    {
      if [ == $EditNeedsXterm true ]
	then
          shell -n 'Edit '^`( basename $static_arg ) $EDITOR $static_arg/$LANG ';' xdtwait
	else
          $EDITOR $static_arg/$LANG
      fi
    }
  }

  %$TOOLSHED$/Accessories/Print.obj /DRX1
  {
    picture=Print1.px;
  }

  %$TOOLSHED$/Accessories/Print.obj /DRX2
  {
    picture=Print2.px;
  }

  %$TOOLSHED$/Accessories/Print.obj /DRX3
  {
    picture=Print3.px;
  }

%// The general rule for an object (directory)

  *.obj /DRX
  {
    picture=%P0/picture.px;
    title=%E0;

    trigger_action: s*
    {
# Is there a rule for this trigger?

      filetype $static_arg/$trigger.objscr

      if [ == $_type(1) F ]
	then
# If there is, execute it (assumed to be a deskshell script)

          cd $static_arg
          . `( canonical $trigger.objscr )
	else
# Otherwise, show a message saying nothing done

          button $trigger

	  filetype $static_arg/s1.objscr
	  # check if this is button 3 and an s1 script exists
	  if [ == $_button third ] && [ == $_type(1) F ]
	  then
	    # collect options and run button 1 script for button 3 action
	    options=`( gti -t `( basename `( unextended $static_arg ) ) 'Enter any options you require:' )
	    if [ -ne $status 0 ]
	    then
	      exit
	    fi
	    cd $static_arg
	    . `( canonical s1.objscr ) `( split $options ) # run s1 script with options set
	  else
# Note that `( basename `( unextended $static_arg )) is different
# to `( unextended `( basename $static_arg ))
            fyi -h icons -t 'Icon: '^`( basename `( unextended $static_arg )) 'The '$_button' mouse button has no effect on this icon.'
	  fi
      fi
    }

%// The same for drag and drop actions

    trigger_action: d*
    {
      filetype $static_arg/$trigger.objscr

      if [ == $_type(1) F ]
	then
          cd $static_arg
	  # dont need to pass dynamic_args on cmd line
          . `( canonical $trigger.objscr )
	else
          button $trigger
	  filetype $static_arg/d1.objscr
	  # check if this is button 3 and a d1 script exists
	  if [ == $_button third ] && [ == $_type(1) F ]
	  then
	    # collect options and run button 1 script for button 3 action
	    options=`( gti -t `( basename `( unextended $static_arg ) ) 'Enter any options you require:' )
	    if [ -ne $status 0 ]
	    then
	      exit
	    fi
	    cd $static_arg
	    # dont need to pass dynamic_args on cmd line
	    . `( canonical d1.objscr ) `( split $options ) # run d1 script with options set
	  else
            fyi -h icons -t 'Icon: '^`( basename `( unextended $static_arg )) 'The '$_button' mouse button has no effect on this icon.'
	  fi
      fi
    }

%/* Right now, this doesn't work because popup is asynchronous.
    This should change before release.

    trigger_action: h3
    {
      filetype $static_arg/$trigger.objscr

      if [ == $_type(1) F ]
	then
	  dynamic_rule `(basename $static_arg ) -f $static_arg/$trigger.objscr
	  popup obj_^$trigger^_menu $static_arg -d $s_desktop
	  remove_dynamic_rule `( basename $static_arg )
	else
          fyi -h icons -t 'Icon: '^`( basename `( unextended $static_arg )) 'There is no menu defined for this icon.'
      fi
    }

    The following rule is a temporary replacement which requires the menu
    to be defined in the rule file:
%*/

    trigger_action: h3
    {
      filetype $static_arg/$trigger.objscr

      if [ == $_type(1) F ]
        then
          popup `{ cat $static_arg/$trigger.objscr } $static_arg -d $s_desktop
      fi
    }

%// And print triggers

    trigger_action: print
    {
      filetype $static_arg/print.objscr

      if [ == $_type(1) F ]
	then
          cd $static_arg
          . `( canonical $trigger.objscr ) $dynamic_args
	else
          button $trigger
          fyi -h print -t 'Icon: '^`( basename `( unextended $static_arg )) 'You may not print this icon.'
      fi
    }

%// The fact that there is no move, copy or discard trigger means that
%// none of these actions may be performed on an object directory.
  }

%// The generic rule for toolshed directories

  *.ts /DRX
  {
    title=%E0;
  }

  *.dbs /DWX
  {
%// M018 use SCO file icon 
%// picture=dbs.px;

    trigger_action: s1
    {
      actions_of d1 -! $XDESKTOP/applications/aisql.obj $static_arg
    }

    trigger_action: d1
    {
      if [ != $#dynamic_args 1 ]
	then
	  fyi -t 'Altered Image-SQL' 'You may only drop one icon onto this icon.'
	  exit
      fi

      if [ == `( extension $dynamic_args ) '.sql' ]
	then
	  aisql $static_arg $dynamic_args || 
	  actions_of s1 -! $XDESKTOP/applications/aisql.obj
          exit
      fi

      fyi -t 'Altered Image-SQL' 'You can''t do that.'
    }
  }

%// The generic rule for all writable directories

  * /DWX
  {
    picture=dir.px;

%// M044
    trigger_action: d2
    {
# A copy, if not a put back
      drop_on_me

      if [ == $_myself 'true' ]
	then
	  fyi -h copyicon -t 'Icon: '^`( basename $static_arg ) 'You may not copy a directory to itself.'
	  exit
      fi

      for idx in `( sequence 1 1 $#dynamic_args )
        do
	  get_type $idx

          if [ == `( dirname `( canonical $icon^/ )) `( canonical $static_arg^/ ) ]
	    then
# The only occasion when it is possible to move an icon into the directory
# where it exists, is if you are coming from a desktop window
	      put_back $type $icon -d $d_desktop
	    else
# The icon is moved into this window from either; a third-party application,
# or another directory window
	      do_actions_of copy $type $icon $static_arg
          fi
	done
    }

%// M044
    trigger_action: d1
    {
# A move, if not a put back

      drop_on_me

      if [ == $_myself 'true' ]
	then
	  fyi -h moveicon -t 'Icon: '^`( basename $static_arg ) 'You may not move a directory to itself.'
	  exit
      fi

      for idx in `( sequence 1 1 $#dynamic_args )
        do
          get_type $idx

          if [ == `( dirname `( canonical $icon^/ )) `( canonical $static_arg^/ ) ]
	    then
	      put_back $type $icon -d $d_desktop
	    else
	      do_actions_of move $type $icon $static_arg
          fi
	done
    }

    trigger_action: move
    {
# Move this directory somewhere else

      if [ == `( canonical $dynamic_args^/ ) `( canonical $static_arg^/ ) ]
	then
	  fyi -h moveicon -t 'Icon: '^`( basename $static_arg ) 'You may not move a directory to itself.'
	  exit
      fi

      if [ == `( dirname `( canonical $dynamic_args^/ )) `( canonical $static_arg^/ ) ]
      then
	  # M050
	  if [ -eq $#d_desktop 0 ]
	  then
	      put_back $dynamic_args
	  else
	      put_back $dynamic_args -d $d_desktop
	  fi
	  exit
      fi

      filetype $dynamic_args

      if [ != $_type(1) D ]
	then
	  fyi -h moving -t 'Icon: '^`( basename $dynamic_args ) 'You must specify a directory to move to.'
	  exit
      fi

      if [ != $_type(3) W ]
	then
	  fyi -h moving -t 'Icon: '^`( basename $dynamic_args ) 'You do not have permission to move into this directory.'
	  exit
      fi

      filetype $dynamic_args/^`( basename $static_arg )

      if [ != $_type(1) G ] && [ != $_type(1) @ ]
	then
# CHANGE: Changing here lets you actually do an overwrite if requested
	  fyi -h moving -t 'Icon: '^`( basename $static_arg ) 'This directory already exists in the destination directory.
Not moving...'

	  exit
      fi

      report -a -t Move -c Cancel 'Moving a directory may take some time.'

      if [ == $status $CANCELLED ]
        then
          report -t Move -c OK 'Move operation cancelled...'
          exit
      fi

      make_new_file -d $dynamic_args -b `( basename $static_arg )

      if [ -ne $status $OK ]
	then
	  exit
      fi

      for file in `( contents_of $static_arg )
	do
	  do_actions_of move -! $static_arg/$file $dynamic_args/^`( basename $static_arg )
	done

# This is a move, so if it was successful, remove this directory

      n_elements=`( contents_of $static_arg)

      if [ -eq $#n_elements 0 ]
	then
	  rmdir $static_arg
	  check -R $static_arg

# use -e because directory may not have been open!
	  # M013 just in case the name get reused remove the old view states
	  remove_dir_view_states Names Details Time Size Show
	  close_directory $static_arg -e
      fi
    }

    trigger_action: discard
    {
      do_trash
    }
  }

%// A generic rule for all readable directories

  * /DRX
  {
%// M018 use SCO icon names
%// picture=dir_read.px;
    picture=dirnw.px;

    trigger_action: s1
    {
      # M013 see if dir is showing dot files, only hide if they are not
      # supposed to be showing e.g. double click on dir that is already
      # open and set to display dot files

      # Get canonical name since icon might be ..
      can_static_arg=`(canonical $static_arg^/)
      vstate=`(list intersect $can_static_arg^Show :: $:_dirview)
      dirname=`(canonical $static_arg)
      if [ == $dirname $HOME/trash ]
      then
	# mark state as Show for trash
        :_dirview=( $static_arg^Show $:_dirview )
      elif [ -eq $#vstate 0 ]
      then
	hide_dot_files
      fi
      display_directory $static_arg
    }

    trigger_action: s2
    {
# This only works because the name of the icon representing the parent
# directory is .. and dirname /dir/.. is /dir

#      M013 Do not hide dot files when switching dirs in same window
#      hide_dot_files

      # M013 need to change dir name here for each state set, (i.e. cd)
      # Get canonical name since icon might be ..
      can_static_arg=`(canonical $static_arg^/)
      if [ != $s_desktop $can_static_arg ]
      then
	save_states=()
        for i in Names Details Time Size Show
	do
	  chk_state=`(list intersect $s_desktop^$i :: $:_dirview)
	  if [ -ne $#chk_state 0 ]
	  then
	    save_states=($save_states $i)
	  fi

	  # remove old dir state info
	  :_dirview=`(list subtract $:_dirview :: $s_desktop^$i)

	  # remove any new dir state info, since cd uses states of old dir
	  :_dirview=`(list subtract $:_dirview :: $can_static_arg^$i)
        done

	# add old state info for new dir
	for i in $save_states
	do
	  :_dirview=($:_dirview $can_static_arg^$i)
	done

	# M086 if old dir was hiding dot files update dynamic rules for new dir
	vstate=`(list intersect $can_static_arg^Show :: $:_dirview)
        if [ -eq $#vstate 0 ]
	then
	  rdr dot_^$s_desktop
	  # Get rid of any .. etc in static_arg
	  static_arg=$can_static_arg
	  hide_dot_files
	fi
      fi

      display_directory $s_desktop $static_arg
#     display_directory `( dirname $static_arg ) $static_arg 

# If backward compatibility is not required,
# check the return status and if it failed open a new window
# This would mean that s1 and s2 would work the same if the parent
# directory wasn't actually open.

#     display_directory $static_arg `( dirname $static_arg ) -e

#     if [ -ne $status $OK ]
#       then
#         display_directory $static_arg
#     fi
    }

    trigger_action: copy
    {
      if [ == `( canonical $dynamic_args^/ ) `( canonical $static_arg^/ ) ]
	then
	  fyi -h copyicon -t 'Icon: '`( basename $static_arg ) 'You may not copy a directory to itself.'
	  exit
      fi

      if [ == `( dirname `( canonical $dynamic_args^/ )) `( canonical $static_arg^/ ) ]
      then
	  # M050
	  if [ -eq $#d_desktop 0 ]
	  then
	      put_back $dynamic_args
	  else
	      put_back $dynamic_args -d $d_desktop
	  fi
	  exit
      fi

      filetype $dynamic_args

      if [ != $_type(1) D ]
	then
	  fyi -h copying -t 'Icon: '^`( basename $dynamic_args ) 'You must specify a directory to copy to.'
	  exit
      fi

      if [ != $_type(3) W ]
	then
	  fyi -h copying -t 'Icon: '^`( basename $dynamic_args ) 'You do not have permission to copy into this directory.'
	  exit		# M048
      fi

      filetype $dynamic_args/^`( basename $static_arg )

      if [ != $_type(1) G ] && [ != $_type(1) @ ]
	then
# NOTE: Change to actually do an overwrite if requested
	  fyi -h copying -t 'Icon: '^`( basename $static_arg ) 'This directory already exists in the destination directory.
Not copying...'

	  exit
      fi

      report -a -t Copy -c Cancel 'Copying a directory may take some time.'

      if [ == $status $CANCELLED ]
        then
          report -t Copy -c OK 'Copy operation cancelled...'
          exit
      fi

      make_new_file -d $dynamic_args -b `( basename $static_arg )

      for file in `( contents_of $static_arg )
	do
	  do_actions_of copy -! $static_arg/$file $dynamic_args/^`( basename $static_arg )
	done
    }

    trigger_action: print
    {
      /bin/sh -c 'ls -l | '`{basename $dynamic_args}
    }
  }

  * /D
  {
%// M018 use SCO icon names
%// picture=dir_pdl.px;		# was used for * /DX
%// picture=dir_noent.px;	# was used for * /DU
    picture=dirnrnw.px;
  }

  xdt3info /FX
  {
    title=Properties;

    trigger_action: s1
    {
       if [ == $_xdt3i_up '0' ] ; then
          fyi -t 'Properties' 'You must drop file(s) on to this icon'
       else
           fyi -t 'Properties' 'Drop a file onto the properties window'
       fi
    }

    trigger_action: d1
    {
      handle_xdt3info $dynamic_args
    }
  }

  scohelp /FX
  {
    trigger_action: s*
    {
      help help_startup
    }

    trigger_action: d*
    {
      if [ -ne $#dynamic_args 1 ]
 	then
 	  fyi -t Help 'You may only drop one icon onto Help.'
	  exit
      fi

      help `( basename $dynamic_args )
    }
  }

  scopaint /FX
  {
    trigger_action: s1
    {
      $static_arg
      pixmap_check
    }

    trigger_action: d1
    {
      sels=()
      for i in $dynamic_args
      do
          ext=`( extension $i)
          if [ == $ext '.px' ] || [ == $ext '.xbm' ] || [ == $ext '.xpm' ]
          then
	      sels=( $sels $i )
          else
	      # check for XPM files
	      head -1 $i | grep '^\! XPM' > /dev/null
	      xpm_status=$status(2)
	      if [ == $xpm_status 0 ] 
	      then
	          sels=( $sels $i )
	      else
	          # check for XBM files
	          grep '^#define' $i | grep '_width [0-9]' > /dev/null
	          xbm_status1=$status(2)
	          grep '^#define' $i | grep '_height [0-9]' > /dev/null
	          xbm_status2=$status(2)
    
	          if [ == $xbm_status1 0 ] && [ == $xbm_status2 0 ]
	          then
	              sels=( $sels $i )
	          else
	              # note 2 line dialog below (newline within quotes)
                      if yni -h Paint.obj -t 'ScoPaint' `(basename $i) 'does not seem to be a pixmap file.
Do you wish to edit the icon picture?'
                      then
	                  sels=( $sels `(query picture $i) )
	              else
	                  sels=( $sels $i )
                      fi
	          fi
	      fi
          fi
      done
      scopaint $sels
      pixmap_check
    }
  }

%// M018 Don't make these look special
%// .xdtdirinfo xdtsysinfo & [sd][1-2].objscr /FR
%// and .xdtdir & xdtsysinfo /DWX
%// and .xdtuserinfo /FM had the following rule
%// picture=rule_file.px;

  adb /FRX
  {
%// M018 Don't make this look special
%// title=Debugger;
%// picture=debug.px;

    trigger_action: s*
    {
      fyi -t 'Debugger' 'You must drop a binary file on to this icon.'
    }

    trigger_action: d*
    {
      if [ -ne $#dynamic_args 1 ]
	then
	  fyi -t 'Debugger' 'You must drop only one icon at a time on to this icon.'
	  exit
      fi

      filetype $dynamic_args

      if [ == $_type(1) F ] && [ == $_type(2) X ]
	then
	  shell -n 'Debugger' 'cd '^`( dirname $static_arg )^' ; '$static_arg' '$dynamic_args
	else
	  fyi -t 'Debugger' 'You must drop only binary files on to this icon.'
      fi
    }
  }

  ar /FRX
  {
%// M018 Don't make this look special
%// title=Archiver;
%// picture=arch.px;

    trigger_action: s*
    {
      fyi -t 'Archiver' 'You must drop a binary file on to this icon.'
    }
  }

  as /FRX
  {
%// M018 Don't make this look special
%// title=Assembler;

    trigger_action: s*
    {
      fyi -t 'Assembler' 'You must drop an assembler source code file on to this icon.'
    }
  }

  asm /FRX
  {
%// M018 Don't make this look special
%// title=Assembler;

    trigger_action: s*
    {
      fyi -t 'Assembler' 'You must drop an assembler source code file on to this icon.'
    }
  }

  at /FRX
  {
%// M018 Don't make this look special
%// picture=clock.px;

    trigger_action: s*
    {
      shell -n 'at' 'atq ; xdtwait'
    }

    trigger_action: h3
    {
      popup at_menu $static_arg -d $d_desktop
    }
  }

  awk /FRX0
  {
%// M018 Don't make this look special
%// picture=awk.px;

    trigger_action: s*
    {
      fyi -t 'Awk' 'You must drop an awk language file on to this icon.'
    }

    trigger_action: d*
    {
      if [ -ne $#dynamic_args 1 ]
	then
          fyi -t 'Awk' 'You may only drop one awk language file on to this icon.'
	  exit
      fi

      filetype $dynamic_args

      if [ != $_type(1) F ]
	then
          fyi -t 'Awk' 'You only drop an awk language file on to this icon.'
      fi

      env AWKFILE $dynamic_args
      variation_class 1 $static_arg
      check $static_arg
    }
  }

  awk /FRX1
  {
%// M018 Don't make this look special
%// picture=awk1.px;

    trigger_action: s*
    {
      variation_class 0 $static_arg
      check $static_arg
    }

    trigger_action: d*
    {
      variation_class 0 $static_arg
      check $static_arg
      shell -n 'Awk' $static_arg' -f '$AWKFILE' '$dynamic_args' ; xdtwait'
      env AWKFILE ''
    }
  }

  *.Z /FW
  {
%// M018 Don't make this look special
%// picture=compressed.px;

    trigger_action: s1
    {
      uncompress $static_arg
      check -R $static_arg `( unextended $static_arg )
    }
  }

  *.ag /F
  {
    title=Asterix Graphic
%B0;
  }

  *.am /F
  {
    title=Asterix Macro
%B0;
  }

  *.as /F
  {
    title=Asterix Spreadsheet
%B0;
  }

  *.aw /F
  {
    title=Asterix Word
%B0;
  }

  *.dt /FR0
  {
    trigger_action: s1
    {
      open_desktop $static_arg
      variation_class 1 $static_arg
    }

    trigger_action: s2
    {
      if [ != `{extension $s_desktop} '.dt' ]
      then  # Not replacing a desktop so forget it
        exit
      fi
      variation_class 0 $s_desktop
      check $s_desktop
      if [ == $main_desktop $s_desktop ]
      then
          open_desktop $s_desktop $static_arg -m -N
          remove_dynamic_rule ""
          dynamic_rule "" -f $static_arg
      else
          open_desktop $s_desktop $static_arg
      fi
      variation_class 1 $static_arg
      check $static_arg
    }

    trigger_action: d1
    {
      icons=`( merge d_obj_types dynamic_args )

      open_desktop -h $static_arg

# Watch out for duplicate name NFO's/FSO's
      get_out -a F -l $icons -d $static_arg

      close_desktop $static_arg
    }

    trigger_action: d2
    {
      open_desktop -h $static_arg

# Watch out for duplicate name NFO's/FSO's
      icons=`( merge d_obj_types dynamic_args )

      what_window $d_desktop

      if [ == $_window_type 'Desktop' ]
	then
          get_out -a F -l $icons -d $static_arg -f $d_desktop
	else
          get_out -a F -l $icons -d $static_arg
      fi

      close_desktop $static_arg
    }
  }

  *.dt /FR1
  {
    trigger_action: s*
    {
      open_desktop $static_arg
    }

    trigger_action: d1
    {
# Watch out for duplicate name NFO's/FSO's
      icons=`( merge d_obj_types dynamic_args )
      get_out -l $icons -d $static_arg
    }

    trigger_action: d2
    {
# Watch out for duplicate name NFO's/FSO's
      icons=`( merge d_obj_types dynamic_args )

      what_window $d_desktop

      if [ == $_window_type 'Desktop' ]
	then
          get_out -l $icons -d $static_arg -f $d_desktop
	else
	  get_out -l $icons -d $static_arg
      fi
    }

%// M016 Apply xdtsysinfo.dropin patch
    drop_in_action: dropin1
    {
      actions_of d1 $s_obj_type $static_arg `( merge d_obj_types dynamic_args )
    }

    drop_in_action: dropin2
    {
      actions_of d2 $s_obj_type $static_arg `( merge d_obj_types dynamic_args )
    }

    drop_in_action: d1
    {
# Watch out for duplicate name NFO's/FSO's
      icons=`( merge d_obj_types dynamic_args )
      get_out -a $s_position -l $icons -d $static_arg
    }
    
    drop_in_action: d2
    {
# Watch out for duplicate name NFO's/FSO's
      icons=`( merge d_obj_types dynamic_args )

      what_window $d_desktop

      if [ == $_window_type 'Desktop' ]
	then
          get_out -a $s_position -l $icons -d $static_arg -f $d_desktop
	else
	  get_out -a $s_position -l $icons -d $static_arg
      fi
    }
  }

  *.dt /FR
  {
    title=%E0 Desktop;
    picture=xdesktop.px;
  }

  %$HOME$/Initial.dt /FR
  {
    title=%$USER$'s%#10#Desktop;
  }

  *.ms /FWM
  {
    trigger_action: print
    {
      /bin/sh -c 'cat '$static_arg' | psroff'
    }
  }

  *.x[bp]m /FR
  {
    picture=%P0;

    trigger_action: s1
    {
      scopaint $static_arg
      # check all pixmaps since user may have used scopaint file menu
      # pixmap_check $static_arg
      pixmap_check
    }
  }

  *.px /FR
  {
    picture=%P0;

    trigger_action: s1
    {
      scopaint $static_arg
      # check all pixmaps since user may have used scopaint file menu
      # pixmap_check $static_arg
      pixmap_check
    }
  }

  *.c /FW
  {
%// M033 Use SCO icon names
%// picture=csrc.px;
    picture=cfile.px;

    trigger_action: s2
    {
      cd `( dirname $static_arg )
      shell -n 'C Compiler' cc -c $static_arg ';' xdtwait
    }

    trigger_action: s3
    {
      cd `( dirname $static_arg )
      
      args=`( gti -t 'C Compiler' 'Enter compiler options:' )

      if [ != $status $OK ]
	then
	  exit
      fi

      shell -n 'C Compiler' cc $args -c $static_arg ';' xdtwait
    }
  }

  *.c /FR
  {
%// M033 Use SCO icon names
%// picture=csrc_read.px;
    picture=cfirnw.px;
  }

  *.c /F
  {
%// M033 Use SCO icon names
%// picture=csrc_pdl.px;
    picture=cfinrnw.px;
  }

  *.h /FW
  {
%// M033 Use SCO icon names
%// picture=hsrc.px;
    picture=hfile.px;
  }

  *.h /FR
  {
%// M033 Use SCO icon names
%// picture=hsrc_r.px;
    picture=hfirnw.px;
  }

  *.h /F
  {
%// M033 Use SCO icon names
%// picture=hsrc_pdl.px;
    picture=hfinrnw.px;
  }

  *.a /FW
  {
    trigger_action: d1
    {
      shell -n Archiver ar rv $static_arg $dynamic_args ';' xdtwait
    }
  }

  *.a /FR
  {
%// M018 Don't make this look special
%// picture=arch.px;

    trigger_action: s1
    {
      if [ == $ViewNeedsXterm true ]
	then
	  shell -n ar tv $static_arg '|' $VIEWER ';' xdtwait
	else
	  ar tv $static_arg '|' $VIEWER
      fi
    }
  }

  *.xde /FW
  {
%// M018 Don't make this look special
%// picture=rule_file.px;

    trigger_action: s1
    {
      change_environment $static_arg
    }

    trigger_action: s2
    {
      save_environment $static_arg
    }

    trigger_action: s3
    {
      replace_environment $static_arg
    }
  }

  *.ace /F
  {
%// M018 Don't make this look special
%// picture=ace.px;
  }

  *.arc /F
  {
%// M018 Don't make this look special
%// picture=arc.px;

    trigger_action: s1
    {
      actions_of d1 -! $XDESKTOP/applications/aisql.obj $static_arg
    }
  }

  *.frm /F
  {
%// M018 Don't make this look special
%// picture=frm.px;

    trigger_action: s1
    {
      actions_of d1 -! $XDESKTOP/applications/aisql.obj $static_arg
    }
  }

  *.sql /F
  {
    trigger_action: s1
    {
      aisql -q $static_arg ||
      actions_of s1 -! $XDESKTOP/applications/aisql.obj
    }
  }

  *.per /F
  {
%// M018 Don't make this look special
%// picture=per.px;
  }

  *.w20 /F
  {
%// M018 Don't make this look special
%// picture=2020_wksht.px;

    trigger_action: s1
    {
      actions_of d1 -! $XDESKTOP/applications/access.obj $static_arg
    }
  }

  *.dcx /F
  {
%// Add rules for Word files
    picture=Wordfile.px;

    trigger_action: s1
    {
      actions_of d1 -! $XDESKTOP/applications/Word.obj $static_arg
    }
  }

  *.wk? /F
  {
%// Add rules for Pro/123 files
    picture=Profile.px;

    trigger_action: s1
    {
      # Run Pro if it is installed
      filetype /usr/bin/procalc
      if [ == $_type(1) F ] && [ == $_type(2) X ]
      then
        actions_of d1 -! $XDESKTOP/applications/Pro.obj $static_arg
      else

        # if Pro is not installed, try Lotus; if not, default to Pro empty *.obj
        filetype $XDESKTOP/applications/123.obj 
        if [ == $_type(1) D ] && [ == $_type(2) X ]
        then
          actions_of d1 -! $XDESKTOP/applications/123.obj $static_arg
        else
          actions_of d1 -! $XDESKTOP/applications/Pro.obj $static_arg
        fi
      fi
    }
  }

  /usr/bin/X11/* /FX
  {
%// M018 Use SCO icon names
    picture=fiXexec.px;

    trigger_action: s1
    {
      $static_arg
    }

    trigger_action: s2
    {
      shell -n `( basename $static_arg ) $static_arg ';' xdtwait
    }

    trigger_action: d1
    {
      $static_arg $dynamic_args
    }

    trigger_action: d2
    {
      shell -n `( basename $static_arg ) $static_arg $dynamic_args ';' xdtwait
    }
  }

  * /FWXM
  {
    trigger_action: discard
    {
      do_trash
    }
  }

  * /FX
  {
%// M018 use SCO icon 
%// picture=prog.px;
    picture=filexec.px;

    trigger_action: s1
    {
      shell -n `( basename $static_arg ) $static_arg ';' xdtwait
    }

    trigger_action: s2
    {
      $static_arg
    }

    trigger_action: s3
    {
      options=`( gti -t `( basename $static_arg ) 'Enter any options you require:' )

      if [ -ne $status 0 ]
	then
	  exit
      fi

      shell -n `( basename $static_arg ) $static_arg $options ';' xdtwait
    }

    trigger_action: d1
    {
      shell -n `( basename $static_arg ) $static_arg $dynamic_args ';' xdtwait
    }

    trigger_action: d2
    {
      $static_arg $dynamic_args
    }

    trigger_action: d3
    {
      options=`( gti -t `( basename $static_arg ) 'Enter any options you require:' )

      if [ -ne $status 0 ]
	then
	  exit
      fi

      shell -n `( basename $static_arg ) $static_arg $options $dynamic_args ';' xdtwait
    }

    trigger_action: copy
    {
      if [ == $dynamic_args $static_arg ]
	then
	  put_back $dynamic_args -d $d_desktop
	  exit
      fi

      filetype $dynamic_args

      if [ != $_type(1) D ]
	then
	  fyi -h copying -t 'Icon: '^`( basename $dynamic_args ) 'You must specify a directory to copy into.'
	  exit
      fi

      if [ != $_type(3) W ]
	then
	  fyi -h copying -t 'Icon: '^`( basename $dynamic_args ) 'You do not have permission to copy into this directory.'
	  exit
      fi

      filetype $dynamic_args/^`( basename $static_arg )

      if [ != $_type(1) G ] && [ != $_type(1) @ ]
	then
# Can change here to actually do an overwrite if requested
	  fyi -h copying -t 'Icon: '^`( basename $static_arg ) 'This file already exists in the destination directory.
Not copying...'

	  exit
      fi

      if [ -gt `( sizeof $static_arg ) $CopyMoveSize ]
        then
          report -a -t `( basename $static_arg ) -c Cancel 'Copying this file may take some time.'
        else
          report -a -t Copy -c Cancel 'Copying: '^`( basename $static_arg )
      fi

      if [ == $status $CANCELLED ]
        then
          report -t Copy -c OK 'Copy operation cancelled...'
          exit
      fi

      copy_into $dynamic_args $static_arg
    }

    trigger_action: move
    {
      if [ == $dynamic_args $static_arg ]
        then
          put_back $dynamic_args -d $d_desktop
          exit
      fi

      filetype $dynamic_args

      if [ != $_type(1) D ]
        then
	  fyi -h moving -t 'Icon: '^`( basename $static_arg ) 'You must specify a directory to move to.'
	  exit
      fi

      if [ != $_type(3) W ]
	then
	  fyi -h moving -t 'Icon: '^`( basename $dynamic_args ) 'You do not have permission to move into this directory.'
	  exit
      fi

      filetype $dynamic_args/^`( basename $static_arg )

      if [ != $_type(1) G ]
	then
# CHANGE REQUEST: Change to actually do an overwrite if requested
	  fyi -h moving -t 'Icon: '^`( basename $static_arg ) 'This file already exists in the destination directory.
Not moving...'
	  exit
      fi

      if [ -gt `( sizeof $static_arg ) $CopyMoveSize ]
        then
          report -a -t `( basename $static_arg ) -c Cancel 'Moving this file may take some time.'
        else
          report -a -t Move -c Cancel 'Moving: '^`( basename $static_arg )
      fi

      if [ == $status $CANCELLED ]
        then
          report -t Move -c OK 'Move operation cancelled...'
          exit
      fi

      move_into $dynamic_args $static_arg -e

# M077 Move across filesystems failed, try a copy and remove as workaround
      if [ != $status $OK ]
      then
	  copy_into $dynamic_args $static_arg
	  if [ == $status $OK ]
	  then
	      remove $static_arg
	  fi
      fi
    }
  }

  * /FWN
  {
    picture=file.px;

    trigger_action: discard
    {
      do_trash
    }

    trigger_action: move
    {
      if [ == $dynamic_args $static_arg ]
	then
	  put_back $dynamic_args -d $d_desktop
	  exit
      fi

      filetype $dynamic_args

      if [ != $_type(1) D ]
	then
	  fyi -h moving -t 'Icon: '^`( basename $static_arg ) 'You must specify a directory to move to.'
	  exit
      fi

      if [ != $_type(3) W ]
	then
	  fyi -h moving -t 'Icon: '^`( basename $dynamic_args ) 'You do not have permission to move into this directory.'
	  exit
      fi

      filetype $dynamic_args/^`( basename $static_arg )

      if [ != $_type(1) G ]
	then
# CHANGE REQUEST: Change to actually do an overwrite if requested
	  fyi -h moving -t 'Icon: '^`( basename $static_arg ) 'This file already exists in the destination directory.
Not moving...'
	  exit
      fi

      if [ -gt `( sizeof $static_arg ) $CopyMoveSize ]
        then
          report -a -t `( basename $static_arg ) -c Cancel 'Moving this file may take some time.'
        else
          report -a -t Move -c Cancel 'Moving: '^`( basename $static_arg )
      fi

      if [ == $status $CANCELLED ]
        then
          report -t Move -c OK 'Move operation cancelled...'
          exit
      fi

      move_into $dynamic_args $static_arg -e

# M077 Move across filesystems failed, try a copy and remove as workaround
      if [ != $status $OK ]
      then
	  copy_into $dynamic_args $static_arg
	  if [ == $status $OK ]
	  then
	      remove $static_arg
	  fi
      fi
    }
  }

  * /FRN
  {
%// M018 use SCO file icon 
%// picture=file_read.px;
    picture=filernw.px;

    trigger_action: s*
    {
      if [ == $EditNeedsXterm true ]
	then
          shell -n 'Edit: '^`( basename $static_arg ) $EDITOR $static_arg ';' xdtwait
	else
          $EDITOR $static_arg
      fi
    }

    trigger_action: copy
    {
      if [ == $dynamic_args $static_arg ]
	then
	  put_back $dynamic_args -d $d_desktop
	  exit
      fi

      filetype $dynamic_args

      if [ != $_type(1) D ]
	then
	  fyi -h copying -t 'Icon: '^`( basename $dynamic_args ) 'You must specify a directory to copy into.'
	  exit
      fi

      if [ != $_type(3) W ]
	then
	  fyi -h copying -t 'Icon: '^`( basename $dynamic_args ) 'You do not have permission to copy into this directory.'
	  exit
      fi

      filetype $dynamic_args/^`( basename $static_arg )

      if [ != $_type(1) G ] && [ != $_type(1) @ ]
	then
# Can change here to actually do an overwrite if requested
	  fyi -h copying -t 'Icon: '^`( basename $static_arg ) 'This file already exists in the destination directory.
Not copying...'

	  exit
      fi

      if [ -gt `( sizeof $static_arg ) $CopyMoveSize ]
        then
          report -a -t `( basename $static_arg ) -c Cancel 'Copying this file may take some time.'
        else
          report -a -t Copy -c Cancel 'Copying: '^`( basename $static_arg )
      fi

      if [ == $status $CANCELLED ]
        then
          report -t Copy -c OK 'Copy operation cancelled...'
          exit
      fi

      copy_into $dynamic_args $static_arg
    }

    trigger_action: print
    {
      /bin/sh -c 'cat '$static_arg' | '`{basename $dynamic_args}
    }
  }

%// The default rules!!

  * /F
  {
    picture=filenrnw.px;
  }

  * /BCP
  {
    picture=file.px;
  }

  * /GI
  {
    picture=ghost.px;
  }

  *
  {
    title=%R0;
    picture=noicon.px;

    trigger_action: s*
    {
      filetype $static_arg
      if [ == $_type(1) 'G' ]     # NFO
      then
         fyi -h ghost -t Ghost $static_arg ' does not exist'
      else
         button $trigger
         fyi -h icons -t 'Icon: '^`( basename $static_arg ) 'The '$_button' mouse button has no effect on this icon.'
      fi
    }

    trigger_action: d*
    {
      button $trigger
      fyi -h icons -t 'Icon: '^`( basename $static_arg ) 'The '$_button' mouse button has no effect on this icon.'
    }

    trigger_action: h*
    {
      button $trigger

      if [ == $_button third ]
	then
          fyi -h icons -t 'Icon: '^`( basename $static_arg ) 'No menu has been defined for this icon.'
	else
	  fyi -h icons -t 'Icon Menus' 'Use button #3 for popup menus.'
      fi
    }

    trigger_action: copy
    {
      fyi -h copying -t 'Icon: '^`( basename $static_arg ) 'You may not copy this icon.'
    }

    trigger_action: discard
    {
      fyi -h trash0 -t 'Icon: '^`( basename $static_arg ) 'You may not discard this icon.'
    }

    trigger_action: move
    {
      fyi -t 'Icon: '^`( basename $static_arg ) 'You may not move this icon.'
    }

    trigger_action: print
    {
      fyi -h print -t 'Icon: '^`( basename $static_arg ) 'You may not print this icon.'
    }

    trigger_action: duplicate
    {
      if [ == $#dynamic_args 0 ]
      then
        fyi -h dupicon -t Duplicate 'You must first select an icon.'
        exit
      fi

      if [ -gt $#dynamic_args 1 ]
      then
        fyi -h dupicon -t Duplicate 'You may only duplicate one item at a time.'
        exit
      fi

      if [ != `(  dirname $dynamic_args ) $static_arg ]
      then
        fyi -h select -t Duplicate 'You may only duplicate items selected in this window.'
        exit
      fi

      filetype $dynamic_args

      if [ != $_type(1) F ] && [ != $_type(1) D ]
      then
        fyi -h copyicon -t Duplicate 'You may only duplicate files and directories.'
        exit
      fi

      if [ == $_type(1) F ]
      then
        duplicate_file $dynamic_args
      else

        newdir=`( gti -h GtiUserHelp -t Duplicate 'Enter name of new directory:')

        if [ != $status $OK ] || [ == $#newdir 0 ]
        then
          exit
        fi

        if [ -gt $#newdir 1 ]
        then
          fyi -t Duplicate 'You may not use spaces in directory names.'
          exit
        fi

        if [ != `( basename $newdir ) $newdir ]
        then
          fyi -t Duplicate 'This option may only be used to duplicate an icon within the same directory.'
          exit
        fi

        make_new_file -d $static_arg -b $newdir -e

        if [ != $status $OK ]
        then
          fyi -t Duplicate 'Unable to create new directory.'
          exit
        fi

        for icon in `( contents_of $dynamic_args )
        do
          do_actions_of copy $dynamic_args/$icon $static_arg/$newdir
        done
      fi
    }

    drop_in_action: deselect
    {
      select -U
    }

%// M016 Apply xdtsysinfo.dropin patch
    drop_in_action: dropin1
    {
      actions_of d1 $s_obj_type $static_arg `( merge d_obj_types dynamic_args )
    }

    drop_in_action: dropin2
    {
      actions_of d2 $s_obj_type $static_arg `( merge d_obj_types dynamic_args )
    }

%// M044
    drop_in_action: d2
    {
      for idx in `( sequence 1 1 $#dynamic_args )
        do
          get_type $idx

          if [ == `( dirname `( canonical $icon^/ )) `( canonical $static_arg^/ ) ]
	    then
	      put_back $type $icon -d $d_desktop
	    else
	      do_actions_of copy $type $icon $static_arg
          fi
	done
    }

%// M044
    drop_in_action: d1
    {
      for idx in `( sequence 1 1 $#dynamic_args )
        do
	  get_type $idx

          if [ == `( dirname `( canonical $icon^/ )) `( canonical $static_arg^/ ) ]
	    then
	      put_back $type $icon -d $d_desktop
	    else
	      do_actions_of move $type $icon $static_arg
          fi
	done
    }

    drop_in_action: d*
    {
      for icon in $dynamic_args
	do
          do_actions_of $trigger $s_obj_type $icon $static_arg
	done
    }
  }
}

menu: tar3_5_menu
{
  menu_item: List Contents
  {
    do_actions_of s1 $static_arg $dynamic_arg
  }
  menu_item: Copy to
  {
    do_actions_of d1 $static_arg $dynamic_arg
  }
  menu_item: Extract All from
  {
    do_actions_of s2 $static_arg $dynamic_arg
  }
  menu_item: Extract Some from
  {
    do_actions_of s3 $static_arg $dynamic_arg
  }
  menu_item: Format
  {
    if [ != $#DISK_DRIVE 0 ]
    then
      if `{yni -t 'Format Disk' -h disk 'Format: 3.5 inch disk ('$DISK_DRIVE')
  WARNING: This action is non reversable!
  The contents of the floppy disk currently
  in the drive will be erased.

  Do you wish to continue?'}
      then
        shell -n 'Format Disk' $THREE_DISK_FORMAT ';' xdtwait
      fi
    else
      fyi -t 'Format Disk' 'The device for the 3.5 inch disk is unknown.
Cannot format.'
    fi
  }
  menu_item: Eject
  {
    eject
  }
}

menu: tar5_25_menu
{
  menu_item: List Contents
  {
    do_actions_of s1 $static_arg $dynamic_arg
  }
  menu_item: Copy to
  {
    do_actions_of d1 $static_arg $dynamic_arg
  }
  menu_item: Extract All from
  {
    do_actions_of s2 $static_arg $dynamic_arg
  }
  menu_item: Extract Some from
  {
    do_actions_of s3 $static_arg $dynamic_arg
  }
  menu_item: Format
  {
    if [ != $#FIVE_DISK 0 ]
    then
      if `{yni -t 'Format Disk' -h disk 'Format: 5.25 inch disk ('$FIVE_DISK')
  WARNING: This action is non reversable!
  The contents of the floppy disk currently
  in the drive will be erased.

  Do you wish to continue?'}
      then
        shell -n 'Format Disk' $FIVE_DISK_FORMAT ';' xdtwait
      fi
    else
      fyi -t 'Format Disk' 'The device for the 5.25 inch disk is unknown.
Cannot format.'
    fi
  }
}

menu: trash_menu
{
  menu_item
  {
    ti=Open;
    enable_if
    {
      items=%$HOME$/trash/[!.]*
      opendirs=(KEEP_LIST_FROM_BEING_EMPTY `(query open_directories))
      opentrash=`(list intersect %$HOME$/trash :: $opendirs )
      if [ -eq $#opentrash 0 ]	# if trash is not open
      then
	 [ -ne $#items 0 ]	# check if trash not empty
      fi
    }
    select_action
    {
      hide_dot_files
      display_directory $static_arg 
    }
  }
  menu_item
  {
    ti=Close;
    enable_if
    {
      opendirs=`(query open_directories)
      if [ -ne $#opendirs 0 ]
      then
	# some dir is open, check if it is trash
        opentrash=`(list intersect %$HOME$/trash :: $opendirs )
        [ -eq $#opentrash 1 ]
      fi
    }
    select_action
    {
      # M013 just in case remove states from trash dir view
      remove_dir_view_states Names Details Time Size Show
      close_directory $static_arg
    }
  }
  menu_item
  {
    ti=Empty;
    enable_if { items=%$HOME$/trash/[!.]*; [ -ne $#items 0 ] }
    select_action { actions_of s3 $s_obj_type $static_arg }
  }
}

menu: at_menu
{
  menu_item: at menu
    {}
  dividing_line;
  menu_item: Add to Queue
    { file=`( gti -t 'at' 'Enter the name of a script file:' )
      time=`( gti -t 'at' 'Enter time to run the job:' )
      shell -n at at $time $file ';' xdtwait
    }
  menu_item: View the Queue
    { shell -n at atq ';' xdtwait }
  menu_item: Remove from Queue
    { job=`( gti -t at 'Enter job numbers to remove:' )

      if [ -ne $status 0 ]
	then
	  exit
      fi

      shell -n at atrm -i $jobs' ; xdtwait'
    }
}

menu: DesktopMenuBar
{
  menu_item: File _F__
    { pull_off_menu=DesktopFileMenu }
  menu_item: Edit _E__
    { pull_off_menu=DesktopEditMenu }
  menu_item: View _V__
    { pull_off_menu=DesktopViewMenu }
  menu_item: Help _H__
    { pull_off_menu=DesktopHelpMenu }
}

menu: DesktopFileMenu
{
  menu_item: Open            _O_Ctrl<Key>O_Ctrl+O
    {
	open_cmd
    }

  dividing_line;

  menu_item: New Desktop...  _N_Ctrl<Key>N_Ctrl+N
    { desktop=`{ gti -h xdtfnewd -t 'New Desktop...' 'Enter name of desktop to create:' }

      if [ -ne $status 0 ] || [ == $#desktop 0 ]
        then
          exit
      fi

      if [ != $#desktop 1 ]
	then
	  fyi -t 'New Desktop...' 'You may not enter any spaces.'
	  exit
      fi

      if [ != `( unextended $desktop )^.dt `( canonical $desktop ) ]
        then
          desktop=$desktop.dt
      fi

      filetype $desktop

      if [ != $_type(1) G ]
	then
	  fyi -h xdtfnewd -t 'New Desktop...' 'This desktop already exists.'
	  exit
      else
        touch $desktop
      fi

      get_out -! $desktop -d $static_arg
      variation_class 1 $desktop
      open_desktop $desktop
    }

  menu_item: Save Desktop    _S_Ctrl<Key>S_Ctrl+S
    { filetype $static_arg

      if [ != $_type(1) F ] || [ != $_type(3) W ]
	then
	  fyi -h prop -t 'Save Desktop' 'You do not have permission to save to this desktop file.'
	  exit
      fi

      copy_desktop -d $static_arg
    }

  menu_item: Save Desktop As...      _A__
    {
%// M011 Set dynamic args to just the selections in this window
      dynamic_args=`(query selections $thread_name(2));
      if [ -eq $#dynamic_args 1 ]
	then
	  filetype $dynamic_args

	  if [ == $_type(1) F ] && [ == $_type(3) W ]
	    then
	      if yni -h xdtsavas -t 'Save Desktop As...' 'Confirm you wish to save to file:
  '$dynamic_args
	        then
	          copy_desktop $dynamic_args -d $static_arg
	          exit
	      fi
	  fi
      fi

      desktop=`{ gti -h xdtfsavas -t 'Save Desktop As...' 'Enter name of desktop to save to:' }

      if [ -ne $status 0 ] || [ == $#desktop 0 ]
        then
          exit
      fi

      if [ != $#desktop 1 ]
	then
	  fyi -t 'Save Desktop As...' 'You may not enter any spaces.'
	  exit
      fi

      if [ != `( unextended $desktop )^.dt `( canonical $desktop ) ]
        then
          desktop=$desktop.dt
      fi

      filetype $desktop

      if [ != $_type(1) G ] && [ != $_type(1) @ ]
	then
	  if [ != $_type(1) F ]
	    then
	      fyi -h xdtfsave -t 'Save Desktop As...' 'A file of this name which is not a
desktop file already exists.  Not saving...'
	      exit
	  fi

	  if [ != $_type(3) W ]
	    then
	      fyi -h prop -t 'Save Desktop As...' 'You do not have permission to save to this desktop file.'
	      exit
	  fi
      fi

      copy_desktop $desktop -d $static_arg
      check $desktop
      get_out -! $desktop -d $static_arg
    }

  dividing_line;

  menu_item: New Directory... _D_Ctrl<Key>D_Ctrl+D
    { newdir=`{ gti -t 'New Directory...' 'Enter new directory name:' }

      if [ != $status $OK ] || [ == $#newdir 0 ]
	then
	  exit
      fi

      if [ -gt $#newdir 1 ]
	then
	  fyi -t 'New Directory...' 'You may not enter any spaces.'
	  exit
      fi

      newdir=`( canonical $newdir )

      filetype $newdir

      if [ != $_type(1) G ]
	then
	  fyi -t 'New Directory...' 'This directory already exists.'
	  exit
      fi

      make_new_file -d `( dirname $newdir ) -b `( basename $newdir )
      get_out -! $newdir -d $static_arg
    }

  menu_item: New File... _F_Ctrl<Key>F_Ctrl+F
    { newfile=`{ gti -t 'New File...' 'Enter new file name:' }

      if [ != $status $OK ] || [ == $#newfile 0 ]
	then
	  exit
      fi

      if [ -gt $#newfile 1 ]
	then
	  fyi -t 'New File...' 'You may not enter any spaces.'
	  exit
      fi

      newfile=`( canonical $newfile )

      filetype $newfile

      if [ != $_type(1) G ]
	then
	  fyi -t 'New File...' 'This file already exists.'
	  exit
      fi

      make_new_file `( dirname $newfile ) -b `( basename $newfile )
      get_out -! $newfile -d $static_arg
    }

  menu_item
  {
    ti=Copy to...    _C__;
    enable_if { sels=`(query selections $thread_name(2)); [ -ne $#sels 0 ] }
    select_action
    {
      copy_cmd
    }
  }

  menu_item
  {
    ti=Move to...    _M__;
    enable_if { sels=`(query selections $thread_name(2)); [ -ne $#sels 0 ] }
    select_action
    {
      move_cmd
    }
  }

  menu_item
  {
    ti=Rename...     _R__;
    enable_if { sels=`(query selections $thread_name(2)); [ -ne $#sels 0 ] }
    select_action
    {
%// M011 Set dynamic args to just the selections in this window
      dynamic_args=`(query selections $thread_name(2));
      for icon in $dynamic_args
	do
	  filetype $icon

	  if [ == $_type(1) @ ] || [ == $_type(1) G ] ||
	     [ != $_type(3) W ]
	    then
	      fyi -h dirfren -t 'Icon: '^`( basename $icon ) 'You may not rename this icon '
	    else
              if [ == $HOME $icon ]
                then
                  fyi -t Rename 'You may not rename your home directory.'
                else
%// M009 Can't use rename on desktop as root; maybe someday
%//	          rename $icon -d $static_arg

      		  newname=`{ gti -t Rename... -d `(basename $icon) 'Enter new file name:' }

	          if [ != $status $OK ] || [ == $#newname 0 ]
	            then
	    	      exit
	          fi

	          if [ -gt $#newname 1 ]
	            then
		      fyi -t Rename... 'You may not enter any spaces.'
		      exit
	          fi

	          if [ != `( basename $newname ) $newname ]
	            then
		      fyi -t Rename... 'You may not rename to a different directory.'
		      exit
	          fi

	          filetype `( dirname $dynamic_args )^/^$newname

	          if [ != $_type(1) G ]
	            then
		      fyi -t Rename... 'A file with this name already exists.'
		      exit
	          fi

	          rename $icon -b $newname
                  chk
              fi
	  fi
	done
    }
  }

  menu_item
  {
    ti=Duplicate... _u__;
    enable_if { sels=`(query selections $thread_name(2)); [ -ne $#sels 0 ] }
    select_action
%//
%// M000, Can't do this for desktop menus
%// {
%//   do_actions_of duplicate $static_arg $dynamic_args
%// }
%//
%// So do the following:
    {
%// M011 Set dynamic args to just the selections in this window
      dynamic_args=`(query selections $thread_name(2));
      if [ == $#dynamic_args 0 ]
      then
        fyi -h select -t Duplicate... 'You must first select an icon.'
        exit
      fi

      if [ -gt $#dynamic_args 1 ]
      then
        fyi -h dupicon -t Duplicate... 'You may only duplicate one item at a time.'
        exit
      fi

      filetype $dynamic_args

      if [ != $_type(1) F ] && [ != $_type(1) D ]
      then
        fyi -h copyicon -t Duplicate... 'You may only duplicate files and directories.'
        exit
      fi

      if [ == $_type(1) F ]
      then
%//
%// M000, must prompt for 'duplicate' name since dir is not open when done
%// from a desktop menu (dir open required for 'duplicate_file' to work)
%//
%//     duplicate_file $dynamic_args
%//
%// So do the following instead:
        new=`( gti -h GtiUserHelp -t Duplicate... 'Enter name of new file:')

        if [ != $status $OK ] || [ == $#new 0 ]
        then
          exit
        fi

        if [ -gt $#new 1 ]
        then
          fyi -t Duplicate... 'You may not use spaces in file names.'
          exit
        fi

        if [ != `( basename $new ) $new ]
        then
          fyi -t Duplicate... 'This option may only be used to duplicate an icon within the same directory.'
          exit
        fi

	dir=`( dirname $dynamic_args )
        duplicate_file $dynamic_args -b $dir/$new

      else

        new=`( gti -h GtiUserHelp -t Duplicate... 'Enter name of new directory:')

        if [ != $status $OK ] || [ == $#new 0 ]
        then
          exit
        fi

        if [ -gt $#new 1 ]
        then
          fyi -t Duplicate... 'You may not use spaces in directory names.'
          exit
        fi

        if [ != `( basename $new ) $new ]
        then
          fyi -t Duplicate... 'This option may only be used to duplicate an icon within the same directory.'
          exit
        fi

	dir=`( dirname $dynamic_args )
        make_new_file -d $dir -b $new -e

        if [ != $status $OK ]
        then
          fyi -t Duplicate... 'Unable to create new directory.'
          exit
        fi

        for icon in `( contents_of $dynamic_args )
        do
          do_actions_of copy $dynamic_args/$icon $dir/$new
        done
      fi
      get_out -! $dir/$new -d $static_arg
    }
  }

  menu_item
  {
    ti=Discard ___;
    enable_if { sels=`(query selections $thread_name(2)); [ -ne $#sels 0 ] }
    select_action
    {
      discard_cmd
    }
  }

  menu_item
  {
    ti=Properties...   _P_Ctrl<Key>P_Ctrl+P;
    enable_if { sels=`(query selections $thread_name(2)); [ -ne $#sels 0 ] }
    select_action
    {
%// M011 Set dynamic args to just the selections in this window
      dynamic_args=`(query selections $thread_name(2));
      handle_xdt3info $dynamic_args
      check $dynamic_args 
    }
  }

  menu_item find: Find... _i__
  {
    find_cmd
  }

  thick_dividing_line;

  menu_item: Close           _C__
    {
       xxx=`(get_resource xdt3.isRoot XDesktop3.IsRoot)

       if [ == $xxx true ] || [ == $xxx True ] || [ == $xxx TRUE ]
       then
		xxx=TRUE
       else
		xxx=FALSE
       fi


       if [ == $main_desktop $static_arg ] && [ == $xxx TRUE ]
       then
	      $XDESKTOP/sessionstop
       else
	      filetype $static_arg
	      if [ == $_type(1) F ] && [ != $_type(3) W ] # file is not writable
	      then
		  if yni -h closewind -t Close 'You do not have permission to save to this desktop file,
do you still want to close?'
		  then
		      variation_class 0 $static_arg
		      close_desktop -N $static_arg
		  # else do nothing
		  fi
	      else
		  variation_class 0 $static_arg
		  close_desktop $static_arg
	      fi
       fi
    }
}

menu: DesktopEditMenu
{
  menu_item
    {
      ti=Put Away     _P__;
      enable_if { sels=`(query selections $thread_name(2)); [ -ne $#sels 0 ] }
      select_action
      { 
%// M011 Set dynamic args to just the selections in this window
        dynamic_args=`(query selections $thread_name(2));
	put_back $dynamic_args -d $static_arg
      }
    }

  dividing_line;

  menu_item
    {
      ti=Select All          _A__;
      enable_if
      {
	sels=`(query selections $thread_name(2))
	conts=`(query contents $thread_name(2))
	[ -ne $#sels $#conts ]
      }
      select_action { select -D $static_arg }
    }

  menu_item
    {
      ti=Deselect All _D__;
      enable_if { sels=`(query selections $thread_name(2)); [ -ne $#sels 0 ] }
      select_action { select -U }
    }
}

menu: DesktopViewMenu
{
  menu_item
    {
      ti=Clean up   _C_Ctrl<Key>C_Ctrl+C;
      enable_if { conts=`(query contents $thread_name(2)); [ -ne $#conts 0 ] }
      select_action { tidy_desktop $static_arg }
    }

  menu_item
    {
      ti=Reorganize... _R_Ctrl<Key>R_Ctrl+R;
      enable_if { conts=`(query contents $thread_name(2)); [ -ne $#conts 0 ] }
      select_action
      {
	if yni -t Reorganize 'This will reposition all icons in rows starting at the upper left corner%#10#Do you still wish to reorganize?'
	then
	  reorganize_desktop $static_arg
	fi
      }
    }
}

menu: DesktopHelpMenu
{
  menu_item
  {
    ti=On Object    _O__;
    enable_if { sels=`(query selections $thread_name(2)); [ -ne $#sels 0 ] }
    select_action
      {
%// M011 Set dynamic args to just the selections in this window
          dynamic_args=`(query selections $thread_name(2));
          help `(basename $dynamic_args(1))
       }
  }

  menu_item: On Window   _W__
    { help xdthelp }

  menu_item: On Keys     _K__
    { help XDesktop3_on_keys }

  menu_item: Index       _I__
    { help index }

  menu_item: On Help     _H__
    { help help_on_help }

  menu_item: On Version   _V__
    { show_greeting }
}

menu: DirMenuBar
{
  menu_item: File _F__
    { pull_off_menu=DirFileMenu }
  menu_item: Edit _E__
    { pull_off_menu=DirEditMenu }
  menu_item: View _V__
    { pull_off_menu=DirViewMenu }
  menu_item: Help _H__
    { pull_off_menu=DirHelpMenu }
}

menu: DirFileMenu
{
  menu_item: Open          _O_Ctrl<Key>O_Ctrl+O
    {
	open_cmd
    }

  dividing_line;

  menu_item: New Directory...     _D_Ctrl<Key>D_Ctrl+D
    { make_new_file -d $static_arg }

  menu_item: New File...          _F_Ctrl<Key>F_Ctrl+F
    { make_new_file $static_arg }

  menu_item
  {
    ti=Copy to...    _C__;
    enable_if { sels=`(query selections $thread_name(2)); [ -ne $#sels 0 ] }
    select_action
    {
      copy_cmd
    }
  }

  menu_item
  {
    ti=Move to...    _M__;
    enable_if { sels=`(query selections $thread_name(2)); [ -ne $#sels 0 ] }
    select_action
    {
      move_cmd
    }
  }

  menu_item
  {
    ti=Rename...     _R__;
    enable_if { sels=`(query selections $thread_name(2)); [ -ne $#sels 0 ] }
    select_action
    {
%// M011 Set dynamic args to just the selections in this window
      dynamic_args=`(query selections $thread_name(2));
      for icon in $dynamic_args
	do
	  filetype $icon

	  if [ == $_type(1) @ ] || [ == $_type(1) G ] ||
	     [ != $_type(3) W ]
	    then
	      fyi -h dirfren -t 'Icon: '^`( basename $icon ) 'You may not rename this icon '
	    else
              if [ == $HOME $icon ]
                then
                  fyi -t Rename 'You may not rename your home directory.'
                else
	          rename $icon
                  chk
              fi
	  fi
	done
    }
  }

  menu_item
  {
    ti=Duplicate... _u__;
    enable_if { sels=`(query selections $thread_name(2)); [ -ne $#sels 0 ] }
    select_action
    {
%// M011 Set dynamic args to just the selections in this window
      dynamic_args=`(query selections $thread_name(2));
      do_actions_of duplicate $static_arg $dynamic_args
    }
  }

  menu_item
  {
    ti=Discard ___;
    enable_if { sels=`(query selections $thread_name(2)); [ -ne $#sels 0 ] }
    select_action
    {
      discard_cmd
    }
  }

  menu_item
  {
    ti=Properties... _P_Ctrl<Key>P_Ctrl+P;
    enable_if { sels=`(query selections $thread_name(2)); [ -ne $#sels 0 ] }
    select_action
    {
%// M011 Set dynamic args to just the selections in this window
      dynamic_args=`(query selections $thread_name(2));
      handle_xdt3info $dynamic_args
      check $dynamic_args 
    }
  }

  menu_item find: Find... _i__
  {
    find_cmd
  }

  thick_dividing_line;

  menu_item: Close         _l_Ctrl<Key>C_Ctrl+C
    {
      # M013 remove state info so next time dir is opened it is clean
      remove_dir_view_states Names Details Time Size Show
      close_directory $static_arg
    }
}

menu: DirEditMenu
{
  menu_item
    {
      ti=Select All          _A__;
      enable_if
      {
   	sels=`(query selections $thread_name(2))
   	conts=`(query contents $thread_name(2))
   	[ -ne $#sels $#conts ]
      }
      select_action { select -D $static_arg }
    }

  menu_item
    {
      ti=Deselect All _D__;
      enable_if { sels=`(query selections $thread_name(2)); [ -ne $#sels 0 ] }
      select_action { select -U }
    }
}

menu: DirViewMenu
{
  menu_item
  {
    ti=Icons   _I_Ctrl<Key>I_Ctrl+I;
    enable_if
    {
      # M013 see if dir is viewed as names or details, if not, stipple
      vstate=`(list intersect $thread_name(2)^Names :: $:_dirview)
      vstate=($vstate `(list intersect $thread_name(2)^Details :: $:_dirview))
      [ -ne $#vstate 0 ]
    }
    select_action
    {
      # M013 don't need to add to state, no entry means icons
      # just remove other states
      remove_dir_view_states Names Details
      display_directory -i $static_arg
    }
  }
  menu_item
  {
    ti=Names   _N_Ctrl<Key>N_Ctrl+N;
    enable_if
    {
      # M013 see if dir is viewed as names already, if so stipple
      vstate=`(list intersect $thread_name(2)^Names :: $:_dirview)
      [ -ne $#vstate 1 ]
    }
    select_action
    {
      # M013 if we got in here then we were either in icon or details state
      remove_dir_view_states Details
      :_dirview=( $static_arg^Names $:_dirview )
      display_directory -nf %I $static_arg
    }
  }
  menu_item
  {
    ti=Details _D__;
    enable_if
    {
      # M013 see if dir is viewed as details already, if so stipple
      vstate=`(list intersect $thread_name(2)^Details :: $:_dirview )
      [ -ne $#vstate 1 ]
    }
    select_action
    {
      # M013 if we got in here then we were either in icon or names state
      remove_dir_view_states Names
      :_dirview=( $static_arg^Details $:_dirview )
      display_directory -nf '%T %S %I' $static_arg
    }
  }

  dividing_line;

  menu_item: Sort    _S__
    { pull_off_menu=DirSortMenu }

  menu_item: Display dot files_f__
    { pull_off_menu=DirDotMenu }

  dividing_line;

  menu_item
    {
      ti=Reorganize _R_Ctrl<Key>R_Ctrl+R;
      enable_if { conts=`(query contents $thread_name(2)); [ -ne $#conts 0 ] }
      select_action { display_directory $static_arg }
    }
}

menu: DirHelpMenu
{
  menu_item
  {
    ti=On Object    _O__;
    enable_if { sels=`(query selections $thread_name(2)); [ -ne $#sels 0 ] }
    select_action
    {
%// M011 Set dynamic args to just the selections in this window
      dynamic_args=`(query selections $thread_name(2));
      help `(basename $dynamic_args(1))
    }
  }

  menu_item: On Window _W__
    { help directories }

  menu_item: On Keys     _K__
    { help XDesktop3_on_keys }

  menu_item: Index       _I__
    { help index }

  menu_item: On Help     _H__
    { help help_on_help  }

  menu_item: On Version   _V__
    { show_greeting }
}

menu: DirSortMenu
{
  menu_item
  {
    ti=by Name _N__;
    enable_if
    {
      # M013 see if dir is sorted by time or size, if not, stipple
      vstate=`(list intersect $thread_name(2)^Time :: $:_dirview)
      vstate=($vstate `(list intersect $thread_name(2)^Size :: $:_dirview))
      [ -ne $#vstate 0 ]
    }
    select_action
    {
      # M013 don't need to add to state, no entry means sort by name
      # just remove other states
      remove_dir_view_states Time Size
      display_directory -D $static_arg
    }
  }

  menu_item
  {
    ti=by Time _T__;
    enable_if
    {
      # M013 see if dir is sorted by time already, if so stipple
      vstate=`(list intersect $thread_name(2)^Time :: $:_dirview)
      [ -ne $#vstate 1 ]
    }
    select_action
    {
      # M013 if we got in here then we were either sorted by name or size
      remove_dir_view_states Size
      :_dirview=( $static_arg^Time $:_dirview )
      display_directory -t $static_arg
    }
  }

  menu_item
  {
    ti=by Size _S__;
    enable_if
    {
      # M013 see if dir is sorted by size already, if so stipple
      vstate=`(list intersect $thread_name(2)^Size :: $:_dirview )
      [ -ne $#vstate 1 ]
    }
    select_action
    {
      # M013 if we got in here then we were either sorted by name or time
      remove_dir_view_states Time
      :_dirview=( $static_arg^Size $:_dirview )
      display_directory -s $static_arg
    }
  }
}

menu: DirDotMenu
{
  menu_item
  {
    ti=Hide _H__;
    enable_if
    {
      # M013 see if dir is hiding dot files, if so, stipple
      vstate=`(list intersect $thread_name(2)^Show :: $:_dirview)
      [ -ne $#vstate 0 ]
    }
    select_action
    {
      # M013 don't need to add to state, no entry means hide dot files
      # just remove show state
      remove_dir_view_states Show
      hide_dot_files
      odw -v $static_arg
    }
  }

  menu_item
  {
    ti=Show _S__;
    enable_if
    {
      # M013 see if dir is showing dot files already, if so stipple
      vstate=`(list intersect $thread_name(2)^Show :: $:_dirview )
      [ -ne $#vstate 1 ]
    }
    select_action
    {
      # M013 if we got in here then we were hiding dot files
      # do not need to remove any states since no 'show' means 'hide'
      :_dirview=( $static_arg^Show $:_dirview )
      rdr dot_^$static_arg
      odw -v $static_arg
    }
  }
}

menu: set_desktop_menu
{
  menu_item: General User
    {
      set_desktop General.dt
    }

  menu_item: Power User
    {
      set_desktop Power.dt
    }

  menu_item: Admin User
    {
      set_desktop Admin.dt
    }
}
