Gettext is needed for bootstrapping.
6 #include "guipixbufs.h"
12 set_title ("no file");
13 set_default_size(WIN_WIDTH,WIN_HEIGHT);
16 // custom icons for the toolbar
17 Glib::RefPtr<Gtk::IconFactory> p_icon_factory = Gtk::IconFactory::create();
19 Glib::RefPtr<Gdk::Pixbuf> p_move_pixbuf = Gdk::Pixbuf::create_from_inline(
20 2328, gui_icons_move);
21 Glib::RefPtr<Gdk::Pixbuf> p_addnode_pixbuf = Gdk::Pixbuf::create_from_inline(
22 2328, gui_icons_addnode);
23 Glib::RefPtr<Gdk::Pixbuf> p_addlink_pixbuf = Gdk::Pixbuf::create_from_inline(
24 2328, gui_icons_addlink);
25 Glib::RefPtr<Gdk::Pixbuf> p_delete_pixbuf = Gdk::Pixbuf::create_from_inline(
26 2328, gui_icons_delete);
27 Glib::RefPtr<Gdk::Pixbuf> p_editlink_pixbuf = Gdk::Pixbuf::create_from_inline(
28 2328, gui_icons_editlink);
29 Glib::RefPtr<Gdk::Pixbuf> p_editnode_pixbuf = Gdk::Pixbuf::create_from_inline(
30 2328, gui_icons_editnode);
31 Glib::RefPtr<Gdk::Pixbuf> p_newmap_pixbuf = Gdk::Pixbuf::create_from_inline(
32 2328, gui_icons_newmap);
34 Gtk::IconSource move_icon_source;
35 move_icon_source.set_pixbuf(p_move_pixbuf);
36 Gtk::IconSet move_icon_set;
37 move_icon_set.add_source(move_icon_source);
38 p_icon_factory->add(Gtk::StockID("gd-move"), move_icon_set);
40 Gtk::IconSource addnode_icon_source;
41 addnode_icon_source.set_pixbuf(p_addnode_pixbuf);
42 Gtk::IconSet addnode_icon_set;
43 addnode_icon_set.add_source(addnode_icon_source);
44 p_icon_factory->add(Gtk::StockID("gd-addnode"), addnode_icon_set);
46 Gtk::IconSource addlink_icon_source;
47 addlink_icon_source.set_pixbuf(p_addlink_pixbuf);
48 Gtk::IconSet addlink_icon_set;
49 addlink_icon_set.add_source(addlink_icon_source);
50 p_icon_factory->add(Gtk::StockID("gd-addlink"), addlink_icon_set);
52 Gtk::IconSource delete_icon_source;
53 delete_icon_source.set_pixbuf(p_delete_pixbuf);
54 Gtk::IconSet delete_icon_set;
55 delete_icon_set.add_source(delete_icon_source);
56 p_icon_factory->add(Gtk::StockID("gd-delete"), delete_icon_set);
58 Gtk::IconSource editlink_icon_source;
59 editlink_icon_source.set_pixbuf(p_editlink_pixbuf);
60 Gtk::IconSet editlink_icon_set;
61 editlink_icon_set.add_source(editlink_icon_source);
62 p_icon_factory->add(Gtk::StockID("gd-editlink"), editlink_icon_set);
64 Gtk::IconSource editnode_icon_source;
65 editnode_icon_source.set_pixbuf(p_editnode_pixbuf);
66 Gtk::IconSet editnode_icon_set;
67 editnode_icon_set.add_source(editnode_icon_source);
68 p_icon_factory->add(Gtk::StockID("gd-editnode"), editnode_icon_set);
70 Gtk::IconSource newmap_icon_source;
71 newmap_icon_source.set_pixbuf(p_newmap_pixbuf);
72 Gtk::IconSet newmap_icon_set;
73 newmap_icon_set.add_source(newmap_icon_source);
74 p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set);
76 p_icon_factory->add_default();
78 ag=Gtk::ActionGroup::create();
80 ag->add( Gtk::Action::create("FileMenu", _("_File")) );
81 ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
82 sigc::mem_fun(*this, &MainWin::newTab));
83 ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
84 sigc::mem_fun(*this, &MainWin::openFile));
85 ag->add( Gtk::Action::create("FileClearTab", _("Clear Tab")),
86 sigc::mem_fun(*this, &MainWin::newFile));
87 ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
88 sigc::mem_fun(*this, &MainWin::saveFile));
89 ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
90 sigc::mem_fun(*this, &MainWin::saveFileAs));
91 ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
92 sigc::mem_fun(*this, &MainWin::closeTab));
93 ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
94 sigc::mem_fun(*this, &MainWin::hide));
96 ag->add( Gtk::Action::create("ViewMenu", _("_View")) );
97 ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
98 sigc::mem_fun(*this, &MainWin::zoomIn));
99 ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
100 sigc::mem_fun(*this, &MainWin::zoomOut));
101 ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
102 sigc::mem_fun(*this, &MainWin::zoomFit));
103 ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
104 sigc::mem_fun(*this, &MainWin::zoom100));
106 ag->add( Gtk::Action::create("ShowMenu", _("_Show")) );
107 ag->add( Gtk::Action::create("ShowMaps", _("_Maps")),
108 sigc::mem_fun(*this, &MainWin::createMapWin));
110 ag->add( Gtk::Action::create("AlgoMenu", _("_Algorithms")) );
111 ag->add( Gtk::Action::create("AlgoGeneral", _("_General")),
112 sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 0) );
113 ag->add( Gtk::Action::create("AlgoKruskal", _("_Kruskal")),
114 sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 1) );
116 Gtk::RadioAction::Group tool_group;
117 ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), _("Move")),
118 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) );
119 ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), _("Create node")),
120 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) );
121 ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), _("Create edge")),
122 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) );
123 ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), _("Delete")),
124 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) );
126 ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), _("Edit edge map")),
127 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) );
128 ag->add( Gtk::RadioAction::create(tool_group, "EditNodeMap", Gtk::StockID("gd-editnode"), _("Edit node map")),
129 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 5) );
131 ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")),
132 sigc::mem_fun ( *this , &MainWin::createNewMapWin ) );
134 uim=Gtk::UIManager::create();
135 uim->insert_action_group(ag);
136 add_accel_group(uim->get_accel_group());
141 Glib::ustring ui_info =
143 " <menubar name='MenuBar'>"
144 " <menu action='FileMenu'>"
145 " <menuitem action='FileNew'/>"
146 " <menuitem action='FileOpen'/>"
147 " <menuitem action='FileClearTab'/>"
148 " <menuitem action='FileSave'/>"
149 " <menuitem action='FileSaveAs'/>"
150 " <menuitem action='Close'/>"
151 " <menuitem action='Quit'/>"
153 " <menu action='ViewMenu'>"
154 " <menuitem action='ViewZoomIn' />"
155 " <menuitem action='ViewZoomOut' />"
156 " <menuitem action='ViewZoom100' />"
157 " <menuitem action='ViewZoomFit' />"
159 " <menu action='ShowMenu'>"
160 " <menuitem action='ShowMaps'/>"
162 " <menu action='AlgoMenu'>"
163 " <menuitem action='AlgoGeneral'/>"
164 " <menuitem action='AlgoKruskal'/>"
167 " <toolbar name='ToolBar'>"
168 " <toolitem action='FileNew' />"
169 " <toolitem action='FileOpen' />"
170 " <toolitem action='FileSave' />"
171 " <toolitem action='Close' />"
173 " <toolitem action='ViewZoomIn' />"
174 " <toolitem action='ViewZoomOut' />"
175 " <toolitem action='ViewZoom100' />"
176 " <toolitem action='ViewZoomFit' />"
178 " <toolitem action='MoveItem' />"
179 " <toolitem action='CreateNode' />"
180 " <toolitem action='CreateEdge' />"
181 " <toolitem action='EraseItem' />"
182 " <toolitem action='EditEdgeMap' />"
183 " <toolitem action='EditNodeMap' />"
185 " <toolitem action='AddMap' />"
189 uim->add_ui_from_string(ui_info);
192 catch(const Glib::Error& ex)
194 std::cerr << "building menus failed: " << ex.what();
197 Gtk::Widget* menubar = uim->get_widget("/MenuBar");
199 vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
202 Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
205 static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
206 vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
209 tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
213 notebook.signal_switch_page().connect(sigc::mem_fun(*this, &MainWin::onChangeTab));
217 vbox.pack_start(notebook);
222 void MainWin::set_tabtitle(std::string name)
224 if(strinst.find(name)==strinst.end())
226 tabnames[active_tab]=name;
232 std::ostringstream o;
234 tabnames[active_tab]=name+" - "+o.str();
236 set_title(tabnames[active_tab] + " - " + prog_name);
237 notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]);
241 void MainWin::readFile(const std::string & filename)
244 tabs[active_tab]->readFile(filename);
247 void MainWin::newTab()
249 int size=tabs.size();
251 tabnames.resize(size+1);
253 tabs[active_tab]=new NoteBookTab();
254 tabs[active_tab]->signal_title_ch().connect(sigc::mem_fun(*this, &MainWin::set_tabtitle));
255 tabs[active_tab]->signal_newmap_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinAfterSignal));
256 tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
257 notebook.append_page((Gtk::Widget&)(*(tabs[active_tab])));
258 notebook.set_current_page(size);
259 set_tabtitle(_("unsaved file"));
263 void MainWin::closeTab()
267 if (tabs[active_tab]->mapstorage.modified)
269 Gtk::MessageDialog mdialog(_("<b>Save changes before closing?</b>"), true,
270 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
271 mdialog.add_button(_("Close file _without Saving"), Gtk::RESPONSE_REJECT);
272 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
273 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
274 switch (mdialog.run())
276 case Gtk::RESPONSE_CANCEL:
278 case Gtk::RESPONSE_REJECT:
280 case Gtk::RESPONSE_ACCEPT:
281 tabs[active_tab]->saveFile();
285 //tabs vector will be decreased with the deleted value
286 int size=tabs.size();
289 for(int i=active_tab+1;i<size;i++)
291 tabnames[i-1]=tabnames[i];
295 //if size==1 resize will delete the only element
297 tabnames.resize(size-1);
299 int old_active_tab=active_tab;
300 notebook.remove_page(active_tab);
302 //If the first tab was active, upon delete notebook
303 //will first switch one tab upper and not lower like
304 //in the case, when not the first tab was active.
305 //But after deletion it will become the first tab,
306 //and this should be registrated in tabs vector,
308 if((old_active_tab==0)&&(size!=1))
313 //if this was the last page in notebook, there is
324 void MainWin::onChangeTab(GtkNotebookPage* page, guint page_num)
328 tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
329 set_title(tabnames[active_tab]);
332 void MainWin::newFile()
336 tabs[active_tab]->newFile();
340 void MainWin::openFile()
344 tabs[active_tab]->openFile();
348 void MainWin::saveFile()
352 tabs[active_tab]->saveFile();
356 void MainWin::saveFileAs()
360 tabs[active_tab]->saveFileAs();
364 void MainWin::close()
368 tabs[active_tab]->close();
372 void MainWin::zoomIn()
376 tabs[active_tab]->gd_canvas->zoomIn();
380 void MainWin::zoomOut()
384 tabs[active_tab]->gd_canvas->zoomOut();
388 void MainWin::zoomFit()
392 tabs[active_tab]->gd_canvas->zoomFit();
396 void MainWin::zoom100()
400 tabs[active_tab]->gd_canvas->zoom100();
404 void MainWin::createMapWin()
408 tabs[active_tab]->createMapWin(tabnames[active_tab]);
412 void MainWin::createAlgoWin(int algoid)
414 AlgoWin * aw=new AlgoWin(algoid, tabnames);
415 aw->signal_closing().connect(sigc::mem_fun(*this, &MainWin::deRegisterAlgoWin));
416 aw->signal_maplist_needed().connect(sigc::mem_fun(*this, &MainWin::updateAlgoWinMaps));
417 aw->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinTabString));
422 void MainWin::updateAlgoWinTabs()
424 std::set< AlgoWin* >::iterator awsi=aws.begin();
425 for(;awsi!=aws.end();awsi++)
427 (*awsi)->update_tablist(tabnames);
431 void MainWin::updateAlgoWinMaps(AlgoWin * awp, std::string tabname)
434 for(;(i<(int)tabnames.size())&&(tabnames[i]!=tabname);i++)
437 awp->update_maplist(&(tabs[i]->mapstorage));
440 void MainWin::deRegisterAlgoWin(AlgoWin * awp)
445 void MainWin::changeEditorialTool(int tool)
450 tabs[active_tab]->gd_canvas->changeEditorialTool(tool);
454 void MainWin::createNewMapWin()
458 NewMapWin * nmw=new NewMapWin(_("Create New Map - ")+tabnames[active_tab], *(tabs[active_tab]));
463 void MainWin::createNewMapWinTabString(std::string tabname, bool itisedge)
466 for(;((i<(int)tabnames.size())&&(tabnames[i]!=tabname));i++)
469 createNewMapWinAfterSignal(tabs[i], itisedge);
472 void MainWin::createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisedge)
474 std::vector<NoteBookTab*>::iterator nbti=tabs.begin();
476 for(;nbti!=tabs.end();nbti++)
487 NewMapWin * nmw=new NewMapWin(_("Create New Map - ")+tabnames[i], *nbt, itisedge, false);