Base To-Do/SQL Syntax Highlighting

From OpenOffice.org Wiki

Jump to: navigation, search

Contents

Description

The SQL view of the query designer, which displays, and allows to edit, raw SQL statements, currently is a mere text input field. It would be helpful especially to the unexperienced user to have syntax highlighting here: SQL keywords should be notable, literals should be distinguished, and the like.

OpenOffice.org already features core components which allow syntax highlighting in a text field - the most prominent example is the Basic IDE -, so there already is a foundation to base this feature on.

Sketch

There is one class which cares for editing the SQL command in the query designer, named OSqlEdit, located in dbaccess/source/ui/inc/sqledit.hxx resp. dbaccess/source/ui/control/sqledit.cxx. The control implemented here currently has not much own functionality, compared with its base class MultiLineEdit. SQL Syntax highlighting would happen in this class, and might include ditching and re-writing it, based on a more appropriate base class.

There are already two places where syntax highlighting is implemented in OpenOffice.org: The Basic IDE uses it to, well, highlight the syntax of the Basic script you're editing; and the other one is Writer/Web, that highlights HTML syntax. Poking in the code for Writer/Web and the Basic IDE - see basctl/source/basicide/*, grep for aHighlighter - would probably be of tremendous help for developing an own plan how to implement SQL syntax highlighting.

The basic idea in the Basic IDE is to use a EditEngine, together with a EditView. Those are classes which allow richt-text functionality, that is, displaying and editing text where different portions of the text can have different style attributes (such as color, italic, bold, and much much more). Those are used together with a syntax highlighter which calculates the actual attributes of actual text portions, according to the Basic syntax. Additional, there is glue code which for instance ensures the text portion attributes are adjusted when the text changes.

A similar approach could be used with SQL syntax highlighting.

Further thoughts

  • editview/editengine would certainly be fine, but from a first look at the code, it seems that a Textengine/Textview (or ExtEditengine/ExtEditview) is enough and faster for our purpose, see also this comment inside the source:

http://lxr.go-oo.org/source/util/svtools/source/edit/texteng.cxx#2846

But these classes can be exchanged very easily, so starting with the "wrong" one is not really an issue.

  • it might make sense to not duplicate pretty much everything from the Basic IDE including ExtEditengine/Editview/Window and so on, but create a new control derived from class MultiLineEdit which would handle syntax highlighting as well. This could then be used from within Writer HTML editor, Basic IDE editor and for the SQL editor. As the SQL editor is using a MultiLineEdit already, this would be extremly easy to exchange by the new control


I started working on this feature for OOo 3.1, more info to follow (mod)

Personal tools
Collection