NAME

TUI::Editors::FileEditor - text editor view bound to a file on disk

HIERARCHY

TObject
  TView
    TEditor
      TFileEditor

SYNOPSIS

use TUI::Objects;
use TUI::Editors;

my $editor = TFileEditor->new(
  bounds     => TRect->new( ax => 0, ay => 1, bx => 79, by => 23 ),
  hScrollBar => $hScrollBar,
  vScrollBar => $vScrollBar,
  indicator  => $indicator,
  fileName   => 'notes.txt',
);
$self->insert( $editor );

DESCRIPTION

TFileEditor is a TEditor that is associated with a file. It loads the file into the editor buffer when it is created and writes the buffer back to the file when it is saved.

The editor handles the cmSave and cmSaveAs commands and asks the user before discarding modified text through the $editorDialog callback of TEditor. When the global $editorFlags contain efBackupFiles, the previous version of the file is renamed to a file with the extension .BAK before it is overwritten.

The text buffer of TEditor is a plain Perl string, so the buffer allocation methods of Turbo Vision (initBuffer, doneBuffer and setBufSize) are inherited unchanged.

ATTRIBUTES

fileName

Name of the file associated with the editor (Str). The name is expanded to a full path when it is set by the constructor or by saveAs. An empty string means the editor is untitled.

CONSTRUCTOR

new

my $editor = TFileEditor->new(
  bounds     => $bounds,
  hScrollBar => $hScrollBar | undef,
  vScrollBar => $vScrollBar | undef,
  indicator  => $indicator  | undef,
  fileName   => $fileName   | undef,
);

Creates a new file editor. If fileName is a non-empty string, the file is loaded into the buffer. A file that does not exist yields an empty buffer.

bounds

Bounding rectangle of the view (TRect).

hScrollBar

Optional horizontal scroll bar (TScrollBar or undef).

vScrollBar

Optional vertical scroll bar (TScrollBar or undef).

indicator

Optional position indicator (TIndicator or undef).

fileName

Optional name of the file to edit (Str).

new_TFileEditor

my $editor = new_TFileEditor(
  $bounds,
  $hScrollBar | undef,
  $vScrollBar | undef,
  $indicator  | undef,
  $fileName   | undef,
);

Factory-style constructor using positional arguments.

METHODS

handleEvent

$editor->handleEvent( $event );

Handles the inherited editor events. A cmSave command saves the file and a cmSaveAs command calls "saveAs". Both commands clear the event.

loadFile

my $bool = $editor->loadFile();

Loads the file named by "fileName" into the buffer and returns true. A file that cannot be opened is treated as a new, empty file. If the file cannot be read completely, the edReadError message is passed to $editorDialog and false is returned.

save

my $bool = $editor->save();

Saves the buffer to "fileName". Calls "saveAs" if the editor is untitled.

saveAs

my $bool = $editor->saveAs();

Asks the user for a new file name through $editorDialog with the edSaveAs message and saves the buffer to it. The file name is expanded to a full path. Returns false if the user cancels.

saveFile

my $bool = $editor->saveFile();

Writes the buffer to "fileName". If efBackupFiles is set in $editorFlags, the existing file is first renamed to the backup name with the .BAK extension. Returns false and passes the edCreateError or edWriteError to $editorDialog on failure.

shutDown

$editor->shutDown();

Disables the cmSave and cmSaveAs commands and shuts the view down.

updateCommands

$editor->updateCommands();

Enables the cmSave and cmSaveAs commands in addition to the editor commands.

valid

my $bool = $editor->valid( $command );

For cmValid, returns the validity of the editor attribute (isValid). For any other command, a modified buffer triggers the edSaveModify or edSaveUntitled message through $editorDialog. cmYes saves the file, cmNo discards the changes and cmCancel rejects the command.

SEE ALSO

TEditor, TIndicator, TFileViewer

AUTHORS

  • Borland International (original Turbo Vision design)

  • J. Schneider <brickpool@cpan.org> (Perl implementation and maintenance)

COPYRIGHT AND LICENSE

Copyright (c) 1990-1994, 1997 by Borland International

Copyright (c) 2026 the "AUTHORS" as listed above.

This software is licensed under the MIT license (see the LICENSE file, which is part of the distribution).