2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
|
* \file InsetFloatList.cpp
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
|
*/
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
2003-05-13 09:48:57 +00:00
|
|
|
|
#include <config.h>
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "InsetFloatList.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Buffer.h"
|
|
|
|
|
#include "BufferParams.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
#include "debug.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "DispatchResult.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
#include "Floating.h"
|
2001-05-04 10:36:36 +00:00
|
|
|
|
#include "FloatList.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "FuncRequest.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
#include "gettext.h"
|
2002-04-04 14:39:55 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "MetricsInfo.h"
|
2006-11-11 00:35:14 +00:00
|
|
|
|
#include "TocBackend.h"
|
2003-05-13 09:48:57 +00:00
|
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using support::bformat;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2001-05-04 13:17:01 +00:00
|
|
|
|
using std::endl;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-05 09:01:27 +00:00
|
|
|
|
using std::ostream;
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
2001-11-27 10:56:14 +00:00
|
|
|
|
InsetFloatList::InsetFloatList()
|
2007-10-19 17:22:55 +00:00
|
|
|
|
: InsetCommand(InsetCommandParams(FLOAT_LIST_CODE), "toc")
|
2003-05-13 09:48:57 +00:00
|
|
|
|
{}
|
2001-11-27 10:56:14 +00:00
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-11-27 10:56:14 +00:00
|
|
|
|
InsetFloatList::InsetFloatList(string const & type)
|
2007-10-19 17:22:55 +00:00
|
|
|
|
: InsetCommand(InsetCommandParams(FLOAT_LIST_CODE), "toc")
|
2001-11-27 10:56:14 +00:00
|
|
|
|
{
|
2006-10-22 18:24:41 +00:00
|
|
|
|
setParam("type", from_ascii(type));
|
2001-11-27 10:56:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
docstring const InsetFloatList::getScreenLabel(Buffer const & buf) const
|
2001-05-04 10:36:36 +00:00
|
|
|
|
{
|
2007-04-29 19:53:54 +00:00
|
|
|
|
FloatList const & floats = buf.params().getTextClass().floats();
|
2006-10-22 18:24:41 +00:00
|
|
|
|
FloatList::const_iterator it = floats[to_ascii(getParam("type"))];
|
2002-08-27 15:51:19 +00:00
|
|
|
|
if (it != floats.end())
|
2006-10-11 19:40:50 +00:00
|
|
|
|
return buf.B_(it->second.listName());
|
2002-04-28 14:00:48 +00:00
|
|
|
|
else
|
2006-10-11 19:40:50 +00:00
|
|
|
|
return _("ERROR: Nonexistent float type!");
|
2001-05-04 10:36:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetFloatList::write(Buffer const &, ostream & os) const
|
2001-05-04 10:36:36 +00:00
|
|
|
|
{
|
2006-10-22 18:24:41 +00:00
|
|
|
|
os << "FloatList " << to_ascii(getParam("type")) << "\n";
|
2001-05-04 10:36:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
|
void InsetFloatList::read(Buffer const & buf, Lexer & lex)
|
2001-05-04 10:36:36 +00:00
|
|
|
|
{
|
2007-04-29 19:53:54 +00:00
|
|
|
|
FloatList const & floats = buf.params().getTextClass().floats();
|
2006-10-22 18:24:41 +00:00
|
|
|
|
string token;
|
|
|
|
|
|
|
|
|
|
if (lex.eatLine()) {
|
|
|
|
|
setParam("type", lex.getDocString());
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::INSETS) << "FloatList::float_type: "
|
2007-05-28 22:27:45 +00:00
|
|
|
|
<< to_ascii(getParam("type")) << endl;
|
2006-10-22 18:24:41 +00:00
|
|
|
|
if (!floats.typeExist(to_ascii(getParam("type"))))
|
|
|
|
|
lex.printError("InsetFloatList: Unknown float type: `$$Token'");
|
|
|
|
|
} else
|
|
|
|
|
lex.printError("InsetFloatList: Parse error: `$$Token'");
|
|
|
|
|
while (lex.isOK()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
token = lex.getString();
|
|
|
|
|
if (token == "\\end_inset")
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (token != "\\end_inset") {
|
|
|
|
|
lex.printError("Missing \\end_inset at this point. "
|
|
|
|
|
"Read: `$$Token'");
|
|
|
|
|
}
|
2001-05-04 10:36:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetFloatList::latex(Buffer const & buf, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const &) const
|
2001-05-04 10:36:36 +00:00
|
|
|
|
{
|
2007-04-29 19:53:54 +00:00
|
|
|
|
FloatList const & floats = buf.params().getTextClass().floats();
|
2006-10-22 18:24:41 +00:00
|
|
|
|
FloatList::const_iterator cit = floats[to_ascii(getParam("type"))];
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
2002-08-27 15:51:19 +00:00
|
|
|
|
if (cit != floats.end()) {
|
2001-05-04 10:36:36 +00:00
|
|
|
|
if (cit->second.builtin()) {
|
|
|
|
|
// Only two different types allowed here:
|
|
|
|
|
string const type = cit->second.type();
|
|
|
|
|
if (type == "table") {
|
|
|
|
|
os << "\\listoftables\n";
|
|
|
|
|
} else if (type == "figure") {
|
|
|
|
|
os << "\\listoffigures\n";
|
|
|
|
|
} else {
|
|
|
|
|
os << "%% unknown builtin float\n";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2006-10-22 18:24:41 +00:00
|
|
|
|
os << "\\listof{" << getParam("type") << "}{"
|
2006-10-19 16:51:30 +00:00
|
|
|
|
<< buf.B_(cit->second.listName()) << "}\n";
|
2001-05-04 10:36:36 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2006-10-22 18:24:41 +00:00
|
|
|
|
os << "%%\\listof{" << getParam("type") << "}{"
|
2006-10-21 00:16:43 +00:00
|
|
|
|
<< bformat(_("List of %1$s"), from_utf8(cit->second.name()))
|
2002-11-24 15:20:31 +00:00
|
|
|
|
<< "}\n";
|
2001-05-04 10:36:36 +00:00
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetFloatList::plaintext(Buffer const & buffer, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const &) const
|
2001-05-04 10:36:36 +00:00
|
|
|
|
{
|
2001-07-28 12:24:16 +00:00
|
|
|
|
os << getScreenLabel(buffer) << "\n\n";
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
2007-01-18 22:29:50 +00:00
|
|
|
|
buffer.tocBackend().writePlaintextTocList(to_ascii(getParam("type")), os);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
2007-02-20 17:52:41 +00:00
|
|
|
|
return PLAINTEXT_NEWLINE;
|
2001-05-04 10:36:36 +00:00
|
|
|
|
}
|
2002-04-04 14:39:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFloatList::validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
2006-10-22 18:24:41 +00:00
|
|
|
|
features.useFloat(to_ascii(getParam("type")));
|
2002-04-04 14:39:55 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|