1 #include <main_win.h> |
1 #include "main_win.h" |
2 |
2 |
3 MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm, |
3 MainWin::MainWin(const std::string& title) : |
4 MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),newmapwin("Creating new map",gd_canvas),gd_canvas(graph, cm, ms, &mapwin) |
4 mapwin("Map Setup", mapstorage, gd_canvas), |
|
5 newmapwin("Creating new map", gd_canvas), gd_canvas(mapstorage, mapwin) |
5 { |
6 { |
6 |
7 |
7 set_title (title); |
8 set_title (title); |
8 set_default_size(WIN_WIDTH,WIN_HEIGHT); |
9 set_default_size(WIN_WIDTH,WIN_HEIGHT); |
9 add(vbox); |
10 add(vbox); |
17 sigc::mem_fun(*this, &MainWin::openFile)); |
18 sigc::mem_fun(*this, &MainWin::openFile)); |
18 ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE), |
19 ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE), |
19 sigc::mem_fun(*this, &MainWin::saveFile)); |
20 sigc::mem_fun(*this, &MainWin::saveFile)); |
20 ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS), |
21 ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS), |
21 sigc::mem_fun(*this, &MainWin::saveFileAs)); |
22 sigc::mem_fun(*this, &MainWin::saveFileAs)); |
22 ag->add( Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), |
23 ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE), |
|
24 sigc::mem_fun(*this, &MainWin::close)); |
|
25 ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT), |
23 sigc::mem_fun(*this, &MainWin::hide)); |
26 sigc::mem_fun(*this, &MainWin::hide)); |
24 |
27 |
25 ag->add( Gtk::Action::create("ViewMenu", "_View") ); |
28 ag->add( Gtk::Action::create("ViewMenu", "_View") ); |
26 ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN), |
29 ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN), |
27 sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn)); |
30 sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn)); |
34 |
37 |
35 ag->add( Gtk::Action::create("ShowMenu", "_Show") ); |
38 ag->add( Gtk::Action::create("ShowMenu", "_Show") ); |
36 ag->add( Gtk::Action::create("ShowMaps", "_Maps"), |
39 ag->add( Gtk::Action::create("ShowMaps", "_Maps"), |
37 sigc::mem_fun(this->mapwin, &MapWin::show)); |
40 sigc::mem_fun(this->mapwin, &MapWin::show)); |
38 |
41 |
39 ag->add( Gtk::Action::create("CreateNode", Gtk::Stock::NO), |
42 Gtk::RadioAction::Group tool_group; |
|
43 ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::Stock::CONVERT, "Move"), |
|
44 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) ); |
|
45 ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::Stock::NO, "Create node"), |
40 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 1) ); |
46 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 1) ); |
41 ag->add( Gtk::Action::create("CreateEdge", Gtk::Stock::REMOVE), |
47 ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::Stock::REMOVE, "Create edge"), |
42 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 2) ); |
48 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 2) ); |
43 ag->add( Gtk::Action::create("EraseItem", Gtk::Stock::DELETE), |
49 ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::Stock::DELETE, "Delete"), |
44 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 3) ); |
50 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 3) ); |
45 ag->add( Gtk::Action::create("MoveItem", Gtk::Stock::CONVERT), |
|
46 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) ); |
|
47 ag->add( Gtk::Action::create("EditEdgeMap", Gtk::Stock::PROPERTIES), |
51 ag->add( Gtk::Action::create("EditEdgeMap", Gtk::Stock::PROPERTIES), |
48 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 4) ); |
52 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 4) ); |
49 ag->add( Gtk::Action::create("EditNodeMap", Gtk::Stock::PREFERENCES), |
53 ag->add( Gtk::Action::create("EditNodeMap", Gtk::Stock::PREFERENCES), |
50 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 5) ); |
54 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 5) ); |
51 ag->add( Gtk::Action::create("AddMap", Gtk::Stock::NEW), |
55 ag->add( Gtk::Action::create("AddMap", Gtk::Stock::NEW), |
64 " <menu action='FileMenu'>" |
68 " <menu action='FileMenu'>" |
65 " <menuitem action='FileNew'/>" |
69 " <menuitem action='FileNew'/>" |
66 " <menuitem action='FileOpen'/>" |
70 " <menuitem action='FileOpen'/>" |
67 " <menuitem action='FileSave'/>" |
71 " <menuitem action='FileSave'/>" |
68 " <menuitem action='FileSaveAs'/>" |
72 " <menuitem action='FileSaveAs'/>" |
69 " <menuitem action='FileQuit'/>" |
73 " <menuitem action='Close'/>" |
|
74 " <menuitem action='Quit'/>" |
70 " </menu>" |
75 " </menu>" |
71 " <menu action='ViewMenu'>" |
76 " <menu action='ViewMenu'>" |
72 " <menuitem action='ViewZoomIn' />" |
77 " <menuitem action='ViewZoomIn' />" |
73 " <menuitem action='ViewZoomOut' />" |
78 " <menuitem action='ViewZoomOut' />" |
74 " <menuitem action='ViewZoomFit' />" |
79 " <menuitem action='ViewZoomFit' />" |
80 " </menubar>" |
85 " </menubar>" |
81 " <toolbar name='ToolBar'>" |
86 " <toolbar name='ToolBar'>" |
82 " <toolitem action='FileNew' />" |
87 " <toolitem action='FileNew' />" |
83 " <toolitem action='FileOpen' />" |
88 " <toolitem action='FileOpen' />" |
84 " <toolitem action='FileSave' />" |
89 " <toolitem action='FileSave' />" |
|
90 " <toolitem action='Close' />" |
85 " <separator />" |
91 " <separator />" |
86 " <toolitem action='ViewZoomIn' />" |
92 " <toolitem action='ViewZoomIn' />" |
87 " <toolitem action='ViewZoomOut' />" |
93 " <toolitem action='ViewZoomOut' />" |
88 " <toolitem action='ViewZoomFit' />" |
94 " <toolitem action='ViewZoomFit' />" |
89 " <toolitem action='ViewZoom100' />" |
95 " <toolitem action='ViewZoom100' />" |
90 " <separator />" |
96 " <separator />" |
|
97 " <toolitem action='MoveItem' />" |
91 " <toolitem action='CreateNode' />" |
98 " <toolitem action='CreateNode' />" |
92 " <toolitem action='CreateEdge' />" |
99 " <toolitem action='CreateEdge' />" |
93 " <toolitem action='EraseItem' />" |
100 " <toolitem action='EraseItem' />" |
94 " <toolitem action='MoveItem' />" |
|
95 " <toolitem action='EditEdgeMap' />" |
101 " <toolitem action='EditEdgeMap' />" |
96 " <toolitem action='EditNodeMap' />" |
102 " <toolitem action='EditNodeMap' />" |
97 " <toolitem action='AddMap' />" |
103 " <toolitem action='AddMap' />" |
98 " </toolbar>" |
104 " </toolbar>" |
99 "</ui>"; |
105 "</ui>"; |
128 show_all_children(); |
134 show_all_children(); |
129 } |
135 } |
130 |
136 |
131 void MainWin::newFile() |
137 void MainWin::newFile() |
132 { |
138 { |
133 std::cerr << "MainWin::newFile(): not yet implemented" << std::endl; |
139 if (mapstorage.modified) |
|
140 { |
|
141 Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING, |
|
142 Gtk::BUTTONS_NONE); |
|
143 mdialog.set_message("<b>Save changes before closing?</b>", true); |
|
144 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); |
|
145 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
|
146 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); |
|
147 switch (mdialog.run()) |
|
148 { |
|
149 case Gtk::RESPONSE_CANCEL: |
|
150 return; |
|
151 case Gtk::RESPONSE_REJECT: |
|
152 break; |
|
153 case Gtk::RESPONSE_ACCEPT: |
|
154 saveFile(); |
|
155 break; |
|
156 } |
|
157 } |
|
158 gd_canvas.clear(); |
|
159 mapstorage.clear(); |
|
160 mapwin.update(); |
134 } |
161 } |
135 |
162 |
136 void MainWin::openFile() |
163 void MainWin::openFile() |
137 { |
164 { |
138 std::cerr << "MainWin::openFile(): not yet implemented" << std::endl; |
165 if (mapstorage.modified) |
|
166 { |
|
167 Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING, |
|
168 Gtk::BUTTONS_NONE); |
|
169 mdialog.set_message("<b>Save changes before closing?</b>", true); |
|
170 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); |
|
171 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
|
172 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); |
|
173 switch (mdialog.run()) |
|
174 { |
|
175 case Gtk::RESPONSE_CANCEL: |
|
176 return; |
|
177 case Gtk::RESPONSE_REJECT: |
|
178 break; |
|
179 case Gtk::RESPONSE_ACCEPT: |
|
180 saveFile(); |
|
181 break; |
|
182 } |
|
183 } |
|
184 gd_canvas.clear(); |
|
185 mapstorage.clear(); |
|
186 Gtk::FileChooserDialog fcdialog("Open File"); |
|
187 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
|
188 fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT); |
|
189 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) |
|
190 { |
|
191 Glib::ustring filename = fcdialog.get_filename(); |
|
192 mapstorage.readFromFile(filename); |
|
193 mapstorage.file_name = filename; |
|
194 mapstorage.modified = false; |
|
195 gd_canvas.drawGraph(); |
|
196 mapwin.update(); |
|
197 } |
139 } |
198 } |
140 |
199 |
141 void MainWin::saveFile() |
200 void MainWin::saveFile() |
142 { |
201 { |
143 std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl; |
202 if (mapstorage.file_name == "") { |
|
203 saveFileAs(); |
|
204 } |
|
205 else |
|
206 { |
|
207 mapstorage.writeToFile(mapstorage.file_name); |
|
208 mapstorage.modified = false; |
|
209 } |
144 } |
210 } |
145 |
211 |
146 void MainWin::saveFileAs() |
212 void MainWin::saveFileAs() |
147 { |
213 { |
148 std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl; |
214 Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE); |
149 } |
215 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
|
216 fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); |
|
217 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) |
|
218 { |
|
219 Glib::ustring filename = fcdialog.get_filename(); |
|
220 mapstorage.file_name = filename; |
|
221 mapstorage.writeToFile(filename); |
|
222 mapstorage.modified = false; |
|
223 } |
|
224 } |
|
225 |
|
226 void MainWin::close() |
|
227 { |
|
228 if (mapstorage.modified) |
|
229 { |
|
230 Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING, |
|
231 Gtk::BUTTONS_NONE); |
|
232 mdialog.set_message("<b>Save changes before closing?</b>", true); |
|
233 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); |
|
234 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
|
235 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); |
|
236 switch (mdialog.run()) |
|
237 { |
|
238 case Gtk::RESPONSE_CANCEL: |
|
239 return; |
|
240 case Gtk::RESPONSE_REJECT: |
|
241 break; |
|
242 case Gtk::RESPONSE_ACCEPT: |
|
243 saveFile(); |
|
244 break; |
|
245 } |
|
246 } |
|
247 gd_canvas.clear(); |
|
248 mapstorage.clear(); |
|
249 mapwin.update(); |
|
250 } |