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.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2002-09-25 14:26:13 +00:00
|
|
|
*
|
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"
|
|
|
|
#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"
|
2010-10-31 01:04:03 +00:00
|
|
|
#include "Font.h"
|
2010-03-05 21:06:22 +00:00
|
|
|
#include "Language.h"
|
2002-04-04 14:39:55 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2010-01-01 02:41:26 +00:00
|
|
|
#include "Paragraph.h"
|
|
|
|
#include "output_xhtml.h"
|
2007-11-07 23:25:08 +00:00
|
|
|
#include "TextClass.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "TocBackend.h"
|
2003-05-13 09:48:57 +00:00
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
|
|
|
#include "support/gettext.h"
|
2003-05-13 09:48:57 +00:00
|
|
|
#include "support/lstrings.h"
|
2001-05-04 10:36:36 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
#include <ostream>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2009-11-08 16:10:34 +00:00
|
|
|
InsetFloatList::InsetFloatList(Buffer * buf)
|
2010-10-29 00:46:21 +00:00
|
|
|
: InsetCommand(buf, InsetCommandParams(FLOAT_LIST_CODE))
|
2003-05-13 09:48:57 +00:00
|
|
|
{}
|
2001-11-27 10:56:14 +00:00
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2009-11-08 16:10:34 +00:00
|
|
|
InsetFloatList::InsetFloatList(Buffer * buf, string const & type)
|
2010-10-29 00:46:21 +00:00
|
|
|
: InsetCommand(buf, InsetCommandParams(FLOAT_LIST_CODE))
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-23 22:01:02 +00:00
|
|
|
ParamInfo const & InsetFloatList::findInfo(string const & /* cmdName */)
|
2007-10-25 04:13:56 +00:00
|
|
|
{
|
2008-02-23 22:01:02 +00:00
|
|
|
static ParamInfo param_info_;
|
|
|
|
if (param_info_.empty()) {
|
Per Abdel's suggestion that we focus on bug-fixing at this point, this will be the last patch in this series for a bit. But I wanted to get this done before I forget what it is I was doing, so here it is.
The idea behind this patch is to make real key-value support for InsetCommand parameters possible. This should be particularly useful for the listings version of InsetInclude, though we would need some kind of UI for it before it would really be helpful. (See below for some thoughts.) This doesn't substantially change anything else, though some things do get re-arranged a bit.
Basically, the idea is this. First, we introduce a whole range of parameter types: Normal LaTeX optional and required parameters; ones for LyX's internal use (like embed); and finally, in connection with keyval, ones that represent keys and ones that represent optional and required arguments where the keyval stuff will appear. (I'm assuming here that there will always be exactly one of those, and that it will accept only keyval-type material.) The parameters themselves are stored in a map, so it's really only the output routines that need to care about the different types of parameters.
Regarding the frontend, it seems to me that something like the following would work:
(i) scan the parameter list for LATEX_KEY type parameters
(ii) the dialog will have a series of lines, each of which has a combo box listing the acceptable keys and a QLineEdit for entering its value, as well as a "delete" button of some sort for removing this key and its value
(iii) there should be an "add line" button to add a new line, activated only when all other lines are filled with values
Probably not even too hard.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23235 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-25 22:13:45 +00:00
|
|
|
param_info_.add("type", ParamInfo::LATEX_REQUIRED);
|
2008-02-23 22:01:02 +00:00
|
|
|
}
|
|
|
|
return param_info_;
|
2007-10-25 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//HACK
|
2007-12-12 19:28:07 +00:00
|
|
|
bool InsetFloatList::isCompatibleCommand(string const & s)
|
2007-11-28 22:12:03 +00:00
|
|
|
{
|
2007-12-12 19:28:07 +00:00
|
|
|
string str = s.substr(0, 6);
|
2007-10-25 04:13:56 +00:00
|
|
|
return str == "listof";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring InsetFloatList::screenLabel() const
|
2001-05-04 10:36:36 +00:00
|
|
|
{
|
2008-02-28 01:42:02 +00:00
|
|
|
FloatList const & floats = buffer().params().documentClass().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())
|
2008-02-27 20:43:16 +00:00
|
|
|
return buffer().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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetFloatList::write(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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetFloatList::read(Lexer & lex)
|
2001-05-04 10:36:36 +00:00
|
|
|
{
|
2008-04-05 21:24:57 +00:00
|
|
|
lex.setContext("InsetFloatList::read");
|
2008-02-28 01:42:02 +00:00
|
|
|
FloatList const & floats = buffer().params().documentClass().floats();
|
2006-10-22 18:24:41 +00:00
|
|
|
string token;
|
|
|
|
|
|
|
|
if (lex.eatLine()) {
|
|
|
|
setParam("type", lex.getDocString());
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::INSETS, "FloatList::float_type: "
|
|
|
|
<< to_ascii(getParam("type")));
|
2006-10-22 18:24:41 +00:00
|
|
|
if (!floats.typeExist(to_ascii(getParam("type"))))
|
2008-04-05 21:24:57 +00:00
|
|
|
lex.printError("Unknown float type");
|
2007-11-15 20:04:51 +00:00
|
|
|
} else {
|
2008-04-05 21:24:57 +00:00
|
|
|
lex.printError("Parse error");
|
2007-11-15 20:04:51 +00:00
|
|
|
}
|
|
|
|
|
2006-10-22 18:24:41 +00:00
|
|
|
while (lex.isOK()) {
|
|
|
|
lex.next();
|
|
|
|
token = lex.getString();
|
|
|
|
if (token == "\\end_inset")
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (token != "\\end_inset") {
|
2008-04-05 21:24:57 +00:00
|
|
|
lex.printError("Missing \\end_inset at this point.");
|
2006-10-22 18:24:41 +00:00
|
|
|
}
|
2001-05-04 10:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Introduce a wrapper class for odocstream to help ensuring that no
blank lines may be inadvertently output. This is achieved by using two
special iomanip-like variables (breakln and safebreakln) in the lyx::
namespace. When they are inserted in the stream, a newline is output
only if not already at the beginning of a line. The difference between
breakln and safebreakln is that, if needed, the former outputs '\n'
and the latter "%\n".
In future, the new class will also be used for counting the number of
newlines issued. Even if the infractrure for doing that is already in
place, the counting is essentially still done the old way.
There are still places in the code where the functionality of the
class could be used, most probably. ATM, it is used for InsetTabular,
InsetListings, InsetFloat, and InsetText.
The Comment and GreyedOut insets required a special treatment and a
new InsetLayout parameter (Display) has been introduced. The default
for Display is "true", meaning that the corresponding latex
environment is of "display" type, i.e., it stands on its own, whereas
"false" means that the contents appear inline with the text. The
latter is the case for both Comment and GreyedOut insets.
Mostly, the only visible effects on latex exports should be the
disappearing of some redundant % chars and the appearing/disappearing
of null {} latex groups after a comment or lyxgreyedout environments
(they are related to the presence or absence of a space immediately
after those environments), as well as the fact that math environments
are now started on their own lines.
As a last thing, only the latex code between \begin{document} and
\end{document} goes through the new class, the preamble being directly
output through odocstream, as usual.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37360 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-29 02:41:13 +00:00
|
|
|
int InsetFloatList::latex(otexstream & os, OutputParams const &) const
|
2001-05-04 10:36:36 +00:00
|
|
|
{
|
2008-02-28 01:42:02 +00:00
|
|
|
FloatList const & floats = buffer().params().documentClass().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()) {
|
2010-03-05 22:58:29 +00:00
|
|
|
Floating const & fl = cit->second;
|
|
|
|
if (fl.needsFloatPkg())
|
|
|
|
os << "\\listof{" << getParam("type") << "}{"
|
|
|
|
<< buffer().B_(fl.listName()) << "}\n";
|
2010-03-05 23:47:33 +00:00
|
|
|
else {
|
|
|
|
if (!fl.listCommand().empty())
|
|
|
|
os << "\\" << from_ascii(fl.listCommand()) << "\n";
|
|
|
|
else
|
|
|
|
os << "%% "
|
|
|
|
<< bformat(_("LyX cannot generate a list of %1$s"), getParam("type"))
|
|
|
|
<< "\n";
|
|
|
|
}
|
2001-05-04 10:36:36 +00:00
|
|
|
} else {
|
2006-10-22 18:24:41 +00:00
|
|
|
os << "%%\\listof{" << getParam("type") << "}{"
|
2010-03-05 21:06:22 +00:00
|
|
|
<< bformat(_("List of %1$s"), getParam("type"))
|
2002-11-24 15:20:31 +00:00
|
|
|
<< "}\n";
|
2001-05-04 10:36:36 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetFloatList::plaintext(odocstream & os, OutputParams const &) const
|
2001-05-04 10:36:36 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
os << screenLabel() << "\n\n";
|
2001-05-04 10:36:36 +00:00
|
|
|
|
2008-02-27 20:43:16 +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
|
|
|
|
|
|
|
|
2010-01-01 02:41:26 +00:00
|
|
|
docstring InsetFloatList::xhtml(XHTMLStream &, OutputParams const &) const {
|
|
|
|
FloatList const & floats = buffer().params().documentClass().floats();
|
|
|
|
FloatList::const_iterator cit = floats[to_ascii(getParam("type"))];
|
|
|
|
|
|
|
|
if (cit == floats.end()) {
|
|
|
|
LYXERR0("Unknown float type `" << getParam("type") << "' in IFL::xhtml.");
|
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
|
|
|
string toctype;
|
|
|
|
docstring toclabel;
|
2010-03-05 21:07:01 +00:00
|
|
|
// FIXME
|
|
|
|
// Other builtin floats should be handled here. But I'm not sure if that is
|
|
|
|
// even possible yet, since I'm not sure if we have a TOC for such things.
|
|
|
|
// If so, then they should define ListName, as non-builtin floats do, and
|
|
|
|
// then we can use that.
|
|
|
|
// Really, all floats should define that.
|
2010-03-05 17:24:38 +00:00
|
|
|
if (!cit->second.needsFloatPkg()) {
|
2010-01-01 02:41:26 +00:00
|
|
|
// Only two different types allowed here:
|
2010-03-04 13:42:05 +00:00
|
|
|
string const type = cit->second.floattype();
|
2010-01-01 02:41:26 +00:00
|
|
|
if (type == "table") {
|
|
|
|
toctype = "table";
|
|
|
|
toclabel = _("List of Tables");
|
|
|
|
} else if (type == "figure") {
|
|
|
|
toctype = "figure";
|
|
|
|
toclabel = _("List of Figures");
|
|
|
|
} else {
|
|
|
|
LYXERR0("Unknown Builtin Float!");
|
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
toctype = to_utf8(getParam("type"));
|
|
|
|
toclabel = buffer().B_(cit->second.listName());
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME Do we need to check if it exists? If so, we need a new
|
|
|
|
// routine in TocBackend to do that.
|
|
|
|
Toc const & toc = buffer().tocBackend().toc(toctype);
|
|
|
|
if (toc.empty())
|
|
|
|
return docstring();
|
|
|
|
|
|
|
|
// we want to look like a chapter, section, or whatever.
|
|
|
|
// so we're going to look for the layout with the minimum toclevel
|
|
|
|
// number > 0---because we don't want Part.
|
|
|
|
// we'll take the first one, just because.
|
|
|
|
// FIXME This could be specified in the layout file.
|
|
|
|
DocumentClass const & dc = buffer().params().documentClass();
|
|
|
|
TextClass::LayoutList::const_iterator lit = dc.begin();
|
|
|
|
TextClass::LayoutList::const_iterator len = dc.end();
|
|
|
|
int minlevel = 1000;
|
|
|
|
Layout const * lay = NULL;
|
|
|
|
for (; lit != len; ++lit) {
|
|
|
|
int const level = lit->toclevel;
|
|
|
|
if (level > 0 && (level == Layout::NOT_IN_TOC || level >= minlevel))
|
|
|
|
continue;
|
|
|
|
lay = &*lit;
|
|
|
|
minlevel = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
string const tocclass = lay ? " " + lay->defaultCSSClass(): "";
|
|
|
|
string const tocattr = "class='tochead + toc-" + toctype + " " + tocclass + "'";
|
|
|
|
|
|
|
|
// we'll use our own stream, because we are going to defer everything.
|
|
|
|
// that's how we deal with the fact that we're probably inside a standard
|
|
|
|
// paragraph, and we don't want to be.
|
|
|
|
odocstringstream ods;
|
|
|
|
XHTMLStream xs(ods);
|
|
|
|
|
2010-01-19 22:08:04 +00:00
|
|
|
xs << html::StartTag("div", "class='toc'");
|
|
|
|
xs << html::StartTag("div", tocattr)
|
2010-01-01 02:41:26 +00:00
|
|
|
<< toclabel
|
2010-01-19 22:08:04 +00:00
|
|
|
<< html::EndTag("div");
|
2010-01-01 02:41:26 +00:00
|
|
|
|
|
|
|
Toc::const_iterator it = toc.begin();
|
|
|
|
Toc::const_iterator const en = toc.end();
|
|
|
|
for (; it != en; ++it) {
|
|
|
|
Paragraph const & par = it->dit().innerParagraph();
|
|
|
|
string const attr = "class='lyxtoc-" + toctype + "'";
|
|
|
|
Font const dummy;
|
2010-01-19 22:08:04 +00:00
|
|
|
xs << html::StartTag("div", attr);
|
2010-01-01 02:41:26 +00:00
|
|
|
string const parattr = "href='#" + par.magicLabel() + "' class='tocarrow'";
|
|
|
|
xs << it->str() << " "
|
2010-01-19 22:08:04 +00:00
|
|
|
<< html::StartTag("a", parattr)
|
2010-01-01 02:41:26 +00:00
|
|
|
// FIXME XHTML
|
|
|
|
// There ought to be a simple way to customize this.
|
2010-11-24 15:27:36 +00:00
|
|
|
<< XHTMLStream::ESCAPE_NONE << ">"
|
2010-01-19 22:08:04 +00:00
|
|
|
<< html::EndTag("a");
|
|
|
|
xs << html::EndTag("div");
|
2010-01-01 02:41:26 +00:00
|
|
|
}
|
2010-01-19 22:08:04 +00:00
|
|
|
xs << html::EndTag("div");
|
2010-01-01 02:41:26 +00:00
|
|
|
return ods.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|