use accel func for all key in chat controls. Fixes #1503
This commit is contained in:
parent
150d109434
commit
4e52e954d0
|
@ -159,9 +159,6 @@ class ChatControlBase(MessageControl):
|
|||
id = widget.connect('clicked', self.on_emoticons_button_clicked)
|
||||
self.handlers[id] = widget
|
||||
|
||||
id = self.widget.connect('key_press_event', self._on_keypress_event)
|
||||
self.handlers[id] = self.widget
|
||||
|
||||
# Create banner and connect signals
|
||||
widget = self.xml.get_widget('banner_eventbox')
|
||||
widget.set_property('height-request', gajim.config.get('chat_avatar_height'))
|
||||
|
@ -430,73 +427,39 @@ class ChatControlBase(MessageControl):
|
|||
return False
|
||||
self.parent_win.notebook.emit('key_press_event', event)
|
||||
|
||||
def _on_keypress_event(self, widget, event):
|
||||
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.clear()
|
||||
return True
|
||||
# CTRL + v: Paste into msg_textview
|
||||
elif event.keyval == gtk.keysyms.v:
|
||||
if not self.msg_textview.is_focus():
|
||||
self.msg_textview.grab_focus()
|
||||
# Paste into the msg textview
|
||||
self.msg_textview.emit('key_press_event', event)
|
||||
# CTRL + u: emacs style clear line
|
||||
elif event.keyval == gtk.keysyms.u:
|
||||
self.clear(self.msg_textview) # clear message textview too
|
||||
elif event.keyval == gtk.keysyms.ISO_Left_Tab: # CTRL + SHIFT + TAB
|
||||
self.parent_win.move_to_next_unread_tab(False)
|
||||
return True
|
||||
elif 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
|
||||
|
||||
elif event.keyval == gtk.keysyms.m and \
|
||||
(event.state & gtk.gdk.MOD1_MASK): # alt + m opens emoticons menu
|
||||
if gajim.config.get('emoticons_theme'):
|
||||
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)
|
||||
# get the window position
|
||||
origin = window.get_origin()
|
||||
size = window.get_size()
|
||||
buf = msg_tv.get_buffer()
|
||||
# get the cursor position
|
||||
cursor = msg_tv.get_iter_location(buf.get_iter_at_mark(
|
||||
buf.get_insert()))
|
||||
cursor = msg_tv.buffer_to_window_coords(gtk.TEXT_WINDOW_TEXT,
|
||||
cursor.x, cursor.y)
|
||||
x = origin[0] + cursor[0]
|
||||
y = origin[1] + size[1]
|
||||
menu_width, menu_height = \
|
||||
gajim.interface.emoticons_menu.size_request()
|
||||
#FIXME: get_line_count is not so good
|
||||
#get the iter of cursor, then tv.get_line_yrange
|
||||
# so we know in which y we are typing (not how many lines we have
|
||||
# then go show just above the current cursor line for up
|
||||
# or just below the current cursor line for down
|
||||
#TEST with having 3 lines and writing in the 2nd
|
||||
if y + menu_height > gtk.gdk.screen_height():
|
||||
# move menu just above cursor
|
||||
y -= menu_height +\
|
||||
(msg_tv.allocation.height / buf.get_line_count())
|
||||
#else: # move menu just below cursor
|
||||
# y -= (msg_tv.allocation.height / buf.get_line_count())
|
||||
return (x, y, True) # push_in True
|
||||
gajim.interface.emoticon_menuitem_clicked = self.append_emoticon
|
||||
gajim.interface.emoticons_menu.popup(None, None,
|
||||
set_emoticons_menu_position, 1, 0)
|
||||
|
||||
elif event.keyval == gtk.keysyms.a and \
|
||||
(event.state & gtk.gdk.MOD1_MASK): # alt + a opens actions menu
|
||||
self.on_actions_button_clicked(self.actions_button)
|
||||
return False
|
||||
def show_emoticons_menu(self):
|
||||
if not gajim.config.get('emoticons_theme'):
|
||||
return
|
||||
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)
|
||||
# get the window position
|
||||
origin = window.get_origin()
|
||||
size = window.get_size()
|
||||
buf = msg_tv.get_buffer()
|
||||
# get the cursor position
|
||||
cursor = msg_tv.get_iter_location(buf.get_iter_at_mark(
|
||||
buf.get_insert()))
|
||||
cursor = msg_tv.buffer_to_window_coords(gtk.TEXT_WINDOW_TEXT,
|
||||
cursor.x, cursor.y)
|
||||
x = origin[0] + cursor[0]
|
||||
y = origin[1] + size[1]
|
||||
menu_width, menu_height = gajim.interface.emoticons_menu.size_request()
|
||||
#FIXME: get_line_count is not so good
|
||||
#get the iter of cursor, then tv.get_line_yrange
|
||||
# so we know in which y we are typing (not how many lines we have
|
||||
# then go show just above the current cursor line for up
|
||||
# or just below the current cursor line for down
|
||||
#TEST with having 3 lines and writing in the 2nd
|
||||
if y + menu_height > gtk.gdk.screen_height():
|
||||
# move menu just above cursor
|
||||
y -= menu_height + (msg_tv.allocation.height / buf.get_line_count())
|
||||
#else: # move menu just below cursor
|
||||
# y -= (msg_tv.allocation.height / buf.get_line_count())
|
||||
return (x, y, True) # push_in True
|
||||
gajim.interface.emoticon_menuitem_clicked = self.append_emoticon
|
||||
gajim.interface.emoticons_menu.popup(None, None,
|
||||
set_emoticons_menu_position, 1, 0)
|
||||
|
||||
def _on_message_textview_key_press_event(self, widget, event):
|
||||
if self.widget_name == 'muc_child_vbox':
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
import gtk
|
||||
import gobject
|
||||
import time
|
||||
|
||||
import common
|
||||
import gtkgui_helpers
|
||||
|
@ -90,12 +91,12 @@ class MessageWindow(object):
|
|||
id = self.window.connect('focus-in-event', self._on_window_focus)
|
||||
self.handlers[id] = self.window
|
||||
|
||||
keys=['<Control>f', '<Control>g', '<Control>h', '<Control>i',
|
||||
'<Control>n', '<Control>t', '<Control>b',
|
||||
'<Control><Shift>Tab', '<Control>Tab',
|
||||
'<Control>F4', '<Control>w', '<Alt>Right',
|
||||
'<Alt>Left', '<Alt>c', 'Escape'] +\
|
||||
['<Alt>'+str(i) for i in xrange(10)]
|
||||
keys=['<Control>f', '<Control>g', '<Control>h', '<Control>i',
|
||||
'<Control>l', '<Control>L', '<Control>n', '<Control>t', '<Control>u',
|
||||
'<Control>v', '<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', 'Escape'] + \
|
||||
['<Alt>'+str(i) for i in xrange(10)]
|
||||
accel_group = gtk.AccelGroup()
|
||||
for key in keys:
|
||||
keyval, mod = gtk.accelerator_parse(key)
|
||||
|
@ -311,25 +312,39 @@ class MessageWindow(object):
|
|||
|
||||
# CTRL mask
|
||||
if modifier & gtk.gdk.CONTROL_MASK:
|
||||
if keyval == gtk.keysyms.h:
|
||||
if keyval == gtk.keysyms.h: # CTRL + h
|
||||
control._on_history_menuitem_activate()
|
||||
elif control.type_id == message_control.TYPE_CHAT and \
|
||||
keyval == gtk.keysyms.f:
|
||||
keyval == gtk.keysyms.f: # CTRL + f
|
||||
control._on_send_file_menuitem_activate(None)
|
||||
elif control.type_id == message_control.TYPE_CHAT and \
|
||||
keyval == gtk.keysyms.g:
|
||||
keyval == gtk.keysyms.g: # CTRL + g
|
||||
control._on_convert_to_gc_menuitem_activate(None)
|
||||
elif control.type_id == message_control.TYPE_CHAT and \
|
||||
keyval == gtk.keysyms.i:
|
||||
keyval == gtk.keysyms.i: # CTRL + i
|
||||
control._on_contact_information_menuitem_activate(None)
|
||||
elif keyval == gtk.keysyms.l or keyval == gtk.keysyms.L: # CTRL + l|L
|
||||
control.conv_textview.clear()
|
||||
elif control.type_id == message_control.TYPE_GC and \
|
||||
keyval == gtk.keysyms.n:
|
||||
keyval == gtk.keysyms.n: # CTRL + n
|
||||
control._on_change_nick_menuitem_activate(None)
|
||||
elif control.type_id == message_control.TYPE_GC and \
|
||||
keyval == gtk.keysyms.t:
|
||||
keyval == gtk.keysyms.t: # CTRL + t
|
||||
control._on_change_subject_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:
|
||||
keyval == gtk.keysyms.b: # CTRL + b
|
||||
control._on_bookmark_room_menuitem_activate(None)
|
||||
# Tab switch bindings
|
||||
elif keyval == gtk.keysyms.ISO_Left_Tab: # CTRL + SHIFT + TAB
|
||||
|
@ -338,12 +353,21 @@ class MessageWindow(object):
|
|||
self.move_to_next_unread_tab(True)
|
||||
elif keyval == gtk.keysyms.F4: # CTRL + F4
|
||||
self.remove_tab(control, self.CLOSE_CTRL_KEY)
|
||||
elif keyval == gtk.keysyms.w: # CTRL + W
|
||||
# CTRL + W removes latest word before sursor when User uses emacs
|
||||
elif keyval == gtk.keysyms.w: # CTRL + w
|
||||
# CTRL + w removes latest word before sursor when User uses emacs
|
||||
# theme
|
||||
if not gtk.settings_get_default().get_property(
|
||||
'gtk-key-theme-name') == 'Emacs':
|
||||
self.remove_tab(control, self.CLOSE_CTRL_KEY)
|
||||
elif keyval in (gtk.keysyms.Page_Up, gtk.keysyms.Page_Down):
|
||||
# CTRL + PageUp | PageDown
|
||||
# Create event and send it to notebook
|
||||
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 = int(keyval)
|
||||
self.notebook.emit('key_press_event', event)
|
||||
|
||||
# MOD1 (ALT) mask
|
||||
elif modifier & gtk.gdk.MOD1_MASK:
|
||||
|
@ -362,6 +386,10 @@ class MessageWindow(object):
|
|||
self.notebook.set_current_page(st.index(chr(keyval)))
|
||||
elif keyval == gtk.keysyms.c: # ALT + C toggles chat buttons
|
||||
control.chat_buttons_set_visible(not control.hide_chat_buttons)
|
||||
elif keyval == gtk.keysyms.m: # ALT + M show emoticons menu
|
||||
control.show_emoticons_menu()
|
||||
elif keyval == gtk.keysyms.a: # ALT + A show actions menu
|
||||
control.on_actions_button_clicked(control.actions_button)
|
||||
# Close tab bindings
|
||||
elif keyval == gtk.keysyms.Escape and \
|
||||
gajim.config.get('escape_key_closes'): # Escape
|
||||
|
|
Loading…
Reference in New Issue