diff --git a/glade/add-request-dialog.glade b/glade/add-request-dialog.glade index 74aff21..898e5f9 100644 --- a/glade/add-request-dialog.glade +++ b/glade/add-request-dialog.glade @@ -1,218 +1,320 @@ - - - + + + - - 300 - 240 - Add Request - True - GTK_WIN_POS_MOUSE - GDK_WINDOW_TYPE_HINT_DIALOG - - - True - - - True - 4 - 6 - - - True - 6 - - - True - 0,000000 - 0,000000 - Instant - - - False - False - - - - - True - True - 0,000000 0,000000 0,000000 1,000000 0,000000 0,000000 - 1 - True - - - 1 - - - - - False - False - - - - - 200 - True - True - GTK_POLICY_NEVER - GTK_POLICY_AUTOMATIC - GTK_SHADOW_IN - - - 100 - True - True - True - - - - - 1 - - - - - True - 2 - 2 - 6 - 6 - - - True - 0,000000 - 0,000000 - Duration - - - 1 - 2 - - - - - - - True - 0,000000 - 0,000000 - Resource - - - - - - - - - True - True - 0,000000 1,000000 0,000000 1,000000 0,000000 0,000000 - 1 - True - - - 1 - 2 - 1 - 2 - - - - - - True - - - 1 - 2 - - - - - - - False - False - 2 - - - - - True - 6 - GTK_BUTTONBOX_SPREAD - - - True - True - gtk-add - True - - - - - True - gtk-remove - True - - - 1 - - - - - False - 3 - - - - - 2 - - - - - True - GTK_BUTTONBOX_SPREAD - - - True - True - True - gtk-cancel - True - -6 - - - - - True - True - True - True - gtk-ok - True - -5 - - - 1 - - - - - False - GTK_PACK_END - - - - - + + + 300 + 240 + Add Request + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_MOUSE + True + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + False + True + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_SPREAD + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 4 + True + False + 6 + + + + True + False + 6 + + + + True + Instant + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + True + 1 + 0 + True + GTK_UPDATE_ALWAYS + False + False + 0 0 inf 1 0 0 + + + 0 + True + True + + + + + 0 + False + False + + + + + + 200 + True + True + GTK_POLICY_NEVER + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + 100 + True + True + True + False + True + True + False + False + False + + + + + 0 + True + True + + + + + + True + 2 + 2 + False + 6 + 6 + + + + True + Duration + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 1 + 2 + + + + + + + + True + Resource + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + + + + + + + + True + True + 1 + 0 + True + GTK_UPDATE_ALWAYS + False + False + 1 1 inf 1 0 0 + + + 1 + 2 + 1 + 2 + + + + + + + True + False + True + + + 1 + 2 + 0 + 1 + fill + + + + + + 0 + False + False + + + + + + 6 + True + GTK_BUTTONBOX_SPREAD + 0 + + + + True + True + gtk-add + True + GTK_RELIEF_NORMAL + True + + + + + + True + gtk-remove + True + GTK_RELIEF_NORMAL + True + + + + + 0 + False + True + + + + + 0 + True + True + + + + + + diff --git a/glade/add-resource-dialog.glade b/glade/add-resource-dialog.glade index 3c54b56..670d9f0 100644 --- a/glade/add-resource-dialog.glade +++ b/glade/add-resource-dialog.glade @@ -103,30 +103,6 @@ - - - True - True - GTK_RELIEF_NORMAL - True - False - False - True - - - - - - - 1 - 2 - 3 - 4 - - - - - True @@ -274,6 +250,30 @@ + + + + True + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + + + + 1 + 2 + 3 + 4 + fill + + + 0 diff --git a/src/backend/concrete_history.cc b/src/backend/concrete_history.cc index fb2a379..32cd497 100644 --- a/src/backend/concrete_history.cc +++ b/src/backend/concrete_history.cc @@ -174,7 +174,7 @@ ConcreteHistory::remove(resource_key_t resource_key) for (Threads::iterator it2 = threads.begin(); it2 != threads.end(); it2++) { Requests& reqs = (*it2)->get_dynamic_requests(); - for (Requests::iterator it3 = reqs.begin(); it3 != reqs.end(); it3++) + for (Requests::iterator it3 = reqs.begin(); it3 != reqs.end();) { SubRequests& subr = (*it3)->get_dynamic_subrequests(); SubRequests::iterator it4 = subr.begin(); @@ -186,6 +186,12 @@ ConcreteHistory::remove(resource_key_t resource_key) } else it4++; + + // erase empty requests + if(subr.size() == 0) + it3 = reqs.erase(it3); + else + ++it3; } } } //~ end monstrous construct, "The Thing That Should Not Be" diff --git a/src/resources_widget.cc b/src/resources_widget.cc index 387b1a4..af1d5b7 100644 --- a/src/resources_widget.cc +++ b/src/resources_widget.cc @@ -68,17 +68,18 @@ ResourcesWidget::~ResourcesWidget() Simulation::get_instance().get_history().detach(*this); } -sgpem::Resource* -ResourcesWidget::get_selected_resource() +bool +ResourcesWidget::get_selected_key(unsigned int& selection) { - TreeModel::iterator sel = get_selection()->get_selected(); + TreeModel::iterator it = get_selection()->get_selected(); - if(!sel) - return NULL; - - const void* p_handle = (*sel)[_handles_column]; - - return reinterpret_cast(const_cast(p_handle)); + if(it) + { + selection = (*it)[_key_column]; + return true; + } + else + return false; } bool @@ -93,14 +94,24 @@ ResourcesWidget::on_button_press_event(GdkEventButton* event) action_group->add( Gtk::Action::create("AddResource", "Add Resource"), sigc::mem_fun(*this, &ResourcesWidget::_on_add_resource) ); + action_group->add( Gtk::Action::create("RemoveResource", "Remove Resource"), + sigc::mem_fun(*this, &ResourcesWidget::_on_remove_resource) ); + RefPtr UIManager = Gtk::UIManager::create(); UIManager->insert_action_group(action_group); + unsigned int selection; Glib::ustring ui_info = "" " " - " " - " " + " "; + if(get_selected_key(selection)) + ui_info += + " " + " "; + + ui_info += + " " ""; UIManager->add_ui_from_string(ui_info); @@ -160,3 +171,10 @@ ResourcesWidget::_on_add_resource() _add_resource_dialog->hide(); } +void +ResourcesWidget::_on_remove_resource() +{ + unsigned int selection; + if(get_selected_key(selection)) + Simulation::get_instance().get_history().remove(selection); +} diff --git a/src/resources_widget.hh b/src/resources_widget.hh index 20e9d6f..188fcfb 100644 --- a/src/resources_widget.hh +++ b/src/resources_widget.hh @@ -51,9 +51,10 @@ namespace sgpem bool on_button_press_event(GdkEventButton* event); private: - Resource* get_selected_resource(); + bool get_selected_key(unsigned int& selection); void _on_add_resource(); + void _on_remove_resource(); Glib::RefPtr _model; Gtk::TreeModelColumnRecord _columns;