From e9cbe2f80f766d3a31891840915e2dc311ac516d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Fri, 22 May 2009 16:26:15 +0000 Subject: [PATCH] A GUI for nomencl settings. Adds the possibility to enter a custom length. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29779 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/FORMAT | 6 ++- development/scons/scons_manifest.py | 3 ++ lib/lyx2lyx/lyx_2_0.py | 25 ++++++++++- lib/ui/stdcontext.inc | 10 ++++- src/Buffer.cpp | 2 +- src/LyXAction.cpp | 6 +-- src/LyXFunc.cpp | 1 + src/Text3.cpp | 4 +- src/frontends/qt4/GuiPrintindex.cpp | 1 + src/frontends/qt4/GuiView.cpp | 9 ++-- src/frontends/qt4/Makefile.am | 3 ++ src/insets/InsetNomencl.cpp | 65 ++++++++++++++++++++++++++++- src/insets/InsetNomencl.h | 9 ++++ 13 files changed, 130 insertions(+), 14 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index 3e819429e9..7aa3453910 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,7 +1,11 @@ LyX file-format changes ----------------------- -2009-04-26 Jürgen Spitzmüller +2009-05-22 Jürgen Spitzmüller + * Format incremented to 360: param width for nomencl_print + CommandInset. + +2009-05-22 Jürgen Spitzmüller * Format incremented to 359: param set_width for nomencl_print CommandInset. diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index bba4c29cdf..fe384078d1 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -746,6 +746,7 @@ src_frontends_qt4_header_files = Split(''' GuiPrefs.h GuiPrint.h GuiPrintindex.h + GuiPrintNomencl.h GuiRef.h GuiSearch.h GuiSelection.h @@ -841,6 +842,7 @@ src_frontends_qt4_files = Split(''' GuiPrefs.cpp GuiPrint.cpp GuiPrintindex.cpp + GuiPrintNomencl.cpp GuiRef.cpp GuiSearch.cpp GuiSelection.cpp @@ -953,6 +955,7 @@ src_frontends_qt4_ui_files = Split(''' PrefsUi.ui PrintUi.ui PrintindexUi.ui + PrintNomenclUi.ui RefUi.ui SearchUi.ui SendtoUi.ui diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index bd4a4778ea..2d562a373f 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -688,6 +688,25 @@ def revert_nomencl_width(document): i = i + 1 +def revert_nomencl_cwidth(document): + " Remove width param from nomencl_print " + i = 0 + while True: + i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i) + if i == -1: + break + j = find_end_of_inset(document.body, i) + l = find_token(document.body, "width", i, j) + if l == -1: + document.warning("Can't find width option for nomencl_print!") + i = j + continue + width = get_value(document.body, "width", i, j).strip('"') + del document.body[l] + add_to_preamble(document, ["\\setlength{\\nomlabelwidth}{" + width + "}"]) + i = i + 1 + + ## # Conversion hub # @@ -706,10 +725,12 @@ convert = [[346, []], [356, []], [357, []], [358, []], - [359, [convert_nomencl_width]] + [359, [convert_nomencl_width]], + [360, []] ] -revert = [[358, [revert_nomencl_width]], +revert = [[359, [revert_nomencl_cwidth]], + [358, [revert_nomencl_width]], [357, [revert_custom_processors]], [356, [revert_ulinelatex]], [355, [revert_uulinewave]], diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc index 4b5bc7ca6b..5794c52b90 100644 --- a/lib/ui/stdcontext.inc +++ b/lib/ui/stdcontext.inc @@ -43,7 +43,7 @@ Menuset Item "Eqnarray Environment|E" "math-mutate eqnarray" Submenu "AMS Environment|A" "ams_environment" Separator - OptItem "Number whole Formula|N" "math-number-toggle" + OptItem "Number whole Formula|N" "math-number-toggle" OptItem "Number this Line|u" "math-number-line-toggle" OptItem "Equation Label|L" "label-insert" OptItem "Copy as Reference|R" "copy-label-as-reference" @@ -534,6 +534,14 @@ Menuset OptItem "Settings...|S" "inset-settings" End +# +# Nomencl List context menu +# + + Menu "context-nomenclprint" + OptItem "Settings...|S" "inset-settings" + End + # # Toc Changes context menu diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 8dca38038d..d9d9547df5 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 = 359; // jspitzm: nomencl auto calculation +int const LYX_FORMAT = 360; // jspitzm: nomencl custom width typedef map DepClean; typedef map > RefCache; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 40322b3edb..a45643eb1d 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -2529,9 +2529,9 @@ void LyXAction::init() * \li Params: : aboutlyx|bibitem|bibtex|box|branch|changes|character|citation|\n document|errorlist|ert|external|file|findreplace|findreplaceadv|float|graphics|\n href|include|index|index_print|info|label|listings|log|mathdelimiter|\n - mathmatrix|mathspace|nomenclature|note|paragraph|phantom|prefs|print|ref|\n - sendto|space|spellchecker|symbols|tabular|tabularcreate|thesaurus|texinfo|\n - toc|view-source|vspace|wrap| \n + mathmatrix|mathspace|nomenclature|note|paragraph|phantom|prefs|print|\n + nomencl_print|ref|sendto|space|spellchecker|symbols|tabular|tabularcreate|\n + thesaurus|texinfo|toc|view-source|vspace|wrap| \n : latexlog|vclog \n : data, usually settings for the given dialog. Use debug mode for the details. diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 77802907b9..1cd5375e20 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -1129,6 +1129,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) case INDEX_CODE: case LABEL_CODE: case NOMENCL_CODE: + case NOMENCL_PRINT_CODE: case REF_CODE: case TOC_CODE: case HYPERLINK_CODE: { diff --git a/src/Text3.cpp b/src/Text3.cpp index 5121b5808a..c8e4a4b1ea 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -1630,7 +1630,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) dispatch(cur, fr); break; } - + case LFUN_NOMENCL_PRINT: case LFUN_TOC_INSERT: case LFUN_LINE_INSERT: @@ -2127,6 +2127,8 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, code = INDEX_PRINT_CODE; else if (cmd.argument() == "nomenclature") code = NOMENCL_CODE; + else if (cmd.argument() == "nomencl_print") + code = NOMENCL_PRINT_CODE; else if (cmd.argument() == "label") code = LABEL_CODE; else if (cmd.argument() == "note") diff --git a/src/frontends/qt4/GuiPrintindex.cpp b/src/frontends/qt4/GuiPrintindex.cpp index 3542ebfdef..c639fd9e47 100644 --- a/src/frontends/qt4/GuiPrintindex.cpp +++ b/src/frontends/qt4/GuiPrintindex.cpp @@ -114,6 +114,7 @@ bool GuiPrintindex::initialiseParams(string const & data) // The name passed with LFUN_INSET_APPLY is also the name // used to identify the mailer. InsetCommand::string2params("index_print", data, params_); + paramsToDialog(params_); return true; } diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 044ec2beb2..a2f86c26fa 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -2420,9 +2420,9 @@ char const * const dialognames[] = { "findreplaceadv", "float", "graphics", "href", "include", "index", "index_print", "info", "listings", "label", "log", "mathdelimiter", "mathmatrix", "mathspace", "nomenclature", "note", "paragraph", "phantom", -"prefs", "print", "ref", "sendto", "space", "spellchecker", "symbols", -"tabular", "tabularcreate", "thesaurus", "texinfo", "toc", "view-source", -"vspace", "wrap" }; +"prefs", "print", "nomencl_print", "ref", "sendto", "space", "spellchecker", +"symbols", "tabular", "tabularcreate", "thesaurus", "texinfo", "toc", +"view-source", "vspace", "wrap" }; char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); @@ -2611,6 +2611,7 @@ Dialog * createGuiPhantom(GuiView & lv); Dialog * createGuiPreferences(GuiView & lv); Dialog * createGuiPrint(GuiView & lv); Dialog * createGuiPrintindex(GuiView & lv); +Dialog * createGuiPrintNomencl(GuiView & lv); Dialog * createGuiRef(GuiView & lv); Dialog * createGuiSearch(GuiView & lv); Dialog * createGuiSearchAdv(GuiView & lv); @@ -2696,6 +2697,8 @@ Dialog * GuiView::build(string const & name) return createGuiPreferences(*this); if (name == "print") return createGuiPrint(*this); + if (name == "nomencl_print") + return createGuiPrintNomencl(*this); if (name == "ref") return createGuiRef(*this); if (name == "sendto") diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 99319b1691..634e336ce8 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -106,6 +106,7 @@ SOURCEFILES = \ GuiPrefs.cpp \ GuiPrint.cpp \ GuiPrintindex.cpp \ + GuiPrintNomencl.cpp \ GuiRef.cpp \ GuiSearch.cpp \ GuiSelection.cpp \ @@ -203,6 +204,7 @@ MOCHEADER = \ GuiPrefs.h \ GuiPrint.h \ GuiPrintindex.h \ + GuiPrintNomencl.h \ GuiRef.h \ GuiSearch.h \ GuiSelection.h \ @@ -302,6 +304,7 @@ UIFILES = \ PrefUi.ui \ PrintUi.ui \ PrintindexUi.ui \ + PrintNomenclUi.ui \ RefUi.ui \ SearchUi.ui \ SendtoUi.ui \ diff --git a/src/insets/InsetNomencl.cpp b/src/insets/InsetNomencl.cpp index 0389afe7fe..d73b701f29 100644 --- a/src/insets/InsetNomencl.cpp +++ b/src/insets/InsetNomencl.cpp @@ -19,9 +19,11 @@ #include "DispatchResult.h" #include "Font.h" #include "FuncRequest.h" +#include "FuncStatus.h" #include "InsetIterator.h" #include "InsetList.h" #include "LaTeXFeatures.h" +#include "Length.h" #include "MetricsInfo.h" #include "sgml.h" @@ -122,7 +124,7 @@ void InsetNomencl::validate(LaTeXFeatures & features) const ///////////////////////////////////////////////////////////////////// InsetPrintNomencl::InsetPrintNomencl(InsetCommandParams const & p) - : InsetCommand(p, "printnomenclature") + : InsetCommand(p, "nomencl_print") {} @@ -134,8 +136,10 @@ ParamInfo const & InsetPrintNomencl::findInfo(string const & /* cmdName */) static ParamInfo param_info_; if (param_info_.empty()) { // how is the width set? - // values: none|auto + // values: none|auto|custom param_info_.add("set_width", ParamInfo::LYX_INTERNAL); + // custom width + param_info_.add("width", ParamInfo::LYX_INTERNAL); } return param_info_; } @@ -147,6 +151,47 @@ docstring InsetPrintNomencl::screenLabel() const } +void InsetPrintNomencl::doDispatch(Cursor & cur, FuncRequest & cmd) +{ + switch (cmd.action) { + + case LFUN_INSET_MODIFY: { + InsetCommandParams p(NOMENCL_PRINT_CODE); + // FIXME UNICODE + InsetCommand::string2params("nomencl_print", + to_utf8(cmd.argument()), p); + if (p.getCmdName().empty()) { + cur.noUpdate(); + break; + } + setParams(p); + break; + } + + default: + InsetCommand::doDispatch(cur, cmd); + break; + } +} + + +bool InsetPrintNomencl::getStatus(Cursor & cur, FuncRequest const & cmd, + FuncStatus & status) const +{ + switch (cmd.action) { + + case LFUN_INSET_DIALOG_UPDATE: + case LFUN_INSET_MODIFY: + status.setEnabled(true); + return true; + + default: + return InsetCommand::getStatus(cur, cmd, status); + } +} + + + int InsetPrintNomencl::docbook(odocstream & os, OutputParams const &) const { os << "\n"; @@ -232,6 +277,16 @@ int InsetPrintNomencl::latex(odocstream & os, OutputParams const &) const os << " {}\n"; lines += 5; } + } else if (getParam("set_width") == "custom") { + // custom length as optional arg of \printnomenclature + string const width = + Length(to_ascii(getParam("width"))).asLatexString(); + os << '\\' + << from_ascii(getCmdName()) + << '[' + << from_ascii(width) + << "]{}"; + return lines; } // output the command \printnomenclature os << getCommand(); @@ -253,4 +308,10 @@ InsetCode InsetPrintNomencl::lyxCode() const } +docstring InsetPrintNomencl::contextMenu(BufferView const &, int, int) const +{ + return from_ascii("context-nomenclprint"); +} + + } // namespace lyx diff --git a/src/insets/InsetNomencl.h b/src/insets/InsetNomencl.h index 87595fd1ea..5ebf4964d1 100644 --- a/src/insets/InsetNomencl.h +++ b/src/insets/InsetNomencl.h @@ -66,6 +66,8 @@ public: /// InsetCode lyxCode() const; /// + bool hasSettings() const { return true; } + /// DisplayType display() const { return AlignCenter; } /// docstring screenLabel() const; @@ -78,6 +80,13 @@ public: { return s == "printnomenclature"; } /// int latex(odocstream &, OutputParams const &) const; + /// + docstring contextMenu(BufferView const & bv, int x, int y) const; +protected: + /// + void doDispatch(Cursor & cur, FuncRequest & cmd); + /// + bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const; private: Inset * clone() const { return new InsetPrintNomencl(*this); } }; -- 2.39.2