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