- Improvements to the schedulables widget, now the menu is context-sensitive

- Started work on the add-request-dialog derived widget, it`s not so difficult as I first thinked...

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@909 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-08-19 00:09:36 +00:00
parent e4c269f5d4
commit dd40bac86c
5 changed files with 272 additions and 50 deletions

View file

@ -57,39 +57,12 @@ SchedulablesTreeWidget::SchedulablesTreeWidget() :
// append_column("handles", _types_column);
// append_column("handles", _handles_column);
/** POPUP MENU **/
_action_group = Gtk::ActionGroup::create();
_action_group->add( Gtk::Action::create("AddProcess", "Add Process"),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_process) );
_action_group->add( Gtk::Action::create("AddThread", "Add Thread"),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_thread) );
_action_group->add( Gtk::Action::create("AddRequest", "Add Request"),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_request) );
_UIManager = Gtk::UIManager::create();
_UIManager->insert_action_group(_action_group);
Glib::ustring ui_info =
"<ui>"
" <popup name='PopupMenu'>"
" <menuitem action='AddProcess'/>"
" <menuitem action='AddThread'/>"
" <menuitem action='AddRequest'/>"
" </popup>"
"</ui>";
_UIManager->add_ui_from_string(ui_info);
_menu = dynamic_cast<Gtk::Menu*>(_UIManager->get_widget("/PopupMenu"));
/** DIALOGS **/
_add_process_dialog_glade->get_widget("AddProcessDialog", _add_process_dialog);
_add_thread_dialog_glade->get_widget("AddThreadDialog", _add_thread_dialog);
// TODO use a derived widget
_add_request_dialog_glade->get_widget("AddRequestDialog", _add_request_dialog);
set_headers_visible(false);
Simulation::get_instance().get_history().attach(*this);
@ -100,6 +73,40 @@ SchedulablesTreeWidget::~SchedulablesTreeWidget()
Simulation::get_instance().get_history().detach(*this);
}
sgpem::Process*
SchedulablesTreeWidget::get_selected_process()
{
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_process)
return NULL;
return reinterpret_cast<Process*>(const_cast<void*>(p_handle));
}
sgpem::Thread*
SchedulablesTreeWidget::get_selected_thread()
{
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));
}
bool
SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event)
{
@ -107,7 +114,38 @@ SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event)
if( (event->type == GDK_BUTTON_PRESS) && (event->button == 3) )
{
_menu->popup(event->button, event->time);
RefPtr<ActionGroup> action_group = Gtk::ActionGroup::create();
action_group->add( Gtk::Action::create("AddProcess", "Add Process"),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_process) );
action_group->add( Gtk::Action::create("AddThread", "Add Thread"),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_thread) );
action_group->add( Gtk::Action::create("AddRequest", "Add Request"),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_request) );
RefPtr<UIManager> UIManager = Gtk::UIManager::create();
UIManager->insert_action_group(action_group);
Glib::ustring ui_info =
"<ui>"
" <popup name='PopupMenu'>"
" <menuitem action='AddProcess'/>";
if(get_selected_process() != NULL)
ui_info +=
" <menuitem action='AddThread'/>";
if(get_selected_thread() != NULL)
ui_info +=
" <menuitem action='AddRequest'/>";
ui_info +=
" </popup>"
"</ui>";
UIManager->add_ui_from_string(ui_info);
Gtk::Menu* menu = dynamic_cast<Gtk::Menu*>(UIManager->get_widget("/PopupMenu"));
menu->popup(event->button, event->time);
return true; //It has been handled.
}
else
@ -204,18 +242,22 @@ SchedulablesTreeWidget::_on_add_process()
void
SchedulablesTreeWidget::_on_add_thread()
{
TreeModel::iterator sel = get_selection()->get_selected();
// TreeModel::iterator sel = get_selection()->get_selected();
//
// if(!sel)
// return;
//
// const void* p_handle = (*sel)[_handles_column];
// HandleType type = (*sel)[_types_column];
// Process* p = reinterpret_cast<Process*>(const_cast<void*>(p_handle));
//
// if(p == NULL || type != htype_process)
// return;
if(!sel)
Process* p = get_selected_process();
if(p == NULL)
return;
const void* p_handle = (*sel)[_handles_column];
HandleType type = (*sel)[_types_column];
Process* p = reinterpret_cast<Process*>(const_cast<void*>(p_handle));
if(p == NULL || type != htype_process)
return;
if(_add_thread_dialog->run() == RESPONSE_OK)
{
Entry* name_entry;
@ -242,16 +284,20 @@ SchedulablesTreeWidget::_on_add_thread()
void
SchedulablesTreeWidget::_on_add_request()
{
TreeModel::iterator sel = get_selection()->get_selected();
// TreeModel::iterator sel = get_selection()->get_selected();
//
// if(!sel)
// return;
//
// const void* p_handle = (*sel)[_handles_column];
// HandleType type = (*sel)[_types_column];
// Thread* t = reinterpret_cast<Thread*>(const_cast<void*>(p_handle));
//
// if(t == NULL || type != htype_thread)
// return;
Thread* t = get_selected_thread();
if(!sel)
return;
const void* p_handle = (*sel)[_handles_column];
HandleType type = (*sel)[_types_column];
Thread* t = reinterpret_cast<Thread*>(const_cast<void*>(p_handle));
if(t == NULL || type != htype_thread)
if(t == NULL)
return;
if(_add_request_dialog->run() == RESPONSE_OK)