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