Commit df650dd6 authored by Kai Willadsen's avatar Kai Willadsen

filediff: Simplify our key press/release event handling

parent f2efad20
...@@ -108,7 +108,8 @@ ...@@ -108,7 +108,8 @@
<object class="GtkVBox" id="filediff"> <object class="GtkVBox" id="filediff">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<signal name="key-press-event" handler="on_key_press_event" swapped="no"/> <signal name="key-press-event" handler="on_key_event" swapped="no"/>
<signal name="key-release-event" handler="on_key_event" swapped="no"/>
<child> <child>
<object class="GtkGrid" id="grid"> <object class="GtkGrid" id="grid">
<property name="visible">True</property> <property name="visible">True</property>
...@@ -295,8 +296,8 @@ ...@@ -295,8 +296,8 @@
<property name="can_focus">True</property> <property name="can_focus">True</property>
<signal name="button-press-event" handler="on_textview_button_press_event" swapped="no"/> <signal name="button-press-event" handler="on_textview_button_press_event" swapped="no"/>
<signal name="draw" handler="on_textview_draw" swapped="no"/> <signal name="draw" handler="on_textview_draw" swapped="no"/>
<signal name="key-release-event" handler="on_key_release_event" swapped="no"/> <signal name="key-release-event" handler="on_key_event" swapped="no"/>
<signal name="key-press-event" handler="on_key_press_event" swapped="no"/> <signal name="key-press-event" handler="on_key_event" swapped="no"/>
<signal name="focus-in-event" handler="on_textview_focus_in_event" swapped="no"/> <signal name="focus-in-event" handler="on_textview_focus_in_event" swapped="no"/>
<signal name="focus-out-event" handler="on_textview_focus_out_event" swapped="no"/> <signal name="focus-out-event" handler="on_textview_focus_out_event" swapped="no"/>
<signal name="popup-menu" handler="on_textview_popup_menu" swapped="no"/> <signal name="popup-menu" handler="on_textview_popup_menu" swapped="no"/>
...@@ -381,8 +382,8 @@ ...@@ -381,8 +382,8 @@
<property name="can_focus">True</property> <property name="can_focus">True</property>
<signal name="button-press-event" handler="on_textview_button_press_event" swapped="no"/> <signal name="button-press-event" handler="on_textview_button_press_event" swapped="no"/>
<signal name="draw" handler="on_textview_draw" swapped="no"/> <signal name="draw" handler="on_textview_draw" swapped="no"/>
<signal name="key-release-event" handler="on_key_release_event" swapped="no"/> <signal name="key-release-event" handler="on_key_event" swapped="no"/>
<signal name="key-press-event" handler="on_key_press_event" swapped="no"/> <signal name="key-press-event" handler="on_key_event" swapped="no"/>
<signal name="focus-in-event" handler="on_textview_focus_in_event" swapped="no"/> <signal name="focus-in-event" handler="on_textview_focus_in_event" swapped="no"/>
<signal name="focus-out-event" handler="on_textview_focus_out_event" swapped="no"/> <signal name="focus-out-event" handler="on_textview_focus_out_event" swapped="no"/>
<signal name="popup-menu" handler="on_textview_popup_menu" swapped="no"/> <signal name="popup-menu" handler="on_textview_popup_menu" swapped="no"/>
...@@ -428,8 +429,8 @@ ...@@ -428,8 +429,8 @@
<property name="can_focus">True</property> <property name="can_focus">True</property>
<signal name="button-press-event" handler="on_textview_button_press_event" swapped="no"/> <signal name="button-press-event" handler="on_textview_button_press_event" swapped="no"/>
<signal name="draw" handler="on_textview_draw" swapped="no"/> <signal name="draw" handler="on_textview_draw" swapped="no"/>
<signal name="key-release-event" handler="on_key_release_event" swapped="no"/> <signal name="key-release-event" handler="on_key_event" swapped="no"/>
<signal name="key-press-event" handler="on_key_press_event" swapped="no"/> <signal name="key-press-event" handler="on_key_event" swapped="no"/>
<signal name="focus-in-event" handler="on_textview_focus_in_event" swapped="no"/> <signal name="focus-in-event" handler="on_textview_focus_in_event" swapped="no"/>
<signal name="focus-out-event" handler="on_textview_focus_out_event" swapped="no"/> <signal name="focus-out-event" handler="on_textview_focus_out_event" swapped="no"/>
<signal name="popup-menu" handler="on_textview_popup_menu" swapped="no"/> <signal name="popup-menu" handler="on_textview_popup_menu" swapped="no"/>
......
...@@ -393,6 +393,18 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component): ...@@ -393,6 +393,18 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
self.emit("action-mode-changed", mode) self.emit("action-mode-changed", mode)
keymask = property(get_keymask, set_keymask) keymask = property(get_keymask, set_keymask)
def on_key_event(self, object, event):
keymap = Gdk.Keymap.get_default()
ok, keyval, group, lvl, consumed = keymap.translate_keyboard_state(
event.hardware_keycode, 0, event.group)
mod_key = self.keylookup.get(keyval, 0)
if event.type == Gdk.EventType.KEY_PRESS:
self.keymask |= mod_key
if event.keyval == Gdk.KEY_Escape:
self.findbar.hide()
elif event.type == Gdk.EventType.KEY_RELEASE:
self.keymask &= ~mod_key
def on_style_set(self, widget, prev_style): def on_style_set(self, widget, prev_style):
style = widget.get_style() style = widget.get_style()
...@@ -844,24 +856,6 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component): ...@@ -844,24 +856,6 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
if key == 'font': if key == 'font':
self.load_font() self.load_font()
def on_key_press_event(self, object, event):
keymap = Gdk.Keymap.get_default()
ok, keyval, group, lvl, consumed = keymap.translate_keyboard_state(
event.hardware_keycode, 0, event.group)
mod_key = self.keylookup.get(keyval, 0)
if self.keymask | mod_key != self.keymask:
self.keymask |= mod_key
elif event.keyval == Gdk.KEY_Escape:
self.findbar.hide()
def on_key_release_event(self, object, event):
keymap = Gdk.Keymap.get_default()
ok, keyval, group, level, consumed = keymap.translate_keyboard_state(
event.hardware_keycode, 0, event.group)
mod_key = self.keylookup.get(keyval, 0)
if self.keymask & ~mod_key != self.keymask:
self.keymask &= ~mod_key
def check_save_modified(self, label=None): def check_save_modified(self, label=None):
response = Gtk.ResponseType.OK response = Gtk.ResponseType.OK
modified = [b.data.modified for b in self.textbuffer] modified = [b.data.modified for b in self.textbuffer]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment