This structure provides the gate of text editors.
A text editor gate allows the control of a complex text view, which provides text editing functionality to the user. The design of the text editor gate is completely oriented towards the Tk text widget (credits to the author).
List of Import References :
See BOOL
See BTUnion
See Char
See Com
See DENOTATION
See Int
See Nat
See Option
See Real
See Seq
See Set
See String
See Void
See WinConfig
See WinInternal
See WinTag
See WinTclTk
SIGNATURE WinTextEditor
$Date: 2010-09-30 18:24:17 +0200 (Do, 30. Sep 2010) $ ($Revision: 616 $)
IMPORT Nat ONLY nat Int ONLY int Void ONLY void String ONLY string Seq[searchOpt] ONLY seq Seq[index] ONLY seq Seq[range] ONLY seq Set[tag, <] ONLY set Option[index] ONLY option IMPORT Com[tag] ONLY com Com[index] ONLY com Com[mark] ONLY com Com[seq[range]] ONLY com Com[void] ONLY com Com[string] ONLY com Com[textEditor] ONLY com Com[option[index]] ONLY com IMPORT WinInternal ONLY view : SORT config : SORT tag : SORT WinConfig ONLY point : SORT WinTag ONLY < : tag ** tag -> bool
A new text editor is constructed with the command below:
SORT textEditor FUN textEditor : com[textEditor]
A text editor is attached to a view with the configuration below:
FUN edit : textEditor -> config
At one time, one editor may be attached to only one view. Subsequent
applications of the editor
configuration cancel the use of the
editor for previous views.
Currently, only text and entry views (see WinText) may have attached a text editor.
Note that any commands on text editors are disabled (i.e. will block) as long as the text editor is not attached to a view which is displayed in a window. To execute e.g. a sequence of initialization commands on a text editor at a time a view isn't yet attached or displayed, an agent may be spawn; the commands will be executed as soon as the view will be displayed.
The characters managed by a text editor may be addressed in
several ways. The type index
is used for this
purpose:
TYPE index == pos (line : nat, -- starts at 1 column : nat) -- starts at 0 point (point : point) -- character below point end -- after the last character chars (index : index, -- adjust count characters count : int) lines (index : index, -- adjust count lines count : int) linestart (index : index) -- beginning of line lineend (index : index) -- end of line wordstart (index : index) -- beginning of word wordend (index : index) -- end of word first (tag : tag) -- first character with tag last (tag : tag) -- last character with tag at (mark : mark) -- character after mark
Continuous ranges of characters are adressed by a value of type range
:
TYPE range == range (first : index, last : index)
The function index
normalizes an index to the form
pos(Line, Column)
.
FUN index : textEditor ** index -> com[index]
A mark is associated with the gap between two characters in a text. If characters around a mark are removed the mark will still remain. Marks may be used in indices to address the character currently following the mark.
SORT mark FUN insert : mark FUN current : mark FUN mark : textEditor ** index -> com[mark] FUN move : textEditor ** mark ** index -> com[void] FUN delete : textEditor ** mark -> com[void]
The predefined mark insert
is associated with the users
insertion cursor. The predefined mark current
is automatically
maintained to address the character nearest to the current mouse position.
The command mark
creates a mark and sets it to point just
before the character addressed by the given index. The command
move
changes the position of a mark.
The command delete
deletes the given mark.
Several commands provide modifying and retrieving the text managed by a text editor.
FUN insert : textEditor ** string -> com[void] FUN insert : textEditor ** string ** index -> com[void] FUN insert : textEditor ** string ** index ** config -> com[tag] FUN delete : textEditor -> com[void] FUN delete : textEditor ** index -> com[void] FUN delete : textEditor ** range -> com[void] FUN delete : textEditor ** seq[range] -> com[void] FUN get : textEditor -> com[string] FUN get : textEditor ** index -> com[string] FUN get : textEditor ** range -> com[string] TYPE searchOpt == forwards backwards exact regexp nocase FUN search : textEditor ** denotation ** index ** seq[searchOpt] -> com[option[index]] FUN see : textEditor ** index -> com[void]
The insert
commands insert the given string at the given index. If
no index is given, the insertion point is at(insert)
. If a
configuration is specified, then the inserted string is tagged with
a newly generated tag (which is returned by the command),
and the configuration is applied to this tag (see below for tags and
configurations).
The delete
commands remove text. If no index or range is given, the
character at(insert)
is addressed.
The get
commands retrieve the text specified by the index or range.
If no index or range is given, the entire text is retrieved.
The search
command implements searching for a phrase specified
by its second argument. A sequence of options determines the searching
mode.
The see
command ensures that the character at the given index
is visible in the scrolling region of the displayed view.
Each character (or embedded window) managed through a text editor may have assigned a set of tags. Via configurations associated with tags the graphical appearence and the reponsive behaviour of characters or groups of characters may be controlled.
FUN selection : tag FUN tag : textEditor ** index ** tag -> com[void] FUN tag : textEditor ** range ** tag -> com[void] FUN tag : textEditor ** seq[range] ** tag -> com[void] FUN untag : textEditor ** index ** tag -> com[void] FUN untag : textEditor ** range ** tag -> com[void] FUN untag : textEditor ** seq[range] ** tag -> com[void] FUN ranges : textEditor ** tag -> com[seq[range]] FUN set : textEditor ** tag ** config -> com[void] FUN lower : textEditor ** tag -> com[void] FUN raise : textEditor ** tag -> com[void]
The tag selection
has a predefined meaning: it is automatically
assigned to the characters belonging to the current selection.
A given tag is associated with a single character, the characters in
a range or the characters in a sequence of ranges with the command
tag
. The command untag
removes an association.
The command ranges
return the (minimal) ranges of characters
which have assigned a given tag. All indices in the returned ranges are
of the form pos(Line, Column)
.
The command set
associates a configuration with a given tag.
The following general configurations are sensitive:
background bgstipple borderwidth fgstipple font foreground relief
bind regulate sync enable
Only event-based bindings are allowed, and only those related to the mouse or keyboard
The commands lower
and raise
manipulate the priority
of tags. If a character has assigend a set of tags, only the
one with the highest priority is effective w.r.t. the associated
configurations. By default, the last tag newly introduced with one of
the tag
or set
commands has highest priority, which
may be changed with these commands.
Views may be embedded in the text managed by a text editor. An embedded view behaves as a single character according to text oriented commands.
FUN insert : textEditor ** view ** index -> com[void] FUN insert : textEditor ** view ** index ** config -> com[tag]
The following specific configurations are supported for embedded views:
TYPE align == top center bottom baseline FUN align : align -> config FUN stretch : config
The alignment specifies how to place the view w.r.t. the line it is
displayed in. With top
, the top of the view is aligned with
the top of the line. With center
, the view is centered within
the range of the line. With bottom
and baseline
, the
bottom of the view is aligned with the bottom resp. baseline of the line.
The configuration stretch
specifies, that the height of
the view should be expanded to the height of the line.
Currently, the providing level of a text editor is completely oriented
towards Tk texts. The command register(Win, Wid)
registers
the Tk text widget Wid
displayed by window Win
to
be edited by the given text editor. Any previous registration is
discarded.
IMPORT WinInternal ONLY window:SORT WinTclTk ONLY widget:SORT FUN register : textEditor ** window ** widget -> com[void]
next node: WinTclTk,
prev node: Windows,
up to node: Subsystem Opal Windows