-
-
Save benwaffle/89f77d35d741b0771a35ca50b609680d to your computer and use it in GitHub Desktop.
This sample code permits to make application-wide keyboard shortcuts using AccelGroup and Action Signals in Vala.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Signal (action = true)] | |
private signal void change_chat_up (); | |
[Signal (action = true)] | |
private signal void change_chat_down (); | |
public MainWindow () { | |
this.init_keyboard_shortcuts (); | |
} | |
private void init_keyboard_shortcuts () { | |
Gtk.AccelGroup accel_group = new Gtk.AccelGroup (); | |
this.add_accel_group (accel_group); | |
/** | |
* Keyboard shortcut for switching to previous/next contact's chatview. | |
* FIXME: Ctrl+Up | Ctrl+Down doesn't call these signals. | |
**/ | |
this.change_chat_up.connect (() => { | |
var index = this.selected_row.get_index (); | |
if (index == 0) { return; } | |
var prev_row = this.friendlist.get_row_at_index (index - 1); | |
this.friendlist.select_row (prev_row); | |
}); | |
this.change_chat_down.connect (() => { | |
var index = this.selected_row.get_index (); | |
if (index == 0) { return; } | |
var next_row = this.friendlist.get_row_at_index (index + 1); | |
this.friendlist.select_row (next_row); | |
}); | |
/** | |
* Shortcut for Ctrl+Up: Change the chat view to the previous one. | |
**/ | |
this.add_accelerator ("change-chat-up", accel_group, Gdk.keyval_from_name("Up"), | |
Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE); | |
/** | |
* Shortcut for Ctrl+Down: Change the chat view to the next one. | |
**/ | |
this.add_accelerator ("change-chat-down", accel_group, Gdk.keyval_from_name("Down"), | |
Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment