Re: GtkSourceView: code folding



Well, while it is true that we are not particularly interested in getting this in gedit, but I still would very much welcome code folding as a feature in gtksourceview.

Note that there is a bug open in bugzilla that contains an implementation of a folding API for gtksourceview, and the drawing part was working quite nicely last time it was tested (but I am pretty sure things have bitrotten in the mean time).
Things were stuck because we wanted to implement the folding logic itself based on the highlighter, but I think that is not a requirement and we could merge an API that allows to fold part of the text, leaving to the caller the logic of where to fold.

I think I understood what you want to do with the text anchor: you want a small clickable target within the buffer, something like [...] to show that there is folded text. The code in the bug/branch I mentioned had this feature, but I think it was done by simply drawing on top of the text instead of inserting a widget.


If you would like to pick up that bug, compare the proposed api/implementation with yours, and try to push things forward in gtksourceview itself, it would be very welcome.  Beside, also preliminary patches to undomanager or other parts to make your implementation work would surely be considered.


Ciao

    Paolo





On Tue, Aug 12, 2014 at 3:55 PM, flix <pupobrasil tiscali it> wrote:
First of all, thank you for your quick reply.

A probably better solution is to implement the code folding as every other text editor do: show +/- buttons in the margin. See GtkSourceGutter. I've implemented a prototype of a gutter renderer for code folding: https://git.gnome.org/browse/gtksourceview/log/?h=wip/gutter-renderer-folds Ideally an API for the code folding should be created in GtkSourceView, but having first a working implementation in an application would be a good first step. See also this utility class, which is useful to store the folding points (it is a private class): https://git.gnome.org/browse/gtksourceview/tree/gtksourceview/gtksourcemarkssequence.h Regards, Sébastien

Well, yes, actually I've already made the gutter part myself and it's working great (zoom included). Initially I just used the default implementation Gsv provides for Gsv::Mark icons (by swapping a 'collapsed mark' with an 'expanded mark' to change state): it worked, but with a custom gutter rendered I managed to use just one mark (extended to contain the folding state) for both states, and to make zooming work in the gutter icons too.

However the main problem of my post is that the TextChildAnchor is necessary if we want to handle collapsed regions properly (for example for saving all the possible space, or to implement free collapsable regions, like in C#): otherwise we can just make bad looking regions (like the Scintilla Editor do, together with many other editors that are commonly used on Linux).

That's why my primary issue is to find out how to remove obj characters (TextChildAnchors in my case, but Pixbufs inside text too) from the undo stack.

P.S. Now I can build a custom UndoManager properly in GtkSourceViewmm (I had to derive from Glib::Object as well and to add something like: Glib::ObjectBase(MyUndoManager) in the ctr initialization list). I'll see if creating a custom undo stack is too complicated for me or not...

Thanks for the links: I'll check them out.



_______________________________________________
gnome-devtools mailing list
gnome-devtools gnome org
https://mail.gnome.org/mailman/listinfo/gnome-devtools



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]