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"
|
2003-09-04 03:54:04 +00:00
|
|
|
#include "funcrequest.h"
|
2002-11-07 00:37:09 +00:00
|
|
|
#include "iterators.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
#include "LyXAction.h"
|
2003-09-06 17:23:08 +00:00
|
|
|
#include "paragraph.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"
|
|
|
|
#include "insets/insetwrap.h"
|
|
|
|
|
|
|
|
#include "support/tostr.h"
|
|
|
|
|
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
|
|
|
|
{
|
2003-02-22 20:05:13 +00:00
|
|
|
string const tmp = tostr(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
|
|
|
{
|
2003-09-21 18:57:15 +00:00
|
|
|
return FuncRequest(LFUN_GOTO_PARAGRAPH, tostr(id_));
|
2002-07-21 15:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const getType(string const & cmdName)
|
|
|
|
{
|
|
|
|
// special case
|
|
|
|
if (cmdName == "tableofcontents")
|
|
|
|
return "TOC";
|
|
|
|
else
|
|
|
|
return cmdName;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
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
|
|
|
|
2003-09-15 15:51:48 +00:00
|
|
|
int const toclevel = pit->layout()->toclevel;
|
2004-03-25 09:16:36 +00:00
|
|
|
if (toclevel > 0 && toclevel <= bufparams.tocdepth) {
|
2003-09-15 15:51:48 +00:00
|
|
|
// insert this into the table of contents
|
|
|
|
TocItem const item(pit->id(), toclevel - 1, pit->asString(buf, true));
|
2002-07-21 15:51:07 +00:00
|
|
|
toclist["TOC"].push_back(item);
|
|
|
|
}
|
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) {
|
2003-07-25 21:20:24 +00:00
|
|
|
if (it->inset->lyxCode() == InsetOld::FLOAT_CODE) {
|
2004-03-25 09:16:36 +00:00
|
|
|
static_cast<InsetFloat*>(it->inset)
|
|
|
|
->addToToc(toclist, buf);
|
2003-07-25 21:20:24 +00:00
|
|
|
} else if (it->inset->lyxCode() == InsetOld::WRAP_CODE) {
|
2004-03-25 09:16:36 +00:00
|
|
|
static_cast<InsetWrap*>(it->inset)
|
|
|
|
->addToToc(toclist, buf);
|
2002-07-21 15:51:07 +00:00
|
|
|
}
|
2002-07-28 22:50:13 +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
|