#include <gtkmm.h>

#include "listmodel_wrapper.h"

#include "grt/grt_manager.h"

#include "shell_view.h"

#include "interfaces/interfaces.h"




void handle_message(const grt::Message &msg, ShellView *shview)
{
  shview->get_command_view()->handle_output(msg.format()+"\n");
}

static Gtk::Window* _main_window(0);
// get_mainwindow is declared in gtk_helpers.h
//------------------------------------------------------------------------------
void* get_mainwindow_impl()
{
  return _main_window;
}


int main(int argc, char **argv)
{
  extern void register_all_metaclasses();
  register_all_metaclasses();
  bool verbose= true;

  Gtk::Main m(argc, argv);
  Gtk::Window window(Gtk::WINDOW_TOPLEVEL);
  _main_window = &window;
  
  window.set_default_size(800,600);

  bec::GRTManager grtm(true, verbose);

  register_interfaces(grtm.get_grt());
  
  ShellView shview(&grtm);

  grtm.set_message_callback(sigc::bind<ShellView*>(sigc::ptr_fun(handle_message), &shview));
  grtm.set_error_callback(sigc::mem_fun(shview.get_command_view(), &ShellCommandView::handle_error));

  bec::IconManager::get_instance()->add_search_path("../../../images/grt");
  bec::IconManager::get_instance()->add_search_path("../../../images/grt/structs");
  grtm.set_search_paths("modules", "structs", "libraries");

  grtm.initialize();

  shview.refresh();
  
  grtm.perform_idle_tasks();
  
  Glib::signal_timeout().connect(sigc::bind_return<bool>(sigc::mem_fun(grtm, &bec::GRTManager::perform_idle_tasks), true), 200);
  
  window.add(shview);
  shview.show();

  //grtm.get_shell()->set_save_directory(options->user_data_dir);

  shview.set_position(600);

  window.show();

  m.run();
  
  return 0;
}







