]> git.lyx.org Git - features.git/commitdiff
Add tablestyle buffer param
authorJuergen Spitzmueller <spitz@lyx.org>
Tue, 26 Mar 2019 15:23:34 +0000 (16:23 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Tue, 26 Mar 2019 15:24:27 +0000 (16:24 +0100)
Fixes: #9901
development/FORMAT
lib/lyx2lyx/lyx_2_4.py
src/BufferParams.cpp
src/BufferParams.h
src/Text3.cpp
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiDocument.h
src/frontends/qt4/ui/TextLayoutUi.ui
src/version.h

index 2bbab73ed93c324230e8ee608ef3d6a016b9b557..007f9ebf9b08df0bbf14088f5ca356a67079ffb3 100644 (file)
@@ -7,6 +7,10 @@ changes happened in particular if possible. A good example would be
 
 -----------------------
 
+2019-03-26  Jürgen Spitzmüller <spitz@lyx.org>
+       * format incremented to 569: New buffer param \tablestyle
+          Determines the standard table template to be used.
+
 2019-03-22  Jürgen Spitzmüller <spitz@lyx.org>
        * format incremented to 568: Support for the soul module:
          \so, \hl, \st, \ul, \caps
index 6b3858e6a8a72a3591198beba57795353b3b1384..6b43eceb4ba34b4397480a454489adf1bd8ecee3 100644 (file)
@@ -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]],
index 0445029ee5ebafda0480c77842ba07ff79f1f204..887dfa3de944ab2118357cc80ca611dbc0ca89fa 100644 (file)
@@ -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";
index 8f402f870db186a776aa765ba158b9d65e1cfdd1..aa8385582f42e5b6b047664ef1d54729d8d7f04b 100644 (file)
@@ -366,6 +366,8 @@ public:
        ///
        std::string pagestyle;
        ///
+       std::string tablestyle;
+       ///
        RGBColor backgroundcolor;
        ///
        bool isbackgroundcolor;
index d63bb93e42f5a791d4b78c4462f26d50ef67be4b..e51d323e03733b9d17be95dd7c6bef4ee4b4b8f2 100644 (file)
@@ -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);
index c3641b9046f3a6824040f90781329257d9af6143..371099c67ffd8777b22e38dc3f0839b4b13fd69d 100644 (file)
@@ -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 <QColor>
 #include <QColorDialog>
 #include <QCloseEvent>
+#include <QDirIterator>
 #include <QFontDatabase>
 #include <QHeaderView>
 #include <QScrollBar>
@@ -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);
index 8812ff91c4e440a2fa536dc7749144b5b0943e39..eebd2675f40f245932bdd169205a01084dd2d90a 100644 (file)
@@ -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_;
index e59db7e7b8f95cd20a4678dfd47ea234fed52545..d8da89af9b0b154df53c19f8dfc471d29f81c3df 100644 (file)
     <x>0</x>
     <y>0</y>
     <width>470</width>
-    <height>380</height>
+    <height>468</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string/>
   </property>
-  <layout class="QGridLayout" name="gridLayout_3">
-   <item row="0" column="0" colspan="3">
+  <layout class="QGridLayout" name="gridLayout_4">
+   <item row="1" column="0">
+    <widget class="QGroupBox" name="spacingGB">
+     <property name="minimumSize">
+      <size>
+       <width>0</width>
+       <height>0</height>
+      </size>
+     </property>
+     <property name="title">
+      <string>Spacing</string>
+     </property>
+     <property name="flat">
+      <bool>true</bool>
+     </property>
+     <property name="checkable">
+      <bool>false</bool>
+     </property>
+     <layout class="QGridLayout" name="gridLayout_2">
+      <item row="0" column="0">
+       <widget class="QLabel" name="lspacingL">
+        <property name="minimumSize">
+         <size>
+          <width>91</width>
+          <height>18</height>
+         </size>
+        </property>
+        <property name="text">
+         <string>&amp;Line spacing:</string>
+        </property>
+        <property name="buddy">
+         <cstring>lspacingCO</cstring>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1">
+       <widget class="QComboBox" name="lspacingCO">
+        <property name="toolTip">
+         <string>Spacing type</string>
+        </property>
+        <property name="duplicatesEnabled">
+         <bool>false</bool>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="2">
+       <widget class="QLineEdit" name="lspacingLE">
+        <property name="enabled">
+         <bool>false</bool>
+        </property>
+        <property name="toolTip">
+         <string>Number of lines</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="3">
+       <spacer name="horizontalSpacer">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>69</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item row="4" column="0">
+    <widget class="QGroupBox" name="tableStyleGB">
+     <property name="title">
+      <string>Table Style</string>
+     </property>
+     <layout class="QGridLayout" name="gridLayout_3">
+      <item row="0" column="0">
+       <layout class="QHBoxLayout" name="horizontalLayout">
+        <item>
+         <widget class="QLabel" name="tableStyleLA">
+          <property name="text">
+           <string>Default St&amp;yle:</string>
+          </property>
+          <property name="buddy">
+           <cstring>tableStyleCO</cstring>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QComboBox" name="tableStyleCO">
+          <property name="sizePolicy">
+           <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+            <horstretch>0</horstretch>
+            <verstretch>0</verstretch>
+           </sizepolicy>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <spacer name="horizontalSpacer_2">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>40</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+       </layout>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item row="7" column="0">
+    <spacer>
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeType">
+      <enum>QSizePolicy::Expanding</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>403</width>
+       <height>21</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item row="0" column="0">
     <widget class="QGroupBox" name="separateGB">
      <property name="title">
       <string>Paragraph Separation</string>
      </layout>
     </widget>
    </item>
-   <item row="1" column="0" colspan="3">
-    <widget class="QGroupBox" name="spacingGB">
-     <property name="minimumSize">
-      <size>
-       <width>0</width>
-       <height>0</height>
-      </size>
-     </property>
-     <property name="title">
-      <string>Spacing</string>
-     </property>
-     <property name="flat">
-      <bool>true</bool>
+   <item row="6" column="0">
+    <widget class="QCheckBox" name="justCB">
+     <property name="toolTip">
+      <string>Justify text in the LyX editor (this does not affect whether the text is justified in the output)</string>
      </property>
-     <property name="checkable">
-      <bool>false</bool>
+     <property name="text">
+      <string>Use &amp;justification in LyX work area</string>
      </property>
-     <layout class="QGridLayout" name="gridLayout_2">
-      <item row="0" column="0">
-       <widget class="QLabel" name="lspacingL">
-        <property name="minimumSize">
-         <size>
-          <width>91</width>
-          <height>18</height>
-         </size>
-        </property>
-        <property name="text">
-         <string>&amp;Line spacing:</string>
-        </property>
-        <property name="buddy">
-         <cstring>lspacingCO</cstring>
-        </property>
-       </widget>
-      </item>
-      <item row="0" column="1">
-       <widget class="QComboBox" name="lspacingCO">
-        <property name="toolTip">
-         <string>Spacing type</string>
-        </property>
-        <property name="duplicatesEnabled">
-         <bool>false</bool>
-        </property>
-       </widget>
-      </item>
-      <item row="0" column="2">
-       <widget class="QLineEdit" name="lspacingLE">
-        <property name="enabled">
-         <bool>false</bool>
-        </property>
-        <property name="toolTip">
-         <string>Number of lines</string>
-        </property>
-       </widget>
-      </item>
-      <item row="0" column="3">
-       <spacer name="horizontalSpacer">
-        <property name="orientation">
-         <enum>Qt::Horizontal</enum>
-        </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>69</width>
-          <height>20</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
-     </layout>
     </widget>
    </item>
-   <item row="2" column="0" colspan="2">
+   <item row="5" column="0">
     <widget class="QCheckBox" name="twoColumnCB">
      <property name="toolTip">
       <string>Format text into two columns</string>
      </property>
     </widget>
    </item>
-   <item row="3" column="0" colspan="2">
-    <widget class="QCheckBox" name="justCB">
-     <property name="toolTip">
-      <string>Justify text in the LyX editor (this does not affect whether the text is justified in the output)</string>
-     </property>
-     <property name="text">
-      <string>Use &amp;justification in LyX work area</string>
-     </property>
-    </widget>
-   </item>
-   <item row="4" column="0" colspan="3">
-    <spacer>
-     <property name="orientation">
-      <enum>Qt::Vertical</enum>
-     </property>
-     <property name="sizeType">
-      <enum>QSizePolicy::Expanding</enum>
-     </property>
-     <property name="sizeHint" stdset="0">
-      <size>
-       <width>403</width>
-       <height>21</height>
-      </size>
-     </property>
-    </spacer>
-   </item>
   </layout>
  </widget>
  <customwidgets>
index cc24a614d82761e67d687a58232af2c37f6b3585..dc50c36d9485b3c6ef42debd04a5c317c46aaaec 100644 (file)
@@ -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