ladanyi@130: #ifdef HAVE_CONFIG_H ladanyi@130: #include ladanyi@130: #endif ladanyi@130: ladanyi@53: #include "main_win.h" ladanyi@100: #include "guipixbufs.h" ladanyi@6: ladanyi@133: #include "i18n.h" ladanyi@130: hegyi@96: MainWin::MainWin() ladanyi@6: { hegyi@96: set_title ("no file"); ladanyi@6: set_default_size(WIN_WIDTH,WIN_HEIGHT); ladanyi@6: add(vbox); ladanyi@6: ladanyi@60: // custom icons for the toolbar ladanyi@60: Glib::RefPtr p_icon_factory = Gtk::IconFactory::create(); ladanyi@60: ladanyi@61: Glib::RefPtr p_move_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@61: 2328, gui_icons_move); ladanyi@61: Glib::RefPtr p_addnode_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@61: 2328, gui_icons_addnode); ladanyi@61: Glib::RefPtr p_addlink_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@61: 2328, gui_icons_addlink); ladanyi@61: Glib::RefPtr p_delete_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@61: 2328, gui_icons_delete); ladanyi@61: Glib::RefPtr p_editlink_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@61: 2328, gui_icons_editlink); ladanyi@61: Glib::RefPtr p_newmap_pixbuf = Gdk::Pixbuf::create_from_inline( ladanyi@61: 2328, gui_icons_newmap); ladanyi@60: ladanyi@60: Gtk::IconSource move_icon_source; ladanyi@61: move_icon_source.set_pixbuf(p_move_pixbuf); ladanyi@60: Gtk::IconSet move_icon_set; ladanyi@60: move_icon_set.add_source(move_icon_source); ladanyi@60: p_icon_factory->add(Gtk::StockID("gd-move"), move_icon_set); ladanyi@60: ladanyi@60: Gtk::IconSource addnode_icon_source; ladanyi@61: addnode_icon_source.set_pixbuf(p_addnode_pixbuf); ladanyi@60: Gtk::IconSet addnode_icon_set; ladanyi@60: addnode_icon_set.add_source(addnode_icon_source); ladanyi@60: p_icon_factory->add(Gtk::StockID("gd-addnode"), addnode_icon_set); ladanyi@60: ladanyi@60: Gtk::IconSource addlink_icon_source; ladanyi@61: addlink_icon_source.set_pixbuf(p_addlink_pixbuf); ladanyi@60: Gtk::IconSet addlink_icon_set; ladanyi@60: addlink_icon_set.add_source(addlink_icon_source); ladanyi@60: p_icon_factory->add(Gtk::StockID("gd-addlink"), addlink_icon_set); ladanyi@60: ladanyi@60: Gtk::IconSource delete_icon_source; ladanyi@61: delete_icon_source.set_pixbuf(p_delete_pixbuf); ladanyi@60: Gtk::IconSet delete_icon_set; ladanyi@60: delete_icon_set.add_source(delete_icon_source); ladanyi@60: p_icon_factory->add(Gtk::StockID("gd-delete"), delete_icon_set); ladanyi@60: ladanyi@60: Gtk::IconSource editlink_icon_source; ladanyi@61: editlink_icon_source.set_pixbuf(p_editlink_pixbuf); ladanyi@60: Gtk::IconSet editlink_icon_set; ladanyi@60: editlink_icon_set.add_source(editlink_icon_source); ladanyi@60: p_icon_factory->add(Gtk::StockID("gd-editlink"), editlink_icon_set); ladanyi@60: ladanyi@60: Gtk::IconSource newmap_icon_source; ladanyi@61: newmap_icon_source.set_pixbuf(p_newmap_pixbuf); ladanyi@60: Gtk::IconSet newmap_icon_set; ladanyi@60: newmap_icon_set.add_source(newmap_icon_source); ladanyi@60: p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set); ladanyi@60: ladanyi@60: p_icon_factory->add_default(); ladanyi@60: ladanyi@6: ag=Gtk::ActionGroup::create(); ladanyi@6: ladanyi@130: ag->add( Gtk::Action::create("FileMenu", _("_File")) ); hegyi@102: ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW), hegyi@96: sigc::mem_fun(*this, &MainWin::newTab)); ladanyi@6: ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN), ladanyi@6: sigc::mem_fun(*this, &MainWin::openFile)); ladanyi@130: ag->add( Gtk::Action::create("FileClearTab", _("Clear Tab")), hegyi@102: sigc::mem_fun(*this, &MainWin::newFile)); ladanyi@6: ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE), ladanyi@6: sigc::mem_fun(*this, &MainWin::saveFile)); ladanyi@6: ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS), ladanyi@6: sigc::mem_fun(*this, &MainWin::saveFileAs)); ladanyi@53: ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE), hegyi@102: sigc::mem_fun(*this, &MainWin::closeTab)); ladanyi@53: ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT), hegyi@47: sigc::mem_fun(*this, &MainWin::hide)); ladanyi@6: ladanyi@130: ag->add( Gtk::Action::create("ViewMenu", _("_View")) ); ladanyi@6: ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN), hegyi@96: sigc::mem_fun(*this, &MainWin::zoomIn)); ladanyi@6: ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT), hegyi@96: sigc::mem_fun(*this, &MainWin::zoomOut)); ladanyi@6: ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT), hegyi@96: sigc::mem_fun(*this, &MainWin::zoomFit)); ladanyi@6: ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100), hegyi@96: sigc::mem_fun(*this, &MainWin::zoom100)); ladanyi@6: ladanyi@130: ag->add( Gtk::Action::create("ShowMenu", _("_Show")) ); ladanyi@130: ag->add( Gtk::Action::create("ShowMaps", _("_Maps")), hegyi@95: sigc::mem_fun(*this, &MainWin::createMapWin)); ladanyi@6: ladanyi@130: ag->add( Gtk::Action::create("AlgoMenu", _("_Algorithms")) ); ladanyi@130: ag->add( Gtk::Action::create("AlgoGeneral", _("_General")), hegyi@103: sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 0) ); ladanyi@130: ag->add( Gtk::Action::create("AlgoKruskal", _("_Kruskal")), hegyi@106: sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 1) ); hegyi@103: ladanyi@53: Gtk::RadioAction::Group tool_group; ladanyi@130: ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), _("Move")), hegyi@96: sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) ); ladanyi@130: ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), _("Create node")), hegyi@96: sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) ); ladanyi@130: ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), _("Create edge")), hegyi@96: sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) ); ladanyi@130: ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), _("Delete")), hegyi@96: sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) ); ladanyi@60: ladanyi@130: ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), _("Edit edge map")), hegyi@96: sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) ); ladanyi@60: ladanyi@60: ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")), hegyi@96: sigc::mem_fun ( *this , &MainWin::createNewMapWin ) ); hegyi@22: ladanyi@6: uim=Gtk::UIManager::create(); ladanyi@6: uim->insert_action_group(ag); ladanyi@6: add_accel_group(uim->get_accel_group()); ladanyi@6: ladanyi@6: try ladanyi@6: { ladanyi@6: ladanyi@6: Glib::ustring ui_info = ladanyi@6: "" ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " hegyi@102: " " ladanyi@6: " " ladanyi@6: " " ladanyi@53: " " ladanyi@53: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@87: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " hegyi@103: " " hegyi@103: " " hegyi@106: " " hegyi@103: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@53: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@6: " " ladanyi@87: " " hegyi@22: " " ladanyi@53: " " hegyi@22: " " hegyi@22: " " hegyi@22: " " hegyi@32: " " ladanyi@60: " " hegyi@41: " " ladanyi@6: " " ladanyi@6: ""; ladanyi@6: ladanyi@6: uim->add_ui_from_string(ui_info); ladanyi@6: ladanyi@6: } ladanyi@6: catch(const Glib::Error& ex) ladanyi@6: { ladanyi@6: std::cerr << "building menus failed: " << ex.what(); ladanyi@6: } ladanyi@6: ladanyi@6: Gtk::Widget* menubar = uim->get_widget("/MenuBar"); ladanyi@6: if (menubar){ ladanyi@6: vbox.pack_start(*menubar, Gtk::PACK_SHRINK); ladanyi@6: } ladanyi@6: ladanyi@6: Gtk::Widget* toolbar = uim->get_widget("/ToolBar"); ladanyi@6: if (toolbar) ladanyi@6: { ladanyi@6: static_cast(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS); ladanyi@6: vbox.pack_start(*toolbar, Gtk::PACK_SHRINK); ladanyi@6: } ladanyi@6: hegyi@50: tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node"); hegyi@50: tooltips.enable(); ladanyi@6: hegyi@96: active_tab=-1; hegyi@96: notebook.signal_switch_page().connect(sigc::mem_fun(*this, &MainWin::onChangeTab)); hegyi@96: ladanyi@107: active_tool = MOVE; ladanyi@107: hegyi@96: vbox.pack_start(notebook); hegyi@96: ladanyi@6: show_all_children(); ladanyi@6: } ladanyi@6: hegyi@96: void MainWin::set_tabtitle(std::string name) ladanyi@57: { hegyi@104: if(strinst.find(name)==strinst.end()) hegyi@104: { hegyi@104: tabnames[active_tab]=name; hegyi@104: strinst[name]=1; hegyi@104: } hegyi@104: else hegyi@104: { hegyi@104: strinst[name]++; hegyi@104: std::ostringstream o; hegyi@104: o << strinst[name]; hegyi@104: tabnames[active_tab]=name+" - "+o.str(); hegyi@104: } hegyi@96: set_title(tabnames[active_tab] + " - " + prog_name); hegyi@96: notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]); hegyi@106: updateAlgoWinTabs(); hegyi@96: } hegyi@96: hegyi@96: void MainWin::readFile(const std::string & filename) hegyi@96: { hegyi@96: newTab(); hegyi@96: tabs[active_tab]->readFile(filename); hegyi@96: } hegyi@96: hegyi@96: void MainWin::newTab() hegyi@96: { hegyi@96: int size=tabs.size(); hegyi@96: tabs.resize(size+1); hegyi@96: tabnames.resize(size+1); hegyi@96: active_tab=size; hegyi@96: tabs[active_tab]=new NoteBookTab(); hegyi@96: tabs[active_tab]->signal_title_ch().connect(sigc::mem_fun(*this, &MainWin::set_tabtitle)); hegyi@96: tabs[active_tab]->signal_newmap_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinAfterSignal)); hegyi@96: tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool); hegyi@96: notebook.append_page((Gtk::Widget&)(*(tabs[active_tab]))); hegyi@96: notebook.set_current_page(size); ladanyi@130: set_tabtitle(_("unsaved file")); hegyi@106: updateAlgoWinTabs(); hegyi@96: } hegyi@96: hegyi@97: void MainWin::closeTab() hegyi@97: { hegyi@97: if(active_tab!=-1) hegyi@97: { hegyi@102: if (tabs[active_tab]->mapstorage.modified) hegyi@102: { ladanyi@130: Gtk::MessageDialog mdialog(_("Save changes before closing?"), true, hegyi@102: Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); ladanyi@130: mdialog.add_button(_("Close file _without Saving"), Gtk::RESPONSE_REJECT); hegyi@102: mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); hegyi@102: mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); hegyi@102: switch (mdialog.run()) hegyi@102: { hegyi@102: case Gtk::RESPONSE_CANCEL: hegyi@102: return; hegyi@102: case Gtk::RESPONSE_REJECT: hegyi@102: break; hegyi@102: case Gtk::RESPONSE_ACCEPT: hegyi@102: tabs[active_tab]->saveFile(); hegyi@102: break; hegyi@102: } hegyi@102: } hegyi@97: //tabs vector will be decreased with the deleted value hegyi@97: int size=tabs.size(); hegyi@97: if(size>1) hegyi@97: { hegyi@97: for(int i=active_tab+1;igd_canvas->changeEditorialTool(active_tool); hegyi@96: set_title(tabnames[active_tab]); hegyi@96: } hegyi@96: ladanyi@6: void MainWin::newFile() ladanyi@6: { hegyi@96: if(active_tab!=-1) ladanyi@53: { hegyi@96: tabs[active_tab]->newFile(); ladanyi@53: } ladanyi@6: } hegyi@96: ladanyi@6: void MainWin::openFile() ladanyi@6: { ladanyi@140: if(active_tab==-1) ladanyi@53: { ladanyi@140: newTab(); ladanyi@53: } ladanyi@140: tabs[active_tab]->openFile(); ladanyi@6: } hegyi@96: ladanyi@6: void MainWin::saveFile() ladanyi@6: { hegyi@96: if(active_tab!=-1) hegyi@96: { hegyi@96: tabs[active_tab]->saveFile(); hegyi@96: } ladanyi@6: } hegyi@96: ladanyi@6: void MainWin::saveFileAs() ladanyi@6: { hegyi@96: if(active_tab!=-1) hegyi@96: { hegyi@96: tabs[active_tab]->saveFileAs(); hegyi@96: } ladanyi@6: } hegyi@96: ladanyi@53: void MainWin::close() ladanyi@53: { hegyi@96: if(active_tab!=-1) ladanyi@53: { hegyi@96: tabs[active_tab]->close(); hegyi@95: } hegyi@94: } hegyi@94: hegyi@96: void MainWin::zoomIn() hegyi@94: { hegyi@96: if(active_tab!=-1) hegyi@95: { hegyi@96: tabs[active_tab]->gd_canvas->zoomIn(); hegyi@96: } hegyi@96: } hegyi@96: hegyi@96: void MainWin::zoomOut() hegyi@96: { hegyi@96: if(active_tab!=-1) hegyi@96: { hegyi@96: tabs[active_tab]->gd_canvas->zoomOut(); hegyi@96: } hegyi@96: } hegyi@96: hegyi@96: void MainWin::zoomFit() hegyi@96: { hegyi@96: if(active_tab!=-1) hegyi@96: { hegyi@96: tabs[active_tab]->gd_canvas->zoomFit(); hegyi@96: } hegyi@96: } hegyi@96: hegyi@96: void MainWin::zoom100() hegyi@96: { hegyi@96: if(active_tab!=-1) hegyi@96: { hegyi@96: tabs[active_tab]->gd_canvas->zoom100(); hegyi@95: } hegyi@94: } hegyi@95: hegyi@95: void MainWin::createMapWin() hegyi@95: { hegyi@96: if(active_tab!=-1) hegyi@95: { hegyi@96: tabs[active_tab]->createMapWin(tabnames[active_tab]); hegyi@95: } hegyi@95: } hegyi@95: hegyi@103: void MainWin::createAlgoWin(int algoid) hegyi@103: { hegyi@108: AlgoWin * aw=new AlgoWin(algoid, tabnames); hegyi@103: aw->signal_closing().connect(sigc::mem_fun(*this, &MainWin::deRegisterAlgoWin)); hegyi@106: aw->signal_maplist_needed().connect(sigc::mem_fun(*this, &MainWin::updateAlgoWinMaps)); hegyi@114: aw->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinTabString)); hegyi@103: aws.insert(aw); hegyi@103: aw->show(); hegyi@103: } hegyi@103: hegyi@106: void MainWin::updateAlgoWinTabs() hegyi@103: { hegyi@103: std::set< AlgoWin* >::iterator awsi=aws.begin(); hegyi@103: for(;awsi!=aws.end();awsi++) hegyi@103: { hegyi@103: (*awsi)->update_tablist(tabnames); hegyi@103: } hegyi@103: } hegyi@103: hegyi@108: void MainWin::updateAlgoWinMaps(AlgoWin * awp, std::string tabname) hegyi@108: { hegyi@108: int i=0; hegyi@108: for(;(i<(int)tabnames.size())&&(tabnames[i]!=tabname);i++) hegyi@108: { hegyi@108: } hegyi@108: awp->update_maplist(&(tabs[i]->mapstorage)); hegyi@108: } hegyi@108: hegyi@108: void MainWin::deRegisterAlgoWin(AlgoWin * awp) hegyi@108: { hegyi@108: aws.erase(awp); hegyi@108: } hegyi@108: hegyi@96: void MainWin::changeEditorialTool(int tool) hegyi@95: { hegyi@96: active_tool=tool; hegyi@96: if(active_tab!=-1) hegyi@96: { hegyi@96: tabs[active_tab]->gd_canvas->changeEditorialTool(tool); hegyi@96: } hegyi@95: } hegyi@96: hegyi@96: void MainWin::createNewMapWin() hegyi@96: { hegyi@96: if(active_tab!=-1) hegyi@96: { ladanyi@130: NewMapWin * nmw=new NewMapWin(_("Create New Map - ")+tabnames[active_tab], *(tabs[active_tab])); hegyi@96: nmw->show(); hegyi@96: } hegyi@96: } hegyi@96: hegyi@114: void MainWin::createNewMapWinTabString(std::string tabname, bool itisedge) hegyi@114: { hegyi@114: int i=0; hegyi@120: for(;((i<(int)tabnames.size())&&(tabnames[i]!=tabname));i++) hegyi@114: { hegyi@114: } hegyi@114: createNewMapWinAfterSignal(tabs[i], itisedge); hegyi@114: } hegyi@114: hegyi@96: void MainWin::createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisedge) hegyi@96: { hegyi@96: std::vector::iterator nbti=tabs.begin(); hegyi@96: int i=0; hegyi@96: for(;nbti!=tabs.end();nbti++) hegyi@96: { hegyi@96: if(*nbti!=nbt) hegyi@96: { hegyi@96: i++; hegyi@96: } hegyi@96: else hegyi@96: { hegyi@96: continue; hegyi@96: } hegyi@96: } ladanyi@130: NewMapWin * nmw=new NewMapWin(_("Create New Map - ")+tabnames[i], *nbt, itisedge, false); hegyi@96: nmw->run(); hegyi@96: }