Thursday, November 10, 2005

Structured Edition

I have been playing since a week or so with the Text System on Cocoa/GNUstep... it's not immediately easy to understand, but it's really nice and powerful :-)
It handles automatically lots of things, you can redefine many things too (create specific layout manager to change the way the text is displayed, eg, to "flow" around an image, etc.)..

For instance, you're supposed to work with NSTextStorage, which contains the content you're editing, and which is supposedly an attributed string (a string plus related attributes -- fonts, links, attachments, etc), and you edit it via a NSTextView. But what if you want MORE than edit an attributed string ? like, say, edit some structured content ?

Well in fact,the answer is to create a subclass of NSTextStorage that will answer the base methods (just four) of NSTextStorage -- it's in fact a class cluster. So the idea is simply to have on one side your structured document (in my case, a simple array of "Section" objects, containing (optionally) a title and a content), and to have a NSTextStorage that will actually serve as a gateway between the text system (which expect a simple NSAttributedString) and your own structured model... Pretty cool :-) and that way you benefit of all the niceties of the text system..

The above screenshot is my current editor (which btw I wrote under Cocoa, and recompiled this evening on GNUstep), the button is there to define a selected text as a title.


Stefan Urbanek said...

Do you have source (xCode project) available?

Nicolas said...

I'd like to clean it up a bit before commiting it (likely on étoilé), but I can send you the current project if you want.

Nicolas said...

Note that one thing I think is doable with this approach is to try to have a code editor done that way :-) (a bit like subtext do). Eg, you could have a code parsing to isolate the methods, then a simple parsing to analyse the code in each method (at least to isolate variables and methods), and then, allow only a "constrained" editing of the code. Goog thing would be to be able to easily implement refactorings, and to present the code in various ways..