mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-08 20:32:49 +00:00
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
This commit is contained in:
parent
9ff98fb5bc
commit
1588f9d201
@ -1745,47 +1745,66 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
|||||||
|
|
||||||
case LFUN_BUFFER_PARAMS_APPLY: {
|
case LFUN_BUFFER_PARAMS_APPLY: {
|
||||||
BOOST_ASSERT(lyx_view_);
|
BOOST_ASSERT(lyx_view_);
|
||||||
biblio::CiteEngine const engine =
|
biblio::CiteEngine const oldEngine =
|
||||||
lyx_view_->buffer()->params().getEngine();
|
lyx_view_->buffer()->params().getEngine();
|
||||||
|
|
||||||
|
Buffer * buffer = lyx_view_->buffer();
|
||||||
|
|
||||||
|
TextClass_ptr oldClass = buffer->params().getTextClass_ptr();
|
||||||
|
recordUndoFullDocument(view());
|
||||||
|
|
||||||
istringstream ss(argument);
|
istringstream ss(argument);
|
||||||
Lexer lex(0,0);
|
Lexer lex(0,0);
|
||||||
lex.setStream(ss);
|
lex.setStream(ss);
|
||||||
int const unknown_tokens =
|
int const unknown_tokens = buffer->readHeader(lex);
|
||||||
lyx_view_->buffer()->readHeader(lex);
|
|
||||||
|
|
||||||
if (unknown_tokens != 0) {
|
if (unknown_tokens != 0) {
|
||||||
lyxerr << "Warning in LFUN_BUFFER_PARAMS_APPLY!\n"
|
lyxerr << "Warning in LFUN_BUFFER_PARAMS_APPLY!\n"
|
||||||
<< unknown_tokens << " unknown token"
|
<< unknown_tokens << " unknown token"
|
||||||
<< (unknown_tokens == 1 ? "" : "s")
|
<< (unknown_tokens == 1 ? "" : "s")
|
||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
if (engine == lyx_view_->buffer()->params().getEngine())
|
|
||||||
break;
|
updateLayout(oldClass, buffer);
|
||||||
|
|
||||||
Cursor & cur = view()->cursor();
|
biblio::CiteEngine const newEngine =
|
||||||
FuncRequest fr(LFUN_INSET_REFRESH);
|
lyx_view_->buffer()->params().getEngine();
|
||||||
|
|
||||||
Inset & inset = lyx_view_->buffer()->inset();
|
if (oldEngine != newEngine) {
|
||||||
InsetIterator it = inset_iterator_begin(inset);
|
Cursor & cur = view()->cursor();
|
||||||
InsetIterator const end = inset_iterator_end(inset);
|
FuncRequest fr(LFUN_INSET_REFRESH);
|
||||||
for (; it != end; ++it)
|
|
||||||
if (it->lyxCode() == Inset::CITE_CODE)
|
Inset & inset = lyx_view_->buffer()->inset();
|
||||||
it->dispatch(cur, fr);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case LFUN_LAYOUT_MODULES_CLEAR: {
|
case LFUN_LAYOUT_MODULES_CLEAR: {
|
||||||
BOOST_ASSERT(lyx_view_);
|
BOOST_ASSERT(lyx_view_);
|
||||||
lyx_view_->buffer()->params().clearLayoutModules();
|
Buffer * buffer = lyx_view_->buffer();
|
||||||
updateFlags = Update::Force;
|
TextClass_ptr oldClass = buffer->params().getTextClass_ptr();
|
||||||
|
recordUndoFullDocument(view());
|
||||||
|
buffer->params().clearLayoutModules();
|
||||||
|
updateLayout(oldClass, buffer);
|
||||||
|
updateFlags = Update::Force | Update::FitCursor;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case LFUN_LAYOUT_MODULE_ADD: {
|
case LFUN_LAYOUT_MODULE_ADD: {
|
||||||
BOOST_ASSERT(lyx_view_);
|
BOOST_ASSERT(lyx_view_);
|
||||||
lyx_view_->buffer()->params().addLayoutModule(argument);
|
Buffer * buffer = lyx_view_->buffer();
|
||||||
updateFlags = Update::Force;
|
TextClass_ptr oldClass = buffer->params().getTextClass_ptr();
|
||||||
|
recordUndoFullDocument(view());
|
||||||
|
buffer->params().addLayoutModule(argument);
|
||||||
|
updateLayout(oldClass, buffer);
|
||||||
|
updateFlags = Update::Force | Update::FitCursor;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1808,22 +1827,11 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
|||||||
// nothing to do
|
// nothing to do
|
||||||
break;
|
break;
|
||||||
|
|
||||||
lyx_view_->message(_("Converting document to new document class..."));
|
|
||||||
recordUndoFullDocument(view());
|
|
||||||
//Save the old, possibly modular, layout for use in conversion.
|
//Save the old, possibly modular, layout for use in conversion.
|
||||||
TextClass_ptr oldClass = buffer->params().getTextClass_ptr();
|
TextClass_ptr oldClass = buffer->params().getTextClass_ptr();
|
||||||
|
recordUndoFullDocument(view());
|
||||||
buffer->params().setBaseClass(new_class);
|
buffer->params().setBaseClass(new_class);
|
||||||
|
updateLayout(oldClass, buffer);
|
||||||
StableDocIterator backcur(view()->cursor());
|
|
||||||
ErrorList & el = buffer->errorList("Class Switch");
|
|
||||||
cap::switchBetweenClasses(
|
|
||||||
oldClass, buffer->params().getTextClass_ptr(),
|
|
||||||
static_cast<InsetText &>(buffer->inset()), el);
|
|
||||||
|
|
||||||
view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
|
|
||||||
|
|
||||||
buffer->errors("Class Switch");
|
|
||||||
updateLabels(*buffer);
|
|
||||||
updateFlags = Update::Force | Update::FitCursor;
|
updateFlags = Update::Force | Update::FitCursor;
|
||||||
break;
|
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<InsetText &>(buffer->inset()), el);
|
||||||
|
|
||||||
|
view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
|
||||||
|
|
||||||
|
buffer->errors("Class Switch");
|
||||||
|
updateLabels(*buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
|
void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include "KeySequence.h"
|
#include "KeySequence.h"
|
||||||
#include "lfuns.h"
|
#include "lfuns.h"
|
||||||
|
#include "TextClass_ptr.h"
|
||||||
|
|
||||||
#include "support/docstring.h"
|
#include "support/docstring.h"
|
||||||
|
|
||||||
@ -25,6 +26,7 @@
|
|||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
|
class Buffer;
|
||||||
class BufferView;
|
class BufferView;
|
||||||
class FuncRequest;
|
class FuncRequest;
|
||||||
class FuncStatus;
|
class FuncStatus;
|
||||||
@ -125,6 +127,8 @@ private:
|
|||||||
void reloadBuffer();
|
void reloadBuffer();
|
||||||
///
|
///
|
||||||
bool ensureBufferClean(BufferView * bv);
|
bool ensureBufferClean(BufferView * bv);
|
||||||
|
///
|
||||||
|
void updateLayout(TextClass_ptr const & oldlayout, Buffer * buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Implementation is in LyX.cpp
|
/// Implementation is in LyX.cpp
|
||||||
|
Loading…
Reference in New Issue
Block a user