2003-08-23 00:17:00 +00:00
|
|
|
/**
|
|
|
|
* \file toc.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-07-21 15:51:07 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
* \author Angus Leeming
|
2002-07-21 15:51:07 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-07-21 15:51:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "toc.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
2002-07-21 15:51:07 +00:00
|
|
|
#include "buffer.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
#include "bufferparams.h"
|
2005-07-04 13:05:03 +00:00
|
|
|
#include "FloatList.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
#include "funcrequest.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
#include "LyXAction.h"
|
2003-09-06 17:23:08 +00:00
|
|
|
#include "paragraph.h"
|
2004-03-28 22:00:22 +00:00
|
|
|
#include "pariterator.h"
|
2002-07-21 15:51:07 +00:00
|
|
|
|
2003-09-06 18:38:02 +00:00
|
|
|
#include "frontends/LyXView.h"
|
|
|
|
|
2003-05-13 14:36:24 +00:00
|
|
|
#include "insets/insetfloat.h"
|
2005-05-12 10:16:04 +00:00
|
|
|
#include "insets/insetoptarg.h"
|
2003-05-13 14:36:24 +00:00
|
|
|
#include "insets/insetwrap.h"
|
|
|
|
|
2005-01-06 16:39:35 +00:00
|
|
|
#include "support/convert.h"
|
2003-05-13 14:36:24 +00:00
|
|
|
|
2002-07-21 15:51:07 +00:00
|
|
|
using std::vector;
|
2002-07-21 16:59:01 +00:00
|
|
|
using std::max;
|
|
|
|
using std::ostream;
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
2002-07-21 15:51:07 +00:00
|
|
|
|
2003-07-27 13:18:55 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace toc {
|
2002-07-21 15:51:07 +00:00
|
|
|
|
|
|
|
string const TocItem::asString() const
|
|
|
|
{
|
|
|
|
return string(4 * depth, ' ') + str;
|
|
|
|
}
|
|
|
|
|
2002-07-28 22:50:13 +00:00
|
|
|
|
2002-07-21 15:51:07 +00:00
|
|
|
void TocItem::goTo(LyXView & lv_) const
|
|
|
|
{
|
2005-01-06 15:40:49 +00:00
|
|
|
string const tmp = convert<string>(id_);
|
2002-08-13 17:43:40 +00:00
|
|
|
lv_.dispatch(FuncRequest(LFUN_GOTO_PARAGRAPH, tmp));
|
2002-07-21 15:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-21 18:57:15 +00:00
|
|
|
FuncRequest TocItem::action() const
|
2002-07-21 15:51:07 +00:00
|
|
|
{
|
2005-01-06 15:40:49 +00:00
|
|
|
return FuncRequest(LFUN_GOTO_PARAGRAPH, convert<string>(id_));
|
2002-07-21 15:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const getType(string const & cmdName)
|
|
|
|
{
|
|
|
|
// special case
|
|
|
|
if (cmdName == "tableofcontents")
|
2005-07-27 15:22:08 +00:00
|
|
|
return "TOC";
|
2002-07-21 15:51:07 +00:00
|
|
|
else
|
|
|
|
return cmdName;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-27 15:22:08 +00:00
|
|
|
string const getGuiName(string const & type, Buffer const & buffer)
|
2005-07-04 13:05:03 +00:00
|
|
|
{
|
|
|
|
FloatList const & floats =
|
|
|
|
buffer.params().getLyXTextClass().floats();
|
2005-07-27 15:22:08 +00:00
|
|
|
if (floats.typeExist(type))
|
|
|
|
return floats.getType(type).name();
|
2005-07-04 13:05:03 +00:00
|
|
|
else
|
2005-07-27 15:22:08 +00:00
|
|
|
return type;
|
2005-07-04 13:05:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
TocList const getTocList(Buffer const & buf)
|
2002-07-21 15:51:07 +00:00
|
|
|
{
|
|
|
|
TocList toclist;
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
BufferParams const & bufparams = buf.params();
|
2005-05-12 10:16:04 +00:00
|
|
|
const int min_toclevel = bufparams.getLyXTextClass().min_toclevel();
|
2002-07-21 15:51:07 +00:00
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
ParConstIterator pit = buf.par_iterator_begin();
|
|
|
|
ParConstIterator end = buf.par_iterator_end();
|
2002-11-07 00:37:09 +00:00
|
|
|
for (; pit != end; ++pit) {
|
2003-09-12 17:13:22 +00:00
|
|
|
|
2005-05-12 10:16:04 +00:00
|
|
|
// the string that goes to the toc (could be the optarg)
|
|
|
|
string tocstring;
|
2002-07-28 22:50:13 +00:00
|
|
|
|
2002-07-21 15:51:07 +00:00
|
|
|
// For each paragraph, traverse its insets and look for
|
2002-09-24 18:36:20 +00:00
|
|
|
// FLOAT_CODE or WRAP_CODE
|
2003-06-12 11:09:55 +00:00
|
|
|
InsetList::const_iterator it = pit->insetlist.begin();
|
|
|
|
InsetList::const_iterator end = pit->insetlist.end();
|
2002-07-21 21:21:06 +00:00
|
|
|
for (; it != end; ++it) {
|
2005-05-12 10:16:04 +00:00
|
|
|
switch (it->inset->lyxCode()) {
|
|
|
|
case InsetBase::FLOAT_CODE:
|
2004-03-25 09:16:36 +00:00
|
|
|
static_cast<InsetFloat*>(it->inset)
|
|
|
|
->addToToc(toclist, buf);
|
2005-05-12 10:16:04 +00:00
|
|
|
break;
|
|
|
|
case InsetBase::WRAP_CODE:
|
2004-03-25 09:16:36 +00:00
|
|
|
static_cast<InsetWrap*>(it->inset)
|
|
|
|
->addToToc(toclist, buf);
|
2005-05-12 10:16:04 +00:00
|
|
|
break;
|
|
|
|
case InsetBase::OPTARG_CODE: {
|
|
|
|
if (!tocstring.empty())
|
|
|
|
break;
|
|
|
|
Paragraph const & par = *static_cast<InsetOptArg*>(it->inset)->paragraphs().begin();
|
|
|
|
if (!pit->getLabelstring().empty())
|
2005-06-09 09:58:08 +00:00
|
|
|
tocstring = pit->getLabelstring()
|
2005-05-12 10:16:04 +00:00
|
|
|
+ ' ';
|
|
|
|
tocstring += par.asString(buf, false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2002-07-21 15:51:07 +00:00
|
|
|
}
|
2002-07-28 22:50:13 +00:00
|
|
|
}
|
2005-05-12 10:16:04 +00:00
|
|
|
|
|
|
|
/// now the toc entry for the paragraph
|
|
|
|
int const toclevel = pit->layout()->toclevel;
|
2005-10-25 13:43:50 +00:00
|
|
|
if (toclevel != LyXLayout::NOT_IN_TOC
|
|
|
|
&& toclevel >= min_toclevel
|
2005-05-12 10:16:04 +00:00
|
|
|
&& toclevel <= bufparams.tocdepth) {
|
|
|
|
// insert this into the table of contents
|
|
|
|
if (tocstring.empty())
|
|
|
|
tocstring = pit->asString(buf, true);
|
2005-06-09 09:58:08 +00:00
|
|
|
TocItem const item(pit->id(), toclevel - min_toclevel,
|
2005-05-12 10:16:04 +00:00
|
|
|
tocstring);
|
2005-07-27 15:22:08 +00:00
|
|
|
toclist["TOC"].push_back(item);
|
2005-05-12 10:16:04 +00:00
|
|
|
}
|
2002-07-21 15:51:07 +00:00
|
|
|
}
|
|
|
|
return toclist;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
vector<string> const getTypes(Buffer const & buffer)
|
2002-07-21 15:51:07 +00:00
|
|
|
{
|
|
|
|
vector<string> types;
|
|
|
|
|
|
|
|
TocList const tmp = getTocList(buffer);
|
|
|
|
|
|
|
|
TocList::const_iterator cit = tmp.begin();
|
|
|
|
TocList::const_iterator end = tmp.end();
|
|
|
|
|
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
types.push_back(cit->first);
|
|
|
|
}
|
|
|
|
|
|
|
|
return types;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
void asciiTocList(string const & type, Buffer const & buffer, ostream & os)
|
2002-07-21 15:51:07 +00:00
|
|
|
{
|
|
|
|
TocList const toc_list = getTocList(buffer);
|
|
|
|
TocList::const_iterator cit = toc_list.find(type);
|
|
|
|
if (cit != toc_list.end()) {
|
|
|
|
Toc::const_iterator ccit = cit->second.begin();
|
|
|
|
Toc::const_iterator end = cit->second.end();
|
|
|
|
for (; ccit != end; ++ccit)
|
|
|
|
os << ccit->asString() << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace toc
|
2003-07-27 13:18:55 +00:00
|
|
|
} // namespace lyx
|