Skip to content

Commit

Permalink
fix #41 (scrolling to top when selecting message text in --textview m…
Browse files Browse the repository at this point in the history
…ode)
  • Loading branch information
naxuroqa committed Mar 1, 2014
1 parent aa4316a commit 53301aa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 40 deletions.
7 changes: 5 additions & 2 deletions src/ui/ConversationWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,18 @@ namespace Venom {
image_call_video.set_from_pixbuf(ResourceFactory.instance.call_video);
image_send_file.set_from_pixbuf(ResourceFactory.instance.send_file);

Gtk.ScrolledWindow scrolled_window = builder.get_object("scrolled_window") as Gtk.ScrolledWindow;

if( ResourceFactory.instance.textview_mode ) {
conversation_view = new TextConversationView();
scrolled_window.add(conversation_view);
} else {
conversation_view = new ConversationView();
scrolled_window.add_with_viewport(conversation_view);
}
conversation_view.get_style_context().add_class("chat_list");
conversation_view.short_names = true;
Gtk.ScrolledWindow scrolled_window = builder.get_object("scrolled_window") as Gtk.ScrolledWindow;
scrolled_window.add_with_viewport(conversation_view);


//TODO: move to bottom only when wanted
conversation_view.size_allocate.connect( () => {
Expand Down
19 changes: 7 additions & 12 deletions src/ui/GroupConversationWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,18 @@ namespace Venom {
image_call_video.set_from_pixbuf(ResourceFactory.instance.call_video);
image_send_file.set_from_pixbuf(ResourceFactory.instance.send_file);

if(ResourceFactory.instance.textview_mode) {

Gtk.ScrolledWindow scrolled_window = builder.get_object("scrolled_window") as Gtk.ScrolledWindow;

if( ResourceFactory.instance.textview_mode ) {
conversation_view = new TextConversationView();
scrolled_window.add(conversation_view);
} else {
conversation_view = new ConversationView();
scrolled_window.add_with_viewport(conversation_view);
}
conversation_view.get_style_context().add_class("chat_list");
Gtk.ScrolledWindow scrolled_window = builder.get_object("scrolled_window") as Gtk.ScrolledWindow;
scrolled_window.add_with_viewport(conversation_view);
conversation_view.short_names = false;

//TODO: move to bottom only when wanted
conversation_view.size_allocate.connect( () => {
Expand All @@ -136,15 +140,6 @@ namespace Venom {
buffer.insert_with_tags(text_end, text, text.length, tag);
}


/*
//history
public void load_history(GLib.List<Message> messages) {
messages.foreach((message) => {
conversation_view.add_message(message);
});
}*/

public void on_incoming_message(GroupMessage message) {
if(message.from != groupchat)
return;
Expand Down
46 changes: 20 additions & 26 deletions src/ui/TextConversationView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,64 +20,58 @@
*/

namespace Venom {
public class TextConversationView : IConversationView, Gtk.EventBox {
public class TextConversationView : IConversationView, Gtk.TextView {
public bool short_names {get; set; default = false;}
private Gtk.TextView text_view;
private Gtk.TextBuffer text_buffer;
private Gtk.TextTag bold_tag;
private Gtk.TextTag grey_tag;
private Gtk.TextTag implication_tag;

public TextConversationView() {
text_view = new Gtk.TextView();
text_view.set_wrap_mode(Gtk.WrapMode.WORD_CHAR);
text_view.editable = false;
text_buffer = text_view.buffer;
set_wrap_mode(Gtk.WrapMode.WORD_CHAR);
editable = false;

this.add(text_view);

bold_tag = text_buffer.create_tag(null, "weight", 600);
grey_tag = text_buffer.create_tag(null, "foreground", "grey");
implication_tag = text_buffer.create_tag(null, "foreground", "green");
bold_tag = buffer.create_tag(null, "weight", 600);
grey_tag = buffer.create_tag(null, "foreground", "grey");
implication_tag = buffer.create_tag(null, "foreground", "green");
}

public void add_message(IMessage message) {
Gtk.TextIter text_end;
string text;
text_buffer.get_end_iter(out text_end);
buffer.get_end_iter(out text_end);
text = "[%s] ".printf(
message.get_time_plain()
);
text_buffer.insert_with_tags(text_end, text, text.length, grey_tag);
buffer.insert_with_tags(text_end, text, text.length, grey_tag);

text_buffer.get_end_iter(out text_end);
buffer.get_end_iter(out text_end);
text = "%s: ".printf(
short_names ? Tools.shorten_name(message.get_sender_plain()) : message.get_sender_plain()
);
text_buffer.insert_with_tags(text_end, text, text.length, bold_tag);
buffer.insert_with_tags(text_end, text, text.length, bold_tag);

text_buffer.get_end_iter(out text_end);
buffer.get_end_iter(out text_end);
text = "%s ".printf(
message.get_message_plain()
);
if (text[0] == '>') {
text_buffer.insert_with_tags(text_end, text, text.length, implication_tag);
buffer.insert_with_tags(text_end, text, text.length, implication_tag);
} else {
text_buffer.insert(ref text_end, text, text.length);
buffer.insert(ref text_end, text, text.length);
}

text_buffer.get_end_iter(out text_end);
text_buffer.insert(ref text_end, "\n", 1);
buffer.get_end_iter(out text_end);
buffer.insert(ref text_end, "\n", 1);
}
public void add_filetransfer(FileTransferChatEntry entry) {
Gtk.TextIter iter;
text_buffer.get_end_iter(out iter);
Gtk.TextChildAnchor child_anchor = text_buffer.create_child_anchor(iter);
text_view.add_child_at_anchor(entry, child_anchor);
buffer.get_end_iter(out iter);
Gtk.TextChildAnchor child_anchor = buffer.create_child_anchor(iter);
add_child_at_anchor(entry, child_anchor);
entry.show();

text_buffer.get_end_iter(out iter);
text_buffer.insert(ref iter, "\n", 1);
buffer.get_end_iter(out iter);
buffer.insert(ref iter, "\n", 1);
}
}
}

0 comments on commit 53301aa

Please sign in to comment.