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