gui/nbtab.cc
changeset 1849 a4d1362397fe
child 1869 52f5a7f9fb48
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gui/nbtab.cc	Tue Dec 06 10:53:38 2005 +0000
     1.3 @@ -0,0 +1,217 @@
     1.4 +#include <nbtab.h>
     1.5 +
     1.6 +NoteBookTab::NoteBookTab():mapwinexists(false)
     1.7 +{
     1.8 +  gd_canvas=new GraphDisplayerCanvas(*this);
     1.9 +  add(*gd_canvas);
    1.10 +
    1.11 +  //connecting signals - controller character
    1.12 +  mapstorage.signal_prop_ch().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::propertyChange));
    1.13 +  show_all_children();
    1.14 +  show();
    1.15 +}
    1.16 +
    1.17 +void NoteBookTab::readFile(const std::string &file)
    1.18 +{
    1.19 +  mapstorage.readFromFile(file);
    1.20 +  mapstorage.file_name = file;
    1.21 +  mapstorage.modified = false;
    1.22 +  gd_canvas->drawGraph();
    1.23 +  if(mapwinexists)
    1.24 +    {
    1.25 +      mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
    1.26 +    }
    1.27 +  signal_title.emit(Glib::filename_display_basename(file));
    1.28 +}
    1.29 +
    1.30 +void NoteBookTab::newFile()
    1.31 +{
    1.32 +  if (mapstorage.modified)
    1.33 +  {
    1.34 +    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
    1.35 +        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
    1.36 +    mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
    1.37 +    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    1.38 +    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
    1.39 +    switch (mdialog.run())
    1.40 +    {
    1.41 +      case Gtk::RESPONSE_CANCEL:
    1.42 +        return;
    1.43 +      case Gtk::RESPONSE_REJECT:
    1.44 +        break;
    1.45 +      case Gtk::RESPONSE_ACCEPT:
    1.46 +        saveFile();
    1.47 +        break;
    1.48 +    }
    1.49 +  }
    1.50 +  gd_canvas->clear();
    1.51 +  mapstorage.clear();
    1.52 +  if(mapwinexists)
    1.53 +    {
    1.54 +      mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
    1.55 +    }
    1.56 +  signal_title.emit("unsaved file");
    1.57 +}
    1.58 +
    1.59 +void NoteBookTab::openFile()
    1.60 +{
    1.61 +  if (mapstorage.modified)
    1.62 +  {
    1.63 +    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true, 
    1.64 +        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
    1.65 +    mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
    1.66 +    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    1.67 +    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
    1.68 +    switch (mdialog.run())
    1.69 +    {
    1.70 +      case Gtk::RESPONSE_CANCEL:
    1.71 +        return;
    1.72 +      case Gtk::RESPONSE_REJECT:
    1.73 +        break;
    1.74 +      case Gtk::RESPONSE_ACCEPT:
    1.75 +        saveFile();
    1.76 +        break;
    1.77 +    }
    1.78 +  }
    1.79 +  Gtk::FileChooserDialog fcdialog("Open File");
    1.80 +  fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    1.81 +  fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
    1.82 +  if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
    1.83 +  {
    1.84 +    gd_canvas->clear();
    1.85 +    mapstorage.clear();
    1.86 +    Glib::ustring filename = fcdialog.get_filename();
    1.87 +    if (!mapstorage.readFromFile(filename))
    1.88 +    {
    1.89 +      mapstorage.file_name = filename;
    1.90 +      mapstorage.modified = false;
    1.91 +      gd_canvas->drawGraph();
    1.92 +      if(mapwinexists)
    1.93 +	{
    1.94 +	  mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
    1.95 +	}
    1.96 +      signal_title.emit(Glib::filename_display_basename(filename));
    1.97 +    }
    1.98 +  }
    1.99 +}
   1.100 +
   1.101 +void NoteBookTab::saveFile()
   1.102 +{
   1.103 +  if (mapstorage.file_name == "") {
   1.104 +    saveFileAs();
   1.105 +  }
   1.106 +  else
   1.107 +  {
   1.108 +    mapstorage.writeToFile(mapstorage.file_name);
   1.109 +    mapstorage.modified = false;
   1.110 +    signal_title.emit(Glib::filename_display_basename(mapstorage.file_name));
   1.111 +  }
   1.112 +}
   1.113 +
   1.114 +void NoteBookTab::saveFileAs()
   1.115 +{
   1.116 +  Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
   1.117 +  fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
   1.118 +  fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
   1.119 +  if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
   1.120 +  {
   1.121 +    Glib::ustring filename = fcdialog.get_filename();
   1.122 +    mapstorage.file_name = filename;
   1.123 +    mapstorage.writeToFile(filename);
   1.124 +    mapstorage.modified = false;
   1.125 +    signal_title.emit(Glib::filename_display_basename(filename));
   1.126 +  }
   1.127 +}
   1.128 +
   1.129 +void NoteBookTab::close()
   1.130 +{
   1.131 +  if (mapstorage.modified)
   1.132 +  {
   1.133 +    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
   1.134 +        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
   1.135 +    mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
   1.136 +    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
   1.137 +    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
   1.138 +    switch (mdialog.run())
   1.139 +    {
   1.140 +      case Gtk::RESPONSE_CANCEL:
   1.141 +        return;
   1.142 +      case Gtk::RESPONSE_REJECT:
   1.143 +        break;
   1.144 +      case Gtk::RESPONSE_ACCEPT:
   1.145 +        saveFile();
   1.146 +        break;
   1.147 +    }
   1.148 +  }
   1.149 +  gd_canvas->clear();
   1.150 +  mapstorage.clear();
   1.151 +  if(mapwinexists)
   1.152 +    {
   1.153 +      mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
   1.154 +    }
   1.155 +  signal_title.emit("unsaved file");
   1.156 +}
   1.157 +
   1.158 +void NoteBookTab::propertyChange(bool itisedge, int prop, std::string mapname)
   1.159 +{
   1.160 +  mapstorage.changeActiveMap(itisedge, prop, mapname);
   1.161 +}
   1.162 +
   1.163 +sigc::signal<void, NoteBookTab *, bool> NoteBookTab::signal_newmap_needed()
   1.164 +{
   1.165 +  return signal_newmap;
   1.166 +}
   1.167 +
   1.168 +void NoteBookTab::popupNewMapWin(bool itisedge, int prop)
   1.169 +{
   1.170 +  prop=prop;
   1.171 +  signal_newmap.emit(this, itisedge);
   1.172 +}
   1.173 +
   1.174 +std::string NoteBookTab::getActiveEdgeMap(int prop)
   1.175 +{
   1.176 +  return mapstorage.getActiveEdgeMap(prop);
   1.177 +}
   1.178 +
   1.179 +std::string NoteBookTab::getActiveNodeMap(int prop)
   1.180 +{
   1.181 +  return mapstorage.getActiveNodeMap(prop);
   1.182 +}
   1.183 +
   1.184 +void NoteBookTab::registerNewEdgeMap(std::string mapname)
   1.185 +{
   1.186 +  if(mapwinexists)
   1.187 +    {
   1.188 +      mapwin->registerNewEdgeMap(mapname);
   1.189 +    }
   1.190 +}
   1.191 +
   1.192 +void NoteBookTab::registerNewNodeMap(std::string mapname)
   1.193 +{
   1.194 +  if(mapwinexists)
   1.195 +    {
   1.196 +      mapwin->registerNewNodeMap(mapname);
   1.197 +    }
   1.198 +}
   1.199 +
   1.200 +void NoteBookTab::createMapWin(std::string name)
   1.201 +{
   1.202 +  if(!mapwinexists)
   1.203 +    {
   1.204 +      mapwin=new MapWin("Map Setup - "+name, mapstorage.getEdgeMapList(), mapstorage.getNodeMapList(), *this);
   1.205 +      mapwin->show();
   1.206 +      mapwinexists=true;
   1.207 +    }
   1.208 +}
   1.209 +
   1.210 +void NoteBookTab::closeMapWin()
   1.211 +{
   1.212 +  mapwinexists=false;
   1.213 +  delete mapwin;
   1.214 +}
   1.215 +
   1.216 +sigc::signal<void, std::string> NoteBookTab::signal_title_ch()
   1.217 +{
   1.218 +  return signal_title;
   1.219 +}
   1.220 +