applying ctrl+keyup/down patch after cleaning and testing. Thanks rohan for patch
This commit is contained in:
parent
9918b17e2f
commit
4166022b3d
55
src/chat.py
55
src/chat.py
|
@ -61,6 +61,12 @@ class Chat:
|
|||
self.names = {} # what is printed in the tab (eg. user.name)
|
||||
self.childs = {}
|
||||
|
||||
#The following vars are used to keep history of user's messages
|
||||
self.sent_history = {}
|
||||
self.sent_history_pos = {}
|
||||
self.typing_new = {}
|
||||
self.orig_msg = {}
|
||||
|
||||
def update_tags(self):
|
||||
for jid in self.tagIn:
|
||||
self.tagIn[jid].set_property('foreground',
|
||||
|
@ -321,6 +327,12 @@ class Chat:
|
|||
|
||||
self.notebook.append_page_menu(child, tab_hbox, gtklabel)
|
||||
|
||||
#init new sent history for this conversation
|
||||
self.sent_history[jid] = []
|
||||
self.sent_history_pos[jid] = 0
|
||||
self.typing_new[jid] = True
|
||||
self.orig_msg[jid] = ''
|
||||
|
||||
self.show_title()
|
||||
|
||||
def on_conversation_textview_key_press_event(self, widget, event):
|
||||
|
@ -742,3 +754,46 @@ class Chat:
|
|||
self.plugin.systray.add_jid(jid, self.account)
|
||||
self.redraw_tab(jid)
|
||||
self.show_title()
|
||||
|
||||
def save_sent_message(self, jid, message):
|
||||
#save the message, so user can scroll though the list with key up/down
|
||||
size = len(self.sent_history[jid])
|
||||
#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 range(0, size - 1):
|
||||
self.sent_history[jid][i] = self.sent_history[jid][i+1]
|
||||
self.sent_history[jid][max_size - 1] = message
|
||||
else:
|
||||
self.sent_history[jid].append(message)
|
||||
|
||||
self.sent_history_pos[jid] = size + 1
|
||||
self.typing_new[jid] = True
|
||||
self.orig_msg[jid] = ''
|
||||
|
||||
def sent_messages_scroll(self, jid, direction, conv_buf):
|
||||
size = len(self.sent_history[jid])
|
||||
if direction == 'up':
|
||||
if self.sent_history_pos[jid] == 0:
|
||||
return
|
||||
|
||||
if self.typing_new[jid]:
|
||||
#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[jid] = conv_buf.get_text(start_iter, end_iter, 0)
|
||||
self.typing_new[jid] = False
|
||||
|
||||
self.sent_history_pos[jid] = self.sent_history_pos[jid] - 1
|
||||
conv_buf.set_text(self.sent_history[jid][self.sent_history_pos[jid]])
|
||||
|
||||
elif direction == 'down':
|
||||
if self.sent_history_pos[jid] >= size - 1:
|
||||
conv_buf.set_text(self.orig_msg[jid]);
|
||||
self.typing_new[jid] = True
|
||||
self.sent_history_pos[jid] = size
|
||||
return
|
||||
|
||||
self.sent_history_pos[jid] = self.sent_history_pos[jid] + 1
|
||||
conv_buf.set_text(self.sent_history[jid][self.sent_history_pos[jid]])
|
||||
|
|
|
@ -102,6 +102,7 @@ class Config:
|
|||
'restore_timeout': [opt_int, 60],
|
||||
'send_on_ctrl_enter': [opt_bool, False], # send on ctrl+enter
|
||||
'show_roster_on_startup': [opt_bool, True],
|
||||
'key_up_lines': [opt_int, 25], # how many lines to store for key up
|
||||
'version': [ None, '0.7' ],
|
||||
}
|
||||
|
||||
|
|
|
@ -615,6 +615,7 @@ class Interface:
|
|||
else:
|
||||
return False
|
||||
if pix.get_width() > 24 or pix.get_height() > 24:
|
||||
#FIXME: inform the user why you don't accept it
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
@ -296,6 +296,10 @@ class Groupchat_window(chat.Chat):
|
|||
room_jid = self.get_active_jid()
|
||||
conversation_textview = self.xmls[room_jid].get_widget(
|
||||
'conversation_textview')
|
||||
message_buffer = widget.get_buffer()
|
||||
start_iter, end_iter = message_buffer.get_bounds()
|
||||
message = message_buffer.get_text(start_iter, end_iter, False)
|
||||
|
||||
if event.keyval == gtk.keysyms.ISO_Left_Tab: # SHIFT + TAB
|
||||
if (event.state & gtk.gdk.CONTROL_MASK): # CTRL + SHIFT + TAB
|
||||
self.notebook.emit('key_press_event', event)
|
||||
|
@ -304,11 +308,9 @@ class Groupchat_window(chat.Chat):
|
|||
self.notebook.emit('key_press_event', event)
|
||||
else:
|
||||
list_nick = self.get_nick_list(room_jid)
|
||||
message_buffer = widget.get_buffer()
|
||||
start_iter = message_buffer.get_start_iter()
|
||||
cursor_position = message_buffer.get_insert()
|
||||
end_iter = message_buffer.get_iter_at_mark(cursor_position)
|
||||
text = message_buffer.get_text(start_iter, end_iter, 0)
|
||||
text = message_buffer.get_text(start_iter, end_iter, False)
|
||||
if not text or text.endswith(' '):
|
||||
return False
|
||||
splitted_text = text.split()
|
||||
|
@ -336,11 +338,8 @@ class Groupchat_window(chat.Chat):
|
|||
event.keyval == gtk.keysyms.KP_Enter: # ENTER
|
||||
if (event.state & gtk.gdk.SHIFT_MASK):
|
||||
return False
|
||||
message_buffer = widget.get_buffer()
|
||||
start_iter = message_buffer.get_start_iter()
|
||||
end_iter = message_buffer.get_end_iter()
|
||||
message = message_buffer.get_text(start_iter, end_iter, 0)
|
||||
if message != '' or message != '\n':
|
||||
self.save_sent_message(room_jid, message)
|
||||
if message == '/clear':
|
||||
self.on_clear(None, conversation_textview) # clear conversation
|
||||
self.on_clear(None, widget) # clear message textview too
|
||||
|
@ -349,6 +348,12 @@ class Groupchat_window(chat.Chat):
|
|||
message_buffer.set_text('', -1)
|
||||
widget.grab_focus()
|
||||
return True
|
||||
elif event.keyval == gtk.keysyms.Up:
|
||||
if event.state & gtk.gdk.CONTROL_MASK: #Ctrl+UP
|
||||
self.sent_messages_scroll(room_jid, 'up', widget.get_buffer())
|
||||
elif event.keyval == gtk.keysyms.Down:
|
||||
if event.state & gtk.gdk.CONTROL_MASK: #Ctrl+Down
|
||||
self.sent_messages_scroll(room_jid, 'down', widget.get_buffer())
|
||||
|
||||
def print_conversation(self, text, room_jid, contact = '', tim = None):
|
||||
"""Print a line in the conversation:
|
||||
|
|
|
@ -1224,7 +1224,7 @@
|
|||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="editable">True</property>
|
||||
<property name="visibility">True</property>
|
||||
<property name="visibility">False</property>
|
||||
<property name="max_length">0</property>
|
||||
<property name="text" translatable="yes"></property>
|
||||
<property name="has_frame">True</property>
|
||||
|
|
|
@ -193,11 +193,9 @@ class Tabbed_chat_window(chat.Chat):
|
|||
s += ' (' + user.status + ')'
|
||||
self.print_conversation(s, user.jid, 'status')
|
||||
|
||||
|
||||
#restore previous conversation
|
||||
self.restore_conversation(user.jid)
|
||||
|
||||
|
||||
#print queued messages
|
||||
if self.plugin.queues[self.account].has_key(user.jid):
|
||||
self.read_queue(user.jid)
|
||||
|
@ -208,6 +206,10 @@ class Tabbed_chat_window(chat.Chat):
|
|||
and printed in the conversation"""
|
||||
jid = self.get_active_jid()
|
||||
conversation_textview = self.xmls[jid].get_widget('conversation_textview')
|
||||
message_buffer = widget.get_buffer()
|
||||
start_iter, end_iter = message_buffer.get_bounds()
|
||||
message = message_buffer.get_text(start_iter, end_iter, False)
|
||||
|
||||
if event.keyval == gtk.keysyms.ISO_Left_Tab: # SHIFT + TAB
|
||||
if event.state & gtk.gdk.CONTROL_MASK: # CTRL + SHIFT + TAB
|
||||
self.notebook.emit('key_press_event', event)
|
||||
|
@ -235,11 +237,8 @@ class Tabbed_chat_window(chat.Chat):
|
|||
dialogs.Error_dialog(_("You're connection has been lost."), \
|
||||
_("Your message can't be sent until you reconnect.")).get_response()
|
||||
return True
|
||||
message_buffer = widget.get_buffer()
|
||||
start_iter = message_buffer.get_start_iter()
|
||||
end_iter = message_buffer.get_end_iter()
|
||||
message = message_buffer.get_text(start_iter, end_iter, 0)
|
||||
if message != '' or message != '\n':
|
||||
self.save_sent_message(jid, message)
|
||||
if message == '/clear':
|
||||
self.on_clear(None, conversation_textview) # clear conversation
|
||||
self.on_clear(None, widget) # clear message textview too
|
||||
|
@ -253,6 +252,12 @@ class Tabbed_chat_window(chat.Chat):
|
|||
message_buffer.set_text('', -1)
|
||||
self.print_conversation(message, jid, jid, encrypted = encrypted)
|
||||
return True
|
||||
elif event.keyval == gtk.keysyms.Up:
|
||||
if event.state & gtk.gdk.CONTROL_MASK: #Ctrl+UP
|
||||
self.sent_messages_scroll(jid, 'up', widget.get_buffer())
|
||||
elif event.keyval == gtk.keysyms.Down:
|
||||
if event.state & gtk.gdk.CONTROL_MASK: #Ctrl+Down
|
||||
self.sent_messages_scroll(jid, 'down', widget.get_buffer())
|
||||
|
||||
def on_contact_button_clicked(self, widget):
|
||||
jid = self.get_active_jid()
|
||||
|
@ -352,7 +357,7 @@ class Tabbed_chat_window(chat.Chat):
|
|||
size = size + 1
|
||||
|
||||
lines.reverse()
|
||||
|
||||
|
||||
for msg in lines:
|
||||
if msg[1] == 'sent':
|
||||
kind = 'outgoing'
|
||||
|
@ -369,3 +374,4 @@ class Tabbed_chat_window(chat.Chat):
|
|||
|
||||
if len(lines):
|
||||
self.print_empty_line(jid)
|
||||
|
||||
|
|
Loading…
Reference in New Issue