Index: gui/main_win.cc
===================================================================
--- gui/main_win.cc	(revision 1601)
+++ gui/main_win.cc	(revision 1606)
@@ -1,6 +1,7 @@
-#include <main_win.h>
-
-MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
-    MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),newmapwin("Creating new map",gd_canvas),gd_canvas(graph, cm, ms, &mapwin)
+#include "main_win.h"
+
+MainWin::MainWin(const std::string& title) :
+  mapwin("Map Setup", mapstorage, gd_canvas),
+  newmapwin("Creating new map", gd_canvas), gd_canvas(mapstorage, mapwin)
 {
 
@@ -20,5 +21,7 @@
   ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
       sigc::mem_fun(*this, &MainWin::saveFileAs));
-  ag->add( Gtk::Action::create("FileQuit", Gtk::Stock::QUIT),
+  ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
+      sigc::mem_fun(*this, &MainWin::close));
+  ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
       sigc::mem_fun(*this, &MainWin::hide));
 
@@ -37,12 +40,13 @@
       sigc::mem_fun(this->mapwin, &MapWin::show));
 
-  ag->add( Gtk::Action::create("CreateNode", Gtk::Stock::NO),
+  Gtk::RadioAction::Group tool_group;
+  ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::Stock::CONVERT, "Move"),
+      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) );
+  ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::Stock::NO, "Create node"),
       sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 1) );
-  ag->add( Gtk::Action::create("CreateEdge", Gtk::Stock::REMOVE),
+  ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::Stock::REMOVE, "Create edge"),
       sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 2) );
-  ag->add( Gtk::Action::create("EraseItem", Gtk::Stock::DELETE),
+  ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::Stock::DELETE, "Delete"),
       sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 3) );
-  ag->add( Gtk::Action::create("MoveItem", Gtk::Stock::CONVERT),
-      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) );
   ag->add( Gtk::Action::create("EditEdgeMap", Gtk::Stock::PROPERTIES),
       sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 4) );
@@ -67,5 +71,6 @@
       "      <menuitem action='FileSave'/>"
       "      <menuitem action='FileSaveAs'/>"
-      "      <menuitem action='FileQuit'/>"
+      "      <menuitem action='Close'/>"
+      "      <menuitem action='Quit'/>"
       "    </menu>"
       "    <menu action='ViewMenu'>"
@@ -83,4 +88,5 @@
       "    <toolitem action='FileOpen' />"
       "    <toolitem action='FileSave' />"
+      "    <toolitem action='Close' />"
       "    <separator />"
       "    <toolitem action='ViewZoomIn' />"
@@ -89,8 +95,8 @@
       "    <toolitem action='ViewZoom100' />"
       "    <separator />"
+      "    <toolitem action='MoveItem' />"
       "    <toolitem action='CreateNode' />"
       "    <toolitem action='CreateEdge' />"
       "    <toolitem action='EraseItem' />"
-      "    <toolitem action='MoveItem' />"
       "    <toolitem action='EditEdgeMap' />"
       "    <toolitem action='EditNodeMap' />"
@@ -131,19 +137,114 @@
 void MainWin::newFile()
 {
-  std::cerr << "MainWin::newFile(): not yet implemented" << std::endl;
+  if (mapstorage.modified)
+  {
+    Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING,
+        Gtk::BUTTONS_NONE);
+    mdialog.set_message("<b>Save changes before closing?</b>", true);
+    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();
+  mapwin.update();
 }
 
 void MainWin::openFile()
 {
-  std::cerr << "MainWin::openFile(): not yet implemented" << std::endl;
+  if (mapstorage.modified)
+  {
+    Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING,
+        Gtk::BUTTONS_NONE);
+    mdialog.set_message("<b>Save changes before closing?</b>", true);
+    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();
+  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)
+  {
+    Glib::ustring filename = fcdialog.get_filename();
+    mapstorage.readFromFile(filename);
+    mapstorage.file_name = filename;
+    mapstorage.modified = false;
+    gd_canvas.drawGraph();
+    mapwin.update();
+  }
 }
 
 void MainWin::saveFile()
 {
-  std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl;
+  if (mapstorage.file_name == "") {
+    saveFileAs();
+  }
+  else
+  {
+    mapstorage.writeToFile(mapstorage.file_name);
+    mapstorage.modified = false;
+  }
 }
 
 void MainWin::saveFileAs()
 {
-  std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl;
-}
+  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;
+  }
+}
+
+void MainWin::close()
+{
+  if (mapstorage.modified)
+  {
+    Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING,
+        Gtk::BUTTONS_NONE);
+    mdialog.set_message("<b>Save changes before closing?</b>", true);
+    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();
+  mapwin.update();
+}
