From b5049e769bba3923cf8e21c980c75b7c00187420 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Thu, 18 Feb 2010 08:28:46 +0000 Subject: [PATCH] * InsetTabular cleanup: - proper message passing for all tabular features - properly define which feature needs an argument * replace LFUN_TABULAR_FEATURE with LFUN_INSET_MODIFY - The math tables are also affected. In the future a common base class between math and text table will solve this inconsistency. - There is a hack in GuiApplication in order to not rename the toolbar icons. This will have to be cleaned up with a general icon naming for LFUN_INSET_MODIFY... to be discussed. * Tabular Dialog: - big cleanup, lots and lots of bug fixing here - migrated to InsetParamsWidget git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33495 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/bind/aqua.bind | 50 +- lib/bind/math.bind | 48 +- lib/ui/stdtoolbars.inc | 50 +- src/FuncCode.h | 3 +- src/LyXAction.cpp | 5 +- src/frontends/qt4/GuiApplication.cpp | 15 + src/frontends/qt4/GuiTabular.cpp | 1115 +++++++---------------- src/frontends/qt4/GuiTabular.h | 107 +-- src/frontends/qt4/GuiView.cpp | 3 - src/frontends/qt4/InsetParamsDialog.cpp | 3 - src/frontends/qt4/ui/TabularUi.ui | 26 +- src/insets/Inset.cpp | 2 +- src/insets/InsetTabular.cpp | 233 ++--- src/insets/InsetTabular.h | 4 - src/mathed/InsetMathAMSArray.cpp | 23 +- src/mathed/InsetMathCases.cpp | 31 +- src/mathed/InsetMathGrid.cpp | 16 +- src/mathed/InsetMathHull.cpp | 5 +- src/mathed/InsetMathNest.cpp | 4 +- src/mathed/InsetMathSplit.cpp | 14 +- src/mathed/InsetMathSubstack.cpp | 14 +- 21 files changed, 634 insertions(+), 1137 deletions(-) diff --git a/lib/bind/aqua.bind b/lib/bind/aqua.bind index 319dc829b8..817163c0ca 100644 --- a/lib/bind/aqua.bind +++ b/lib/bind/aqua.bind @@ -87,28 +87,28 @@ \bind "M-~S-e x l" "primary-selection-paste" \bind "M-~S-e x p" "primary-selection-paste paragraph" -\bind "M-~S-e t m" "tabular-feature multicolumn" -\bind "M-~S-e t t" "tabular-feature toggle-line-top" -\bind "M-~S-e t b" "tabular-feature toggle-line-bottom" -\bind "M-~S-e t l" "tabular-feature toggle-line-left" -\bind "M-~S-e t r" "tabular-feature toggle-line-right" -\bind "M-~S-e t e" "tabular-feature align-left" -\bind "M-~S-e t c" "tabular-feature align-center" -\bind "M-~S-e t i" "tabular-feature align-right" -\bind "M-~S-e t o" "tabular-feature valign-top" -\bind "M-~S-e t n" "tabular-feature valign-center" -\bind "M-~S-e t v" "tabular-feature valign-bottom" -\bind "M-~S-e t a" "tabular-feature append-row" -\bind "M-~S-e t w" "tabular-feature delete-row" -\bind "M-~S-e t u" "tabular-feature append-column" -\bind "M-~S-e t d" "tabular-feature delete-column" +\bind "M-~S-e t m" "inset-modify tabular multicolumn" +\bind "M-~S-e t t" "inset-modify tabular toggle-line-top" +\bind "M-~S-e t b" "inset-modify tabular toggle-line-bottom" +\bind "M-~S-e t l" "inset-modify tabular toggle-line-left" +\bind "M-~S-e t r" "inset-modify tabular toggle-line-right" +\bind "M-~S-e t e" "inset-modify tabular align-left" +\bind "M-~S-e t c" "inset-modify tabular align-center" +\bind "M-~S-e t i" "inset-modify tabular align-right" +\bind "M-~S-e t o" "inset-modify tabular valign-top" +\bind "M-~S-e t n" "inset-modify tabular valign-center" +\bind "M-~S-e t v" "inset-modify tabular valign-bottom" +\bind "M-~S-e t a" "inset-modify tabular append-row" +\bind "M-~S-e t w" "inset-modify tabular delete-row" +\bind "M-~S-e t u" "inset-modify tabular append-column" +\bind "M-~S-e t d" "inset-modify tabular delete-column" \bind "M-~S-e m n" "math-number-toggle" \bind "M-~S-e m u" "math-number-line-toggle" -\bind "M-~S-e m r" "tabular-feature append-row" -\bind "M-~S-e m d" "tabular-feature delete-row" -\bind "M-~S-e m c" "tabular-feature append-column" -\bind "M-~S-e m e" "tabular-feature delete-column" +\bind "M-~S-e m r" "inset-modify tabular append-row" +\bind "M-~S-e m d" "inset-modify tabular delete-row" +\bind "M-~S-e m c" "inset-modify tabular append-column" +\bind "M-~S-e m e" "inset-modify tabular delete-column" \bind "M-~S-e m l t" "math-limits empty" \bind "M-~S-e m l d" "math-limits limits" @@ -120,12 +120,12 @@ \bind "M-~S-e m f a" "math-mutate align" \bind "M-~S-e m f f" "math-mutate flalign" -\bind "M-~S-e m a l" "tabular-feature align-left" -\bind "M-~S-e m a c" "tabular-feature align-center" -\bind "M-~S-e m a r" "tabular-feature align-right" -\bind "M-~S-e m a t" "tabular-feature valign-top" -\bind "M-~S-e m a e" "tabular-feature valign-center" -\bind "M-~S-e m a b" "tabular-feature valign-bottom" +\bind "M-~S-e m a l" "inset-modify tabular align-left" +\bind "M-~S-e m a c" "inset-modify tabular align-center" +\bind "M-~S-e m a r" "inset-modify tabular align-right" +\bind "M-~S-e m a t" "inset-modify tabular valign-top" +\bind "M-~S-e m a e" "inset-modify tabular valign-center" +\bind "M-~S-e m a b" "inset-modify tabular valign-bottom" \bind "M-~S-v l" "latex-view-log" \bind "M-~S-v t" "toc-view" diff --git a/lib/bind/math.bind b/lib/bind/math.bind index 164b6f6e75..e5b21b4d14 100644 --- a/lib/bind/math.bind +++ b/lib/bind/math.bind @@ -73,30 +73,30 @@ \bind "M-m t e" "math-mutate eqnarray" \bind "M-m t m" "math-mutate multline" -\bind "M-m c i" "tabular-feature append-column" -\bind "M-m c d" "tabular-feature delete-column" -\bind "M-m c c" "tabular-feature copy-column" -\bind "M-m c s" "tabular-feature swap-column" -\bind "M-m c a" "tabular-feature add-vline-left" -\bind "M-m c e" "tabular-feature delete-vline-left" -\bind "M-m c z" "tabular-feature add-vline-right" -\bind "M-m c x" "tabular-feature delete-vline-right" - -\bind "M-m w i" "tabular-feature append-row" -\bind "M-m w d" "tabular-feature delete-row" -\bind "M-m w c" "tabular-feature copy-row" -\bind "M-m w s" "tabular-feature swap-row" -\bind "M-m w a" "tabular-feature add-hline-above" -\bind "M-m w e" "tabular-feature delete-hline-above" -\bind "M-m w z" "tabular-feature add-hline-below" -\bind "M-m w x" "tabular-feature delete-hline-below" - -\bind "M-m w t" "tabular-feature valign-top" -\bind "M-m w m" "tabular-feature valign-middle" -\bind "M-m w b" "tabular-feature valign-bottom" -\bind "M-m c l" "tabular-feature align-left" -\bind "M-m c m" "tabular-feature align-center" -\bind "M-m c r" "tabular-feature align-right" +\bind "M-m c i" "inset-modify tabular append-column" +\bind "M-m c d" "inset-modify tabular delete-column" +\bind "M-m c c" "inset-modify tabular copy-column" +\bind "M-m c s" "inset-modify tabular swap-column" +\bind "M-m c a" "inset-modify tabular add-vline-left" +\bind "M-m c e" "inset-modify tabular delete-vline-left" +\bind "M-m c z" "inset-modify tabular add-vline-right" +\bind "M-m c x" "inset-modify tabular delete-vline-right" + +\bind "M-m w i" "inset-modify tabular append-row" +\bind "M-m w d" "inset-modify tabular delete-row" +\bind "M-m w c" "inset-modify tabular copy-row" +\bind "M-m w s" "inset-modify tabular swap-row" +\bind "M-m w a" "inset-modify tabular add-hline-above" +\bind "M-m w e" "inset-modify tabular delete-hline-above" +\bind "M-m w z" "inset-modify tabular add-hline-below" +\bind "M-m w x" "inset-modify tabular delete-hline-below" + +\bind "M-m w t" "inset-modify tabular valign-top" +\bind "M-m w m" "inset-modify tabular valign-middle" +\bind "M-m w b" "inset-modify tabular valign-bottom" +\bind "M-m c l" "inset-modify tabular align-left" +\bind "M-m c m" "inset-modify tabular align-center" +\bind "M-m c r" "inset-modify tabular align-right" # Decoration accents diff --git a/lib/ui/stdtoolbars.inc b/lib/ui/stdtoolbars.inc index 21bae0fb93..00f4cae687 100644 --- a/lib/ui/stdtoolbars.inc +++ b/lib/ui/stdtoolbars.inc @@ -137,31 +137,31 @@ ToolbarSet End Toolbar "table" "Table" - Item "Add row" "tabular-feature append-row" - Item "Add column" "tabular-feature append-column" - Item "Delete row" "tabular-feature delete-row" - Item "Delete column" "tabular-feature delete-column" + Item "Add row" "inset-modify tabular append-row" + Item "Add column" "inset-modify tabular append-column" + Item "Delete row" "inset-modify tabular delete-row" + Item "Delete column" "inset-modify tabular delete-column" Separator - Item "Set top line" "tabular-feature toggle-line-top" - Item "Set bottom line" "tabular-feature toggle-line-bottom" - Item "Set left line" "tabular-feature toggle-line-left" - Item "Set right line" "tabular-feature toggle-line-right" - Item "Set border lines" "tabular-feature set-border-lines" - Item "Set all lines" "tabular-feature set-all-lines" - Item "Unset all lines" "tabular-feature unset-all-lines" + Item "Set top line" "inset-modify tabular toggle-line-top" + Item "Set bottom line" "inset-modify tabular toggle-line-bottom" + Item "Set left line" "inset-modify tabular toggle-line-left" + Item "Set right line" "inset-modify tabular toggle-line-right" + Item "Set border lines" "inset-modify tabular set-border-lines" + Item "Set all lines" "inset-modify tabular set-all-lines" + Item "Unset all lines" "inset-modify tabular unset-all-lines" Separator - Item "Align left" "command-alternatives tabular-feature m-align-left;tabular-feature align-left" - Item "Align center" "command-alternatives tabular-feature m-align-center;tabular-feature align-center" - Item "Align right" "command-alternatives tabular-feature m-align-right;tabular-feature align-right" + Item "Align left" "command-alternatives inset-modify tabular m-align-left;inset-modify tabular align-left" + Item "Align center" "command-alternatives inset-modify tabular m-align-center;inset-modify tabular align-center" + Item "Align right" "command-alternatives inset-modify tabular m-align-right;inset-modify tabular align-right" Separator - Item "Align top" "command-alternatives tabular-feature m-valign-top;tabular-feature valign-top" - Item "Align middle" "command-alternatives tabular-feature m-valign-middle;tabular-feature valign-middle" - Item "Align bottom" "command-alternatives tabular-feature m-valign-bottom;tabular-feature valign-bottom" + Item "Align top" "command-alternatives inset-modify tabular m-valign-top;inset-modify tabular valign-top" + Item "Align middle" "command-alternatives inset-modify tabular m-valign-middle;inset-modify tabular valign-middle" + Item "Align bottom" "command-alternatives inset-modify tabular m-valign-bottom;inset-modify tabular valign-bottom" Separator - Item "Rotate cell" "tabular-feature toggle-rotate-cell" - Item "Rotate table" "tabular-feature toggle-rotate-tabular" - Item "Set multi-column" "tabular-feature multicolumn" - Item "Set multi-row" "tabular-feature multirow" + Item "Rotate cell" "inset-modify tabular toggle-rotate-cell" + Item "Rotate table" "inset-modify tabular toggle-rotate-tabular" + Item "Set multi-column" "inset-modify tabular multicolumn" + Item "Set multi-row" "inset-modify tabular multirow" End Toolbar "math" "Math" @@ -183,10 +183,10 @@ ToolbarSet Separator Item "Insert matrix" "dialog-show mathmatrix" Item "Insert cases environment" "math-insert \cases" - Item "Add row" "tabular-feature append-row" - Item "Add column" "tabular-feature append-column" - Item "Delete row" "tabular-feature delete-row" - Item "Delete column" "tabular-feature delete-column" + Item "Add row" "inset-modify tabular append-row" + Item "Add column" "inset-modify tabular append-column" + Item "Delete row" "inset-modify tabular delete-row" + Item "Delete column" "inset-modify tabular delete-column" Separator Item "Toggle math panels" "toolbar-toggle math_panels" End diff --git a/src/FuncCode.h b/src/FuncCode.h index d298d04765..e137083bd4 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -258,7 +258,7 @@ enum FuncCode LFUN_CAPTION_INSERT, // Lgb 20000718; inactive as of 20060905 LFUN_BUFFER_SWITCH, // 190 - LFUN_TABULAR_FEATURE, // Jug 20000728 + LFUN_BUFFER_CHKTEX, // Asger 971030 LFUN_LAYOUT_TABULAR, // Jug 20000731 LFUN_BUFFER_UPDATE, // Dekel 20000805 LFUN_INDEX_INSERT, // Angus 20000803 @@ -445,7 +445,6 @@ enum FuncCode LFUN_SPELLING_ADD, // spitz 20100118 // 345 LFUN_SPELLING_IGNORE, // spitz 20100118 - LFUN_BUFFER_CHKTEX, // Asger 971030 LFUN_LASTACTION // end of the table }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 358b2630fa..1042b6a7cf 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -2080,7 +2080,10 @@ void LyXAction::init() * \li Origin: Jug, 28 Jul 2000 * \endvar */ - { LFUN_TABULAR_FEATURE, "tabular-feature", Noop, Edit }, +// FIXME: This LFUN has been replaced with LFUN_INSET_MODIFY with the +// "tabular" argument. How to insert above documentation into LFUN_INSET_MODIFY doc? +// { LFUN_TABULAR_FEATURE, "tabular-feature", Noop, Edit }, + /*! * \var lyx::FuncCode lyx::LFUN_CELL_BACKWARD * \li Action: Moves the cursor to the previous cell inside the table. diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 7006a7844a..7c90f449b6 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -331,9 +331,24 @@ QString iconName(FuncRequest const & f, bool unknown) docstring firstcom; docstring dummy = split(f.argument(), firstcom, ';'); name1 = toqstr(firstcom); + // FIXME: we should rename the icons to tabular-xxx instead of + // "tabular-feature-xxx" + name1.replace("inset-modify tabular", "tabular-feature"); name1.replace(' ', '_'); break; } + case LFUN_INSET_MODIFY: { + // FIXME: we should rename the icons to tabular-xxx instead of + // "tabular-feature-xxx" and generalize this naming to all + // insets, not to tabular using ones. + string inset_name; + string const command = split(to_utf8(f.argument()), inset_name, ' '); + if (insetCode(inset_name) == TABULAR_CODE) { + name1 = "tabular-feature "+ toqstr(command); + name1.replace(' ', '_'); + break; + } + } default: name2 = toqstr(lyxaction.getActionName(f.action)); name1 = name2; diff --git a/src/frontends/qt4/GuiTabular.cpp b/src/frontends/qt4/GuiTabular.cpp index dac596a856..4d3e3e6c11 100644 --- a/src/frontends/qt4/GuiTabular.cpp +++ b/src/frontends/qt4/GuiTabular.cpp @@ -15,6 +15,7 @@ #include "GuiTabular.h" +#include "GuiApplication.h" #include "GuiSetBorder.h" #include "GuiView.h" #include "LengthCombo.h" @@ -29,6 +30,8 @@ #include "insets/InsetTabular.h" +#include "support/debug.h" + #include #include #include @@ -39,13 +42,9 @@ using namespace std; namespace lyx { namespace frontend { -GuiTabular::GuiTabular(GuiView & lv) - : GuiDialog(lv, "tabular", qt_("Table Settings")), - // tabular_ is initialised at dialog construction in initialiseParams() - tabular_(&(lv.currentBufferView()->buffer()), 0, 0) +GuiTabular::GuiTabular(QWidget * parent) + : InsetParamsWidget(parent) { - active_cell_ = Tabular::npos; - setupUi(this); widthED->setValidator(unsignedLengthValidator(widthED)); @@ -56,27 +55,27 @@ GuiTabular::GuiTabular(GuiView & lv) widthUnitCB->setCurrentItem(Length::defaultUnit()); connect(topspaceED, SIGNAL(returnPressed()), - this, SLOT(topspace_changed())); + this, SLOT(checkEnabled())); connect(topspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)), - this, SLOT(topspace_changed())); + this, SLOT(checkEnabled())); connect(topspaceCO, SIGNAL(activated(int)), - this, SLOT(topspace_changed())); + this, SLOT(checkEnabled())); connect(bottomspaceED, SIGNAL(returnPressed()), - this, SLOT(bottomspace_changed())); + this, SLOT(checkEnabled())); connect(bottomspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)), - this, SLOT(bottomspace_changed())); + this, SLOT(checkEnabled())); connect(bottomspaceCO, SIGNAL(activated(int)), - this, SLOT(bottomspace_changed())); + this, SLOT(checkEnabled())); connect(interlinespaceED, SIGNAL(returnPressed()), - this, SLOT(interlinespace_changed())); + this, SLOT(checkEnabled())); connect(interlinespaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)), - this, SLOT(interlinespace_changed())); + this, SLOT(checkEnabled())); connect(interlinespaceCO, SIGNAL(activated(int)), - this, SLOT(interlinespace_changed())); + this, SLOT(checkEnabled())); connect(booktabsRB, SIGNAL(clicked(bool)), - this, SLOT(booktabsChanged(bool))); + this, SLOT(checkEnabled())); connect(borderDefaultRB, SIGNAL(clicked(bool)), - this, SLOT(booktabsChanged(bool))); + this, SLOT(checkEnabled())); connect(borderSetPB, SIGNAL(clicked()), this, SLOT(borderSet_clicked())); connect(borderUnsetPB, SIGNAL(clicked()), @@ -91,577 +90,427 @@ GuiTabular::GuiTabular(GuiView & lv) connect(longTabularCB, SIGNAL(toggled(bool)), TableAlignCB, SLOT(setDisabled(bool))); connect(hAlignCB, SIGNAL(activated(int)), - this, SLOT(hAlign_changed(int))); + this, SLOT(checkEnabled())); connect(vAlignCB, SIGNAL(activated(int)), - this, SLOT(vAlign_changed(int))); + this, SLOT(checkEnabled())); connect(multicolumnCB, SIGNAL(clicked()), - this, SLOT(multicolumn_clicked())); + this, SLOT(checkEnabled())); connect(multirowCB, SIGNAL(clicked()), - this, SLOT(multirow_clicked())); + this, SLOT(checkEnabled())); connect(newpageCB, SIGNAL(clicked()), - this, SLOT(ltNewpage_clicked())); + this, SLOT(checkEnabled())); connect(headerStatusCB, SIGNAL(clicked()), - this, SLOT(ltHeaderStatus_clicked())); + this, SLOT(checkEnabled())); connect(headerBorderAboveCB, SIGNAL(clicked()), - this, SLOT(ltHeaderBorderAbove_clicked())); + this, SLOT(checkEnabled())); connect(headerBorderBelowCB, SIGNAL(clicked()), - this, SLOT(ltHeaderBorderBelow_clicked())); + this, SLOT(checkEnabled())); connect(firstheaderStatusCB, SIGNAL(clicked()), - this, SLOT(ltFirstHeaderStatus_clicked())); + this, SLOT(checkEnabled())); connect(firstheaderBorderAboveCB, SIGNAL(clicked()), - this, SLOT(ltFirstHeaderBorderAbove_clicked())); + this, SLOT(checkEnabled())); connect(firstheaderBorderBelowCB, SIGNAL(clicked()), - this, SLOT(ltFirstHeaderBorderBelow_clicked())); + this, SLOT(checkEnabled())); connect(firstheaderNoContentsCB, SIGNAL(clicked()), - this, SLOT(ltFirstHeaderEmpty_clicked())); + this, SLOT(checkEnabled())); connect(footerStatusCB, SIGNAL(clicked()), - this, SLOT(ltFooterStatus_clicked())); + this, SLOT(checkEnabled())); connect(footerBorderAboveCB, SIGNAL(clicked()), - this, SLOT(ltFooterBorderAbove_clicked())); + this, SLOT(checkEnabled())); connect(footerBorderBelowCB, SIGNAL(clicked()), - this, SLOT(ltFooterBorderBelow_clicked())); + this, SLOT(checkEnabled())); connect(lastfooterStatusCB, SIGNAL(clicked()), - this, SLOT(ltLastFooterStatus_clicked())); + this, SLOT(checkEnabled())); connect(lastfooterBorderAboveCB, SIGNAL(clicked()), - this, SLOT(ltLastFooterBorderAbove_clicked())); + this, SLOT(checkEnabled())); connect(lastfooterBorderBelowCB, SIGNAL(clicked()), - this, SLOT(ltLastFooterBorderBelow_clicked())); + this, SLOT(checkEnabled())); connect(lastfooterNoContentsCB, SIGNAL(clicked()), - this, SLOT(ltLastFooterEmpty_clicked())); + this, SLOT(checkEnabled())); connect(specialAlignmentED, SIGNAL(returnPressed()), - this, SLOT(specialAlignment_changed())); - connect(widthED, SIGNAL(editingFinished()), - this, SLOT(width_changed())); + this, SLOT(checkEnabled())); + connect(widthED, SIGNAL(textEdited(QString)), + this, SLOT(checkEnabled())); connect(widthUnitCB, SIGNAL(selectionChanged(lyx::Length::UNIT)), - this, SLOT(width_changed())); - connect(closePB, SIGNAL(clicked()), - this, SLOT(close_clicked())); + this, SLOT(checkEnabled())); connect(borders, SIGNAL(topSet(bool)), - this, SLOT(topBorder_changed())); + this, SLOT(checkEnabled())); connect(borders, SIGNAL(bottomSet(bool)), - this, SLOT(bottomBorder_changed())); + this, SLOT(checkEnabled())); connect(borders, SIGNAL(rightSet(bool)), - this, SLOT(rightBorder_changed())); + this, SLOT(checkEnabled())); connect(borders, SIGNAL(leftSet(bool)), - this, SLOT(leftBorder_changed())); + this, SLOT(checkEnabled())); connect(rotateTabularCB, SIGNAL(clicked()), - this, SLOT(rotateTabular())); + this, SLOT(checkEnabled())); connect(rotateCellCB, SIGNAL(clicked()), - this, SLOT(rotateCell())); + this, SLOT(checkEnabled())); connect(TableAlignCB, SIGNAL(activated(int)), - this, SLOT(tableAlignment_changed(int))); + this, SLOT(checkEnabled())); connect(longTabularCB, SIGNAL(clicked()), - this, SLOT(longTabular())); + this, SLOT(checkEnabled())); connect(leftRB, SIGNAL(clicked()), - this, SLOT(ltAlignment_clicked())); + this, SLOT(checkEnabled())); connect(centerRB, SIGNAL(clicked()), - this, SLOT(ltAlignment_clicked())); + this, SLOT(checkEnabled())); connect(rightRB, SIGNAL(clicked()), - this, SLOT(ltAlignment_clicked())); + this, SLOT(checkEnabled())); - bc().setPolicy(ButtonPolicy::IgnorantPolicy); - - bc().addReadOnly(topspaceED); - bc().addReadOnly(topspaceUnit); - bc().addReadOnly(topspaceCO); - bc().addReadOnly(bottomspaceED); - bc().addReadOnly(bottomspaceUnit); - bc().addReadOnly(bottomspaceCO); - bc().addReadOnly(interlinespaceED); - bc().addReadOnly(interlinespaceUnit); - bc().addReadOnly(interlinespaceCO); - bc().addReadOnly(borderDefaultRB); - bc().addReadOnly(booktabsRB); - - bc().addReadOnly(multicolumnCB); - bc().addReadOnly(multirowCB); - bc().addReadOnly(rotateCellCB); - bc().addReadOnly(rotateTabularCB); - bc().addReadOnly(specialAlignmentED); - bc().addReadOnly(widthED); - bc().addReadOnly(widthUnitCB); - bc().addReadOnly(hAlignCB); - bc().addReadOnly(vAlignCB); - bc().addReadOnly(TableAlignCB); - bc().addReadOnly(borderSetPB); - bc().addReadOnly(borderUnsetPB); - bc().addReadOnly(borders); - bc().addReadOnly(longTabularCB); - bc().addReadOnly(headerStatusCB); - bc().addReadOnly(headerBorderAboveCB); - bc().addReadOnly(headerBorderBelowCB); - bc().addReadOnly(firstheaderStatusCB); - bc().addReadOnly(firstheaderBorderAboveCB); - bc().addReadOnly(firstheaderBorderBelowCB); - bc().addReadOnly(firstheaderNoContentsCB); - bc().addReadOnly(footerStatusCB); - bc().addReadOnly(footerBorderAboveCB); - bc().addReadOnly(footerBorderBelowCB); - bc().addReadOnly(lastfooterStatusCB); - bc().addReadOnly(lastfooterBorderAboveCB); - bc().addReadOnly(lastfooterBorderBelowCB); - bc().addReadOnly(lastfooterNoContentsCB); - bc().addReadOnly(newpageCB); - bc().addReadOnly(leftRB); - bc().addReadOnly(centerRB); - bc().addReadOnly(rightRB); // initialize the length validator - bc().addCheckedLineEdit(widthED, fixedWidthColLA); - bc().addCheckedLineEdit(topspaceED, topspaceLA); - bc().addCheckedLineEdit(bottomspaceED, bottomspaceLA); - bc().addCheckedLineEdit(interlinespaceED, interlinespaceLA); -} - - -GuiTabular::~GuiTabular() -{ -} - - -void GuiTabular::change_adaptor() -{ - changed(); -} - - -void GuiTabular::booktabsChanged(bool) -{ - changed(); - booktabs(booktabsRB->isChecked()); - updateBorders(tabular_); -} - - -void GuiTabular::topspace_changed() -{ - switch (topspaceCO->currentIndex()) { - case 0: { - set(Tabular::SET_TOP_SPACE, ""); - topspaceED->setEnabled(false); - topspaceUnit->setEnabled(false); - break; - } - case 1: { - set(Tabular::SET_TOP_SPACE, "default"); - topspaceED->setEnabled(false); - topspaceUnit->setEnabled(false); - break; - } - case 2: { - if (!topspaceED->text().isEmpty()) - set(Tabular::SET_TOP_SPACE, - widgetsToLength(topspaceED, - topspaceUnit)); - if (!bc().policy().isReadOnly()) { - topspaceED->setEnabled(true); - topspaceUnit->setEnabled(true); - } - break; - } - } - changed(); -} - - -void GuiTabular::bottomspace_changed() -{ - switch (bottomspaceCO->currentIndex()) { - case 0: { - set(Tabular::SET_BOTTOM_SPACE, ""); - bottomspaceED->setEnabled(false); - bottomspaceUnit->setEnabled(false); - break; - } - case 1: { - set(Tabular::SET_BOTTOM_SPACE, "default"); - bottomspaceED->setEnabled(false); - bottomspaceUnit->setEnabled(false); - break; - } - case 2: { - if (!bottomspaceED->text().isEmpty()) - set(Tabular::SET_BOTTOM_SPACE, - widgetsToLength(bottomspaceED, - bottomspaceUnit)); - if (!bc().policy().isReadOnly()) { - bottomspaceED->setEnabled(true); - bottomspaceUnit->setEnabled(true); - } - break; - } - } - changed(); + addCheckedWidget(widthED, fixedWidthColLA); + addCheckedWidget(topspaceED, topspaceLA); + addCheckedWidget(bottomspaceED, bottomspaceLA); + addCheckedWidget(interlinespaceED, interlinespaceLA); } -void GuiTabular::interlinespace_changed() +void GuiTabular::checkEnabled() { - switch (interlinespaceCO->currentIndex()) { - case 0: { - set(Tabular::SET_INTERLINE_SPACE, ""); - interlinespaceED->setEnabled(false); - interlinespaceUnit->setEnabled(false); - break; - } - case 1: { - set(Tabular::SET_INTERLINE_SPACE, "default"); - interlinespaceED->setEnabled(false); - interlinespaceUnit->setEnabled(false); - break; - } - case 2: { - if (!interlinespaceED->text().isEmpty()) - set(Tabular::SET_INTERLINE_SPACE, - widgetsToLength(interlinespaceED, - interlinespaceUnit)); - if (!bc().policy().isReadOnly()) { - interlinespaceED->setEnabled(true); - interlinespaceUnit->setEnabled(true); - } - break; - } - } + topspaceED->setEnabled(topspaceCO->currentIndex() == 2); + topspaceUnit->setEnabled(topspaceCO->currentIndex() == 2); + bottomspaceED->setEnabled(bottomspaceCO->currentIndex() == 2); + bottomspaceUnit->setEnabled(bottomspaceCO->currentIndex() == 2); + interlinespaceED->setEnabled(interlinespaceCO->currentIndex() == 2); + interlinespaceUnit->setEnabled(interlinespaceCO->currentIndex() == 2); changed(); } -void GuiTabular::close_clicked() -{ - closeGUI(tabular_); - slotClose(); -} - - void GuiTabular::borderSet_clicked() { - set(Tabular::SET_ALL_LINES); - updateBorders(tabular_); - changed(); + borders->setTop(true); + borders->setBottom(true); + borders->setLeft(true); + borders->setRight(true); + // repaint the setborder widget + borders->update(); + checkEnabled(); } void GuiTabular::borderUnset_clicked() { - set(Tabular::UNSET_ALL_LINES); - updateBorders(tabular_); - changed(); -} - - -void GuiTabular::leftBorder_changed() -{ - set(Tabular::TOGGLE_LINE_LEFT); - changed(); -} - - -void GuiTabular::rightBorder_changed() -{ - set(Tabular::TOGGLE_LINE_RIGHT); - changed(); -} - - -void GuiTabular::topBorder_changed() -{ - set(Tabular::TOGGLE_LINE_TOP); - changed(); -} - - -void GuiTabular::bottomBorder_changed() -{ - set(Tabular::TOGGLE_LINE_BOTTOM); - changed(); + borders->setTop(false); + borders->setBottom(false); + borders->setLeft(false); + borders->setRight(false); + // repaint the setborder widget + borders->update(); + checkEnabled(); } -void GuiTabular::specialAlignment_changed() +static void setParam(string & param_str, Tabular::Feature f, string const & arg = string()) { - string special = fromqstr(specialAlignmentED->text()); - setSpecial(tabular_, special); - changed(); + param_str += ' '; + param_str += featureAsString(f) + ' ' + arg; } -void GuiTabular::width_changed() +// to get the status of the longtable row settings +static bool funcEnabled(Tabular::Feature f) { - changed(); - string const width = widgetsToLength(widthED, widthUnitCB); - setWidth(tabular_, width); + return getStatus( + FuncRequest(LFUN_INSET_MODIFY, featureAsString(f))).enabled(); } -void GuiTabular::multicolumn_clicked() +void GuiTabular::setHAlign(string & param_str) const { - toggleMultiColumn(); - changed(); -} + int const align = hAlignCB->currentIndex(); -void GuiTabular::multirow_clicked() -{ - toggleMultiRow(); - changed(); -} + enum HALIGN { LEFT, RIGHT, CENTER, BLOCK }; + HALIGN h = LEFT; + switch (align) { + case 0: h = LEFT; break; + case 1: h = CENTER; break; + case 2: h = RIGHT; break; + case 3: h = BLOCK; break; + } -void GuiTabular::rotateTabular() -{ - rotateTabular(rotateTabularCB->isChecked()); - changed(); -} + Tabular::Feature num = Tabular::ALIGN_LEFT; + Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT; + switch (h) { + case LEFT: + num = Tabular::ALIGN_LEFT; + multi_num = Tabular::M_ALIGN_LEFT; + break; + case CENTER: + num = Tabular::ALIGN_CENTER; + multi_num = Tabular::M_ALIGN_CENTER; + break; + case RIGHT: + num = Tabular::ALIGN_RIGHT; + multi_num = Tabular::M_ALIGN_RIGHT; + break; + case BLOCK: + num = Tabular::ALIGN_BLOCK; + //multi_num: no equivalent + break; + } -void GuiTabular::rotateCell() -{ - rotateCell(rotateCellCB->isChecked()); - changed(); + if (multicolumnCB->isChecked()) + setParam(param_str, multi_num); + else + setParam(param_str, num); } -void GuiTabular::hAlign_changed(int align) +void GuiTabular::setVAlign(string & param_str) const { - GuiTabular::HALIGN h = GuiTabular::LEFT; + int const align = vAlignCB->currentIndex(); + enum VALIGN { TOP, MIDDLE, BOTTOM }; + VALIGN v = TOP; switch (align) { - case 0: h = GuiTabular::LEFT; break; - case 1: h = GuiTabular::CENTER; break; - case 2: h = GuiTabular::RIGHT; break; - case 3: h = GuiTabular::BLOCK; break; + case 0: v = TOP; break; + case 1: v = MIDDLE; break; + case 2: v = BOTTOM; break; } - halign(tabular_, h); -} - - -void GuiTabular::vAlign_changed(int align) -{ - GuiTabular::VALIGN v = GuiTabular::TOP; + Tabular::Feature num = Tabular::VALIGN_MIDDLE; + Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE; - switch (align) { - case 0: v = GuiTabular::TOP; break; - case 1: v = GuiTabular::MIDDLE; break; - case 2: v = GuiTabular::BOTTOM; break; + switch (v) { + case TOP: + num = Tabular::VALIGN_TOP; + multi_num = Tabular::M_VALIGN_TOP; + break; + case MIDDLE: + num = Tabular::VALIGN_MIDDLE; + multi_num = Tabular::M_VALIGN_MIDDLE; + break; + case BOTTOM: + num = Tabular::VALIGN_BOTTOM; + multi_num = Tabular::M_VALIGN_BOTTOM; + break; } - - valign(tabular_, v); + if (multicolumnCB->isChecked() || multirowCB->isChecked()) + setParam(param_str, multi_num); + else + setParam(param_str, num); } -void GuiTabular::tableAlignment_changed(int align) +void GuiTabular::setTableAlignment(string & param_str) const { + int const align = TableAlignCB->currentIndex(); switch (align) { - case 0: set(Tabular::TABULAR_VALIGN_TOP); + case 0: setParam(param_str, Tabular::TABULAR_VALIGN_TOP); break; - case 1: set(Tabular::TABULAR_VALIGN_MIDDLE); + case 1: setParam(param_str, Tabular::TABULAR_VALIGN_MIDDLE); break; - case 2: set(Tabular::TABULAR_VALIGN_BOTTOM); + case 2: setParam(param_str, Tabular::TABULAR_VALIGN_BOTTOM); break; } } -void GuiTabular::longTabular() +docstring GuiTabular::dialogToParams() const { - longTabular(longTabularCB->isChecked()); - changed(); -} + // FIXME: We should use Tabular directly. + string param_str = "tabular"; + setHAlign(param_str); + setVAlign(param_str); + setTableAlignment(param_str); + // + if (booktabsRB->isChecked()) + setParam(param_str, Tabular::SET_BOOKTABS); + else + setParam(param_str, Tabular::UNSET_BOOKTABS); + // + switch (topspaceCO->currentIndex()) { + case 0: + setParam(param_str, Tabular::SET_TOP_SPACE, "none"); + break; + case 1: + setParam(param_str, Tabular::SET_TOP_SPACE, "default"); + break; + case 2: + if (!topspaceED->text().isEmpty()) + setParam(param_str, Tabular::SET_TOP_SPACE, + widgetsToLength(topspaceED, topspaceUnit)); + break; + } -void GuiTabular::ltNewpage_clicked() -{ - set(Tabular::SET_LTNEWPAGE); - changed(); -} + // + switch (bottomspaceCO->currentIndex()) { + case 0: + setParam(param_str, Tabular::SET_BOTTOM_SPACE, "none"); + break; + case 1: + setParam(param_str, Tabular::SET_BOTTOM_SPACE, "default"); + break; + case 2: + if (!bottomspaceED->text().isEmpty()) + setParam(param_str, Tabular::SET_BOTTOM_SPACE, + widgetsToLength(bottomspaceED, + bottomspaceUnit)); + break; + } + // + switch (interlinespaceCO->currentIndex()) { + case 0: + setParam(param_str, Tabular::SET_INTERLINE_SPACE, "none"); + break; + case 1: + setParam(param_str, Tabular::SET_INTERLINE_SPACE, "default"); + break; + case 2: + if (!interlinespaceED->text().isEmpty()) + setParam(param_str, Tabular::SET_INTERLINE_SPACE, + widgetsToLength(interlinespaceED, + interlinespaceUnit)); + break; + } -void GuiTabular::on_captionStatusCB_toggled() -{ - set(Tabular::TOGGLE_LTCAPTION); - changed(); -} + // + if (borders->getTop() && borders->getBottom() && borders->getLeft() + && borders->getRight()) + setParam(param_str, Tabular::SET_ALL_LINES); + else if (!borders->getTop() && !borders->getBottom() && !borders->getLeft() + && !borders->getRight()) + setParam(param_str, Tabular::UNSET_ALL_LINES); + else if (borders->getLeft()) + setParam(param_str, Tabular::TOGGLE_LINE_LEFT); + else if (borders->getRight()) + setParam(param_str, Tabular::TOGGLE_LINE_RIGHT); + else if (borders->getTop()) + setParam(param_str, Tabular::TOGGLE_LINE_TOP); + else if (borders->getBottom()) + setParam(param_str, Tabular::TOGGLE_LINE_BOTTOM); -void GuiTabular::ltHeaderStatus_clicked() -{ - bool enable = headerStatusCB->isChecked(); - if (enable) - set(Tabular::SET_LTHEAD, ""); + // apply the special alignment + string special = fromqstr(specialAlignmentED->text()); + if (special.empty()) + special = "none"; + if (multicolumnCB->isChecked()) + setParam(param_str, Tabular::SET_SPECIAL_MULTICOLUMN, special); + else if (multirowCB->isChecked()) + setParam(param_str, Tabular::SET_SPECIAL_MULTIROW, special); else - set(Tabular::UNSET_LTHEAD, ""); - changed(); -} + setParam(param_str, Tabular::SET_SPECIAL_COLUMN, special); + // apply the fixed width values + string width = widgetsToLength(widthED, widthUnitCB); + if (width.empty()) + width = "0pt"; + if (multicolumnCB->isChecked()) + setParam(param_str, Tabular::SET_MPWIDTH, width); + else + setParam(param_str, Tabular::SET_PWIDTH, width); -void GuiTabular::ltHeaderBorderAbove_clicked() -{ + // + if (multicolumnCB->isChecked()) + setParam(param_str, Tabular::MULTICOLUMN); + // + if (multirowCB->isChecked()) + setParam(param_str, Tabular::MULTIROW); + // + if (rotateTabularCB->isChecked()) + setParam(param_str, Tabular::SET_ROTATE_TABULAR); + else + setParam(param_str, Tabular::UNSET_ROTATE_TABULAR); + // + if (rotateCellCB->isChecked()) + setParam(param_str, Tabular::SET_ROTATE_CELL); + else + setParam(param_str, Tabular::UNSET_ROTATE_CELL); + // + if (longTabularCB->isChecked()) + setParam(param_str, Tabular::SET_LONGTABULAR); + else + setParam(param_str, Tabular::UNSET_LONGTABULAR); + // + if (newpageCB->isChecked()) + setParam(param_str, Tabular::SET_LTNEWPAGE); + // + if (captionStatusCB->isChecked()) + setParam(param_str, Tabular::TOGGLE_LTCAPTION); + // + if (headerStatusCB->isChecked()) + setParam(param_str, Tabular::SET_LTHEAD, "none"); + else + setParam(param_str, Tabular::UNSET_LTHEAD, "none"); + // if (headerBorderAboveCB->isChecked()) - set(Tabular::SET_LTHEAD, "dl_above"); + setParam(param_str, Tabular::SET_LTHEAD, "dl_above"); else - set(Tabular::UNSET_LTHEAD, "dl_above"); - changed(); -} - - -void GuiTabular::ltHeaderBorderBelow_clicked() -{ + setParam(param_str, Tabular::UNSET_LTHEAD, "dl_above"); + // if (headerBorderBelowCB->isChecked()) - set(Tabular::SET_LTHEAD, "dl_below"); + setParam(param_str, Tabular::SET_LTHEAD, "dl_below"); else - set(Tabular::UNSET_LTHEAD, "dl_below"); - changed(); -} - - -void GuiTabular::ltFirstHeaderBorderAbove_clicked() -{ + setParam(param_str, Tabular::UNSET_LTHEAD, "dl_below"); if (firstheaderBorderAboveCB->isChecked()) - set(Tabular::SET_LTFIRSTHEAD, "dl_above"); + setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_above"); else - set(Tabular::UNSET_LTFIRSTHEAD, "dl_above"); - changed(); -} - - -void GuiTabular::ltFirstHeaderBorderBelow_clicked() -{ + setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_above"); if (firstheaderBorderBelowCB->isChecked()) - set(Tabular::SET_LTFIRSTHEAD, "dl_below"); + setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_below"); else - set(Tabular::UNSET_LTFIRSTHEAD, "dl_below"); - changed(); -} - - -void GuiTabular::ltFirstHeaderStatus_clicked() -{ - bool enable = firstheaderStatusCB->isChecked(); - if (enable) - set(Tabular::SET_LTFIRSTHEAD, ""); + setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_below"); + if (firstheaderStatusCB->isChecked()) + setParam(param_str, Tabular::SET_LTFIRSTHEAD, "none"); else - set(Tabular::UNSET_LTFIRSTHEAD, ""); - changed(); -} - - -void GuiTabular::ltFirstHeaderEmpty_clicked() -{ - bool enable = firstheaderNoContentsCB->isChecked(); - if (enable) - set(Tabular::SET_LTFIRSTHEAD, "empty"); + setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "none"); + if (firstheaderNoContentsCB->isChecked()) + setParam(param_str, Tabular::SET_LTFIRSTHEAD, "empty"); else - set(Tabular::UNSET_LTFIRSTHEAD, "empty"); - changed(); -} - - -void GuiTabular::ltFooterStatus_clicked() -{ - bool enable = footerStatusCB->isChecked(); - if (enable) - set(Tabular::SET_LTFOOT, ""); + setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "empty"); + if (footerStatusCB->isChecked()) + setParam(param_str, Tabular::SET_LTFOOT, "none"); else - set(Tabular::UNSET_LTFOOT, ""); - changed(); -} - - -void GuiTabular::ltFooterBorderAbove_clicked() -{ + setParam(param_str, Tabular::UNSET_LTFOOT, "none"); if (footerBorderAboveCB->isChecked()) - set(Tabular::SET_LTFOOT, "dl_above"); + setParam(param_str, Tabular::SET_LTFOOT, "dl_above"); else - set(Tabular::UNSET_LTFOOT, "dl_above"); - changed(); -} - - -void GuiTabular::ltFooterBorderBelow_clicked() -{ + setParam(param_str, Tabular::UNSET_LTFOOT, "dl_above"); if (footerBorderBelowCB->isChecked()) - set(Tabular::SET_LTFOOT, "dl_below"); + setParam(param_str, Tabular::SET_LTFOOT, "dl_below"); else - set(Tabular::UNSET_LTFOOT, "dl_below"); - changed(); -} - - -void GuiTabular::ltLastFooterStatus_clicked() -{ - bool enable = lastfooterStatusCB->isChecked(); - if (enable) - set(Tabular::SET_LTLASTFOOT, ""); + setParam(param_str, Tabular::UNSET_LTFOOT, "dl_below"); + if (lastfooterStatusCB->isChecked()) + setParam(param_str, Tabular::SET_LTLASTFOOT, "none"); else - set(Tabular::UNSET_LTLASTFOOT, ""); - changed(); -} - - -void GuiTabular::ltLastFooterBorderAbove_clicked() -{ + setParam(param_str, Tabular::UNSET_LTLASTFOOT, "none"); if (lastfooterBorderAboveCB->isChecked()) - set(Tabular::SET_LTLASTFOOT, "dl_above"); + setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_above"); else - set(Tabular::UNSET_LTLASTFOOT, "dl_above"); - changed(); -} - - -void GuiTabular::ltLastFooterBorderBelow_clicked() -{ + setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_above"); if (lastfooterBorderBelowCB->isChecked()) - set(Tabular::SET_LTLASTFOOT, "dl_below"); + setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_below"); else - set(Tabular::UNSET_LTLASTFOOT, "dl_below"); - changed(); -} - - -void GuiTabular::ltLastFooterEmpty_clicked() -{ - bool enable = lastfooterNoContentsCB->isChecked(); - if (enable) - set(Tabular::SET_LTLASTFOOT, "empty"); + setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_below"); + if (lastfooterNoContentsCB->isChecked()) + setParam(param_str, Tabular::SET_LTLASTFOOT, "empty"); else - set(Tabular::UNSET_LTLASTFOOT, "empty"); - changed(); -} + setParam(param_str, Tabular::UNSET_LTLASTFOOT, "empty"); - -void GuiTabular::ltAlignment_clicked() -{ if (leftRB->isChecked()) - set(Tabular::LONGTABULAR_ALIGN_LEFT); + setParam(param_str, Tabular::LONGTABULAR_ALIGN_LEFT); else if (centerRB->isChecked()) - set(Tabular::LONGTABULAR_ALIGN_CENTER); + setParam(param_str, Tabular::LONGTABULAR_ALIGN_CENTER); else if (rightRB->isChecked()) - set(Tabular::LONGTABULAR_ALIGN_RIGHT); - changed(); -} + setParam(param_str, Tabular::LONGTABULAR_ALIGN_RIGHT); - -void GuiTabular::updateBorders(Tabular const & tabular) -{ - Tabular::idx_type const cell = getActiveCell(); - borders->setTop(tabular.topLine(cell)); - borders->setBottom(tabular.bottomLine(cell)); - borders->setLeft(tabular.leftLine(cell)); - borders->setRight(tabular.rightLine(cell)); - // repaint the setborder widget - borders->update(); + return from_utf8(param_str); } -namespace { - -Length getColumnPWidth(Tabular const & t, size_t cell) +static Length getColumnPWidth(Tabular const & t, size_t cell) { return t.column_info[t.cellColumn(cell)].p_width; } -Length getMColumnPWidth(Tabular const & t, size_t cell) +static Length getMColumnPWidth(Tabular const & t, size_t cell) { if (t.isMultiColumn(cell) || t.isMultiRow(cell)) return t.cellInfo(cell).p_width; @@ -669,7 +518,7 @@ Length getMColumnPWidth(Tabular const & t, size_t cell) } -docstring getAlignSpecial(Tabular const & t, size_t cell, int what) +static docstring getAlignSpecial(Tabular const & t, size_t cell, int what) { if (what == Tabular::SET_SPECIAL_MULTICOLUMN || what == Tabular::SET_SPECIAL_MULTIROW) @@ -677,19 +526,15 @@ docstring getAlignSpecial(Tabular const & t, size_t cell, int what) return t.column_info[t.cellColumn(cell)].align_special; } -} - -void GuiTabular::updateContents() +void GuiTabular::paramsToDialog(Inset const * inset) { - initialiseParams(string()); - paramsToDialog(tabular_); -} + InsetTabular const * itab = static_cast(inset); + // Copy Tabular of current inset. + Tabular const & tabular = itab->tabular; - -void GuiTabular::paramsToDialog(Tabular const & tabular) -{ - size_t const cell = getActiveCell(); + BufferView const * bv = guiApp->currentView()->currentBufferView(); + size_t const cell = bv->cursor().idx(); Tabular::row_type const row = tabular.cellRow(cell); Tabular::col_type const col = tabular.cellColumn(cell); @@ -697,10 +542,10 @@ void GuiTabular::paramsToDialog(Tabular const & tabular) tabularRowED->setText(QString::number(row + 1)); tabularColumnED->setText(QString::number(col + 1)); - bool const multicol(tabular.isMultiColumn(cell)); + bool const multicol = tabular.isMultiColumn(cell); multicolumnCB->setChecked(multicol); - bool const multirow(tabular.isMultiRow(cell)); + bool const multirow = tabular.isMultiRow(cell); multirowCB->setChecked(multirow); rotateCellCB->setChecked(tabular.getRotateCell(cell)); @@ -708,7 +553,13 @@ void GuiTabular::paramsToDialog(Tabular const & tabular) longTabularCB->setChecked(tabular.is_long_tabular); - updateBorders(tabular); + // + borders->setTop(tabular.topLine(cell)); + borders->setBottom(tabular.bottomLine(cell)); + borders->setLeft(tabular.leftLine(cell)); + borders->setRight(tabular.rightLine(cell)); + // repaint the setborder widget + borders->update(); Length pwidth; docstring special; @@ -729,9 +580,6 @@ void GuiTabular::paramsToDialog(Tabular const & tabular) specialAlignmentED->setText(toqstr(special)); - bool const isReadonly = bc().policy().isReadOnly(); - specialAlignmentED->setEnabled(!isReadonly); - Length::UNIT const default_unit = Length::defaultUnit(); borderDefaultRB->setChecked(!tabular.use_booktabs); @@ -749,11 +597,6 @@ void GuiTabular::paramsToDialog(Tabular const & tabular) tabular.row_info[row].top_space.asString(), default_unit); } - topspaceED->setEnabled(!isReadonly - && (topspaceCO->currentIndex() == 2)); - topspaceUnit->setEnabled(!isReadonly - && (topspaceCO->currentIndex() == 2)); - topspaceCO->setEnabled(!isReadonly); if (tabular.row_info[row].bottom_space.empty() && !tabular.row_info[row].bottom_space_default) { @@ -767,11 +610,6 @@ void GuiTabular::paramsToDialog(Tabular const & tabular) tabular.row_info[row].bottom_space.asString(), default_unit); } - bottomspaceED->setEnabled(!isReadonly - && (bottomspaceCO->currentIndex() == 2)); - bottomspaceUnit->setEnabled(!isReadonly - && (bottomspaceCO->currentIndex() == 2)); - bottomspaceCO->setEnabled(!isReadonly); if (tabular.row_info[row].interline_space.empty() && !tabular.row_info[row].interline_space_default) { @@ -785,12 +623,6 @@ void GuiTabular::paramsToDialog(Tabular const & tabular) tabular.row_info[row].interline_space.asString(), default_unit); } - interlinespaceED->setEnabled(!isReadonly - && (interlinespaceCO->currentIndex() == 2)); - interlinespaceUnit->setEnabled(!isReadonly - && (interlinespaceCO->currentIndex() == 2)); - interlinespaceCO->setEnabled(!isReadonly); - string colwidth; if (!pwidth.zero()) { colwidth = pwidth.asString(); @@ -799,9 +631,6 @@ void GuiTabular::paramsToDialog(Tabular const & tabular) colwidth, default_unit); } - widthED->setEnabled(!isReadonly); - widthUnitCB->setEnabled(!isReadonly); - hAlignCB->clear(); hAlignCB->addItem(qt_("Left")); hAlignCB->addItem(qt_("Center")); @@ -893,10 +722,10 @@ void GuiTabular::paramsToDialog(Tabular const & tabular) captionStatusCB->setChecked(false); captionStatusCB->blockSignals(false); return; - } else + } else { // longtables cannot have a vertical alignment TableAlignCB->setCurrentIndex(Tabular::LYX_VALIGN_MIDDLE); - + } switch (tabular.longtabular_alignment) { case Tabular::LYX_LONGTABULAR_ALIGN_LEFT: leftRB->setChecked(true); @@ -1031,304 +860,6 @@ void GuiTabular::paramsToDialog(Tabular const & tabular) } -void GuiTabular::closeGUI(Tabular const & tabular) -{ - // ugly hack to auto-apply the stuff that hasn't been - // yet. don't let this continue to exist ... - - // Subtle here, we must /not/ apply any changes and - // then refer to tabular, as it will have been freed - // since the changes update the actual tabular_ - // - // apply the fixed width values - size_t const cell = getActiveCell(); - bool const multicol = tabular.isMultiColumn(cell); - bool const multirow = tabular.isMultiRow(cell); - string width = widgetsToLength(widthED, widthUnitCB); - string width2; - - Length llen = getColumnPWidth(tabular, cell); - Length llenMulti = getMColumnPWidth(tabular, cell); - - if (multicol && multirow && !llenMulti.zero()) - width2 = llenMulti.asString(); - else if (!multicol && !multirow && !llen.zero()) - width2 = llen.asString(); - - // apply the special alignment - docstring const sa1 = qstring_to_ucs4(specialAlignmentED->text()); - docstring sa2; - - if (multicol) - sa2 = getAlignSpecial(tabular, cell, - Tabular::SET_SPECIAL_MULTICOLUMN); - else if (multirow) - sa2 = getAlignSpecial(tabular, cell, - Tabular::SET_SPECIAL_MULTIROW); - else - sa2 = getAlignSpecial(tabular, cell, - Tabular::SET_SPECIAL_COLUMN); - - if (sa1 != sa2) { - if (multicol) - set(Tabular::SET_SPECIAL_MULTICOLUMN, to_utf8(sa1)); - if (multirow) - set(Tabular::SET_SPECIAL_MULTIROW, to_utf8(sa1)); - else - set(Tabular::SET_SPECIAL_COLUMN, to_utf8(sa1)); - } - - if (width != width2) { - if (multicol) - set(Tabular::SET_MPWIDTH, width); - else - set(Tabular::SET_PWIDTH, width); - } - - /* DO WE NEED THIS? - switch (topspaceCO->currentIndex()) { - case 0: - set(Tabular::SET_TOP_SPACE, ""); - break; - case 1: - set(Tabular::SET_TOP_SPACE, "default"); - break; - case 2: - set(Tabular::SET_TOP_SPACE, - widgetsToLength(topspaceED, - topspaceUnit)); - break; - } - - switch (bottomspaceCO->currentIndex()) { - case 0: - set(Tabular::SET_BOTTOM_SPACE, ""); - break; - case 1: - set(Tabular::SET_BOTTOM_SPACE, "default"); - break; - case 2: - set(Tabular::SET_BOTTOM_SPACE, - widgetsToLength(bottomspaceED, - bottomspaceUnit)); - break; - } - - switch (interlinespaceCO->currentIndex()) { - case 0: - set(Tabular::SET_INTERLINE_SPACE, ""); - break; - case 1: - set(Tabular::SET_INTERLINE_SPACE, "default"); - break; - case 2: - set(Tabular::SET_INTERLINE_SPACE, - widgetsToLength(interlinespaceED, - interlinespaceUnit)); - break; - } -*/ -} - - -bool GuiTabular::initialiseParams(string const & data) -{ - // try to get the current cell - BufferView const * const bv = bufferview(); - InsetTabular const * current_inset = 0; - if (bv) { - Cursor const & cur = bv->cursor(); - // get the innermost tabular inset; - // assume that it is "ours" - for (int i = cur.depth() - 1; i >= 0; --i) - if (cur[i].inset().lyxCode() == TABULAR_CODE) { - current_inset = - static_cast(&cur[i].inset()); - active_cell_ = cur[i].idx(); - break; - } - } - - if (current_inset && data.empty()) { - tabular_ = Tabular(current_inset->tabular); - return true; - } - - InsetTabular tmp(const_cast(&buffer())); - InsetTabular::string2params(data, tmp); - tabular_ = Tabular(tmp.tabular); - return true; -} - - -void GuiTabular::clearParams() -{ - // This function is also called when LyX is closing and the dialog - // is still open. At that time, the buffer might not be available - // anymore. - if (isBufferAvailable()) { - InsetTabular tmp(const_cast(&buffer())); - tabular_ = tmp.tabular; - } - active_cell_ = Tabular::npos; -} - - -Tabular::idx_type GuiTabular::getActiveCell() const -{ - return active_cell_; -} - - -void GuiTabular::set(Tabular::Feature f, string const & arg) -{ - string const data = featureAsString(f) + ' ' + arg; - dispatch(FuncRequest(getLfun(), data)); -} - - -void GuiTabular::setSpecial(Tabular const & tabular, string const & special) -{ - if (tabular.isMultiColumn(getActiveCell())) - set(Tabular::SET_SPECIAL_MULTICOLUMN, special); - else if (tabular.isMultiRow(getActiveCell())) - set(Tabular::SET_SPECIAL_MULTIROW, special); - else - set(Tabular::SET_SPECIAL_COLUMN, special); -} - - -void GuiTabular::setWidth(Tabular const & tabular, string const & width) -{ - if (tabular.isMultiColumn(getActiveCell())) - set(Tabular::SET_MPWIDTH, width); - else - set(Tabular::SET_PWIDTH, width); - - updateView(); -} - - -void GuiTabular::toggleMultiColumn() -{ - set(Tabular::MULTICOLUMN); - updateView(); -} - - -void GuiTabular::toggleMultiRow() -{ - set(Tabular::MULTIROW); - updateView(); -} - - -void GuiTabular::rotateTabular(bool yes) -{ - if (yes) - set(Tabular::SET_ROTATE_TABULAR); - else - set(Tabular::UNSET_ROTATE_TABULAR); -} - - -void GuiTabular::rotateCell(bool yes) -{ - if (yes) - set(Tabular::SET_ROTATE_CELL); - else - set(Tabular::UNSET_ROTATE_CELL); -} - - -void GuiTabular::halign(Tabular const & tabular, GuiTabular::HALIGN h) -{ - Tabular::Feature num = Tabular::ALIGN_LEFT; - Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT; - - switch (h) { - case LEFT: - num = Tabular::ALIGN_LEFT; - multi_num = Tabular::M_ALIGN_LEFT; - break; - case CENTER: - num = Tabular::ALIGN_CENTER; - multi_num = Tabular::M_ALIGN_CENTER; - break; - case RIGHT: - num = Tabular::ALIGN_RIGHT; - multi_num = Tabular::M_ALIGN_RIGHT; - break; - case BLOCK: - num = Tabular::ALIGN_BLOCK; - //multi_num: no equivalent - break; - } - - if (tabular.isMultiColumn(getActiveCell())) - set(multi_num); - else - set(num); -} - - -void GuiTabular::valign(Tabular const & tabular, GuiTabular::VALIGN v) -{ - Tabular::Feature num = Tabular::VALIGN_MIDDLE; - Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE; - - switch (v) { - case TOP: - num = Tabular::VALIGN_TOP; - multi_num = Tabular::M_VALIGN_TOP; - break; - case MIDDLE: - num = Tabular::VALIGN_MIDDLE; - multi_num = Tabular::M_VALIGN_MIDDLE; - break; - case BOTTOM: - num = Tabular::VALIGN_BOTTOM; - multi_num = Tabular::M_VALIGN_BOTTOM; - break; - } - - if (tabular.isMultiColumn(getActiveCell()) - || tabular.isMultiRow(getActiveCell())) - set(multi_num); - else - set(num); -} - - -void GuiTabular::booktabs(bool yes) -{ - if (yes) - set(Tabular::SET_BOOKTABS); - else - set(Tabular::UNSET_BOOKTABS); -} - - -void GuiTabular::longTabular(bool yes) -{ - if (yes) - set(Tabular::SET_LONGTABULAR); - else - set(Tabular::UNSET_LONGTABULAR); -} - - -// to get the status of the longtable row settings -bool GuiTabular::funcEnabled(Tabular::Feature f) const -{ - return getStatus( - FuncRequest(getLfun(), featureAsString(f))).enabled(); -} - - -Dialog * createGuiTabular(GuiView & lv) { return new GuiTabular(lv); } - - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiTabular.h b/src/frontends/qt4/GuiTabular.h index 4dcd13534b..ac5f353bdf 100644 --- a/src/frontends/qt4/GuiTabular.h +++ b/src/frontends/qt4/GuiTabular.h @@ -15,118 +15,39 @@ #ifndef GUITABULAR_H #define GUITABULAR_H -#include "GuiDialog.h" +#include "InsetParamsWidget.h" #include "ui_TabularUi.h" -#include "insets/InsetTabular.h" namespace lyx { namespace frontend { -class GuiTabular : public GuiDialog, public Ui::TabularUi +class GuiTabular : public InsetParamsWidget, public Ui::TabularUi { Q_OBJECT public: - GuiTabular(GuiView & lv); - ~GuiTabular(); + GuiTabular(QWidget * parent = 0); private Q_SLOTS: - void change_adaptor(); - - void topspace_changed(); - void bottomspace_changed(); - void interlinespace_changed(); - void booktabsChanged(bool); - void close_clicked(); + void checkEnabled(); void borderSet_clicked(); void borderUnset_clicked(); - void leftBorder_changed(); - void rightBorder_changed(); - void topBorder_changed(); - void bottomBorder_changed(); - void multicolumn_clicked(); - void multirow_clicked(); - void rotateTabular(); - void rotateCell(); - void hAlign_changed(int align); - void vAlign_changed(int align); - void tableAlignment_changed(int align); - void specialAlignment_changed(); - void width_changed(); - void longTabular(); - void ltNewpage_clicked(); - void ltHeaderStatus_clicked(); - void ltHeaderBorderAbove_clicked(); - void ltHeaderBorderBelow_clicked(); - void ltFirstHeaderStatus_clicked(); - void ltFirstHeaderBorderAbove_clicked(); - void ltFirstHeaderBorderBelow_clicked(); - void ltFirstHeaderEmpty_clicked(); - void ltFooterStatus_clicked(); - void ltFooterBorderAbove_clicked(); - void ltFooterBorderBelow_clicked(); - void ltLastFooterStatus_clicked(); - void ltLastFooterBorderAbove_clicked(); - void ltLastFooterBorderBelow_clicked(); - void ltLastFooterEmpty_clicked(); - void ltAlignment_clicked(); - void on_captionStatusCB_toggled(); private: - /// - bool isValid() { return true; } - /// update borders - void updateBorders(Tabular const & tabular); - /// update - void updateContents(); - /// - void paramsToDialog(Tabular const & tabular); - /// save some values before closing the gui - void closeGUI(Tabular const & tabular); - /// - bool initialiseParams(std::string const & data); - /// clean-up on hide. - void clearParams(); - /// We use set() instead. - void dispatchParams() {}; - /// - bool isBufferDependent() const { return true; } - /// - FuncCode getLfun() const { return LFUN_TABULAR_FEATURE; } + /// \name InsetParamsWidget inherited methods + //@{ + InsetCode insetCode() const { return TABULAR_CODE; } + FuncCode creationCode() const { return LFUN_TABULAR_INSERT; } + void paramsToDialog(Inset const *); + docstring dialogToParams() const; + //@} /// - Tabular::idx_type getActiveCell() const; - /// set a parameter - void set(Tabular::Feature, std::string const & arg = std::string()); - - void setSpecial(Tabular const & tabular, std::string const & special); - - void setWidth(Tabular const & tabular, std::string const & width); - - void toggleMultiColumn(); - void toggleMultiRow(); - - void rotateTabular(bool yes); - void rotateCell(bool yes); - - enum HALIGN { LEFT, RIGHT, CENTER, BLOCK }; - - void halign(Tabular const & tabular, HALIGN h); - - enum VALIGN { TOP, MIDDLE, BOTTOM }; - - void valign(Tabular const & tabular, VALIGN h); - - void booktabs(bool yes); - - void longTabular(bool yes); - - bool funcEnabled(Tabular::Feature f) const; - + void setHAlign(std::string & param_str) const; /// - Tabular::idx_type active_cell_; + void setVAlign(std::string & param_str) const; /// - Tabular tabular_; + void setTableAlignment(std::string & param_str) const; }; } // namespace frontend diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index c5f51c5b23..d440b6c114 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -3476,7 +3476,6 @@ Dialog * createGuiShowFile(GuiView & lv); Dialog * createGuiSpellchecker(GuiView & lv); Dialog * createGuiSymbols(GuiView & lv); Dialog * createGuiTabularCreate(GuiView & lv); -Dialog * createGuiTabular(GuiView & lv); Dialog * createGuiTexInfo(GuiView & lv); Dialog * createGuiTextHSpace(GuiView & lv); Dialog * createGuiToc(GuiView & lv); @@ -3570,8 +3569,6 @@ Dialog * GuiView::build(string const & name) return createGuiSpellchecker(*this); if (name == "symbols") return createGuiSymbols(*this); - if (name == "tabular") - return createGuiTabular(*this); if (name == "tabularcreate") return createGuiTabularCreate(*this); if (name == "texinfo") diff --git a/src/frontends/qt4/InsetParamsDialog.cpp b/src/frontends/qt4/InsetParamsDialog.cpp index 82d371e629..33344c7675 100644 --- a/src/frontends/qt4/InsetParamsDialog.cpp +++ b/src/frontends/qt4/InsetParamsDialog.cpp @@ -195,12 +195,9 @@ Dialog * createDialog(GuiView & lv, InsetCode code) case INFO_CODE: widget = new GuiInfo; break; - //FIXME: not ready yet. - /* case TABULAR_CODE: widget = new GuiTabular; break; - */ case VSPACE_CODE: widget = new GuiVSpace; break; diff --git a/src/frontends/qt4/ui/TabularUi.ui b/src/frontends/qt4/ui/TabularUi.ui index 7aa451d851..51aaa50481 100644 --- a/src/frontends/qt4/ui/TabularUi.ui +++ b/src/frontends/qt4/ui/TabularUi.ui @@ -1,18 +1,19 @@ + TabularUi - + 0 0 - 378 - 401 + 397 + 429 - + true @@ -97,22 +98,6 @@ - - - - - 0 - 0 - - - - Close - - - false - - - @@ -1519,7 +1504,6 @@ multirowCB rotateCellCB specialAlignmentED - closePB borderSetPB borderUnsetPB borderDefaultRB diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index 7edf4df634..b3fdf6fd94 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -298,7 +298,7 @@ bool Inset::showInsetDialog(BufferView * bv) const case BOX_CODE: case INFO_CODE: //FIXME: not ready yet. - //case TABULAR_CODE: + case TABULAR_CODE: case VSPACE_CODE: bv->showDialog(insetName(code)); break; diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 8f2c5c38da..c91b87e3d0 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -101,75 +101,76 @@ boost::scoped_ptr paste_tabular; struct TabularFeature { Tabular::Feature action; string feature; + bool need_value; }; TabularFeature tabularFeature[] = { - { Tabular::APPEND_ROW, "append-row" }, - { Tabular::APPEND_COLUMN, "append-column" }, - { Tabular::DELETE_ROW, "delete-row" }, - { Tabular::DELETE_COLUMN, "delete-column" }, - { Tabular::COPY_ROW, "copy-row" }, - { Tabular::COPY_COLUMN, "copy-column" }, - { Tabular::TOGGLE_LINE_TOP, "toggle-line-top" }, - { Tabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" }, - { Tabular::TOGGLE_LINE_LEFT, "toggle-line-left" }, - { Tabular::TOGGLE_LINE_RIGHT, "toggle-line-right" }, - { Tabular::ALIGN_LEFT, "align-left" }, - { Tabular::ALIGN_RIGHT, "align-right" }, - { Tabular::ALIGN_CENTER, "align-center" }, - { Tabular::ALIGN_BLOCK, "align-block" }, - { Tabular::VALIGN_TOP, "valign-top" }, - { Tabular::VALIGN_BOTTOM, "valign-bottom" }, - { Tabular::VALIGN_MIDDLE, "valign-middle" }, - { Tabular::M_ALIGN_LEFT, "m-align-left" }, - { Tabular::M_ALIGN_RIGHT, "m-align-right" }, - { Tabular::M_ALIGN_CENTER, "m-align-center" }, - { Tabular::M_VALIGN_TOP, "m-valign-top" }, - { Tabular::M_VALIGN_BOTTOM, "m-valign-bottom" }, - { Tabular::M_VALIGN_MIDDLE, "m-valign-middle" }, - { Tabular::MULTICOLUMN, "multicolumn" }, - { Tabular::MULTIROW, "multirow" }, - { Tabular::SET_ALL_LINES, "set-all-lines" }, - { Tabular::UNSET_ALL_LINES, "unset-all-lines" }, - { Tabular::SET_LONGTABULAR, "set-longtabular" }, - { Tabular::UNSET_LONGTABULAR, "unset-longtabular" }, - { Tabular::SET_PWIDTH, "set-pwidth" }, - { Tabular::SET_MPWIDTH, "set-mpwidth" }, - { Tabular::SET_ROTATE_TABULAR, "set-rotate-tabular" }, - { Tabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" }, - { Tabular::TOGGLE_ROTATE_TABULAR, "toggle-rotate-tabular" }, - { Tabular::SET_ROTATE_CELL, "set-rotate-cell" }, - { Tabular::UNSET_ROTATE_CELL, "unset-rotate-cell" }, - { Tabular::TOGGLE_ROTATE_CELL, "toggle-rotate-cell" }, - { Tabular::SET_USEBOX, "set-usebox" }, - { Tabular::SET_LTHEAD, "set-lthead" }, - { Tabular::UNSET_LTHEAD, "unset-lthead" }, - { Tabular::SET_LTFIRSTHEAD, "set-ltfirsthead" }, - { Tabular::UNSET_LTFIRSTHEAD, "unset-ltfirsthead" }, - { Tabular::SET_LTFOOT, "set-ltfoot" }, - { Tabular::UNSET_LTFOOT, "unset-ltfoot" }, - { Tabular::SET_LTLASTFOOT, "set-ltlastfoot" }, - { Tabular::UNSET_LTLASTFOOT, "unset-ltlastfoot" }, - { Tabular::SET_LTNEWPAGE, "set-ltnewpage" }, - { Tabular::TOGGLE_LTCAPTION, "toggle-ltcaption" }, - { Tabular::SET_SPECIAL_COLUMN, "set-special-column" }, - { Tabular::SET_SPECIAL_MULTICOLUMN, "set-special-multicolumn" }, - { Tabular::SET_SPECIAL_MULTIROW, "set-special-multirow" }, - { Tabular::SET_BOOKTABS, "set-booktabs" }, - { Tabular::UNSET_BOOKTABS, "unset-booktabs" }, - { Tabular::SET_TOP_SPACE, "set-top-space" }, - { Tabular::SET_BOTTOM_SPACE, "set-bottom-space" }, - { Tabular::SET_INTERLINE_SPACE, "set-interline-space" }, - { Tabular::SET_BORDER_LINES, "set-border-lines" }, + { Tabular::APPEND_ROW, "append-row", false }, + { Tabular::APPEND_COLUMN, "append-column", false }, + { Tabular::DELETE_ROW, "delete-row", false }, + { Tabular::DELETE_COLUMN, "delete-column", false }, + { Tabular::COPY_ROW, "copy-row", false }, + { Tabular::COPY_COLUMN, "copy-column", false }, + { Tabular::TOGGLE_LINE_TOP, "toggle-line-top", false }, + { Tabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom", false }, + { Tabular::TOGGLE_LINE_LEFT, "toggle-line-left", false }, + { Tabular::TOGGLE_LINE_RIGHT, "toggle-line-right", false }, + { Tabular::ALIGN_LEFT, "align-left", false }, + { Tabular::ALIGN_RIGHT, "align-right", false }, + { Tabular::ALIGN_CENTER, "align-center", false }, + { Tabular::ALIGN_BLOCK, "align-block", false }, + { Tabular::VALIGN_TOP, "valign-top", false }, + { Tabular::VALIGN_BOTTOM, "valign-bottom", false }, + { Tabular::VALIGN_MIDDLE, "valign-middle", false }, + { Tabular::M_ALIGN_LEFT, "m-align-left", false }, + { Tabular::M_ALIGN_RIGHT, "m-align-right", false }, + { Tabular::M_ALIGN_CENTER, "m-align-center", false }, + { Tabular::M_VALIGN_TOP, "m-valign-top", false }, + { Tabular::M_VALIGN_BOTTOM, "m-valign-bottom", false }, + { Tabular::M_VALIGN_MIDDLE, "m-valign-middle", false }, + { Tabular::MULTICOLUMN, "multicolumn", false }, + { Tabular::MULTIROW, "multirow", false }, + { Tabular::SET_ALL_LINES, "set-all-lines", false }, + { Tabular::UNSET_ALL_LINES, "unset-all-lines", false }, + { Tabular::SET_LONGTABULAR, "set-longtabular", false }, + { Tabular::UNSET_LONGTABULAR, "unset-longtabular", false }, + { Tabular::SET_PWIDTH, "set-pwidth", true }, + { Tabular::SET_MPWIDTH, "set-mpwidth", true }, + { Tabular::SET_ROTATE_TABULAR, "set-rotate-tabular", false }, + { Tabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular", false }, + { Tabular::TOGGLE_ROTATE_TABULAR, "toggle-rotate-tabular", false }, + { Tabular::SET_ROTATE_CELL, "set-rotate-cell", false }, + { Tabular::UNSET_ROTATE_CELL, "unset-rotate-cell", false }, + { Tabular::TOGGLE_ROTATE_CELL, "toggle-rotate-cell", false }, + { Tabular::SET_USEBOX, "set-usebox", true }, + { Tabular::SET_LTHEAD, "set-lthead", true }, + { Tabular::UNSET_LTHEAD, "unset-lthead", true }, + { Tabular::SET_LTFIRSTHEAD, "set-ltfirsthead", true }, + { Tabular::UNSET_LTFIRSTHEAD, "unset-ltfirsthead", true }, + { Tabular::SET_LTFOOT, "set-ltfoot", true }, + { Tabular::UNSET_LTFOOT, "unset-ltfoot", true }, + { Tabular::SET_LTLASTFOOT, "set-ltlastfoot", true }, + { Tabular::UNSET_LTLASTFOOT, "unset-ltlastfoot", true }, + { Tabular::SET_LTNEWPAGE, "set-ltnewpage", false }, + { Tabular::TOGGLE_LTCAPTION, "toggle-ltcaption", false }, + { Tabular::SET_SPECIAL_COLUMN, "set-special-column", true }, + { Tabular::SET_SPECIAL_MULTICOLUMN, "set-special-multicolumn", true }, + { Tabular::SET_SPECIAL_MULTIROW, "set-special-multirow", false }, + { Tabular::SET_BOOKTABS, "set-booktabs", false }, + { Tabular::UNSET_BOOKTABS, "unset-booktabs", false }, + { Tabular::SET_TOP_SPACE, "set-top-space", true }, + { Tabular::SET_BOTTOM_SPACE, "set-bottom-space", true }, + { Tabular::SET_INTERLINE_SPACE, "set-interline-space", true }, + { Tabular::SET_BORDER_LINES, "set-border-lines", false }, { Tabular::TABULAR_VALIGN_TOP, "tabular-valign-top"}, { Tabular::TABULAR_VALIGN_MIDDLE, "tabular-valign-middle"}, { Tabular::TABULAR_VALIGN_BOTTOM, "tabular-valign-bottom"}, - { Tabular::LONGTABULAR_ALIGN_LEFT, "longtabular-align-left" }, - { Tabular::LONGTABULAR_ALIGN_CENTER, "longtabular-align-center" }, - { Tabular::LONGTABULAR_ALIGN_RIGHT, "longtabular-align-right" }, - { Tabular::LAST_ACTION, "" } + { Tabular::LONGTABULAR_ALIGN_LEFT, "longtabular-align-left", false }, + { Tabular::LONGTABULAR_ALIGN_CENTER, "longtabular-align-center", false }, + { Tabular::LONGTABULAR_ALIGN_RIGHT, "longtabular-align-right", false }, + { Tabular::LAST_ACTION, "", false } }; @@ -3858,14 +3859,10 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd) // } case LFUN_LAYOUT_TABULAR: - cur.bv().showDialog("tabular", params2string(*this), this); + cur.bv().showDialog("tabular"); break; - case LFUN_INSET_DIALOG_UPDATE: - cur.bv().updateDialog("tabular", params2string(*this)); - break; - - case LFUN_TABULAR_FEATURE: + case LFUN_INSET_MODIFY: if (!tabularFeatures(cur, to_utf8(cmd.argument()))) cur.undispatched(); break; @@ -4032,12 +4029,22 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & status) const { switch (cmd.action) { - case LFUN_TABULAR_FEATURE: { + case LFUN_INSET_MODIFY: { + istringstream is(to_utf8(cmd.argument())); + string s; + is >> s; + if (insetCode(s) != TABULAR_CODE) { + status.clear(); + status.setEnabled(false); + break; + } + is >> s; + // FIXME: We only check for the very first argument... int action = Tabular::LAST_ACTION; int i = 0; for (; tabularFeature[i].action != Tabular::LAST_ACTION; ++i) { string const tmp = tabularFeature[i].feature; - if (tmp == to_utf8(cmd.argument()).substr(0, tmp.length())) { + if (tmp == s.substr(0, tmp.length())) { action = tabularFeature[i].action; break; } @@ -4049,7 +4056,7 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd, } string const argument - = ltrim(to_utf8(cmd.argument()).substr(tabularFeature[i].feature.length())); + = ltrim(s.substr(tabularFeature[i].feature.length())); row_type sel_row_start = 0; row_type sel_row_end = 0; @@ -4365,17 +4372,11 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd, // relay this lfun to Inset, not to the cell. return Inset::getStatus(cur, cmd, status); - case LFUN_INSET_MODIFY: - if (insetCode(cmd.getArg(0)) == TABULAR_CODE) { - status.setEnabled(true); - return true; - } - // Fall through - default: // we try to handle this event in the insets dispatch function. return cell(cur.idx())->getStatus(cur, cmd, status); } + return false; } @@ -4732,27 +4733,45 @@ void InsetTabular::movePrevCell(Cursor & cur, EntryDirection entry_from) } -bool InsetTabular::tabularFeatures(Cursor & cur, string const & what) +bool InsetTabular::tabularFeatures(Cursor & cur, string const & argument) { - Tabular::Feature action = Tabular::LAST_ACTION; + istringstream is(argument); + string s; + is >> s; + if (insetCode(s) != TABULAR_CODE) + return false; - int i = 0; - for (; tabularFeature[i].action != Tabular::LAST_ACTION; ++i) { - string const tmp = tabularFeature[i].feature; + // Safe guard. + size_t safe_guard = 0; + for (;;) { + safe_guard++; + if (safe_guard > 1000) { + LYXERR0("parameter max count reached!"); + break; + } + is >> s; + if (is.eof()) + break; + Tabular::Feature action = Tabular::LAST_ACTION; + + size_t i = 0; + for (; tabularFeature[i].action != Tabular::LAST_ACTION; ++i) { + if (s != tabularFeature[i].feature) + continue; - if (tmp == what.substr(0, tmp.length())) { - //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(), - //tabularFeatures[i].feature.length())) action = tabularFeature[i].action; break; } + if (action == Tabular::LAST_ACTION) { + LYXERR0("Feature not found " << s); + continue; + } + string val; + if (tabularFeature[i].need_value) + is >> val; + LYXERR(Debug::DEBUG, "Feature: " << s << "\t\tvalue: " << val); + tabularFeatures(cur, action, val); } - if (action == Tabular::LAST_ACTION) - return false; - - string const val = - ltrim(what.substr(tabularFeature[i].feature.length())); - tabularFeatures(cur, action, val); return true; } @@ -4866,7 +4885,10 @@ void InsetTabular::tabularFeatures(Cursor & cur, case Tabular::SET_SPECIAL_COLUMN: case Tabular::SET_SPECIAL_MULTICOLUMN: - tabular.setAlignSpecial(cur.idx(), from_utf8(value), feature); + if (value == "none") + tabular.setAlignSpecial(cur.idx(), docstring(), feature); + else + tabular.setAlignSpecial(cur.idx(), from_utf8(value), feature); break; case Tabular::APPEND_ROW: @@ -5192,12 +5214,12 @@ void InsetTabular::tabularFeatures(Cursor & cur, if (value == "default") for (row_type i = sel_row_start; i <= sel_row_end; ++i) tabular.row_info[i].top_space_default = true; - else if (isValidLength(value, &len)) + else if (value == "none") for (row_type i = sel_row_start; i <= sel_row_end; ++i) { tabular.row_info[i].top_space_default = false; tabular.row_info[i].top_space = len; } - else + else if (isValidLength(value, &len)) for (row_type i = sel_row_start; i <= sel_row_end; ++i) { tabular.row_info[i].top_space_default = false; tabular.row_info[i].top_space = len; @@ -5210,12 +5232,12 @@ void InsetTabular::tabularFeatures(Cursor & cur, if (value == "default") for (row_type i = sel_row_start; i <= sel_row_end; ++i) tabular.row_info[i].bottom_space_default = true; - else if (isValidLength(value, &len)) + else if (value == "none") for (row_type i = sel_row_start; i <= sel_row_end; ++i) { tabular.row_info[i].bottom_space_default = false; tabular.row_info[i].bottom_space = len; } - else + else if (isValidLength(value, &len)) for (row_type i = sel_row_start; i <= sel_row_end; ++i) { tabular.row_info[i].bottom_space_default = false; tabular.row_info[i].bottom_space = len; @@ -5228,12 +5250,12 @@ void InsetTabular::tabularFeatures(Cursor & cur, if (value == "default") for (row_type i = sel_row_start; i <= sel_row_end; ++i) tabular.row_info[i].interline_space_default = true; - else if (isValidLength(value, &len)) + else if (value == "none") for (row_type i = sel_row_start; i <= sel_row_end; ++i) { tabular.row_info[i].interline_space_default = false; tabular.row_info[i].interline_space = len; } - else + else if (isValidLength(value, &len)) for (row_type i = sel_row_start; i <= sel_row_end; ++i) { tabular.row_info[i].interline_space_default = false; tabular.row_info[i].interline_space = len; @@ -5248,21 +5270,6 @@ void InsetTabular::tabularFeatures(Cursor & cur, } -bool InsetTabular::showInsetDialog(BufferView * bv) const -{ - bv->showDialog("tabular", params2string(*this), - const_cast(this)); - return true; -} - - -void InsetTabular::openLayoutDialog(BufferView * bv) const -{ - bv->showDialog("tabular", params2string(*this), - const_cast(this)); -} - - bool InsetTabular::copySelection(Cursor & cur) { if (!cur.selection()) diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h index ce56ba0988..ecf36f9b9d 100644 --- a/src/insets/InsetTabular.h +++ b/src/insets/InsetTabular.h @@ -803,10 +803,6 @@ public: /// void tabularFeatures(Cursor & cur, Tabular::Feature feature, std::string const & val = std::string()); - /// - void openLayoutDialog(BufferView *) const; - /// - bool showInsetDialog(BufferView *) const; /// number of cells size_t nargs() const { return tabular.numberofcells; } /// diff --git a/src/mathed/InsetMathAMSArray.cpp b/src/mathed/InsetMathAMSArray.cpp index b9efc3d0e2..d2921c6f53 100644 --- a/src/mathed/InsetMathAMSArray.cpp +++ b/src/mathed/InsetMathAMSArray.cpp @@ -24,12 +24,14 @@ #include "support/lstrings.h" +#include #include -namespace lyx { +using namespace std; +using namespace lyx::support; -using support::bformat; +namespace lyx { InsetMathAMSArray::InsetMathAMSArray(Buffer * buf, docstring const & name, @@ -105,19 +107,26 @@ bool InsetMathAMSArray::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { switch (cmd.action) { - case LFUN_TABULAR_FEATURE: { - docstring const & s = cmd.argument(); + case LFUN_INSET_MODIFY: { + istringstream is(to_utf8(cmd.argument())); + string s; + is >> s; + if (s != "tabular") + break; + is >> s; if (s == "add-vline-left" || s == "add-vline-right") { flag.message(bformat( - from_utf8(N_("Can't add vertical grid lines in '%1$s'")), name_)); + from_utf8(N_("Can't add vertical grid lines in '%1$s'")), + name_)); flag.setEnabled(false); return true; } - return InsetMathGrid::getStatus(cur, cmd, flag); + break; } default: - return InsetMathGrid::getStatus(cur, cmd, flag); + break; } + return InsetMathGrid::getStatus(cur, cmd, flag); } diff --git a/src/mathed/InsetMathCases.cpp b/src/mathed/InsetMathCases.cpp index 9b55c51ea9..94a9c0e84b 100644 --- a/src/mathed/InsetMathCases.cpp +++ b/src/mathed/InsetMathCases.cpp @@ -71,19 +71,25 @@ void InsetMathCases::doDispatch(Cursor & cur, FuncRequest & cmd) { //lyxerr << "*** InsetMathCases: request: " << cmd << endl; switch (cmd.action) { - case LFUN_TABULAR_FEATURE: { - docstring const & s = cmd.argument(); + case LFUN_INSET_MODIFY: { + istringstream is(to_utf8(cmd.argument())); + string s; + is >> s; + if (s != "tabular") + break; + is >> s; // vertical lines and adding/deleting columns is not allowed for \cases if (s == "append-column" || s == "delete-column" - || s == "add-vline-left" || s == "add-vline-right") { + || s == "add-vline-left" || s == "add-vline-right") { cur.undispatched(); break; } cur.recordUndo(); } default: - InsetMathGrid::doDispatch(cur, cmd); + break; } + InsetMathGrid::doDispatch(cur, cmd); } @@ -91,26 +97,33 @@ bool InsetMathCases::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { switch (cmd.action) { - case LFUN_TABULAR_FEATURE: { - docstring const & s = cmd.argument(); + case LFUN_INSET_MODIFY: { + istringstream is(to_utf8(cmd.argument())); + string s; + is >> s; + if (s != "tabular") + break; + is >> s; if (s == "add-vline-left" || s == "add-vline-right") { flag.setEnabled(false); flag.message(bformat( from_utf8(N_("No vertical grid lines in 'cases': feature %1$s")), - s)); + from_utf8(s))); return true; } if (s == "append-column" || s == "delete-column") { flag.setEnabled(false); flag.message(bformat( from_utf8(N_("Changing number of columns not allowed in " - "'cases': feature %1$s")), s)); + "'cases': feature %1$s")), from_utf8(s))); return true; } + break; } default: - return InsetMathGrid::getStatus(cur, cmd, flag); + break; } + return InsetMathGrid::getStatus(cur, cmd, flag); } diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index 8629568037..2753dc8e40 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -1161,12 +1161,17 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd) break; } - case LFUN_TABULAR_FEATURE: { + case LFUN_INSET_MODIFY: { cur.recordUndoInset(); //lyxerr << "handling tabular-feature " << to_utf8(cmd.argument()) << endl; istringstream is(to_utf8(cmd.argument())); string s; is >> s; + if (s != "tabular") { + InsetMathNest::doDispatch(cur, cmd); + return; + } + is >> s; if (s == "valign-top") setVerticalAlignment('t'); else if (s == "valign-middle") @@ -1398,8 +1403,13 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & status) const { switch (cmd.action) { - case LFUN_TABULAR_FEATURE: { - string const s = cmd.getArg(0); + case LFUN_INSET_MODIFY: { + istringstream is(to_utf8(cmd.argument())); + string s; + is >> s; + if (s != "tabular") + return InsetMathNest::getStatus(cur, cmd, status); + is >> s; if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) { status.setEnabled(false); status.message(from_utf8(N_("Only one row"))); diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index bd3c41ad2c..c9f16f407a 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -1487,10 +1487,13 @@ bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd, } return InsetMathGrid::getStatus(cur, cmd, status); - case LFUN_TABULAR_FEATURE: { + case LFUN_INSET_MODIFY: { istringstream is(to_utf8(cmd.argument())); string s; is >> s; + if (s != "tabular") + return InsetMathGrid::getStatus(cur, cmd, status); + is >> s; if (!rowChangeOK() && (s == "append-row" || s == "delete-row" diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index e95c89c007..0a7810784a 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -1266,11 +1266,11 @@ bool InsetMathNest::getStatus(Cursor & cur, FuncRequest const & cmd, bool ret = true; string const arg = to_utf8(cmd.argument()); switch (cmd.action) { - case LFUN_TABULAR_FEATURE: + case LFUN_INSET_MODIFY: flag.setEnabled(false); break; #if 0 - case LFUN_TABULAR_FEATURE: + case LFUN_INSET_MODIFY: // FIXME: check temporarily disabled // valign code char align = mathcursor::valign(); diff --git a/src/mathed/InsetMathSplit.cpp b/src/mathed/InsetMathSplit.cpp index 7efd406b77..673d611000 100644 --- a/src/mathed/InsetMathSplit.cpp +++ b/src/mathed/InsetMathSplit.cpp @@ -70,19 +70,25 @@ bool InsetMathSplit::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { switch (cmd.action) { - case LFUN_TABULAR_FEATURE: { - docstring const & s = cmd.argument(); + case LFUN_INSET_MODIFY: { + istringstream is(to_utf8(cmd.argument())); + string s; + is >> s; + if (s != "tabular") + break; + is >> s; if (s == "add-vline-left" || s == "add-vline-right") { flag.message(bformat( from_utf8(N_("Can't add vertical grid lines in '%1$s'")), name_)); flag.setEnabled(false); return true; } - return InsetMathGrid::getStatus(cur, cmd, flag); + break; } default: - return InsetMathGrid::getStatus(cur, cmd, flag); + break; } + return InsetMathGrid::getStatus(cur, cmd, flag); } diff --git a/src/mathed/InsetMathSubstack.cpp b/src/mathed/InsetMathSubstack.cpp index 1736da409f..544230a659 100644 --- a/src/mathed/InsetMathSubstack.cpp +++ b/src/mathed/InsetMathSubstack.cpp @@ -63,9 +63,14 @@ bool InsetMathSubstack::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { switch (cmd.action) { - case LFUN_TABULAR_FEATURE: { + case LFUN_INSET_MODIFY: { + istringstream is(to_utf8(cmd.argument())); + string s; + is >> s; + if (s != "tabular") + break; + is >> s; string const name = "substack"; - docstring const & s = cmd.argument(); if (s == "add-vline-left" || s == "add-vline-right") { flag.message(bformat( from_utf8(N_("Can't add vertical grid lines in '%1$s'")), @@ -73,11 +78,12 @@ bool InsetMathSubstack::getStatus(Cursor & cur, FuncRequest const & cmd, flag.setEnabled(false); return true; } - return InsetMathGrid::getStatus(cur, cmd, flag); + break; } default: - return InsetMathGrid::getStatus(cur, cmd, flag); + break; } + return InsetMathGrid::getStatus(cur, cmd, flag); } -- 2.39.2