[slava]Quoting the recieved messages with the keyboard shortcuts. Fixes #6822

This commit is contained in:
Denis Fomin 2011-03-10 13:55:15 +03:00
parent 5dc76a23e7
commit b74852014e
1 changed files with 101 additions and 80 deletions

View File

@ -90,6 +90,7 @@ if gajim.config.get('use_speller') and HAS_GTK_SPELL:
spell.detach() spell.detach()
del tv del tv
################################################################################ ################################################################################
class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
""" """
@ -105,6 +106,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
keycode_ins = keymap.get_entries_for_keyval(gtk.keysyms.Insert)[0][0] keycode_ins = keymap.get_entries_for_keyval(gtk.keysyms.Insert)[0][0]
except TypeError: except TypeError:
keycode_ins = 118 keycode_ins = 118
def make_href(self, match): def make_href(self, match):
url_color = gajim.config.get('urlmsgcolor') url_color = gajim.config.get('urlmsgcolor')
url = match.group() url = match.group()
@ -430,6 +432,8 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
# the following vars are used to keep history of user's messages # the following vars are used to keep history of user's messages
self.sent_history = [] self.sent_history = []
self.sent_history_pos = 0 self.sent_history_pos = 0
self.received_history = []
self.received_history_pos = 0
self.orig_msg = None self.orig_msg = None
# Emoticons menu # Emoticons menu
@ -670,6 +674,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
def show_emoticons_menu(self): def show_emoticons_menu(self):
if not gajim.config.get('emoticons_theme'): if not gajim.config.get('emoticons_theme'):
return return
def set_emoticons_menu_position(w, msg_tv=self.msg_textview): def set_emoticons_menu_position(w, msg_tv=self.msg_textview):
window = msg_tv.get_window(gtk.TEXT_WINDOW_WIDGET) window = msg_tv.get_window(gtk.TEXT_WINDOW_WIDGET)
# get the window position # get the window position
@ -758,11 +763,17 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
event.time = 0 # assign current time event.time = 0 # assign current time
if event.keyval == gtk.keysyms.Up: if event.keyval == gtk.keysyms.Up:
if event.state & gtk.gdk.CONTROL_MASK: # Ctrl+UP if event.state == gtk.gdk.CONTROL_MASK: # Ctrl+UP
self.sent_messages_scroll('up', widget.get_buffer()) self.scroll_messages('up', message_buffer, 'sent')
# Ctrl+Shift+UP
elif event.state == (gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK):
self.scroll_messages('up', message_buffer, 'received')
elif event.keyval == gtk.keysyms.Down: elif event.keyval == gtk.keysyms.Down:
if event.state & gtk.gdk.CONTROL_MASK: # Ctrl+Down if event.state == gtk.gdk.CONTROL_MASK: # Ctrl+Down
self.sent_messages_scroll('down', widget.get_buffer()) self.scroll_messages('down', message_buffer, 'sent')
# Ctrl+Shift+Down
elif event.state == (gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK):
self.scroll_messages('down', message_buffer, 'received')
elif event.keyval == gtk.keysyms.Return or \ elif event.keyval == gtk.keysyms.Return or \
event.keyval == gtk.keysyms.KP_Enter: # ENTER event.keyval == gtk.keysyms.KP_Enter: # ENTER
# NOTE: SHIFT + ENTER is not needed to be emulated as it is not # NOTE: SHIFT + ENTER is not needed to be emulated as it is not
@ -850,8 +861,8 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
label=label, label=label,
callback=callback, callback_args=callback_args) callback=callback, callback_args=callback_args)
# Record message history # Record the history of sent messages
self.save_sent_message(message) self.save_message(message, 'sent')
# Be sure to send user nickname only once according to JEP-0172 # Be sure to send user nickname only once according to JEP-0172
self.user_nick = None self.user_nick = None
@ -860,21 +871,22 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
message_buffer = self.msg_textview.get_buffer() message_buffer = self.msg_textview.get_buffer()
message_buffer.set_text('') # clear message buffer (and tv of course) message_buffer.set_text('') # clear message buffer (and tv of course)
def save_sent_message(self, message): def save_message(self, message, msg_type):
# save the message, so user can scroll though the list with key up/down # save the message, so user can scroll though the list with key up/down
if msg_type == 'sent':
history = self.sent_history
else:
history = self.received_history
size = len(self.sent_history) size = len(self.sent_history)
# we don't want size of the buffer to grow indefinately # we don't want size of the buffer to grow indefinately
max_size = gajim.config.get('key_up_lines') max_size = gajim.config.get('key_up_lines')
if size >= max_size: for i in xrange(size - max_size + 1):
for i in xrange(0, size - 1): history.pop(0)
self.sent_history[i] = self.sent_history[i + 1] history.append(message)
self.sent_history[max_size - 1] = message if msg_type == 'sent':
# self.sent_history_pos has changed if we browsed sent_history, self.sent_history_pos = len(history)
# reset to real value
self.sent_history_pos = max_size
else: else:
self.sent_history.append(message) self.received_history_pos = len(history)
self.sent_history_pos = size + 1
self.orig_msg = None self.orig_msg = None
def print_conversation_line(self, text, kind, name, tim, def print_conversation_line(self, text, kind, name, tim,
@ -910,6 +922,10 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
# other_tags_for_text == ['marked'] --> highlighted gc message # other_tags_for_text == ['marked'] --> highlighted gc message
gajim.last_message_time[self.account][full_jid] = time.time() gajim.last_message_time[self.account][full_jid] = time.time()
if kind in ('incoming', 'incoming_queue'):
# Record the history of received messages
self.save_message(text, 'received')
if kind in ('incoming', 'incoming_queue', 'error'): if kind in ('incoming', 'incoming_queue', 'error'):
gc_message = False gc_message = False
if self.type_id == message_control.TYPE_GC: if self.type_id == message_control.TYPE_GC:
@ -1050,7 +1066,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
font_dialog.fontsel) font_dialog.fontsel)
font_dialog.show_all() font_dialog.show_all()
def on_actions_button_clicked(self, widget): def on_actions_button_clicked(self, widget):
""" """
Popup action menu Popup action menu
@ -1109,8 +1124,8 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
prim_text = _('Really send file?') prim_text = _('Really send file?')
sec_text = _('If you send a file to %s, he/she will know your ' sec_text = _('If you send a file to %s, he/she will know your '
'real Jabber ID.') % gc_contact.name 'real Jabber ID.') % gc_contact.name
dialog = dialogs.NonModalConfirmationDialog(prim_text, sec_text, dialog = dialogs.NonModalConfirmationDialog(prim_text,
on_response_ok = (_on_ok, gc_contact)) sec_text, on_response_ok=(_on_ok, gc_contact))
dialog.popup() dialog.popup()
return return
_on_ok(gc_contact) _on_ok(gc_contact)
@ -1148,7 +1163,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
# There were events to remove # There were events to remove
self.redraw_after_event_removed(jid) self.redraw_after_event_removed(jid)
def bring_scroll_to_end(self, textview, diff_y=0): def bring_scroll_to_end(self, textview, diff_y=0):
""" """
Scroll to the end of textview if end is not visible Scroll to the end of textview if end is not visible
@ -1298,31 +1312,39 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
gajim.interface.roster.draw_contact(jid, self.account) gajim.interface.roster.draw_contact(jid, self.account)
gajim.interface.roster.show_title() gajim.interface.roster.show_title()
def sent_messages_scroll(self, direction, conv_buf): def scroll_messages(self, direction, msg_buf, msg_type):
size = len(self.sent_history) if msg_type == 'sent':
history = self.sent_history
pos = self.sent_history_pos
self.received_history_pos = len(self.received_history)
else:
history = self.received_history
pos = self.received_history_pos
self.sent_history_pos = len(self.sent_history)
size = len(history)
if self.orig_msg is None: if self.orig_msg is None:
# user was typing something and then went into history, so save # user was typing something and then went into history, so save
# whatever is already typed # whatever is already typed
start_iter = conv_buf.get_start_iter() start_iter = msg_buf.get_start_iter()
end_iter = conv_buf.get_end_iter() end_iter = msg_buf.get_end_iter()
self.orig_msg = conv_buf.get_text(start_iter, end_iter, 0).decode( self.orig_msg = msg_buf.get_text(start_iter, end_iter, 0).decode(
'utf-8') 'utf-8')
if direction == 'up': pos += -1 if direction == 'up' else +1
if self.sent_history_pos == 0: if pos == -1:
return return
self.sent_history_pos = self.sent_history_pos - 1 if pos >= size:
self.smooth = False pos = size
conv_buf.set_text(self.sent_history[self.sent_history_pos]) message = self.orig_msg
elif direction == 'down':
if self.sent_history_pos >= size - 1:
conv_buf.set_text(self.orig_msg)
self.orig_msg = None self.orig_msg = None
self.sent_history_pos = size else:
return message = history[pos]
if msg_type == 'sent':
self.sent_history_pos = self.sent_history_pos + 1 self.sent_history_pos = pos
self.smooth = False else:
conv_buf.set_text(self.sent_history[self.sent_history_pos]) self.received_history_pos = pos
if self.orig_msg is not None:
message = '> %s\n' % message.replace('\n', '\n> ')
msg_buf.set_text(message)
def lighten_color(self, color): def lighten_color(self, color):
p = 0.4 p = 0.4
@ -1366,6 +1388,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self.no_autonegotiation = False self.no_autonegotiation = False
# FIXME: Set sensitivity for toolbar # FIXME: Set sensitivity for toolbar
################################################################################ ################################################################################
class ChatControl(ChatControlBase): class ChatControl(ChatControlBase):
""" """
@ -1757,7 +1780,6 @@ class ChatControl(ChatControlBase):
if self.video_sid and sid in (self.video_sid, None): if self.video_sid and sid in (self.video_sid, None):
self.close_jingle_content('video') self.close_jingle_content('video')
def _set_jingle_state(self, jingle_type, state, sid=None, reason=None): def _set_jingle_state(self, jingle_type, state, sid=None, reason=None):
if jingle_type not in ('audio', 'video'): if jingle_type not in ('audio', 'video'):
return return
@ -1818,7 +1840,6 @@ class ChatControl(ChatControlBase):
# Save volume to config # Save volume to config
gajim.config.set('audio_input_volume', value) gajim.config.set('audio_input_volume', value)
def on_sound_hscale_value_changed(self, widget, value): def on_sound_hscale_value_changed(self, widget, value):
self._get_audio_content().set_out_volume(value / 100) self._get_audio_content().set_out_volume(value / 100)
# Save volume to config # Save volume to config
@ -2448,7 +2469,6 @@ class ChatControl(ChatControlBase):
else: # active or not chatstate, get color from gtk else: # active or not chatstate, get color from gtk
color = self.parent_win.notebook.style.fg[gtk.STATE_ACTIVE] color = self.parent_win.notebook.style.fg[gtk.STATE_ACTIVE]
name = self.contact.get_shown_name() name = self.contact.get_shown_name()
if self.resource: if self.resource:
name += '/' + self.resource name += '/' + self.resource
@ -2647,6 +2667,7 @@ class ChatControl(ChatControlBase):
if time.time() - gajim.last_message_time[self.account]\ if time.time() - gajim.last_message_time[self.account]\
[self.get_full_jid()] < 2: [self.get_full_jid()] < 2:
# 2 seconds # 2 seconds
def on_ok(): def on_ok():
on_yes(self) on_yes(self)