User's Guide to the Tycho File Class

The File class in Tycho is the base class for most editors. It provides a top-level window with a menu bar at the top. It also handles autosave and crash recovery. Tycho will save the data to a file with the same name as the current file but with the prefix #auto#. This file is automatically removed when you save the modified data.

By itself, this class is not very useful; the derived classes are the ones actually used. Keyboard shortcuts are provided for many commands, as well as for traversal of the menus.

Version Control

The version control or revision control mechanism built into the File class interfaces to either SCCS, a Unix "source code control system", or RCS, a public domain improvement. When the Revision Control command in the File menu is invoked, then if the file is already under version control by either SCCS or RCS, a control panel will appear that permits the user to check out the file (if it is not checked out), check in the file (if it is checked out), examine the version history, or unedit the file (cancel changes made since the file was checked out). The version history mechanism displays the comments that were filed with checkins as well as version numbers and dates. Double clicking on an older version will cause that version to be displayed in a new window.

If the file is not currently under revision control, then invoking the Revision Control command will query the user about whether the file should be placed under revision control. The list of revision control systems presented to the user can be set as an option, but currently includes only SCCS and RCS, with SCCS being the default.

Revision control is also used by the Toggle read-only command, if the file is already under revision control. If it is not, then the read-only permissions are simply changed without the intervention of any revision control system.

The Tycho development group uses SCCS, and has configured the options to follow our style. In particular, when a file is put under the control of SCCS, it is required to have "ID keywords", which are strings like %W% and %G%. When a file is checked in, these get converted into the version number and date. In addition, in order to support copyright notices, %Q% gets converted into the current year.

Window Menu

File objects have a Window menu in the menu bar. The menu contains commands that somewhat duplicate typical window manager functions, but are provided in order to have convenient key bindings. It also contains commands to open new, blank editors for any type of editor that has been registered with the File class. In addition, all open editors that are associated with named files are listed. This makes it easier to find editors that may have been buried by other windows on the screen. Note that if the editor is open in another screen of a virtual window manager, it will not appear when you issue the command in the Window menu. Also, if an editor has the name NoName associated with it, it does not appear in the Window menu. To give it a name, use SaveAs (in the File menu).

Help Menu

The Help menu provides access to the on-line documentation for Tycho. The User's Guide entry in the menu will bring up a user's guide for the widget in which you invoke the command, if one exists. The Index entry will bring up the master Tycho index.

Registering an editor

Since Tycho is meant to be an extensible system, it is expected that users will create new editors. Integrating these editors into Tycho is easy. The code illustrated in the following example is generally contained in the package load file of the package containing your editor (see Tycho's package system), or you can execute it directly into the Tycho console, or source a file containing at after you start Tycho.

First, you need to create a "mode" for the file type -- this is much like a file mode in emacs. For example:

::tycho::register mode "foo" \
	-command  {::tycho::view EditFoo -file {%s}} \
	-viewclass ::tycho::EditFoo \
	-label    {Foo editor} \
	-category "text" \
	-underline 0
Here, the arguments to the ::tycho::register mode command are:
  • The first argument is the name of the mode.
  • The -command argument is a Tcl command that is executed when a file is opened in this mode. An occurrence of an embedded %s is replaced with the file name before invoking the command, using the Tcl format command.
  • The -viewclass argument is the class of your editor.
  • The -label argument is a description of the editor. If it is supplied, then the command will be added to the Window menu of all File objects opened in the future using the value of this description as the menu label. This permits the user to open a new blank editor of the given class.
  • The -category argument selects the sub-menu of the Windows menu into which this editor will be placed. The standard set of categories is text, graphics, tool, and html.
  • The -underline argument is the position of the character in -label to underline for menu traversal.
  • You also need to associate one or more file extensions with the mode. For example:

    ::tycho::register extensions "foo" .foo .bar .baz
    

    Now, any file that ends with one of the extensions .foo, .bar, or .baz will by default be opened in an EditFoo widget. For example, a Tycho Open File command on a file called file.foo will cause a window containing an instance of ::tycho::EditFoo to be created, and file.foo will be loaded into it. The syntax of the command that creates the windows will be:

      ::tycho::view EditFoo -file file.foo
    
    The name of the widget is generated automatically. The -file option must (obviously) be understood by the editor. But that is the only constraint on the editor.

    If an editor has a ToolBar, then the ::tycho::register mode command might look like this:

     ::tycho::register mode "html" \
    	-command  {::tycho::view HTML -file {%s} -toolbar 1} \
    	-viewclass ::tycho::HTML \
    	-label    {HTML Viewer}  \
    	-category "html" \
    	-underline 5
    

    Tycho Home Page


    Copyright © 1996-1998, The Regents of the University of California. All rights reserved.
    Last updated: 06/11/98, comments to: eal@eecs.berkeley.edu