From: Florian Zeitz Date: Sun, 6 Jan 2013 22:51:55 +0000 (+0100) Subject: Scroll ChatTextView to the end when text is added X-Git-Url: https://cgit.babelmonkeys.de/?a=commitdiff_plain;h=292cda5cf5f5ea121307153aaaea63288abc71e4;p=jubjub.git Scroll ChatTextView to the end when text is added --- diff --git a/src/gui/gtk/JubGtkChatUI.h b/src/gui/gtk/JubGtkChatUI.h index 1b27ca1..351eb6d 100644 --- a/src/gui/gtk/JubGtkChatUI.h +++ b/src/gui/gtk/JubGtkChatUI.h @@ -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; diff --git a/src/gui/gtk/JubGtkChatUI.m b/src/gui/gtk/JubGtkChatUI.m index 277cfe5..8fc633e 100644 --- a/src/gui/gtk/JubGtkChatUI.m +++ b/src/gui/gtk/JubGtkChatUI.m @@ -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