Bugfix.
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_newmap_pixbuf = Gdk::Pixbuf::create_from_inline(
30 2328, gui_icons_newmap);
32 Gtk::IconSource move_icon_source;
33 move_icon_source.set_pixbuf(p_move_pixbuf);
34 Gtk::IconSet move_icon_set;
35 move_icon_set.add_source(move_icon_source);
36 p_icon_factory->add(Gtk::StockID("gd-move"), move_icon_set);
38 Gtk::IconSource addnode_icon_source;
39 addnode_icon_source.set_pixbuf(p_addnode_pixbuf);
40 Gtk::IconSet addnode_icon_set;
41 addnode_icon_set.add_source(addnode_icon_source);
42 p_icon_factory->add(Gtk::StockID("gd-addnode"), addnode_icon_set);
44 Gtk::IconSource addlink_icon_source;
45 addlink_icon_source.set_pixbuf(p_addlink_pixbuf);
46 Gtk::IconSet addlink_icon_set;
47 addlink_icon_set.add_source(addlink_icon_source);
48 p_icon_factory->add(Gtk::StockID("gd-addlink"), addlink_icon_set);
50 Gtk::IconSource delete_icon_source;
51 delete_icon_source.set_pixbuf(p_delete_pixbuf);
52 Gtk::IconSet delete_icon_set;
53 delete_icon_set.add_source(delete_icon_source);
54 p_icon_factory->add(Gtk::StockID("gd-delete"), delete_icon_set);
56 Gtk::IconSource editlink_icon_source;
57 editlink_icon_source.set_pixbuf(p_editlink_pixbuf);
58 Gtk::IconSet editlink_icon_set;
59 editlink_icon_set.add_source(editlink_icon_source);
60 p_icon_factory->add(Gtk::StockID("gd-editlink"), editlink_icon_set);
62 Gtk::IconSource newmap_icon_source;
63 newmap_icon_source.set_pixbuf(p_newmap_pixbuf);
64 Gtk::IconSet newmap_icon_set;
65 newmap_icon_set.add_source(newmap_icon_source);
66 p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set);
68 p_icon_factory->add_default();
70 ag=Gtk::ActionGroup::create();
72 ag->add( Gtk::Action::create("FileMenu", _("_File")) );
73 ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
74 sigc::mem_fun(*this, &MainWin::newTab));
75 ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
76 sigc::mem_fun(*this, &MainWin::openFile));
77 ag->add( Gtk::Action::create("FileClearTab", _("Clear Tab")),
78 sigc::mem_fun(*this, &MainWin::newFile));
79 ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
80 sigc::mem_fun(*this, &MainWin::saveFile));
81 ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
82 sigc::mem_fun(*this, &MainWin::saveFileAs));
83 ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
84 sigc::mem_fun(*this, &MainWin::closeTab));
85 ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
86 sigc::mem_fun(*this, &MainWin::hide));
88 ag->add( Gtk::Action::create("ViewMenu", _("_View")) );
89 ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
90 sigc::mem_fun(*this, &MainWin::zoomIn));
91 ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
92 sigc::mem_fun(*this, &MainWin::zoomOut));
93 ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
94 sigc::mem_fun(*this, &MainWin::zoomFit));
95 ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
96 sigc::mem_fun(*this, &MainWin::zoom100));
98 ag->add( Gtk::Action::create("ShowMenu", _("_Show")) );
99 ag->add( Gtk::Action::create("ShowMaps", _("_Maps")),
100 sigc::mem_fun(*this, &MainWin::createMapWin));
102 ag->add( Gtk::Action::create("AlgoMenu", _("_Algorithms")) );
103 ag->add( Gtk::Action::create("AlgoGeneral", _("_General")),
104 sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 0) );
105 ag->add( Gtk::Action::create("AlgoKruskal", _("_Kruskal")),
106 sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 1) );
108 Gtk::RadioAction::Group tool_group;
109 ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), _("Move")),
110 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) );
111 ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), _("Create node")),
112 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) );
113 ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), _("Create edge")),
114 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) );
115 ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), _("Delete")),
116 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) );
118 ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), _("Edit edge map")),
119 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) );
121 ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")),
122 sigc::mem_fun ( *this , &MainWin::createNewMapWin ) );
124 uim=Gtk::UIManager::create();
125 uim->insert_action_group(ag);
126 add_accel_group(uim->get_accel_group());
131 Glib::ustring ui_info =
133 " <menubar name='MenuBar'>"
134 " <menu action='FileMenu'>"
135 " <menuitem action='FileNew'/>"
136 " <menuitem action='FileOpen'/>"
137 " <menuitem action='FileClearTab'/>"
138 " <menuitem action='FileSave'/>"
139 " <menuitem action='FileSaveAs'/>"
140 " <menuitem action='Close'/>"
141 " <menuitem action='Quit'/>"
143 " <menu action='ViewMenu'>"
144 " <menuitem action='ViewZoomIn' />"
145 " <menuitem action='ViewZoomOut' />"
146 " <menuitem action='ViewZoom100' />"
147 " <menuitem action='ViewZoomFit' />"
149 " <menu action='ShowMenu'>"
150 " <menuitem action='ShowMaps'/>"
152 " <menu action='AlgoMenu'>"
153 " <menuitem action='AlgoGeneral'/>"
154 " <menuitem action='AlgoKruskal'/>"
157 " <toolbar name='ToolBar'>"
158 " <toolitem action='FileNew' />"
159 " <toolitem action='FileOpen' />"
160 " <toolitem action='FileSave' />"
161 " <toolitem action='Close' />"
163 " <toolitem action='ViewZoomIn' />"
164 " <toolitem action='ViewZoomOut' />"
165 " <toolitem action='ViewZoom100' />"
166 " <toolitem action='ViewZoomFit' />"
168 " <toolitem action='MoveItem' />"
169 " <toolitem action='CreateNode' />"
170 " <toolitem action='CreateEdge' />"
171 " <toolitem action='EraseItem' />"
172 " <toolitem action='EditEdgeMap' />"
174 " <toolitem action='AddMap' />"
178 uim->add_ui_from_string(ui_info);
181 catch(const Glib::Error& ex)
183 std::cerr << "building menus failed: " << ex.what();
186 Gtk::Widget* menubar = uim->get_widget("/MenuBar");
188 vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
191 Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
194 static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
195 vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
198 tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
202 notebook.signal_switch_page().connect(sigc::mem_fun(*this, &MainWin::onChangeTab));
206 vbox.pack_start(notebook);
211 void MainWin::set_tabtitle(std::string name)
213 if(strinst.find(name)==strinst.end())
215 tabnames[active_tab]=name;
221 std::ostringstream o;
223 tabnames[active_tab]=name+" - "+o.str();
225 set_title(tabnames[active_tab] + " - " + prog_name);
226 notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]);
230 void MainWin::readFile(const std::string & filename)
233 tabs[active_tab]->readFile(filename);
236 void MainWin::newTab()
238 int size=tabs.size();
240 tabnames.resize(size+1);
242 tabs[active_tab]=new NoteBookTab();
243 tabs[active_tab]->signal_title_ch().connect(sigc::mem_fun(*this, &MainWin::set_tabtitle));
244 tabs[active_tab]->signal_newmap_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinAfterSignal));
245 tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
246 notebook.append_page((Gtk::Widget&)(*(tabs[active_tab])));
247 notebook.set_current_page(size);
248 set_tabtitle(_("unsaved file"));
252 void MainWin::closeTab()
256 if (tabs[active_tab]->mapstorage.modified)
258 Gtk::MessageDialog mdialog(_("<b>Save changes before closing?</b>"), true,
259 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
260 mdialog.add_button(_("Close file _without Saving"), Gtk::RESPONSE_REJECT);
261 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
262 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
263 switch (mdialog.run())
265 case Gtk::RESPONSE_CANCEL:
267 case Gtk::RESPONSE_REJECT:
269 case Gtk::RESPONSE_ACCEPT:
270 tabs[active_tab]->saveFile();
274 //tabs vector will be decreased with the deleted value
275 int size=tabs.size();
278 for(int i=active_tab+1;i<size;i++)
280 tabnames[i-1]=tabnames[i];
284 //if size==1 resize will delete the only element
286 tabnames.resize(size-1);
288 int old_active_tab=active_tab;
289 notebook.remove_page(active_tab);
291 //If the first tab was active, upon delete notebook
292 //will first switch one tab upper and not lower like
293 //in the case, when not the first tab was active.
294 //But after deletion it will become the first tab,
295 //and this should be registrated in tabs vector,
297 if((old_active_tab==0)&&(size!=1))
302 //if this was the last page in notebook, there is
313 void MainWin::onChangeTab(GtkNotebookPage* page, guint page_num)
317 tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
318 set_title(tabnames[active_tab]);
321 void MainWin::newFile()
325 tabs[active_tab]->newFile();
329 void MainWin::openFile()
335 tabs[active_tab]->openFile();
338 void MainWin::saveFile()
342 tabs[active_tab]->saveFile();
346 void MainWin::saveFileAs()
350 tabs[active_tab]->saveFileAs();
354 void MainWin::close()
358 tabs[active_tab]->close();
362 void MainWin::zoomIn()
366 tabs[active_tab]->gd_canvas->zoomIn();
370 void MainWin::zoomOut()
374 tabs[active_tab]->gd_canvas->zoomOut();
378 void MainWin::zoomFit()
382 tabs[active_tab]->gd_canvas->zoomFit();
386 void MainWin::zoom100()
390 tabs[active_tab]->gd_canvas->zoom100();
394 void MainWin::createMapWin()
398 tabs[active_tab]->createMapWin(tabnames[active_tab]);
402 void MainWin::createAlgoWin(int algoid)
404 AlgoWin * aw=new AlgoWin(algoid, tabnames);
405 aw->signal_closing().connect(sigc::mem_fun(*this, &MainWin::deRegisterAlgoWin));
406 aw->signal_maplist_needed().connect(sigc::mem_fun(*this, &MainWin::updateAlgoWinMaps));
407 aw->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinTabString));
412 void MainWin::updateAlgoWinTabs()
414 std::set< AlgoWin* >::iterator awsi=aws.begin();
415 for(;awsi!=aws.end();awsi++)
417 (*awsi)->update_tablist(tabnames);
421 void MainWin::updateAlgoWinMaps(AlgoWin * awp, std::string tabname)
424 for(;(i<(int)tabnames.size())&&(tabnames[i]!=tabname);i++)
427 awp->update_maplist(&(tabs[i]->mapstorage));
430 void MainWin::deRegisterAlgoWin(AlgoWin * awp)
435 void MainWin::changeEditorialTool(int tool)
440 tabs[active_tab]->gd_canvas->changeEditorialTool(tool);
444 void MainWin::createNewMapWin()
448 NewMapWin * nmw=new NewMapWin(_("Create New Map - ")+tabnames[active_tab], *(tabs[active_tab]));
453 void MainWin::createNewMapWinTabString(std::string tabname, bool itisedge)
456 for(;((i<(int)tabnames.size())&&(tabnames[i]!=tabname));i++)
459 createNewMapWinAfterSignal(tabs[i], itisedge);
462 void MainWin::createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisedge)
464 std::vector<NoteBookTab*>::iterator nbti=tabs.begin();
466 for(;nbti!=tabs.end();nbti++)
477 NewMapWin * nmw=new NewMapWin(_("Create New Map - ")+tabnames[i], *nbt, itisedge, false);