mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Fix missing updates for lazy MacroData
Not all accessors did update the data previously. Therefore it could happen that document export from the command line would output \newcommand, and from GUI it would output \renewcommand for the same macro, simply because in the GUI case the data was updated as a side effect of the GUI thread reading some other member. I also removed the mutable flag for requires_, since this member is always set on construction and does not need any lazy update.
This commit is contained in:
parent
50af06c29b
commit
561c5bfd50
@ -45,16 +45,15 @@ MacroData::MacroData(Buffer * buf)
|
||||
redefinition_(false), type_(MacroTypeNewcommand)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
|
||||
MacroData::MacroData(Buffer * buf, DocIterator const & pos)
|
||||
: buffer_(buf), pos_(pos), queried_(false), numargs_(0),
|
||||
optionals_(0), lockCount_(0), redefinition_(false),
|
||||
type_(MacroTypeNewcommand)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
MacroData::MacroData(Buffer * buf, MathMacroTemplate const & macro)
|
||||
: buffer_(buf), queried_(false), numargs_(0), optionals_(0), lockCount_(0),
|
||||
redefinition_(false), type_(MacroTypeNewcommand)
|
||||
@ -100,7 +99,7 @@ size_t MacroData::optionals() const
|
||||
}
|
||||
|
||||
|
||||
vector<docstring> const & MacroData::defaults() const
|
||||
vector<docstring> const & MacroData::defaults() const
|
||||
{
|
||||
updateData();
|
||||
return defaults_;
|
||||
@ -126,7 +125,7 @@ void MacroData::queryData(MathMacroTemplate const & macro) const
|
||||
redefinition_ = macro.redefinition();
|
||||
type_ = macro.type();
|
||||
optionals_ = macro.numOptionals();
|
||||
|
||||
|
||||
macro.getDefaults(defaults_);
|
||||
}
|
||||
|
||||
@ -137,21 +136,21 @@ void MacroData::updateData() const
|
||||
return;
|
||||
|
||||
LBUFERR(buffer_);
|
||||
|
||||
|
||||
// Try to fix position DocIterator. Should not do anything in theory.
|
||||
pos_.fixIfBroken();
|
||||
|
||||
|
||||
// find macro template
|
||||
Inset * inset = pos_.nextInset();
|
||||
if (inset == 0 || inset->lyxCode() != MATHMACRO_CODE) {
|
||||
lyxerr << "BUG: No macro template found by MacroData" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// query the data from the macro template
|
||||
queryData(static_cast<MathMacroTemplate const &>(*inset));
|
||||
queryData(static_cast<MathMacroTemplate const &>(*inset));
|
||||
}
|
||||
|
||||
|
||||
|
||||
int MacroData::write(odocstream & os, bool overwriteRedefinition) const
|
||||
{
|
||||
@ -163,7 +162,7 @@ int MacroData::write(odocstream & os, bool overwriteRedefinition) const
|
||||
lyxerr << "BUG: No macro template found by MacroData" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// output template
|
||||
MathMacroTemplate const & tmpl =
|
||||
static_cast<MathMacroTemplate const &>(*inset);
|
||||
|
@ -33,7 +33,7 @@ enum MacroType {
|
||||
MacroTypeNewcommandx,
|
||||
MacroTypeDef
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
class MacroData {
|
||||
public:
|
||||
@ -58,27 +58,23 @@ public:
|
||||
///
|
||||
std::vector<docstring> const & defaults() const;
|
||||
///
|
||||
std::string const & requires() const { updateData(); return requires_; }
|
||||
std::string const & requires() const { return requires_; }
|
||||
///
|
||||
std::string & requires() { updateData(); return requires_; }
|
||||
|
||||
std::string & requires() { return requires_; }
|
||||
|
||||
/// lock while being drawn to avoid recursions
|
||||
int lock() const { return ++lockCount_; }
|
||||
/// is it being drawn?
|
||||
bool locked() const { return lockCount_ != 0; }
|
||||
///
|
||||
void unlock() const;
|
||||
|
||||
///
|
||||
bool redefinition() const { return redefinition_; }
|
||||
///
|
||||
void setRedefinition(bool redefined) { redefinition_ = redefined; }
|
||||
|
||||
///
|
||||
MacroType type() const { return type_; }
|
||||
bool redefinition() const { updateData(); return redefinition_; }
|
||||
|
||||
///
|
||||
MacroType & type() { return type_; }
|
||||
|
||||
MacroType type() const { updateData(); return type_; }
|
||||
|
||||
/// output as TeX macro, only works for lazy MacroData!!!
|
||||
int write(odocstream & os, bool overwriteRedefinition) const;
|
||||
|
||||
@ -86,7 +82,7 @@ public:
|
||||
bool operator==(MacroData const & x) const {
|
||||
updateData();
|
||||
x.updateData();
|
||||
return definition_ == x.definition_
|
||||
return definition_ == x.definition_
|
||||
&& numargs_ == x.numargs_
|
||||
&& display_ == x.display_
|
||||
&& requires_ == x.requires_
|
||||
@ -105,10 +101,10 @@ private:
|
||||
Buffer const * buffer_;
|
||||
/// The position of the definition in the buffer.
|
||||
/// There is no guarantee it stays valid if the buffer
|
||||
/// changes. But it (normally) exists only until the
|
||||
/// changes. But it (normally) exists only until the
|
||||
/// next Buffer::updateMacros call where new MacroData
|
||||
/// objects are created for each macro definition.
|
||||
/// In the worst case, it is invalidated and the MacroData
|
||||
/// In the worst case, it is invalidated and the MacroData
|
||||
/// returns its defaults values and the user sees unfolded
|
||||
/// macros.
|
||||
mutable DocIterator pos_;
|
||||
@ -121,7 +117,7 @@ private:
|
||||
///
|
||||
mutable docstring display_;
|
||||
///
|
||||
mutable std::string requires_;
|
||||
std::string requires_;
|
||||
///
|
||||
mutable size_t optionals_;
|
||||
///
|
||||
@ -140,7 +136,7 @@ class MacroNameSet : public std::set<docstring> {};
|
||||
///
|
||||
class MacroSet : public std::set<MacroData const *> {};
|
||||
|
||||
|
||||
|
||||
/// A lookup table of macro definitions.
|
||||
/**
|
||||
* This contains a table of "global" macros that are always accessible,
|
||||
@ -179,10 +175,10 @@ class MacroContext {
|
||||
public:
|
||||
/// construct context for the insets at pos
|
||||
MacroContext(Buffer const * buf, DocIterator const & pos);
|
||||
|
||||
|
||||
/// Lookup macro
|
||||
MacroData const * get(docstring const & name) const;
|
||||
|
||||
|
||||
private:
|
||||
///
|
||||
Buffer const * buf_;
|
||||
|
Loading…
Reference in New Issue
Block a user