Fix display of counters for included listings.

This commit is contained in:
Richard Kimberly Heck 2024-02-09 19:53:55 -05:00
parent fe99f7b01e
commit 91bd457a67
2 changed files with 15 additions and 8 deletions

View File

@ -79,6 +79,7 @@ End
Counter listing Counter listing
GuiName Listing GuiName Listing
PrettyFormat "Listing ##"
End End
Counter equation Counter equation

View File

@ -1444,22 +1444,28 @@ void InsetInclude::updateBuffer(ParIterator const & it, UpdateType utype, bool c
if (!isListings(params())) if (!isListings(params()))
return; return;
Buffer const & master = *buffer().masterBuffer();
listings_label_ = master.B_("Program Listing");
Counters & counters = master.params().documentClass().counters();
docstring const cnt = from_ascii("listing");
bool const hasCounter = counters.hasCounter(cnt);
if (hasCounter) {
counters.saveLastCounter();
counters.step(cnt, utype);
listings_label_ += " " + convert<docstring>(counters.value(cnt));
}
if (label_) if (label_)
label_->updateBuffer(it, utype, deleted); label_->updateBuffer(it, utype, deleted);
if (hasCounter)
counters.restoreLastCounter();
InsetListingsParams const par(to_utf8(params()["lstparams"])); InsetListingsParams const par(to_utf8(params()["lstparams"]));
if (par.getParamValue("caption").empty()) { if (par.getParamValue("caption").empty()) {
listings_label_ = buffer().B_("Program Listing"); listings_label_ = buffer().B_("Program Listing");
return; return;
} }
Buffer const & master = *buffer().masterBuffer();
Counters & counters = master.params().documentClass().counters();
docstring const cnt = from_ascii("listing");
listings_label_ = master.B_("Program Listing");
if (counters.hasCounter(cnt)) {
counters.step(cnt, utype);
listings_label_ += " " + convert<docstring>(counters.value(cnt));
}
} }