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
|
2006-04-19 14:48:22 +00:00
|
|
|
* \author Abdelrazak Younes
|
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"
|
2006-04-19 14:48:22 +00:00
|
|
|
#include "cursor.h"
|
|
|
|
#include "debug.h"
|
2006-04-26 17:43:03 +00:00
|
|
|
#include "undo.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
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
using std::map;
|
|
|
|
using std::pair;
|
|
|
|
using std::make_pair;
|
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;
|
2006-04-22 18:48:28 +00:00
|
|
|
using std::cout;
|
|
|
|
using std::endl;
|
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
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
typedef map<Buffer const *, lyx::TocBackend> TocMap;
|
|
|
|
static TocMap toc_backend_;
|
2002-07-21 15:51:07 +00:00
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Interface to toc_backend_
|
2002-07-28 22:50:13 +00:00
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
void updateToc(Buffer const & buf)
|
2002-07-21 15:51:07 +00:00
|
|
|
{
|
2006-04-22 18:48:28 +00:00
|
|
|
TocMap::iterator it = toc_backend_.find(&buf);
|
|
|
|
if (it == toc_backend_.end()) {
|
|
|
|
pair<TocMap::iterator, bool> result
|
|
|
|
= toc_backend_.insert(make_pair(&buf, TocBackend(&buf)));
|
|
|
|
if (!result.second)
|
|
|
|
return;
|
|
|
|
|
|
|
|
it = result.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
it->second.update();
|
2002-07-21 15:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
TocList const & getTocList(Buffer const & buf)
|
2002-07-21 15:51:07 +00:00
|
|
|
{
|
2006-04-22 18:48:28 +00:00
|
|
|
return toc_backend_[&buf].tocs();
|
2002-07-21 15:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
Toc const & getToc(Buffer const & buf, std::string const & type)
|
2002-07-21 15:51:07 +00:00
|
|
|
{
|
2006-04-22 18:48:28 +00:00
|
|
|
return toc_backend_[&buf].toc(type);
|
2002-07-21 15:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
TocIterator const getCurrentTocItem(Buffer const & buf, LCursor const & cur,
|
|
|
|
std::string const & type)
|
2005-07-04 13:05:03 +00:00
|
|
|
{
|
2006-04-22 18:48:28 +00:00
|
|
|
return toc_backend_[&buf].item(type, ParConstIterator(cur));
|
2005-07-04 13:05:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
vector<string> const & getTypes(Buffer const & buf)
|
2002-07-21 15:51:07 +00:00
|
|
|
{
|
2006-04-22 18:48:28 +00:00
|
|
|
return toc_backend_[&buf].types();
|
2002-07-21 15:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
void asciiTocList(string const & type, Buffer const & buf, ostream & os)
|
2006-04-19 14:48:22 +00:00
|
|
|
{
|
2006-04-22 18:48:28 +00:00
|
|
|
toc_backend_[&buf].asciiTocList(type, os);
|
2006-04-19 14:48:22 +00:00
|
|
|
}
|
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Other functions
|
2006-04-19 14:48:22 +00:00
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
string const getType(string const & cmdName)
|
2002-07-21 15:51:07 +00:00
|
|
|
{
|
2006-04-22 18:48:28 +00:00
|
|
|
// special case
|
|
|
|
if (cmdName == "tableofcontents")
|
|
|
|
return "TOC";
|
|
|
|
else
|
|
|
|
return cmdName;
|
2002-07-21 15:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
string const getGuiName(string const & type, Buffer const & buffer)
|
2002-07-21 15:51:07 +00:00
|
|
|
{
|
2006-04-22 18:48:28 +00:00
|
|
|
FloatList const & floats =
|
|
|
|
buffer.params().getLyXTextClass().floats();
|
|
|
|
if (floats.typeExist(type))
|
|
|
|
return floats.getType(type).name();
|
|
|
|
else
|
|
|
|
return type;
|
2002-07-21 15:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-26 17:43:03 +00:00
|
|
|
void outline(OutlineOp mode, LCursor & cur)
|
2006-03-29 05:08:42 +00:00
|
|
|
{
|
2006-04-26 17:43:03 +00:00
|
|
|
recordUndo(cur);
|
|
|
|
Buffer * buf = & cur.buffer();
|
|
|
|
pit_type & pit = cur.pit();
|
2006-03-29 05:08:42 +00:00
|
|
|
ParagraphList & pars = buf->text().paragraphs();
|
|
|
|
ParagraphList::iterator bgn = pars.begin();
|
|
|
|
ParagraphList::iterator s = boost::next(bgn, pit);
|
|
|
|
ParagraphList::iterator p = s;
|
|
|
|
ParagraphList::iterator end = pars.end();
|
|
|
|
|
|
|
|
LyXTextClass::const_iterator lit =
|
|
|
|
buf->params().getLyXTextClass().begin();
|
|
|
|
LyXTextClass::const_iterator const lend =
|
|
|
|
buf->params().getLyXTextClass().end();
|
|
|
|
|
|
|
|
int const thistoclevel = s->layout()->toclevel;
|
|
|
|
int toclevel;
|
|
|
|
switch (mode) {
|
2006-04-28 07:28:10 +00:00
|
|
|
case Up: {
|
2006-03-29 05:08:42 +00:00
|
|
|
if (p != end)
|
|
|
|
++p;
|
|
|
|
for (; p != end; ++p) {
|
|
|
|
toclevel = p->layout()->toclevel;
|
2006-04-05 23:56:29 +00:00
|
|
|
if (toclevel != LyXLayout::NOT_IN_TOC
|
2006-03-29 05:08:42 +00:00
|
|
|
&& toclevel <= thistoclevel) {
|
2006-04-05 23:56:29 +00:00
|
|
|
break;
|
2006-03-29 05:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ParagraphList::iterator q = s;
|
|
|
|
if (q != bgn)
|
|
|
|
--q;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
for (; q != bgn; --q) {
|
|
|
|
toclevel = q->layout()->toclevel;
|
2006-04-05 23:56:29 +00:00
|
|
|
if (toclevel != LyXLayout::NOT_IN_TOC
|
2006-03-29 05:08:42 +00:00
|
|
|
&& toclevel <= thistoclevel) {
|
2006-04-05 23:56:29 +00:00
|
|
|
break;
|
2006-03-29 05:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pit_type const newpit = std::distance(pars.begin(), q);
|
|
|
|
pit_type const len = std::distance(s, p);
|
|
|
|
pit += len;
|
|
|
|
pars.insert(q, s, p);
|
|
|
|
s = boost::next(pars.begin(), pit);
|
|
|
|
ParagraphList::iterator t = boost::next(s, len);
|
|
|
|
pit = newpit;
|
|
|
|
pars.erase(s, t);
|
|
|
|
break;
|
|
|
|
}
|
2006-04-28 07:28:10 +00:00
|
|
|
case Down: {
|
2006-04-05 23:56:29 +00:00
|
|
|
if (p != end)
|
2006-03-29 05:08:42 +00:00
|
|
|
++p;
|
|
|
|
for (; p != end; ++p) {
|
|
|
|
toclevel = p->layout()->toclevel;
|
2006-04-05 23:56:29 +00:00
|
|
|
if (toclevel != LyXLayout::NOT_IN_TOC
|
2006-03-29 05:08:42 +00:00
|
|
|
&& toclevel <= thistoclevel) {
|
2006-04-05 23:56:29 +00:00
|
|
|
break;
|
2006-03-29 05:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ParagraphList::iterator q = p;
|
|
|
|
if (q != end)
|
|
|
|
++q;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
for (; q != end; ++q) {
|
|
|
|
toclevel = q->layout()->toclevel;
|
2006-04-05 23:56:29 +00:00
|
|
|
if (toclevel != LyXLayout::NOT_IN_TOC
|
2006-03-29 05:08:42 +00:00
|
|
|
&& toclevel <= thistoclevel) {
|
2006-04-05 23:56:29 +00:00
|
|
|
break;
|
2006-03-29 05:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pit_type const newpit = std::distance(pars.begin(), q);
|
|
|
|
pit_type const len = std::distance(s, p);
|
|
|
|
pars.insert(q, s, p);
|
|
|
|
s = boost::next(pars.begin(), pit);
|
|
|
|
ParagraphList::iterator t = boost::next(s, len);
|
|
|
|
pit = newpit - len;
|
|
|
|
pars.erase(s, t);
|
|
|
|
break;
|
|
|
|
}
|
2006-04-28 07:28:10 +00:00
|
|
|
case In:
|
2006-03-29 05:08:42 +00:00
|
|
|
for (; lit != lend; ++lit) {
|
2006-04-26 17:43:03 +00:00
|
|
|
if ((*lit)->toclevel == thistoclevel + 1 &&
|
|
|
|
s->layout()->labeltype == (*lit)->labeltype) {
|
2006-03-29 05:08:42 +00:00
|
|
|
s->layout((*lit));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-04-28 07:28:10 +00:00
|
|
|
case Out:
|
2006-03-29 05:08:42 +00:00
|
|
|
for (; lit != lend; ++lit) {
|
2006-04-26 17:43:03 +00:00
|
|
|
if ((*lit)->toclevel == thistoclevel - 1 &&
|
|
|
|
s->layout()->labeltype == (*lit)->labeltype) {
|
2006-03-29 05:08:42 +00:00
|
|
|
s->layout((*lit));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-21 15:51:07 +00:00
|
|
|
} // namespace toc
|
2003-07-27 13:18:55 +00:00
|
|
|
} // namespace lyx
|