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