[LyX/master] Allow to set multipage-table and caption on tabular insertion

Juergen Spitzmueller <[email protected]> Thu, 30 Apr 2026 12:47:12 +0000
Newsgroups gmane.editors.lyx.cvs
Message-ID <[email protected]>
commit b00e7f7c7ff5eb4699da0cedd8076b4bd2613719
Author: Juergen Spitzmueller <[email protected]>
Date:   Thu Apr 30 14:45:39 2026 +0200

    Allow to set multipage-table and caption on tabular insertion
    
    Both can be set now in the tabular create dialog (for all styles)
    or with the lfuns
---
 src/LyXAction.cpp                      |  6 ++++--
 src/Text.cpp                           | 18 ++++++++++++++++--
 src/frontends/qt/GuiTabularCreate.cpp  | 17 ++++++++++++++++-
 src/frontends/qt/GuiTabularCreate.h    |  1 +
 src/frontends/qt/ui/TabularCreateUi.ui | 23 ++++++++++++++++++++++-
 5 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index dd6f438af6..0e0826ead4 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -4047,8 +4047,9 @@ void LyXAction::init()
  * \li Action: Inserts table into the document.
  * \li Notion: See #LFUN_TABULAR_FEATURE for some more details
                about tabular modifications.
- * \li Syntax: tabular-insert [<ROWS> <COLUMNS>]
+ * \li Syntax: tabular-insert [<ROWS> <COLUMNS> <EXTRAS>]
  * \li Params: In case no arguments are given show insert dialog.
+ *             EXTRAS can be "longtable" or "longtable-caption" currently.
  * \li Origin: Jug, 12 Apr 2000
  * \endvar
  */
@@ -4059,9 +4060,10 @@ void LyXAction::init()
  * \li Action: Inserts table of a given style into the document.
  * \li Notion: See #LFUN_TABULAR_FEATURE for some more details
 	       about tabular modifications.
- * \li Syntax: tabular-style-insert <style> <ROWS> <COLUMNS>
+ * \li Syntax: tabular-style-insert <style> <ROWS> <COLUMNS> <EXTRAS>
  * \li Params: Valid styles are the names of the files in lib/tabletemplates,
  *             minus _1x<n> and .lyx suffix.
+ *             EXTRAS can be "longtable" or "longtable-caption" currently.
  * \li Origin: spitz, 25 Mar 2019
  * \endvar
  */
diff --git a/src/Text.cpp b/src/Text.cpp
index a5fe9474da..e41b86232b 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -5572,11 +5572,15 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 		if (cmd.argument().empty()) {
 			bv->showDialog("tabularcreate");
 			break;
-		} else if (cur.buffer()->masterParams().tablestyle != "default"
-			   || bv->buffer().params().documentClass().tablestyle() != "default") {
+		}
+		string const extras = cmd.getArg(2);
+		if (!extras.empty() || cur.buffer()->masterParams().tablestyle != "default"
+		    || bv->buffer().params().documentClass().tablestyle() != "default") {
 			string tabstyle = cur.buffer()->masterParams().tablestyle;
 			if (tabstyle == "default")
 				tabstyle = bv->buffer().params().documentClass().tablestyle();
+			if (tabstyle == "default")
+				tabstyle = "Grid_with_Head";
 			if (!libFileSearch("tabletemplates", tabstyle + ".lyx").empty()) {
 				FuncRequest fr(LFUN_TABULAR_STYLE_INSERT,
 					       tabstyle + " " + to_ascii(cmd.argument()));
@@ -5599,6 +5603,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 		string const style = cmd.getArg(0);
 		string const rows = cmd.getArg(1);
 		string const cols = cmd.getArg(2);
+		string const extras = cmd.getArg(3);
 		if (cols.empty() || !isStrInt(cols)
 		    || rows.empty() || !isStrInt(rows))
 			break;
@@ -5640,6 +5645,15 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 		if (r > 1)
 			// go to first cell
 			cur.up();
+		if (extras == "longtable") {
+				FuncRequest fr(LFUN_TABULAR_FEATURE, "set-longtabular");
+				lyx::dispatch(fr);
+		} else if (extras == "longtable-caption") {
+			FuncRequest fr(LFUN_COMMAND_SEQUENCE, "tabular-feature set-longtabular;"
+							      "tabular-feature append-row;"
+							      "tabular-feature set-ltcaption");
+			lyx::dispatch(fr);
+		}
 		break;
 	}
 
diff --git a/src/frontends/qt/GuiTabularCreate.cpp b/src/frontends/qt/GuiTabularCreate.cpp
index 95eb3b8f81..43cfac450c 100644
--- a/src/frontends/qt/GuiTabularCreate.cpp
+++ b/src/frontends/qt/GuiTabularCreate.cpp
@@ -92,6 +92,9 @@ GuiTabularCreate::GuiTabularCreate(GuiView & lv)
 	connect(columnsSB, SIGNAL(valueChanged(int)),
 		this, SLOT(columnsChanged(int)));
 
+	connect(longtableCB, SIGNAL(clicked()),
+		this, SLOT(longtableChanged()));
+
 	bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
 	bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
 	bc().setApply(buttonBox->button(QDialogButtonBox::Apply));
@@ -123,6 +126,12 @@ void GuiTabularCreate::rowsChanged(int)
 }
 
 
+void GuiTabularCreate::longtableChanged()
+{
+	captionCB->setEnabled(longtableCB->isChecked());
+}
+
+
 void GuiTabularCreate::applyView()
 {
 	params_.first = ulong(rowsSB->value());
@@ -135,6 +144,7 @@ bool GuiTabularCreate::initialiseParams(string const &)
 	params_.first  = 5;
 	params_.second = 5;
 	style_ = styleCO->itemData(styleCO->currentIndex()).toString();
+	longtableChanged();
 	changed();
 	return true;
 }
@@ -153,6 +163,11 @@ void GuiTabularCreate::dispatchParams()
 	if (style_ != "default")
 		sdata = fromqstr(style_) + ' ';
 	sdata += convert<string>(params().first) + ' ' + convert<string>(params().second);
+	if (longtableCB->isChecked()) {
+		sdata += " longtable";
+		if (captionCB->isChecked())
+			sdata += "-caption";
+	}
 	dispatch(FuncRequest(getLfun(), sdata));
 }
 
@@ -160,7 +175,7 @@ void GuiTabularCreate::dispatchParams()
 FuncCode GuiTabularCreate::getLfun() const
 {
 	if (style_.isEmpty() || style_ == "default")
-		return  LFUN_TABULAR_INSERT;
+		return LFUN_TABULAR_INSERT;
 	
 	return LFUN_TABULAR_STYLE_INSERT;
 }
diff --git a/src/frontends/qt/GuiTabularCreate.h b/src/frontends/qt/GuiTabularCreate.h
index 7495bc73b2..df860dac8f 100644
--- a/src/frontends/qt/GuiTabularCreate.h
+++ b/src/frontends/qt/GuiTabularCreate.h
@@ -32,6 +32,7 @@ private Q_SLOTS:
 	void columnsChanged(int);
 	void rowsChanged(int);
 	void on_styleCO_activated(int);
+	void longtableChanged();
 
 private:
 	/// Apply changes
diff --git a/src/frontends/qt/ui/TabularCreateUi.ui b/src/frontends/qt/ui/TabularCreateUi.ui
index 23e3665aa0..4a476e357a 100644
--- a/src/frontends/qt/ui/TabularCreateUi.ui
+++ b/src/frontends/qt/ui/TabularCreateUi.ui
@@ -114,6 +114,27 @@
     </widget>
    </item>
    <item row="2" column="0">
+    <layout class="QHBoxLayout" name="horizontalLayout_5">
+     <item>
+      <widget class="QCheckBox" name="longtableCB">
+       <property name="toolTip">
+        <string>Insert a table that can spread across multiple pages</string>
+       </property>
+       <property name="text">
+        <string>&amp;Multi-page table</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QCheckBox" name="captionCB">
+       <property name="text">
+        <string>With ca&amp;ption</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item row="3" column="0">
     <layout class="QHBoxLayout" name="horizontalLayout_4">
      <item>
       <widget class="QLabel" name="styleLA">
@@ -137,7 +158,7 @@
      </item>
     </layout>
    </item>
-   <item row="3" column="0">
+   <item row="4" column="0">
     <widget class="QDialogButtonBox" name="buttonBox">
      <property name="standardButtons">
       <set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs