gtk - How to load an accelerators map from a file using GTK3 in Vala? -
i'm making text editor using gtk3 in vala. have gtk.menubar
in gtk.window
, want use accelerators activate gtk.menuitems
. want user able change key combinations, i'm loading accelerators specifications file using method gtk.accelmap.load("accels")
. however, after calling method, accelerators not loaded: menu items don't have accellabels
, not activated when press key combinations. here 2 files i'm working on. first file contains small version of application (to show i'm trying do) , second 1 accels file load accels specifications, , must in same directory.
main.vala
// compile me with: valac main.vala -o main --pkg gtk+-3.0 public class mywindow: gtk.window { public mywindow() { this.set_default_size(500, 500); var main_box = new gtk.vbox(false, 0); this.add(main_box); var accel_group = new gtk.accelgroup(); this.add_accel_group(accel_group); // load accelerators file gtk.accelmap.load("accels"); // create action var quit_action = new gtk.action("file-quit", "quit", "quit application", null); quit_action.activate.connect(()=>{ gtk.main_quit(); }); quit_action.set_accel_group(accel_group); quit_action.set_accel_path("<mywindow>/file/quit"); // menubar var menubar = new gtk.menubar(); main_box.pack_start(menubar, false, false, 0); var file = new gtk.menuitem.with_label("file"); menubar.add(file); var file_menu = new gtk.menu(); file.set_submenu(file_menu); var quit_mi = (gtk.menuitem)quit_action.create_menu_item(); file_menu.append(quit_mi); // label var label = new gtk.label("my window"); main_box.pack_start(label, true, true, 0); this.destroy.connect(gtk.main_quit); } } int main(string[] args) { gtk.init(ref args); var win = new mywindow(); win.show_all(); gtk.main(); return 0; }
"accels" file
; main gtkaccelmap rc-file -*- scheme -*- ; file automated accelerator map dump ; ; (gtk_accel_path "<mywindow>/file/quit" "<control>q")
so, why not working? have before or after loading accel file?
ps: don't want use gtk.uimanager
.
Comments
Post a Comment