main_win.cc
branchgui
changeset 96 e664d8aa3f72
parent 95 628c0b383d2f
child 97 23f0afd1a323
     1.1 --- a/main_win.cc	Wed Nov 30 13:24:23 2005 +0000
     1.2 +++ b/main_win.cc	Tue Dec 06 10:53:38 2005 +0000
     1.3 @@ -1,19 +1,13 @@
     1.4  #include "main_win.h"
     1.5  #include "icons/guipixbufs.h"
     1.6  
     1.7 -MainWin::MainWin():mapwinexists(false)
     1.8 +MainWin::MainWin()
     1.9  {
    1.10 -  gd_canvas=new GraphDisplayerCanvas(*this);
    1.11 -
    1.12 -  set_title ("unsaved file - " + prog_name);
    1.13 +  set_title ("no file");
    1.14    set_default_size(WIN_WIDTH,WIN_HEIGHT);
    1.15    add(vbox);
    1.16  
    1.17 -  //connecting signals - controller character
    1.18 -  mapstorage.signal_prop_ch().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::propertyChange));
    1.19 -
    1.20    // custom icons for the toolbar
    1.21 -
    1.22    Glib::RefPtr<Gtk::IconFactory> p_icon_factory = Gtk::IconFactory::create();
    1.23   
    1.24    Glib::RefPtr<Gdk::Pixbuf> p_move_pixbuf = Gdk::Pixbuf::create_from_inline(
    1.25 @@ -75,10 +69,11 @@
    1.26  
    1.27    p_icon_factory->add_default();
    1.28    
    1.29 -
    1.30    ag=Gtk::ActionGroup::create();
    1.31  
    1.32    ag->add( Gtk::Action::create("FileMenu", "_File") );
    1.33 +  ag->add( Gtk::Action::create("FileNewTab", "New _Tab"),
    1.34 +      sigc::mem_fun(*this, &MainWin::newTab));
    1.35    ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
    1.36        sigc::mem_fun(*this, &MainWin::newFile));
    1.37    ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
    1.38 @@ -94,13 +89,13 @@
    1.39  
    1.40    ag->add( Gtk::Action::create("ViewMenu", "_View") );
    1.41    ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
    1.42 -      sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoomIn));
    1.43 +      sigc::mem_fun(*this, &MainWin::zoomIn));
    1.44    ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
    1.45 -      sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoomOut));
    1.46 +      sigc::mem_fun(*this, &MainWin::zoomOut));
    1.47    ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
    1.48 -      sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoomFit));
    1.49 +      sigc::mem_fun(*this, &MainWin::zoomFit));
    1.50    ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
    1.51 -      sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoom100));
    1.52 +      sigc::mem_fun(*this, &MainWin::zoom100));
    1.53    
    1.54    ag->add( Gtk::Action::create("ShowMenu", "_Show") );
    1.55    ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
    1.56 @@ -108,21 +103,21 @@
    1.57  
    1.58    Gtk::RadioAction::Group tool_group;
    1.59    ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), "Move"),
    1.60 -      sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 0) );
    1.61 +      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) );
    1.62    ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), "Create node"),
    1.63 -      sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 1) );
    1.64 +      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) );
    1.65    ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), "Create edge"),
    1.66 -      sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 2) );
    1.67 +      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) );
    1.68    ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), "Delete"),
    1.69 -      sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 3) );
    1.70 +      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) );
    1.71  
    1.72    ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), "Edit edge map"),
    1.73 -      sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 4) );
    1.74 +      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) );
    1.75    ag->add( Gtk::RadioAction::create(tool_group, "EditNodeMap", Gtk::StockID("gd-editnode"), "Edit node map"),
    1.76 -      sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 5) );
    1.77 +      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 5) );
    1.78  
    1.79    ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")),
    1.80 -      sigc::mem_fun (new NewMapWin("NewMapWin", *this), &NewMapWin::show ) );
    1.81 +      sigc::mem_fun ( *this , &MainWin::createNewMapWin ) );
    1.82  
    1.83    uim=Gtk::UIManager::create();
    1.84    uim->insert_action_group(ag);
    1.85 @@ -135,6 +130,7 @@
    1.86        "<ui>"
    1.87        "  <menubar name='MenuBar'>"
    1.88        "    <menu action='FileMenu'>"
    1.89 +      "      <menuitem action='FileNewTab'/>"
    1.90        "      <menuitem action='FileNew'/>"
    1.91        "      <menuitem action='FileOpen'/>"
    1.92        "      <menuitem action='FileSave'/>"
    1.93 @@ -194,208 +190,171 @@
    1.94      vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
    1.95    }
    1.96  
    1.97 -  Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
    1.98 -  pScrolledWindow->set_shadow_type(Gtk::SHADOW_IN);
    1.99 -  pScrolledWindow->add(*gd_canvas);
   1.100 -  vbox.pack_start(*pScrolledWindow);
   1.101 -
   1.102    tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
   1.103    tooltips.enable();
   1.104  
   1.105 +  active_tab=-1;
   1.106 +  notebook.signal_switch_page().connect(sigc::mem_fun(*this, &MainWin::onChangeTab));
   1.107 +
   1.108 +  vbox.pack_start(notebook);
   1.109 +  
   1.110    show_all_children();
   1.111  }
   1.112  
   1.113 -void MainWin::readFile(const std::string &file)
   1.114 +void MainWin::set_tabtitle(std::string name)
   1.115  {
   1.116 -  mapstorage.readFromFile(file);
   1.117 -  mapstorage.file_name = file;
   1.118 -  mapstorage.modified = false;
   1.119 -  gd_canvas->drawGraph();
   1.120 -  if(mapwinexists)
   1.121 -    {
   1.122 -      mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
   1.123 -    }
   1.124 -  set_title(Glib::filename_display_basename(file) + " - " + prog_name);
   1.125 +  tabnames[active_tab]=name;
   1.126 +  set_title(tabnames[active_tab] + " - " + prog_name);
   1.127 +  notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]);
   1.128 +}
   1.129 +
   1.130 +void MainWin::readFile(const std::string & filename)
   1.131 +{
   1.132 +  newTab();
   1.133 +  tabs[active_tab]->readFile(filename);
   1.134 +}
   1.135 +
   1.136 +void MainWin::newTab()
   1.137 +{
   1.138 +  int size=tabs.size();
   1.139 +  tabs.resize(size+1);
   1.140 +  tabnames.resize(size+1);
   1.141 +  active_tab=size;
   1.142 +  tabs[active_tab]=new NoteBookTab();
   1.143 +  tabnames[active_tab]="unsaved file";
   1.144 +  tabs[active_tab]->signal_title_ch().connect(sigc::mem_fun(*this, &MainWin::set_tabtitle));
   1.145 +  tabs[active_tab]->signal_newmap_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinAfterSignal));
   1.146 +  tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
   1.147 +  notebook.append_page((Gtk::Widget&)(*(tabs[active_tab])));
   1.148 +  notebook.set_current_page(size);
   1.149 +  set_tabtitle(tabnames[active_tab]);
   1.150 +}
   1.151 +
   1.152 +void MainWin::onChangeTab(GtkNotebookPage* page, guint page_num)
   1.153 +{
   1.154 +  page=page;
   1.155 +  active_tab=page_num;
   1.156 +  tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
   1.157 +  set_title(tabnames[active_tab]);
   1.158 +}
   1.159 +
   1.160 +void MainWin::onCloseTab()
   1.161 +{
   1.162  }
   1.163  
   1.164  void MainWin::newFile()
   1.165  {
   1.166 -  if (mapstorage.modified)
   1.167 -  {
   1.168 -    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
   1.169 -        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
   1.170 -    mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
   1.171 -    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
   1.172 -    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
   1.173 -    switch (mdialog.run())
   1.174 +  if(active_tab!=-1)
   1.175      {
   1.176 -      case Gtk::RESPONSE_CANCEL:
   1.177 -        return;
   1.178 -      case Gtk::RESPONSE_REJECT:
   1.179 -        break;
   1.180 -      case Gtk::RESPONSE_ACCEPT:
   1.181 -        saveFile();
   1.182 -        break;
   1.183 +      tabs[active_tab]->newFile();
   1.184      }
   1.185 -  }
   1.186 -  gd_canvas->clear();
   1.187 -  mapstorage.clear();
   1.188 -  if(mapwinexists)
   1.189 -    {
   1.190 -      mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
   1.191 -    }
   1.192 -  set_title("unsaved file - " + prog_name);
   1.193  }
   1.194 -
   1.195 + 
   1.196  void MainWin::openFile()
   1.197  {
   1.198 -  if (mapstorage.modified)
   1.199 -  {
   1.200 -    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true, 
   1.201 -        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
   1.202 -    mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
   1.203 -    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
   1.204 -    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
   1.205 -    switch (mdialog.run())
   1.206 +  if(active_tab!=-1)
   1.207      {
   1.208 -      case Gtk::RESPONSE_CANCEL:
   1.209 -        return;
   1.210 -      case Gtk::RESPONSE_REJECT:
   1.211 -        break;
   1.212 -      case Gtk::RESPONSE_ACCEPT:
   1.213 -        saveFile();
   1.214 -        break;
   1.215 +      tabs[active_tab]->openFile();
   1.216      }
   1.217 -  }
   1.218 -  Gtk::FileChooserDialog fcdialog("Open File");
   1.219 -  fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
   1.220 -  fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
   1.221 -  if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
   1.222 -  {
   1.223 -    gd_canvas->clear();
   1.224 -    mapstorage.clear();
   1.225 -    Glib::ustring filename = fcdialog.get_filename();
   1.226 -    if (!mapstorage.readFromFile(filename))
   1.227 -    {
   1.228 -      mapstorage.file_name = filename;
   1.229 -      mapstorage.modified = false;
   1.230 -      gd_canvas->drawGraph();
   1.231 -      if(mapwinexists)
   1.232 -	{
   1.233 -	  mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
   1.234 -	}
   1.235 -      set_title(Glib::filename_display_basename(filename) + " - " + prog_name);
   1.236 -    }
   1.237 -  }
   1.238  }
   1.239 -
   1.240 + 
   1.241  void MainWin::saveFile()
   1.242  {
   1.243 -  if (mapstorage.file_name == "") {
   1.244 -    saveFileAs();
   1.245 -  }
   1.246 -  else
   1.247 -  {
   1.248 -    mapstorage.writeToFile(mapstorage.file_name);
   1.249 -    mapstorage.modified = false;
   1.250 -    set_title(Glib::filename_display_basename(mapstorage.file_name) + " - " +
   1.251 -        prog_name);
   1.252 -  }
   1.253 +  if(active_tab!=-1)
   1.254 +    {
   1.255 +      tabs[active_tab]->saveFile();
   1.256 +    }
   1.257  }
   1.258 -
   1.259 + 
   1.260  void MainWin::saveFileAs()
   1.261  {
   1.262 -  Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
   1.263 -  fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
   1.264 -  fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
   1.265 -  if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
   1.266 -  {
   1.267 -    Glib::ustring filename = fcdialog.get_filename();
   1.268 -    mapstorage.file_name = filename;
   1.269 -    mapstorage.writeToFile(filename);
   1.270 -    mapstorage.modified = false;
   1.271 -    set_title(Glib::filename_display_basename(filename) + " - " + prog_name);
   1.272 -  }
   1.273 +  if(active_tab!=-1)
   1.274 +    {
   1.275 +      tabs[active_tab]->saveFileAs();
   1.276 +    }
   1.277  }
   1.278 -
   1.279 + 
   1.280  void MainWin::close()
   1.281  {
   1.282 -  if (mapstorage.modified)
   1.283 -  {
   1.284 -    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
   1.285 -        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
   1.286 -    mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
   1.287 -    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
   1.288 -    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
   1.289 -    switch (mdialog.run())
   1.290 +  if(active_tab!=-1)
   1.291      {
   1.292 -      case Gtk::RESPONSE_CANCEL:
   1.293 -        return;
   1.294 -      case Gtk::RESPONSE_REJECT:
   1.295 -        break;
   1.296 -      case Gtk::RESPONSE_ACCEPT:
   1.297 -        saveFile();
   1.298 -        break;
   1.299 -    }
   1.300 -  }
   1.301 -  gd_canvas->clear();
   1.302 -  mapstorage.clear();
   1.303 -  if(mapwinexists)
   1.304 -    {
   1.305 -      mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
   1.306 -    }
   1.307 -  set_title("unsaved file - " + prog_name);
   1.308 -}
   1.309 -
   1.310 -void MainWin::propertyChange(bool itisedge, int prop, std::string mapname)
   1.311 -{
   1.312 -  mapstorage.changeActiveMap(itisedge, prop, mapname);
   1.313 -}
   1.314 -
   1.315 -void MainWin::popupNewMapWin(bool itisedge, int prop)
   1.316 -{
   1.317 -  prop=prop;
   1.318 -  (new NewMapWin("NewMapWin", *this, itisedge, false))->run();
   1.319 -}
   1.320 -
   1.321 -std::string MainWin::getActiveEdgeMap(int prop)
   1.322 -{
   1.323 -  return mapstorage.getActiveEdgeMap(prop);
   1.324 -}
   1.325 -
   1.326 -std::string MainWin::getActiveNodeMap(int prop)
   1.327 -{
   1.328 -  return mapstorage.getActiveNodeMap(prop);
   1.329 -}
   1.330 -
   1.331 -void MainWin::registerNewEdgeMap(std::string mapname)
   1.332 -{
   1.333 -  if(mapwinexists)
   1.334 -    {
   1.335 -      mapwin->registerNewEdgeMap(mapname);
   1.336 +      tabs[active_tab]->close();
   1.337      }
   1.338  }
   1.339  
   1.340 -void MainWin::registerNewNodeMap(std::string mapname)
   1.341 +void MainWin::zoomIn()
   1.342  {
   1.343 -  if(mapwinexists)
   1.344 +  if(active_tab!=-1)
   1.345      {
   1.346 -      mapwin->registerNewNodeMap(mapname);
   1.347 +      tabs[active_tab]->gd_canvas->zoomIn();
   1.348 +    }
   1.349 +}
   1.350 +
   1.351 +void MainWin::zoomOut()
   1.352 +{
   1.353 +  if(active_tab!=-1)
   1.354 +    {
   1.355 +      tabs[active_tab]->gd_canvas->zoomOut();
   1.356 +    }
   1.357 +}
   1.358 +
   1.359 +void MainWin::zoomFit()
   1.360 +{
   1.361 +  if(active_tab!=-1)
   1.362 +    {
   1.363 +      tabs[active_tab]->gd_canvas->zoomFit();
   1.364 +    }
   1.365 +}
   1.366 +
   1.367 +void MainWin::zoom100()
   1.368 +{
   1.369 +  if(active_tab!=-1)
   1.370 +    {
   1.371 +      tabs[active_tab]->gd_canvas->zoom100();
   1.372      }
   1.373  }
   1.374  
   1.375  void MainWin::createMapWin()
   1.376  {
   1.377 -  if(!mapwinexists)
   1.378 +  if(active_tab!=-1)
   1.379      {
   1.380 -      mapwin=new MapWin("Map Setup", mapstorage.getEdgeMapList(), mapstorage.getNodeMapList(), *this);
   1.381 -      mapwin->show();
   1.382 -      mapwinexists=true;
   1.383 +      tabs[active_tab]->createMapWin(tabnames[active_tab]);
   1.384      }
   1.385  }
   1.386  
   1.387 -void MainWin::closeMapWin()
   1.388 +void MainWin::changeEditorialTool(int tool)
   1.389  {
   1.390 -  mapwinexists=false;
   1.391 -  delete mapwin;
   1.392 +  active_tool=tool;
   1.393 +  if(active_tab!=-1)
   1.394 +    {
   1.395 +      tabs[active_tab]->gd_canvas->changeEditorialTool(tool);
   1.396 +    }
   1.397  }
   1.398 +
   1.399 +void MainWin::createNewMapWin()
   1.400 +{
   1.401 +  if(active_tab!=-1)
   1.402 +    {
   1.403 +      NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[active_tab], *(tabs[active_tab]));
   1.404 +      nmw->show();
   1.405 +    }
   1.406 +}
   1.407 +
   1.408 +void MainWin::createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisedge)
   1.409 +{
   1.410 +  std::vector<NoteBookTab*>::iterator nbti=tabs.begin();
   1.411 +  int i=0;
   1.412 +  for(;nbti!=tabs.end();nbti++)
   1.413 +    {
   1.414 +      if(*nbti!=nbt)
   1.415 +	{
   1.416 +	  i++;
   1.417 +	}
   1.418 +      else
   1.419 +	{
   1.420 +	  continue;
   1.421 +	}
   1.422 +    }
   1.423 +  NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[i], *nbt, itisedge, false);
   1.424 +  nmw->run();
   1.425 +}