navitrix.icn: Procedures to perform file navigation

link navitrix
July 10, 2002; Ralph E. Griswold
Requires: Version 9 graphics, UNIX
This file is in the public domain.

This package provides an interface for file navigation.  It is
intended for use with another application with a visual interface.
____________________________________________________________

The code is based on Unix but may work in other Unix-like environments.

Directories are shown with a trailing slash.  Clicking on a directory
moves there.  Clicking on a file name selects it.  The text of the
button used to dismiss the navigator is put in the global variable
nav_state, while the name of the selected file is put in the global
variable nav_file.

nav_keyboard() processes keyboard shortcuts.  A return character is
equivalent to clicking on the Okay button.  Other characters cause
the top list entry to be positioned at a name that starts with or is
close to the character.

The other application needs only to know this:

     The navigator is initialized by calling nav_init().  This opens a
     hidden window, assigned to the global variable nav_window, for
     the navigator.  It also assigns the navigator root vidget to the
     global variable nav_root.

     To use the navigator, the other application needs to change the
     canvas status nav_window to normal so it can accept user events
     and hide it again when it has been "dismissed".  The navigator
     puts the selected file in nav_file as mentioned above.

     If the application wants to support the navigator's keyboard
     shortcuts, it needs to set the shortcut procedure to nav_keyboard
     when the navigator window is active.

A typical event loop for using the navigator is:

repeat {                     # event loop
   case Active() of {
      &window   :  {         # application window
         root_cur := root
         shortcuts_cur := shortcuts
         }
      nav_window   :  {      # navigation window
         root_cur := nav_root
         shortcuts_cur := nav_keyboard
         }
      }
   ProcessEvent(root_cur, , shortcuts_cur)
   case nav_state of {
      &null   :  next
      "Okay"  :  load_pattern()
      }
   nav_state := &null
   WAttrib(nav_window, "canvas=hidden")
   }

where process_file() is a procedure that does something with the
file.

Note that the value of nav_state determines what needs to be done.  It is
null when the navigator has not been used since the last event.  If
the navigator is dismissed with "Cancel" instead of "Okay", nothing
needs to be done except hide the navigator window and set the nav_state
to null.

Coupled with this is a procedure (or more than one) that makes the
navigator window visible, as in

     procedure open_cb()
        WAttrib(nav_window, "canvas=normal")
        ...
        return
     end

If there is more than one use of the navigator, the callbacks that
enable it can set process_file to the appropriate companion procedure.

Source code | Program Library Page | Icon Home Page