ladanyi@53: #include "main_win.h"
ladanyi@6:
ladanyi@53: MainWin::MainWin(const std::string& title) :
ladanyi@53: mapwin("Map Setup", mapstorage, gd_canvas),
ladanyi@53: newmapwin("Creating new map", gd_canvas), gd_canvas(mapstorage, mapwin)
ladanyi@6: {
hegyi@41:
ladanyi@6: set_title (title);
ladanyi@6: set_default_size(WIN_WIDTH,WIN_HEIGHT);
ladanyi@6: add(vbox);
ladanyi@6:
ladanyi@6: ag=Gtk::ActionGroup::create();
ladanyi@6:
ladanyi@6: ag->add( Gtk::Action::create("FileMenu", "_File") );
ladanyi@6: ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
ladanyi@6: sigc::mem_fun(*this, &MainWin::newFile));
ladanyi@6: ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
ladanyi@6: sigc::mem_fun(*this, &MainWin::openFile));
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),
ladanyi@53: sigc::mem_fun(*this, &MainWin::close));
ladanyi@53: ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
hegyi@47: sigc::mem_fun(*this, &MainWin::hide));
ladanyi@6:
ladanyi@6: ag->add( Gtk::Action::create("ViewMenu", "_View") );
ladanyi@6: ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
ladanyi@6: sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn));
ladanyi@6: ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
ladanyi@6: sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut));
ladanyi@6: ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
ladanyi@6: sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit));
ladanyi@6: ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
ladanyi@6: sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100));
ladanyi@6:
ladanyi@6: ag->add( Gtk::Action::create("ShowMenu", "_Show") );
ladanyi@6: ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
hegyi@47: sigc::mem_fun(this->mapwin, &MapWin::show));
ladanyi@6:
ladanyi@53: Gtk::RadioAction::Group tool_group;
ladanyi@53: ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::Stock::CONVERT, "Move"),
ladanyi@53: sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) );
ladanyi@53: ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::Stock::NO, "Create node"),
hegyi@22: sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 1) );
ladanyi@53: ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::Stock::REMOVE, "Create edge"),
hegyi@22: sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 2) );
ladanyi@53: ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::Stock::DELETE, "Delete"),
hegyi@22: sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 3) );
hegyi@32: ag->add( Gtk::Action::create("EditEdgeMap", Gtk::Stock::PROPERTIES),
hegyi@32: sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 4) );
hegyi@32: ag->add( Gtk::Action::create("EditNodeMap", Gtk::Stock::PREFERENCES),
hegyi@32: sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 5) );
hegyi@41: ag->add( Gtk::Action::create("AddMap", Gtk::Stock::NEW),
hegyi@41: sigc::mem_fun ( this->newmapwin, &NewMapWin::show ) );
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: " "
ladanyi@6: " "
ladanyi@6: " "
ladanyi@6: " "
ladanyi@6: " "
ladanyi@6: " "
ladanyi@53: " "
ladanyi@6: " "
ladanyi@6: " "
ladanyi@6: " "
ladanyi@6: " "
ladanyi@6: " "
hegyi@22: " "
ladanyi@53: " "
hegyi@22: " "
hegyi@22: " "
hegyi@22: " "
hegyi@32: " "
hegyi@32: " "
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:
ladanyi@6: Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
ladanyi@6: pScrolledWindow->add(gd_canvas);
ladanyi@6: vbox.pack_start(*pScrolledWindow);
hegyi@50:
hegyi@50: tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
hegyi@50: tooltips.enable();
ladanyi@6:
ladanyi@6: show_all_children();
ladanyi@6: }
ladanyi@6:
ladanyi@6: void MainWin::newFile()
ladanyi@6: {
ladanyi@53: if (mapstorage.modified)
ladanyi@53: {
ladanyi@53: Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING,
ladanyi@53: Gtk::BUTTONS_NONE);
ladanyi@53: mdialog.set_message("Save changes before closing?", true);
ladanyi@53: mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
ladanyi@53: mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
ladanyi@53: mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
ladanyi@53: switch (mdialog.run())
ladanyi@53: {
ladanyi@53: case Gtk::RESPONSE_CANCEL:
ladanyi@53: return;
ladanyi@53: case Gtk::RESPONSE_REJECT:
ladanyi@53: break;
ladanyi@53: case Gtk::RESPONSE_ACCEPT:
ladanyi@53: saveFile();
ladanyi@53: break;
ladanyi@53: }
ladanyi@53: }
ladanyi@53: gd_canvas.clear();
ladanyi@53: mapstorage.clear();
ladanyi@53: mapwin.update();
ladanyi@6: }
ladanyi@6:
ladanyi@6: void MainWin::openFile()
ladanyi@6: {
ladanyi@53: if (mapstorage.modified)
ladanyi@53: {
ladanyi@53: Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING,
ladanyi@53: Gtk::BUTTONS_NONE);
ladanyi@53: mdialog.set_message("Save changes before closing?", true);
ladanyi@53: mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
ladanyi@53: mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
ladanyi@53: mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
ladanyi@53: switch (mdialog.run())
ladanyi@53: {
ladanyi@53: case Gtk::RESPONSE_CANCEL:
ladanyi@53: return;
ladanyi@53: case Gtk::RESPONSE_REJECT:
ladanyi@53: break;
ladanyi@53: case Gtk::RESPONSE_ACCEPT:
ladanyi@53: saveFile();
ladanyi@53: break;
ladanyi@53: }
ladanyi@53: }
ladanyi@53: gd_canvas.clear();
ladanyi@53: mapstorage.clear();
ladanyi@53: Gtk::FileChooserDialog fcdialog("Open File");
ladanyi@53: fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
ladanyi@53: fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
ladanyi@53: if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
ladanyi@53: {
ladanyi@53: Glib::ustring filename = fcdialog.get_filename();
ladanyi@53: mapstorage.readFromFile(filename);
ladanyi@53: mapstorage.file_name = filename;
ladanyi@53: mapstorage.modified = false;
ladanyi@53: gd_canvas.drawGraph();
ladanyi@53: mapwin.update();
ladanyi@53: }
ladanyi@6: }
ladanyi@6:
ladanyi@6: void MainWin::saveFile()
ladanyi@6: {
ladanyi@53: if (mapstorage.file_name == "") {
ladanyi@53: saveFileAs();
ladanyi@53: }
ladanyi@53: else
ladanyi@53: {
ladanyi@53: mapstorage.writeToFile(mapstorage.file_name);
ladanyi@53: mapstorage.modified = false;
ladanyi@53: }
ladanyi@6: }
ladanyi@6:
ladanyi@6: void MainWin::saveFileAs()
ladanyi@6: {
ladanyi@53: Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
ladanyi@53: fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
ladanyi@53: fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
ladanyi@53: if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
ladanyi@53: {
ladanyi@53: Glib::ustring filename = fcdialog.get_filename();
ladanyi@53: mapstorage.file_name = filename;
ladanyi@53: mapstorage.writeToFile(filename);
ladanyi@53: mapstorage.modified = false;
ladanyi@53: }
ladanyi@6: }
ladanyi@53:
ladanyi@53: void MainWin::close()
ladanyi@53: {
ladanyi@53: if (mapstorage.modified)
ladanyi@53: {
ladanyi@53: Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING,
ladanyi@53: Gtk::BUTTONS_NONE);
ladanyi@53: mdialog.set_message("Save changes before closing?", true);
ladanyi@53: mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
ladanyi@53: mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
ladanyi@53: mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
ladanyi@53: switch (mdialog.run())
ladanyi@53: {
ladanyi@53: case Gtk::RESPONSE_CANCEL:
ladanyi@53: return;
ladanyi@53: case Gtk::RESPONSE_REJECT:
ladanyi@53: break;
ladanyi@53: case Gtk::RESPONSE_ACCEPT:
ladanyi@53: saveFile();
ladanyi@53: break;
ladanyi@53: }
ladanyi@53: }
ladanyi@53: gd_canvas.clear();
ladanyi@53: mapstorage.clear();
ladanyi@53: mapwin.update();
ladanyi@53: }