Re: [gtkmm] Problems with UIManager, Action, and Accelerators



On Fri, 2004-03-19 at 00:56, Bryan Forbes wrote:
> I have this small test case that I cannot get the accelerators to work.


I don't know where you got the AccelGroup stuff from, but you don't need
it and it doesn't seem to work. Here is a patch to your test that makes
it work for me. You do need to call
  add_accel_group(m_refUIManager->get_accel_group());
on the parent window, and that seems a bit obscure.

> This also shows that the Action API is quite strange in C++ and I think
> we need some solution to it.

Can you be more precise? Where exactly is the problem? I don't think
it's very different from the old gtkmm 2.2 menu/toolbar API or the
libgnomeuimm UIInfo API.

You can make it more compact by doing the Action::create() inside the
add() call. You didn't do that this time because you thought you had to
do the extra accelgroup stuff.

Had you seen demos/gtk-demo/example_uimanager.cc?
 
>   Any suggestions would be awesome.  I may
> have some ideas tonite when I get back, but for now, I've attached my
> example.

-- 
Murray Cumming
www.murrayc.com
murrayc murrayc com
--- test_actions_old.cc	2004-03-19 10:11:13.000000000 +0100
+++ test_actions.cc	2004-03-19 10:03:27.000000000 +0100
@@ -75,7 +75,6 @@ MyWindow::MyWindow()
   using namespace Gtk;
   add(m_VBox);
 
-  m_rpAccelGroup = AccelGroup::create();
   m_rpActionGroup = ActionGroup::create("MenuActions");
 
   Glib::RefPtr<Action> action;
@@ -87,26 +86,20 @@ MyWindow::MyWindow()
   m_rpActionGroup->add(action);
 
   action = Action::create("Open", Gtk::Stock::OPEN, "_Open", "Open a file");
-  m_rpActionGroup->add(action, AccelKey("<control>O"), sigc::mem_fun(*this, &MyWindow::on_open));
-  action->set_accel_group(m_rpAccelGroup);
+  m_rpActionGroup->add(action, sigc::mem_fun(*this, &MyWindow::on_open));
 
   action = Action::create("Exit", Gtk::Stock::QUIT, "_Exit", "Exit the program");
   m_rpActionGroup->add(action, AccelKey("<control>Q"), sigc::mem_fun(*this, &MyWindow::on_quit));
-  action->set_accel_group(m_rpAccelGroup);
-
+ 
   action = Action::create("ZoomIn", Gtk::Stock::ZOOM_IN, "Zoom _In", "Zoom into the image");
   m_rpActionGroup->add(action, AccelKey("plus"), sigc::mem_fun(*this, &MyWindow::on_zoom_in));
-  action->set_accel_group(m_rpAccelGroup);
-
+  
   action = Action::create("ZoomOut", Gtk::Stock::ZOOM_OUT, "Zoom _Out", "Zoom away from the image");
   m_rpActionGroup->add(action, AccelKey("minus"), sigc::mem_fun(*this, &MyWindow::on_zoom_out));
-  action->set_accel_group(m_rpAccelGroup);
-  
-
+ 
   Glib::RefPtr<ToggleAction> toggleaction;
   toggleaction = ToggleAction::create("FullScreen", "_Full Screen", "Switch between full screen and windowed mode");
   m_rpActionGroup->add(toggleaction, AccelKey("F11"), sigc::mem_fun(*this, &MyWindow::on_full_screen));
-  action->set_accel_group(m_rpAccelGroup);
   
 
   Glib::RefPtr<RadioAction> radioaction;
@@ -121,9 +114,9 @@ MyWindow::MyWindow()
 
 
   m_rpUIManager = UIManager::create();
-  m_rpUIManager->insert_action_group(m_rpActionGroup, 0);
+  m_rpUIManager->insert_action_group(m_rpActionGroup);
+  add_accel_group(m_rpUIManager->get_accel_group());
 
-  add_accel_group(m_rpAccelGroup);
 
   if(!m_rpUIManager->add_ui_from_string(ui_description))
   {


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