better keypress handling

This commit is contained in:
Yann Leboulanger 2008-12-05 14:12:31 +00:00
parent d8c9aa0c5a
commit 28bc50316e
2 changed files with 32 additions and 25 deletions

View File

@ -429,9 +429,12 @@ class ChatControlBase(MessageControl):
def _conv_textview_key_press_event(self, widget, event):
if gtk.gtk_version < (2, 12, 0):
return
if event.state & (gtk.gdk.SHIFT_MASK | gtk.gdk.CONTROL_MASK):
if event.state & gtk.gdk.CONTROL_MASK and event.keyval == gtk.keysyms.c \
or event.state & gtk.gdk.SHIFT_MASK and event.keyval in (
gtk.keysyms.Page_Down, gtk.keysyms.Page_Up):
return False
self.parent_win.notebook.emit('key_press_event', event)
return True
def show_emoticons_menu(self):
if not gajim.config.get('emoticons_theme'):
@ -467,6 +470,7 @@ class ChatControlBase(MessageControl):
set_emoticons_menu_position, 1, 0)
def _on_message_textview_key_press_event(self, widget, event):
# Ctrl [+ Shift] + Tab are not forwarded to notebook. We handle it here
if self.widget_name == 'muc_child_vbox':
if event.keyval not in (gtk.keysyms.ISO_Left_Tab, gtk.keysyms.Tab):
self.last_key_tabs = False
@ -485,15 +489,6 @@ class ChatControlBase(MessageControl):
if event.keyval == gtk.keysyms.Tab: # CTRL + TAB
self.parent_win.move_to_next_unread_tab(True)
return True
# CTRL + PAGE_[UP|DOWN]: send to parent notebook
elif event.keyval == gtk.keysyms.Page_Down or \
event.keyval == gtk.keysyms.Page_Up:
self.parent_win.notebook.emit('key_press_event', event)
return True
# we pressed a control key or ctrl+sth: we don't block
# the event in order to let ctrl+c (copy text) and
# others do their default work
self.conv_textview.tv.emit('key_press_event', event)
return False
def _on_message_textview_mykeypress_event(self, widget, event_keyval,

View File

@ -99,7 +99,7 @@ class MessageWindow(object):
self.handlers[id_] = self.window
keys=['<Control>f', '<Control>g', '<Control>h', '<Control>i',
'<Control>l', '<Control>L', '<Control>n', '<Control>u', '<Control>v',
'<Control>l', '<Control>L', '<Control>n', '<Control>u',
'<Control>b', '<Control><Shift>Tab', '<Control>Tab', '<Control>F4',
'<Control>w', '<Control>Page_Up', '<Control>Page_Down', '<Alt>Right',
'<Alt>Left', '<Alt>a', '<Alt>c', '<Alt>m', '<Alt>t', 'Escape'] + \
@ -333,16 +333,6 @@ class MessageWindow(object):
control._on_change_nick_menuitem_activate(None)
elif keyval == gtk.keysyms.u: # CTRL + u: emacs style clear line
control.clear(control.msg_textview)
elif keyval == gtk.keysyms.v: # CTRL + v: Paste into msg_textview
if not control.msg_textview.is_focus():
control.msg_textview.grab_focus()
# Paste into the msg textview
event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
event.window = self.window.window
event.time = int(time.time())
event.state = gtk.gdk.CONTROL_MASK
event.keyval = gtk.keysyms.v
control.msg_textview.emit('key_press_event', event)
elif control.type_id == message_control.TYPE_GC and \
keyval == gtk.keysyms.b: # CTRL + b
control._on_bookmark_room_menuitem_activate(None)
@ -397,6 +387,7 @@ class MessageWindow(object):
elif keyval == gtk.keysyms.Escape and \
gajim.config.get('escape_key_closes'): # Escape
self.remove_tab(control, self.CLOSE_ESC)
return True
def _on_close_button_clicked(self, button, control):
'''When close button is pressed: close a tab'''
@ -734,15 +725,36 @@ class MessageWindow(object):
control.msg_textview.grab_focus()
def _on_notebook_key_press(self, widget, event):
# Ctrl+PageUP / DOWN has to be handled by notebook
if (event.state & gtk.gdk.CONTROL_MASK and
event.keyval in (gtk.keysyms.Page_Down, gtk.keysyms.Page_Up)):
return False
# when tab itself is selected, make sure <- and -> are allowed for navigating between tabs
if event.keyval in (gtk.keysyms.Left, gtk.keysyms.Right):
return False
control = self.get_active_control()
if event.state & gtk.gdk.SHIFT_MASK:
# CTRL + SHIFT + TAB
if event.state & gtk.gdk.CONTROL_MASK and \
event.keyval == gtk.keysyms.ISO_Left_Tab:
self.move_to_next_unread_tab(False)
return True
# SHIFT + PAGE_[UP|DOWN]: send to conv_textview
elif event.keyval in (gtk.keysyms.Page_Down, gtk.keysyms.Page_Up):
control.conv_textview.tv.emit('key_press_event', event)
return True
elif event.state & gtk.gdk.CONTROL_MASK:
if event.keyval == gtk.keysyms.Tab: # CTRL + TAB
self.move_to_next_unread_tab(True)
return True
# Ctrl+PageUP / DOWN has to be handled by notebook
elif event.keyval == gtk.keysyms.Page_Down:
self.move_to_next_unread_tab(True)
return True
elif event.keyval == gtk.keysyms.Page_Up:
self.move_to_next_unread_tab(False)
return True
elif event.keyval == gtk.keysyms.Control_L:
return True
if isinstance(control, ChatControlBase):
# we forwarded it to message textview
control.msg_textview.emit('key_press_event', event)