mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-22 07:42:02 +00:00
Fix for bug 3637, joint work of Bo Peng and myself:
* src/insets/InsetListingsParams.{cpp,h} - implement getParamValue that returns the value of a listings param * src/insets/InsetInclude.cpp: - (getLabelList): pass listings label to the list, if available - doDispatch: implement changeRefsIfUnique for listing labels git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18405 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
73849af5df
commit
a42d3e670b
@ -62,6 +62,7 @@ using support::copy;
|
||||
using support::DocFileName;
|
||||
using support::FileName;
|
||||
using support::getFileContents;
|
||||
using support::getVectorFromString;
|
||||
using support::isFileReadable;
|
||||
using support::isLyXFilename;
|
||||
using support::latex_path;
|
||||
@ -70,6 +71,7 @@ using support::makeDisplayPath;
|
||||
using support::makeRelPath;
|
||||
using support::onlyFilename;
|
||||
using support::onlyPath;
|
||||
using support::prefixIs;
|
||||
using support::subst;
|
||||
using support::sum;
|
||||
|
||||
@ -79,6 +81,7 @@ using std::auto_ptr;
|
||||
using std::istringstream;
|
||||
using std::ostream;
|
||||
using std::ostringstream;
|
||||
using std::vector;
|
||||
|
||||
namespace Alert = frontend::Alert;
|
||||
namespace fs = boost::filesystem;
|
||||
@ -92,6 +95,12 @@ docstring const uniqueID()
|
||||
return "file" + convert<docstring>(++seed);
|
||||
}
|
||||
|
||||
|
||||
bool isListings(InsetCommandParams const & params)
|
||||
{
|
||||
return params.getCmdName() == "lstinputlisting";
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
@ -129,6 +138,17 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
InsetCommandParams p("include");
|
||||
InsetIncludeMailer::string2params(to_utf8(cmd.argument()), p);
|
||||
if (!p.getCmdName().empty()) {
|
||||
if (isListings(p)){
|
||||
InsetListingsParams par_old(params().getOptions());
|
||||
InsetListingsParams par_new(p.getOptions());
|
||||
if (par_old.getParamValue("label") !=
|
||||
par_new.getParamValue("label")
|
||||
&& !par_new.getParamValue("label").empty())
|
||||
cur.bv().buffer()->changeRefsIfUnique(
|
||||
from_utf8(par_old.getParamValue("label")),
|
||||
from_utf8(par_new.getParamValue("label")),
|
||||
Inset::REF_CODE);
|
||||
}
|
||||
set(p, cur.buffer());
|
||||
cur.buffer().updateBibfilesCache();
|
||||
} else
|
||||
@ -209,12 +229,6 @@ bool isVerbatim(InsetCommandParams const & params)
|
||||
}
|
||||
|
||||
|
||||
bool isListings(InsetCommandParams const & params)
|
||||
{
|
||||
return params.getCmdName() == "lstinputlisting";
|
||||
}
|
||||
|
||||
|
||||
string const masterFilename(Buffer const & buffer)
|
||||
{
|
||||
return buffer.getMasterBuffer()->fileName();
|
||||
@ -630,7 +644,13 @@ void InsetInclude::validate(LaTeXFeatures & features) const
|
||||
void InsetInclude::getLabelList(Buffer const & buffer,
|
||||
std::vector<docstring> & list) const
|
||||
{
|
||||
if (loadIfNeeded(buffer, params_)) {
|
||||
if (isListings(params_)) {
|
||||
InsetListingsParams params(params_.getOptions());
|
||||
string label = params.getParamValue("label");
|
||||
if (!label.empty())
|
||||
list.push_back(from_utf8(label));
|
||||
}
|
||||
else if (loadIfNeeded(buffer, params_)) {
|
||||
string const included_file = includedFilename(buffer, params_).absFilename();
|
||||
Buffer * tmp = theBufferList().getBuffer(included_file);
|
||||
tmp->setParentName("");
|
||||
|
@ -28,6 +28,9 @@ using std::string;
|
||||
using std::exception;
|
||||
using lyx::support::trim;
|
||||
using lyx::support::isStrInt;
|
||||
using lyx::support::prefixIs;
|
||||
using lyx::support::suffixIs;
|
||||
using lyx::support::getVectorFromString;
|
||||
|
||||
namespace lyx
|
||||
{
|
||||
@ -557,5 +560,24 @@ void InsetListingsParams::fromEncodedString(string const & in)
|
||||
}
|
||||
|
||||
|
||||
string InsetListingsParams::getParamValue(string const & param) const
|
||||
{
|
||||
// is this parameter defined?
|
||||
if (find(keys_.begin(), keys_.end(), param) == keys_.end())
|
||||
return string();
|
||||
// if so, search for it
|
||||
vector<string> pars = getVectorFromString(separatedParams(), "\n");
|
||||
for (vector<string>::iterator it = pars.begin(); it != pars.end(); ++it)
|
||||
if (prefixIs(*it, param + "=")) {
|
||||
string par = it->substr(param.size() + 1);
|
||||
if (prefixIs(par, "{") && suffixIs(par, "}"))
|
||||
return par.substr(1, par.size() - 2);
|
||||
else
|
||||
return par;
|
||||
}
|
||||
// if param= is not found, should be something like float, return ""
|
||||
return string();
|
||||
}
|
||||
|
||||
|
||||
} // namespace lyx
|
||||
|
@ -66,6 +66,9 @@ public:
|
||||
///
|
||||
void setInline(bool i) { inline_ = i; }
|
||||
|
||||
/// get value of option \c param
|
||||
std::string getParamValue(std::string const & param) const;
|
||||
|
||||
///
|
||||
void clear() { params_.clear(); }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user