gui/nbtab.cc
author alpar
Mon, 20 Feb 2006 06:44:07 +0000
changeset 1974 191223f4b639
parent 1878 409a31271efd
child 2066 b72fe5e2631a
permissions -rw-r--r--
Public data members of xy became documented
     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)
   168 {
   169   signal_newmap.emit(this, itisedge);
   170 }
   171 
   172 std::string NoteBookTab::getActiveEdgeMap(int prop)
   173 {
   174   return mapstorage.getActiveEdgeMap(prop);
   175 }
   176 
   177 std::string NoteBookTab::getActiveNodeMap(int prop)
   178 {
   179   return mapstorage.getActiveNodeMap(prop);
   180 }
   181 
   182 void NoteBookTab::registerNewEdgeMap(std::string mapname)
   183 {
   184   if(mapwinexists)
   185     {
   186       mapwin->registerNewEdgeMap(mapname);
   187     }
   188 }
   189 
   190 void NoteBookTab::registerNewNodeMap(std::string mapname)
   191 {
   192   if(mapwinexists)
   193     {
   194       mapwin->registerNewNodeMap(mapname);
   195     }
   196 }
   197 
   198 void NoteBookTab::createMapWin(std::string name)
   199 {
   200   if(!mapwinexists)
   201     {
   202       mapwin=new MapWin("Map Setup - "+name, mapstorage.getEdgeMapList(), mapstorage.getNodeMapList(), *this);
   203       mapwin->show();
   204       mapwinexists=true;
   205     }
   206 }
   207 
   208 void NoteBookTab::closeMapWin()
   209 {
   210   mapwinexists=false;
   211   delete mapwin;
   212 }
   213 
   214 sigc::signal<void, std::string> NoteBookTab::signal_title_ch()
   215 {
   216   return signal_title;
   217 }
   218