When working on the listings translation I noticed that \lstlistoflistings 
is not supported by LyX, although almost everything is already there. The 
attached patch implements this. Is it OK to go in (+ file format change of 
course)?


Georg
diff --git a/lib/layouts/stdinsets.inc b/lib/layouts/stdinsets.inc
index faa6d1c..2000172 100644
--- a/lib/layouts/stdinsets.inc
+++ b/lib/layouts/stdinsets.inc
@@ -170,25 +170,35 @@ InsetLayout Phantom
 	ForcePlain            true
 End
 
-InsetLayout IncludeListings
+InsetLayout ListOfListings
 	# We need the [[List of Listings]] context, since "Listings" is also
 	# the name of the inset and translated differently.
 	# "Listings[[List of Listings]]" is the name of the "List of listings"
 	# ("Listings" is the predefined english name) in listings.sty, so it
 	# must be used here as well.
 	BabelPreamble
-		\addto\captions$$lang{\renewcommand{\lstlistingname}{_(Listing)}}
 		\addto\captions$$lang{\renewcommand{\lstlistlistingname}{_(Listings[[List of Listings]])}}
 	EndBabelPreamble
-	# The commands do not need to be defined in LangPreamble, since
-	# listings.sty does that already. However they need to be redefined
+	# The command does not need to be defined in LangPreamble, since
+	# listings.sty does that already. However it needs to be redefined
 	# in order to be used for non-english single-language documents.
 	LangPreamble
-		\renewcommand{\lstlistingname}{_(Listing)}
 		\renewcommand{\lstlistlistingname}{_(Listings[[List of Listings]])}
 	EndLangPreamble
 End
 
+InsetLayout IncludeListings
+	BabelPreamble
+		\addto\captions$$lang{\renewcommand{\lstlistingname}{_(Listing)}}
+	EndBabelPreamble
+	# The command does not need to be defined in LangPreamble, since
+	# listings.sty does that already. However it needs to be redefined
+	# in order to be used for non-english single-language documents.
+	LangPreamble
+		\renewcommand{\lstlistingname}{_(Listing)}
+	EndLangPreamble
+End
+
 InsetLayout Listings
 	CopyStyle IncludeListings
 	LabelString           Listings[[inset]]
diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc
index 6ab91f3..9a88185 100644
--- a/lib/ui/stdmenus.inc
+++ b/lib/ui/stdmenus.inc
@@ -451,6 +451,7 @@ Menuset
 		Item "Table of Contents|C" "inset-insert toc"
 		FloatListInsert
 		IndicesLists
+		Item "List of Listings|L" "inset-insert toc CommandInset toc LatexCommand lstlistoflistings \end_inset"
 		Item "Nomenclature|N" "nomencl-print"
 		Item "BibTeX Bibliography...|B" "dialog-show-new-inset bibtex"
 	End
diff --git a/src/frontends/qt4/TocWidget.cpp b/src/frontends/qt4/TocWidget.cpp
index 80c9db9..345b40e 100644
--- a/src/frontends/qt4/TocWidget.cpp
+++ b/src/frontends/qt4/TocWidget.cpp
@@ -496,9 +496,11 @@ void TocWidget::filterContents()
 static QString decodeType(QString const & str)
 {
 	QString type = str;
-	if (type.contains("tableofcontents")) {
+	if (type.contains("tableofcontents"))
 		type = "tableofcontents";
-	} else if (type.contains("floatlist")) {
+	else if (type.contains("lstlistoflistings"))
+		type = "listing";
+	else if (type.contains("floatlist")) {
 		if (type.contains("\"figure"))
 			type = "figure";
 		else if (type.contains("\"table"))
diff --git a/src/insets/InsetTOC.cpp b/src/insets/InsetTOC.cpp
index 0ab4b65..af62d41 100644
--- a/src/insets/InsetTOC.cpp
+++ b/src/insets/InsetTOC.cpp
@@ -37,6 +37,15 @@ using namespace std;
 
 namespace lyx {
 
+namespace {
+string cmd2type(string const & cmd)
+{
+	if (cmd == "lstlistoflistings")
+		return "listing";
+	return cmd;
+}
+}
+
 
 InsetTOC::InsetTOC(Buffer * buf, InsetCommandParams const & p)
 	: InsetCommand(buf, p)
@@ -53,10 +62,18 @@ ParamInfo const & InsetTOC::findInfo(string const & /* cmdName */)
 }
 
 
+bool InsetTOC::isCompatibleCommand(string const & cmd)
+{
+	return cmd == defaultCommand() || cmd == "lstlistoflistings";
+}
+
+
 docstring InsetTOC::screenLabel() const
 {
 	if (getCmdName() == "tableofcontents")
 		return buffer().B_("Table of Contents");
+	if (getCmdName() == "lstlistoflistings")
+		return buffer().B_("List of Listings");
 	return _("Unknown TOC type");
 }
 
@@ -76,10 +93,18 @@ void InsetTOC::doDispatch(Cursor & cur, FuncRequest & cmd) {
 }
 
 
+docstring InsetTOC::layoutName() const
+{
+	if (getCmdName() == "lstlistoflistings")
+		return from_ascii("ListOfListings");
+	return docstring();
+}
+
+
 int InsetTOC::plaintext(odocstream & os, OutputParams const &) const
 {
 	os << screenLabel() << "\n\n";
-	buffer().tocBackend().writePlaintextTocList(getCmdName(), os);
+	buffer().tocBackend().writePlaintextTocList(cmd2type(getCmdName()), os);
 	return PLAINTEXT_NEWLINE;
 }
 
@@ -94,6 +119,9 @@ int InsetTOC::docbook(odocstream & os, OutputParams const &) const
 
 docstring InsetTOC::xhtml(XHTMLStream &, OutputParams const & op) const
 {
+	if (getCmdName() != "tableofcontents")
+		return docstring();
+
 	Layout const & lay = buffer().params().documentClass().htmlTOCLayout();
 	string const & tocclass = lay.defaultCSSClass();
 	string const tocattr = "class='tochead " + tocclass + "'";
@@ -104,15 +132,14 @@ docstring InsetTOC::xhtml(XHTMLStream &, OutputParams const & op) const
 	odocstringstream ods;
 	XHTMLStream xs(ods);
 
-	Toc const & toc = buffer().tocBackend().toc("tableofcontents");
+	Toc const & toc = buffer().tocBackend().toc(cmd2type(getCmdName()));
 	if (toc.empty())
 		return docstring();
 
 	xs << html::StartTag("div", "class='toc'");
 
 	// Title of TOC
-	static string toctitle = N_("Table of Contents");
-	docstring title = buffer().B_(toctitle);
+	docstring title = screenLabel();
 	xs << html::StartTag("div", tocattr)
 		 << title
 		 << html::EndTag("div");
diff --git a/src/insets/InsetTOC.h b/src/insets/InsetTOC.h
index 9ba7cf0..e13be42 100644
--- a/src/insets/InsetTOC.h
+++ b/src/insets/InsetTOC.h
@@ -19,8 +19,8 @@ namespace lyx {
 
 
 /// Used to insert table of contents and similar lists
-/// at present, supports only \tableofcontents. Other
-/// such commands, such as \listoffigures, are supported
+/// at present, supports only \tableofcontents and \listoflistings.
+/// Other such commands, such as \listoffigures, are supported
 /// by InsetFloatList.
 class InsetTOC : public InsetCommand {
 public:
@@ -32,6 +32,8 @@ public:
 	///
 	InsetCode lyxCode() const { return TOC_CODE; }
 	///
+	docstring layoutName() const;
+	///
 	DisplayType display() const { return AlignCenter; }
 	///
 	int plaintext(odocstream &, OutputParams const &) const;
@@ -52,8 +54,7 @@ public:
 	///
 	static std::string defaultCommand() { return "tableofcontents"; }
 	///
-	static bool isCompatibleCommand(std::string const & cmd)
-		{ return cmd == defaultCommand(); }
+	static bool isCompatibleCommand(std::string const & cmd);
 	//@}
 
 private:

Reply via email to