From: Richard Heck Date: Sat, 1 Sep 2007 04:01:13 +0000 (+0000) Subject: This addresses a bug in the module code so far committed. The problem is that changin... X-Git-Tag: 1.6.10~8581 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=1588f9d2010f2abc05e18d1b599952c5ffff600d;p=lyx.git This addresses a bug in the module code so far committed. The problem is that changing the modules used would update the Buffer's TextClass---but it wouldn't update the layouts used by existing paragraphs, the way changing the TextClass does. The solution, obviously, is to do that update. So what I've done is extract that logic from LFUN_TEXTCLASS_APPLY into an updateLayout() routine and then call that from LFUN_BUFFER_PARAMS_APPLY, LFUN_LAYOUT_MODULE_ADD, and LFUN_LAYOUT_MODULES_CLEAR, which are the three places the modules could be changed. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19964 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 19f29fc80b..2dc4086bb4 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -1745,47 +1745,66 @@ void LyXFunc::dispatch(FuncRequest const & cmd) case LFUN_BUFFER_PARAMS_APPLY: { BOOST_ASSERT(lyx_view_); - biblio::CiteEngine const engine = - lyx_view_->buffer()->params().getEngine(); + biblio::CiteEngine const oldEngine = + lyx_view_->buffer()->params().getEngine(); + + Buffer * buffer = lyx_view_->buffer(); + TextClass_ptr oldClass = buffer->params().getTextClass_ptr(); + recordUndoFullDocument(view()); + istringstream ss(argument); Lexer lex(0,0); lex.setStream(ss); - int const unknown_tokens = - lyx_view_->buffer()->readHeader(lex); + int const unknown_tokens = buffer->readHeader(lex); if (unknown_tokens != 0) { lyxerr << "Warning in LFUN_BUFFER_PARAMS_APPLY!\n" - << unknown_tokens << " unknown token" - << (unknown_tokens == 1 ? "" : "s") - << endl; + << unknown_tokens << " unknown token" + << (unknown_tokens == 1 ? "" : "s") + << endl; } - if (engine == lyx_view_->buffer()->params().getEngine()) - break; - - Cursor & cur = view()->cursor(); - FuncRequest fr(LFUN_INSET_REFRESH); - - Inset & inset = lyx_view_->buffer()->inset(); - InsetIterator it = inset_iterator_begin(inset); - InsetIterator const end = inset_iterator_end(inset); - for (; it != end; ++it) - if (it->lyxCode() == Inset::CITE_CODE) - it->dispatch(cur, fr); + + updateLayout(oldClass, buffer); + + biblio::CiteEngine const newEngine = + lyx_view_->buffer()->params().getEngine(); + + if (oldEngine != newEngine) { + Cursor & cur = view()->cursor(); + FuncRequest fr(LFUN_INSET_REFRESH); + + Inset & inset = lyx_view_->buffer()->inset(); + InsetIterator it = inset_iterator_begin(inset); + InsetIterator const end = inset_iterator_end(inset); + for (; it != end; ++it) + if (it->lyxCode() == Inset::CITE_CODE) + it->dispatch(cur, fr); + } + + updateFlags = Update::Force | Update::FitCursor; break; } case LFUN_LAYOUT_MODULES_CLEAR: { BOOST_ASSERT(lyx_view_); - lyx_view_->buffer()->params().clearLayoutModules(); - updateFlags = Update::Force; + Buffer * buffer = lyx_view_->buffer(); + TextClass_ptr oldClass = buffer->params().getTextClass_ptr(); + recordUndoFullDocument(view()); + buffer->params().clearLayoutModules(); + updateLayout(oldClass, buffer); + updateFlags = Update::Force | Update::FitCursor; break; } case LFUN_LAYOUT_MODULE_ADD: { BOOST_ASSERT(lyx_view_); - lyx_view_->buffer()->params().addLayoutModule(argument); - updateFlags = Update::Force; + Buffer * buffer = lyx_view_->buffer(); + TextClass_ptr oldClass = buffer->params().getTextClass_ptr(); + recordUndoFullDocument(view()); + buffer->params().addLayoutModule(argument); + updateLayout(oldClass, buffer); + updateFlags = Update::Force | Update::FitCursor; break; } @@ -1808,22 +1827,11 @@ void LyXFunc::dispatch(FuncRequest const & cmd) // nothing to do break; - lyx_view_->message(_("Converting document to new document class...")); - recordUndoFullDocument(view()); //Save the old, possibly modular, layout for use in conversion. TextClass_ptr oldClass = buffer->params().getTextClass_ptr(); + recordUndoFullDocument(view()); buffer->params().setBaseClass(new_class); - - StableDocIterator backcur(view()->cursor()); - ErrorList & el = buffer->errorList("Class Switch"); - cap::switchBetweenClasses( - oldClass, buffer->params().getTextClass_ptr(), - static_cast(buffer->inset()), el); - - view()->setCursor(backcur.asDocIterator(&(buffer->inset()))); - - buffer->errors("Class Switch"); - updateLabels(*buffer); + updateLayout(oldClass, buffer); updateFlags = Update::Force | Update::FitCursor; break; } @@ -2285,6 +2293,24 @@ bool LyXFunc::wasMetaKey() const } +void LyXFunc::updateLayout(TextClass_ptr const & oldlayout, + Buffer * buffer) +{ + lyx_view_->message(_("Converting document to new document class...")); + + StableDocIterator backcur(view()->cursor()); + ErrorList & el = buffer->errorList("Class Switch"); + cap::switchBetweenClasses( + oldlayout, buffer->params().getTextClass_ptr(), + static_cast(buffer->inset()), el); + + view()->setCursor(backcur.asDocIterator(&(buffer->inset()))); + + buffer->errors("Class Switch"); + updateLabels(*buffer); +} + + namespace { void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new) diff --git a/src/LyXFunc.h b/src/LyXFunc.h index 2e8f286bda..d512bc2018 100644 --- a/src/LyXFunc.h +++ b/src/LyXFunc.h @@ -17,6 +17,7 @@ #include "KeySequence.h" #include "lfuns.h" +#include "TextClass_ptr.h" #include "support/docstring.h" @@ -25,6 +26,7 @@ namespace lyx { +class Buffer; class BufferView; class FuncRequest; class FuncStatus; @@ -125,6 +127,8 @@ private: void reloadBuffer(); /// bool ensureBufferClean(BufferView * bv); + /// + void updateLayout(TextClass_ptr const & oldlayout, Buffer * buffer); }; /// Implementation is in LyX.cpp