[pedevel] 2nd. Suggestion for refactoring of PText

  • From: Oliver Tappe <pedevel@xxxxxxxxxxxxxxx>
  • To: Pe Develop <pedevel@xxxxxxxxxxxxx>
  • Date: Sat, 12 Apr 2008 18:38:59 +0200

Hi again,

here's my next suggestion:

A - The Basic Text Model

CTextBuffer     (was: PTextBuffer)
        - exists once per file
        - implements a gap-in-the-middle buffer abstraction (allowing swift
          consecutive insertions at the same place)
        - supports inserting and deleting text
        - manages a set of listeners and a queue of changes for each listener
        - listeners will be informed asynchronously by BMessage when their queue
          becomes non-empty

B - Specific Functionality Models (Controlling the Basic Text Model)

CTextEditor
        - creates connection between CTextBuffer and itself
        - listens to CTextBuffer, i.e. receives ModelChanged-Messages and polls
          the actual changes from its own queue in the model
        - implements basic editing (insert & delete)
        - implements language-specific formatting (auto-indenting, 
brace-matching)
        - sets up CTextStructure, CTextSelection and CTextSearch
        - is linked to a single view (CView - see below)
        - provides complete and clean interface (facade) to be used by
          PTextView and potential scripting language - many methods of this 
          interface are implemented by either CTextStructure, CTextSelection or
          CTextSearch
        Examples for methods implemented here:
                + InsertText()
                + DeleteText()
                + FindMatching()
                + AutoIndent()

CTextStructure
        - refers to a CTextBuffer and analyses the contents of that
        - implements structural analysis of text:
                + maintains info about individual (logical) lines, i.e. wrapping
                  happens here
                + supports finding word boundaries (via callout to 
language-addon)
                + supports finding logical blocks (functions) - delegating the 
real
                  work to a language-addon
        Examples for methods implemented here:
                + Offset2Line()
                + Line2Offset()
                + SetWrapColumn()
                + SetWrappingEnabled()

CTextSelection
        - refers to a CTextBuffer
        - refers to a CTextStructure
        - maintains current position (caret) and start of selection (anchor)
        - maintains virtual position in line (column of caret before vertical
          movement started)
        - supports navigation along structural items (chars, lines, words, 
          functions)
        - supports selecting along structural items
        - supports block selection
        Examples for methods implemented here:
                + GoToLine()
                + GoToOffset()
                + MoveCharacterLeft()
                + MoveCharacterRight()
                + MoveLineUp()
                + MoveLineDown()
                + SetSelection()
                + GetSelection()
                + GetSelectedText()
                + ExtendSelectionCharacterLeft()
                + ExtendSelectionCharacterRight()

CTextSearch
        - refers to a CTextBuffer
        - executes searches and manages results and replace-states
        - implements replacing (as delete + insert)
        Examples for methods implemented here:
                + StartSearch()
                + SearchNext()
                + GetCurrentMatch()
                + CanReplace()
                + Replace()

C - Views

CView [abstract class]
        - declares DirtyLinesChanged() which is invoked by CTextEditor whenever
          something has changed that made one or more lines dirty.

PEditView               (was: PText)
        - is a CView
        - implements DirtyLinesChanged() to invoke RedrawDirtyLines().
        - uses CTextEditor to implement the edit view
        - translates key/mouse events to appropriate method calls on CTextEditor
        - renders text for editing on screen

PPrintView
        - is a CView
        - probably provides empty DirtyLinesChanged() [only redraws once upon
          creation?]
        - sets up CTextEditor as appropriate for printing (activates wrapping)
        - renders text for printing (less color, hidden invisibles)

Well, that's it for this time ;-)

Again, please do not hesitate to send comments.

cheers,
        Oliver

Other related posts: