- Now everything can be removed!

- Reverted the patch to ConcreteSimulation, I was trying to make it do what ought to be done in the frontend, and now the frontend does it

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@927 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-08-21 23:44:18 +00:00
parent 82b4105519
commit 495896597c
4 changed files with 187 additions and 33 deletions

View file

@ -75,8 +75,47 @@ SchedulablesTreeWidget::~SchedulablesTreeWidget()
Simulation::get_instance().get_history().detach(*this);
}
sgpem::Process*
SchedulablesTreeWidget::get_selected_process()
template <typename T>
bool
SchedulablesTreeWidget::check_type(SchedulablesTreeWidget::HandleType type)
{
return false;
}
namespace sgpem
{
template <>
bool
SchedulablesTreeWidget::check_type<Process>(HandleType type)
{
return type == htype_process;
}
template <>
bool
SchedulablesTreeWidget::check_type<Thread>(HandleType type)
{
return type == htype_thread;
}
template <>
bool
SchedulablesTreeWidget::check_type<Request>(HandleType type)
{
return type == htype_request;
}
template <>
bool
SchedulablesTreeWidget::check_type<SubRequest>(HandleType type)
{
return type == htype_subrequest;
}
}
template <typename T>
T*
SchedulablesTreeWidget::get_selected()
{
TreeModel::iterator sel = get_selection()->get_selected();
@ -86,27 +125,21 @@ SchedulablesTreeWidget::get_selected_process()
const void* p_handle = (*sel)[_handles_column];
HandleType type = (*sel)[_types_column];
if(type != htype_process)
if(!check_type<T>(type))
return NULL;
return reinterpret_cast<Process*>(const_cast<void*>(p_handle));
return reinterpret_cast<T*>(const_cast<void*>(p_handle));
}
sgpem::Thread*
SchedulablesTreeWidget::get_selected_thread()
SchedulablesTreeWidget::HandleType
SchedulablesTreeWidget::get_selection_type()
{
TreeModel::iterator sel = get_selection()->get_selected();
if(!sel)
return NULL;
const void* p_handle = (*sel)[_handles_column];
HandleType type = (*sel)[_types_column];
if(type != htype_thread)
return NULL;
return reinterpret_cast<Thread*>(const_cast<void*>(p_handle));
return htype_undefined;
else
return (*sel)[_types_column];
}
bool
@ -127,19 +160,60 @@ SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event)
action_group->add( Gtk::Action::create("AddRequest", "Add Request"),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_request) );
action_group->add( Gtk::Action::create("RemoveProcess", "Remove Process"),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_process) );
action_group->add( Gtk::Action::create("RemoveThread", "Remove Thread"),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_thread) );
action_group->add( Gtk::Action::create("RemoveRequest", "Remove Request"),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_request) );
action_group->add( Gtk::Action::create("RemoveSubrequest", "Remove Subrequest"),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_subrequest) );
RefPtr<UIManager> UIManager = Gtk::UIManager::create();
UIManager->insert_action_group(action_group);
const HandleType selection_type = get_selection_type();
Glib::ustring ui_info =
"<ui>"
" <popup name='PopupMenu'>"
" <menuitem action='AddProcess'/>";
if(get_selected_process() != NULL)
ui_info +=
" <popup name='PopupMenu'>";
if(selection_type == htype_process)
ui_info +=
" <menuitem action='AddThread'/>";
if(get_selected_thread() != NULL)
else if(selection_type == htype_thread)
ui_info +=
" <menuitem action='AddRequest'/>";
ui_info +=
" <menuitem action='AddProcess'/>";
if(selection_type != htype_undefined)
ui_info +=
" <separator/>";
switch(selection_type)
{
case htype_process:
ui_info +=
" <menuitem action='RemoveProcess'/>";
break;
case htype_thread:
ui_info +=
" <menuitem action='RemoveThread'/>";
break;
case htype_request:
ui_info +=
" <menuitem action='RemoveRequest'/>";
break;
case htype_subrequest:
ui_info +=
" <menuitem action='RemoveSubrequest'/>";
}
ui_info +=
" </popup>"
"</ui>";
@ -244,7 +318,7 @@ SchedulablesTreeWidget::_on_add_process()
void
SchedulablesTreeWidget::_on_add_thread()
{
Process* p = get_selected_process();
Process* p = get_selected<Process>();
if(p == NULL)
return;
@ -274,7 +348,7 @@ SchedulablesTreeWidget::_on_add_thread()
void
SchedulablesTreeWidget::_on_add_request()
{
Thread* t = get_selected_thread();
Thread* t = get_selected<Thread>();
if(t == NULL)
return;
@ -284,3 +358,46 @@ SchedulablesTreeWidget::_on_add_request()
_add_request_dialog->hide();
}
void
SchedulablesTreeWidget::_on_remove_process()
{
Process* p = get_selected<Process>();
assert(p != NULL);
Simulation::get_instance().get_history().remove(*p);
}
void
SchedulablesTreeWidget::_on_remove_thread()
{
Thread* t = get_selected<Thread>();
assert(t != NULL);
Simulation::get_instance().get_history().remove(*t);
}
void
SchedulablesTreeWidget::_on_remove_request()
{
Request* r = get_selected<Request>();
assert(r != NULL);
Simulation::get_instance().get_history().remove(*r);
}
void
SchedulablesTreeWidget::_on_remove_subrequest()
{
SubRequest* sr = get_selected<SubRequest>();
assert(sr != NULL);
Request& owner = sr->get_request();
Simulation::get_instance().get_history().remove(*sr);
// empty requests are COMPLETELY useless with the current GUI
if(owner.get_subrequests().empty())
Simulation::get_instance().get_history().remove(owner);
}