COIN-OR::LEMON - Graph Library

source: lemon-0.x/gui/nbtab.cc @ 1959:264811b995f3

Last change on this file since 1959:264811b995f3 was 1891:56a718d144c4, checked in by Hegyi Péter, 19 years ago

Documentation of NoteBookTab?. Redundant function parameters are removed from other classes as well.

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