nbtab.cc
author hegyi
Fri, 06 Jan 2006 23:16:51 +0000
branchgui
changeset 115 9e5196647a5a
parent 102 25a4698cbe0c
child 121 637c12cbd64c
permissions -rw-r--r--
Forgotten file committed.
     1 #include <nbtab.h>
     2 
     3 NoteBookTab::NoteBookTab():mapwinexists(false)
     4 {
     5   gd_canvas=new GraphDisplayerCanvas(*this);
     6   add(*gd_canvas);
     7 
     8   //connecting signals - controller character
     9   mapstorage.signal_prop_ch().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::propertyChange));
    10   mapstorage.signal_node_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::registerNewNodeMap));
    11   mapstorage.signal_edge_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::registerNewEdgeMap));
    12   show_all_children();
    13   show();
    14 }
    15 
    16 void NoteBookTab::readFile(const std::string &file)
    17 {
    18   mapstorage.readFromFile(file);
    19   mapstorage.file_name = file;
    20   mapstorage.modified = false;
    21   gd_canvas->drawGraph();
    22   if(mapwinexists)
    23     {
    24       mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
    25     }
    26   signal_title.emit(Glib::filename_display_basename(file));
    27 }
    28 
    29 void NoteBookTab::newFile()
    30 {
    31   if (mapstorage.modified)
    32   {
    33     Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
    34         Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
    35     mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT);
    36     mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    37     mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
    38     switch (mdialog.run())
    39     {
    40       case Gtk::RESPONSE_CANCEL:
    41         return;
    42       case Gtk::RESPONSE_REJECT:
    43         break;
    44       case Gtk::RESPONSE_ACCEPT:
    45         saveFile();
    46         break;
    47     }
    48   }
    49   gd_canvas->clear();
    50   mapstorage.clear();
    51   if(mapwinexists)
    52     {
    53       mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
    54     }
    55   signal_title.emit("unsaved file");
    56 }
    57 
    58 void NoteBookTab::openFile()
    59 {
    60   if (mapstorage.modified)
    61   {
    62     Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true, 
    63         Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
    64     mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT);
    65     mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    66     mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
    67     switch (mdialog.run())
    68     {
    69       case Gtk::RESPONSE_CANCEL:
    70         return;
    71       case Gtk::RESPONSE_REJECT:
    72         break;
    73       case Gtk::RESPONSE_ACCEPT:
    74         saveFile();
    75         break;
    76     }
    77   }
    78   Gtk::FileChooserDialog fcdialog("Open File");
    79   fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    80   fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
    81   if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
    82   {
    83     gd_canvas->clear();
    84     mapstorage.clear();
    85     Glib::ustring filename = fcdialog.get_filename();
    86     if (!mapstorage.readFromFile(filename))
    87     {
    88       mapstorage.file_name = filename;
    89       mapstorage.modified = false;
    90       gd_canvas->drawGraph();
    91       if(mapwinexists)
    92 	{
    93 	  mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
    94 	}
    95       signal_title.emit(Glib::filename_display_basename(filename));
    96     }
    97   }
    98 }
    99 
   100 void NoteBookTab::saveFile()
   101 {
   102   if (mapstorage.file_name == "") {
   103     saveFileAs();
   104   }
   105   else
   106   {
   107     mapstorage.writeToFile(mapstorage.file_name);
   108     mapstorage.modified = false;
   109     signal_title.emit(Glib::filename_display_basename(mapstorage.file_name));
   110   }
   111 }
   112 
   113 void NoteBookTab::saveFileAs()
   114 {
   115   Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
   116   fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
   117   fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
   118   if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
   119   {
   120     Glib::ustring filename = fcdialog.get_filename();
   121     mapstorage.file_name = filename;
   122     mapstorage.writeToFile(filename);
   123     mapstorage.modified = false;
   124     signal_title.emit(Glib::filename_display_basename(filename));
   125   }
   126 }
   127 
   128 void NoteBookTab::close()
   129 {
   130   if (mapstorage.modified)
   131   {
   132     Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
   133         Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
   134     mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
   135     mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
   136     mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
   137     switch (mdialog.run())
   138     {
   139       case Gtk::RESPONSE_CANCEL:
   140         return;
   141       case Gtk::RESPONSE_REJECT:
   142         break;
   143       case Gtk::RESPONSE_ACCEPT:
   144         saveFile();
   145         break;
   146     }
   147   }
   148   gd_canvas->clear();
   149   mapstorage.clear();
   150   if(mapwinexists)
   151     {
   152       mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
   153     }
   154   signal_title.emit("unsaved file");
   155 }
   156 
   157 void NoteBookTab::propertyChange(bool itisedge, int prop, std::string mapname)
   158 {
   159   mapstorage.changeActiveMap(itisedge, prop, mapname);
   160 }
   161 
   162 sigc::signal<void, NoteBookTab *, bool> NoteBookTab::signal_newmap_needed()
   163 {
   164   return signal_newmap;
   165 }
   166 
   167 void NoteBookTab::popupNewMapWin(bool itisedge, int prop)
   168 {
   169   prop=prop;
   170   signal_newmap.emit(this, itisedge);
   171 }
   172 
   173 std::string NoteBookTab::getActiveEdgeMap(int prop)
   174 {
   175   return mapstorage.getActiveEdgeMap(prop);
   176 }
   177 
   178 std::string NoteBookTab::getActiveNodeMap(int prop)
   179 {
   180   return mapstorage.getActiveNodeMap(prop);
   181 }
   182 
   183 void NoteBookTab::registerNewEdgeMap(std::string mapname)
   184 {
   185   if(mapwinexists)
   186     {
   187       mapwin->registerNewEdgeMap(mapname);
   188     }
   189 }
   190 
   191 void NoteBookTab::registerNewNodeMap(std::string mapname)
   192 {
   193   if(mapwinexists)
   194     {
   195       mapwin->registerNewNodeMap(mapname);
   196     }
   197 }
   198 
   199 void NoteBookTab::createMapWin(std::string name)
   200 {
   201   if(!mapwinexists)
   202     {
   203       mapwin=new MapWin("Map Setup - "+name, mapstorage.getEdgeMapList(), mapstorage.getNodeMapList(), *this);
   204       mapwin->show();
   205       mapwinexists=true;
   206     }
   207 }
   208 
   209 void NoteBookTab::closeMapWin()
   210 {
   211   mapwinexists=false;
   212   delete mapwin;
   213 }
   214 
   215 sigc::signal<void, std::string> NoteBookTab::signal_title_ch()
   216 {
   217   return signal_title;
   218 }
   219