Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to load an accelerators map from a file using GTK3 in Vala?
    text
    copied!<p>I'm making a text editor using GTK3 in Vala. I have a <code>Gtk.MenuBar</code> in a <code>Gtk.Window</code> and I want to use accelerators to easily activate its <code>Gtk.MenuItems</code>. But I want the user to be able to change the key combinations, so I'm loading the accelerators specifications from a file using the method <code>Gtk.AccelMap.load("accels")</code>. However, after calling this method, the accelerators are not loaded: the menu items don't have <code>AccelLabels</code> and are not activated when I press the key combinations. Here are the two files I'm working on. The first file contains a small version of my application (to show what I'm trying to do) and the second one is the accels file from which I load the accels specifications, and they must be in the same directory.</p> <p>main.vala</p> <pre><code>// 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 the accelerators from the file Gtk.AccelMap.load("accels"); // Create the action var quit_action = new Gtk.Action("file-quit", "Quit", "Quit the application", null); quit_action.activate.connect(()=&gt;{ Gtk.main_quit(); }); quit_action.set_accel_group(accel_group); quit_action.set_accel_path("&lt;MyWindow&gt;/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; } </code></pre> <p>"accels" file</p> <pre><code>; main GtkAccelMap rc-file -*- scheme -*- ; this file is an automated accelerator map dump ; ; (gtk_accel_path "&lt;MyWindow&gt;/File/Quit" "&lt;Control&gt;q") </code></pre> <p>So, why is this not working? What do I have to do before or after loading the accel file?</p> <p>PS: I don't want to use a <code>Gtk.UIManager</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload