Changeset 1849:a4d1362397fe in lemon-0.x for gui/main_win.cc
- Timestamp:
- 12/06/05 11:53:38 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2414
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gui/main_win.cc
r1838 r1849 2 2 #include "icons/guipixbufs.h" 3 3 4 MainWin::MainWin():mapwinexists(false) 5 { 6 gd_canvas=new GraphDisplayerCanvas(*this); 7 8 set_title ("unsaved file - " + prog_name); 4 MainWin::MainWin() 5 { 6 set_title ("no file"); 9 7 set_default_size(WIN_WIDTH,WIN_HEIGHT); 10 8 add(vbox); 11 9 12 //connecting signals - controller character13 mapstorage.signal_prop_ch().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::propertyChange));14 15 10 // custom icons for the toolbar 16 17 11 Glib::RefPtr<Gtk::IconFactory> p_icon_factory = Gtk::IconFactory::create(); 18 12 … … 76 70 p_icon_factory->add_default(); 77 71 78 79 72 ag=Gtk::ActionGroup::create(); 80 73 81 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 77 ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW), 83 78 sigc::mem_fun(*this, &MainWin::newFile)); … … 95 90 ag->add( Gtk::Action::create("ViewMenu", "_View") ); 96 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 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 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 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 100 ag->add( Gtk::Action::create("ShowMenu", "_Show") ); … … 109 104 Gtk::RadioAction::Group tool_group; 110 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 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 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 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 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 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 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 122 uim=Gtk::UIManager::create(); … … 136 131 " <menubar name='MenuBar'>" 137 132 " <menu action='FileMenu'>" 133 " <menuitem action='FileNewTab'/>" 138 134 " <menuitem action='FileNew'/>" 139 135 " <menuitem action='FileOpen'/>" … … 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 193 tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node"); 203 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 201 show_all_children(); 206 202 } 207 203 208 void MainWin::readFile(const std::string &file) 209 { 210 mapstorage.readFromFile(file); 211 mapstorage.file_name = file; 212 mapstorage.modified = false; 213 gd_canvas->drawGraph(); 214 if(mapwinexists) 215 { 216 mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList()); 217 } 218 set_title(Glib::filename_display_basename(file) + " - " + prog_name); 204 void MainWin::set_tabtitle(std::string name) 205 { 206 tabnames[active_tab]=name; 207 set_title(tabnames[active_tab] + " - " + prog_name); 208 notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]); 209 } 210 211 void MainWin::readFile(const std::string & filename) 212 { 213 newTab(); 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 245 void MainWin::newFile() 222 246 { 223 if (mapstorage.modified) 224 { 225 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true, 226 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); 227 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); 228 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 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 247 if(active_tab!=-1) 248 { 249 tabs[active_tab]->newFile(); 250 } 251 } 252 250 253 void MainWin::openFile() 251 254 { 252 if (mapstorage.modified) 253 { 254 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true, 255 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); 256 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); 257 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 258 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); 259 switch (mdialog.run()) 260 { 261 case Gtk::RESPONSE_CANCEL: 262 return; 263 case Gtk::RESPONSE_REJECT: 264 break; 265 case Gtk::RESPONSE_ACCEPT: 266 saveFile(); 267 break; 268 } 269 } 270 Gtk::FileChooserDialog fcdialog("Open File"); 271 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 272 fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT); 273 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) 274 { 275 gd_canvas->clear(); 276 mapstorage.clear(); 277 Glib::ustring filename = fcdialog.get_filename(); 278 if (!mapstorage.readFromFile(filename)) 279 { 280 mapstorage.file_name = filename; 281 mapstorage.modified = false; 282 gd_canvas->drawGraph(); 283 if(mapwinexists) 255 if(active_tab!=-1) 256 { 257 tabs[active_tab]->openFile(); 258 } 259 } 260 261 void MainWin::saveFile() 262 { 263 if(active_tab!=-1) 264 { 265 tabs[active_tab]->saveFile(); 266 } 267 } 268 269 void MainWin::saveFileAs() 270 { 271 if(active_tab!=-1) 272 { 273 tabs[active_tab]->saveFileAs(); 274 } 275 } 276 277 void MainWin::close() 278 { 279 if(active_tab!=-1) 280 { 281 tabs[active_tab]->close(); 282 } 283 } 284 285 void MainWin::zoomIn() 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); 288 } 289 } 290 } 291 292 void MainWin::saveFile() 293 { 294 if (mapstorage.file_name == "") { 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 } 353 else 354 { 355 continue; 356 } 357 } 358 NewMapWin * nmw=new NewMapWin("Create New Map - "+tabnames[i], *nbt, itisedge, false); 359 nmw->run(); 360 }
Note: See TracChangeset
for help on using the changeset viewer.