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"
|
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"
|
2003-09-05 09:01:27 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2009-04-16 07:29:01 +00:00
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "MetricsInfo.h"
|
2004-10-25 00:26:05 +00:00
|
|
|
#include "sgml.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"
|
|
|
|
|
2007-11-06 21:45:24 +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-04-16 07:29:01 +00:00
|
|
|
InsetIndex::InsetIndex(Buffer const & buf, InsetIndexParams const & params)
|
|
|
|
: InsetCollapsable(buf), params_(params)
|
2007-11-02 17:47:51 +00:00
|
|
|
{}
|
2007-10-03 13:38:19 +00:00
|
|
|
|
|
|
|
|
2008-04-26 14:24:28 +00:00
|
|
|
int InsetIndex::latex(odocstream & os,
|
2008-07-14 08:20:24 +00:00
|
|
|
OutputParams const & runparams) const
|
2008-04-26 14:24:28 +00:00
|
|
|
{
|
2009-04-16 07:29:01 +00:00
|
|
|
if (buffer().masterBuffer()->params().use_indices && !params_.index.empty()
|
|
|
|
&& params_.index != "idx") {
|
|
|
|
os << "\\sindex[";
|
|
|
|
os << params_.index;
|
|
|
|
os << "]{";
|
|
|
|
} else {
|
|
|
|
os << "\\index";
|
|
|
|
os << '{';
|
|
|
|
}
|
2008-10-19 11:28:23 +00:00
|
|
|
int i = 0;
|
2008-08-05 14:25:32 +00:00
|
|
|
|
|
|
|
// get contents of InsetText as LaTeX and plaintext
|
|
|
|
odocstringstream ourlatex;
|
|
|
|
InsetText::latex(ourlatex, runparams);
|
|
|
|
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)
|
2008-08-05 14:25:32 +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.
|
|
|
|
docstring spart2;
|
2008-09-15 16:20:12 +00:00
|
|
|
for (size_t n = 0; n < spart.size(); ++n) {
|
2008-09-15 14:19:00 +00:00
|
|
|
try {
|
|
|
|
spart2 += runparams.encoding->latexChar(spart[n]);
|
|
|
|
} catch (EncodingException & /* e */) {
|
|
|
|
LYXERR0("Uncodable character in index entry. Sorting might be wrong!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (spart != spart2 && !runparams.dryrun) {
|
|
|
|
// 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 =
|
2008-09-15 14:19:00 +00:00
|
|
|
subst(spart2, 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 "|"
|
2008-10-19 11:28:23 +00:00
|
|
|
if (!cmd.empty())
|
2008-08-05 14:25:32 +00:00
|
|
|
os << "|" << cmd;
|
2008-04-26 14:24:28 +00:00
|
|
|
os << '}';
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
if (cmd.getArg(0) == "changetype") {
|
|
|
|
params_.index = from_utf8(cmd.getArg(1));
|
|
|
|
setLayout(cur.buffer()->params());
|
|
|
|
break;
|
|
|
|
}
|
2009-04-17 09:22:44 +00:00
|
|
|
InsetIndexParams params;
|
|
|
|
InsetIndex::string2params(to_utf8(cmd.argument()), params);
|
|
|
|
params_.index = params.index;
|
|
|
|
setLayout(cur.buffer()->params());
|
|
|
|
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:
|
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & flag) const
|
|
|
|
{
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2009-04-17 09:22:44 +00:00
|
|
|
flag.setEnabled(true);
|
|
|
|
return true;
|
|
|
|
|
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:
|
|
|
|
return InsetCollapsable::getStatus(cur, cmd, flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
docstring const InsetIndex::buttonLabel(BufferView const & bv) const
|
|
|
|
{
|
|
|
|
docstring s = _("Idx");
|
|
|
|
if (decoration() == InsetLayout::CLASSIC)
|
|
|
|
return isOpen(bv) ? s : getNewLabel(s);
|
|
|
|
else
|
|
|
|
return getNewLabel(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 += ": ";
|
|
|
|
OutputParams rp(&buffer().params().encoding());
|
|
|
|
odocstringstream ods;
|
|
|
|
InsetText::plaintext(ods, rp);
|
|
|
|
tip += ods.str();
|
|
|
|
// shorten it if necessary
|
|
|
|
if (tip.size() > 200)
|
|
|
|
tip = tip.substr(0, 200) + "...";
|
|
|
|
return tip;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetIndex::write(ostream & os) const
|
2007-10-03 13:38:19 +00:00
|
|
|
{
|
2009-04-16 07:29:01 +00:00
|
|
|
os << to_utf8(name());
|
|
|
|
params_.write(os);
|
2008-02-27 20:43:16 +00:00
|
|
|
InsetCollapsable::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);
|
|
|
|
InsetCollapsable::read(lex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-13 08:23:44 +00:00
|
|
|
void InsetIndex::addToToc(DocIterator const & cpit)
|
2008-02-13 13:19:39 +00:00
|
|
|
{
|
2008-05-13 08:23:44 +00:00
|
|
|
DocIterator pit = cpit;
|
|
|
|
pit.push_back(CursorSlice(*this));
|
2008-11-07 13:06:20 +00:00
|
|
|
docstring const item = text().asString(0, 1, AS_STR_LABEL | AS_STR_INSETS);
|
|
|
|
buffer().tocBackend().toc("index").push_back(TocItem(pit, 0, item));
|
2008-06-03 11:33:13 +00:00
|
|
|
// Proceed with the rest of the inset.
|
|
|
|
InsetCollapsable::addToToc(cpit);
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
docstring InsetIndex::contextMenu(BufferView const &, int, int) const
|
|
|
|
{
|
|
|
|
return from_ascii("context-index");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
|
2009-04-16 07:29:01 +00:00
|
|
|
: InsetCommand(p, "index_print")
|
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()) {
|
|
|
|
param_info_.add("type", ParamInfo::LATEX_OPTIONAL);
|
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("name", ParamInfo::LATEX_REQUIRED);
|
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-16 07:29:01 +00:00
|
|
|
if ((!buffer().masterBuffer()->params().use_indices
|
|
|
|
&& getParam("type") == from_ascii("idx"))
|
|
|
|
|| getParam("type").empty())
|
|
|
|
return _("Index");
|
|
|
|
Buffer const & realbuffer = *buffer().masterBuffer();
|
|
|
|
IndicesList const & indiceslist = realbuffer.params().indiceslist();
|
|
|
|
Index const * index = indiceslist.findShortcut(getParam("type"));
|
|
|
|
if (!index)
|
|
|
|
return _("Unknown index type!");
|
|
|
|
docstring res = index->index();
|
|
|
|
if (!buffer().masterBuffer()->params().use_indices)
|
|
|
|
res += " (" + _("non-active") + ")";
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-17 14:29:32 +00:00
|
|
|
void InsetPrintIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|
|
|
{
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
InsetCommandParams p(INDEX_PRINT_CODE);
|
|
|
|
// FIXME UNICODE
|
|
|
|
InsetCommand::string2params("index_print",
|
|
|
|
to_utf8(cmd.argument()), p);
|
|
|
|
if (p.getCmdName().empty()) {
|
|
|
|
cur.noUpdate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
setParam("type", p["type"]);
|
|
|
|
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
|
|
|
|
{
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
2009-04-17 14:29:32 +00:00
|
|
|
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);
|
|
|
|
InsetCommand::string2params("index_print",
|
|
|
|
to_utf8(cmd.argument()), p);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-04-22 20:55:13 +00:00
|
|
|
case LFUN_INSET_DIALOG_UPDATE: {
|
2009-04-16 07:29:01 +00:00
|
|
|
Buffer const & realbuffer = *buffer().masterBuffer();
|
2009-04-17 14:29:32 +00:00
|
|
|
status.setEnabled(realbuffer.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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetPrintIndex::latex(odocstream & os, OutputParams const &) const
|
|
|
|
{
|
|
|
|
if (!buffer().masterBuffer()->params().use_indices) {
|
|
|
|
if (getParam("type") == from_ascii("idx"))
|
|
|
|
os << "\\printindex{}";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
os << getCommand();
|
|
|
|
return 0;
|
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");
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-16 07:29:01 +00:00
|
|
|
docstring InsetPrintIndex::contextMenu(BufferView const &, int, int) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2009-04-16 07:29:01 +00:00
|
|
|
return buffer().masterBuffer()->params().use_indices ?
|
|
|
|
from_ascii("context-indexprint") : docstring();
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|