diff --git a/src/frontends/controllers/ControlParagraph.cpp b/src/frontends/controllers/ControlParagraph.cpp index 4df90883d0..9480c9d112 100644 --- a/src/frontends/controllers/ControlParagraph.cpp +++ b/src/frontends/controllers/ControlParagraph.cpp @@ -31,106 +31,26 @@ namespace lyx { namespace frontend { ControlParagraph::ControlParagraph(Dialog & parent) - : Controller(parent), ininset_(false) + : Controller(parent) {} -bool ControlParagraph::initialiseParams(string const & data) +ParagraphParameters & ControlParagraph::params() { - istringstream is(data); - Lexer lex(0,0); - lex.setStream(is); - - // Set tri-state flag: - // action == 0: show dialog - // action == 1: update dialog, accept changes - // action == 2: update dialog, do not accept changes - int action = 0; - - if (lex.isOK()) { - lex.next(); - string const token = lex.getString(); - - if (token == "show") { - action = 0; - } else if (token == "update") { - lex.next(); - bool const accept = lex.getBool(); - if (lex) { - action = accept ? 1 : 2; - } else { - // Unrecognised update option - return false; - } - } else if (!token.empty()) { - // Unrecognised token - return false; - } - } - - ParagraphParameters tmp; - tmp.read(lex); - - // For now, only reset the params on "show". - // Don't bother checking if the params are different on "update" - if (action == 0) - params_ = tmp; - - // Read the rest of the data irrespective of "show" or "update" - int nset = 0; - while (lex.isOK()) { - lex.next(); - string const token = lex.getString(); - - if (token.empty()) - continue; - - int Int = 0; - if (token == "\\alignpossible" || - token == "\\aligndefault" || - token == "\\ininset") { - lex.next(); - Int = lex.getInteger(); - } else { - // Unrecognised token - return false; - } - - ++nset; - - if (token == "\\alignpossible") { - alignpossible_ = static_cast(Int); - } else if (token == "\\aligndefault") { - aligndefault_ = static_cast(Int); - } else { - ininset_ = Int; - } - } - if (nset != 3) { - return false; - } - - // If "update", then set the activation status of the button controller - if (action > 0) { - bool const accept = action == 1; - dialog().setButtonsValid(accept); - } - return true; + return bufferview()->cursor().paragraph().params(); } -void ControlParagraph::clearParams() +ParagraphParameters const & ControlParagraph::params() const { - params_ = ParagraphParameters(); + return bufferview()->cursor().paragraph().params(); } void ControlParagraph::dispatchParams() { - ostringstream data; - params().write(data); - FuncRequest const fr(LFUN_PARAGRAPH_PARAMS_APPLY, data.str()); - dispatch(fr); + bufferview()->updateMetrics(false); + bufferview()->buffer().changed(); } @@ -150,13 +70,13 @@ bool ControlParagraph::canIndent() const LyXAlignment ControlParagraph::alignPossible() const { - return alignpossible_; + return bufferview()->cursor().paragraph().layout()->alignpossible; } LyXAlignment ControlParagraph::alignDefault() const { - return aligndefault_; + return bufferview()->cursor().paragraph().layout()->align; } } // namespace frontend diff --git a/src/frontends/controllers/ControlParagraph.h b/src/frontends/controllers/ControlParagraph.h index d396771094..1abf56f0e5 100644 --- a/src/frontends/controllers/ControlParagraph.h +++ b/src/frontends/controllers/ControlParagraph.h @@ -25,37 +25,25 @@ public: /// ControlParagraph(Dialog &); /// - virtual bool initialiseParams(std::string const & data); + virtual bool initialiseParams(std::string const & data) { return true; } /// clean-up on hide. - virtual void clearParams(); + virtual void clearParams() {} /// virtual void dispatchParams(); /// virtual bool isBufferDependent() const { return true; } /// - ParagraphParameters & params() { return params_; } + ParagraphParameters & params(); /// - ParagraphParameters const & params() const { return params_; } + ParagraphParameters const & params() const; /// bool haveMulitParSelection(); /// - bool inInset() const { return ininset_; } - /// bool canIndent() const; /// LyXAlignment alignPossible() const; /// LyXAlignment alignDefault() const; - -private: - /// - ParagraphParameters params_; - /// - bool ininset_; - /// - LyXAlignment alignpossible_; - /// - LyXAlignment aligndefault_; }; } // namespace frontend diff --git a/src/frontends/qt4/GuiParagraph.cpp b/src/frontends/qt4/GuiParagraph.cpp index 0606fca896..11c4393477 100644 --- a/src/frontends/qt4/GuiParagraph.cpp +++ b/src/frontends/qt4/GuiParagraph.cpp @@ -166,6 +166,11 @@ LyXAlignment GuiParagraphDialog::getAlignmentFromDialog() void GuiParagraphDialog::applyView() { + // FIXME: We should not access params() at all! + // we should just pass the relevant GUI information + // and let the controller do the rest. + // With this architecture, only current parent paragraph will be + // modified when we have a multi-paragraph selection. ParagraphParameters & params = controller().params(); params.align(getAlignmentFromDialog());