- Fixed bug causing crash on adding a resource after simulation is terminated. A workaround was used, it was caused by Simulation::get_front() returning a wrong value.

- Other minor improvements to the ResourceWidget

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@988 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-09-02 00:20:24 +00:00
parent d570314405
commit f617c51a87
2 changed files with 14 additions and 12 deletions

View File

@ -95,12 +95,12 @@ ResourcesWidget::get_selected_key(unsigned int& selection)
Resource* Resource*
ResourcesWidget::get_selected_resource() ResourcesWidget::get_selected_resource()
{ {
unsigned int key; TreeModel::iterator it = get_selection()->get_selected();
if(get_selected_key(key))
if(it)
{ {
Simulation& sim = Simulation::get_instance(); const void* r_handle = (*it)[_handles_column];
const Environment& env = sim.get_history().get_environment_at(sim.get_front()); return reinterpret_cast<Resource*>(const_cast<void*>(r_handle));
return env.get_resources().find(key)->second;
} }
else else
return NULL; return NULL;
@ -111,7 +111,8 @@ ResourcesWidget::on_button_press_event(GdkEventButton* event)
{ {
TreeView::on_button_press_event(event); TreeView::on_button_press_event(event);
if((event->type == GDK_BUTTON_PRESS) && (event->button == 3) ) if((Simulation::get_instance().get_state() == Simulation::state_stopped) &&
(event->type == GDK_BUTTON_PRESS) && (event->button == 3) )
{ {
RefPtr<ActionGroup> action_group = Gtk::ActionGroup::create(); RefPtr<ActionGroup> action_group = Gtk::ActionGroup::create();
@ -127,12 +128,11 @@ ResourcesWidget::on_button_press_event(GdkEventButton* event)
RefPtr<UIManager> UIManager = Gtk::UIManager::create(); RefPtr<UIManager> UIManager = Gtk::UIManager::create();
UIManager->insert_action_group(action_group); UIManager->insert_action_group(action_group);
unsigned int selection;
Glib::ustring ui_info = Glib::ustring ui_info =
"<ui>" "<ui>"
" <popup name='PopupMenu'>" " <popup name='PopupMenu'>"
" <menuitem action='AddResource'/>"; " <menuitem action='AddResource'/>";
if(get_selected_key(selection)) if(get_selected_resource() != NULL)
ui_info += ui_info +=
" <separator/>" " <separator/>"
" <menuitem action='EditResource'/>" " <menuitem action='EditResource'/>"
@ -157,8 +157,7 @@ void
ResourcesWidget::update(const History& history) ResourcesWidget::update(const History& history)
{ {
typedef Environment::Resources::const_iterator ResourceIt; typedef Environment::Resources::const_iterator ResourceIt;
const Environment::Resources& resources = const Environment::Resources& resources = history.get_last_environment().get_resources();
Simulation::get_instance().get_history().get_last_environment().get_resources();
_model->clear(); _model->clear();
@ -279,8 +278,10 @@ ResourcesWidget::_on_cell_name_data(Gtk::CellRenderer* cr,
unsigned int key = (*it)[_key_column]; unsigned int key = (*it)[_key_column];
Simulation& sim = Simulation::get_instance(); Simulation& sim = Simulation::get_instance();
const Environment& env = sim.get_history().get_environment_at(sim.get_front()); const Environment& env = sim.get_history().get_last_environment();
Resource& resource = *(env.get_resources().find(key)->second);
const void* r_handle = (*it)[_handles_column];
Resource& resource = *reinterpret_cast<Resource*>(const_cast<void*>(r_handle));
std::ostringstream oss; std::ostringstream oss;

View File

@ -341,6 +341,7 @@ SchedulablesTreeWidget::update(const History& history)
// We can clear it now, since until next update we won't need it. // We can clear it now, since until next update we won't need it.
_expanded_rows.clear(); _expanded_rows.clear();
} }
void void