#ifndef _SHELL_VIEW_H_
#define _SHELL_VIEW_H_

#include <gtkmm.h>

#include "treemodel_wrapper.h"

#include "grt/grt_structs_tree.h"

class AutoCompletable;

namespace bec
{
  class GRTManager;
  class ValueTreeBE;
  class ValueInspectorBE;
};

namespace grt
{
  class Message;
};


class ShellCommandView : public Gtk::VBox
{
  Gtk::TextView       _text;
  Gtk::ScrolledWindow _text_scroller;
  Gtk::Entry          _entry;
  AutoCompletable    *_completion;
  Gtk::Label          _prompt;
  
  bec::GRTManager *_grtm;

  void activate_entry();

  bool key_press(GdkEventKey* key);
public:
  ShellCommandView(bec::GRTManager *grtm);
  ~ShellCommandView();

  void setup_shell_handlers();
  
  void handle_prompt(const std::string &text);
  void handle_error(const std::string &text, const std::string &detail);
  void handle_output(const std::string &text);
};


class ShellTreeViews : public sigc::trackable
{
  Gtk::TreeView _value_tree;
  Gtk::TreeView _struct_tree;
  Gtk::TreeView _module_tree;

  Gtk::TreeView _inspector_tree;

  Gtk::ScrolledWindow _value_swin;
  Gtk::ScrolledWindow _struct_swin;
  Gtk::ScrolledWindow _module_swin;

  bec::ValueTreeBE *_value_tree_be;
  bec::ValueInspectorBE *_inspector;
  
  Gtk::ScrolledWindow _inspector_swin;
  
  Gtk::TextView _module_text;
  Gtk::ScrolledWindow _module_text_swin;
  
  Glib::RefPtr<TreeModelWrapper> _structs_model;
  Glib::RefPtr<TreeModelWrapper> _modules_model;
  Glib::RefPtr<TreeModelWrapper> _values_model;

  Glib::RefPtr<ListModelWrapper> _inspector_model;
  
  Glib::RefPtr<Gtk::TextBuffer::Tag> _bold_tag;

  bec::GRTManager *_grtm;

  void value_selected();
  void module_selected();
  
public:
  ShellTreeViews(bec::GRTManager *grtm);

  Gtk::TreeView* get_value_tree() { return &_value_tree; }
  Gtk::TreeView* get_struct_tree() { return &_struct_tree; }
  Gtk::TreeView* get_module_tree() { return &_module_tree; }
  Gtk::TreeView* get_inspector_tree() { return &_inspector_tree; }

  Gtk::ScrolledWindow* get_value_tree_base() { return &_value_swin; }
  Gtk::ScrolledWindow* get_struct_tree_base() { return &_struct_swin; }
  Gtk::ScrolledWindow* get_module_tree_base() { return &_module_swin; }
  Gtk::ScrolledWindow* get_inspector_tree_base() { return &_inspector_swin; }
 
  Gtk::TextView* get_module_text() { return &_module_text; }
  Gtk::ScrolledWindow *get_module_text_base() { return &_module_text_swin; }

  void set_struct_sorting(bec::StructsTreeBE::DisplayMode mode);
  
  void set_globals_tree_path(const std::string &path);
  
  void refresh_all();
};


class ShellView : public Gtk::HPaned
{
  Gtk::Notebook _note;
  
  ShellCommandView _command_view;

  ShellTreeViews _shell_trees;

public:
  ShellView(bec::GRTManager *grtm);
  
  ShellCommandView *get_command_view() { return &_command_view; }
  
  void refresh();
};



#endif
