[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

View file

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