- Experimented a bit more with the treeview widget, with little success, It should segfault on selection of the menu entry "Add Process"

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@869 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-08-15 00:43:34 +00:00
parent 45ef305a1b
commit 047f0b8f86
4 changed files with 60 additions and 18 deletions

View File

@ -29,3 +29,6 @@ UserInterruptException::UserInterruptException(const char* msg)
: CPUPolicyException(msg)
{}
UserInterruptException::UserInterruptException(const std::string& msg)
: CPUPolicyException(msg)
{}

View File

@ -38,6 +38,7 @@ namespace sgpem
{
public:
explicit UserInterruptException(const char* msg = "");
explicit UserInterruptException(const std::string& msg = "");
};
} //~ namespace sgpem

View File

@ -19,8 +19,16 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "schedulables_tree_widget.hh"
#include "templates/sequences.tcc"
#include "backend/history.hh"
#include "backend/simulation.hh"
#include "backend/process.hh"
#include <iostream>
#include <gtk/gtk.h>
#include <gtkmm/entry.h>
#include <gtkmm/spinbutton.h>
using namespace sgpem;
using namespace Gtk;
@ -30,20 +38,23 @@ using Gnome::Glade::Xml;
SchedulablesTreeWidget::SchedulablesTreeWidget() :
_add_process_dialog_glade(Xml::create(GLADEDIR "/add-process-dialog.glade"))
{
_columns.add(_column);
_columns.add(_main_column);
_columns.add(_handles_column);
_model = TreeStore::create(_columns);
set_model(_model);
/** JUST A BIT OF DATA FOR TESTING **/
Gtk::TreeModel::Row row1 = *(_model->append());
row1[_column] = ustring("ciccio");
//Gtk::TreeModel::Row row1 = *(_model->append());
//row1[_main_column] = ustring("ciccio");
Gtk::TreeModel::Row row2 = *(_model->append());
row2[_column] = ustring("pippo");
// Gtk::TreeModel::Row row2 = *(_model->append());
// row2[_main_column] = ustring("pippo");
append_column("schedulables", _column);
append_column("schedulables", _main_column);
//invisible
// append_column("handles", _handles_column);
/** POPUP MENU **/
@ -77,9 +88,17 @@ SchedulablesTreeWidget::SchedulablesTreeWidget() :
_add_process_dialog->hide();
set_headers_visible(false);
Simulation::get_instance().get_history().attach(*this);
}
bool SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event)
SchedulablesTreeWidget::~SchedulablesTreeWidget()
{
Simulation::get_instance().get_history().detach(*this);
}
bool
SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event)
{
TreeView::on_button_press_event(event);
@ -92,25 +111,43 @@ bool SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event)
return false;
}
SchedulablesTreeWidget::~SchedulablesTreeWidget()
{}
void
SchedulablesTreeWidget::update(const History& history)
{
const Environment::Processes& processes =
Simulation::get_instance().get_history().get_last_environment().get_processes();
_model.clear();
for(unsigned int i = 0; i < processes.size(); ++i)
{
Process& p = *processes[i];
TreeModel::Row row = *(_model->append());
row[_main_column] = p.get_name();
row[_handles_column] = &p;
}
}
void
SchedulablesTreeWidget::_on_add_process()
{
switch(_add_process_dialog->run())
if(_add_process_dialog->run() == RESPONSE_OK)
{
case RESPONSE_OK:
std::cout << "added the process ;-)\n";
break;
default:
std::cout << "operation cancelled ;-)\n";
Entry* name_entry;
SpinButton* arrival_time_spin;
SpinButton* base_priority_spin;
_add_process_dialog_glade->get_widget("Name.Entry", name_entry);
_add_process_dialog_glade->get_widget("ArrivalTime.Spin", arrival_time_spin);
_add_process_dialog_glade->get_widget("BasePriority.Spin", base_priority_spin);
Simulation::get_instance().get_history().add_process(name_entry->get_text(),
arrival_time_spin->get_value_as_int(),
base_priority_spin->get_value_as_int());
}
_add_process_dialog->hide();
}

View File

@ -54,7 +54,8 @@ namespace sgpem
Glib::RefPtr<Gtk::TreeStore> _model;
Gtk::TreeModelColumnRecord _columns;
Gtk::TreeModelColumn<Glib::ustring> _column;
Gtk::TreeModelColumn<Glib::ustring> _main_column;
Gtk::TreeModelColumn<void*> _handles_column;
Glib::RefPtr<Gtk::ActionGroup> _action_group;
Glib::RefPtr<Gtk::UIManager> _UIManager;
Gtk::Menu* _menu;