]> git.babelmonkeys.de Git - jubjub.git/commitdiff
Scroll ChatTextView to the end when text is added
authorFlorian Zeitz <florob@babelmonkeys.de>
Sun, 6 Jan 2013 22:51:55 +0000 (23:51 +0100)
committerFlorian Zeitz <florob@babelmonkeys.de>
Sun, 6 Jan 2013 22:51:55 +0000 (23:51 +0100)
src/gui/gtk/JubGtkChatUI.h
src/gui/gtk/JubGtkChatUI.m

index 1b27ca1d0f9f5db4f0ec24405911125be33f4450..351eb6d02c10cf91943442836ed9493770733d5a 100644 (file)
@@ -8,6 +8,7 @@ typedef void (^jub_close_block_t)(void);
 @interface JubGtkChatUI: OFObject
 {
        GtkWidget *chat_window;
+       GtkTextView *chat_view;
        GtkTextBuffer *chat_buffer;
        jub_send_block_t sendBlock;
        jub_close_block_t closeBlock;
index 277cfe5d5407a93e9908fbd6e6729669e95ce84c..8fc633e067cfdbd46df680a6a8b4c2759883276a 100644 (file)
@@ -47,7 +47,6 @@ static void call_close_block(GtkWidget *object, gpointer data)
                bufferEmpty = YES;
 
                g_idle_add_block(^{
-                       GtkTextView *chat_view;
                        GtkEntry *chat_entry;
 
                        GtkBuilder *builder = gtk_builder_new();
@@ -110,23 +109,27 @@ static void call_close_block(GtkWidget *object, gpointer data)
        BOOL first = bufferEmpty;
        if (OF_UNLIKELY(bufferEmpty)) bufferEmpty = NO;
 
-       g_object_ref(chat_buffer);
        g_idle_add_block(^{
-               GtkTextIter endIter;
+               GtkTextIter end_iter;
+               GtkTextMark *insert_mark =
+                   gtk_text_buffer_get_insert(chat_buffer);
+
                if (OF_LIKELY(!first))
                        gtk_text_buffer_insert_at_cursor(chat_buffer, "\n", 1);
 
-               gtk_text_buffer_get_end_iter(chat_buffer, &endIter);
-               gtk_text_buffer_insert_with_tags_by_name(chat_buffer, &endIter,
+               gtk_text_buffer_get_end_iter(chat_buffer, &end_iter);
+               gtk_text_buffer_insert_with_tags_by_name(chat_buffer, &end_iter,
                    [sender UTF8String], [sender UTF8StringLength], "bold",
                    NULL);
-               gtk_text_buffer_get_end_iter(chat_buffer, &endIter);
-               gtk_text_buffer_insert_with_tags_by_name(chat_buffer, &endIter,
+               gtk_text_buffer_get_end_iter(chat_buffer, &end_iter);
+               gtk_text_buffer_insert_with_tags_by_name(chat_buffer, &end_iter,
                    ": ", 2, "bold", NULL);
 
                gtk_text_buffer_insert_at_cursor(chat_buffer, [text UTF8String],
                    [text UTF8StringLength]);
-               g_object_unref(chat_buffer);
+
+               gtk_text_view_scroll_to_mark(chat_view, insert_mark, 0,
+                   FALSE, 0, 0);
        });
 }
 @end