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