2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetIndex.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
|
2009-04-16 07:29:01 +00:00
|
|
|
* \author Jürgen Spitzmüller
|
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
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetIndex.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2008-02-15 10:13:32 +00:00
|
|
|
#include "Buffer.h"
|
2009-04-16 07:29:01 +00:00
|
|
|
#include "BufferParams.h"
|
2009-04-17 09:22:44 +00:00
|
|
|
#include "BufferView.h"
|
2009-04-16 07:29:01 +00:00
|
|
|
#include "ColorSet.h"
|
2010-10-31 01:04:03 +00:00
|
|
|
#include "Cursor.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "DispatchResult.h"
|
2008-09-15 14:19:00 +00:00
|
|
|
#include "Encoding.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2007-10-03 13:38:19 +00:00
|
|
|
#include "FuncStatus.h"
|
2009-04-16 07:29:01 +00:00
|
|
|
#include "IndicesList.h"
|
2013-03-23 13:10:01 +00:00
|
|
|
#include "Language.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2009-04-16 07:29:01 +00:00
|
|
|
#include "Lexer.h"
|
2009-11-21 23:28:20 +00:00
|
|
|
#include "output_latex.h"
|
2010-01-12 20:44:39 +00:00
|
|
|
#include "output_xhtml.h"
|
2004-10-25 00:26:05 +00:00
|
|
|
#include "sgml.h"
|
2016-06-19 02:39:38 +00:00
|
|
|
#include "texstream.h"
|
2010-10-31 01:04:03 +00:00
|
|
|
#include "TextClass.h"
|
2008-02-13 13:19:39 +00:00
|
|
|
#include "TocBackend.h"
|
|
|
|
|
2008-08-05 14:25:32 +00:00
|
|
|
#include "support/debug.h"
|
2008-04-27 08:52:43 +00:00
|
|
|
#include "support/docstream.h"
|
2008-02-13 13:19:39 +00:00
|
|
|
#include "support/gettext.h"
|
2008-04-27 08:52:43 +00:00
|
|
|
#include "support/lstrings.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2008-09-15 14:19:00 +00:00
|
|
|
#include "frontends/alert.h"
|
|
|
|
|
2010-04-22 11:45:34 +00:00
|
|
|
#include <algorithm>
|
2013-03-08 19:52:18 +00:00
|
|
|
#include <ostream>
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2008-04-27 08:52:43 +00:00
|
|
|
using namespace lyx::support;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
2006-10-11 19:40:50 +00:00
|
|
|
|
2008-03-05 00:21:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// InsetIndex
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetIndex::InsetIndex(Buffer * buf, InsetIndexParams const & params)
|
2017-10-16 08:12:21 +00:00
|
|
|
: InsetCollapsible(buf), params_(params)
|
2007-11-02 17:47:51 +00:00
|
|
|
{}
|
2007-10-03 13:38:19 +00:00
|
|
|
|
|
|
|
|
2011-02-10 20:02:48 +00:00
|
|
|
void InsetIndex::latex(otexstream & os, OutputParams const & runparams_in) const
|
2008-04-26 14:24:28 +00:00
|
|
|
{
|
2009-09-10 12:07:42 +00:00
|
|
|
OutputParams runparams(runparams_in);
|
|
|
|
runparams.inIndexEntry = true;
|
|
|
|
|
2009-04-16 07:29:01 +00:00
|
|
|
if (buffer().masterBuffer()->params().use_indices && !params_.index.empty()
|
|
|
|
&& params_.index != "idx") {
|
|
|
|
os << "\\sindex[";
|
2012-07-01 06:38:54 +00:00
|
|
|
os << escape(params_.index);
|
2009-04-16 07:29:01 +00:00
|
|
|
os << "]{";
|
|
|
|
} else {
|
|
|
|
os << "\\index";
|
|
|
|
os << '{';
|
|
|
|
}
|
2008-08-05 14:25:32 +00:00
|
|
|
|
|
|
|
// get contents of InsetText as LaTeX and plaintext
|
|
|
|
odocstringstream ourlatex;
|
2016-09-23 22:49:00 +00:00
|
|
|
// FIXME: do Tex/Row correspondence (I don't currently understand what is
|
|
|
|
// being generated from latexstr below)
|
2016-06-19 02:39:38 +00:00
|
|
|
otexstream ots(ourlatex);
|
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
|
|
|
InsetText::latex(ots, runparams);
|
2008-08-05 14:25:32 +00:00
|
|
|
odocstringstream ourplain;
|
|
|
|
InsetText::plaintext(ourplain, runparams);
|
|
|
|
docstring latexstr = ourlatex.str();
|
|
|
|
docstring plainstr = ourplain.str();
|
|
|
|
|
|
|
|
// this will get what follows | if anything does
|
|
|
|
docstring cmd;
|
|
|
|
|
|
|
|
// check for the | separator
|
|
|
|
// FIXME This would go wrong on an escaped "|", but
|
|
|
|
// how far do we want to go here?
|
|
|
|
size_t pos = latexstr.find(from_ascii("|"));
|
|
|
|
if (pos != docstring::npos) {
|
|
|
|
// put the bit after "|" into cmd...
|
|
|
|
cmd = latexstr.substr(pos + 1);
|
|
|
|
// ...and erase that stuff from latexstr
|
|
|
|
latexstr = latexstr.erase(pos);
|
|
|
|
// ...and similarly from plainstr
|
|
|
|
size_t ppos = plainstr.find(from_ascii("|"));
|
|
|
|
if (ppos < plainstr.size())
|
|
|
|
plainstr.erase(ppos);
|
|
|
|
else
|
|
|
|
LYXERR0("The `|' separator was not found in the plaintext version!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Separate the entires and subentries, i.e., split on "!"
|
|
|
|
// FIXME This would do the wrong thing with escaped ! characters
|
2008-07-14 08:20:24 +00:00
|
|
|
std::vector<docstring> const levels =
|
2008-08-05 14:25:32 +00:00
|
|
|
getVectorFromString(latexstr, from_ascii("!"), true);
|
2008-07-14 08:20:24 +00:00
|
|
|
std::vector<docstring> const levels_plain =
|
2008-08-05 14:25:32 +00:00
|
|
|
getVectorFromString(plainstr, from_ascii("!"), true);
|
|
|
|
|
2008-07-14 08:20:24 +00:00
|
|
|
vector<docstring>::const_iterator it = levels.begin();
|
|
|
|
vector<docstring>::const_iterator end = levels.end();
|
|
|
|
vector<docstring>::const_iterator it2 = levels_plain.begin();
|
2008-08-05 14:25:32 +00:00
|
|
|
bool first = true;
|
2008-07-14 08:20:24 +00:00
|
|
|
for (; it != end; ++it) {
|
2008-08-05 14:25:32 +00:00
|
|
|
// write the separator except the first time
|
2008-10-19 11:28:23 +00:00
|
|
|
if (!first)
|
2008-07-14 08:20:24 +00:00
|
|
|
os << '!';
|
2008-10-19 11:28:23 +00:00
|
|
|
else
|
2008-08-05 14:25:32 +00:00
|
|
|
first = false;
|
|
|
|
|
2008-07-14 08:20:24 +00:00
|
|
|
// correctly sort macros and formatted strings
|
|
|
|
// if we do find a command, prepend a plain text
|
|
|
|
// version of the content to get sorting right,
|
|
|
|
// e.g. \index{LyX@\LyX}, \index{text@\textbf{text}}
|
|
|
|
// Don't do that if the user entered '@' himself, though.
|
|
|
|
if (contains(*it, '\\') && !contains(*it, '@')) {
|
2008-07-14 16:09:59 +00:00
|
|
|
// Plaintext might return nothing (e.g. for ERTs)
|
2017-07-03 17:53:14 +00:00
|
|
|
docstring const spart =
|
2008-09-15 14:19:00 +00:00
|
|
|
(it2 < levels_plain.end() && !(*it2).empty())
|
|
|
|
? *it2 : *it;
|
|
|
|
// Now we need to validate that all characters in
|
|
|
|
// the sorting part are representable in the current
|
|
|
|
// encoding. If not try the LaTeX macro which might
|
|
|
|
// or might not be a good choice, and issue a warning.
|
2012-06-30 11:34:49 +00:00
|
|
|
pair<docstring, docstring> spart_latexed =
|
|
|
|
runparams.encoding->latexString(spart, runparams.dryrun);
|
|
|
|
if (!spart_latexed.second.empty())
|
2008-09-15 14:19:00 +00:00
|
|
|
LYXERR0("Uncodable character in index entry. Sorting might be wrong!");
|
2012-06-30 11:34:49 +00:00
|
|
|
if (spart != spart_latexed.first && !runparams.dryrun) {
|
2008-09-15 14:19:00 +00:00
|
|
|
// FIXME: warning should be passed to the error dialog
|
|
|
|
frontend::Alert::warning(_("Index sorting failed"),
|
|
|
|
bformat(_("LyX's automatic index sorting algorithm faced\n"
|
|
|
|
"problems with the entry '%1$s'.\n"
|
|
|
|
"Please specify the sorting of this entry manually, as\n"
|
|
|
|
"explained in the User Guide."), spart));
|
|
|
|
}
|
2008-05-09 09:50:18 +00:00
|
|
|
// remove remaining \'s for the sorting part
|
2008-07-14 08:20:24 +00:00
|
|
|
docstring const ppart =
|
2012-06-30 11:34:49 +00:00
|
|
|
subst(spart_latexed.first, from_ascii("\\"), docstring());
|
2008-07-14 08:20:24 +00:00
|
|
|
os << ppart;
|
2008-04-27 08:52:43 +00:00
|
|
|
os << '@';
|
2008-05-08 09:43:27 +00:00
|
|
|
}
|
2008-07-14 08:20:24 +00:00
|
|
|
docstring const tpart = *it;
|
|
|
|
os << tpart;
|
|
|
|
if (it2 < levels_plain.end())
|
|
|
|
++it2;
|
2008-04-26 14:24:28 +00:00
|
|
|
}
|
2008-08-05 14:25:32 +00:00
|
|
|
// write the bit that followed "|"
|
2010-04-16 23:47:39 +00:00
|
|
|
if (!cmd.empty()) {
|
2008-08-05 14:25:32 +00:00
|
|
|
os << "|" << cmd;
|
2010-04-16 23:47:39 +00:00
|
|
|
}
|
2008-04-26 14:24:28 +00:00
|
|
|
os << '}';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetIndex::docbook(odocstream & os, OutputParams const & runparams) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2007-10-03 13:38:19 +00:00
|
|
|
os << "<indexterm><primary>";
|
2008-02-27 20:43:16 +00:00
|
|
|
int const i = InsetText::docbook(os, runparams);
|
2007-10-03 13:38:19 +00:00
|
|
|
os << "</primary></indexterm>";
|
|
|
|
return i;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2003-08-26 10:33:59 +00:00
|
|
|
|
2010-01-12 20:44:39 +00:00
|
|
|
docstring InsetIndex::xhtml(XHTMLStream & xs, OutputParams const &) const
|
2009-06-12 17:23:17 +00:00
|
|
|
{
|
2017-07-03 17:53:14 +00:00
|
|
|
// we just print an anchor, taking the paragraph ID from
|
2010-01-12 20:44:39 +00:00
|
|
|
// our own interior paragraph, which doesn't get printed
|
|
|
|
std::string const magic = paragraphs().front().magicLabel();
|
|
|
|
std::string const attr = "id='" + magic + "'";
|
2010-01-19 22:08:04 +00:00
|
|
|
xs << html::CompTag("a", attr);
|
2009-06-12 17:23:17 +00:00
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-17 09:22:44 +00:00
|
|
|
bool InsetIndex::showInsetDialog(BufferView * bv) const
|
|
|
|
{
|
|
|
|
bv->showDialog("index", params2string(params_),
|
|
|
|
const_cast<InsetIndex *>(this));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-16 07:29:01 +00:00
|
|
|
void InsetIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2009-04-16 07:29:01 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
if (cmd.getArg(0) == "changetype") {
|
2015-03-12 14:57:29 +00:00
|
|
|
cur.recordUndoInset(this);
|
2009-04-16 07:29:01 +00:00
|
|
|
params_.index = from_utf8(cmd.getArg(1));
|
|
|
|
break;
|
|
|
|
}
|
2009-04-17 09:22:44 +00:00
|
|
|
InsetIndexParams params;
|
|
|
|
InsetIndex::string2params(to_utf8(cmd.argument()), params);
|
2015-03-12 14:57:29 +00:00
|
|
|
cur.recordUndoInset(this);
|
2009-04-17 09:22:44 +00:00
|
|
|
params_.index = params.index;
|
2010-07-09 14:37:00 +00:00
|
|
|
// what we really want here is a TOC update, but that means
|
|
|
|
// a full buffer update
|
|
|
|
cur.forceBufferUpdate();
|
2009-04-17 09:22:44 +00:00
|
|
|
break;
|
2009-04-16 07:29:01 +00:00
|
|
|
}
|
|
|
|
|
2009-04-17 09:22:44 +00:00
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
cur.bv().updateDialog("index", params2string(params_));
|
|
|
|
break;
|
|
|
|
|
2009-04-16 07:29:01 +00:00
|
|
|
default:
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::doDispatch(cur, cmd);
|
2009-04-16 07:29:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & flag) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2009-04-16 07:29:01 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
if (cmd.getArg(0) == "changetype") {
|
|
|
|
docstring const newtype = from_utf8(cmd.getArg(1));
|
|
|
|
Buffer const & realbuffer = *buffer().masterBuffer();
|
|
|
|
IndicesList const & indiceslist = realbuffer.params().indiceslist();
|
|
|
|
Index const * index = indiceslist.findShortcut(newtype);
|
|
|
|
flag.setEnabled(index != 0);
|
|
|
|
flag.setOnOff(
|
|
|
|
from_utf8(cmd.getArg(1)) == params_.index);
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-16 08:12:21 +00:00
|
|
|
return InsetCollapsible::getStatus(cur, cmd, flag);
|
2009-04-17 09:22:44 +00:00
|
|
|
|
2009-04-22 20:55:13 +00:00
|
|
|
case LFUN_INSET_DIALOG_UPDATE: {
|
2009-04-17 09:22:44 +00:00
|
|
|
Buffer const & realbuffer = *buffer().masterBuffer();
|
|
|
|
flag.setEnabled(realbuffer.params().use_indices);
|
|
|
|
return true;
|
|
|
|
}
|
2009-04-16 07:29:01 +00:00
|
|
|
|
|
|
|
default:
|
2017-10-16 08:12:21 +00:00
|
|
|
return InsetCollapsible::getStatus(cur, cmd, flag);
|
2009-04-16 07:29:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-13 06:46:52 +00:00
|
|
|
ColorCode InsetIndex::labelColor() const
|
|
|
|
{
|
|
|
|
if (params_.index.empty() || params_.index == from_ascii("idx"))
|
2017-10-16 08:12:21 +00:00
|
|
|
return InsetCollapsible::labelColor();
|
2009-07-13 06:46:52 +00:00
|
|
|
// FIXME UNICODE
|
|
|
|
ColorCode c = lcolor.getFromLyXName(to_utf8(params_.index));
|
|
|
|
if (c == Color_none)
|
2017-10-16 08:12:21 +00:00
|
|
|
c = InsetCollapsible::labelColor();
|
2009-07-13 06:46:52 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-16 07:29:01 +00:00
|
|
|
docstring InsetIndex::toolTip(BufferView const &, int, int) const
|
|
|
|
{
|
|
|
|
docstring tip = _("Index Entry");
|
|
|
|
if (buffer().params().use_indices && !params_.index.empty()) {
|
|
|
|
Buffer const & realbuffer = *buffer().masterBuffer();
|
|
|
|
IndicesList const & indiceslist = realbuffer.params().indiceslist();
|
|
|
|
tip += " (";
|
|
|
|
Index const * index = indiceslist.findShortcut(params_.index);
|
|
|
|
if (!index)
|
|
|
|
tip += _("unknown type!");
|
|
|
|
else
|
|
|
|
tip += index->index();
|
|
|
|
tip += ")";
|
|
|
|
}
|
|
|
|
tip += ": ";
|
2010-11-17 17:25:22 +00:00
|
|
|
return toolTipText(tip);
|
2009-04-16 07:29:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-17 14:47:45 +00:00
|
|
|
docstring const InsetIndex::buttonLabel(BufferView const & bv) const
|
|
|
|
{
|
|
|
|
InsetLayout const & il = getLayout();
|
|
|
|
docstring label = translateIfPossible(il.labelstring());
|
|
|
|
|
|
|
|
if (buffer().params().use_indices && !params_.index.empty()) {
|
|
|
|
Buffer const & realbuffer = *buffer().masterBuffer();
|
|
|
|
IndicesList const & indiceslist = realbuffer.params().indiceslist();
|
|
|
|
label += " (";
|
|
|
|
Index const * index = indiceslist.findShortcut(params_.index);
|
|
|
|
if (!index)
|
|
|
|
label += _("unknown type!");
|
|
|
|
else
|
|
|
|
label += index->index();
|
|
|
|
label += ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!il.contentaslabel() || geometry(bv) != ButtonOnly)
|
|
|
|
return label;
|
|
|
|
return getNewLabel(label);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetIndex::write(ostream & os) const
|
2007-10-03 13:38:19 +00:00
|
|
|
{
|
2011-03-28 22:33:04 +00:00
|
|
|
os << to_utf8(layoutName());
|
2009-04-16 07:29:01 +00:00
|
|
|
params_.write(os);
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::write(os);
|
2007-10-03 13:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-16 07:29:01 +00:00
|
|
|
void InsetIndex::read(Lexer & lex)
|
|
|
|
{
|
|
|
|
params_.read(lex);
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::read(lex);
|
2009-04-16 07:29:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-17 09:22:44 +00:00
|
|
|
string InsetIndex::params2string(InsetIndexParams const & params)
|
|
|
|
{
|
|
|
|
ostringstream data;
|
|
|
|
data << "index";
|
|
|
|
params.write(data);
|
|
|
|
return data.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetIndex::string2params(string const & in, InsetIndexParams & params)
|
|
|
|
{
|
|
|
|
params = InsetIndexParams();
|
|
|
|
if (in.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
istringstream data(in);
|
|
|
|
Lexer lex;
|
|
|
|
lex.setStream(data);
|
|
|
|
lex.setContext("InsetIndex::string2params");
|
|
|
|
lex >> "index";
|
|
|
|
params.read(lex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-27 06:05:00 +00:00
|
|
|
void InsetIndex::addToToc(DocIterator const & cpit, bool output_active,
|
2017-01-13 10:06:48 +00:00
|
|
|
UpdateType utype, TocBackend & backend) const
|
2008-02-13 13:19:39 +00:00
|
|
|
{
|
2008-05-13 08:23:44 +00:00
|
|
|
DocIterator pit = cpit;
|
2011-01-12 22:23:27 +00:00
|
|
|
pit.push_back(CursorSlice(const_cast<InsetIndex &>(*this)));
|
2010-12-20 21:55:09 +00:00
|
|
|
docstring str;
|
2015-05-09 13:30:10 +00:00
|
|
|
string type = "index";
|
|
|
|
if (buffer().masterBuffer()->params().use_indices)
|
|
|
|
type += ":" + to_utf8(params_.index);
|
2015-05-28 22:02:46 +00:00
|
|
|
// this is unlikely to be terribly long
|
|
|
|
text().forOutliner(str, INT_MAX);
|
2017-01-13 10:06:48 +00:00
|
|
|
TocBuilder & b = backend.builder(type);
|
2017-01-09 16:37:50 +00:00
|
|
|
b.pushItem(pit, str, output_active);
|
2008-06-03 11:33:13 +00:00
|
|
|
// Proceed with the rest of the inset.
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::addToToc(cpit, output_active, utype, backend);
|
2017-01-09 16:37:50 +00:00
|
|
|
b.pop();
|
2008-02-13 13:19:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-16 07:29:01 +00:00
|
|
|
void InsetIndex::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
if (buffer().masterBuffer()->params().use_indices
|
|
|
|
&& !params_.index.empty()
|
|
|
|
&& params_.index != "idx")
|
|
|
|
features.require("splitidx");
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::validate(features);
|
2009-04-16 07:29:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-29 14:48:55 +00:00
|
|
|
string InsetIndex::contextMenuName() const
|
2009-04-16 07:29:01 +00:00
|
|
|
{
|
2011-10-29 14:48:55 +00:00
|
|
|
return "context-index";
|
2009-04-16 07:29:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-22 20:55:13 +00:00
|
|
|
bool InsetIndex::hasSettings() const
|
|
|
|
{
|
|
|
|
return buffer().masterBuffer()->params().use_indices;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// InsetIndexParams
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2009-04-16 07:29:01 +00:00
|
|
|
void InsetIndexParams::write(ostream & os) const
|
|
|
|
{
|
|
|
|
os << ' ';
|
|
|
|
if (!index.empty())
|
|
|
|
os << to_utf8(index);
|
|
|
|
else
|
|
|
|
os << "idx";
|
|
|
|
os << '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetIndexParams::read(Lexer & lex)
|
|
|
|
{
|
|
|
|
if (lex.eatLine())
|
|
|
|
index = lex.getDocString();
|
|
|
|
else
|
|
|
|
index = from_ascii("idx");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-05 00:21:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// InsetPrintIndex
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-11-08 16:10:34 +00:00
|
|
|
InsetPrintIndex::InsetPrintIndex(Buffer * buf, InsetCommandParams const & p)
|
2010-10-29 00:46:21 +00:00
|
|
|
: InsetCommand(buf, p)
|
2000-07-15 23:51:46 +00:00
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2002-05-01 22:17:09 +00:00
|
|
|
|
2008-02-23 22:01:02 +00:00
|
|
|
ParamInfo const & InsetPrintIndex::findInfo(string const & /* cmdName */)
|
2007-10-25 04:13:56 +00:00
|
|
|
{
|
2008-02-23 22:01:02 +00:00
|
|
|
static ParamInfo param_info_;
|
2009-04-16 07:29:01 +00:00
|
|
|
if (param_info_.empty()) {
|
2012-06-30 11:34:49 +00:00
|
|
|
param_info_.add("type", ParamInfo::LATEX_OPTIONAL,
|
2017-01-30 06:44:55 +00:00
|
|
|
ParamInfo::HANDLING_ESCAPE);
|
|
|
|
param_info_.add("name", ParamInfo::LATEX_OPTIONAL,
|
|
|
|
ParamInfo::HANDLING_LATEXIFY);
|
|
|
|
param_info_.add("literal", ParamInfo::LYX_INTERNAL);
|
2009-04-16 07:29:01 +00:00
|
|
|
}
|
2008-02-23 22:01:02 +00:00
|
|
|
return param_info_;
|
2007-10-25 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring InsetPrintIndex::screenLabel() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2009-04-27 06:10:25 +00:00
|
|
|
bool const printall = suffixIs(getCmdName(), '*');
|
|
|
|
bool const multind = buffer().masterBuffer()->params().use_indices;
|
|
|
|
if ((!multind
|
2009-04-16 07:29:01 +00:00
|
|
|
&& getParam("type") == from_ascii("idx"))
|
2009-04-27 06:10:25 +00:00
|
|
|
|| (getParam("type").empty() && !printall))
|
2009-04-16 07:29:01 +00:00
|
|
|
return _("Index");
|
|
|
|
Buffer const & realbuffer = *buffer().masterBuffer();
|
|
|
|
IndicesList const & indiceslist = realbuffer.params().indiceslist();
|
|
|
|
Index const * index = indiceslist.findShortcut(getParam("type"));
|
2009-04-27 06:10:25 +00:00
|
|
|
if (!index && !printall)
|
2009-04-16 07:29:01 +00:00
|
|
|
return _("Unknown index type!");
|
2010-11-12 20:15:25 +00:00
|
|
|
docstring res = printall ? _("All indexes") : index->index();
|
2009-04-27 06:10:25 +00:00
|
|
|
if (!multind)
|
2009-04-16 07:29:01 +00:00
|
|
|
res += " (" + _("non-active") + ")";
|
2009-04-27 06:10:25 +00:00
|
|
|
else if (contains(getCmdName(), "printsubindex"))
|
2009-04-26 11:24:38 +00:00
|
|
|
res += " (" + _("subindex") + ")";
|
2009-04-16 07:29:01 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-27 06:10:25 +00:00
|
|
|
bool InsetPrintIndex::isCompatibleCommand(string const & s)
|
|
|
|
{
|
|
|
|
return s == "printindex" || s == "printsubindex"
|
|
|
|
|| s == "printindex*" || s == "printsubindex*";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-17 14:29:32 +00:00
|
|
|
void InsetPrintIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2009-04-17 14:29:32 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
2009-04-26 11:24:38 +00:00
|
|
|
if (cmd.argument() == from_ascii("toggle-subindex")) {
|
2009-04-27 06:10:25 +00:00
|
|
|
string cmd = getCmdName();
|
|
|
|
if (contains(cmd, "printindex"))
|
|
|
|
cmd = subst(cmd, "printindex", "printsubindex");
|
2009-04-26 11:24:38 +00:00
|
|
|
else
|
2009-04-27 06:10:25 +00:00
|
|
|
cmd = subst(cmd, "printsubindex", "printindex");
|
2010-11-29 09:47:46 +00:00
|
|
|
cur.recordUndo();
|
2009-04-27 06:10:25 +00:00
|
|
|
setCmdName(cmd);
|
|
|
|
break;
|
|
|
|
} else if (cmd.argument() == from_ascii("check-printindex*")) {
|
|
|
|
string cmd = getCmdName();
|
|
|
|
if (suffixIs(cmd, '*'))
|
|
|
|
break;
|
|
|
|
cmd += '*';
|
2010-11-29 09:47:46 +00:00
|
|
|
cur.recordUndo();
|
2009-04-27 06:10:25 +00:00
|
|
|
setParam("type", docstring());
|
|
|
|
setCmdName(cmd);
|
2009-04-26 11:24:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-04-17 14:29:32 +00:00
|
|
|
InsetCommandParams p(INDEX_PRINT_CODE);
|
|
|
|
// FIXME UNICODE
|
2010-10-29 00:25:28 +00:00
|
|
|
InsetCommand::string2params(to_utf8(cmd.argument()), p);
|
2009-04-17 14:29:32 +00:00
|
|
|
if (p.getCmdName().empty()) {
|
2010-07-08 20:04:35 +00:00
|
|
|
cur.noScreenUpdate();
|
2009-04-17 14:29:32 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-06-03 08:31:38 +00:00
|
|
|
cur.recordUndo();
|
2009-04-26 11:24:38 +00:00
|
|
|
setParams(p);
|
2009-04-17 14:29:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
InsetCommand::doDispatch(cur, cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-16 07:29:01 +00:00
|
|
|
bool InsetPrintIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & status) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2009-04-16 07:29:01 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
2009-04-26 11:24:38 +00:00
|
|
|
if (cmd.argument() == from_ascii("toggle-subindex")) {
|
|
|
|
status.setEnabled(buffer().masterBuffer()->params().use_indices);
|
2009-04-27 06:10:25 +00:00
|
|
|
status.setOnOff(contains(getCmdName(), "printsubindex"));
|
|
|
|
return true;
|
|
|
|
} else if (cmd.argument() == from_ascii("check-printindex*")) {
|
|
|
|
status.setEnabled(buffer().masterBuffer()->params().use_indices);
|
|
|
|
status.setOnOff(suffixIs(getCmdName(), '*'));
|
2009-04-26 11:24:38 +00:00
|
|
|
return true;
|
|
|
|
} if (cmd.getArg(0) == "index_print"
|
2009-04-18 16:02:36 +00:00
|
|
|
&& cmd.getArg(1) == "CommandInset") {
|
2009-04-17 14:29:32 +00:00
|
|
|
InsetCommandParams p(INDEX_PRINT_CODE);
|
2010-10-29 00:25:28 +00:00
|
|
|
InsetCommand::string2params(to_utf8(cmd.argument()), p);
|
2009-04-27 06:10:25 +00:00
|
|
|
if (suffixIs(p.getCmdName(), '*')) {
|
|
|
|
status.setEnabled(true);
|
|
|
|
status.setOnOff(false);
|
|
|
|
return true;
|
|
|
|
}
|
2009-04-17 14:29:32 +00:00
|
|
|
Buffer const & realbuffer = *buffer().masterBuffer();
|
|
|
|
IndicesList const & indiceslist =
|
|
|
|
realbuffer.params().indiceslist();
|
|
|
|
Index const * index = indiceslist.findShortcut(p["type"]);
|
|
|
|
status.setEnabled(index != 0);
|
|
|
|
status.setOnOff(p["type"] == getParam("type"));
|
|
|
|
return true;
|
2009-04-18 16:20:08 +00:00
|
|
|
} else
|
|
|
|
return InsetCommand::getStatus(cur, cmd, status);
|
2009-04-17 14:29:32 +00:00
|
|
|
}
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2009-04-22 20:55:13 +00:00
|
|
|
case LFUN_INSET_DIALOG_UPDATE: {
|
2009-04-26 11:24:38 +00:00
|
|
|
status.setEnabled(buffer().masterBuffer()->params().use_indices);
|
2009-04-16 07:29:01 +00:00
|
|
|
return true;
|
2009-04-17 14:29:32 +00:00
|
|
|
}
|
2009-04-16 07:29:01 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return InsetCommand::getStatus(cur, cmd, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-30 06:44:55 +00:00
|
|
|
void InsetPrintIndex::updateBuffer(ParIterator const &, UpdateType)
|
|
|
|
{
|
|
|
|
Index const * index =
|
|
|
|
buffer().masterParams().indiceslist().findShortcut(getParam("type"));
|
|
|
|
if (index)
|
|
|
|
setParam("name", index->index());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-10 20:02:48 +00:00
|
|
|
void InsetPrintIndex::latex(otexstream & os, OutputParams const & runparams_in) const
|
2009-04-16 07:29:01 +00:00
|
|
|
{
|
|
|
|
if (!buffer().masterBuffer()->params().use_indices) {
|
|
|
|
if (getParam("type") == from_ascii("idx"))
|
2016-12-16 09:20:25 +00:00
|
|
|
os << "\\printindex" << termcmd;
|
2011-02-10 20:02:48 +00:00
|
|
|
return;
|
2009-04-16 07:29:01 +00:00
|
|
|
}
|
2010-02-13 13:08:32 +00:00
|
|
|
OutputParams runparams = runparams_in;
|
|
|
|
os << getCommand(runparams);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetPrintIndex::validate(LaTeXFeatures & features) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-11-19 15:34:11 +00:00
|
|
|
features.require("makeidx");
|
2009-04-16 07:29:01 +00:00
|
|
|
if (buffer().masterBuffer()->params().use_indices)
|
|
|
|
features.require("splitidx");
|
2017-01-30 06:44:55 +00:00
|
|
|
InsetCommand::validate(features);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-29 14:48:55 +00:00
|
|
|
string InsetPrintIndex::contextMenuName() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2009-04-16 07:29:01 +00:00
|
|
|
return buffer().masterBuffer()->params().use_indices ?
|
2011-10-29 14:48:55 +00:00
|
|
|
"context-indexprint" : string();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2009-04-17 14:29:32 +00:00
|
|
|
|
2009-04-22 20:55:13 +00:00
|
|
|
bool InsetPrintIndex::hasSettings() const
|
2009-04-17 14:29:32 +00:00
|
|
|
{
|
2009-04-22 20:55:13 +00:00
|
|
|
return buffer().masterBuffer()->params().use_indices;
|
2009-04-17 14:29:32 +00:00
|
|
|
}
|
|
|
|
|
2009-11-21 23:28:20 +00:00
|
|
|
|
2010-01-12 20:44:39 +00:00
|
|
|
namespace {
|
|
|
|
|
2010-01-14 20:01:53 +00:00
|
|
|
void parseItem(docstring & s, bool for_output)
|
|
|
|
{
|
|
|
|
// this does not yet check for escaped things
|
|
|
|
size_type loc = s.find(from_ascii("@"));
|
|
|
|
if (loc != string::npos) {
|
|
|
|
if (for_output)
|
|
|
|
s.erase(0, loc + 1);
|
|
|
|
else
|
|
|
|
s.erase(loc);
|
|
|
|
}
|
|
|
|
loc = s.find(from_ascii("|"));
|
|
|
|
if (loc != string::npos)
|
|
|
|
s.erase(loc);
|
|
|
|
}
|
|
|
|
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2010-01-14 20:01:53 +00:00
|
|
|
void extractSubentries(docstring const & entry, docstring & main,
|
|
|
|
docstring & sub1, docstring & sub2)
|
|
|
|
{
|
|
|
|
if (entry.empty())
|
|
|
|
return;
|
|
|
|
size_type const loc = entry.find(from_ascii(" ! "));
|
|
|
|
if (loc == string::npos)
|
|
|
|
main = entry;
|
|
|
|
else {
|
|
|
|
main = trim(entry.substr(0, loc));
|
|
|
|
size_t const locend = loc + 3;
|
|
|
|
size_type const loc2 = entry.find(from_ascii(" ! "), locend);
|
|
|
|
if (loc2 == string::npos) {
|
|
|
|
sub1 = trim(entry.substr(locend));
|
|
|
|
} else {
|
|
|
|
sub1 = trim(entry.substr(locend, loc2 - locend));
|
|
|
|
sub2 = trim(entry.substr(loc2 + 3));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-12 20:44:39 +00:00
|
|
|
struct IndexEntry
|
2009-06-12 17:23:17 +00:00
|
|
|
{
|
2017-07-03 17:53:14 +00:00
|
|
|
IndexEntry()
|
2010-01-12 20:44:39 +00:00
|
|
|
{}
|
2017-07-03 17:53:14 +00:00
|
|
|
|
|
|
|
IndexEntry(docstring const & s, DocIterator const & d)
|
2010-01-14 20:01:53 +00:00
|
|
|
: dit(d)
|
|
|
|
{
|
|
|
|
extractSubentries(s, main, sub, subsub);
|
|
|
|
parseItem(main, false);
|
|
|
|
parseItem(sub, false);
|
|
|
|
parseItem(subsub, false);
|
|
|
|
}
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2010-01-14 20:01:53 +00:00
|
|
|
bool equal(IndexEntry const & rhs) const
|
|
|
|
{
|
|
|
|
return main == rhs.main && sub == rhs.sub && subsub == rhs.subsub;
|
|
|
|
}
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2010-01-14 20:01:53 +00:00
|
|
|
bool same_sub(IndexEntry const & rhs) const
|
|
|
|
{
|
|
|
|
return main == rhs.main && sub == rhs.sub;
|
|
|
|
}
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2010-01-14 20:01:53 +00:00
|
|
|
bool same_main(IndexEntry const & rhs) const
|
|
|
|
{
|
|
|
|
return main == rhs.main;
|
|
|
|
}
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2010-01-14 20:01:53 +00:00
|
|
|
docstring main;
|
|
|
|
docstring sub;
|
|
|
|
docstring subsub;
|
2010-01-12 20:44:39 +00:00
|
|
|
DocIterator dit;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool operator<(IndexEntry const & lhs, IndexEntry const & rhs)
|
|
|
|
{
|
2012-04-03 21:54:50 +00:00
|
|
|
int comp = compare_no_case(lhs.main, rhs.main);
|
|
|
|
if (comp == 0)
|
|
|
|
comp = compare_no_case(lhs.sub, rhs.sub);
|
|
|
|
if (comp == 0)
|
|
|
|
comp = compare_no_case(lhs.subsub, rhs.subsub);
|
|
|
|
return (comp < 0);
|
2010-01-12 20:44:39 +00:00
|
|
|
}
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2010-01-12 20:44:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
|
|
|
|
{
|
2010-01-14 20:01:53 +00:00
|
|
|
BufferParams const & bp = buffer().masterBuffer()->params();
|
|
|
|
|
|
|
|
// we do not presently support multiple indices, so we refuse to print
|
|
|
|
// anything but the main index, so as not to generate multiple indices.
|
|
|
|
// NOTE Multiple index support would require some work. The reason
|
|
|
|
// is that the TOC does not know about multiple indices. Either it would
|
|
|
|
// need to be told about them (not a bad idea), or else the index entries
|
|
|
|
// would need to be collected differently, say, during validation.
|
|
|
|
if (bp.use_indices && getParam("type") != from_ascii("idx"))
|
|
|
|
return docstring();
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2015-09-01 16:08:35 +00:00
|
|
|
shared_ptr<Toc const> toc = buffer().tocBackend().toc("index");
|
|
|
|
if (toc->empty())
|
2010-01-14 20:01:53 +00:00
|
|
|
return docstring();
|
|
|
|
|
2013-03-25 21:33:54 +00:00
|
|
|
// Collect the index entries in a form we can use them.
|
2015-09-01 16:08:35 +00:00
|
|
|
Toc::const_iterator it = toc->begin();
|
|
|
|
Toc::const_iterator const en = toc->end();
|
2010-01-14 20:01:53 +00:00
|
|
|
vector<IndexEntry> entries;
|
|
|
|
for (; it != en; ++it)
|
2013-03-25 21:33:54 +00:00
|
|
|
if (it->isOutput())
|
|
|
|
entries.push_back(IndexEntry(it->str(), it->dit()));
|
|
|
|
|
|
|
|
if (entries.empty())
|
|
|
|
// not very likely that all the index entries are in notes or
|
|
|
|
// whatever, but....
|
|
|
|
return docstring();
|
|
|
|
|
2010-01-14 20:01:53 +00:00
|
|
|
stable_sort(entries.begin(), entries.end());
|
|
|
|
|
|
|
|
Layout const & lay = bp.documentClass().htmlTOCLayout();
|
2010-01-12 20:44:39 +00:00
|
|
|
string const & tocclass = lay.defaultCSSClass();
|
2013-03-24 13:33:47 +00:00
|
|
|
string const tocattr = "class='index " + tocclass + "'";
|
2010-01-12 20:44:39 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2013-03-23 13:10:01 +00:00
|
|
|
xs << html::StartTag("div", tocattr);
|
2017-07-03 17:53:14 +00:00
|
|
|
xs << html::StartTag(lay.htmltag(), lay.htmlattr())
|
2013-03-23 13:10:01 +00:00
|
|
|
<< translateIfPossible(from_ascii("Index"),
|
|
|
|
op.local_font->language()->lang())
|
2010-01-19 22:08:04 +00:00
|
|
|
<< html::EndTag(lay.htmltag());
|
|
|
|
xs << html::StartTag("ul", "class='main'");
|
2010-01-12 20:44:39 +00:00
|
|
|
Font const dummy;
|
2010-01-12 21:06:55 +00:00
|
|
|
|
2010-01-12 20:44:39 +00:00
|
|
|
vector<IndexEntry>::const_iterator eit = entries.begin();
|
2010-01-12 21:06:55 +00:00
|
|
|
vector<IndexEntry>::const_iterator const een = entries.end();
|
2010-01-14 20:01:53 +00:00
|
|
|
// tracks whether we are already inside a main entry (1),
|
|
|
|
// a sub-entry (2), or a sub-sub-entry (3). see below for the
|
|
|
|
// details.
|
|
|
|
int level = 1;
|
|
|
|
// the last one we saw
|
|
|
|
IndexEntry last;
|
|
|
|
int entry_number = -1;
|
2010-01-12 20:44:39 +00:00
|
|
|
for (; eit != een; ++eit) {
|
|
|
|
Paragraph const & par = eit->dit.innerParagraph();
|
2010-01-14 20:01:53 +00:00
|
|
|
if (entry_number == -1 || !eit->equal(last)) {
|
|
|
|
if (entry_number != -1) {
|
|
|
|
// not the first time through the loop, so
|
|
|
|
// close last entry or entries, depending.
|
|
|
|
if (level == 3) {
|
|
|
|
// close this sub-sub-entry
|
2011-04-01 19:18:25 +00:00
|
|
|
xs << html::EndTag("li") << html::CR();
|
2010-01-14 20:01:53 +00:00
|
|
|
// is this another sub-sub-entry within the same sub-entry?
|
|
|
|
if (!eit->same_sub(last)) {
|
|
|
|
// close this level
|
2011-04-01 19:18:25 +00:00
|
|
|
xs << html::EndTag("ul") << html::CR();
|
2010-01-14 20:01:53 +00:00
|
|
|
level = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// the point of the second test here is that we might get
|
|
|
|
// here two ways: (i) by falling through from above; (ii) because,
|
|
|
|
// though the sub-entry hasn't changed, the sub-sub-entry has,
|
|
|
|
// which means that it is the first sub-sub-entry within this
|
|
|
|
// sub-entry. In that case, we do not want to close anything.
|
|
|
|
if (level == 2 && !eit->same_sub(last)) {
|
2017-07-03 17:53:14 +00:00
|
|
|
// close sub-entry
|
2011-04-01 19:18:25 +00:00
|
|
|
xs << html::EndTag("li") << html::CR();
|
2010-01-14 20:01:53 +00:00
|
|
|
// is this another sub-entry with the same main entry?
|
|
|
|
if (!eit->same_main(last)) {
|
|
|
|
// close this level
|
2011-04-01 19:18:25 +00:00
|
|
|
xs << html::EndTag("ul") << html::CR();
|
2010-01-14 20:01:53 +00:00
|
|
|
level = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// again, we can get here two ways: from above, or because we have
|
|
|
|
// found the first sub-entry. in the latter case, we do not want to
|
|
|
|
// close the entry.
|
|
|
|
if (level == 1 && !eit->same_main(last)) {
|
|
|
|
// close entry
|
2011-04-01 19:18:25 +00:00
|
|
|
xs << html::EndTag("li") << html::CR();
|
2010-01-14 20:01:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// we'll be starting new entries
|
2010-01-12 21:06:55 +00:00
|
|
|
entry_number = 0;
|
2010-01-14 20:01:53 +00:00
|
|
|
|
|
|
|
// We need to use our own stream, since we will have to
|
|
|
|
// modify what we get back.
|
|
|
|
odocstringstream ent;
|
|
|
|
XHTMLStream entstream(ent);
|
2010-01-14 22:24:43 +00:00
|
|
|
OutputParams ours = op;
|
|
|
|
ours.for_toc = true;
|
|
|
|
par.simpleLyXHTMLOnePar(buffer(), entstream, ours, dummy);
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2010-01-14 20:01:53 +00:00
|
|
|
// these will contain XHTML versions of the main entry, etc
|
|
|
|
// remember that everything will already have been escaped,
|
|
|
|
// so we'll need to use NextRaw() during output.
|
|
|
|
docstring main;
|
|
|
|
docstring sub;
|
|
|
|
docstring subsub;
|
|
|
|
extractSubentries(ent.str(), main, sub, subsub);
|
|
|
|
parseItem(main, true);
|
|
|
|
parseItem(sub, true);
|
|
|
|
parseItem(subsub, true);
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2010-01-14 20:01:53 +00:00
|
|
|
if (level == 3) {
|
|
|
|
// another subsubentry
|
2017-07-03 17:53:14 +00:00
|
|
|
xs << html::StartTag("li", "class='subsubentry'")
|
2010-11-24 15:27:36 +00:00
|
|
|
<< XHTMLStream::ESCAPE_NONE << subsub;
|
2010-01-14 20:01:53 +00:00
|
|
|
} else if (level == 2) {
|
2017-07-03 17:53:14 +00:00
|
|
|
// there are two ways we can be here:
|
2010-01-14 20:01:53 +00:00
|
|
|
// (i) we can actually be inside a sub-entry already and be about
|
|
|
|
// to output the first sub-sub-entry. in this case, our sub
|
|
|
|
// and the last sub will be the same.
|
|
|
|
// (ii) we can just have closed a sub-entry, possibly after also
|
|
|
|
// closing a list of sub-sub-entries. here our sub and the last
|
|
|
|
// sub are different.
|
|
|
|
// only in the latter case do we need to output the new sub-entry.
|
|
|
|
// note that in this case, too, though, the sub-entry might already
|
|
|
|
// have a sub-sub-entry.
|
|
|
|
if (eit->sub != last.sub)
|
2017-07-03 17:53:14 +00:00
|
|
|
xs << html::StartTag("li", "class='subentry'")
|
2010-11-24 15:27:36 +00:00
|
|
|
<< XHTMLStream::ESCAPE_NONE << sub;
|
2010-01-14 20:01:53 +00:00
|
|
|
if (!subsub.empty()) {
|
|
|
|
// it's actually a subsubentry, so we need to start that list
|
2011-04-01 19:18:25 +00:00
|
|
|
xs << html::CR()
|
2017-07-03 17:53:14 +00:00
|
|
|
<< html::StartTag("ul", "class='subsubentry'")
|
|
|
|
<< html::StartTag("li", "class='subsubentry'")
|
2010-11-24 15:27:36 +00:00
|
|
|
<< XHTMLStream::ESCAPE_NONE << subsub;
|
2010-01-14 20:01:53 +00:00
|
|
|
level = 3;
|
2017-07-03 17:53:14 +00:00
|
|
|
}
|
2010-01-14 20:01:53 +00:00
|
|
|
} else {
|
2017-07-03 17:53:14 +00:00
|
|
|
// there are also two ways we can be here:
|
2010-01-14 20:01:53 +00:00
|
|
|
// (i) we can actually be inside an entry already and be about
|
|
|
|
// to output the first sub-entry. in this case, our main
|
|
|
|
// and the last main will be the same.
|
|
|
|
// (ii) we can just have closed an entry, possibly after also
|
|
|
|
// closing a list of sub-entries. here our main and the last
|
|
|
|
// main are different.
|
|
|
|
// only in the latter case do we need to output the new main entry.
|
|
|
|
// note that in this case, too, though, the main entry might already
|
|
|
|
// have a sub-entry, or even a sub-sub-entry.
|
|
|
|
if (eit->main != last.main)
|
2010-01-19 22:08:04 +00:00
|
|
|
xs << html::StartTag("li", "class='main'") << main;
|
2010-01-14 20:01:53 +00:00
|
|
|
if (!sub.empty()) {
|
|
|
|
// there's a sub-entry, too
|
2011-04-01 19:18:25 +00:00
|
|
|
xs << html::CR()
|
2017-07-03 17:53:14 +00:00
|
|
|
<< html::StartTag("ul", "class='subentry'")
|
|
|
|
<< html::StartTag("li", "class='subentry'")
|
2010-11-24 15:27:36 +00:00
|
|
|
<< XHTMLStream::ESCAPE_NONE << sub;
|
2010-01-14 20:01:53 +00:00
|
|
|
level = 2;
|
|
|
|
if (!subsub.empty()) {
|
|
|
|
// and a sub-sub-entry
|
2011-04-01 19:18:25 +00:00
|
|
|
xs << html::CR()
|
2017-07-03 17:53:14 +00:00
|
|
|
<< html::StartTag("ul", "class='subsubentry'")
|
|
|
|
<< html::StartTag("li", "class='subsubentry'")
|
2010-11-24 15:27:36 +00:00
|
|
|
<< XHTMLStream::ESCAPE_NONE << subsub;
|
2010-01-14 20:01:53 +00:00
|
|
|
level = 3;
|
|
|
|
}
|
2017-07-03 17:53:14 +00:00
|
|
|
}
|
2010-01-14 20:01:53 +00:00
|
|
|
}
|
2010-01-12 21:06:55 +00:00
|
|
|
}
|
2010-01-14 20:01:53 +00:00
|
|
|
// finally, then, we can output the index link itself
|
2010-01-12 20:44:39 +00:00
|
|
|
string const parattr = "href='#" + par.magicLabel() + "'";
|
2010-01-14 20:01:53 +00:00
|
|
|
xs << (entry_number == 0 ? ":" : ",");
|
2010-01-19 22:08:04 +00:00
|
|
|
xs << " " << html::StartTag("a", parattr)
|
|
|
|
<< ++entry_number << html::EndTag("a");
|
2010-01-14 20:01:53 +00:00
|
|
|
last = *eit;
|
|
|
|
}
|
|
|
|
// now we have to close all the open levels
|
|
|
|
while (level > 0) {
|
2011-04-01 19:18:25 +00:00
|
|
|
xs << html::EndTag("li") << html::EndTag("ul") << html::CR();
|
2010-01-14 20:01:53 +00:00
|
|
|
--level;
|
2010-01-12 20:44:39 +00:00
|
|
|
}
|
2011-04-01 19:18:25 +00:00
|
|
|
xs << html::EndTag("div") << html::CR();
|
2010-01-12 20:44:39 +00:00
|
|
|
return ods.str();
|
2009-06-12 17:23:17 +00:00
|
|
|
}
|
2009-04-17 14:29:32 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|