From 2d876923d93d78d55c660c12514574b55ebc500d Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Thu, 27 Jul 2006 10:54:12 +0000 Subject: [PATCH] move the draw og the focus out line to conversation_textview.py reset focus_out_end_iter_offset var when we clear the textview. Fixes #2175 --- src/chat_control.py | 2 +- src/conversation_textview.py | 68 ++++++++++++++++++++++++++++++++++++ src/groupchat_control.py | 65 ++-------------------------------- 3 files changed, 71 insertions(+), 64 deletions(-) diff --git a/src/chat_control.py b/src/chat_control.py index 1c67e0d77..0d5963dec 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -250,7 +250,7 @@ class ChatControlBase(MessageControl): if event.state & gtk.gdk.CONTROL_MASK: # CTRL + l|L: clear conv_textview if event.keyval == gtk.keysyms.l or event.keyval == gtk.keysyms.L: - self.conv_textview.tv.get_buffer().set_text('') + self.conv_textview.clear() return True # CTRL + v: Paste into msg_textview elif event.keyval == gtk.keysyms.v: diff --git a/src/conversation_textview.py b/src/conversation_textview.py index 90ff38b14..d4de054f1 100644 --- a/src/conversation_textview.py +++ b/src/conversation_textview.py @@ -28,6 +28,7 @@ import pango import gobject import time import sys +import os import tooltips import dialogs import locale @@ -132,6 +133,10 @@ class ConversationTextview: buffer.create_tag('focus-out-line', justification = gtk.JUSTIFY_CENTER) + self.allow_focus_out_line = True + # holds the iter's offset which points to the end of --- line + self.focus_out_end_iter_offset = None + self.line_tooltip = tooltips.BaseTooltip() def del_handlers(self): @@ -187,6 +192,68 @@ class ConversationTextview: self.tv.scroll_to_iter(end_iter, 0, False, 1, 1) return False # when called in an idle_add, just do it once + def show_focus_out_line(self): + if not self.allow_focus_out_line: + # if room did not receive focus-in from the last time we added + # --- line then do not readd + return + + print_focus_out_line = False + buffer = self.tv.get_buffer() + + if self.focus_out_end_iter_offset is None: + # this happens only first time we focus out on this room + print_focus_out_line = True + + else: + if self.focus_out_end_iter_offset != buffer.get_end_iter().\ + get_offset(): + # this means after last-focus something was printed + # (else end_iter's offset is the same as before) + # only then print ---- line (eg. we avoid printing many following + # ---- lines) + print_focus_out_line = True + + if print_focus_out_line and buffer.get_char_count() > 0: + buffer.begin_user_action() + + # remove previous focus out line if such focus out line exists + if self.focus_out_end_iter_offset is not None: + end_iter_for_previous_line = buffer.get_iter_at_offset( + self.focus_out_end_iter_offset) + begin_iter_for_previous_line = end_iter_for_previous_line.copy() + # img_char+1 (the '\n') + begin_iter_for_previous_line.backward_chars(2) + + # remove focus out line + buffer.delete(begin_iter_for_previous_line, + end_iter_for_previous_line) + + # add the new focus out line + # FIXME: Why is this loaded from disk everytime + path_to_file = os.path.join(gajim.DATA_DIR, 'pixmaps', 'muc_separator.png') + focus_out_line_pixbuf = gtk.gdk.pixbuf_new_from_file(path_to_file) + end_iter = buffer.get_end_iter() + buffer.insert(end_iter, '\n') + buffer.insert_pixbuf(end_iter, focus_out_line_pixbuf) + + end_iter = buffer.get_end_iter() + before_img_iter = end_iter.copy() + before_img_iter.backward_char() # one char back (an image also takes one char) + buffer.apply_tag_by_name('focus-out-line', before_img_iter, end_iter) + #FIXME: remove this workaround when bug is fixed + # c http://bugzilla.gnome.org/show_bug.cgi?id=318569 + + self.allow_focus_out_line = False + + # update the iter we hold to make comparison the next time + self.focus_out_end_iter_offset = buffer.get_end_iter().get_offset() + + buffer.end_user_action() + + # scroll to the end (via idle in case the scrollbar has appeared) + gobject.idle_add(self.scroll_to_end) + def show_line_tooltip(self): pointer = self.tv.get_pointer() x, y = self.tv.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, pointer[0], @@ -241,6 +308,7 @@ class ConversationTextview: buffer = self.tv.get_buffer() start, end = buffer.get_bounds() buffer.delete(start, end) + self.focus_out_end_iter_offset = None def visit_url_from_menuitem(self, widget, link): '''basically it filters out the widget instance''' diff --git a/src/groupchat_control.py b/src/groupchat_control.py index 4b599765e..fd8d20862 100644 --- a/src/groupchat_control.py +++ b/src/groupchat_control.py @@ -196,10 +196,6 @@ class GroupchatControl(ChatControlBase): self.tooltip = tooltips.GCTooltip() - self.allow_focus_out_line = True - # holds the iter's offset which points to the end of --- line - self.focus_out_end_iter_offset = None - # connect the menuitems to their respective functions xm = gtkgui_helpers.get_glade('gc_control_popup_menu.glade') @@ -332,7 +328,7 @@ class GroupchatControl(ChatControlBase): def _on_window_focus_in_event(self, widget, event): '''When window gets focus''' if self.parent_win.get_active_jid() == self.room_jid: - self.allow_focus_out_line = True + self.conv_textview.allow_focus_out_line = True def on_treeview_size_allocate(self, widget, allocation): '''The MUC treeview has resized. Move the hpaned in all tabs to match''' @@ -603,64 +599,7 @@ class GroupchatControl(ChatControlBase): # we have full focus (we are reading it!) return - if not self.allow_focus_out_line: - # if room did not receive focus-in from the last time we added - # --- line then do not readd - return - - print_focus_out_line = False - buffer = self.conv_textview.tv.get_buffer() - - if self.focus_out_end_iter_offset is None: - # this happens only first time we focus out on this room - print_focus_out_line = True - - else: - if self.focus_out_end_iter_offset != buffer.get_end_iter().get_offset(): - # this means after last-focus something was printed - # (else end_iter's offset is the same as before) - # only then print ---- line (eg. we avoid printing many following - # ---- lines) - print_focus_out_line = True - - if print_focus_out_line and buffer.get_char_count() > 0: - buffer.begin_user_action() - - # remove previous focus out line if such focus out line exists - if self.focus_out_end_iter_offset is not None: - end_iter_for_previous_line = buffer.get_iter_at_offset( - self.focus_out_end_iter_offset) - begin_iter_for_previous_line = end_iter_for_previous_line.copy() - begin_iter_for_previous_line.backward_chars(2) # img_char+1 (the '\n') - - # remove focus out line - buffer.delete(begin_iter_for_previous_line, - end_iter_for_previous_line) - - # add the new focus out line - # FIXME: Why is this loaded from disk everytime - path_to_file = os.path.join(gajim.DATA_DIR, 'pixmaps', 'muc_separator.png') - focus_out_line_pixbuf = gtk.gdk.pixbuf_new_from_file(path_to_file) - end_iter = buffer.get_end_iter() - buffer.insert(end_iter, '\n') - buffer.insert_pixbuf(end_iter, focus_out_line_pixbuf) - - end_iter = buffer.get_end_iter() - before_img_iter = end_iter.copy() - before_img_iter.backward_char() # one char back (an image also takes one char) - buffer.apply_tag_by_name('focus-out-line', before_img_iter, end_iter) - #FIXME: remove this workaround when bug is fixed - # c http://bugzilla.gnome.org/show_bug.cgi?id=318569 - - self.allow_focus_out_line = False - - # update the iter we hold to make comparison the next time - self.focus_out_end_iter_offset = buffer.get_end_iter().get_offset() - - buffer.end_user_action() - - # scroll to the end (via idle in case the scrollbar has appeared) - gobject.idle_add(self.conv_textview.scroll_to_end) + self.conv_textview.show_focus_out_line() def needs_visual_notification(self, text): '''checks text to see whether any of the words in (muc_highlight_words