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