Hello, On the application I'm currently working on [1], I want limit the size of the text entered in a GtkTextBuffer to those saved in the DBMS, so 4096 chars.
I so connected to the 'changed' signal of the GtkTextBuffer, and the handler is : static void on_notes_changed( GtkTextBuffer *buffer, void *empty ) { static const gchar *thisfn = "my_utils_on_notes_changed"; static const gint MAX_LENGTH = 4096; static gboolean in = FALSE; gint count; GtkTextIter start, end; /* prevent an infinite recursion */ if( !in ){ count = gtk_text_buffer_get_char_count( buffer ); if( count >= MAX_LENGTH ){ /* * this code works, but emit the following Gtk-Warning: * * Invalid text buffer iterator: either the iterator is * uninitialized, or the characters/pixbufs/widgets in the * buffer have been modified since the iterator was created. * You must use marks, character numbers, or line numbers to * preserve a position across buffer modifications. * You can apply tags and insert marks without invalidating * your iterators, but any mutation that affects 'indexable' * buffer contents (contents that can be referred to by character * offset) will invalidate all outstanding iterators */ gtk_text_buffer_get_iter_at_offset( buffer, &start, MAX_LENGTH-1 ); /*gtk_text_iter_backward_char( &start );*/ /*gtk_text_buffer_get_iter_at_offset( buffer, &end, count );*/ gtk_text_buffer_get_end_iter( buffer, &end ); /*gtk_text_iter_backward_char( &end );*/ in = TRUE; g_debug( "%s: count=%d, start=%d, end=%d", thisfn, count, gtk_text_iter_get_offset( &start ), gtk_text_iter_get_offset( &end )); gtk_text_buffer_delete( buffer, &start, &end ); in = FALSE; } } } As stated in the comment, the code works (the size if actually limited to 4095 chars), but each execution of gtk_text_buffer_delete() triggers the well-known warning "Invalid text buffer iterator". I am a bit stucked here, because I do not understand why this happens, as the buffer is not modified between taking the iters and deleting the content... Can anyone help me in this matter ? Thanks in advance. Regards Pierre _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list