]> git.lyx.org Git - features.git/commitdiff
the 'tabular unifiaction patch' (even with the removal of duplicated menu
authorAndré Pönitz <poenitz@gmx.net>
Wed, 21 Aug 2002 13:47:52 +0000 (13:47 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Wed, 21 Aug 2002 13:47:52 +0000 (13:47 +0000)
entries)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5057 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
lib/ChangeLog
lib/bind/math.bind
lib/ui/default.ui
src/ChangeLog
src/LyXAction.C
src/commandtags.h
src/lyxfunc.C
src/mathed/formulabase.C
src/mathed/math_gridinset.C
src/mathed/math_gridinset.h
src/mathed/math_hullinset.C
src/mathed/math_hullinset.h

index 44f8195ec89bcb6cdefab5692a77c6cbc320a21d..5336b20b3c8013323877b96e5874b76041ed85d7 100644 (file)
@@ -1,3 +1,9 @@
+
+
+2002-08-21  André Pönitz <poenitz@gmx.net>
+
+       * ui/default.ui: adjust to "tabular unification"
+
 2002-08-15  Juergen Spitzmueller <j.spitzmueller@gmx.de>
 
        * bind/de_menus.bind: cleanup shortcuts for section layouts. Starred
index a9e1c22b3661377e0a3d32ad792fdd5cffcdd060..ffcf7162f17d47b0eb49ad8bdb90c9dec2cca0f8 100644 (file)
 \bind "M-m t e"   "math-mutate eqnarray"
 \bind "M-m t m"   "math-mutate multline"
 
-\bind "M-m c i"   "math-column-insert"
-\bind "M-m c d"   "math-column-delete"
-
-\bind "M-m w i"   "math-row-insert"
-\bind "M-m w d"   "math-row-delete"
-
-\bind "M-m a v t"   "math-valign top"
-\bind "M-m a v c"   "math-valign center"
-\bind "M-m a v b"   "math-valign bottom"
-\bind "M-m a h l"   "math-halign left"
-\bind "M-m a h c"   "math-halign center"
-\bind "M-m a h r"   "math-halign right"
+\bind "M-m c i"   "tabular-feature insert-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 w i"   "tabular-feature insert-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 t"   "tabular-feature valign-top"
+\bind "M-m w m"   "tabular-feature valign-center"
+\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"
 
 # Decoration accents
 
index 79250ade8c8778da7d888832e43d2ad415d9ef9c..c3f54638ee2ca152fbb052d6d6bba551ac7b7286 100644 (file)
@@ -108,9 +108,13 @@ Menuset
        Separator
        Item "Add Row|A" "tabular-feature append-row"
        Item "Delete Row|w" "tabular-feature delete-row"
+       Item "Copy Row" "tabular-feature copy-row"
+       Item "Swap Rows" "tabular-feature swap-row"
        Separator
        Item "Add Column|u" "tabular-feature append-column"
        Item "Delete Column|D" "tabular-feature delete-column"
+       Item "Copy Column" "tabular-feature copy-column"
+       Item "Swap Columns" "tabular-feature swap-column"
     End
 
     Menu "edit_math"
@@ -129,20 +133,12 @@ Menuset
        Submenu "Change formula type...|t" "edit_math_mutate"
        Separator
        Submenu "Use computer algebra system|t" "edit_math_extern"
-       Separator
-       Item "Align Left|f" "math-halign left"
-       Item "Align Center|C" "math-halign center"
-       Item "Align Right|R" "math-halign right"
-       Separator
-       Item "V.Align Top|T" "math-valign top"
-       Item "V.Align Center|e" "math-valign center"
-       Item "V.Align Bottom|B" "math-valign bottom"
-       Separator
-       Item "Add Row" "math-row-insert"
-       Item "Delete Row" "math-row-delete"
-       Separator
-       Item "Add Column" "math-column-insert"
-       Item "Delete Column" "math-column-delete"
+
+       #Item "Line Top|T" "tabular-feature toggle-line-top"
+       #Item "Line Bottom|B" "tabular-feature toggle-line-bottom"
+       #Item "Line Left|L" "tabular-feature toggle-line-left"
+       #Item "Line Right|R" "tabular-feature toggle-line-right"
+       #Separator
     End
 
     Menu "edit_math_extern"
index 4cdc385205df574c656efebf9cd59ddbd67145e5..3bf8e880aaf901639402a3d121f9b770b90a5daf 100644 (file)
@@ -1,3 +1,11 @@
+
+2002-08-20  André Pönitz <poenitz@gmx.net>
+
+       * commandtags.h: new LFUNs for swapping/copying table row/colums
+
+       * LyXAction.C:
+       * lyxfunc.C: support for new lfuns
+
 2002-08-21  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * tabular.C: 
index 348f935d1cf3fd2c0d09279a58b91e0b8063c5d7..f20f8b5227493d507be6c6e99ce9195fbb88fe6a 100644 (file)
@@ -296,12 +296,6 @@ void LyXAction::init()
                { LFUN_MATH_NONUMBER, "math-nonumber", "", Noop },
                { LFUN_MATH_NUMBER, "math-number", "", Noop },
                { LFUN_MATH_EXTERN, "math-extern", "", Noop },
-               { LFUN_MATH_VALIGN, "math-valign", "", Noop },
-               { LFUN_MATH_HALIGN, "math-halign", "", Noop },
-               { LFUN_MATH_ROW_INSERT, "math-row-insert", "", Noop },
-               { LFUN_MATH_ROW_DELETE, "math-row-delete", "", Noop },
-               { LFUN_MATH_COLUMN_INSERT, "math-column-insert", "", Noop },
-               { LFUN_MATH_COLUMN_DELETE, "math-column-delete", "", Noop },
                { LFUN_MATH_PANEL, "math-panel", "", Noop },
                { LFUN_MATH_SIZE, "math-size", "", Noop },
                { LFUN_MENU_OPEN_BY_NAME, "menu-open", "", NoBuffer },
index ae74a9ab5596cd50a0169fbf87b3da947f4d7708..6469b95ee09082cfa47273e313c58d2a3a686fd4 100644 (file)
@@ -142,12 +142,6 @@ enum kb_action {
        LFUN_MATH_MACRO,                // ale970510
        LFUN_MATH_EXTERN,    // 120     // Andre' 20010424
        LFUN_MATH_PANEL,                // Andre' 20010522
-       LFUN_MATH_VALIGN,               // Andre' 20010522
-       LFUN_MATH_HALIGN,               // Andre' 20010522
-       LFUN_MATH_ROW_INSERT,           // Andre' 20010522
-       LFUN_MATH_ROW_DELETE,           // Andre' 20010522
-       LFUN_MATH_COLUMN_INSERT,        // Andre' 20010522
-       LFUN_MATH_COLUMN_DELETE,        // Andre' 20010522
        LFUN_MATH_MUTATE,               // Andre' 20010523
        LFUN_MATH_IMPORT_SELECTION,     // Andre' 20010704
        LFUN_MATH_SPACE,                // Andre' 20010725
index 61ffa58b04849f98aed0a01fb1972009ee7441fb..9f0327bc49025c28e6f47e396a84c0c8ab71661b 100644 (file)
@@ -362,7 +362,47 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        }
 
        case LFUN_TABULAR_FEATURE:
-               disable = true;
+               if (mathcursor) {
+#if 0
+                       // FIXME: check temporarily disabled
+                       // valign code
+                       char align = mathcursor->valign();
+                       if (align == '\0') {
+                               disable = true;
+                               break;
+                       }
+                       if (ev.argument.empty()) {
+                               flag.clear();
+                               break;
+                       }
+                       if (!contains("tcb", ev.argument[0])) {
+                               disable = true;
+                               break;
+                       }
+                       flag.setOnOff(ev.argument[0] == align);
+               } else
+                       disable = true;
+
+                       char align = mathcursor->halign();
+                       if (align == '\0') {
+                               disable = true;
+                               break;
+                       }
+                       if (ev.argument.empty()) {
+                               flag.clear();
+                               break;
+                       }
+                       if (!contains("lcr", ev.argument[0])) {
+                               disable = true;
+                               break;
+                       }
+                       flag.setOnOff(ev.argument[0] == align);
+#endif
+
+                       disable = !mathcursor->halign();
+                       break;
+               }
+
                if (tli) {
                        FuncStatus ret;
                        //ret.disabled(true);
@@ -416,45 +456,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        case LFUN_LATEX_LOG:
                disable = !IsFileReadable(buf->getLogName().second);
                break;
-       case LFUN_MATH_VALIGN:
-               if (mathcursor) {
-                       char align = mathcursor->valign();
-                       if (align == '\0') {
-                               disable = true;
-                               break;
-                       }
-                       if (ev.argument.empty()) {
-                               flag.clear();
-                               break;
-                       }
-                       if (!contains("tcb", ev.argument[0])) {
-                               disable = true;
-                               break;
-                       }
-                       flag.setOnOff(ev.argument[0] == align);
-               } else
-                       disable = true;
-               break;
-
-       case LFUN_MATH_HALIGN:
-               if (mathcursor) {
-                       char align = mathcursor->halign();
-                       if (align == '\0') {
-                               disable = true;
-                               break;
-                       }
-                       if (ev.argument.empty()) {
-                               flag.clear();
-                               break;
-                       }
-                       if (!contains("lcr", ev.argument[0])) {
-                               disable = true;
-                               break;
-                       }
-                       flag.setOnOff(ev.argument[0] == align);
-               } else
-                       disable = true;
-               break;
 
        case LFUN_MATH_MUTATE:
                if (mathcursor)
@@ -474,15 +475,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                disable = !mathcursor;
                break;
 
-       // we need to be math mode and a math array for that
-       // Hack: halign produces non-zero result iff we are in a math array
-       case LFUN_MATH_ROW_INSERT:
-       case LFUN_MATH_ROW_DELETE:
-       case LFUN_MATH_COLUMN_INSERT:
-       case LFUN_MATH_COLUMN_DELETE:
-               disable = !mathcursor || !mathcursor->halign();
-               break;
-
        default:
                break;
        }
index 6914826429068c0df4a481be0004fe19ac02f4f1..495e9a257f0a39770e5c2cc10dac0edb0ad1f366 100644 (file)
@@ -415,12 +415,6 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
 
        case LFUN_MATH_MUTATE:
        case LFUN_MATH_DISPLAY:
-       case LFUN_MATH_HALIGN:
-       case LFUN_MATH_VALIGN:
-       case LFUN_MATH_ROW_INSERT:
-       case LFUN_MATH_ROW_DELETE:
-       case LFUN_MATH_COLUMN_INSERT:
-       case LFUN_MATH_COLUMN_DELETE:
        case LFUN_MATH_NUMBER:
        case LFUN_MATH_NONUMBER:
        case LFUN_TABINSERT:
@@ -428,6 +422,7 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
        case LFUN_DELETE_LINE_FORWARD:
        case LFUN_INSERT_LABEL:
        case LFUN_MATH_EXTERN:
+       case LFUN_TABULAR_FEATURE:
                bv->lockedInsetStoreUndo(Undo::EDIT);
                mathcursor->dispatch(cmd);
                updateLocal(bv, true);
index 57a30f4e41e0168a7d512643b7b82bf5352fd896..f578582589584f19495325e2bee565e6ba557e97 100644 (file)
@@ -578,6 +578,25 @@ void MathGridInset::delRow(row_type row)
 }
 
 
+void MathGridInset::copyRow(row_type row)
+{
+       addRow(row);
+       for (col_type col = 0; col < ncols(); ++col)
+               cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
+}
+
+
+void MathGridInset::swapRow(row_type row)
+{
+       if (nrows() == 1)
+               return;
+       if (row + 1 == nrows())
+               --row;
+       for (col_type col = 0; col < ncols(); ++col)
+               swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
+}
+
+
 void MathGridInset::addCol(col_type newcol)
 {
        const col_type nc = ncols();
@@ -621,6 +640,25 @@ void MathGridInset::delCol(col_type col)
 }
 
 
+void MathGridInset::copyCol(col_type col)
+{
+       addCol(col);
+       for (row_type row = 0; row < nrows(); ++row)
+               cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
+}
+
+
+void MathGridInset::swapCol(col_type col)
+{
+       if (ncols() == 1)
+               return;
+       if (col + 1 == ncols())
+               --col;
+       for (row_type row = 0; row < nrows(); ++row)
+               swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
+}
+
+
 int MathGridInset::cellXOffset(idx_type idx) const
 {
        col_type c = col(idx);
@@ -968,41 +1006,49 @@ MathInset::result_type MathGridInset::dispatch
                        return DISPATCHED_POP;
                }
 
-               case LFUN_MATH_HALIGN:
-                       halign((cmd.argument + "c")[0], col(idx));
-                       return DISPATCHED_POP;
-
-               case LFUN_MATH_VALIGN:
-                       valign((cmd.argument + "c")[0]);
-                       return DISPATCHED_POP;
-
-               case LFUN_MATH_ROW_INSERT:
-                       addRow(row(idx));
-                       return DISPATCHED_POP;
-
-               case LFUN_MATH_ROW_DELETE:
-                       delRow(row(idx));
-                       if (idx > nargs())
-                               idx -= ncols();
-                       return DISPATCHED_POP;
-
-               case LFUN_MATH_COLUMN_INSERT: {
-                       row_type r = row(idx);
-                       col_type c = col(idx);
-                       addFancyCol(c);
-                       idx = index(r, c);
-                       return DISPATCHED_POP;
-               }
-
-               case LFUN_MATH_COLUMN_DELETE: {
-                       row_type r = row(idx);
-                       col_type c = col(idx);
-                       delFancyCol(col(idx));
-                       idx = index(r, c);
-                       if (idx > nargs())
-                               idx -= ncols();
+               case LFUN_TABULAR_FEATURE:
+                       //lyxerr << "handling tabular-feature " << cmd.argument << "\n";
+                       if (cmd.argument == "valign-top")
+                               valign('t');
+                       else if (cmd.argument == "valign-center")
+                               valign('c');
+                       else if (cmd.argument == "valign-bottom")
+                               valign('b');
+                       else if (cmd.argument == "align-left")
+                               halign('l', col(idx));
+                       else if (cmd.argument == "align-right")
+                               halign('r', col(idx));
+                       else if (cmd.argument == "align-center")
+                               halign('c', col(idx));
+                       else if (cmd.argument == "append-row")
+                               addRow(row(idx));
+                       else if (cmd.argument == "delete-row") {
+                               delRow(row(idx));
+                               if (idx > nargs())
+                                       idx -= ncols();
+                       } else if (cmd.argument == "copy-row")
+                               copyRow(row(idx));
+                       else if (cmd.argument == "swap-row")
+                               swapRow(row(idx));
+                       else if (cmd.argument == "append-column") {
+                               row_type r = row(idx);
+                               col_type c = col(idx);
+                               addCol(c);
+                               idx = index(r, c);
+                       } else if (cmd.argument == "delete-column") {
+                               row_type r = row(idx);
+                               col_type c = col(idx);
+                               delCol(col(idx));
+                               idx = index(r, c);
+                               if (idx > nargs())
+                                       idx -= ncols();
+                       } else if (cmd.argument == "copy-column")
+                               copyCol(col(idx));
+                       else if (cmd.argument == "swap-column")
+                               swapCol(col(idx));
+                       else 
+                               return UNDISPATCHED;
                        return DISPATCHED_POP;
-               }
 
                case LFUN_PASTE: {
                        //lyxerr << "pasting '" << cmd.argument << "'\n";
index 808735a29f4a01cddce289aaa75ffe31a54e2309..84cdaaf5099313cbd68702b7c622f3d529d3c7ba 100644 (file)
@@ -164,17 +164,17 @@ public:
        ///
        virtual void delRow(row_type r);
        ///
-       virtual void addFancyRow(row_type r) { addRow(r); }
+       virtual void copyRow(row_type r);
        ///
-       virtual void delFancyRow(row_type r) { delRow(r); }
+       virtual void swapRow(row_type r);
        ///
        virtual void addCol(col_type c);
        ///
        virtual void delCol(col_type c);
        ///
-       virtual void addFancyCol(col_type c) { addCol(c); }
+       virtual void copyCol(col_type c);
        ///
-       virtual void delFancyCol(col_type c) { delCol(c); }
+       virtual void swapCol(col_type c);
        ///
        virtual void appendRow();
        ///
index 85d3af38ace90c8c7e1308b9a8687983db526a90..6d4e2809918f087a663eacd8be0247aa018231a8 100644 (file)
@@ -400,6 +400,12 @@ void MathHullInset::footer_write(WriteStream & os) const
 }
 
 
+bool MathHullInset::colChangeOK() const
+{
+       return type_ == "align" || type_ == "alignat" || type_ == "xalignat";
+}
+
+
 void MathHullInset::addRow(row_type row)
 {
        nonum_.insert(nonum_.begin() + row + 1, !numberedType());
@@ -418,26 +424,21 @@ void MathHullInset::delRow(row_type row)
 }
 
 
-void MathHullInset::addFancyCol(col_type col)
+void MathHullInset::addCol(col_type col)
 {
-       if (type_ == "equation")
-               mutate("eqnarray");
-
-       else if (type_ == "eqnarray") {
-               mutate("align");
-               addFancyCol(col);
-       }
-
-       else if (type_ == "align" || type_ == "alignat"
-             || type_ == "xalignat" || type_ == "xxalignat")
+       if (colChangeOK()) 
                MathGridInset::addCol(col);
+       else
+               lyxerr << "Can't change number of columns in '" << type_ << "'\n";
 }
 
 
-void MathHullInset::delFancyCol(col_type col)
+void MathHullInset::delCol(col_type col)
 {
-       if (type_ == "alignat" || type_ == "xalignat" || type_ == "xxalignat")
+       if (colChangeOK()) 
                MathGridInset::delCol(col);
+       else
+               lyxerr << "Can't change number of columns in '" << type_ << "'\n";
 }
 
 
@@ -584,12 +585,16 @@ void MathHullInset::mutate(string const & newtype)
        }
 
        else if (type_ == "multline") {
-               if (newtype == "gather") {
-                       setType("gather");
+               if (newtype == "gather" || newtype == "align" ||        
+                          newtype == "xalign" || newtype == "xxalign")
+                       setType(newtype);
+               else if (newtype == "eqnarray") {
+                       MathGridInset::addCol(1);
+                       MathGridInset::addCol(1);
+                       setType("eqnarray");
                } else {
                        lyxerr << "mutation from '" << type_
-                               << "' to '" << newtype << "' not implemented"
-                                                << endl;
+                               << "' to '" << newtype << "' not implemented" << endl;
                }
        }
 
@@ -801,11 +806,6 @@ MathInset::result_type MathHullInset::dispatch
                        return DISPATCHED;
                }
 
-               case LFUN_MATH_HALIGN:
-               case LFUN_MATH_VALIGN:
-                       // we explicitly don't want the default behaviour here
-                       return UNDISPATCHED;
-
                case LFUN_MATH_EXTERN:
                        doExtern(cmd, idx, pos);
                        return DISPATCHED_POP;
index 1c84e36ff66a8d9cb64473235ace9e1151430340..903f97ae5fd79cc5b912582fdfb11c10eb0ea208 100644 (file)
@@ -57,14 +57,14 @@ public:
        /// identifies HullInset
        MathHullInset * asHullInset() { return this; }
 
-       ///
-       void addRow(row_type);
-       ///
-       void delRow(row_type);
-       ///
-       void addFancyCol(col_type);
-       ///
-       void delFancyCol(col_type);
+       /// add a row
+       void addRow(row_type row);
+       /// delete a row
+       void delRow(row_type row);
+       /// add a column
+       void addCol(col_type col);
+       /// delete a column
+       void delCol(col_type col);
 
        /// get type
        string const & getType() const;
@@ -112,6 +112,8 @@ private:
        char const * standardFont() const;
        /// consistency check
        void check() const;
+       /// can this change its number of cols?
+       bool colChangeOK() const;
 
        /// "none", "simple", "display", "eqnarray",...
        string type_;