// src/resources_widget.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 RESOURCES_WIDGET_HH
#define RESOURCES_WIDGET_HH 1

namespace sgpem
{
  class Resource;
}

#include "config.h"

#include <gtkmm/treeview.h>
#include <gtkmm/liststore.h>
#include <gtkmm/menu.h>
#include <gtkmm/uimanager.h>
#include <gtkmm/actiongroup.h>
#include <gtkmm/dialog.h>
#include <libglademm/xml.h>

#include <sgpemv2/history_observer.hh>

namespace sgpem
{
  class ResourcesWidget : public Gtk::TreeView, public HistoryObserver
  {
  public:
    ResourcesWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& glade);
    virtual ~ResourcesWidget();

    virtual void update(const History& history);
    
    bool on_button_press_event(GdkEventButton* event);

  private:
    class CellRendererTextMarkup : public Gtk::CellRendererText
    {
      public:
	Glib::PropertyProxy_Base _property_renderable();
    };

    bool get_selected_key(unsigned int& selection);
    
    Resource* get_selected_resource();

    void _on_add_resource();
    void _on_edit_resource();
    void add_edit_resource(bool adding);
    
    void _on_remove_resource();
    
    void _on_cell_name_data(Gtk::CellRenderer* cr, 
                            const Gtk::TreeModel::iterator& it);
    
    Glib::RefPtr<Gtk::ListStore> _model;
    Gtk::TreeModelColumnRecord _columns;
    Gtk::TreeModelColumn<unsigned int> _key_column;
    Gtk::TreeModelColumn<Glib::ustring> _main_column;
    Gtk::TreeModelColumn<void*> _handles_column;
    
    Glib::RefPtr<Gtk::UIManager> _UIManager;
    Glib::RefPtr<Gnome::Glade::Xml> _add_resource_dialog_glade;
    Gtk::Dialog* _add_resource_dialog;

    CellRendererTextMarkup _cell_renderer;
  };

} //~ namespace sgpem


#endif //~ RESOURCES_WIDGET_HH
