How do I set buffer limit for gtk_text_view in C?
I want my GtkTextView to display only a certain number of characters at the end of a long string. Is this possible, and how can I d开发者_高级运维o it?
Connect to the insert-text
signal of GtkTextBuffer
. In your callback, get the length of the text. If it's longer than the limit, get two start iters, and move one of them forward by the amount of characters you want to delete:
GtkTextIter range_start, range_end;
gtk_text_buffer_get_start_iter(buffer, &range_start);
range_end = range_start;
gtk_text_iter_forward_chars(&range_end, num_chars);
gtk_text_buffer_delete(buffer, &range_start, &range_end);
That said, you'd have to put a LOT of text in a GtkTextBuffer
to crash the application.
精彩评论