2001-03-30 19:24:28 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2001-04-26 18:40:38 +00:00
|
|
|
#include "ViewBase.h"
|
|
|
|
#include "ButtonControllerBase.h"
|
2001-03-30 19:24:28 +00:00
|
|
|
#include "ControlToc.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "Dialogs.h"
|
|
|
|
#include "LyXView.h"
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
#include "support/lstrings.h" // tostr
|
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
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using SigC::slot;
|
|
|
|
|
|
|
|
ControlToc::ControlToc(LyXView & lv, Dialogs & d)
|
|
|
|
: ControlCommand(lv, d, LFUN_TOC_INSERT)
|
|
|
|
{
|
|
|
|
d_.showTOC.connect(slot(this, &ControlToc::showInset));
|
|
|
|
d_.createTOC.connect(slot(this, &ControlToc::createInset));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace toc
|
|
|
|
{
|
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
string const getType(string const & cmdName)
|
2001-03-30 19:24:28 +00:00
|
|
|
{
|
|
|
|
string type;
|
|
|
|
|
|
|
|
// It would be nice to have a map to extract this info.
|
|
|
|
// Does one already exist, Lars?
|
|
|
|
if (cmdName == "tableofcontents" )
|
|
|
|
type = "TOC";
|
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
return cmdName;
|
2001-03-30 19:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace toc
|