From 0bd5c5fca866a53c4bf319b41afbb9b655d8e108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Sun, 26 Apr 2009 11:24:38 +0000 Subject: [PATCH] * Add support for splitindex's \printsubindex command. File format change. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29409 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/FORMAT | 4 ++ lib/lyx2lyx/lyx_2_0.py | 32 +++++++++++++++- lib/ui/stdcontext.inc | 2 + src/Buffer.cpp | 2 +- src/frontends/qt4/GuiPrintindex.cpp | 7 ++++ src/frontends/qt4/ui/PrintindexUi.ui | 56 ++++++++++++++++------------ src/insets/InsetIndex.cpp | 20 ++++++++-- src/insets/InsetIndex.h | 4 +- 8 files changed, 95 insertions(+), 32 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index 541522062a..107b1ff762 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,6 +1,10 @@ LyX file-format changes ----------------------- +2009-04-26 Jürgen Spitzmüller + * Format incremented to 353: support for splitindex's + printsubindex. + 2009-04-15 Jürgen Spitzmüller * Format incremented to 352: splitindex support. diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index b1f5cd5d25..a811b531ad 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -554,6 +554,32 @@ def convert_splitindex(document): i = i + 1 +def revert_subindex(document): + " Reverts \\printsubindex CommandInset types " + i = find_token(document.header, '\\use_indices', 0) + if i == -1: + document.warning("Malformed LyX document: Missing \\use_indices.") + return + indices = get_value(document.header, "\\use_indices", i) + i = 0 + while True: + i = find_token(document.body, "\\begin_inset CommandInset index_print", i) + if i == -1: + return + k = find_end_of_inset(document.body, i) + ctype = get_value(document.body, 'LatexCommand', i, k) + if ctype != "printsubindex": + i = i + 1 + continue + ptype = get_value(document.body, 'type', i, k).strip('"') + if indices == "false": + del document.body[i:k+1] + else: + subst = [put_cmd_in_ert("\\printsubindex[" + ptype + "]{}")] + document.body[i:k+1] = subst + i = i + 1 + + ## # Conversion hub # @@ -565,10 +591,12 @@ convert = [[346, []], [349, []], [350, []], [351, []], - [352, [convert_splitindex]] + [352, [convert_splitindex]], + [353, []] ] -revert = [[351, [revert_splitindex]], +revert = [[352, [revert_subindex]], + [351, [revert_splitindex]], [350, [revert_backgroundcolor]], [349, [revert_outputformat]], [348, [revert_xetex]], diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc index 28f233f96b..a320fa48bb 100644 --- a/lib/ui/stdcontext.inc +++ b/lib/ui/stdcontext.inc @@ -522,6 +522,8 @@ Menuset Menu "context-indexprint" IndicesListsContext Separator + Item "Subindex|b" "next-inset-modify toggle-subindex" + Separator OptItem "Settings...|S" "inset-settings" End diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 840de8cd68..ff1451a588 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -125,7 +125,7 @@ namespace { // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -int const LYX_FORMAT = 352; // jspitzm: splitindex support +int const LYX_FORMAT = 353; // jspitzm: subindex support typedef map DepClean; typedef map > RefCache; diff --git a/src/frontends/qt4/GuiPrintindex.cpp b/src/frontends/qt4/GuiPrintindex.cpp index 53278497e0..a175f8b651 100644 --- a/src/frontends/qt4/GuiPrintindex.cpp +++ b/src/frontends/qt4/GuiPrintindex.cpp @@ -39,6 +39,7 @@ GuiPrintindex::GuiPrintindex(GuiView & lv) connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); connect(cancelPB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(indicesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); + connect(subindexCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); bc().setOK(okPB); @@ -69,6 +70,7 @@ void GuiPrintindex::updateContents() int const pos = indicesCO->findData(toqstr(cur_index)); indicesCO->setCurrentIndex(pos); + subindexCB->setChecked(params_.getCmdName() == "printsubindex"); } @@ -76,6 +78,10 @@ void GuiPrintindex::applyView() { QString const index = indicesCO->itemData( indicesCO->currentIndex()).toString(); + if (subindexCB->isChecked()) + params_.setCmdName("printsubindex"); + else + params_.setCmdName("printindex"); params_["type"] = qstring_to_ucs4(index); } @@ -83,6 +89,7 @@ void GuiPrintindex::applyView() void GuiPrintindex::paramsToDialog(InsetCommandParams const & /*icp*/) { int const pos = indicesCO->findData(toqstr(params_["type"])); + subindexCB->setChecked(params_.getCmdName() == "printsubindex"); indicesCO->setCurrentIndex(pos); bc().setValid(isValid()); } diff --git a/src/frontends/qt4/ui/PrintindexUi.ui b/src/frontends/qt4/ui/PrintindexUi.ui index 62b9506fd6..3cc6d07bb6 100644 --- a/src/frontends/qt4/ui/PrintindexUi.ui +++ b/src/frontends/qt4/ui/PrintindexUi.ui @@ -6,7 +6,7 @@ 0 0 262 - 108 + 130 @@ -22,20 +22,17 @@ 6 - - - - Qt::Horizontal + + + + &Cancel - - - 71 - 20 - + + true - + - + &OK @@ -45,6 +42,29 @@ + + + + Qt::Horizontal + + + + 78 + 29 + + + + + + + + Check if this index should be part (e.g., a section) of the former one. + + + &Subindex + + + @@ -66,22 +86,12 @@ - Select the index this entry should be listed in. + Select the index that shall be printed at this place of the document. - - - - &Cancel - - - true - - - diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index c74dcd7676..d18c407dc9 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -410,6 +410,8 @@ docstring InsetPrintIndex::screenLabel() const docstring res = index->index(); if (!buffer().masterBuffer()->params().use_indices) res += " (" + _("non-active") + ")"; + else if (getCmdName() == "printsubindex") + res += " (" + _("subindex") + ")"; return res; } @@ -419,6 +421,13 @@ void InsetPrintIndex::doDispatch(Cursor & cur, FuncRequest & cmd) switch (cmd.action) { case LFUN_INSET_MODIFY: { + if (cmd.argument() == from_ascii("toggle-subindex")) { + if (getCmdName() == "printindex") + setCmdName("printsubindex"); + else + setCmdName("printindex"); + break; + } InsetCommandParams p(INDEX_PRINT_CODE); // FIXME UNICODE InsetCommand::string2params("index_print", @@ -427,7 +436,7 @@ void InsetPrintIndex::doDispatch(Cursor & cur, FuncRequest & cmd) cur.noUpdate(); break; } - setParam("type", p["type"]); + setParams(p); break; } @@ -444,7 +453,11 @@ bool InsetPrintIndex::getStatus(Cursor & cur, FuncRequest const & cmd, switch (cmd.action) { case LFUN_INSET_MODIFY: { - if (cmd.getArg(0) == "index_print" + if (cmd.argument() == from_ascii("toggle-subindex")) { + status.setEnabled(buffer().masterBuffer()->params().use_indices); + status.setOnOff(getCmdName() == "printsubindex"); + return true; + } if (cmd.getArg(0) == "index_print" && cmd.getArg(1) == "CommandInset") { InsetCommandParams p(INDEX_PRINT_CODE); InsetCommand::string2params("index_print", @@ -461,8 +474,7 @@ bool InsetPrintIndex::getStatus(Cursor & cur, FuncRequest const & cmd, } case LFUN_INSET_DIALOG_UPDATE: { - Buffer const & realbuffer = *buffer().masterBuffer(); - status.setEnabled(realbuffer.params().use_indices); + status.setEnabled(buffer().masterBuffer()->params().use_indices); return true; } diff --git a/src/insets/InsetIndex.h b/src/insets/InsetIndex.h index 69d1a3d23e..83bf4beaa8 100644 --- a/src/insets/InsetIndex.h +++ b/src/insets/InsetIndex.h @@ -98,8 +98,8 @@ public: /// static std::string defaultCommand() { return "printindex"; }; /// - static bool isCompatibleCommand(std::string const & s) - { return s == "printindex"; } + static bool isCompatibleCommand(std::string const & s) + { return s == "printindex" || s == "printsubindex"; } /// int latex(odocstream &, OutputParams const &) const; ///