mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-12 16:50:39 +00:00
Fix bug #7183 (User math macros defined in child documents are shadowed on loading)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@36986 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
b9c2a9229d
commit
5738192a31
@ -634,6 +634,14 @@ bool Buffer::readDocument(Lexer & lex)
|
||||
// read main text
|
||||
bool const res = text().read(*this, lex, errorList, d->inset);
|
||||
|
||||
// inform parent buffer about local macros
|
||||
if (parent()) {
|
||||
Buffer const * pbuf = parent();
|
||||
UserMacroSet::const_iterator cit = usermacros.begin();
|
||||
UserMacroSet::const_iterator end = usermacros.end();
|
||||
for (; cit != end; ++cit)
|
||||
pbuf->usermacros.insert(*cit);
|
||||
}
|
||||
usermacros.clear();
|
||||
updateMacros();
|
||||
updateMacroInstances();
|
||||
|
@ -398,7 +398,7 @@ public:
|
||||
|
||||
/// Collect user macro names at loading time
|
||||
typedef std::set<docstring> UserMacroSet;
|
||||
UserMacroSet usermacros;
|
||||
mutable UserMacroSet usermacros;
|
||||
|
||||
/// Replace the inset contents for insets which InsetCode is equal
|
||||
/// to the passed \p inset_code.
|
||||
|
@ -272,7 +272,7 @@ Inset * createInsetHelper(Buffer & buf, FuncRequest const & cmd)
|
||||
case INCLUDE_CODE: {
|
||||
InsetCommandParams icp(code);
|
||||
InsetCommand::string2params(name, to_utf8(cmd.argument()), icp);
|
||||
return new InsetInclude(icp);
|
||||
return new InsetInclude(buf, icp);
|
||||
}
|
||||
|
||||
case INDEX_CODE:
|
||||
@ -465,7 +465,7 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
|
||||
inset.reset(new InsetHyperlink(inscmd));
|
||||
break;
|
||||
case INCLUDE_CODE:
|
||||
inset.reset(new InsetInclude(inscmd));
|
||||
inset.reset(new InsetInclude(buf, inscmd));
|
||||
break;
|
||||
case INDEX_PRINT_CODE:
|
||||
inset.reset(new InsetPrintIndex(inscmd));
|
||||
|
@ -46,6 +46,8 @@
|
||||
#include "insets/InsetListingsParams.h"
|
||||
#include "insets/RenderPreview.h"
|
||||
|
||||
#include "mathed/MacroTable.h"
|
||||
|
||||
#include "support/convert.h"
|
||||
#include "support/debug.h"
|
||||
#include "support/docstream.h"
|
||||
@ -158,17 +160,22 @@ InsetLabel * createLabel(docstring const & label_str)
|
||||
} // namespace anon
|
||||
|
||||
|
||||
InsetInclude::InsetInclude(InsetCommandParams const & p)
|
||||
InsetInclude::InsetInclude(Buffer const & buf, InsetCommandParams const & p)
|
||||
: InsetCommand(p, "include"), include_label(uniqueID()),
|
||||
preview_(new RenderMonitoredPreview(this)), failedtoload_(false),
|
||||
set_label_(false), label_(0)
|
||||
{
|
||||
// In order to be able to track macros at loading time, the
|
||||
// buffer has to be set here and not after construction.
|
||||
setBuffer(const_cast<Buffer &>(buf));
|
||||
|
||||
preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
|
||||
|
||||
if (isListings(params())) {
|
||||
InsetListingsParams listing_params(to_utf8(p["lstparams"]));
|
||||
label_ = createLabel(from_utf8(listing_params.getParamValue("label")));
|
||||
}
|
||||
} else if (isInputOrInclude(params()) && isBufferValid())
|
||||
loadIfNeeded(buffer());
|
||||
}
|
||||
|
||||
|
||||
@ -408,18 +415,32 @@ Buffer * InsetInclude::loadIfNeeded(Buffer const & parent) const
|
||||
// Buffer creation is not possible.
|
||||
return 0;
|
||||
|
||||
// Set parent before loading, such that macros can be tracked
|
||||
child->setParent(&parent);
|
||||
|
||||
if (!child->loadLyXFile(included_file)) {
|
||||
failedtoload_ = true;
|
||||
child->setParent(0);
|
||||
//close the buffer we just opened
|
||||
theBufferList().release(child);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (!child->errorList("Parse").empty()) {
|
||||
// FIXME: Do something.
|
||||
}
|
||||
} else {
|
||||
// The file was already loaded, so, simply
|
||||
// inform parent buffer about local macros.
|
||||
child->setParent(&parent);
|
||||
MacroNameSet macros;
|
||||
child->listMacroNames(macros);
|
||||
MacroNameSet::const_iterator cit = macros.begin();
|
||||
MacroNameSet::const_iterator end = macros.end();
|
||||
for (; cit != end; ++cit)
|
||||
parent.usermacros.insert(*cit);
|
||||
}
|
||||
child->setParent(&parent);
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ class RenderMonitoredPreview;
|
||||
class InsetInclude : public InsetCommand {
|
||||
public:
|
||||
///
|
||||
InsetInclude(InsetCommandParams const &);
|
||||
InsetInclude(Buffer const & buf, InsetCommandParams const &);
|
||||
~InsetInclude();
|
||||
|
||||
void setBuffer(Buffer & buffer);
|
||||
|
@ -84,6 +84,8 @@ What's new
|
||||
- Fix insertion of a user math macro through the math-insert lfun when a
|
||||
selection is present (bug 6939).
|
||||
|
||||
- Don't shadow user math macros defined in child documents (bug 7183).
|
||||
|
||||
- Make the modules description in the menu "Document -> Settings" fully
|
||||
translatable (bug 6987).
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user