ladanyi@1606: #include "main_win.h"
ladanyi@1442:
ladanyi@1606: MainWin::MainWin(const std::string& title) :
ladanyi@1606: mapwin("Map Setup", mapstorage, gd_canvas),
hegyi@1614: newmapwin("Creating new map", gd_canvas), gd_canvas(mapstorage, mapwin, (Gtk::Window *)this)
ladanyi@1442: {
ladanyi@1442: set_title (title);
ladanyi@1442: set_default_size(WIN_WIDTH,WIN_HEIGHT);
ladanyi@1442: add(vbox);
ladanyi@1442:
ladanyi@1442: ag=Gtk::ActionGroup::create();
ladanyi@1442:
ladanyi@1442: ag->add( Gtk::Action::create("FileMenu", "_File") );
ladanyi@1442: ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
ladanyi@1442: sigc::mem_fun(*this, &MainWin::newFile));
ladanyi@1442: ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
ladanyi@1442: sigc::mem_fun(*this, &MainWin::openFile));
ladanyi@1442: ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
ladanyi@1442: sigc::mem_fun(*this, &MainWin::saveFile));
ladanyi@1442: ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
ladanyi@1442: sigc::mem_fun(*this, &MainWin::saveFileAs));
ladanyi@1606: ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
ladanyi@1606: sigc::mem_fun(*this, &MainWin::close));
ladanyi@1606: ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
hegyi@1598: sigc::mem_fun(*this, &MainWin::hide));
ladanyi@1442:
ladanyi@1442: ag->add( Gtk::Action::create("ViewMenu", "_View") );
ladanyi@1442: ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
ladanyi@1442: sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn));
ladanyi@1442: ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
ladanyi@1442: sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut));
ladanyi@1442: ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
ladanyi@1442: sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit));
ladanyi@1442: ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
ladanyi@1442: sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100));
ladanyi@1442:
ladanyi@1442: ag->add( Gtk::Action::create("ShowMenu", "_Show") );
ladanyi@1442: ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
hegyi@1598: sigc::mem_fun(this->mapwin, &MapWin::show));
ladanyi@1442:
ladanyi@1606: Gtk::RadioAction::Group tool_group;
ladanyi@1606: ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::Stock::CONVERT, "Move"),
ladanyi@1606: sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) );
ladanyi@1606: ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::Stock::NO, "Create node"),
hegyi@1502: sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 1) );
ladanyi@1606: ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::Stock::REMOVE, "Create edge"),
hegyi@1502: sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 2) );
ladanyi@1606: ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::Stock::DELETE, "Delete"),
hegyi@1502: sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 3) );
hegyi@1550: ag->add( Gtk::Action::create("EditEdgeMap", Gtk::Stock::PROPERTIES),
hegyi@1550: sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 4) );
hegyi@1550: ag->add( Gtk::Action::create("EditNodeMap", Gtk::Stock::PREFERENCES),
hegyi@1550: sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 5) );
hegyi@1592: ag->add( Gtk::Action::create("AddMap", Gtk::Stock::NEW),
hegyi@1592: sigc::mem_fun ( this->newmapwin, &NewMapWin::show ) );
hegyi@1502:
ladanyi@1442: uim=Gtk::UIManager::create();
ladanyi@1442: uim->insert_action_group(ag);
ladanyi@1442: add_accel_group(uim->get_accel_group());
ladanyi@1442:
ladanyi@1442: try
ladanyi@1442: {
ladanyi@1442:
ladanyi@1442: Glib::ustring ui_info =
ladanyi@1442: ""
ladanyi@1442: " "
ladanyi@1442: " "
ladanyi@1442: " "
ladanyi@1442: " "
ladanyi@1442: " "
ladanyi@1442: " "
ladanyi@1442: " "
ladanyi@1442: " "
ladanyi@1442: " "
ladanyi@1606: " "
ladanyi@1442: " "
ladanyi@1442: " "
ladanyi@1442: " "
ladanyi@1442: " "
ladanyi@1442: " "
hegyi@1502: " "
ladanyi@1606: " "
hegyi@1502: " "
hegyi@1502: " "
hegyi@1502: " "
hegyi@1550: " "
hegyi@1550: " "
hegyi@1592: " "
ladanyi@1442: " "
ladanyi@1442: "";
ladanyi@1442:
ladanyi@1442: uim->add_ui_from_string(ui_info);
ladanyi@1442:
ladanyi@1442: }
ladanyi@1442: catch(const Glib::Error& ex)
ladanyi@1442: {
ladanyi@1442: std::cerr << "building menus failed: " << ex.what();
ladanyi@1442: }
ladanyi@1442:
ladanyi@1442: Gtk::Widget* menubar = uim->get_widget("/MenuBar");
ladanyi@1442: if (menubar){
ladanyi@1442: vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
ladanyi@1442: }
ladanyi@1442:
ladanyi@1442: Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
ladanyi@1442: if (toolbar)
ladanyi@1442: {
ladanyi@1442: static_cast(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
ladanyi@1442: vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
ladanyi@1442: }
ladanyi@1442:
ladanyi@1442: Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
ladanyi@1442: pScrolledWindow->add(gd_canvas);
ladanyi@1442: vbox.pack_start(*pScrolledWindow);
hegyi@1601:
hegyi@1601: tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
hegyi@1601: tooltips.enable();
ladanyi@1442:
ladanyi@1442: show_all_children();
ladanyi@1442: }
ladanyi@1442:
ladanyi@1616: void MainWin::readFile(const std::string &file)
ladanyi@1616: {
ladanyi@1616: mapstorage.readFromFile(file);
ladanyi@1616: mapstorage.file_name = file;
ladanyi@1616: mapstorage.modified = false;
ladanyi@1616: gd_canvas.drawGraph();
ladanyi@1616: mapwin.update();
ladanyi@1616: }
ladanyi@1616:
ladanyi@1442: void MainWin::newFile()
ladanyi@1442: {
ladanyi@1606: if (mapstorage.modified)
ladanyi@1606: {
ladanyi@1615: Gtk::MessageDialog mdialog("Save changes before closing?", true,
ladanyi@1615: Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
ladanyi@1606: mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
ladanyi@1606: mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
ladanyi@1606: mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
ladanyi@1606: switch (mdialog.run())
ladanyi@1606: {
ladanyi@1606: case Gtk::RESPONSE_CANCEL:
ladanyi@1606: return;
ladanyi@1606: case Gtk::RESPONSE_REJECT:
ladanyi@1606: break;
ladanyi@1606: case Gtk::RESPONSE_ACCEPT:
ladanyi@1606: saveFile();
ladanyi@1606: break;
ladanyi@1606: }
ladanyi@1606: }
ladanyi@1606: gd_canvas.clear();
ladanyi@1606: mapstorage.clear();
ladanyi@1606: mapwin.update();
ladanyi@1442: }
ladanyi@1442:
ladanyi@1442: void MainWin::openFile()
ladanyi@1442: {
ladanyi@1606: if (mapstorage.modified)
ladanyi@1606: {
ladanyi@1615: Gtk::MessageDialog mdialog("Save changes before closing?", true,
ladanyi@1615: Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
ladanyi@1606: mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
ladanyi@1606: mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
ladanyi@1606: mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
ladanyi@1606: switch (mdialog.run())
ladanyi@1606: {
ladanyi@1606: case Gtk::RESPONSE_CANCEL:
ladanyi@1606: return;
ladanyi@1606: case Gtk::RESPONSE_REJECT:
ladanyi@1606: break;
ladanyi@1606: case Gtk::RESPONSE_ACCEPT:
ladanyi@1606: saveFile();
ladanyi@1606: break;
ladanyi@1606: }
ladanyi@1606: }
ladanyi@1606: gd_canvas.clear();
ladanyi@1606: mapstorage.clear();
ladanyi@1606: Gtk::FileChooserDialog fcdialog("Open File");
ladanyi@1606: fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
ladanyi@1606: fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
ladanyi@1606: if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
ladanyi@1606: {
ladanyi@1606: Glib::ustring filename = fcdialog.get_filename();
ladanyi@1606: mapstorage.readFromFile(filename);
ladanyi@1606: mapstorage.file_name = filename;
ladanyi@1606: mapstorage.modified = false;
ladanyi@1606: gd_canvas.drawGraph();
ladanyi@1606: mapwin.update();
ladanyi@1606: }
ladanyi@1442: }
ladanyi@1442:
ladanyi@1442: void MainWin::saveFile()
ladanyi@1442: {
ladanyi@1606: if (mapstorage.file_name == "") {
ladanyi@1606: saveFileAs();
ladanyi@1606: }
ladanyi@1606: else
ladanyi@1606: {
ladanyi@1606: mapstorage.writeToFile(mapstorage.file_name);
ladanyi@1606: mapstorage.modified = false;
ladanyi@1606: }
ladanyi@1442: }
ladanyi@1442:
ladanyi@1442: void MainWin::saveFileAs()
ladanyi@1442: {
ladanyi@1606: Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
ladanyi@1606: fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
ladanyi@1606: fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
ladanyi@1606: if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
ladanyi@1606: {
ladanyi@1606: Glib::ustring filename = fcdialog.get_filename();
ladanyi@1606: mapstorage.file_name = filename;
ladanyi@1606: mapstorage.writeToFile(filename);
ladanyi@1606: mapstorage.modified = false;
ladanyi@1606: }
ladanyi@1442: }
ladanyi@1606:
ladanyi@1606: void MainWin::close()
ladanyi@1606: {
ladanyi@1606: if (mapstorage.modified)
ladanyi@1606: {
ladanyi@1615: Gtk::MessageDialog mdialog("Save changes before closing?", true,
ladanyi@1615: Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
ladanyi@1606: mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
ladanyi@1606: mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
ladanyi@1606: mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
ladanyi@1606: switch (mdialog.run())
ladanyi@1606: {
ladanyi@1606: case Gtk::RESPONSE_CANCEL:
ladanyi@1606: return;
ladanyi@1606: case Gtk::RESPONSE_REJECT:
ladanyi@1606: break;
ladanyi@1606: case Gtk::RESPONSE_ACCEPT:
ladanyi@1606: saveFile();
ladanyi@1606: break;
ladanyi@1606: }
ladanyi@1606: }
ladanyi@1606: gd_canvas.clear();
ladanyi@1606: mapstorage.clear();
ladanyi@1606: mapwin.update();
ladanyi@1606: }