Logo Search packages:      
Sourcecode: cadabra version File versions

Glib::RefPtr< DataCell > XCadabra::add_cell ( Glib::RefPtr< DataCell newcell,
Glib::RefPtr< DataCell ref,
bool  before = true 
)

Adding and removing cells from the current document. These routines also update all NotebookCanvas objects so that they reflect the current structure of the document. The DataCell ownership is handled by the XCadabra class once it has been added here.

Definition at line 1474 of file window.cc.

References canvasses.

Referenced by on_file_new(), and receive().

      {
      modified=true;
      update_title();

      // First the data object, of which there is only one per cell.
      if(ref==0)
            datacells.push_back(newcell);
      else {
            DataCells_t::iterator fnd=find(datacells.begin(), datacells.end(), ref); 
            if(fnd==datacells.end()) {
                  datacells.push_back(newcell);
                  }
            else {
                   if(!before) {
                          do {
                                    ++fnd;
                                    } while( fnd!=datacells.end() &&
                                                      ( (*fnd)->cell_type==DataCell::c_output ||
                                                        (*fnd)->cell_type==DataCell::c_error ) );
                          }
                  datacells.insert(fnd, newcell);
                  }
            }

      Gtk::Allocation al=get_allocation();

      try {
            switch(newcell->cell_type) {
                  case DataCell::c_output:
                        newcell->texbuf->generate("\\begin{dmath*}[compact,spread=2pt]\n","\\end{dmath*}\n");
                        break;
                  case DataCell::c_comment:
                        newcell->texbuf->generate("\\begin{verbatim}\n","\\end{verbatim}\n");
                        break;
                  case DataCell::c_input:
                        newcell->textbuf->signal_changed().connect(sigc::mem_fun(this, &XCadabra::input_cell_modified));

                        // Connect insert/delete signals to undo stack handler.
                        newcell->textbuf->signal_insert().connect(
                              sigc::bind<Glib::RefPtr<DataCell> >(sigc::mem_fun(this, &XCadabra::on_my_insert), newcell), false);
                        newcell->textbuf->signal_erase().connect(
                              sigc::bind<Glib::RefPtr<DataCell> >(sigc::mem_fun(this, &XCadabra::on_my_erase), newcell), false);

                        break;
                  case DataCell::c_error:
                        newcell->texbuf->generate("{\\color[named]{Red}", "}");
                        break;
                  case DataCell::c_tex:
                        newcell->texbuf->generate("","");
                        newcell->textbuf->signal_changed().connect(sigc::mem_fun(this, &XCadabra::tex_cell_modified));

                        // Connect insert/delete signals to undo/redo stack handler.
                        newcell->texbuf->tex_source->signal_insert().connect(
                              sigc::bind<Glib::RefPtr<DataCell> >(sigc::mem_fun(this, &XCadabra::on_my_insert), newcell), false);
                        newcell->texbuf->tex_source->signal_erase().connect(
                              sigc::bind<Glib::RefPtr<DataCell> >(sigc::mem_fun(this, &XCadabra::on_my_erase), newcell), false);

                        break;
                  }
            
            // Now we have to tell all NotebookCanvas objects to create a
            // view on the just created DataCell. 
            
            for(unsigned int i=0; i<canvasses.size(); ++i) {
                  VisualCell *vis=canvasses[i]->add_cell(newcell, ref, before);
                  if(canvasses[i]==active_canvas) {
                        //                active_canvas->cell_grab_focus(vis);
                        // make this new cell the active cell if it is an input or tex cell.
                        if(newcell->cell_type==DataCell::c_input || newcell->cell_type==DataCell::c_tex)
                              active_cell=vis;
                        }
                  }
            }
      catch(std::exception& ex) {
            kernel_idle();
            size_t lines=1;
            std::string what=ex.what();
            for(size_t i=0; i<what.size(); ++i)
                  if(what[i]=='\n')
                        ++lines;
            if(lines<11) {
                  Gtk::MessageDialog md(ex.what());
                  md.set_type_hint(Gdk::WINDOW_TYPE_HINT_DIALOG);
                  md.run();
                  }
            else {
                  Gtk::Dialog md;
                  Gtk::TextView tv;
                  Glib::RefPtr<Gtk::TextBuffer> tb=Gtk::TextBuffer::create();
                  Gtk::ScrolledWindow sw;
                  Gtk::Button ok(Gtk::Stock::OK);
                  tb->set_text(ex.what());
                  md.get_vbox()->add(sw);
                  md.add_button(Gtk::Stock::OK, 1);
                  sw.add(tv);
                  tv.set_buffer(tb);
                  tv.set_editable(false);
                  md.set_size_request(400,300);
                  md.show_all();
                  md.run();
                  }
            }


      return newcell;
      }


Generated by  Doxygen 1.6.0   Back to index