Wednesday, June 3, 2009

Editor components API

Today I managed to finish the tests for the "Text with changes" data structures described in a previous post.

I felt ready to create a basic Gedit plugin - but to my surprise, I found out that the API offered by Gedit doesn't offer a few essential notifications. I want to be able to register a callback with events such as 'buffer changes', regardless of cause (insertions, deletions, cuts, pastes, undos, redos etc.)

It turns out that the concepts used in the Gedit API are described in the PyGTK tutorial, but the event system in Gedit is even weaker than that in the TextView component of GTK (which doesn't offer generic enough 'buffer modification' events either).

I can hook up the keyboard events and handle insertions and deletions, but when it comes to cuts/pastes/undos/redos I have a hard time detecting the events (the user may use non-standard shortcuts) but, most importantly, I cannot isolate the text changes (which characters changed).

After a little more digging, I found out that 1) Scintilla supports a 'buffer modification' event that offers everything I need and 2) wxPython has a portable (GTK+/Win32) wrapper over Scintilla, along with demos with full source code that show how to use the control AND the 'buffer modification' notification/event.

So Synpl changes once again, not so radically this time. It was supposed to become a Gedit plugin, now it seems I'll end up with a standalone editor based on Scintilla and wxPython.

At least I feel like I'm making progress.

No comments: