2001-03-30 19:24:28 +00:00
|
|
|
/* This file is part of
|
2002-03-21 21:21:28 +00:00
|
|
|
* ======================================================
|
2001-03-30 19:24:28 +00:00
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 2001 The LyX Team.
|
|
|
|
*
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* \file ControlToc.C
|
|
|
|
* \author Angus Leeming <a.leeming@ic.ac.uk>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
#include "ControlToc.h"
|
2001-03-30 19:24:28 +00:00
|
|
|
#include "buffer.h"
|
|
|
|
#include "Dialogs.h"
|
|
|
|
#include "lyxfunc.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
#include "gettext.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "BufferView.h"
|
2001-03-30 19:24:28 +00:00
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
#include "support/lstrings.h" // tostr
|
|
|
|
|
2001-03-30 19:24:28 +00:00
|
|
|
using std::vector;
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
2001-03-30 19:24:28 +00:00
|
|
|
ControlToc::ControlToc(LyXView & lv, Dialogs & d)
|
|
|
|
: ControlCommand(lv, d, LFUN_TOC_INSERT)
|
2002-06-18 15:44:30 +00:00
|
|
|
{}
|
2001-03-30 19:24:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ControlToc::Goto(int const & id) const
|
|
|
|
{
|
|
|
|
string const tmp = tostr(id);
|
2001-07-16 15:42:57 +00:00
|
|
|
lv_.getLyXFunc()->dispatch(LFUN_GOTO_PARAGRAPH, tmp);
|
2001-03-30 19:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vector<string> const ControlToc::getTypes() const
|
|
|
|
{
|
|
|
|
vector<string> types;
|
|
|
|
|
|
|
|
Buffer::Lists const tmp = lv_.view()->buffer()->getLists();
|
|
|
|
|
|
|
|
Buffer::Lists::const_iterator cit = tmp.begin();
|
|
|
|
Buffer::Lists::const_iterator end = tmp.end();
|
|
|
|
|
|
|
|
for (; cit != end; ++cit) {
|
2001-04-03 14:30:58 +00:00
|
|
|
types.push_back(cit->first);
|
2001-03-30 19:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return types;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::SingleList const ControlToc::getContents(string const & type) const
|
|
|
|
{
|
2001-06-11 17:20:17 +00:00
|
|
|
Buffer::SingleList empty_list;
|
2001-03-30 19:24:28 +00:00
|
|
|
|
|
|
|
// This shouldn't be possible...
|
|
|
|
if (!lv_.view()->available()) {
|
2001-06-11 17:20:17 +00:00
|
|
|
return empty_list;
|
2001-03-30 19:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Buffer::Lists tmp = lv_.view()->buffer()->getLists();
|
|
|
|
|
|
|
|
Buffer::Lists::iterator it = tmp.find(type);
|
|
|
|
|
|
|
|
if (it == tmp.end()) {
|
2001-06-11 17:20:17 +00:00
|
|
|
return empty_list;
|
2001-03-30 19:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
namespace toc
|
2001-03-30 19:24:28 +00:00
|
|
|
{
|
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
string const getType(string const & cmdName)
|
2001-03-30 19:24:28 +00:00
|
|
|
{
|
2001-11-27 10:56:14 +00:00
|
|
|
string type = cmdName;
|
2001-03-30 19:24:28 +00:00
|
|
|
|
2001-11-27 10:56:14 +00:00
|
|
|
// special case
|
|
|
|
if (cmdName == "tableofcontents")
|
2001-03-30 19:24:28 +00:00
|
|
|
type = "TOC";
|
|
|
|
|
2001-11-27 10:56:14 +00:00
|
|
|
return type;
|
2001-03-30 19:24:28 +00:00
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
|
|
} // namespace toc
|