### -------------------------------------------------------------------------
###
###  Popups (TkDesk Configuration File)
###
###  This file defines the file-specific popup-menus that are accessed
###  by pressing the right mouse button in any of TkDesk's file lists.
###  Also the popup menu of the "Copy" dialog is defined here.
###
###  *** Press F5 to save changes and reload this file into TkDesk, 
###  *** F6 to do the same plus to close this window.
###
### -------------------------------------------------------------------------

### In this file four Tcl lists are defined: One for directories, one for
### executables and one for all other files.  The fourth defines the
### popup menu contained in the "Copy, Move, Link" dialog.

### Definition of Popup-Menus:
### The Popup-Menus are defined by the elements of a Tcl list.
### (In the following I try to explain its structure, although it will
### probably best to just have a look at the example definition below.)
### Each element of the list is again a Tcl list, whose first element
### contains a list of "glob" patterns. If a file matches any of these
### patterns, this entry will be used for its popup menu. The second
### element defines the entries of the popup menu, by a set of (usually)
### 2-element lists. The first element is the entry's label, while the
### second contains a Tcl script to execute when this menu entry is
### invoked. Cascaded menus are currently not possible.
### The first menu entry of each popup menu defines the default action,
### which will be invoked when a matching file is double-clicked.
###
### TkDesk commands that can be used in the list definition:
### (Only the most common ones are listed here. For a complete overview
### and a detailed explanation refer to the User's Guide.)
###
### dsk_exec cmd ...   : Executes shell command cmd in background.
### dsk_path_exec path cmd ... : Execute cmd in path.
### dsk_view cmd ...   : Executes cmd, displays output in Editor window.
### dsk_open_dir path  : Opens a new file list for directory path.
### dsk_open_browser path    : Opens a new file browser for directory path.
### dsk_edit file      : Edits file.
### dsk_print file     : Prints file.
### dsk_cd path        : Changes directory of browser to path.
### dsk_du path        : Displays disk usage of directory path.
### dsk_periodic cmd seconds : Executes cmd every x seconds.
### dsk_confirm text script  : Executes script when confirmation was positive.
### dsk_read_string label script  : Executes script when entered string is
###                      not empty. "label" will be displayed in the dialog.
### dsk_sound id       : Plays sound id (defined in config-file Sounds). 
### dsk_cbhelp file regexp   : Invokes TkDesk's help system on file.
### dsk_ask_exec       : Asks for a command to execute.
### dsk_ask_dir        : Asks for a directory to open.
### dsk_save_config    : Saves window layout, history, bookmarks etc.
### dsk_exit ?ask?     : Quits TkDesk. "ask" may be one 1 or 0.
###
### Abbreviations that will be replaced with file names etc.:
###
### %s : Full pathname of the first selected file.
### %f : Its filename only.
### %b : "Basename": just the filename without extension.
### %d : Its directory only.
### %B : Same as %A, but will be replaced with "" if no files are selected.
### %A : List containing full pathnames of all selected resp. dropped files.
### %D : Directory of last "active" viewer.
### %x : Current X selection.
###
### The very first Button provides access to a few functions of TkDesk,
### like history menus, configuration menu etc. Its labels are mostly
### "internally reserved" keywords.
### The second button is only defined by the magic word "date" which inserts
### TkDesk's date display at that place into the AB.
###

### Definition of Popup-Menus for Directories:
### (You should better not change the first, i.e. default entry...!)

set tkdesk(popup,directories) {
    {{RCS} {
        {{Check Out...} {jdb_rcs_co %d}}
        {{Open} {dsk_cd %s}}
	{{New Window} {dsk_open_dir %s}}
	{{New Browser} {dsk_open_browser %s}}
	-
	{{Disk Usage} {dsk_du %s}}
	{{Start XTerm here} {
	    cd %s
	    eval exec $tkdesk(cmd,xterm) &
	    cd ~  ;# this is the standard workdir of TkDesk
	}}
	{{Make tar.gz} {dsk_exec tar cf - -C %d %f | gzip >[string_replace %s " " "_"].tar.gz}}	
    }}
    {{*} {
	{{Open} {dsk_cd %s}}
	{{New Window} {dsk_open_dir %s}}
	{{New Browser} {dsk_open_browser %s}}
	-
	{{Find...} {dsk_find_files -path %s}}
	{{Disk Usage} {dsk_du %s}}
	{{Start XTerm here} {
	    cd %s
	    eval exec $tkdesk(cmd,xterm) &
	    cd ~  ;# this is the standard workdir of TkDesk
	}}
	-
	{{Make tar.gz} {dsk_exec tar cf - -C %d %f | gzip >[string_replace %s " " "_"].tar.gz}}	
	{{Make zip} {dsk_exec zip -r %s.zip %f}}
	{{Which rpm} {dsk_view rpm -qfli %s}}
    }}
}

### Definition of Popup-Menus for Executables:
### (If the label of one of the entries is "Edit" it will only be added to the
### menu if the executable is script, ie. the first two characters are #!. 
### If you want an "Edit" entry for all executables just change "Edit" to 
### anything else, e.g. "Do Edit" or "Edit the file!".)

set tkdesk(popup,executables) {
    {{*.class} {
	{{Execute in Xterm} {eval dsk_exec $tkdesk(cmd,xterm) -sb -T %f -n %f -e pauseme java %b}}
    	{{Execute} {dsk_exec java %b}}
	{{View Output} {dsk_view java %b}}
    }}
    {{{*.tcl} {*.tk}} {
	{{Source} {source %s}}
	{{Execute} {dsk_exec %s}}
	{{Execute in Xterm} {eval dsk_exec $tkdesk(cmd,xterm) -sb -T %f -n %f -e pauseme %s}}
	{{View Output} {dsk_view %s}}
	-
	{{Edit} {dsk_edit %s}}
    }}
    {{*} {
	{{Execute} {dsk_exec %s}}
	{{Execute in Xterm} {eval dsk_exec $tkdesk(cmd,xterm) -sb -T %f -n %f -e pauseme %s}}
	{{View Output} {dsk_view %s}}
	{{Manual Page} {dsk_view man %f | col -b}}
	-
	{{Edit} {dsk_edit %s}}
	{{Strip} {dsk_exec strip %s}}
	{{Libraries} {dsk_view ldd %s}}
	{{Which rpm} {dsk_view rpm -qfli %s}}
    }}
}

###
### Definition of Popup-Menus for "Regular" (and other) Files:

set tkdesk(popup,regulars) {
    {{{*-HOWTO} {*-HOWTO.gz}} {
    	{{View (cbhelp)} {dsk_cbhelp %s howto}}
    	{{Edit} {dsk_edit %s}}
    }}
    {{{Makefile} {Gmakefile} {makefile}} {
        {{Make...} {
	    dsk_read_string {Make Target:} {
		eval dsk_exec $tkdesk(cmd,xterm) -sb -geom 80x15 -T \\"make $dsk_read_string\\" -e pauseme make -f %s $dsk_read_string
	    }
        }}
        {{Make Default} {
	    eval dsk_exec $tkdesk(cmd,xterm) -sb -geom 80x15 -T "make" -e pauseme make -f %s
        }}
	-
	{{Edit} {dsk_edit %s}}
	{{XEmacs} {xemacs_load %s}}
	{{Other Window} {xemacs_load %s other}}
	{{Other Frame} {xemacs_load %s frame}}
	-
        {{Check In... (RCS)} {jdb_rcs_ci %s}}
	{{Print...} {dsk_print %s}}
    }}
    {{{*.a} {*.o} {*.sl}} {
    	{{List Symbols} {dsk_view nm %s}}
    	{{List Matches...} {
    	    dsk_read_string {List Symbols Matching (RegExp):} {
    	    	dsk_view nm %s | grep $dsk_read_string
    	    }
    	}}
    }}
    {{{*.c} {*.h} {*.cpp} {*.tcl}} {
	{{Edit} {dsk_edit %s}}
	{{XEmacs} {xemacs_load %s}}
	{{Other Window} {xemacs_load %s other}}
	{{Other Frame} {xemacs_load %s frame}}
	-
        {{Check In... (RCS)} {jdb_rcs_ci %s}}
	{{Print} {dsk_print %s}}
    }}
    {{*.class} {
	{{Execute in Xterm} {eval dsk_exec $tkdesk(cmd,xterm) -sb -T %f -n %f -e pauseme java %b}}
    	{{Execute} {dsk_exec java %b}}
	{{View Output} {dsk_view java %b}}
    }}
    {{core} {
    	{{Strings in Header...} {dsk_view head %s | od -s -A x}}
    }}
    {{*.deb} {
        {{Info } {dsk_view dpkg --info %s}}
        -
        {{Install} {eval dsk_exec $tkdesk(cmd,xterm) -sl 256 -T "dpkg -i %f" -e pauseme "dpkg -i %s"}}
        {{List} {dsk_view dpkg-deb -c %s}}
        {{Extract} {dsk_exec dpkg-deb -x %s ./}}
    }}    
    {{{*.diff} {*.patch}} {
    	{{Apply here } {eval dsk_exec $tkdesk(cmd,xterm) -sb -T \\"patch from %f\\" -n patch -e pauseme sh -c \\"patch <%s\\"}}
    	{{Edit/View} {dsk_edit %s}}
    	{{Print} {dsk_print %s}}
    }}
    {{{*.diff.gz} {*.patch.gz}} {
    	{{Apply here } {eval dsk_exec $tkdesk(cmd,xterm) -sb -T "patch from %f" -n patch -e pauseme sh -c \\"gzip -cd %s | patch\\"}}
    	{{Edit/View} {dsk_edit %s}}
    }}
    {{*.dvi} {
    	{{View} {dsk_exec xdvi -paper a4 -s 3 %s}}
    	{{Print} {dsk_print %s}}
    	{{-> Postscript } {dsk_exec dvips %s}}
    }}
    {{{*.gif} {*.jpg} {*.jpeg} {*.bmp} {*.pcx} {*.p?m} {*.rle} {*.tif} {*.tga} {*.png}} {
	{{View (xv)} {dsk_exec xv %s}}
      	{{Background (tiled)} {dsk_exec xv -root -quit %s}}
      	{{Background (expand)} {dsk_exec xv -root -max -smooth -quit %s}}
    }}
    {{{*.html} {*.htm}} {
    	{{Netscape (new window)} {dsk_netscape file %s window}}
	{{Netscape (reuse window)} {dsk_netscape file %s}}
    	{{Lynx} {eval dsk_exec $tkdesk(cmd,xterm) -e lynx %s}}
	{-}
    	{{Edit} {dsk_edit %s}}
	{{XEmacs} {xemacs_load %s}}
	{{Other Window} {xemacs_load %s other}}
	{{Other Frame} {xemacs_load %s frame}}
    }}
    {{*.java} {
      	{{Edit} {dsk_edit %s}}
      	{{Compile} {eval dsk_exec $tkdesk(cmd,xterm) -sb -geom 80x15 -T [list "javac %f"] -e pauseme javac %s}}
      	-
      	{{Print} {dsk_exec groff -Tps -mandoc %s | $tkdesk(cmd,print)}}
    }} 
    {{{*.man} {*.[1-8n]}} {
      	{{View} {dsk_view groff -Tascii -mandoc %s | col -b}}
      	{{Edit} {dsk_edit %s}}
      	{{Print (Postscript)} {dsk_exec groff -Tps -mandoc %s | $tkdesk(cmd,print)}}
    }}
    {{{*.man.gz} {*.[1-8n].gz}} {
      	{{View} {dsk_view gzip -cd %s | groff -Tascii -mandoc | col -b}}
      	{{Edit} {dsk_edit %s}}
      	{{Print (Postscript)} {dsk_exec gzip -cd %s | groff -Tps -mandoc | $tkdesk(cmd,print)}}
    }}
    {{{*.man.Z} {*.[1-8n].Z}} {
      	{{View} {dsk_view zcat %s | groff -Tascii -mandoc | col -b}}
      	{{Edit} {dsk_edit %s}}
      	{{Print (Postscript)} {dsk_exec zcat %s | groff -Tps -mandoc | $tkdesk(cmd,print)}}
    }}
    {{{*.mov} {*.avi}} {
        {{View} {dsk_exec xanim %s}}
    }}
    {{{*.mpg} {*.mpeg}} {
	{{View} {dsk_exec mpeg_play %s 2>/dev/null}}
	{{View (big)} {dsk_exec mpeg_play -dither 2x2 %s 2>/dev/null}}
	{{View (gray)} {dsk_exec mpeg_play -dither gray %s 2>/dev/null}}
    }}
    {{{*.ps} {*.eps}} {
    	{{View (ghostview)} {dsk_exec ghostview -a4 -magstep 1 %s}}
    	{{View (gv)} {dsk_exec gv %s}}
    	{{Print} {dsk_print %s}}
        -
        {{Odd Pages -> ...odd.ps} {dsk_exec psselect -o %s %d/%b.odd.ps}}
        {{Even Pages -> ...even.ps} {dsk_exec psselect -e %s %d/%b.even.ps}}
        {{Two-page doc -> ...2.ps} {dsk_exec psnup -pa4 -2 %s %d/%b.2.ps}}
        -
        {{ps -> eps} {dsk_exec gs -sDEVICE=epswrite -sOutputFile=%b.eps %s}}
        -
        {{Edit} {dsk_edit %s}}
        {{Compress (gzip)} {dsk_exec gzip %A}}
    }}
    {{*.pdf} {
    	{{View (acroread)} {dsk_exec acroread %s}}
      	{{Edit} {dsk_edit %s}}
    }}
    {{{*.ps.gz} {*.ps.Z}} {
    	{{View (ghostview)} {
	     dsk_exec gzip -cd %s | ghostview -a4 -magstep 1 -
	}}
    	{{Print} {dsk_exec gzip -cd %s | $tkdesk(cmd,print)}}
	-
	{{Uncompress} {dsk_exec gzip -d %s}}
    }}
    {{*.rpm} {
       {{Query} {dsk_view rpm -qip %s}}
       {{File List} {dsk_view rpm -qlp %s}}
       {{Full Query} {dsk_view rpm -qiRlp %s}}
       {{Install} {dsk_view rpm -U %s}}
       -
       {{Test} {dsk_view sh -c "rpm -i --test %s 2>&1 && echo 'Test Successful'"}} 
    }}
    {{*.tar} {
      	{{List Contents} {dsk_view tar tvf %s}}
      	{{Short Listing} {dsk_view tar tf %s}}
	-
      	{{Extract} {dsk_exec tar xf %s}}
      	{{Extract to /} {dsk_exec tar xf %s -C /}}
      	{{Extract to /usr/tmp} {dsk_exec tar xf %s -C /usr/tmp}}
    }}
    {{{*.tar.bz2} {*_tar.bz2} {*.tb2}}  {
        {{List Contents} {dsk_view bzip2 -cd %s | tar tvf - | sort +5}}
        {{Short Listing} {dsk_view bzip2 -cd %s | tar tf - | sort}}
        {{Uncompressed Size } {dsk_view bzip2 -l %s}}
        -
        {{Extract} {dsk_exec bzip2 -cd %s | tar xpf -}}
        {{Extract to /} {dsk_exec bzip2 -cd %s | tar xpf - -C /}}
        {{Extract to /usr/tmp} {dsk_exec bzip2 -cd %s | tar xpf - -C /usr/tmp}}
    }}
    {{{*.tar.z} {*.tar.Z} {*.taz} {*.t.Z}} {
      	{{List Contents} {dsk_view zcat %s | tar tvf - | sort +5}}
      	{{Short Listing} {dsk_view zcat %s | tar tf - | sort}}
	-
      	{{Extract} {dsk_exec zcat %s | tar xpf -}}
      	{{Extract to Subdir} {
      		set err [catch {exec mkdir %d/%b} errmsg]
      		if !$err {
      		  dsk_exec sh -c "zcat %s | (cd %d/%b; tar xpvf -)"
      		  dsk_cd %d/%b
      		} else {
      		  cb_error $errmsg
      		}
      	}}
      	{{Extract to /} {dsk_exec zcat %s | tar xpf - -C /}}
      	{{Extract to /usr/tmp} {dsk_exec zcat %s | tar xpf - -C /usr/tmp}}
	-
	{{Open XSelected} {
	    dsk_busy
	    set err [catch {
		eval exec zcat %s | tar xf - -C $tkdesk(tmpdir) %x
	    } errmsg]
	    dsk_lazy
            if {!$err} {
		if [file readable $tkdesk(tmpdir)/%x] {
		    dsk_open "" $tkdesk(tmpdir)/%x
		    exec rm -r $tkdesk(tmpdir)/%x
		}
	    } else {
		dsk_msg_error $errmsg
	    }
        }}
    }}
    {{{*.tar.gz} {*.tgz}} {
      	{{List Contents} {dsk_view gzip -cd %s | tar tvf - | sort +5}}
      	{{Short Listing} {dsk_view gzip -cd %s | tar tf - | sort}}
	{{Uncompressed Size } {dsk_view gzip -l %s}}
	-
      	{{Extract} {dsk_exec gzip -cd %s | tar xpf -}}
      	{{Extract to Subdir} {
      		set err [catch {exec mkdir %d/%b} errmsg]
      		if !$err {
      		  dsk_exec sh -c "gzip -cd %s | (cd %d/%b; tar xpvf -)"
      		  dsk_cd %d/%b
      		} else {
      		  cb_error $errmsg
      		}
      	}}
      	{{Extract to /} {dsk_exec gzip -cd %s | tar xpf - -C /}}
      	{{Extract to /usr/tmp} {dsk_exec gzip -cd %s | tar xpf - -C /usr/tmp}}
	-
	{{Open XSelected} {
	    dsk_busy
	    set err [catch {
		eval exec gzip -cd %s | tar xf - -C $tkdesk(tmpdir) %x
	    } errmsg]
	    dsk_lazy
            if {!$err} {
		if [file readable $tkdesk(tmpdir)/%x] {
		    dsk_open "" $tkdesk(tmpdir)/%x
		    exec rm -r $tkdesk(tmpdir)/%x
		}
	    } else {
		dsk_msg_error $errmsg
	    }
        }}
    }}
    {{*.url} {
    	{{Netscape (new window)} {dsk_netscape url [exec cat %s] window}}
	{{Netscape (reuse window)} {dsk_netscape url [exec cat %s]}}
    	{{Lynx} {eval dsk_exec $tkdesk(cmd,xterm) -e lynx [string trimleft [exec cat %s] file:]}}
	{-}
    	{{Edit} {dsk_edit %s}}
    }}
    {{{*.voc} {*.wav} {*.au}} {
    	{{Play } {
	    if {[info exists tkdesk(soundcmd)]} {
		if {$tkdesk(soundcmd) != ""} {
		    catch {eval exec [format $tkdesk(soundcmd) %s]}
		}
	    } else {
		cb_alert {Don't know how to play a sound. Edit the "Sounds" config file to tell me how.}
	    }
	}}
    }}
    {{*.xbm} {
	{{View (xv)} {dsk_exec xv %s}}
	{{Edit (bitmap)} {dsk_exec bitmap %s}}
	{{Edit ASCII} {dsk_edit %s}}
    }}
    {{*.xpm} {
	{{View (sxpm)} {dsk_exec sxpm %s}}
	{{View (xv)} {dsk_exec xv %s}}
	{{Edit (pixmap)} {dsk_exec pixmap -filename %s}}
	{{Edit ASCII} {dsk_edit %s}}
    }}
    {{{*.z} {*.Z}} {
	{{Edit} {dsk_edit %s}}
	{{Uncompress} {dsk_exec gzip -d %s}}
    }}
    {{*.gz} {
	{{Edit} {dsk_edit %s}}
	{{Uncompressed Size } {dsk_view gzip -l %s}}
	-
	{{Uncompress} {dsk_exec gzip -d %s}}
    }}
    {{*.bz2} {
        {{Edit} {dsk_edit %s}}
        {{Uncompressed Size } {dsk_view bzip2 -l %s}}
        -
        {{Uncompress} {dsk_exec bzip2 -d %s}}
    }}
    {{{*.zip}} {
        {{List Contents} {dsk_view unzip -l %s}}
        -
        {{Extract} {dsk_exec unzip %s}}
        {{Extract to /} {dsk_exec unzip %s -d /}}
        {{Extract to /usr/tmp} {dsk_exec unzip %s -d /usr/tmp}}
    }}
    {{*} {
	{{Edit} {dsk_edit %s}}
	{{XEmacs} {xemacs_load %s}}
	{{Other Window} {xemacs_load %s other}}
	{{Other Frame} {xemacs_load %s frame}}
	-
	{{Open Directory} {dsk_open_dir %d}}
	{{Print...} {dsk_print %s}}
	{{Mail to...} {dsk_mail %s}}
	{{Which rpm} {dsk_view rpm -qfli %s}}
    }}
}


### (fileops,popup):
### Defines the popup menu of the "Copy, Move, Link" dialog.
### For this list, the following shortcuts are available in addition
### to the "usual" ones (see top of this file):
###
### %S : Selected files or file entered in the "File" entry field
### %T : File/directory entered in the "Destination" entry field.

set tkdesk(fileops,popup) {
    {{Link (symbolic)} {
	dsk_exec $tkdesk(cmd,symln) %S %T
    }}
    {{Link (hard)} {
    	dsk_exec $tkdesk(cmd,ln) %S %T
    }}
    {-}
    {{Tar (create)} {
	set l {}
	foreach lf [list %S] {
		lappend l [file tail \$lf]
	}
	eval dsk_exec tar cvf %T \$l
    }}
    {{Tar (append)} {
	set l {}
	foreach lf [list %S] {
		lappend l [file tail \$lf]
	}
	eval dsk_exec tar rvf %T \$l
    }}
    {{Untar} {
        set ext [file extension %S]
	if {\$ext == ".gz" || \$ext == ".Z"} {
	    dsk_bgexec {sh -c "gzip -cd %S | (cd %T; tar xvf -)"} {Untaring %f...}
	} else {
	    dsk_bgexec {sh -c "cd %T; tar xvf %S"} {Untaring %f...}
	}
    }}
    {-}
    {{Diff} {
	dsk_view diff -bc %S %T
    }}
    {{Patch} {
	dsk_path_exec %T $tkdesk(cmd,xterm) -sb -T \\"patch from %f\\" -n patch -e pauseme sh -c \\"patch <%S\\"
    }}
    {{Concatenate} {
	dsk_exec cat %S >%T
    }}
}


# ---------------------------------------------------------------------------
# xemacs_load what ?where?
# An improved proc provided by Erez Strauss (erez@newplaces.com) to
# communicate with a running XEmacs.  For this to work you need to put the
# lines:
# (gnuserv-start)
# (require 'ange-ftp)
# into your ~/.emacs.  The second line allows for FTP through XEmacs.
# $what is the file that is to be loaded, $where may be: same, other, frame.

proc xemacs_load {what {where same}} {

    catch {auto_reset}        
    if ![dsk_auto_execok "gnudoit"] {
        dsk_errbell
        cb_error "Couldn't find gnudoit.  Maybe you don't have XEmacs installed?"
        return
    }
    
    switch $where {
        "same" {
            set func find-file
            # exec gnudoit -q (find-file \"$what\")
        }
        "other" {
            set func find-file-other-window
            # exec gnudoit -q (find-file-other-window \"$what\")
        }
        "frame" {
            set func find-file-other-frame
            # exec gnudoit -q (find-file-other-frame \"$what\")
        }
        "scratch" {
            set func switch-to-buffer-other-frame
            set what {*scratch*}
            # exec gnudoit -q (switch-to-buffer-other-frame \"*scratch*\")
        }
    }
    set err [catch { exec gnudoit -q ($func \"$what\") }]
    if $err {
        if {[cb_yesno "XEmacs is not yet running on your display. Start it now
	?"] == 0} {
            # start new xemacs
            eval dsk_exec xemacs $what
        }
    }
}

