Redesign of the SynEdit component/es

From Lazarus wiki
Jump to navigationJump to search

English (en) español (es)

Este es un intento de reestructurar la clase monolítica TCustomSynEdit dentro de una clase base más general, la cual puede ser compartida entre varios componentes editor o visor. Este enfoque permitirá encapsular la funcionalidad básica, por lo que las clases derivadas no podrán romper su funcionalidad vital. El objetivo del rediseño es un conjunto de clases, útiles en la creación del editor de código fuente source code editor y otros visores / editores.

Árbol de clases

I just came across the RichView control, that already is based on a general scrolling window component RVScroll. Este componentes llegará a ser la raiz de mi rediseño.

Una vez que se encapsulan los detalles del scrollbar, se puede derivar un componente base tipo grid. De acuerdo con nuestro objetivo de un source code editor, las celdas en esta grid contendrán posteriormente caracteres, de una fuente monoespacio. Al contrario que el componente TCustomGrid, nuestra grid es solamente una organización lógica de la superficie de dibujo. En lugar de filas y columnas fijas, se puede mostrar gutter a la izquierda de la grid.

El próximo nivel implementará una clase de grid de carácter, con la implementación de una demo de un visor simple de texto. En esta clase se implementarán el manejo de fuentes (determinación del tamaño de celda), a caret, y líneas de longitud arbitraria.

En los próximos niveles más elevados se implementan cambios en el texto y finalmente la funcionalidad específica de Lazarus.

Clases relacionadas

Much specific functionality can be implemented in helper classes, so that the editor component can be customized by replacing the SynEdit helpers with other objects. One obvious helper is dedicated to the gutter display, another one to the display of the lines in the character grid, and the text lines are provided and managed by a third helper.

Gutter

A gutter pane to the left of the grid can be used to display additional information. Where SynEdit displays line numbers and markers, some other application may display e.g. a table of contents in the gutter.

Grid Painters

The basic grid delegates painting to the gutter object and a virtual PaintGrid method. In the case of a character grid, the PaintGrid method organizes the display of entire grid rows, calling another virtual PaintRow method for the actual painting. The PaintRow method again can call a PaintCell method, or it delegates the display of the text in the line to an text painter object.

Grid Contents

The contents of a character grid typically are stored in some TStrings object, accessible as strings by line/row numbers. For proper display, all tabs must be expanded into spaces, what suggests an alternative method to retrieve the display strings from the string list. This method also can provide Unicode strings, in order to simplify the column index calculations. Syntax highlighting requires a synchronization between the parser, the highlighting painter, and the list of strings. When wordwrap or block folding can affect the number of visible lines, a translation between display rows and line numbers (string indices) has to be implemented in a dedicated content class. Such specialized content classes should be used only together with appropriate control classes.

When multiple source files shall be presented in a tabbed editor window (notebook?), the contents of the control should be easily exchangable. When also the same file can be shown in multiple edit controls, at the same time, the actual caret position and further context information must be stored in the content objects, apart from the common text and file information. Changes to an shared text must be reported to all active edit/content objects. Such features require a proper separation of the configuration and context information, into control settings, display content state, and physical text source state.