Index: gui/main_win.cc
===================================================================
--- gui/main_win.cc	(revision 1838)
+++ gui/main_win.cc	(revision 1849)
@@ -2,17 +2,11 @@
 #include "icons/guipixbufs.h"
 
-MainWin::MainWin():mapwinexists(false)
-{
-  gd_canvas=new GraphDisplayerCanvas(*this);
-
-  set_title ("unsaved file - " + prog_name);
+MainWin::MainWin()
+{
+  set_title ("no file");
   set_default_size(WIN_WIDTH,WIN_HEIGHT);
   add(vbox);
 
-  //connecting signals - controller character
-  mapstorage.signal_prop_ch().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::propertyChange));
-
   // custom icons for the toolbar
-
   Glib::RefPtr<Gtk::IconFactory> p_icon_factory = Gtk::IconFactory::create();
  
@@ -76,8 +70,9 @@
   p_icon_factory->add_default();
   
-
   ag=Gtk::ActionGroup::create();
 
   ag->add( Gtk::Action::create("FileMenu", "_File") );
+  ag->add( Gtk::Action::create("FileNewTab", "New _Tab"),
+      sigc::mem_fun(*this, &MainWin::newTab));
   ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
       sigc::mem_fun(*this, &MainWin::newFile));
@@ -95,11 +90,11 @@
   ag->add( Gtk::Action::create("ViewMenu", "_View") );
   ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
-      sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoomIn));
+      sigc::mem_fun(*this, &MainWin::zoomIn));
   ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
-      sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoomOut));
+      sigc::mem_fun(*this, &MainWin::zoomOut));
   ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
-      sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoomFit));
+      sigc::mem_fun(*this, &MainWin::zoomFit));
   ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
-      sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoom100));
+      sigc::mem_fun(*this, &MainWin::zoom100));
   
   ag->add( Gtk::Action::create("ShowMenu", "_Show") );
@@ -109,19 +104,19 @@
   Gtk::RadioAction::Group tool_group;
   ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), "Move"),
-      sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 0) );
+      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) );
   ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), "Create node"),
-      sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 1) );
+      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) );
   ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), "Create edge"),
-      sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 2) );
+      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) );
   ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), "Delete"),
-      sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 3) );
+      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) );
 
   ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), "Edit edge map"),
-      sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 4) );
+      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) );
   ag->add( Gtk::RadioAction::create(tool_group, "EditNodeMap", Gtk::StockID("gd-editnode"), "Edit node map"),
-      sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 5) );
+      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 5) );
 
   ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")),
-      sigc::mem_fun (new NewMapWin("NewMapWin", *this), &NewMapWin::show ) );
+      sigc::mem_fun ( *this , &MainWin::createNewMapWin ) );
 
   uim=Gtk::UIManager::create();
@@ -136,4 +131,5 @@
       "  <menubar name='MenuBar'>"
       "    <menu action='FileMenu'>"
+      "      <menuitem action='FileNewTab'/>"
       "      <menuitem action='FileNew'/>"
       "      <menuitem action='FileOpen'/>"
@@ -195,207 +191,170 @@
   }
 
-  Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
-  pScrolledWindow->set_shadow_type(Gtk::SHADOW_IN);
-  pScrolledWindow->add(*gd_canvas);
-  vbox.pack_start(*pScrolledWindow);
-
   tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
   tooltips.enable();
 
+  active_tab=-1;
+  notebook.signal_switch_page().connect(sigc::mem_fun(*this, &MainWin::onChangeTab));
+
+  vbox.pack_start(notebook);
+  
   show_all_children();
 }
 
-void MainWin::readFile(const std::string &file)
-{
-  mapstorage.readFromFile(file);
-  mapstorage.file_name = file;
-  mapstorage.modified = false;
-  gd_canvas->drawGraph();
-  if(mapwinexists)
-    {
-      mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
-    }
-  set_title(Glib::filename_display_basename(file) + " - " + prog_name);
+void MainWin::set_tabtitle(std::string name)
+{
+  tabnames[active_tab]=name;
+  set_title(tabnames[active_tab] + " - " + prog_name);
+  notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]);
+}
+
+void MainWin::readFile(const std::string & filename)
+{
+  newTab();
+  tabs[active_tab]->readFile(filename);
+}
+
+void MainWin::newTab()
+{
+  int size=tabs.size();
+  tabs.resize(size+1);
+  tabnames.resize(size+1);
+  active_tab=size;
+  tabs[active_tab]=new NoteBookTab();
+  tabnames[active_tab]="unsaved file";
+  tabs[active_tab]->signal_title_ch().connect(sigc::mem_fun(*this, &MainWin::set_tabtitle));
+  tabs[active_tab]->signal_newmap_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinAfterSignal));
+  tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
+  notebook.append_page((Gtk::Widget&)(*(tabs[active_tab])));
+  notebook.set_current_page(size);
+  set_tabtitle(tabnames[active_tab]);
+}
+
+void MainWin::onChangeTab(GtkNotebookPage* page, guint page_num)
+{
+  page=page;
+  active_tab=page_num;
+  tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
+  set_title(tabnames[active_tab]);
+}
+
+void MainWin::onCloseTab()
+{
 }
 
 void MainWin::newFile()
 {
-  if (mapstorage.modified)
-  {
-    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
-        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
-    mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
-    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
-    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
-    switch (mdialog.run())
-    {
-      case Gtk::RESPONSE_CANCEL:
-        return;
-      case Gtk::RESPONSE_REJECT:
-        break;
-      case Gtk::RESPONSE_ACCEPT:
-        saveFile();
-        break;
-    }
-  }
-  gd_canvas->clear();
-  mapstorage.clear();
-  if(mapwinexists)
-    {
-      mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
-    }
-  set_title("unsaved file - " + prog_name);
-}
-
+  if(active_tab!=-1)
+    {
+      tabs[active_tab]->newFile();
+    }
+}
+ 
 void MainWin::openFile()
 {
-  if (mapstorage.modified)
-  {
-    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true, 
-        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
-    mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
-    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
-    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
-    switch (mdialog.run())
-    {
-      case Gtk::RESPONSE_CANCEL:
-        return;
-      case Gtk::RESPONSE_REJECT:
-        break;
-      case Gtk::RESPONSE_ACCEPT:
-        saveFile();
-        break;
-    }
-  }
-  Gtk::FileChooserDialog fcdialog("Open File");
-  fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
-  fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
-  if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
-  {
-    gd_canvas->clear();
-    mapstorage.clear();
-    Glib::ustring filename = fcdialog.get_filename();
-    if (!mapstorage.readFromFile(filename))
-    {
-      mapstorage.file_name = filename;
-      mapstorage.modified = false;
-      gd_canvas->drawGraph();
-      if(mapwinexists)
+  if(active_tab!=-1)
+    {
+      tabs[active_tab]->openFile();
+    }
+}
+ 
+void MainWin::saveFile()
+{
+  if(active_tab!=-1)
+    {
+      tabs[active_tab]->saveFile();
+    }
+}
+ 
+void MainWin::saveFileAs()
+{
+  if(active_tab!=-1)
+    {
+      tabs[active_tab]->saveFileAs();
+    }
+}
+ 
+void MainWin::close()
+{
+  if(active_tab!=-1)
+    {
+      tabs[active_tab]->close();
+    }
+}
+
+void MainWin::zoomIn()
+{
+  if(active_tab!=-1)
+    {
+      tabs[active_tab]->gd_canvas->zoomIn();
+    }
+}
+
+void MainWin::zoomOut()
+{
+  if(active_tab!=-1)
+    {
+      tabs[active_tab]->gd_canvas->zoomOut();
+    }
+}
+
+void MainWin::zoomFit()
+{
+  if(active_tab!=-1)
+    {
+      tabs[active_tab]->gd_canvas->zoomFit();
+    }
+}
+
+void MainWin::zoom100()
+{
+  if(active_tab!=-1)
+    {
+      tabs[active_tab]->gd_canvas->zoom100();
+    }
+}
+
+void MainWin::createMapWin()
+{
+  if(active_tab!=-1)
+    {
+      tabs[active_tab]->createMapWin(tabnames[active_tab]);
+    }
+}
+
+void MainWin::changeEditorialTool(int tool)
+{
+  active_tool=tool;
+  if(active_tab!=-1)
+    {
+      tabs[active_tab]->gd_canvas->changeEditorialTool(tool);
+    }
+}
+
+void MainWin::createNewMapWin()
+{
+  if(active_tab!=-1)
+    {
+      NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[active_tab], *(tabs[active_tab]));
+      nmw->show();
+    }
+}
+
+void MainWin::createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisedge)
+{
+  std::vector<NoteBookTab*>::iterator nbti=tabs.begin();
+  int i=0;
+  for(;nbti!=tabs.end();nbti++)
+    {
+      if(*nbti!=nbt)
 	{
-	  mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
+	  i++;
 	}
-      set_title(Glib::filename_display_basename(filename) + " - " + prog_name);
-    }
-  }
-}
-
-void MainWin::saveFile()
-{
-  if (mapstorage.file_name == "") {
-    saveFileAs();
-  }
-  else
-  {
-    mapstorage.writeToFile(mapstorage.file_name);
-    mapstorage.modified = false;
-    set_title(Glib::filename_display_basename(mapstorage.file_name) + " - " +
-        prog_name);
-  }
-}
-
-void MainWin::saveFileAs()
-{
-  Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
-  fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
-  fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
-  if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
-  {
-    Glib::ustring filename = fcdialog.get_filename();
-    mapstorage.file_name = filename;
-    mapstorage.writeToFile(filename);
-    mapstorage.modified = false;
-    set_title(Glib::filename_display_basename(filename) + " - " + prog_name);
-  }
-}
-
-void MainWin::close()
-{
-  if (mapstorage.modified)
-  {
-    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
-        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
-    mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
-    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
-    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
-    switch (mdialog.run())
-    {
-      case Gtk::RESPONSE_CANCEL:
-        return;
-      case Gtk::RESPONSE_REJECT:
-        break;
-      case Gtk::RESPONSE_ACCEPT:
-        saveFile();
-        break;
-    }
-  }
-  gd_canvas->clear();
-  mapstorage.clear();
-  if(mapwinexists)
-    {
-      mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
-    }
-  set_title("unsaved file - " + prog_name);
-}
-
-void MainWin::propertyChange(bool itisedge, int prop, std::string mapname)
-{
-  mapstorage.changeActiveMap(itisedge, prop, mapname);
-}
-
-void MainWin::popupNewMapWin(bool itisedge, int prop)
-{
-  prop=prop;
-  (new NewMapWin("NewMapWin", *this, itisedge, false))->run();
-}
-
-std::string MainWin::getActiveEdgeMap(int prop)
-{
-  return mapstorage.getActiveEdgeMap(prop);
-}
-
-std::string MainWin::getActiveNodeMap(int prop)
-{
-  return mapstorage.getActiveNodeMap(prop);
-}
-
-void MainWin::registerNewEdgeMap(std::string mapname)
-{
-  if(mapwinexists)
-    {
-      mapwin->registerNewEdgeMap(mapname);
-    }
-}
-
-void MainWin::registerNewNodeMap(std::string mapname)
-{
-  if(mapwinexists)
-    {
-      mapwin->registerNewNodeMap(mapname);
-    }
-}
-
-void MainWin::createMapWin()
-{
-  if(!mapwinexists)
-    {
-      mapwin=new MapWin("Map Setup", mapstorage.getEdgeMapList(), mapstorage.getNodeMapList(), *this);
-      mapwin->show();
-      mapwinexists=true;
-    }
-}
-
-void MainWin::closeMapWin()
-{
-  mapwinexists=false;
-  delete mapwin;
-}
+      else
+	{
+	  continue;
+	}
+    }
+  NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[i], *nbt, itisedge, false);
+  nmw->run();
+}
