* 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/ustring.h>
#include <gtkmm/aboutdialog.h>
#include <gtkmm/action.h>
#include <gtkmm/button.h>
#include <gtkmm/messagedialog.h>
#include <gtkmm/menutoolbutton.h>
@ -532,8 +533,16 @@ GuiBuilder::on_selected_resource_policy(ResourcePolicy* pol)
void
GuiBuilder::on_toggle_simulation_mode()
{
Gtk::CheckMenuItem* continuous_mode;
_refXml->get_widget("MenuItem.Simulation.ContinuousMode", continuous_mode);
using namespace Gtk;
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)
Simulation::get_instance().set_mode(Simulation::mode_continuous);
else
@ -578,6 +587,7 @@ GuiBuilder::GuiBuilder(const std::string& uifile)
_show_threads(true)
{
using namespace Gtk;
using Glib::RefPtr;
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));
@ -587,54 +597,44 @@ GuiBuilder::GuiBuilder(const std::string& uifile)
// Note: the Play, Pause and Stop menu items are already managed by sgpem::SimulationController.
// file new dialog
MenuItem* file_new = NULL;
_refXml->get_widget("MenuItem.File.New", file_new);
file_new->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_new_activate));
RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.File.New"))
->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_new_activate));
// file open dialog
MenuItem* file_open = NULL;
_refXml->get_widget("MenuItem.File.Open", file_open);
file_open->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_open_activate));
RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.File.Open"))
->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_open_activate));
// file save dialog
MenuItem* file_save = NULL;
_refXml->get_widget("MenuItem.File.Save", file_save);
file_save->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_save_activate));
RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.File.Save"))
->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_save_activate));
// file save dialog
MenuItem* file_saveas = NULL;
_refXml->get_widget("MenuItem.File.SaveAs", file_saveas);
file_saveas->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_saveas_activate));
RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.File.SaveAs"))
->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_saveas_activate));
MenuItem* file_quit = NULL;
_refXml->get_widget("MenuItem.File.Quit", file_quit);
RefPtr<Action> file_quit = RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.File.Quit"));
file_quit->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::ask_save));
file_quit->signal_activate().connect(sigc::ptr_fun(&Main::quit));
// preferences dialog
MenuItem* edit_preferences;
_refXml->get_widget("MenuItem.Edit.Preferences", edit_preferences);
edit_preferences->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_edit_preferences_activate));
RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.Edit.Preferences"))
->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_edit_preferences_activate));
// enable/disable show threads on widgets
MenuItem* show_threads;
_refXml->get_widget("MenuItem.View.ShowThreads", show_threads);
show_threads->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_view_show_threads_activate));
RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.View.ShowThreads"))
->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_view_show_threads_activate));
// show/hide holt graph window
MenuItem* show_holt_graph;
_refXml->get_widget("MenuItem.View.ShowHoltGraph", show_holt_graph);
show_holt_graph->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_view_show_holt_graph_activate));
RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.View.ShowHoltGraph"))
->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_view_show_holt_graph_activate));
// show/hide statistics window
MenuItem* show_statistics_graph;
_refXml->get_widget("MenuItem.View.ShowStatistics", show_statistics_graph);
show_statistics_graph->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_view_show_statistics_activate));
RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.View.ShowStatistics"))
->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_view_show_statistics_activate));
CheckMenuItem* continuous_mode;
_refXml->get_widget("MenuItem.Simulation.ContinuousMode", continuous_mode);
continuous_mode->signal_toggled().connect(sigc::mem_fun(*this, &GuiBuilder::on_toggle_simulation_mode));
RefPtr<Action>::cast_dynamic (_refXml->get_object("Action.Simulation.ContinuousMode"))
->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_toggle_simulation_mode));
// ---------------- Toolbar buttons ------------------
@ -668,11 +668,10 @@ GuiBuilder::GuiBuilder(const std::string& uifile)
// ---------------------------------------------------
// About dialog
MenuItem* help_about;
_refXml->get_widget("MenuItem.Help.About", help_about);
AboutDialog* about_dialog = NULL;
_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_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)
{
using namespace Gtk;
using Glib::RefPtr;
_sim.attach(*this);
@ -60,17 +61,21 @@ SimulationController::SimulationController(Simulation& simulation, Glib::RefPtr<
refXml->get_widget("ToolBar.Pause", _toolbt_pause);
refXml->get_widget("ToolBar.Stop", _toolbt_stop);
refXml->get_widget("MenuItem.Simulation.Play", _menuit_start);
refXml->get_widget("MenuItem.Simulation.Pause", _menuit_pause);
refXml->get_widget("MenuItem.Simulation.Stop", _menuit_stop);
_action_start = RefPtr<Action>::cast_dynamic (refXml->get_object("Action.Simulation.Play"));
_action_pause = RefPtr<Action>::cast_dynamic (refXml->get_object("Action.Simulation.Pause"));
_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_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));
_menuit_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));
_menuit_stop->signal_activate().connect(sigc::mem_fun(*this, &SimulationController::on_simulation_stop));
_action_start->signal_activate().connect(sigc::mem_fun(*this, &SimulationController::on_simulation_run));
_action_pause->signal_activate().connect(sigc::mem_fun(*this, &SimulationController::on_simulation_pause));
_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_stop->set_sensitive(true);
_menuit_start->set_sensitive(false);
_menuit_pause->set_sensitive(true);
_menuit_stop->set_sensitive(true);
_action_start->set_sensitive(false);
_action_pause->set_sensitive(true);
_action_stop->set_sensitive(true);
_break_requested = false;
// Used instead of simply calling "_sim.run()" to
@ -107,9 +112,9 @@ SimulationController::on_simulation_pause()
_toolbt_pause->set_sensitive(false);
_toolbt_stop->set_sensitive(true);
_menuit_start->set_sensitive(true);
_menuit_pause->set_sensitive(false);
_menuit_stop->set_sensitive(true);
_action_start->set_sensitive(true);
_action_pause->set_sensitive(false);
_action_stop->set_sensitive(true);
_break_requested = true;
_sim.pause();
@ -124,9 +129,9 @@ SimulationController::on_simulation_stop()
_toolbt_pause->set_sensitive(false);
_toolbt_stop->set_sensitive(false);
_menuit_start->set_sensitive(true);
_menuit_pause->set_sensitive(false);
_menuit_stop->set_sensitive(false);
_action_start->set_sensitive(true);
_action_pause->set_sensitive(false);
_action_stop->set_sensitive(false);
_break_requested = true;
_sim.stop();

View File

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

View File

@ -11,160 +11,159 @@
<property name="lower">0</property>
<property name="page_increment">10</property>
<property name="value">0</property>
<property name="page_size">10</property>
<property name="step_increment">1</property>
</object>
<object class="GtkUIManager" id="uimanager1">
<object class="GtkUIManager" id="UIManager">
<child>
<object class="GtkActionGroup" id="actiongroup1">
<child>
<object class="GtkAction" id="MenuItem.File">
<property name="name">MenuItem.File</property>
<object class="GtkAction" id="Action.File">
<property name="name">Action.File</property>
<property name="label">_File</property>
</object>
</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="name">MenuItem.File.New</property>
<property name="name">Action.File.New</property>
</object>
</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="name">MenuItem.File.Open</property>
<property name="name">Action.File.Open</property>
</object>
</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="name">MenuItem.File.Save</property>
<property name="name">Action.File.Save</property>
</object>
</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="name">MenuItem.File.SaveAs</property>
<property name="name">Action.File.SaveAs</property>
</object>
</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="name">MenuItem.File.Quit</property>
<property name="name">Action.File.Quit</property>
</object>
</child>
<child>
<object class="GtkAction" id="MenuItem.Edit">
<property name="name">MenuItem.Edit</property>
<object class="GtkAction" id="Action.Edit">
<property name="name">Action.Edit</property>
<property name="label">_Edit</property>
</object>
</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="name">MenuItem.Edit.Preferences</property>
<property name="name">Action.Edit.Preferences</property>
</object>
</child>
<child>
<object class="GtkAction" id="MenuItem.View">
<property name="name">MenuItem.View</property>
<object class="GtkAction" id="Action.View">
<property name="name">Action.View</property>
<property name="label">_View</property>
</object>
</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="name">MenuItem.View.ShowThreads</property>
<property name="name">Action.View.ShowThreads</property>
</object>
</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="name">MenuItem.View.ShowHoltGraph</property>
<property name="name">Action.View.ShowHoltGraph</property>
</object>
</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="name">MenuItem.View.ShowStatistics</property>
<property name="name">Action.View.ShowStatistics</property>
</object>
</child>
<child>
<object class="GtkAction" id="MenuItem.Simulation">
<property name="name">MenuItem.Simulation</property>
<object class="GtkAction" id="Action.Simulation">
<property name="name">Action.Simulation</property>
<property name="label">_Simulation</property>
</object>
</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="name">MenuItem.Simulation.Play</property>
<property name="name">Action.Simulation.Play</property>
</object>
<accelerator key="F5" modifiers=""/>
</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="name">MenuItem.Simulation.Pause</property>
<property name="name">Action.Simulation.Pause</property>
</object>
<accelerator key="F6" modifiers=""/>
</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="name">MenuItem.Simulation.Stop</property>
<property name="name">Action.Simulation.Stop</property>
<signal handler="on_stop1_activate" name="activate"/>
</object>
<accelerator key="F7" modifiers=""/>
</child>
<child>
<object class="GtkToggleAction" id="MenuItem.Simulation.ContinuousMode">
<object class="GtkToggleAction" id="Action.Simulation.ContinuousMode">
<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>
</object>
</child>
<child>
<object class="GtkAction" id="MenuItem.Help">
<property name="name">MenuItem.Help</property>
<object class="GtkAction" id="Action.Help">
<property name="name">Action.Help</property>
<property name="label">_Help</property>
</object>
</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="name">MenuItem.Help.About</property>
<property name="name">Action.Help.About</property>
</object>
</child>
</object>
</child>
<ui>
<menubar name="MenuBar">
<menu action="MenuItem.File">
<menuitem action="MenuItem.File.New"/>
<menuitem action="MenuItem.File.Open"/>
<menuitem action="MenuItem.File.Save"/>
<menuitem action="MenuItem.File.SaveAs"/>
<menu action="Action.File">
<menuitem action="Action.File.New"/>
<menuitem action="Action.File.Open"/>
<menuitem action="Action.File.Save"/>
<menuitem action="Action.File.SaveAs"/>
<separator/>
<menuitem action="MenuItem.File.Quit"/>
<menuitem action="Action.File.Quit"/>
</menu>
<menu action="MenuItem.Edit">
<menuitem action="MenuItem.Edit.Preferences"/>
<menu action="Action.Edit">
<menuitem action="Action.Edit.Preferences"/>
</menu>
<menu action="MenuItem.View">
<menuitem action="MenuItem.View.ShowThreads"/>
<menuitem action="MenuItem.View.ShowHoltGraph"/>
<menuitem action="MenuItem.View.ShowStatistics"/>
<menu action="Action.View">
<menuitem action="Action.View.ShowThreads"/>
<menuitem action="Action.View.ShowHoltGraph"/>
<menuitem action="Action.View.ShowStatistics"/>
</menu>
<menu action="MenuItem.Simulation">
<menuitem action="MenuItem.Simulation.Play"/>
<menuitem action="MenuItem.Simulation.Pause"/>
<menuitem action="MenuItem.Simulation.Stop"/>
<menu action="Action.Simulation">
<menuitem action="Action.Simulation.Play"/>
<menuitem action="Action.Simulation.Pause"/>
<menuitem action="Action.Simulation.Stop"/>
<separator/>
<menuitem action="MenuItem.Simulation.ContinuousMode"/>
<menuitem action="Action.Simulation.ContinuousMode"/>
</menu>
<menu action="MenuItem.Help">
<menuitem action="MenuItem.Help.About"/>
<menu action="Action.Help">
<menuitem action="Action.Help.About"/>
</menu>
</menubar>
</ui>
@ -178,7 +177,7 @@
<object class="GtkVBox" id="MainBox">
<property name="visible">True</property>
<child>
<object class="GtkMenuBar" constructor="uimanager1" id="MenuBar">
<object class="GtkMenuBar" constructor="UIManager" id="MenuBar">
<property name="visible">True</property>
</object>
<packing>