hegyi@1849
|
1 |
#include <nbtab.h>
|
hegyi@1849
|
2 |
|
hegyi@1849
|
3 |
NoteBookTab::NoteBookTab():mapwinexists(false)
|
hegyi@1849
|
4 |
{
|
hegyi@1849
|
5 |
gd_canvas=new GraphDisplayerCanvas(*this);
|
hegyi@1849
|
6 |
add(*gd_canvas);
|
hegyi@1849
|
7 |
|
hegyi@1849
|
8 |
//connecting signals - controller character
|
hegyi@1849
|
9 |
mapstorage.signal_prop_ch().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::propertyChange));
|
hegyi@1849
|
10 |
show_all_children();
|
hegyi@1849
|
11 |
show();
|
hegyi@1849
|
12 |
}
|
hegyi@1849
|
13 |
|
hegyi@1849
|
14 |
void NoteBookTab::readFile(const std::string &file)
|
hegyi@1849
|
15 |
{
|
hegyi@1849
|
16 |
mapstorage.readFromFile(file);
|
hegyi@1849
|
17 |
mapstorage.file_name = file;
|
hegyi@1849
|
18 |
mapstorage.modified = false;
|
hegyi@1849
|
19 |
gd_canvas->drawGraph();
|
hegyi@1849
|
20 |
if(mapwinexists)
|
hegyi@1849
|
21 |
{
|
hegyi@1849
|
22 |
mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
|
hegyi@1849
|
23 |
}
|
hegyi@1849
|
24 |
signal_title.emit(Glib::filename_display_basename(file));
|
hegyi@1849
|
25 |
}
|
hegyi@1849
|
26 |
|
hegyi@1849
|
27 |
void NoteBookTab::newFile()
|
hegyi@1849
|
28 |
{
|
hegyi@1849
|
29 |
if (mapstorage.modified)
|
hegyi@1849
|
30 |
{
|
hegyi@1849
|
31 |
Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
|
hegyi@1849
|
32 |
Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
|
hegyi@1849
|
33 |
mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
|
hegyi@1849
|
34 |
mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
hegyi@1849
|
35 |
mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
|
hegyi@1849
|
36 |
switch (mdialog.run())
|
hegyi@1849
|
37 |
{
|
hegyi@1849
|
38 |
case Gtk::RESPONSE_CANCEL:
|
hegyi@1849
|
39 |
return;
|
hegyi@1849
|
40 |
case Gtk::RESPONSE_REJECT:
|
hegyi@1849
|
41 |
break;
|
hegyi@1849
|
42 |
case Gtk::RESPONSE_ACCEPT:
|
hegyi@1849
|
43 |
saveFile();
|
hegyi@1849
|
44 |
break;
|
hegyi@1849
|
45 |
}
|
hegyi@1849
|
46 |
}
|
hegyi@1849
|
47 |
gd_canvas->clear();
|
hegyi@1849
|
48 |
mapstorage.clear();
|
hegyi@1849
|
49 |
if(mapwinexists)
|
hegyi@1849
|
50 |
{
|
hegyi@1849
|
51 |
mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
|
hegyi@1849
|
52 |
}
|
hegyi@1849
|
53 |
signal_title.emit("unsaved file");
|
hegyi@1849
|
54 |
}
|
hegyi@1849
|
55 |
|
hegyi@1849
|
56 |
void NoteBookTab::openFile()
|
hegyi@1849
|
57 |
{
|
hegyi@1849
|
58 |
if (mapstorage.modified)
|
hegyi@1849
|
59 |
{
|
hegyi@1849
|
60 |
Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
|
hegyi@1849
|
61 |
Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
|
hegyi@1849
|
62 |
mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
|
hegyi@1849
|
63 |
mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
hegyi@1849
|
64 |
mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
|
hegyi@1849
|
65 |
switch (mdialog.run())
|
hegyi@1849
|
66 |
{
|
hegyi@1849
|
67 |
case Gtk::RESPONSE_CANCEL:
|
hegyi@1849
|
68 |
return;
|
hegyi@1849
|
69 |
case Gtk::RESPONSE_REJECT:
|
hegyi@1849
|
70 |
break;
|
hegyi@1849
|
71 |
case Gtk::RESPONSE_ACCEPT:
|
hegyi@1849
|
72 |
saveFile();
|
hegyi@1849
|
73 |
break;
|
hegyi@1849
|
74 |
}
|
hegyi@1849
|
75 |
}
|
hegyi@1849
|
76 |
Gtk::FileChooserDialog fcdialog("Open File");
|
hegyi@1849
|
77 |
fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
hegyi@1849
|
78 |
fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
|
hegyi@1849
|
79 |
if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
|
hegyi@1849
|
80 |
{
|
hegyi@1849
|
81 |
gd_canvas->clear();
|
hegyi@1849
|
82 |
mapstorage.clear();
|
hegyi@1849
|
83 |
Glib::ustring filename = fcdialog.get_filename();
|
hegyi@1849
|
84 |
if (!mapstorage.readFromFile(filename))
|
hegyi@1849
|
85 |
{
|
hegyi@1849
|
86 |
mapstorage.file_name = filename;
|
hegyi@1849
|
87 |
mapstorage.modified = false;
|
hegyi@1849
|
88 |
gd_canvas->drawGraph();
|
hegyi@1849
|
89 |
if(mapwinexists)
|
hegyi@1849
|
90 |
{
|
hegyi@1849
|
91 |
mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
|
hegyi@1849
|
92 |
}
|
hegyi@1849
|
93 |
signal_title.emit(Glib::filename_display_basename(filename));
|
hegyi@1849
|
94 |
}
|
hegyi@1849
|
95 |
}
|
hegyi@1849
|
96 |
}
|
hegyi@1849
|
97 |
|
hegyi@1849
|
98 |
void NoteBookTab::saveFile()
|
hegyi@1849
|
99 |
{
|
hegyi@1849
|
100 |
if (mapstorage.file_name == "") {
|
hegyi@1849
|
101 |
saveFileAs();
|
hegyi@1849
|
102 |
}
|
hegyi@1849
|
103 |
else
|
hegyi@1849
|
104 |
{
|
hegyi@1849
|
105 |
mapstorage.writeToFile(mapstorage.file_name);
|
hegyi@1849
|
106 |
mapstorage.modified = false;
|
hegyi@1849
|
107 |
signal_title.emit(Glib::filename_display_basename(mapstorage.file_name));
|
hegyi@1849
|
108 |
}
|
hegyi@1849
|
109 |
}
|
hegyi@1849
|
110 |
|
hegyi@1849
|
111 |
void NoteBookTab::saveFileAs()
|
hegyi@1849
|
112 |
{
|
hegyi@1849
|
113 |
Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
|
hegyi@1849
|
114 |
fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
hegyi@1849
|
115 |
fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
|
hegyi@1849
|
116 |
if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
|
hegyi@1849
|
117 |
{
|
hegyi@1849
|
118 |
Glib::ustring filename = fcdialog.get_filename();
|
hegyi@1849
|
119 |
mapstorage.file_name = filename;
|
hegyi@1849
|
120 |
mapstorage.writeToFile(filename);
|
hegyi@1849
|
121 |
mapstorage.modified = false;
|
hegyi@1849
|
122 |
signal_title.emit(Glib::filename_display_basename(filename));
|
hegyi@1849
|
123 |
}
|
hegyi@1849
|
124 |
}
|
hegyi@1849
|
125 |
|
hegyi@1849
|
126 |
void NoteBookTab::close()
|
hegyi@1849
|
127 |
{
|
hegyi@1849
|
128 |
if (mapstorage.modified)
|
hegyi@1849
|
129 |
{
|
hegyi@1849
|
130 |
Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
|
hegyi@1849
|
131 |
Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
|
hegyi@1849
|
132 |
mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
|
hegyi@1849
|
133 |
mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
hegyi@1849
|
134 |
mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
|
hegyi@1849
|
135 |
switch (mdialog.run())
|
hegyi@1849
|
136 |
{
|
hegyi@1849
|
137 |
case Gtk::RESPONSE_CANCEL:
|
hegyi@1849
|
138 |
return;
|
hegyi@1849
|
139 |
case Gtk::RESPONSE_REJECT:
|
hegyi@1849
|
140 |
break;
|
hegyi@1849
|
141 |
case Gtk::RESPONSE_ACCEPT:
|
hegyi@1849
|
142 |
saveFile();
|
hegyi@1849
|
143 |
break;
|
hegyi@1849
|
144 |
}
|
hegyi@1849
|
145 |
}
|
hegyi@1849
|
146 |
gd_canvas->clear();
|
hegyi@1849
|
147 |
mapstorage.clear();
|
hegyi@1849
|
148 |
if(mapwinexists)
|
hegyi@1849
|
149 |
{
|
hegyi@1849
|
150 |
mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
|
hegyi@1849
|
151 |
}
|
hegyi@1849
|
152 |
signal_title.emit("unsaved file");
|
hegyi@1849
|
153 |
}
|
hegyi@1849
|
154 |
|
hegyi@1849
|
155 |
void NoteBookTab::propertyChange(bool itisedge, int prop, std::string mapname)
|
hegyi@1849
|
156 |
{
|
hegyi@1849
|
157 |
mapstorage.changeActiveMap(itisedge, prop, mapname);
|
hegyi@1849
|
158 |
}
|
hegyi@1849
|
159 |
|
hegyi@1849
|
160 |
sigc::signal<void, NoteBookTab *, bool> NoteBookTab::signal_newmap_needed()
|
hegyi@1849
|
161 |
{
|
hegyi@1849
|
162 |
return signal_newmap;
|
hegyi@1849
|
163 |
}
|
hegyi@1849
|
164 |
|
hegyi@1849
|
165 |
void NoteBookTab::popupNewMapWin(bool itisedge, int prop)
|
hegyi@1849
|
166 |
{
|
hegyi@1849
|
167 |
prop=prop;
|
hegyi@1849
|
168 |
signal_newmap.emit(this, itisedge);
|
hegyi@1849
|
169 |
}
|
hegyi@1849
|
170 |
|
hegyi@1849
|
171 |
std::string NoteBookTab::getActiveEdgeMap(int prop)
|
hegyi@1849
|
172 |
{
|
hegyi@1849
|
173 |
return mapstorage.getActiveEdgeMap(prop);
|
hegyi@1849
|
174 |
}
|
hegyi@1849
|
175 |
|
hegyi@1849
|
176 |
std::string NoteBookTab::getActiveNodeMap(int prop)
|
hegyi@1849
|
177 |
{
|
hegyi@1849
|
178 |
return mapstorage.getActiveNodeMap(prop);
|
hegyi@1849
|
179 |
}
|
hegyi@1849
|
180 |
|
hegyi@1849
|
181 |
void NoteBookTab::registerNewEdgeMap(std::string mapname)
|
hegyi@1849
|
182 |
{
|
hegyi@1849
|
183 |
if(mapwinexists)
|
hegyi@1849
|
184 |
{
|
hegyi@1849
|
185 |
mapwin->registerNewEdgeMap(mapname);
|
hegyi@1849
|
186 |
}
|
hegyi@1849
|
187 |
}
|
hegyi@1849
|
188 |
|
hegyi@1849
|
189 |
void NoteBookTab::registerNewNodeMap(std::string mapname)
|
hegyi@1849
|
190 |
{
|
hegyi@1849
|
191 |
if(mapwinexists)
|
hegyi@1849
|
192 |
{
|
hegyi@1849
|
193 |
mapwin->registerNewNodeMap(mapname);
|
hegyi@1849
|
194 |
}
|
hegyi@1849
|
195 |
}
|
hegyi@1849
|
196 |
|
hegyi@1849
|
197 |
void NoteBookTab::createMapWin(std::string name)
|
hegyi@1849
|
198 |
{
|
hegyi@1849
|
199 |
if(!mapwinexists)
|
hegyi@1849
|
200 |
{
|
hegyi@1849
|
201 |
mapwin=new MapWin("Map Setup - "+name, mapstorage.getEdgeMapList(), mapstorage.getNodeMapList(), *this);
|
hegyi@1849
|
202 |
mapwin->show();
|
hegyi@1849
|
203 |
mapwinexists=true;
|
hegyi@1849
|
204 |
}
|
hegyi@1849
|
205 |
}
|
hegyi@1849
|
206 |
|
hegyi@1849
|
207 |
void NoteBookTab::closeMapWin()
|
hegyi@1849
|
208 |
{
|
hegyi@1849
|
209 |
mapwinexists=false;
|
hegyi@1849
|
210 |
delete mapwin;
|
hegyi@1849
|
211 |
}
|
hegyi@1849
|
212 |
|
hegyi@1849
|
213 |
sigc::signal<void, std::string> NoteBookTab::signal_title_ch()
|
hegyi@1849
|
214 |
{
|
hegyi@1849
|
215 |
return signal_title;
|
hegyi@1849
|
216 |
}
|
hegyi@1849
|
217 |
|