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