NAME

Tk::MARC::Editor - a free-form editor for MARC::Record objects

SYNOPSIS

 use Tk;
 use Tk::MARC::Editor;

 # Get a MARC::Record to play with
 use MARC::File::USMARC;
 my $file = MARC::File::USMARC->in( "path/to/marc/record/file.mrc" );
 my $marc = $file->next();
 $file->close();
 undef $file;

 my $mw = MainWindow->new;
 $mw->title("A free-form MARC editor");

 my $FRAME = $mw->Frame()->pack(-side => 'top');

 # Create the editor, passing in the record to edit
 my $ed = $FRAME->Editor(-record => $marc, 
			 -background => 'white'
 			 )->pack(-side => 'top');

 # Or better yet, a scrollable editor
 my $ed = $FRAME->Scrolled('Editor', 
			   -scrollbars => 'e', 
			   -record => $marc, 
			   -background => 'white',
			   )->pack(-side => 'top');

 # Create a space to write information to 
 my $ln = $FRAME->Text(-background => 'lightgray', -height => 10)->pack(-side => 'top');

 # ...and some buttons to do neat things
 my $b1 = $mw->Button( -text => "Get MARC", 
		       -command => sub { my $marc = $ed->Contents();
					 print $marc->as_usmarc();
				     }
		       )->pack(-side => 'left');
 my $b2 = $mw->Button( -text => "Lint", 
		       -command => sub { my $s = $ed->Lint();
					 $ln->Contents( $s );
				     }
		       )->pack(-side => 'left');
 my $b3 = $mw->Button( -text => "Errorchecks", 
		       -command => sub { my $s = $ed->Errorchecks();
					 $ln->Contents( $s );
				     }
		       )->pack(-side => 'left');

 # This one shows that the leader gets updated properly:
 my $b4 = $mw->Button( -text => "Get MARC and reload it", 
		       -command => sub { my $marc = $ed->Contents();
					 $ed->Contents( $marc );
				     }
		       )->pack(-side => 'left');

 MainLoop;

DESCRIPTION

Module for editing MARC records as text. It is derived from Tk::Text; the Contents method is overriden to handle MARC::Record objects.

Right-clicking on the editor will bring up a menu which lets you add fields/subfields (and tells you what they are).

You can, of course, simply use the [Enter] key to open up a new line, and type in your new field from scratch. When the entry cursor moves off that line, the color formatting is applied.

You can use the mouse or keyboard to select and delete text as if this were any other text editor (in fact, you can do almost anything that you could do with Tk::Text).

Only certain elements of the leader are editable (the rest, such as 'record length', are handled internally by MARC::Record.

There are a couple of example programs in the pl directory.

WIDGET-SPECIFIC OPTIONS

-record => marc

    Specify the MARC::Record object to edit. Required. You can change the record being edited later using the Configure( $record ) method.

INSERT VS. OVERSTRIKE MODE

    All areas (field designation, indicators, subfield designation, fixed-field data, etc) will always be in Overstrike mode.

    Pressing the Insert key while in a data region (for example, while in the actual words of the title) will toggle between insert and overstrike, but only for the data regions.

    If you are in Insert mode in a data region, any other region is still in Overstrike mode. When you return to a data region, you will be returned to Insert mode (that is, it remembers what mode you were using the last time you were in a data region).

COLOR

You can completely configure the colour scheme by specifying any combination of the following switches:

-fieldfg       -fieldbg
-ind1fg        -ind1bg
-ind2fg        -ind2bg
-subfieldfg    -subfieldbg
-datafg        -databg
-fixedfg       -fixedbg
-leaderfg      -leaderbg
-leadereditfg  -leadereditbg

So, for example, to create the editor to look like one of the old amber-on-black terminals (remember those?), you could do something like this:

 my $ed = $FRAME->Scrolled('Editor', 
			   -scrollbars => 'e', 
			   -record => $marc, 
			   -background => 'black',
			   -leaderbg => 'yellow',
			   -leaderfg => 'black',
			   -fieldbg => 'black',
			   -fieldfg => 'yellow',
			   -ind1bg => 'black',
			   -ind1fg => 'yellow',
			   -ind2bg => 'black',
			   -ind2fg => 'yellow',
			   -subfieldbg => 'yellow',
			   -subfieldfg => 'black',
			   -databg => 'black',
			   -datafg => 'yellow',
			   -fixedbg => 'black',
			   -fixedfg => 'yellow',
			   )->pack(-side => 'top');

You can, of course, always use the configure( -attribute => value ); form to deal with colors individually. For example, $ed->configure( -leaderbg => 'darkgreen' );

You can also use the ColorScheme method to get or set all the colors at once.

METHODS

Lint()

    Returns the result of using MARC::Lint on the record being edited, as a string.

Errorchecks()

    Returns the result of using MARC::Errorchecks on the record being edited, as a string.

Contents( marc )

    Load the given MARC::Record object into the editor.

    When invoked without a parameter, gets the contents of the editor converted into a MARC::Record object.

ColorScheme( href )

    Set or retrieve the current color scheme.

    When invoked without a parameter, gets the color scheme - a hash of the following form:

        %color = ( "field"      => { fg => 'darkgreen',     bg => undef },
    	       "ind1"       => { fg => 'yellow',        bg => 'darkslategrey' },
    	       "ind2"       => { fg => 'yellow',        bg => 'darkslategrey' },
    	       "subfield"   => { fg => 'darkgoldenrod', bg => undef },
    	       "data"       => { fg => 'blue',          bg => undef },
    	       "fixed"      => { fg => 'black',         bg => undef },
    	       "leader"     => { fg => 'black',         bg => 'blanchedalmond' },
    	       "leaderedit" => { fg => 'black',         bg => 'white' },
    	       "background" => 'white',
    	       );

    Note that you can always use the configure( -attribute = value );> form to deal with colors individually. For example, $ed-configure( -leaderbg => 'darkgreen' );>

REQUIREMENTS

Tk::MARC::Editor requires MARC::Record, MARC::Descriptions, MARC::Lint, and MARC::Errorchecks

SEE ALSO

LICENSE

This code may be distributed under the same terms as Perl itself.

AUTHOR

David Christensen, <David dot A dot Christensen at gmail dot com>