#include "Buffer.h"
#include "BufferParams.h"
+#include "BufferView.h"
#include "ColorSet.h"
#include "DispatchResult.h"
#include "Encoding.h"
#include "LaTeXFeatures.h"
#include "Lexer.h"
#include "MetricsInfo.h"
+#include "output_latex.h"
#include "sgml.h"
#include "TocBackend.h"
///////////////////////////////////////////////////////////////////////
-InsetIndex::InsetIndex(Buffer const & buf, InsetIndexParams const & params)
+InsetIndex::InsetIndex(Buffer * buf, InsetIndexParams const & params)
: InsetCollapsable(buf), params_(params)
{}
int InsetIndex::latex(odocstream & os,
- OutputParams const & runparams) const
+ OutputParams const & runparams_in) const
{
+ OutputParams runparams(runparams_in);
+ runparams.inIndexEntry = true;
+
if (buffer().masterBuffer()->params().use_indices && !params_.index.empty()
&& params_.index != "idx") {
os << "\\sindex[";
}
+docstring InsetIndex::xhtml(XHTMLStream &, OutputParams const &) const
+{
+ return docstring();
+}
+
+
+bool InsetIndex::showInsetDialog(BufferView * bv) const
+{
+ bv->showDialog("index", params2string(params_),
+ const_cast<InsetIndex *>(this));
+ return true;
+}
+
+
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;
}
+ InsetIndexParams params;
+ InsetIndex::string2params(to_utf8(cmd.argument()), params);
+ params_.index = params.index;
+ break;
}
+ case LFUN_INSET_DIALOG_UPDATE:
+ cur.bv().updateDialog("index", params2string(params_));
+ break;
+
default:
InsetCollapsable::doDispatch(cur, cmd);
break;
from_utf8(cmd.getArg(1)) == params_.index);
return true;
}
+ flag.setEnabled(true);
+ return true;
+
+ case LFUN_INSET_DIALOG_UPDATE: {
+ Buffer const & realbuffer = *buffer().masterBuffer();
+ flag.setEnabled(realbuffer.params().use_indices);
+ return true;
+ }
default:
return InsetCollapsable::getStatus(cur, cmd, flag);
}
-docstring const InsetIndex::buttonLabel(BufferView const & bv) const
+ColorCode InsetIndex::labelColor() const
{
- docstring s = _("Idx");
- if (decoration() == InsetLayout::CLASSIC)
- return isOpen(bv) ? s : getNewLabel(s);
- else
- return getNewLabel(s);
+ if (params_.index.empty() || params_.index == from_ascii("idx"))
+ return InsetCollapsable::labelColor();
+ // FIXME UNICODE
+ ColorCode c = lcolor.getFromLyXName(to_utf8(params_.index));
+ if (c == Color_none)
+ c = InsetCollapsable::labelColor();
+ return c;
}
odocstringstream ods;
InsetText::plaintext(ods, rp);
tip += ods.str();
- // shorten it if necessary
- if (tip.size() > 200)
- tip = tip.substr(0, 200) + "...";
- return tip;
+ return wrapParas(tip);
}
}
+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);
+}
+
+
void InsetIndex::addToToc(DocIterator const & cpit)
{
DocIterator pit = cpit;
}
+bool InsetIndex::hasSettings() const
+{
+ return buffer().masterBuffer()->params().use_indices;
+}
+
+
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// InsetIndexParams
+//
+///////////////////////////////////////////////////////////////////////
+
+
void InsetIndexParams::write(ostream & os) const
{
os << ' ';
//
///////////////////////////////////////////////////////////////////////
-InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
- : InsetCommand(p, "index_print")
+InsetPrintIndex::InsetPrintIndex(Buffer * buf, InsetCommandParams const & p)
+ : InsetCommand(buf, p, "index_print")
{}
docstring InsetPrintIndex::screenLabel() const
{
- if ((!buffer().masterBuffer()->params().use_indices
+ bool const printall = suffixIs(getCmdName(), '*');
+ bool const multind = buffer().masterBuffer()->params().use_indices;
+ if ((!multind
&& getParam("type") == from_ascii("idx"))
- || getParam("type").empty())
+ || (getParam("type").empty() && !printall))
return _("Index");
Buffer const & realbuffer = *buffer().masterBuffer();
IndicesList const & indiceslist = realbuffer.params().indiceslist();
Index const * index = indiceslist.findShortcut(getParam("type"));
- if (!index)
+ if (!index && !printall)
return _("Unknown index type!");
- docstring res = index->index();
- if (!buffer().masterBuffer()->params().use_indices)
+ docstring res = printall ? _("All indices") : index->index();
+ if (!multind)
res += " (" + _("non-active") + ")";
+ else if (contains(getCmdName(), "printsubindex"))
+ res += " (" + _("subindex") + ")";
return res;
}
+bool InsetPrintIndex::isCompatibleCommand(string const & s)
+{
+ return s == "printindex" || s == "printsubindex"
+ || s == "printindex*" || s == "printsubindex*";
+}
+
+
+void InsetPrintIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
+{
+ switch (cmd.action) {
+
+ case LFUN_INSET_MODIFY: {
+ if (cmd.argument() == from_ascii("toggle-subindex")) {
+ string cmd = getCmdName();
+ if (contains(cmd, "printindex"))
+ cmd = subst(cmd, "printindex", "printsubindex");
+ else
+ cmd = subst(cmd, "printsubindex", "printindex");
+ setCmdName(cmd);
+ break;
+ } else if (cmd.argument() == from_ascii("check-printindex*")) {
+ string cmd = getCmdName();
+ if (suffixIs(cmd, '*'))
+ break;
+ cmd += '*';
+ setParam("type", docstring());
+ setCmdName(cmd);
+ break;
+ }
+ InsetCommandParams p(INDEX_PRINT_CODE);
+ // FIXME UNICODE
+ InsetCommand::string2params("index_print",
+ to_utf8(cmd.argument()), p);
+ if (p.getCmdName().empty()) {
+ cur.noUpdate();
+ break;
+ }
+ setParams(p);
+ break;
+ }
+
+ default:
+ InsetCommand::doDispatch(cur, cmd);
+ break;
+ }
+}
+
+
bool InsetPrintIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & status) const
{
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
- 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"));
+ if (cmd.argument() == from_ascii("toggle-subindex")) {
+ status.setEnabled(buffer().masterBuffer()->params().use_indices);
+ 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(), '*'));
+ return true;
+ } if (cmd.getArg(0) == "index_print"
+ && cmd.getArg(1) == "CommandInset") {
+ InsetCommandParams p(INDEX_PRINT_CODE);
+ InsetCommand::string2params("index_print",
+ to_utf8(cmd.argument()), p);
+ if (suffixIs(p.getCmdName(), '*')) {
+ status.setEnabled(true);
+ status.setOnOff(false);
+ return true;
+ }
+ 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;
+ } else
+ return InsetCommand::getStatus(cur, cmd, status);
+ }
+
+ case LFUN_INSET_DIALOG_UPDATE: {
+ status.setEnabled(buffer().masterBuffer()->params().use_indices);
return true;
- }
+ }
default:
return InsetCommand::getStatus(cur, cmd, status);
from_ascii("context-indexprint") : docstring();
}
+
+bool InsetPrintIndex::hasSettings() const
+{
+ return buffer().masterBuffer()->params().use_indices;
+}
+
+
+docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const &) const
+{
+ return docstring();
+}
+
} // namespace lyx