gui/main_win.cc
changeset 2014 313875e0a34a
parent 1890 4a583e07d4b8
child 2052 c54ce7a5f4e7
equal deleted inserted replaced
37:251aa0c41571 38:2aed64db09df
       
     1 #ifdef HAVE_CONFIG_H
       
     2 #include <config.h>
       
     3 #endif
       
     4 
     1 #include "main_win.h"
     5 #include "main_win.h"
     2 #include "guipixbufs.h"
     6 #include "guipixbufs.h"
       
     7 
       
     8 #include "gettext.h"
       
     9 #define _(string) gettext (string)
     3 
    10 
     4 MainWin::MainWin()
    11 MainWin::MainWin()
     5 {
    12 {
     6   set_title ("no file");
    13   set_title ("no file");
     7   set_default_size(WIN_WIDTH,WIN_HEIGHT);
    14   set_default_size(WIN_WIDTH,WIN_HEIGHT);
    69 
    76 
    70   p_icon_factory->add_default();
    77   p_icon_factory->add_default();
    71   
    78   
    72   ag=Gtk::ActionGroup::create();
    79   ag=Gtk::ActionGroup::create();
    73 
    80 
    74   ag->add( Gtk::Action::create("FileMenu", "_File") );
    81   ag->add( Gtk::Action::create("FileMenu", _("_File")) );
    75   ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
    82   ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
    76       sigc::mem_fun(*this, &MainWin::newTab));
    83       sigc::mem_fun(*this, &MainWin::newTab));
    77   ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
    84   ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
    78       sigc::mem_fun(*this, &MainWin::openFile));
    85       sigc::mem_fun(*this, &MainWin::openFile));
    79   ag->add( Gtk::Action::create("FileClearTab", "Clear Tab"),
    86   ag->add( Gtk::Action::create("FileClearTab", _("Clear Tab")),
    80       sigc::mem_fun(*this, &MainWin::newFile));
    87       sigc::mem_fun(*this, &MainWin::newFile));
    81   ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
    88   ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
    82       sigc::mem_fun(*this, &MainWin::saveFile));
    89       sigc::mem_fun(*this, &MainWin::saveFile));
    83   ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
    90   ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
    84       sigc::mem_fun(*this, &MainWin::saveFileAs));
    91       sigc::mem_fun(*this, &MainWin::saveFileAs));
    85   ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
    92   ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
    86       sigc::mem_fun(*this, &MainWin::closeTab));
    93       sigc::mem_fun(*this, &MainWin::closeTab));
    87   ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
    94   ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
    88       sigc::mem_fun(*this, &MainWin::hide));
    95       sigc::mem_fun(*this, &MainWin::hide));
    89 
    96 
    90   ag->add( Gtk::Action::create("ViewMenu", "_View") );
    97   ag->add( Gtk::Action::create("ViewMenu", _("_View")) );
    91   ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
    98   ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
    92       sigc::mem_fun(*this, &MainWin::zoomIn));
    99       sigc::mem_fun(*this, &MainWin::zoomIn));
    93   ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
   100   ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
    94       sigc::mem_fun(*this, &MainWin::zoomOut));
   101       sigc::mem_fun(*this, &MainWin::zoomOut));
    95   ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
   102   ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
    96       sigc::mem_fun(*this, &MainWin::zoomFit));
   103       sigc::mem_fun(*this, &MainWin::zoomFit));
    97   ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
   104   ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
    98       sigc::mem_fun(*this, &MainWin::zoom100));
   105       sigc::mem_fun(*this, &MainWin::zoom100));
    99   
   106   
   100   ag->add( Gtk::Action::create("ShowMenu", "_Show") );
   107   ag->add( Gtk::Action::create("ShowMenu", _("_Show")) );
   101   ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
   108   ag->add( Gtk::Action::create("ShowMaps", _("_Maps")),
   102 	   sigc::mem_fun(*this, &MainWin::createMapWin));
   109 	   sigc::mem_fun(*this, &MainWin::createMapWin));
   103 
   110 
   104   ag->add( Gtk::Action::create("AlgoMenu", "_Algorithms") );
   111   ag->add( Gtk::Action::create("AlgoMenu", _("_Algorithms")) );
   105   ag->add( Gtk::Action::create("AlgoGeneral", "_General"),
   112   ag->add( Gtk::Action::create("AlgoGeneral", _("_General")),
   106 	   sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 0) );
   113 	   sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 0) );
   107   ag->add( Gtk::Action::create("AlgoKruskal", "_Kruskal"),
   114   ag->add( Gtk::Action::create("AlgoKruskal", _("_Kruskal")),
   108 	   sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 1) );
   115 	   sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 1) );
   109 
   116 
   110   Gtk::RadioAction::Group tool_group;
   117   Gtk::RadioAction::Group tool_group;
   111   ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), "Move"),
   118   ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), _("Move")),
   112       sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) );
   119       sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) );
   113   ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), "Create node"),
   120   ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), _("Create node")),
   114       sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) );
   121       sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) );
   115   ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), "Create edge"),
   122   ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), _("Create edge")),
   116       sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) );
   123       sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) );
   117   ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), "Delete"),
   124   ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), _("Delete")),
   118       sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) );
   125       sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) );
   119 
   126 
   120   ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), "Edit edge map"),
   127   ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), _("Edit edge map")),
   121       sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) );
   128       sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) );
   122   ag->add( Gtk::RadioAction::create(tool_group, "EditNodeMap", Gtk::StockID("gd-editnode"), "Edit node map"),
   129   ag->add( Gtk::RadioAction::create(tool_group, "EditNodeMap", Gtk::StockID("gd-editnode"), _("Edit node map")),
   123       sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 5) );
   130       sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 5) );
   124 
   131 
   125   ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")),
   132   ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")),
   126       sigc::mem_fun ( *this , &MainWin::createNewMapWin ) );
   133       sigc::mem_fun ( *this , &MainWin::createNewMapWin ) );
   127 
   134 
   248   tabs[active_tab]->signal_title_ch().connect(sigc::mem_fun(*this, &MainWin::set_tabtitle));
   255   tabs[active_tab]->signal_title_ch().connect(sigc::mem_fun(*this, &MainWin::set_tabtitle));
   249   tabs[active_tab]->signal_newmap_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinAfterSignal));
   256   tabs[active_tab]->signal_newmap_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinAfterSignal));
   250   tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
   257   tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
   251   notebook.append_page((Gtk::Widget&)(*(tabs[active_tab])));
   258   notebook.append_page((Gtk::Widget&)(*(tabs[active_tab])));
   252   notebook.set_current_page(size);
   259   notebook.set_current_page(size);
   253   set_tabtitle("unsaved file");
   260   set_tabtitle(_("unsaved file"));
   254   updateAlgoWinTabs();
   261   updateAlgoWinTabs();
   255 }
   262 }
   256 
   263 
   257 void MainWin::closeTab()
   264 void MainWin::closeTab()
   258 {
   265 {
   259   if(active_tab!=-1)
   266   if(active_tab!=-1)
   260     {
   267     {
   261       if (tabs[active_tab]->mapstorage.modified)
   268       if (tabs[active_tab]->mapstorage.modified)
   262 	{
   269 	{
   263 	  Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true, 
   270 	  Gtk::MessageDialog mdialog(_("<b>Save changes before closing?</b>"), true, 
   264 				     Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
   271 				     Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
   265 	  mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT);
   272 	  mdialog.add_button(_("Close file _without Saving"), Gtk::RESPONSE_REJECT);
   266 	  mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
   273 	  mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
   267 	  mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
   274 	  mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
   268 	  switch (mdialog.run())
   275 	  switch (mdialog.run())
   269 	    {
   276 	    {
   270 	    case Gtk::RESPONSE_CANCEL:
   277 	    case Gtk::RESPONSE_CANCEL:
   447 
   454 
   448 void MainWin::createNewMapWin()
   455 void MainWin::createNewMapWin()
   449 {
   456 {
   450   if(active_tab!=-1)
   457   if(active_tab!=-1)
   451     {
   458     {
   452       NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[active_tab], *(tabs[active_tab]));
   459       NewMapWin * nmw=new NewMapWin(_("Create New Map - ")+tabnames[active_tab], *(tabs[active_tab]));
   453       nmw->show();
   460       nmw->show();
   454     }
   461     }
   455 }
   462 }
   456 
   463 
   457 void MainWin::createNewMapWinTabString(std::string tabname, bool itisedge)
   464 void MainWin::createNewMapWinTabString(std::string tabname, bool itisedge)
   476       else
   483       else
   477 	{
   484 	{
   478 	  continue;
   485 	  continue;
   479 	}
   486 	}
   480     }
   487     }
   481   NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[i], *nbt, itisedge, false);
   488   NewMapWin * nmw=new NewMapWin(_("Create New Map - ")+tabnames[i], *nbt, itisedge, false);
   482   nmw->run();
   489   nmw->run();
   483 }
   490 }