[gtkmm] Problems with Gtk::MenuItem accelerators



Hi!

I want to create a menu with accelerators for menu items (e.g. <control>q
for "File->Quit"). My understanding of the accelerator path and the
accelerator map is that I can define a path in the global map with:

Gtk::AccelMap::add_entry("<something>/File/Quit", 'q', Gtk::CONTROL_MASK);

And then I just need to set the accelerator path of my menu item:

my_menu_item.set_accel_path("<something>/File/Quit")

But this does not work. What else do I need to do, to use the
Gtk::AccelMap functionalities? Gtk::AccelMap::save() and
Gtk::AccelMap::load() looks like an easy way to save keybindings of
users.

I prepared code that works, but the menu items do not have
accelerators. I noticed that I need to include <gtkmm/accelmap.h>
manually.

--------8<--------

#include <gtkmm.h>
#include <gtkmm/accelmap.h>

class cMyWin : public Gtk::Window
{
  private:
    Gtk::MenuBar menu_bar;
    Gtk::MenuItem top_file;
    Gtk::Menu top_menu_file;
    Gtk::MenuItem file_new;
    Gtk::MenuItem file_close;
    Gtk::MenuItem file_quit;

  public:
    cMyWin (void)
      {
        /* Setup menubar with items */
        top_file.add_label("_File");
	top_file.set_submenu(top_menu_file);
        menu_bar.append(top_file);
        file_new.add_label("_New");
        file_close.add_label("_Close");
        file_quit.add_label("_Quit");
	top_menu_file.append(file_new);
	top_menu_file.append(file_close);
	top_menu_file.append(file_quit);
	/* Install accels in map */
	Gtk::AccelMap::add_entry("<test>/File/New", 'n', Gdk::CONTROL_MASK);
	Gtk::AccelMap::add_entry("<test>/File/Close", 'c', Gdk::CONTROL_MASK);
	Gtk::AccelMap::add_entry("<test>/File/Quit", 'q', Gdk::CONTROL_MASK);
	/* Set accels for the menu items */
	file_new.set_accel_path("<test>/File/New");
	file_close.set_accel_path("<test>/File/Close");
	file_quit.set_accel_path("<test>/File/Quit");
	/* Window stuff */
	add(menu_bar);
	show_all();
      }
};

int
main (int argc, char* argv[])
{
  Gtk::Main kit(&argc, &argv);

  cMyWin win;

  Gtk::Main::run (win);
}

--------8<--------

Regards.

-- 
Simon Fuhrmann | NightSlayer at gmx.de | http://www.dismember.de
All people talk about the real life, but where can I download it?



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]