#!/bin/csh
# This script is called for files listed in .GDEmenus files
# using openitem:

# It chooses a viewer, depending on the file extension.
# Mime might be the 'right' way to do this, but it's
# immensly easier to just write a short script, and probably
# more reliable.

# In most cases the file extension tells us what to do with
# the file. However, we also want to be able to correctly handle
# a URL, so URL tells us if $1 is a URL, rather than a local
# file name. 
set EXT = $1:e


set URLFLAG = `echo $1 | egrep -e '^http:|^https:|^ftp:|^ftps:'`
if ($URLFLAG != "") set EXT = "html"

switch ($EXT)
  # -------- Web pages
  case "html": 
        browser.csh $1 &
    breaksw
  case "shtml": 
        browser.csh $1 &
    breaksw
  case "HTML": 
        browser.csh $1 &
    breaksw
  case "htm": 
        browser.csh $1 &
    breaksw    
  case "HTM": 
        browser.csh $1 &
    breaksw
  # -------- PDF, PostScript
  case "pdf": 
    $BL_PDFViewer $1 &
    breaksw
  case "PDF": 
    $BL_PDFViewer $1 &
    breaksw
  case "ps": 
    $BL_PSViewer $1 &
    breaksw
  case "PS": 
    $BL_PSViewer $1 &
    breaksw
  # -------- Bitmap graphics
  case "GIF": 
    $BL_ImageViewer $1 &
    breaksw  
  case "gif": 
    $BL_ImageViewer $1 &
    breaksw  
  case "JPG": 
    $BL_ImageViewer $1 &
    breaksw  
  case "jpg": 
    $BL_ImageViewer $1 &
    breaksw  
  case "JPEG": 
    $BL_ImageViewer $1 &
    breaksw  
  case "jpeg": 
    $BL_ImageViewer $1 &
    breaksw  
  case "PNG": 
    $BL_ImageViewer $1 &
    breaksw  
  case "png": 
    $BL_ImageViewer $1 &
    breaksw  
  case "BMP": 
    $BL_ImageViewer $1 &
    breaksw  
  case "bmp": 
    $BL_ImageViewer $1 &
    breaksw  
  case "TIF": 
    $BL_ImageViewer $1 &
    breaksw  
  case "tif": 
    $BL_ImageViewer $1 &
    breaksw    
  case "TIFF": 
    $BL_ImageViewer $1 &
    breaksw  
  case "tiff": 
    $BL_ImageViewer $1 &
    breaksw    
  # -------- Default is text editor
  default: 
   # Special code for text editors used by GDE and scripts called by GDE
   # Nedit crashes in some Linux systems due to libraries set in BIRCHLIBS.
   # nedit_wrapper unsets LD_LIBRARY_PATH before calling nedit.
   # gedit opens all files in a single window. gedit_wrapper.sh forces
   # gedit to open each file in different window.
   # choose_edit_wrapper.sh returns the name of the wrapper to use
   # for each editor, or just returns BL_TextEditor if there is no
   # wrapper.
   setenv BL_TextEditor `choose_edit_wrapper.sh`  
   $BL_TextEditor $1 &
    breaksw
endsw

