From c23eef3abf6a8384c9df7389e7be95ad2842aeb1 Mon Sep 17 00:00:00 2001 From: Tommaso Cucinotta Date: Sun, 8 May 2011 23:51:44 +0000 Subject: [PATCH] Still addressing #6560: instead of cloning the BufferParams, which might cause a number of unforeseen issues (like the inheritance of the default master, as pointed out in http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg168225.html), now we simply set the language into the search & replace buffers. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38647 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferParams.cpp | 15 +++++++++++++-- src/BufferParams.h | 4 ++++ src/frontends/qt4/FindAndReplace.cpp | 25 +++++-------------------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index c52255a130..d27f001102 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -2087,6 +2087,18 @@ void BufferParams::readLocalLayout(Lexer & lex) } +bool BufferParams::setLanguage(string const & lang) +{ + Language const *new_language = languages.getLanguage(lang); + if (!new_language) { + // Language lang was not found + return false; + } + language = new_language; + return true; +} + + void BufferParams::readLanguage(Lexer & lex) { if (!lex.next()) return; @@ -2094,8 +2106,7 @@ void BufferParams::readLanguage(Lexer & lex) string const tmptok = lex.getString(); // check if tmptok is part of tex_babel in tex-defs.h - language = languages.getLanguage(tmptok); - if (!language) { + if (!setLanguage(tmptok)) { // Language tmptok was not found language = default_language; lyxerr << "Warning: Setting language `" diff --git a/src/BufferParams.h b/src/BufferParams.h index ee2b22a248..96747d51f3 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -414,6 +414,10 @@ public: /// use refstyle? or prettyref? bool use_refstyle; + /// Return true if language could be set to lang, + /// otherwise return false and do not change language + bool setLanguage(std::string const & lang); + private: /// void readPreamble(Lexer &); diff --git a/src/frontends/qt4/FindAndReplace.cpp b/src/frontends/qt4/FindAndReplace.cpp index 104ec0ccf0..7934797684 100644 --- a/src/frontends/qt4/FindAndReplace.cpp +++ b/src/frontends/qt4/FindAndReplace.cpp @@ -45,20 +45,6 @@ namespace lyx { namespace frontend { -/// Apply to buf the parameters supplied through bp -static void ApplyParams(Buffer &buf, BufferParams const & bp) { - ostringstream ss; - ss << "\\begin_header\n"; - bp.writeFile(ss); - ss << "\\end_header\n"; - istringstream iss(ss.str()); - Lexer lex; - lex.setStream(iss); - int unknown_tokens = buf.readHeader(lex); - LASSERT(unknown_tokens == 0, /* */); -} - - FindAndReplaceWidget::FindAndReplaceWidget(GuiView & view) : QTabWidget(&view), view_(view) { @@ -489,18 +475,17 @@ void FindAndReplaceWidget::showEvent(QShowEvent * /* ev */) if (bv) { Buffer & doc_buf = bv->buffer(); BufferParams & doc_bp = doc_buf.params(); + string const & lang = doc_bp.language->lang(); Buffer & find_buf = find_work_area_->bufferView().buffer(); LYXERR(Debug::FIND, "Applying document params to find buffer"); - ApplyParams(find_buf, doc_bp); + find_buf.params().setLanguage(lang); Buffer & replace_buf = replace_work_area_->bufferView().buffer(); LYXERR(Debug::FIND, "Applying document params to replace buffer"); - ApplyParams(replace_buf, doc_bp); + replace_buf.params().setLanguage(lang); - string lang = doc_bp.language->lang(); LYXERR(Debug::FIND, "Setting current editing language to " << lang << endl); - FuncRequest cmd(LFUN_LANGUAGE, lang); - find_buf.text().dispatch(find_work_area_->bufferView().cursor(), cmd); - replace_buf.text().dispatch(replace_work_area_->bufferView().cursor(), cmd); + find_work_area_->bufferView().cursor().current_font.setLanguage(doc_bp.language); + replace_work_area_->bufferView().cursor().current_font.setLanguage(doc_bp.language); } find_work_area_->installEventFilter(this);