2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetTOC.cpp
|
2002-09-25 14:26:13 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2002-09-25 14:26:13 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
*/
|
2003-10-28 11:18:40 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetTOC.h"
|
2003-09-04 01:18:42 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
2009-12-10 18:30:48 +00:00
|
|
|
#include "BufferParams.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "DispatchResult.h"
|
|
|
|
#include "FuncRequest.h"
|
2009-12-10 18:30:48 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "MetricsInfo.h"
|
|
|
|
#include "OutputParams.h"
|
2009-12-10 18:30:48 +00:00
|
|
|
#include "output_xhtml.h"
|
|
|
|
#include "Paragraph.h"
|
|
|
|
#include "TextClass.h"
|
2006-11-11 00:35:14 +00:00
|
|
|
#include "TocBackend.h"
|
2003-09-04 01:18:42 +00:00
|
|
|
|
2009-12-10 18:30:48 +00:00
|
|
|
#include "support/debug.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "support/gettext.h"
|
|
|
|
|
2008-05-06 10:42:26 +00:00
|
|
|
#include <ostream>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
2006-10-11 19:40:50 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
|
2009-11-08 16:10:34 +00:00
|
|
|
InsetTOC::InsetTOC(Buffer * buf, InsetCommandParams const & p)
|
|
|
|
: InsetCommand(buf, p, "toc")
|
2003-02-25 14:51:38 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2008-02-23 22:01:02 +00:00
|
|
|
ParamInfo const & InsetTOC::findInfo(string const & /* cmdName */)
|
2007-10-25 04:13:56 +00:00
|
|
|
{
|
2008-02-23 22:01:02 +00:00
|
|
|
static ParamInfo param_info_;
|
|
|
|
if (param_info_.empty()) {
|
Per Abdel's suggestion that we focus on bug-fixing at this point, this will be the last patch in this series for a bit. But I wanted to get this done before I forget what it is I was doing, so here it is.
The idea behind this patch is to make real key-value support for InsetCommand parameters possible. This should be particularly useful for the listings version of InsetInclude, though we would need some kind of UI for it before it would really be helpful. (See below for some thoughts.) This doesn't substantially change anything else, though some things do get re-arranged a bit.
Basically, the idea is this. First, we introduce a whole range of parameter types: Normal LaTeX optional and required parameters; ones for LyX's internal use (like embed); and finally, in connection with keyval, ones that represent keys and ones that represent optional and required arguments where the keyval stuff will appear. (I'm assuming here that there will always be exactly one of those, and that it will accept only keyval-type material.) The parameters themselves are stored in a map, so it's really only the output routines that need to care about the different types of parameters.
Regarding the frontend, it seems to me that something like the following would work:
(i) scan the parameter list for LATEX_KEY type parameters
(ii) the dialog will have a series of lines, each of which has a combo box listing the acceptable keys and a QLineEdit for entering its value, as well as a "delete" button of some sort for removing this key and its value
(iii) there should be an "add line" button to add a new line, activated only when all other lines are filled with values
Probably not even too hard.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23235 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-25 22:13:45 +00:00
|
|
|
param_info_.add("type", ParamInfo::LATEX_REQUIRED);
|
2008-02-23 22:01:02 +00:00
|
|
|
}
|
|
|
|
return param_info_;
|
2007-10-25 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring InsetTOC::screenLabel() const
|
2003-10-28 11:18:40 +00:00
|
|
|
{
|
|
|
|
if (getCmdName() == "tableofcontents")
|
2008-02-27 20:43:16 +00:00
|
|
|
return buffer().B_("Table of Contents");
|
2007-05-01 08:26:40 +00:00
|
|
|
return _("Unknown TOC type");
|
2000-08-01 17:33:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetTOC::plaintext(odocstream & os, OutputParams const &) const
|
2001-01-11 14:55:36 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
os << screenLabel() << "\n\n";
|
|
|
|
buffer().tocBackend().writePlaintextTocList(getCmdName(), os);
|
2007-02-20 17:52:41 +00:00
|
|
|
return PLAINTEXT_NEWLINE;
|
2001-01-11 14:55:36 +00:00
|
|
|
}
|
|
|
|
|
2000-08-01 17:33:32 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetTOC::docbook(odocstream & os, OutputParams const &) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
2001-04-27 07:58:56 +00:00
|
|
|
if (getCmdName() == "tableofcontents")
|
2000-08-01 17:33:32 +00:00
|
|
|
os << "<toc></toc>";
|
2000-03-06 02:42:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2009-12-10 18:30:48 +00:00
|
|
|
docstring InsetTOC::xhtml(XHTMLStream &, OutputParams const & op) const
|
|
|
|
{
|
|
|
|
// we'll use our own stream, because we are going to defer everything.
|
|
|
|
// that's how we deal with the fact that we're probably inside a standard
|
|
|
|
// paragraph, and we don't want to be.
|
|
|
|
odocstringstream ods;
|
|
|
|
XHTMLStream xs(ods);
|
|
|
|
// FIXME XHTML
|
|
|
|
// This is temporary. We'll get the main TOC working first. The rest will
|
|
|
|
// then be a fairly simple adapation of this code, I hope.
|
|
|
|
if (getCmdName() != "tableofcontents")
|
|
|
|
return docstring();
|
|
|
|
Toc const & toc = buffer().tocBackend().toc("tableofcontents");
|
|
|
|
if (toc.empty())
|
|
|
|
return docstring();
|
|
|
|
|
|
|
|
xs << StartTag("div", "class='toc'");
|
|
|
|
|
2009-12-10 19:28:00 +00:00
|
|
|
// we want to look like a chapter, section, or whatever.
|
2009-12-10 18:30:48 +00:00
|
|
|
// so we're going to look for the layout with the minimum toclevel
|
2009-12-10 19:28:00 +00:00
|
|
|
// number > 0, because we don't want Part.
|
|
|
|
// we'll take the first one, just because.
|
2009-12-10 18:30:48 +00:00
|
|
|
DocumentClass const & dc = buffer().params().documentClass();
|
|
|
|
TextClass::LayoutList::const_iterator lit = dc.begin();
|
|
|
|
TextClass::LayoutList::const_iterator len = dc.end();
|
|
|
|
int minlevel = 1000;
|
|
|
|
Layout const * lay = NULL;
|
|
|
|
for (; lit != len; ++lit) {
|
|
|
|
int const level = lit->toclevel;
|
2009-12-10 19:28:00 +00:00
|
|
|
if (level > 0 && (level == Layout::NOT_IN_TOC || level >= minlevel))
|
2009-12-10 18:30:48 +00:00
|
|
|
continue;
|
|
|
|
lay = &*lit;
|
|
|
|
minlevel = level;
|
|
|
|
}
|
|
|
|
|
2009-12-10 19:28:00 +00:00
|
|
|
string const tocclass = lay ? " " + lay->defaultCSSClass(): "";
|
|
|
|
string const tocattr = "class='tochead" + tocclass + "'";
|
2009-12-10 18:30:48 +00:00
|
|
|
|
|
|
|
xs << StartTag("div", tocattr)
|
|
|
|
<< _("Table of Contents")
|
|
|
|
<< EndTag("div");
|
|
|
|
Toc::const_iterator it = toc.begin();
|
|
|
|
Toc::const_iterator const en = toc.end();
|
|
|
|
int lastdepth = 0;
|
|
|
|
for (; it != en; ++it) {
|
|
|
|
Paragraph const & par = it->dit().innerParagraph();
|
|
|
|
Font const dummy;
|
|
|
|
int const depth = it->depth();
|
|
|
|
if (depth > lastdepth) {
|
|
|
|
xs.cr();
|
|
|
|
// open as many tags as we need to open to get to this level
|
|
|
|
// this includes the tag for the current level
|
|
|
|
for (int i = lastdepth + 1; i <= depth; ++i) {
|
|
|
|
stringstream attr;
|
|
|
|
attr << "class='lyxtoc-" << i << "'";
|
|
|
|
xs << StartTag("div", attr.str());
|
|
|
|
}
|
|
|
|
lastdepth = depth;
|
|
|
|
}
|
|
|
|
else if (depth < lastdepth) {
|
|
|
|
// close as many as we have to close to get back to this level
|
|
|
|
// this includes closing the last tag at this level
|
|
|
|
for (int i = lastdepth; i >= depth; --i)
|
|
|
|
xs << EndTag("div");
|
|
|
|
// now open our tag
|
|
|
|
stringstream attr;
|
|
|
|
attr << "class='lyxtoc-" << depth << "'";
|
|
|
|
xs << StartTag("div", attr.str());
|
|
|
|
lastdepth = depth;
|
|
|
|
} else {
|
|
|
|
// no change of level, so close and open
|
|
|
|
xs << EndTag("div");
|
|
|
|
stringstream attr;
|
|
|
|
attr << "class='lyxtoc-" << depth << "'";
|
|
|
|
xs << StartTag("div", attr.str());
|
|
|
|
}
|
|
|
|
par.simpleLyXHTMLOnePar(buffer(), xs, op, dummy, true);
|
|
|
|
}
|
|
|
|
for (int i = lastdepth; i > 0; --i)
|
|
|
|
xs << EndTag("div");
|
|
|
|
xs << EndTag("div");
|
|
|
|
return ods.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|