73 newmap_icon_set.add_source(newmap_icon_source); |
67 newmap_icon_set.add_source(newmap_icon_source); |
74 p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set); |
68 p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set); |
75 |
69 |
76 p_icon_factory->add_default(); |
70 p_icon_factory->add_default(); |
77 |
71 |
78 |
|
79 ag=Gtk::ActionGroup::create(); |
72 ag=Gtk::ActionGroup::create(); |
80 |
73 |
81 ag->add( Gtk::Action::create("FileMenu", "_File") ); |
74 ag->add( Gtk::Action::create("FileMenu", "_File") ); |
|
75 ag->add( Gtk::Action::create("FileNewTab", "New _Tab"), |
|
76 sigc::mem_fun(*this, &MainWin::newTab)); |
82 ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW), |
77 ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW), |
83 sigc::mem_fun(*this, &MainWin::newFile)); |
78 sigc::mem_fun(*this, &MainWin::newFile)); |
84 ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN), |
79 ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN), |
85 sigc::mem_fun(*this, &MainWin::openFile)); |
80 sigc::mem_fun(*this, &MainWin::openFile)); |
86 ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE), |
81 ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE), |
92 ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT), |
87 ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT), |
93 sigc::mem_fun(*this, &MainWin::hide)); |
88 sigc::mem_fun(*this, &MainWin::hide)); |
94 |
89 |
95 ag->add( Gtk::Action::create("ViewMenu", "_View") ); |
90 ag->add( Gtk::Action::create("ViewMenu", "_View") ); |
96 ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN), |
91 ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN), |
97 sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoomIn)); |
92 sigc::mem_fun(*this, &MainWin::zoomIn)); |
98 ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT), |
93 ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT), |
99 sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoomOut)); |
94 sigc::mem_fun(*this, &MainWin::zoomOut)); |
100 ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT), |
95 ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT), |
101 sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoomFit)); |
96 sigc::mem_fun(*this, &MainWin::zoomFit)); |
102 ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100), |
97 ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100), |
103 sigc::mem_fun(*(this->gd_canvas), &GraphDisplayerCanvas::zoom100)); |
98 sigc::mem_fun(*this, &MainWin::zoom100)); |
104 |
99 |
105 ag->add( Gtk::Action::create("ShowMenu", "_Show") ); |
100 ag->add( Gtk::Action::create("ShowMenu", "_Show") ); |
106 ag->add( Gtk::Action::create("ShowMaps", "_Maps"), |
101 ag->add( Gtk::Action::create("ShowMaps", "_Maps"), |
107 sigc::mem_fun(*this, &MainWin::createMapWin)); |
102 sigc::mem_fun(*this, &MainWin::createMapWin)); |
108 |
103 |
109 Gtk::RadioAction::Group tool_group; |
104 Gtk::RadioAction::Group tool_group; |
110 ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), "Move"), |
105 ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), "Move"), |
111 sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 0) ); |
106 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) ); |
112 ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), "Create node"), |
107 ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), "Create node"), |
113 sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 1) ); |
108 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) ); |
114 ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), "Create edge"), |
109 ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), "Create edge"), |
115 sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 2) ); |
110 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) ); |
116 ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), "Delete"), |
111 ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), "Delete"), |
117 sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 3) ); |
112 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) ); |
118 |
113 |
119 ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), "Edit edge map"), |
114 ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), "Edit edge map"), |
120 sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 4) ); |
115 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) ); |
121 ag->add( Gtk::RadioAction::create(tool_group, "EditNodeMap", Gtk::StockID("gd-editnode"), "Edit node map"), |
116 ag->add( Gtk::RadioAction::create(tool_group, "EditNodeMap", Gtk::StockID("gd-editnode"), "Edit node map"), |
122 sigc::bind( sigc::mem_fun ( *(this->gd_canvas), &GraphDisplayerCanvas::changeEditorialTool ), 5) ); |
117 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 5) ); |
123 |
118 |
124 ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")), |
119 ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")), |
125 sigc::mem_fun (new NewMapWin("NewMapWin", *this), &NewMapWin::show ) ); |
120 sigc::mem_fun ( *this , &MainWin::createNewMapWin ) ); |
126 |
121 |
127 uim=Gtk::UIManager::create(); |
122 uim=Gtk::UIManager::create(); |
128 uim->insert_action_group(ag); |
123 uim->insert_action_group(ag); |
129 add_accel_group(uim->get_accel_group()); |
124 add_accel_group(uim->get_accel_group()); |
130 |
125 |
192 { |
188 { |
193 static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS); |
189 static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS); |
194 vbox.pack_start(*toolbar, Gtk::PACK_SHRINK); |
190 vbox.pack_start(*toolbar, Gtk::PACK_SHRINK); |
195 } |
191 } |
196 |
192 |
197 Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow()); |
|
198 pScrolledWindow->set_shadow_type(Gtk::SHADOW_IN); |
|
199 pScrolledWindow->add(*gd_canvas); |
|
200 vbox.pack_start(*pScrolledWindow); |
|
201 |
|
202 tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node"); |
193 tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node"); |
203 tooltips.enable(); |
194 tooltips.enable(); |
204 |
195 |
|
196 active_tab=-1; |
|
197 notebook.signal_switch_page().connect(sigc::mem_fun(*this, &MainWin::onChangeTab)); |
|
198 |
|
199 vbox.pack_start(notebook); |
|
200 |
205 show_all_children(); |
201 show_all_children(); |
206 } |
202 } |
207 |
203 |
208 void MainWin::readFile(const std::string &file) |
204 void MainWin::set_tabtitle(std::string name) |
209 { |
205 { |
210 mapstorage.readFromFile(file); |
206 tabnames[active_tab]=name; |
211 mapstorage.file_name = file; |
207 set_title(tabnames[active_tab] + " - " + prog_name); |
212 mapstorage.modified = false; |
208 notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]); |
213 gd_canvas->drawGraph(); |
209 } |
214 if(mapwinexists) |
210 |
215 { |
211 void MainWin::readFile(const std::string & filename) |
216 mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList()); |
212 { |
217 } |
213 newTab(); |
218 set_title(Glib::filename_display_basename(file) + " - " + prog_name); |
214 tabs[active_tab]->readFile(filename); |
|
215 } |
|
216 |
|
217 void MainWin::newTab() |
|
218 { |
|
219 int size=tabs.size(); |
|
220 tabs.resize(size+1); |
|
221 tabnames.resize(size+1); |
|
222 active_tab=size; |
|
223 tabs[active_tab]=new NoteBookTab(); |
|
224 tabnames[active_tab]="unsaved file"; |
|
225 tabs[active_tab]->signal_title_ch().connect(sigc::mem_fun(*this, &MainWin::set_tabtitle)); |
|
226 tabs[active_tab]->signal_newmap_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinAfterSignal)); |
|
227 tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool); |
|
228 notebook.append_page((Gtk::Widget&)(*(tabs[active_tab]))); |
|
229 notebook.set_current_page(size); |
|
230 set_tabtitle(tabnames[active_tab]); |
|
231 } |
|
232 |
|
233 void MainWin::onChangeTab(GtkNotebookPage* page, guint page_num) |
|
234 { |
|
235 page=page; |
|
236 active_tab=page_num; |
|
237 tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool); |
|
238 set_title(tabnames[active_tab]); |
|
239 } |
|
240 |
|
241 void MainWin::onCloseTab() |
|
242 { |
219 } |
243 } |
220 |
244 |
221 void MainWin::newFile() |
245 void MainWin::newFile() |
222 { |
246 { |
223 if (mapstorage.modified) |
247 if(active_tab!=-1) |
224 { |
248 { |
225 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true, |
249 tabs[active_tab]->newFile(); |
226 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
250 } |
227 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); |
251 } |
228 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
252 |
229 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); |
|
230 switch (mdialog.run()) |
|
231 { |
|
232 case Gtk::RESPONSE_CANCEL: |
|
233 return; |
|
234 case Gtk::RESPONSE_REJECT: |
|
235 break; |
|
236 case Gtk::RESPONSE_ACCEPT: |
|
237 saveFile(); |
|
238 break; |
|
239 } |
|
240 } |
|
241 gd_canvas->clear(); |
|
242 mapstorage.clear(); |
|
243 if(mapwinexists) |
|
244 { |
|
245 mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList()); |
|
246 } |
|
247 set_title("unsaved file - " + prog_name); |
|
248 } |
|
249 |
|
250 void MainWin::openFile() |
253 void MainWin::openFile() |
251 { |
254 { |
252 if (mapstorage.modified) |
255 if(active_tab!=-1) |
253 { |
256 { |
254 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true, |
257 tabs[active_tab]->openFile(); |
255 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
258 } |
256 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); |
259 } |
257 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
260 |
258 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); |
261 void MainWin::saveFile() |
259 switch (mdialog.run()) |
262 { |
260 { |
263 if(active_tab!=-1) |
261 case Gtk::RESPONSE_CANCEL: |
264 { |
262 return; |
265 tabs[active_tab]->saveFile(); |
263 case Gtk::RESPONSE_REJECT: |
266 } |
264 break; |
267 } |
265 case Gtk::RESPONSE_ACCEPT: |
268 |
266 saveFile(); |
269 void MainWin::saveFileAs() |
267 break; |
270 { |
268 } |
271 if(active_tab!=-1) |
269 } |
272 { |
270 Gtk::FileChooserDialog fcdialog("Open File"); |
273 tabs[active_tab]->saveFileAs(); |
271 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
274 } |
272 fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT); |
275 } |
273 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) |
276 |
274 { |
277 void MainWin::close() |
275 gd_canvas->clear(); |
278 { |
276 mapstorage.clear(); |
279 if(active_tab!=-1) |
277 Glib::ustring filename = fcdialog.get_filename(); |
280 { |
278 if (!mapstorage.readFromFile(filename)) |
281 tabs[active_tab]->close(); |
279 { |
282 } |
280 mapstorage.file_name = filename; |
283 } |
281 mapstorage.modified = false; |
284 |
282 gd_canvas->drawGraph(); |
285 void MainWin::zoomIn() |
283 if(mapwinexists) |
286 { |
|
287 if(active_tab!=-1) |
|
288 { |
|
289 tabs[active_tab]->gd_canvas->zoomIn(); |
|
290 } |
|
291 } |
|
292 |
|
293 void MainWin::zoomOut() |
|
294 { |
|
295 if(active_tab!=-1) |
|
296 { |
|
297 tabs[active_tab]->gd_canvas->zoomOut(); |
|
298 } |
|
299 } |
|
300 |
|
301 void MainWin::zoomFit() |
|
302 { |
|
303 if(active_tab!=-1) |
|
304 { |
|
305 tabs[active_tab]->gd_canvas->zoomFit(); |
|
306 } |
|
307 } |
|
308 |
|
309 void MainWin::zoom100() |
|
310 { |
|
311 if(active_tab!=-1) |
|
312 { |
|
313 tabs[active_tab]->gd_canvas->zoom100(); |
|
314 } |
|
315 } |
|
316 |
|
317 void MainWin::createMapWin() |
|
318 { |
|
319 if(active_tab!=-1) |
|
320 { |
|
321 tabs[active_tab]->createMapWin(tabnames[active_tab]); |
|
322 } |
|
323 } |
|
324 |
|
325 void MainWin::changeEditorialTool(int tool) |
|
326 { |
|
327 active_tool=tool; |
|
328 if(active_tab!=-1) |
|
329 { |
|
330 tabs[active_tab]->gd_canvas->changeEditorialTool(tool); |
|
331 } |
|
332 } |
|
333 |
|
334 void MainWin::createNewMapWin() |
|
335 { |
|
336 if(active_tab!=-1) |
|
337 { |
|
338 NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[active_tab], *(tabs[active_tab])); |
|
339 nmw->show(); |
|
340 } |
|
341 } |
|
342 |
|
343 void MainWin::createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisedge) |
|
344 { |
|
345 std::vector<NoteBookTab*>::iterator nbti=tabs.begin(); |
|
346 int i=0; |
|
347 for(;nbti!=tabs.end();nbti++) |
|
348 { |
|
349 if(*nbti!=nbt) |
284 { |
350 { |
285 mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList()); |
351 i++; |
286 } |
352 } |
287 set_title(Glib::filename_display_basename(filename) + " - " + prog_name); |
353 else |
288 } |
354 { |
289 } |
355 continue; |
290 } |
356 } |
291 |
357 } |
292 void MainWin::saveFile() |
358 NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[i], *nbt, itisedge, false); |
293 { |
359 nmw->run(); |
294 if (mapstorage.file_name == "") { |
360 } |
295 saveFileAs(); |
|
296 } |
|
297 else |
|
298 { |
|
299 mapstorage.writeToFile(mapstorage.file_name); |
|
300 mapstorage.modified = false; |
|
301 set_title(Glib::filename_display_basename(mapstorage.file_name) + " - " + |
|
302 prog_name); |
|
303 } |
|
304 } |
|
305 |
|
306 void MainWin::saveFileAs() |
|
307 { |
|
308 Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE); |
|
309 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
|
310 fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); |
|
311 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) |
|
312 { |
|
313 Glib::ustring filename = fcdialog.get_filename(); |
|
314 mapstorage.file_name = filename; |
|
315 mapstorage.writeToFile(filename); |
|
316 mapstorage.modified = false; |
|
317 set_title(Glib::filename_display_basename(filename) + " - " + prog_name); |
|
318 } |
|
319 } |
|
320 |
|
321 void MainWin::close() |
|
322 { |
|
323 if (mapstorage.modified) |
|
324 { |
|
325 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true, |
|
326 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
|
327 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); |
|
328 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
|
329 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); |
|
330 switch (mdialog.run()) |
|
331 { |
|
332 case Gtk::RESPONSE_CANCEL: |
|
333 return; |
|
334 case Gtk::RESPONSE_REJECT: |
|
335 break; |
|
336 case Gtk::RESPONSE_ACCEPT: |
|
337 saveFile(); |
|
338 break; |
|
339 } |
|
340 } |
|
341 gd_canvas->clear(); |
|
342 mapstorage.clear(); |
|
343 if(mapwinexists) |
|
344 { |
|
345 mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList()); |
|
346 } |
|
347 set_title("unsaved file - " + prog_name); |
|
348 } |
|
349 |
|
350 void MainWin::propertyChange(bool itisedge, int prop, std::string mapname) |
|
351 { |
|
352 mapstorage.changeActiveMap(itisedge, prop, mapname); |
|
353 } |
|
354 |
|
355 void MainWin::popupNewMapWin(bool itisedge, int prop) |
|
356 { |
|
357 prop=prop; |
|
358 (new NewMapWin("NewMapWin", *this, itisedge, false))->run(); |
|
359 } |
|
360 |
|
361 std::string MainWin::getActiveEdgeMap(int prop) |
|
362 { |
|
363 return mapstorage.getActiveEdgeMap(prop); |
|
364 } |
|
365 |
|
366 std::string MainWin::getActiveNodeMap(int prop) |
|
367 { |
|
368 return mapstorage.getActiveNodeMap(prop); |
|
369 } |
|
370 |
|
371 void MainWin::registerNewEdgeMap(std::string mapname) |
|
372 { |
|
373 if(mapwinexists) |
|
374 { |
|
375 mapwin->registerNewEdgeMap(mapname); |
|
376 } |
|
377 } |
|
378 |
|
379 void MainWin::registerNewNodeMap(std::string mapname) |
|
380 { |
|
381 if(mapwinexists) |
|
382 { |
|
383 mapwin->registerNewNodeMap(mapname); |
|
384 } |
|
385 } |
|
386 |
|
387 void MainWin::createMapWin() |
|
388 { |
|
389 if(!mapwinexists) |
|
390 { |
|
391 mapwin=new MapWin("Map Setup", mapstorage.getEdgeMapList(), mapstorage.getNodeMapList(), *this); |
|
392 mapwin->show(); |
|
393 mapwinexists=true; |
|
394 } |
|
395 } |
|
396 |
|
397 void MainWin::closeMapWin() |
|
398 { |
|
399 mapwinexists=false; |
|
400 delete mapwin; |
|
401 } |
|