- 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:
parent
e4c269f5d4
commit
dd40bac86c
|
@ -292,6 +292,7 @@ sgpemv2_LDADD = \
|
|||
|
||||
# Please keep this in sorted order:
|
||||
sgpemv2_SOURCES = \
|
||||
src/add_request_dialog.cc \
|
||||
src/cairo_elements.cc \
|
||||
src/cairo_widget.cc \
|
||||
src/graphical_preferences_editor.cc \
|
||||
|
@ -303,6 +304,7 @@ sgpemv2_SOURCES = \
|
|||
src/text_simulation.cc
|
||||
|
||||
noinst_HEADERS += \
|
||||
src/add_request_dialog.hh \
|
||||
src/cairo_elements.hh \
|
||||
src/cairo_widget.hh \
|
||||
src/graphical_preferences_editor.hh \
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
// src/add_request_dialog.cc - Copyright 2005, 2006, University
|
||||
// of Padova, dept. of Pure and Applied
|
||||
// Mathematics
|
||||
//
|
||||
// This file is part of SGPEMv2.
|
||||
//
|
||||
// This is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// SGPEMv2 is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with SGPEMv2; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
#include "add_request_dialog.hh"
|
||||
#include "templates/sequences.tcc"
|
||||
#include "backend/history.hh"
|
||||
#include "backend/environment.hh"
|
||||
#include "backend/simulation.hh"
|
||||
#include "backend/resource.hh"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "gettext.h"
|
||||
|
||||
using namespace sgpem;
|
||||
using namespace Gtk;
|
||||
using namespace Glib;
|
||||
using Gnome::Glade::Xml;
|
||||
|
||||
AddRequestDialog::AddRequestDialog(BaseObjectType* cobject, const RefPtr<Xml>& glade) :
|
||||
Dialog(cobject)
|
||||
{
|
||||
glade->get_widget("SubRequests.View", _list);
|
||||
glade->get_widget("Add", _add_button);
|
||||
glade->get_widget("Add", _remove_button);
|
||||
glade->get_widget("Resource.Combo", _resource_combo);
|
||||
|
||||
/** ATTACH SIGNAL HANDLERS FOR BUTTONS **/
|
||||
|
||||
_add_button->signal_clicked().connect(sigc::mem_fun(*this, &AddRequestDialog::_on_add));
|
||||
_remove_button->signal_clicked().connect(sigc::mem_fun(*this, &AddRequestDialog::_on_remove));
|
||||
|
||||
/** INITIALIZE COMBOBOX **/
|
||||
_combo_columns.add(_combo_key_column);
|
||||
_combo_columns.add(_combo_resource_column);
|
||||
|
||||
_combo_model = ListStore::create(_combo_columns);
|
||||
_resource_combo->set_model(_combo_model);
|
||||
|
||||
/** INITIALIZE LISTVIEW **/
|
||||
|
||||
_list_columns.add(_list_resource_column);
|
||||
_list_columns.add(_list_length_column);
|
||||
|
||||
_list_model = ListStore::create(_list_columns);
|
||||
_list->set_model(_list_model);
|
||||
|
||||
_list->append_column(_("resource"), _list_resource_column);
|
||||
_list->append_column(_("length"), _list_length_column);
|
||||
}
|
||||
|
||||
void
|
||||
AddRequestDialog::on_show()
|
||||
{
|
||||
typedef Environment::Resources::const_iterator ResourceIt;
|
||||
|
||||
Dialog::on_show();
|
||||
|
||||
const Environment::Resources& resources =
|
||||
Simulation::get_instance().get_history().get_last_environment().get_resources();
|
||||
|
||||
_combo_model->clear();
|
||||
|
||||
for(Iseq<ResourceIt> it = const_iseq(resources); it; ++it)
|
||||
{
|
||||
TreeModel::Row row = *(_combo_model->append());
|
||||
row[_combo_key_column] = it->first;
|
||||
row[_combo_resource_column] = it->second->get_name();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AddRequestDialog::_on_add()
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
void
|
||||
AddRequestDialog::_on_remove()
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
// src/add_request_dialog.hh - Copyright 2005, 2006, University
|
||||
// of Padova, dept. of Pure and Applied
|
||||
// Mathematics
|
||||
//
|
||||
// This file is part of SGPEMv2.
|
||||
//
|
||||
// This is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// SGPEMv2 is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with SGPEMv2; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
#ifndef ADD_REQUEST_DIALOG_HH
|
||||
#define ADD_REQUEST_DIALOG_HH 1
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gtkmm/treeview.h>
|
||||
#include <gtkmm/liststore.h>
|
||||
#include <gtkmm/dialog.h>
|
||||
#include <gtkmm/combobox.h>
|
||||
#include <libglademm/xml.h>
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
class AddRequestDialog : public Gtk::Dialog
|
||||
{
|
||||
public:
|
||||
AddRequestDialog(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& glade);
|
||||
|
||||
protected:
|
||||
virtual void on_show();
|
||||
|
||||
private:
|
||||
void _on_add();
|
||||
void _on_remove();
|
||||
|
||||
Gtk::TreeView* _list;
|
||||
Glib::RefPtr<Gtk::ListStore> _list_model;
|
||||
Gtk::TreeModelColumnRecord _list_columns;
|
||||
Gtk::TreeModelColumn<Glib::ustring> _list_resource_column;
|
||||
Gtk::TreeModelColumn<unsigned int> _list_length_column;
|
||||
|
||||
Gtk::Button* _add_button;
|
||||
Gtk::Button* _remove_button;
|
||||
|
||||
Gtk::ComboBox* _resource_combo;
|
||||
Glib::RefPtr<Gtk::ListStore> _combo_model;
|
||||
Gtk::TreeModelColumnRecord _combo_columns;
|
||||
Gtk::TreeModelColumn<unsigned int> _combo_key_column;
|
||||
Gtk::TreeModelColumn<Glib::ustring> _combo_resource_column;
|
||||
};
|
||||
|
||||
} //~ namespace sgpem
|
||||
|
||||
|
||||
#endif //~ ADD_REQUEST_DIALOG_HH
|
|
@ -57,37 +57,10 @@ 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);
|
||||
|
@ -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,16 +242,20 @@ 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)
|
||||
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)
|
||||
Process* p = get_selected_process();
|
||||
if(p == NULL)
|
||||
return;
|
||||
|
||||
if(_add_thread_dialog->run() == RESPONSE_OK)
|
||||
|
@ -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)
|
||||
|
|
|
@ -21,6 +21,12 @@
|
|||
#ifndef SCHEDULABLES_TREE_WIDGET_HH
|
||||
#define SCHEDULABLES_TREE_WIDGET_HH 1
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
class Process;
|
||||
class Thread;
|
||||
}
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gtkmm/treeview.h>
|
||||
|
@ -49,6 +55,7 @@ namespace sgpem
|
|||
|
||||
bool on_button_press_event(GdkEventButton* event);
|
||||
|
||||
|
||||
private:
|
||||
enum HandleType
|
||||
{
|
||||
|
@ -59,6 +66,9 @@ namespace sgpem
|
|||
htype_undefined
|
||||
};
|
||||
|
||||
Process* get_selected_process();
|
||||
Thread* get_selected_thread();
|
||||
|
||||
void _on_add_process();
|
||||
void _on_add_thread();
|
||||
void _on_add_request();
|
||||
|
@ -68,9 +78,7 @@ namespace sgpem
|
|||
Gtk::TreeModelColumn<Glib::ustring> _main_column;
|
||||
Gtk::TreeModelColumn<HandleType> _types_column;
|
||||
Gtk::TreeModelColumn<void*> _handles_column;
|
||||
Glib::RefPtr<Gtk::ActionGroup> _action_group;
|
||||
Glib::RefPtr<Gtk::UIManager> _UIManager;
|
||||
Gtk::Menu* _menu;
|
||||
Glib::RefPtr<Gnome::Glade::Xml> _add_process_dialog_glade;
|
||||
Glib::RefPtr<Gnome::Glade::Xml> _add_thread_dialog_glade;
|
||||
Glib::RefPtr<Gnome::Glade::Xml> _add_request_dialog_glade;
|
||||
|
|
Loading…
Reference in New Issue