* Start using Gtk::Actions instead of directly MenuItems where possible

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1332 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2008-11-08 23:45:22 +00:00
parent ed9e5bfa0a
commit e34b70004a
4 changed files with 117 additions and 114 deletions

View File

@ -52,6 +52,7 @@
#include <glibmm/markup.h> #include <glibmm/markup.h>
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
#include <gtkmm/aboutdialog.h> #include <gtkmm/aboutdialog.h>
#include <gtkmm/action.h>
#include <gtkmm/button.h> #include <gtkmm/button.h>
#include <gtkmm/messagedialog.h> #include <gtkmm/messagedialog.h>
#include <gtkmm/menutoolbutton.h> #include <gtkmm/menutoolbutton.h>
@ -532,8 +533,16 @@ GuiBuilder::on_selected_resource_policy(ResourcePolicy* pol)
void void
GuiBuilder::on_toggle_simulation_mode() GuiBuilder::on_toggle_simulation_mode()
{ {
Gtk::CheckMenuItem* continuous_mode; using namespace Gtk;
_refXml->get_widget("MenuItem.Simulation.ContinuousMode", continuous_mode); using Glib::RefPtr;
RefPtr<UIManager> uimanager = RefPtr<UIManager>::cast_dynamic (_refXml->get_object("UIManager"));
CheckMenuItem* continuous_mode = NULL;
continuous_mode = dynamic_cast<CheckMenuItem*>(uimanager->get_widget
("/MenuBar/Action.Simulation/Action.Simulation.ContinuousMode"));
g_assert (continuous_mode != NULL);
if(continuous_mode->get_active() == true) if(continuous_mode->get_active() == true)
Simulation::get_instance().set_mode(Simulation::mode_continuous); Simulation::get_instance().set_mode(Simulation::mode_continuous);
else else
@ -578,6 +587,7 @@ GuiBuilder::GuiBuilder(const std::string& uifile)
_show_threads(true) _show_threads(true)
{ {
using namespace Gtk; using namespace Gtk;
using Glib::RefPtr;
Window& main_window = get_initial_window(); Window& main_window = get_initial_window();
main_window.signal_delete_event().connect(sigc::bind_return(sigc::hide(sigc::mem_fun(*this, &GuiBuilder::ask_save)), false)); main_window.signal_delete_event().connect(sigc::bind_return(sigc::hide(sigc::mem_fun(*this, &GuiBuilder::ask_save)), false));
@ -587,54 +597,44 @@ GuiBuilder::GuiBuilder(const std::string& uifile)
// Note: the Play, Pause and Stop menu items are already managed by sgpem::SimulationController. // Note: the Play, Pause and Stop menu items are already managed by sgpem::SimulationController.
// file new dialog // file new dialog
MenuItem* file_new = NULL; RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.File.New"))
_refXml->get_widget("MenuItem.File.New", file_new); ->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_new_activate));
file_new->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_new_activate));
// file open dialog // file open dialog
MenuItem* file_open = NULL; RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.File.Open"))
_refXml->get_widget("MenuItem.File.Open", file_open); ->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_open_activate));
file_open->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_open_activate));
// file save dialog // file save dialog
MenuItem* file_save = NULL; RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.File.Save"))
_refXml->get_widget("MenuItem.File.Save", file_save); ->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_save_activate));
file_save->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_save_activate));
// file save dialog // file save dialog
MenuItem* file_saveas = NULL; RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.File.SaveAs"))
_refXml->get_widget("MenuItem.File.SaveAs", file_saveas); ->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_saveas_activate));
file_saveas->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_saveas_activate));
MenuItem* file_quit = NULL; RefPtr<Action> file_quit = RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.File.Quit"));
_refXml->get_widget("MenuItem.File.Quit", file_quit);
file_quit->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::ask_save)); file_quit->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::ask_save));
file_quit->signal_activate().connect(sigc::ptr_fun(&Main::quit)); file_quit->signal_activate().connect(sigc::ptr_fun(&Main::quit));
// preferences dialog // preferences dialog
MenuItem* edit_preferences; RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.Edit.Preferences"))
_refXml->get_widget("MenuItem.Edit.Preferences", edit_preferences); ->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_edit_preferences_activate));
edit_preferences->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_edit_preferences_activate));
// enable/disable show threads on widgets // enable/disable show threads on widgets
MenuItem* show_threads; RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.View.ShowThreads"))
_refXml->get_widget("MenuItem.View.ShowThreads", show_threads); ->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_view_show_threads_activate));
show_threads->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_view_show_threads_activate));
// show/hide holt graph window // show/hide holt graph window
MenuItem* show_holt_graph; RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.View.ShowHoltGraph"))
_refXml->get_widget("MenuItem.View.ShowHoltGraph", show_holt_graph); ->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_view_show_holt_graph_activate));
show_holt_graph->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_view_show_holt_graph_activate));
// show/hide statistics window // show/hide statistics window
MenuItem* show_statistics_graph; RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.View.ShowStatistics"))
_refXml->get_widget("MenuItem.View.ShowStatistics", show_statistics_graph); ->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_view_show_statistics_activate));
show_statistics_graph->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_view_show_statistics_activate));
CheckMenuItem* continuous_mode; RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.Simulation.ContinuousMode"))
_refXml->get_widget("MenuItem.Simulation.ContinuousMode", continuous_mode); ->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_toggle_simulation_mode));
continuous_mode->signal_toggled().connect(sigc::mem_fun(*this, &GuiBuilder::on_toggle_simulation_mode));
// ---------------- Toolbar buttons ------------------ // ---------------- Toolbar buttons ------------------
@ -668,11 +668,10 @@ GuiBuilder::GuiBuilder(const std::string& uifile)
// --------------------------------------------------- // ---------------------------------------------------
// About dialog // About dialog
MenuItem* help_about;
_refXml->get_widget("MenuItem.Help.About", help_about);
AboutDialog* about_dialog = NULL; AboutDialog* about_dialog = NULL;
_refXml->get_widget("AboutDialog", about_dialog); _refXml->get_widget("AboutDialog", about_dialog);
help_about->signal_activate().connect(sigc::mem_fun(*about_dialog, &Window::show)); RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.Help.About"))
->signal_activate().connect(sigc::mem_fun(*about_dialog, &Window::show));
about_dialog->set_wrap_license(true); about_dialog->set_wrap_license(true);
about_dialog->set_logo(Gdk::Pixbuf::create_from_file(UIDIR "/logo.png")); about_dialog->set_logo(Gdk::Pixbuf::create_from_file(UIDIR "/logo.png"));

View File

@ -50,6 +50,7 @@ SimulationController::SimulationController(Simulation& simulation, Glib::RefPtr<
: _sim(simulation), _break_requested(false) : _sim(simulation), _break_requested(false)
{ {
using namespace Gtk; using namespace Gtk;
using Glib::RefPtr;
_sim.attach(*this); _sim.attach(*this);
@ -60,17 +61,21 @@ SimulationController::SimulationController(Simulation& simulation, Glib::RefPtr<
refXml->get_widget("ToolBar.Pause", _toolbt_pause); refXml->get_widget("ToolBar.Pause", _toolbt_pause);
refXml->get_widget("ToolBar.Stop", _toolbt_stop); refXml->get_widget("ToolBar.Stop", _toolbt_stop);
refXml->get_widget("MenuItem.Simulation.Play", _menuit_start); _action_start = RefPtr<Action>::cast_dynamic (refXml->get_object("Action.Simulation.Play"));
refXml->get_widget("MenuItem.Simulation.Pause", _menuit_pause); _action_pause = RefPtr<Action>::cast_dynamic (refXml->get_object("Action.Simulation.Pause"));
refXml->get_widget("MenuItem.Simulation.Stop", _menuit_stop); _action_stop = RefPtr<Action>::cast_dynamic (refXml->get_object("Action.Simulation.Stop"));
g_assert (_action_start != NULL);
g_assert (_action_pause != NULL);
g_assert (_action_stop != NULL);
_toolbt_start->signal_clicked().connect(sigc::mem_fun(*this, &SimulationController::on_simulation_run)); _toolbt_start->signal_clicked().connect(sigc::mem_fun(*this, &SimulationController::on_simulation_run));
_toolbt_pause->signal_clicked().connect(sigc::mem_fun(*this, &SimulationController::on_simulation_pause)); _toolbt_pause->signal_clicked().connect(sigc::mem_fun(*this, &SimulationController::on_simulation_pause));
_toolbt_stop->signal_clicked().connect(sigc::mem_fun(*this, &SimulationController::on_simulation_stop)); _toolbt_stop->signal_clicked().connect(sigc::mem_fun(*this, &SimulationController::on_simulation_stop));
_menuit_start->signal_activate().connect(sigc::mem_fun(*this, &SimulationController::on_simulation_run)); _action_start->signal_activate().connect(sigc::mem_fun(*this, &SimulationController::on_simulation_run));
_menuit_pause->signal_activate().connect(sigc::mem_fun(*this, &SimulationController::on_simulation_pause)); _action_pause->signal_activate().connect(sigc::mem_fun(*this, &SimulationController::on_simulation_pause));
_menuit_stop->signal_activate().connect(sigc::mem_fun(*this, &SimulationController::on_simulation_stop)); _action_stop->signal_activate().connect(sigc::mem_fun(*this, &SimulationController::on_simulation_stop));
} }
@ -88,9 +93,9 @@ SimulationController::on_simulation_run()
_toolbt_pause->set_sensitive(true); _toolbt_pause->set_sensitive(true);
_toolbt_stop->set_sensitive(true); _toolbt_stop->set_sensitive(true);
_menuit_start->set_sensitive(false); _action_start->set_sensitive(false);
_menuit_pause->set_sensitive(true); _action_pause->set_sensitive(true);
_menuit_stop->set_sensitive(true); _action_stop->set_sensitive(true);
_break_requested = false; _break_requested = false;
// Used instead of simply calling "_sim.run()" to // Used instead of simply calling "_sim.run()" to
@ -107,9 +112,9 @@ SimulationController::on_simulation_pause()
_toolbt_pause->set_sensitive(false); _toolbt_pause->set_sensitive(false);
_toolbt_stop->set_sensitive(true); _toolbt_stop->set_sensitive(true);
_menuit_start->set_sensitive(true); _action_start->set_sensitive(true);
_menuit_pause->set_sensitive(false); _action_pause->set_sensitive(false);
_menuit_stop->set_sensitive(true); _action_stop->set_sensitive(true);
_break_requested = true; _break_requested = true;
_sim.pause(); _sim.pause();
@ -124,9 +129,9 @@ SimulationController::on_simulation_stop()
_toolbt_pause->set_sensitive(false); _toolbt_pause->set_sensitive(false);
_toolbt_stop->set_sensitive(false); _toolbt_stop->set_sensitive(false);
_menuit_start->set_sensitive(true); _action_start->set_sensitive(true);
_menuit_pause->set_sensitive(false); _action_pause->set_sensitive(false);
_menuit_stop->set_sensitive(false); _action_stop->set_sensitive(false);
_break_requested = true; _break_requested = true;
_sim.stop(); _sim.stop();

View File

@ -26,7 +26,7 @@
#include <sgpemv2/simulation_observer.hh> #include <sgpemv2/simulation_observer.hh>
#include <gtkmm/toolbutton.h> #include <gtkmm/toolbutton.h>
#include <gtkmm/menuitem.h> #include <gtkmm/action.h>
#include <gtkmm/builder.h> #include <gtkmm/builder.h>
namespace sgpem namespace sgpem
@ -85,9 +85,9 @@ namespace sgpem
Gtk::ToolButton* _toolbt_pause; Gtk::ToolButton* _toolbt_pause;
Gtk::ToolButton* _toolbt_stop; Gtk::ToolButton* _toolbt_stop;
Gtk::MenuItem* _menuit_start; Glib::RefPtr<Gtk::Action> _action_start;
Gtk::MenuItem* _menuit_pause; Glib::RefPtr<Gtk::Action> _action_pause;
Gtk::MenuItem* _menuit_stop; Glib::RefPtr<Gtk::Action> _action_stop;
}; };
} //~ namespace sgpem } //~ namespace sgpem

View File

@ -11,160 +11,159 @@
<property name="lower">0</property> <property name="lower">0</property>
<property name="page_increment">10</property> <property name="page_increment">10</property>
<property name="value">0</property> <property name="value">0</property>
<property name="page_size">10</property>
<property name="step_increment">1</property> <property name="step_increment">1</property>
</object> </object>
<object class="GtkUIManager" id="uimanager1"> <object class="GtkUIManager" id="UIManager">
<child> <child>
<object class="GtkActionGroup" id="actiongroup1"> <object class="GtkActionGroup" id="actiongroup1">
<child> <child>
<object class="GtkAction" id="MenuItem.File"> <object class="GtkAction" id="Action.File">
<property name="name">MenuItem.File</property> <property name="name">Action.File</property>
<property name="label">_File</property> <property name="label">_File</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkAction" id="MenuItem.File.New"> <object class="GtkAction" id="Action.File.New">
<property name="stock_id">gtk-new</property> <property name="stock_id">gtk-new</property>
<property name="name">MenuItem.File.New</property> <property name="name">Action.File.New</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkAction" id="MenuItem.File.Open"> <object class="GtkAction" id="Action.File.Open">
<property name="stock_id">gtk-open</property> <property name="stock_id">gtk-open</property>
<property name="name">MenuItem.File.Open</property> <property name="name">Action.File.Open</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkAction" id="MenuItem.File.Save"> <object class="GtkAction" id="Action.File.Save">
<property name="stock_id">gtk-save</property> <property name="stock_id">gtk-save</property>
<property name="name">MenuItem.File.Save</property> <property name="name">Action.File.Save</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkAction" id="MenuItem.File.SaveAs"> <object class="GtkAction" id="Action.File.SaveAs">
<property name="stock_id">gtk-save-as</property> <property name="stock_id">gtk-save-as</property>
<property name="name">MenuItem.File.SaveAs</property> <property name="name">Action.File.SaveAs</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkAction" id="MenuItem.File.Quit"> <object class="GtkAction" id="Action.File.Quit">
<property name="stock_id">gtk-quit</property> <property name="stock_id">gtk-quit</property>
<property name="name">MenuItem.File.Quit</property> <property name="name">Action.File.Quit</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkAction" id="MenuItem.Edit"> <object class="GtkAction" id="Action.Edit">
<property name="name">MenuItem.Edit</property> <property name="name">Action.Edit</property>
<property name="label">_Edit</property> <property name="label">_Edit</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkAction" id="MenuItem.Edit.Preferences"> <object class="GtkAction" id="Action.Edit.Preferences">
<property name="stock_id">gtk-preferences</property> <property name="stock_id">gtk-preferences</property>
<property name="name">MenuItem.Edit.Preferences</property> <property name="name">Action.Edit.Preferences</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkAction" id="MenuItem.View"> <object class="GtkAction" id="Action.View">
<property name="name">MenuItem.View</property> <property name="name">Action.View</property>
<property name="label">_View</property> <property name="label">_View</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkAction" id="MenuItem.View.ShowThreads"> <object class="GtkAction" id="Action.View.ShowThreads">
<property name="stock_id">gtk-select-font</property> <property name="stock_id">gtk-select-font</property>
<property name="name">MenuItem.View.ShowThreads</property> <property name="name">Action.View.ShowThreads</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkAction" id="MenuItem.View.ShowHoltGraph"> <object class="GtkAction" id="Action.View.ShowHoltGraph">
<property name="stock_id">gtk-convert</property> <property name="stock_id">gtk-convert</property>
<property name="name">MenuItem.View.ShowHoltGraph</property> <property name="name">Action.View.ShowHoltGraph</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkAction" id="MenuItem.View.ShowStatistics"> <object class="GtkAction" id="Action.View.ShowStatistics">
<property name="stock_id">gtk-justify-left</property> <property name="stock_id">gtk-justify-left</property>
<property name="name">MenuItem.View.ShowStatistics</property> <property name="name">Action.View.ShowStatistics</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkAction" id="MenuItem.Simulation"> <object class="GtkAction" id="Action.Simulation">
<property name="name">MenuItem.Simulation</property> <property name="name">Action.Simulation</property>
<property name="label">_Simulation</property> <property name="label">_Simulation</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkAction" id="MenuItem.Simulation.Play"> <object class="GtkAction" id="Action.Simulation.Play">
<property name="stock_id">gtk-media-play</property> <property name="stock_id">gtk-media-play</property>
<property name="name">MenuItem.Simulation.Play</property> <property name="name">Action.Simulation.Play</property>
</object> </object>
<accelerator key="F5" modifiers=""/> <accelerator key="F5" modifiers=""/>
</child> </child>
<child> <child>
<object class="GtkAction" id="MenuItem.Simulation.Pause"> <object class="GtkAction" id="Action.Simulation.Pause">
<property name="stock_id">gtk-media-pause</property> <property name="stock_id">gtk-media-pause</property>
<property name="name">MenuItem.Simulation.Pause</property> <property name="name">Action.Simulation.Pause</property>
</object> </object>
<accelerator key="F6" modifiers=""/> <accelerator key="F6" modifiers=""/>
</child> </child>
<child> <child>
<object class="GtkAction" id="MenuItem.Simulation.Stop"> <object class="GtkAction" id="Action.Simulation.Stop">
<property name="stock_id">gtk-media-stop</property> <property name="stock_id">gtk-media-stop</property>
<property name="name">MenuItem.Simulation.Stop</property> <property name="name">Action.Simulation.Stop</property>
<signal handler="on_stop1_activate" name="activate"/> <signal handler="on_stop1_activate" name="activate"/>
</object> </object>
<accelerator key="F7" modifiers=""/> <accelerator key="F7" modifiers=""/>
</child> </child>
<child> <child>
<object class="GtkToggleAction" id="MenuItem.Simulation.ContinuousMode"> <object class="GtkToggleAction" id="Action.Simulation.ContinuousMode">
<property name="active">True</property> <property name="active">True</property>
<property name="name">MenuItem.Simulation.ContinuousMode</property> <property name="name">Action.Simulation.ContinuousMode</property>
<property name="label">Continuous mode</property> <property name="label">Continuous mode</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkAction" id="MenuItem.Help"> <object class="GtkAction" id="Action.Help">
<property name="name">MenuItem.Help</property> <property name="name">Action.Help</property>
<property name="label">_Help</property> <property name="label">_Help</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkAction" id="MenuItem.Help.About"> <object class="GtkAction" id="Action.Help.About">
<property name="stock_id">gtk-about</property> <property name="stock_id">gtk-about</property>
<property name="name">MenuItem.Help.About</property> <property name="name">Action.Help.About</property>
</object> </object>
</child> </child>
</object> </object>
</child> </child>
<ui> <ui>
<menubar name="MenuBar"> <menubar name="MenuBar">
<menu action="MenuItem.File"> <menu action="Action.File">
<menuitem action="MenuItem.File.New"/> <menuitem action="Action.File.New"/>
<menuitem action="MenuItem.File.Open"/> <menuitem action="Action.File.Open"/>
<menuitem action="MenuItem.File.Save"/> <menuitem action="Action.File.Save"/>
<menuitem action="MenuItem.File.SaveAs"/> <menuitem action="Action.File.SaveAs"/>
<separator/> <separator/>
<menuitem action="MenuItem.File.Quit"/> <menuitem action="Action.File.Quit"/>
</menu> </menu>
<menu action="MenuItem.Edit"> <menu action="Action.Edit">
<menuitem action="MenuItem.Edit.Preferences"/> <menuitem action="Action.Edit.Preferences"/>
</menu> </menu>
<menu action="MenuItem.View"> <menu action="Action.View">
<menuitem action="MenuItem.View.ShowThreads"/> <menuitem action="Action.View.ShowThreads"/>
<menuitem action="MenuItem.View.ShowHoltGraph"/> <menuitem action="Action.View.ShowHoltGraph"/>
<menuitem action="MenuItem.View.ShowStatistics"/> <menuitem action="Action.View.ShowStatistics"/>
</menu> </menu>
<menu action="MenuItem.Simulation"> <menu action="Action.Simulation">
<menuitem action="MenuItem.Simulation.Play"/> <menuitem action="Action.Simulation.Play"/>
<menuitem action="MenuItem.Simulation.Pause"/> <menuitem action="Action.Simulation.Pause"/>
<menuitem action="MenuItem.Simulation.Stop"/> <menuitem action="Action.Simulation.Stop"/>
<separator/> <separator/>
<menuitem action="MenuItem.Simulation.ContinuousMode"/> <menuitem action="Action.Simulation.ContinuousMode"/>
</menu> </menu>
<menu action="MenuItem.Help"> <menu action="Action.Help">
<menuitem action="MenuItem.Help.About"/> <menuitem action="Action.Help.About"/>
</menu> </menu>
</menubar> </menubar>
</ui> </ui>
@ -178,7 +177,7 @@
<object class="GtkVBox" id="MainBox"> <object class="GtkVBox" id="MainBox">
<property name="visible">True</property> <property name="visible">True</property>
<child> <child>
<object class="GtkMenuBar" constructor="uimanager1" id="MenuBar"> <object class="GtkMenuBar" constructor="UIManager" id="MenuBar">
<property name="visible">True</property> <property name="visible">True</property>
</object> </object>
<packing> <packing>