From feb701e35e55ca4a832b282b1d7e0e97a9e597c5 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Thu, 18 Nov 2004 12:58:19 +0000 Subject: [PATCH] determine current cell in the tabular controller instead of the inset git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9265 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ChangeLog | 4 ++ src/frontends/controllers/ControlTabular.C | 23 +++++++--- src/insets/ChangeLog | 5 +++ src/insets/insettabular.C | 51 +++++----------------- src/insets/insettabular.h | 4 +- 5 files changed, 39 insertions(+), 48 deletions(-) diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index ac35000f99..b17637abf5 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,7 @@ +2004-11-18 Georg Baum + + * ControlTabular.C (initialiseParams): Compute the active cell + 2004-11-09 Georg Baum * ControlInclude.C (browse): Use GetExtension() instead of diff --git a/src/frontends/controllers/ControlTabular.C b/src/frontends/controllers/ControlTabular.C index be18472954..5fa7c20cac 100644 --- a/src/frontends/controllers/ControlTabular.C +++ b/src/frontends/controllers/ControlTabular.C @@ -10,7 +10,9 @@ #include +#include "BufferView.h" #include "ControlTabular.h" +#include "cursor.h" #include "funcrequest.h" #include "lyxrc.h" #include "paragraph.h" @@ -29,14 +31,21 @@ ControlTabular::ControlTabular(Dialog & parent) bool ControlTabular::initialiseParams(string const & data) { - Buffer & buffer = kernel().buffer(); - - InsetTabular tmp(buffer); - int cell = InsetTabularMailer::string2params(data, tmp); - if (cell != -1) { - params_.reset(new LyXTabular(tmp.tabular)); - active_cell_ = cell; + // try to get the current cell + BufferView const * const bv = kernel().bufferview(); + if (bv) { + LCursor const & cur = bv->cursor(); + // get the innermost tabular inset; + // assume that it is "ours" + for (int i = cur.size() - 1; i >= 0; --i) + if (cur[i].inset().lyxCode() == InsetBase::TABULAR_CODE) { + active_cell_ = cur[i].idx(); + break; + } } + InsetTabular tmp(kernel().buffer()); + InsetTabularMailer::string2params(data, tmp); + params_.reset(new LyXTabular(tmp.tabular)); return true; } diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 369eb7fb22..83b9841f0d 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2004-11-18 Georg Baum + + * insettabular.[Ch] (string2params): Don't pretend to return the + active cell anymore and simplify keyword parsing. + 2004-11-10 Jean-Marc Lasgouttes * insetlatexaccent.h (isLetter): implement, so that word selection diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index efdcacd229..77560cc055 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -1762,64 +1762,37 @@ string const InsetTabularMailer::inset2string(Buffer const &) const } -int InsetTabularMailer::string2params(string const & in, InsetTabular & inset) +void InsetTabularMailer::string2params(string const & in, InsetTabular & inset) { istringstream data(in); LyXLex lex(0,0); lex.setStream(data); -#ifdef WITH_WARNINGS -#warning CHECK verify that this is a sane value to return. -#endif if (in.empty()) - return -1; + return; - if (lex.isOK()) { - lex.next(); - string const token = lex.getString(); - if (token != name_) - return -1; - } - - int cell = -1; - if (lex.isOK()) { - lex.next(); - string const token = lex.getString(); - if (token != "\\active_cell") - return -1; - lex.next(); - cell = lex.getInteger(); - } + string token; + lex >> token; + if (!lex || token != name_) + return print_mailer_error("InsetTabularMailer", in, 1, + name_); // This is part of the inset proper that is usually swallowed // by Buffer::readInset - if (lex.isOK()) { - lex.next(); - string const token = lex.getString(); - if (token != "Tabular") - return -1; - } - - if (!lex.isOK()) - return -1; + lex >> token; + if (!lex || token != "Tabular") + return print_mailer_error("InsetTabularMailer", in, 2, + "Tabular"); Buffer const & buffer = inset.buffer(); inset.read(buffer, lex); - - // We can't set the active cell, but we can tell the frontend - // what it is. - return cell; } string const InsetTabularMailer::params2string(InsetTabular const & inset) { ostringstream data; -#ifdef WITH_WARNINGS -#warning wrong! -#endif - //data << name_ << " \\active_cell " << inset.getActCell() << '\n'; - data << name_ << " \\active_cell " << 0 << '\n'; + data << name_ << ' '; inset.write(inset.buffer(), data); data << "\\end_inset\n"; return data.str(); diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index a5be0c360c..ec48c8ae6b 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -205,8 +205,8 @@ public: virtual std::string const & name() const { return name_; } /// virtual std::string const inset2string(Buffer const &) const; - /// Returns the active cell if successful, else -1. - static int string2params(std::string const &, InsetTabular &); + /// + static void string2params(std::string const &, InsetTabular &); /// static std::string const params2string(InsetTabular const &); private: -- 2.39.2