kumoshk
November 24th, 2009, 09:41 AM
Question #1:
How do I set up menu shortcuts in Gtk? I have menus, and they have mnemonics, but I don't see any examples or documentation as to how one can set up shortcuts.
I figured they'd have functionality that doesn't require one to work with key events (most of the GUI libraries I've tried do, anyhow).
Here's an example menu:
var menubar = new MenuBar();
var file_menu = new Menu();
var open_item=new MenuItem.with_mnemonic("_Open");
var quit_item=new MenuItem.with_mnemonic("_Quit");
file_menu.append(open_item);
file_menu.append(quit_item);
open_item.activate+=on_open;
quit_item.activate+=Gtk.main_quit;
var file_launcher=new MenuItem.with_mnemonic("_File");
file_launcher.set_submenu(file_menu);
menubar.append(file_launcher);
Question #2:
How can I get key combinations to register in KeyEvents? I mean, I want Ctrl+Y to signal a redo function, but it only catches Ctrl or Y (not both) in string form. I'm not sure how to do it in non-string form.
I've been using this
string key = Gdk.keyval_name (event.keyval);
to get my key events, but I figure I have to do something else, since it only returns one.
How do I set up menu shortcuts in Gtk? I have menus, and they have mnemonics, but I don't see any examples or documentation as to how one can set up shortcuts.
I figured they'd have functionality that doesn't require one to work with key events (most of the GUI libraries I've tried do, anyhow).
Here's an example menu:
var menubar = new MenuBar();
var file_menu = new Menu();
var open_item=new MenuItem.with_mnemonic("_Open");
var quit_item=new MenuItem.with_mnemonic("_Quit");
file_menu.append(open_item);
file_menu.append(quit_item);
open_item.activate+=on_open;
quit_item.activate+=Gtk.main_quit;
var file_launcher=new MenuItem.with_mnemonic("_File");
file_launcher.set_submenu(file_menu);
menubar.append(file_launcher);
Question #2:
How can I get key combinations to register in KeyEvents? I mean, I want Ctrl+Y to signal a redo function, but it only catches Ctrl or Y (not both) in string form. I'm not sure how to do it in non-string form.
I've been using this
string key = Gdk.keyval_name (event.keyval);
to get my key events, but I figure I have to do something else, since it only returns one.