From ecb2427f4165a678304591cd38891873f1ad84a7 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Tue, 26 Mar 2019 16:23:34 +0100 Subject: [PATCH] Add tablestyle buffer param Fixes: #9901 --- development/FORMAT | 4 + lib/lyx2lyx/lyx_2_4.py | 13 +- src/BufferParams.cpp | 6 +- src/BufferParams.h | 2 + src/Text3.cpp | 10 +- src/frontends/qt4/GuiDocument.cpp | 52 ++++++ src/frontends/qt4/GuiDocument.h | 2 + src/frontends/qt4/ui/TextLayoutUi.ui | 238 ++++++++++++++++----------- src/version.h | 4 +- 9 files changed, 230 insertions(+), 101 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index 2bbab73ed9..007f9ebf9b 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -7,6 +7,10 @@ changes happened in particular if possible. A good example would be ----------------------- +2019-03-26 Jürgen Spitzmüller + * format incremented to 569: New buffer param \tablestyle + Determines the standard table template to be used. + 2019-03-22 Jürgen Spitzmüller * format incremented to 568: Support for the soul module: \so, \hl, \st, \ul, \caps diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py index 6b3858e6a8..6b43eceb4b 100644 --- a/lib/lyx2lyx/lyx_2_4.py +++ b/lib/lyx2lyx/lyx_2_4.py @@ -1434,6 +1434,15 @@ def revert_soul(document): revert_flex_inset(document.body, "Capitalize", "\\caps") +def revert_tablestyle(document): + " Remove tablestyle params " + + i = 0 + i = find_token(document.header, "\\tablestyle", 0) + if i != -1: + del document.header[i] + + ## # Conversion hub @@ -1464,10 +1473,12 @@ convert = [ [565, [convert_AdobeFonts]], # Handle adobe fonts in GUI [566, [convert_hebrew_parentheses]], [567, []], - [568, []] + [568, []], + [569, []] ] revert = [ + [568, [revert_tablestyle]], [567, [revert_soul]], [566, [revert_malayalam]], [565, [revert_hebrew_parentheses]], diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 0445029ee5..887dfa3de9 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -435,6 +435,7 @@ BufferParams::BufferParams() columns = 1; listings_params = string(); pagestyle = "default"; + tablestyle = "default"; suppress_date = false; justification = true; // no color is the default (white) @@ -1052,6 +1053,8 @@ string BufferParams::readToken(Lexer & lex, string const & token, sides = sidestranslator().find(psides); } else if (token == "\\paperpagestyle") { lex >> pagestyle; + } else if (token == "\\tablestyle") { + lex >> tablestyle; } else if (token == "\\bullet") { readBullets(lex); } else if (token == "\\bulletLaTeX") { @@ -1396,7 +1399,8 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const << "\n\\dynamic_quotes " << dynamic_quotes << "\n\\papercolumns " << columns << "\n\\papersides " << sides - << "\n\\paperpagestyle " << pagestyle << '\n'; + << "\n\\paperpagestyle " << pagestyle + << "\n\\tablestyle " << tablestyle << '\n'; if (!listings_params.empty()) os << "\\listings_params \"" << InsetListingsParams(listings_params).encodedString() << "\"\n"; diff --git a/src/BufferParams.h b/src/BufferParams.h index 8f402f870d..aa8385582f 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -366,6 +366,8 @@ public: /// std::string pagestyle; /// + std::string tablestyle; + /// RGBColor backgroundcolor; /// bool isbackgroundcolor; diff --git a/src/Text3.cpp b/src/Text3.cpp index d63bb93e42..e51d323e03 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -2077,7 +2077,14 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) break; } - case LFUN_TABULAR_INSERT: + case LFUN_TABULAR_INSERT: { + if (cur.buffer()->masterParams().tablestyle != "default") { + FuncRequest fr(LFUN_TABULAR_STYLE_INSERT, + cur.buffer()->masterParams().tablestyle + " " + + to_ascii(cmd.argument())); + lyx::dispatch(fr); + break; + } // if there were no arguments, just open the dialog if (doInsertInset(cur, this, cmd, false, true)) cur.posForward(); @@ -2085,6 +2092,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) bv->showDialog("tabularcreate"); break; + } case LFUN_TABULAR_STYLE_INSERT: { string const style = cmd.getArg(0); diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index c3641b9046..371099c67f 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -65,6 +65,7 @@ #include "support/gettext.h" #include "support/lassert.h" #include "support/lstrings.h" +#include "support/Package.h" #include "support/TempFile.h" #include "frontends/alert.h" @@ -74,6 +75,7 @@ #include #include #include +#include #include #include #include @@ -828,6 +830,9 @@ GuiDocument::GuiDocument(GuiView & lv) connect(textLayoutModule->justCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); + connect(textLayoutModule->tableStyleCO, SIGNAL(activated(int)), + this, SLOT(change_adaptor())); + textLayoutModule->lspacingLE->setValidator(new QDoubleValidator( textLayoutModule->lspacingLE)); textLayoutModule->indentLE->setValidator(new LengthValidator( @@ -852,6 +857,9 @@ GuiDocument::GuiDocument(GuiView & lv) // initialize the length validator bc().addCheckedLineEdit(textLayoutModule->indentLE); bc().addCheckedLineEdit(textLayoutModule->skipLE); + + textLayoutModule->tableStyleCO->addItem(qt_("Default"), toqstr("default")); + getTableStyles(); // master/child handling @@ -2967,6 +2975,45 @@ void GuiDocument::updateNumbering() } +void GuiDocument::getTableStyles() +{ + // We look for lyx files in the subdirectory dir of + // 1) user_lyxdir + // 2) build_lyxdir (if not empty) + // 3) system_lyxdir + // in this order. Files with a given sub-hierarchy will + // only be listed once. + // We also consider i18n subdirectories and store them separately. + QStringList dirs; + + // The three locations to look at. + string const user = addPath(package().user_support().absFileName(), "tabletemplates"); + string const build = addPath(package().build_support().absFileName(), "tabletemplates"); + string const system = addPath(package().system_support().absFileName(), "tabletemplates"); + + dirs << toqstr(user) + << toqstr(build) + << toqstr(system); + + for (int i = 0; i < dirs.size(); ++i) { + QString const dir = dirs.at(i); + QDirIterator it(dir, QDir::Files, QDirIterator::Subdirectories); + while (it.hasNext()) { + QString fn = QFileInfo(it.next()).fileName(); + if (!fn.endsWith(".lyx") || fn.contains("_1x")) + continue; + QString data = fn.left(fn.lastIndexOf(".lyx")); + QString guiname = data; + guiname = toqstr(translateIfPossible(qstring_to_ucs4(guiname.replace('_', ' ')))); + QString relpath = toqstr(makeRelPath(qstring_to_ucs4(fn), + qstring_to_ucs4(dir))); + if (textLayoutModule->tableStyleCO->findData(data) == -1) + textLayoutModule->tableStyleCO->addItem(guiname, data); + } + } +} + + void GuiDocument::updateDefaultFormat() { if (!bufferview()) @@ -3285,6 +3332,8 @@ void GuiDocument::applyView() break; } } + bp_.tablestyle = fromqstr(textLayoutModule->tableStyleCO->itemData( + textLayoutModule->tableStyleCO->currentIndex()).toString()); bp_.options = fromqstr(latexModule->optionsLE->text()); @@ -3737,6 +3786,9 @@ void GuiDocument::paramsToDialog() bp_.spacing().getValueAsString()); } setLSpacing(nitem); + int ts = textLayoutModule->tableStyleCO->findData(toqstr(bp_.tablestyle)); + if (ts != -1) + textLayoutModule->tableStyleCO->setCurrentIndex(ts); if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) { textLayoutModule->indentRB->setChecked(true); diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index 8812ff91c4..eebd2675f4 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -211,6 +211,8 @@ private: void setLayoutComboByIDString(std::string const & idString); /// Update quotes styles combo, indicating the current language's default void updateQuoteStyles(bool const set = false); + /// + void getTableStyles(); /// available modules GuiIdListModel modules_av_model_; diff --git a/src/frontends/qt4/ui/TextLayoutUi.ui b/src/frontends/qt4/ui/TextLayoutUi.ui index e59db7e7b8..d8da89af9b 100644 --- a/src/frontends/qt4/ui/TextLayoutUi.ui +++ b/src/frontends/qt4/ui/TextLayoutUi.ui @@ -7,14 +7,146 @@ 0 0 470 - 380 + 468 - - + + + + + + 0 + 0 + + + + Spacing + + + true + + + false + + + + + + + 91 + 18 + + + + &Line spacing: + + + lspacingCO + + + + + + + Spacing type + + + false + + + + + + + false + + + Number of lines + + + + + + + Qt::Horizontal + + + + 69 + 20 + + + + + + + + + + + Table Style + + + + + + + + Default St&yle: + + + tableStyleCO + + + + + + + + 0 + 0 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 403 + 21 + + + + + Paragraph Separation @@ -185,77 +317,17 @@ - - - - - 0 - 0 - - - - Spacing - - - true + + + + Justify text in the LyX editor (this does not affect whether the text is justified in the output) - - false + + Use &justification in LyX work area - - - - - - 91 - 18 - - - - &Line spacing: - - - lspacingCO - - - - - - - Spacing type - - - false - - - - - - - false - - - Number of lines - - - - - - - Qt::Horizontal - - - - 69 - 20 - - - - - - + Format text into two columns @@ -265,32 +337,6 @@ - - - - Justify text in the LyX editor (this does not affect whether the text is justified in the output) - - - Use &justification in LyX work area - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 403 - 21 - - - - diff --git a/src/version.h b/src/version.h index cc24a614d8..dc50c36d94 100644 --- a/src/version.h +++ b/src/version.h @@ -32,8 +32,8 @@ extern char const * const lyx_version_info; // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -#define LYX_FORMAT_LYX 568 // spitz :soul.module -#define LYX_FORMAT_TEX2LYX 568 +#define LYX_FORMAT_LYX 569 // spitz: tablestyle buffer param +#define LYX_FORMAT_TEX2LYX 569 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #ifndef _MSC_VER -- 2.39.2