]> git.lyx.org Git - features.git/commitdiff
More ascii-export fixes and when making copy of single tabular cells now the
authorJürgen Vigna <jug@sad.it>
Thu, 27 Dec 2001 15:54:25 +0000 (15:54 +0000)
committerJürgen Vigna <jug@sad.it>
Thu, 27 Dec 2001 15:54:25 +0000 (15:54 +0000)
data is copied as tab separated values to the clipboard (not when copiing the
whole paragraph!).

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

src/ChangeLog
src/buffer.C
src/buffer.h
src/insets/ChangeLog
src/insets/inset.h
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insettabular.C
src/insets/insettext.C
src/tabular.C
src/tabular.h

index d211cea8db005d559a6d824ba0f299a276243de3..6c465017a4ef29798981e0b89208386e31196e19 100644 (file)
@@ -1,5 +1,11 @@
 2001-12-27  Juergen Vigna  <jug@sad.it>
 
+       * buffer.C (asciiParagraph): more fixes.
+
+       * tabular.C (ascii): make ascii export support export of only the
+       data separated by a column-delimiter.
+       (ascii): better support for ascii export.
+
        * buffer.C (asciiParagraph): rewrote to hopefully work as expected!
 
 2001-12-26  Jean-Marc Lasgouttes  <Jean-Marc.Lasgouttes@inria.fr>
index 3ba5c4509326fac046d5e88243e4bb6ad7e33a0e..e789579d21dd6d967c2e7e10a391107603042eb9 100644 (file)
@@ -1768,7 +1768,8 @@ bool Buffer::writeFile(string const & fname, bool flag) const
 
 
 string const Buffer::asciiParagraph(Paragraph const * par,
-                                    unsigned int linelen) const
+                                    unsigned int linelen,
+                                    bool noparbreak) const
 {
        ostringstream buffer;
        ostringstream word;
@@ -1777,8 +1778,6 @@ string const Buffer::asciiParagraph(Paragraph const * par,
        Paragraph::depth_type ltype_depth = 0;
        string::size_type currlinelen = 0;
        bool ref_printed = false;
-
-       int noparbreak = 0;
 //     if (!par->previous()) {
 #if 0
        // begins or ends a deeper area ?
@@ -1907,7 +1906,7 @@ string const Buffer::asciiParagraph(Paragraph const * par,
                        if (inset) {
                                if (linelen > 0)
                                        buffer << word.str();
-                               if (inset->ascii(this, buffer)) {
+                               if (inset->ascii(this, buffer, linelen)) {
                                        // to be sure it breaks paragraph
                                        currlinelen += linelen;
                                }
@@ -1999,7 +1998,7 @@ void Buffer::writeFileAscii(ostream & ofs, int linelen)
 {
        Paragraph * par = paragraph;
        while (par) {
-               ofs << asciiParagraph(par, linelen);
+               ofs << asciiParagraph(par, linelen, par->previous() == 0);
                par = par->next();
        }
        ofs << "\n";
index 9d097efc5a991fdd79cb9993d45300b1e3f9f53f..cd8c55d7cf966d19e11e8ffe17d2e231613517de 100644 (file)
@@ -151,8 +151,8 @@ public:
        ///
        void writeFileAscii(std::ostream &, int);
        ///
-       string const asciiParagraph(Paragraph const *,
-                                   unsigned int linelen) const;
+       string const asciiParagraph(Paragraph const *, unsigned int linelen,
+                                   bool noparbreak = false) const;
        ///
        void makeLaTeXFile(string const & filename,
                           string const & original_path,
index 7dbfa4c436e09313ea0af105eb9047c98c30c0b4..423970a702fe1f919efa0d5e06f3b96423844c6a 100644 (file)
@@ -1,3 +1,15 @@
+2001-12-27  Juergen Vigna  <jug@sad.it>
+
+       * insettabular.C (ascii): export as tab-separated-values if the
+       function was not called from export (f.ex.: clipboard).
+
+       * insetcollapsable.h: added default support for ascii, linuxdoc and
+       docbook export (the insettext is exported by default!)
+
+       * insettabular.C (copySelection): suff the clipboard with the tabular
+       data in a tab separated format, seems more naturals then with all the
+       formating.
+
 2001-12-24  Juergen Vigna  <jug@sad.it>
 
        * insettext.C (insetMotionNotify): added a mouse_x & mouse_y position
index 8e070260b16d660a6279663e46cdeb9be76703b7..bc0ed0aae84700c8bc4c9ac1de0fb4b6747f2201 100644 (file)
@@ -191,7 +191,7 @@ public:
                          bool free_spc) const = 0;
        ///
        virtual int ascii(Buffer const *,
-                         std::ostream &, int linelen = 0) const = 0;
+                         std::ostream &, int linelen = 0) const = 0;
        ///
        virtual int linuxdoc(Buffer const *, std::ostream &) const = 0;
        ///
index 8a0ab06fb517cb1ba72e968b7fda00b0165d45c9..7a04702f9e425426c8a38c37a8f017be0f1762c3 100644 (file)
@@ -381,6 +381,24 @@ int InsetCollapsable::latex(Buffer const * buf, ostream & os,
        return inset.latex(buf, os, fragile, free_spc);
 }
 
+
+int InsetCollapsable::ascii(Buffer const *buf, std::ostream & os, int ll) const
+{
+       return inset.ascii(buf, os, ll);
+}
+
+
+int InsetCollapsable::linuxdoc(Buffer const *buf, std::ostream & os) const
+{
+       return inset.linuxdoc(buf, os);
+}
+
+
+int InsetCollapsable::docbook(Buffer const *buf, std::ostream & os) const
+{
+       return inset.docbook(buf, os);
+}
+
 #if 0
 int InsetCollapsable::getMaxWidth(BufferView * bv,
                                   UpdatableInset const * in) const
index 3a53cce62553b335b682aa22797bff3aaa01e956..4d1a94fcbb460dd3d6623e6cb8533f57d2847b6a 100644 (file)
@@ -103,11 +103,11 @@ public:
        int latex(Buffer const *, std::ostream &,
                  bool fragile, bool free_spc) const;
        ///
-       int ascii(Buffer const *, std::ostream &, int) const { return 0; }
+       int ascii(Buffer const *, std::ostream &, int) const;
        ///
-       int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
+       int linuxdoc(Buffer const *, std::ostream &) const;
        ///
-       int docbook(Buffer const *, std::ostream &) const { return 0; }
+       int docbook(Buffer const *, std::ostream &) const;
        ///
        void validate(LaTeXFeatures & features) const;
        ///
index fe7630bbc067f24c4221501654d6fa0f50a05452..6e68763d7d0ce0c7a157d146bf3ee0e8b008d6ff 100644 (file)
@@ -34,6 +34,7 @@
 #include "BufferView.h"
 #include "undo_funcs.h"
 #include "lyxlength.h"
+#include "ParagraphParameters.h"
 
 #include "frontends/Dialogs.h"
 #include "frontends/Alert.h"
@@ -1188,22 +1189,24 @@ InsetTabular::localDispatch(BufferView * bv, kb_action action,
 
 
 int InsetTabular::latex(Buffer const * buf, ostream & os,
-                       bool fragile, bool fp) const
+                        bool fragile, bool fp) const
 {
-       return tabular->Latex(buf, os, fragile, fp);
+       return tabular->latex(buf, os, fragile, fp);
 }
 
 
-int InsetTabular::ascii(Buffer const * buf, ostream & os, int) const
+int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
 {
-       // This should be changed to a real ascii export
-       return tabular->Ascii(buf, os);
+       if (ll > 0)
+               return tabular->ascii(buf, os, (int)parOwner()->params().depth(),
+                                     false,0);
+       return tabular->ascii(buf, os, 0, false,0);
 }
 
 
 int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
 {
-       return tabular->Ascii(buf,os);
+       return tabular->ascii(buf,os, (int)parOwner()->params().depth(), false, 0);
 }
 
 
@@ -1222,7 +1225,7 @@ int InsetTabular::docbook(Buffer const * buf, ostream & os) const
                os << "<informaltable>\n";
                ret++;
        }
-       ret+= tabular->DocBook(buf,os);
+       ret+= tabular->docBook(buf,os);
        if (!master) {
                os << "</informaltable>\n";
                ret++;
@@ -2449,7 +2452,8 @@ bool InsetTabular::copySelection(BufferView * bv)
                                    true, true);
 
        ostringstream sstr;
-       paste_tabular->Ascii(bv->buffer(), sstr);
+       paste_tabular->ascii(bv->buffer(), sstr,
+                            (int)parOwner()->params().depth(), true, '\t');
        bv->stuffClipboard(sstr.str().c_str());
        return true;
 }
index 4133732325f9ee46ee023724806c3002dfd269bf..f46f8d4f6722d99f82515a046110fa799ad47cc6 100644 (file)
@@ -1428,7 +1428,7 @@ int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
        unsigned int lines = 0;
        
        while (p) {
-               string const tmp = buf->asciiParagraph(p, linelen);
+               string const tmp = buf->asciiParagraph(p, linelen, p->previous()==0);
                lines += countChar(tmp, '\n');
                os << tmp;
                p = p->next();
index 2bde383bd6c9c2d989ee1f98f2043d60238012b0..80dfcbcfc04b589055a05c8d9f9abcaded7356a8 100644 (file)
@@ -2181,7 +2181,7 @@ int LyXTabular::TeXRow(ostream & os, int const i, Buffer const * buf,
 }
 
 
-int LyXTabular::Latex(Buffer const * buf,
+int LyXTabular::latex(Buffer const * buf,
                                          ostream & os, bool fragile, bool fp) const
 {
        int ret = 0;
@@ -2323,7 +2323,7 @@ int LyXTabular::docbookRow(Buffer const * buf, ostream & os, int row) const
 }      
 
 
-int LyXTabular::DocBook(Buffer const * buf, ostream & os) const
+int LyXTabular::docBook(Buffer const * buf, ostream & os) const
 {
        int ret = 0;
 
@@ -2407,20 +2407,11 @@ int LyXTabular::DocBook(Buffer const * buf, ostream & os) const
        return ret;
 }
 
-
-namespace {
-
-       inline
-       void print_n_chars(ostream & os, unsigned char ch, int n)
-       {
-               os << string(n, ch);
-       }
-
-} // namespace anon
-
-
-int LyXTabular::AsciiTopHLine(ostream & os, int row,
-                                                         vector<unsigned int> const & clen) const
+//--
+// ASCII export function and helpers
+//--
+int LyXTabular::asciiTopHLine(ostream & os, int row,
+                              vector<unsigned int> const & clen) const
 {
        int const fcell = GetFirstCellInRow(row);
        int const n = NumberOfCellsInRow(fcell) + fcell;
@@ -2451,7 +2442,7 @@ int LyXTabular::AsciiTopHLine(ostream & os, int row,
                int len = clen[column];
                while (IsPartOfMultiColumn(row, ++column))
                        len += clen[column] + 4;
-               print_n_chars(os, ch, len);
+               os << string(len, ch);
                if (TopLine(i)) {
                        if (RightLine(i))
                                os << "-+";
@@ -2466,8 +2457,8 @@ int LyXTabular::AsciiTopHLine(ostream & os, int row,
 }
 
 
-int LyXTabular::AsciiBottomHLine(ostream & os, int row,
-                                                                vector<unsigned int> const & clen) const
+int LyXTabular::asciiBottomHLine(ostream & os, int row,
+                                 vector<unsigned int> const & clen) const
 {
        int const fcell = GetFirstCellInRow(row);
        int const n = NumberOfCellsInRow(fcell) + fcell;
@@ -2498,7 +2489,7 @@ int LyXTabular::AsciiBottomHLine(ostream & os, int row,
                int len = clen[column];
                while (IsPartOfMultiColumn(row, ++column))
                        len += clen[column] + 4;
-               print_n_chars(os, ch, len);
+               os << string(len, ch);
                if (BottomLine(i)) {
                        if (RightLine(i))
                                os << "-+";
@@ -2513,13 +2504,19 @@ int LyXTabular::AsciiBottomHLine(ostream & os, int row,
 }
 
 
-int LyXTabular::AsciiPrintCell(Buffer const * buf, ostream & os,
-                              int cell, int row, int column,
-                              vector<unsigned int> const & clen) const
+int LyXTabular::asciiPrintCell(Buffer const * buf, ostream & os,
+                               int cell, int row, int column,
+                               vector<unsigned int> const & clen,
+                               bool onlydata) const
 {
        ostringstream sstr;
        int ret = GetCellInset(cell)->ascii(buf, sstr, 0);
 
+       if (onlydata) {
+               os << sstr.str();
+               return ret;
+       }
+       
        if (LeftLine(cell))
                os << "| ";
        else
@@ -2560,7 +2557,8 @@ int LyXTabular::AsciiPrintCell(Buffer const * buf, ostream & os,
 }
 
 
-int LyXTabular::Ascii(Buffer const * buf, ostream & os) const
+int LyXTabular::ascii(Buffer const * buf, ostream & os, int const depth,
+                                         bool onlydata, unsigned char delim) const
 {
        int ret = 0;
 
@@ -2569,49 +2567,68 @@ int LyXTabular::Ascii(Buffer const * buf, ostream & os) const
        //+---------------------------------------------------------------------
        vector<unsigned int> clen(columns_);
 
-       // first all non (real) multicolumn cells!
-       for (int j = 0; j < columns_; ++j) {
-               clen[j] = 0;
-               for (int i = 0; i < rows_; ++i) {
-                       int cell = GetCellNumber(i, j);
-                       if (IsMultiColumn(cell, true))
-                               continue;
-                       ostringstream sstr;
-                       GetCellInset(cell)->ascii(buf, sstr, 0);
-                       if (clen[j] < sstr.str().length())
-                               clen[j] = sstr.str().length();
+       if (!onlydata) {
+               // first all non (real) multicolumn cells!
+               for (int j = 0; j < columns_; ++j) {
+                       clen[j] = 0;
+                       for (int i = 0; i < rows_; ++i) {
+                               int cell = GetCellNumber(i, j);
+                               if (IsMultiColumn(cell, true))
+                                       continue;
+                               ostringstream sstr;
+                               GetCellInset(cell)->ascii(buf, sstr, 0);
+                               if (clen[j] < sstr.str().length())
+                                       clen[j] = sstr.str().length();
+                       }
                }
-       }
-       // then all (real) multicolumn cells!
-       for (int j = 0; j < columns_; ++j) {
-               for (int i = 0; i < rows_; ++i) {
-                       int cell = GetCellNumber(i, j);
-                       if (!IsMultiColumn(cell, true) || IsPartOfMultiColumn(i, j))
-                               continue;
-                       ostringstream sstr;
-                       GetCellInset(cell)->ascii(buf, sstr, 0);
-                       int len = int(sstr.str().length());
-                       int const n = cells_in_multicolumn(cell);
-                       for (int k = j; (len > 0) && (k < (j + n - 1)); ++k)
-                               len -= clen[k];
-                       if (len > int(clen[j + n - 1]))
-                               clen[j + n - 1] = len;
+               // then all (real) multicolumn cells!
+               for (int j = 0; j < columns_; ++j) {
+                       for (int i = 0; i < rows_; ++i) {
+                               int cell = GetCellNumber(i, j);
+                               if (!IsMultiColumn(cell, true) || IsPartOfMultiColumn(i, j))
+                                       continue;
+                               ostringstream sstr;
+                               GetCellInset(cell)->ascii(buf, sstr, 0);
+                               int len = int(sstr.str().length());
+                               int const n = cells_in_multicolumn(cell);
+                               for (int k = j; (len > 0) && (k < (j + n - 1)); ++k)
+                                       len -= clen[k];
+                               if (len > int(clen[j + n - 1]))
+                                       clen[j + n - 1] = len;
+                       }
                }
        }
        int cell = 0;
        for (int i = 0; i < rows_; ++i) {
-               AsciiTopHLine(os, i, clen);
+               if (!onlydata) {
+                       if (asciiTopHLine(os, i, clen)) {
+                               for (int j = 0; j < depth; ++j)
+                                       os << "  ";
+                       }
+               }
                for (int j = 0; j < columns_; ++j) {
                        if (IsPartOfMultiColumn(i,j))
                                continue;
-                       ret += AsciiPrintCell(buf, os, cell, i, j, clen);
+                       if (onlydata && j > 0)
+                               os << delim;
+                       ret += asciiPrintCell(buf, os, cell, i, j, clen, onlydata);
                        ++cell;
                }
                os << endl;
-               AsciiBottomHLine(os, i, clen);
+               if (!onlydata) {
+                       for (int j = 0; j < depth; ++j)
+                               os << "  ";
+                       if (asciiBottomHLine(os, i, clen)) {
+                               for (int j = 0; j < depth; ++j)
+                                       os << "  ";
+                       }
+               }
        }
        return ret;
 }
+//--
+// end ascii export
+//--
 
 
 InsetText * LyXTabular::GetCellInset(int cell) const
index ada0609fa5dc6d4aaa76ff6b1282a02a86976223..cb4ffb41626edd18169fccbbd2bde126689461fb 100644 (file)
@@ -290,44 +290,13 @@ public:
        void Read(Buffer const *, LyXLex &);
        ///
        void OldFormatRead(LyXLex &, string const &);
-       //
-       // helper function for Latex returns number of newlines
-       ///
-       int TeXTopHLine(std::ostream &, int row) const;
-       ///
-       int TeXBottomHLine(std::ostream &, int row) const;
-       ///
-       int TeXCellPreamble(std::ostream &, int cell) const;
-       ///
-       int TeXCellPostamble(std::ostream &, int cell) const;
-       ///
-       int TeXLongtableHeaderFooter(std::ostream &, Buffer const * buf,
-                                    bool fragile, bool fp) const;
-       ///
-       bool isValidRow(int const row) const;
-       ///
-       int TeXRow(std::ostream &, int const row, Buffer const * buf,
-                  bool fragile, bool fp) const;
-       ///
-       int Latex(Buffer const *, std::ostream &, bool, bool) const;
-       /// auxiliary function for docbook rows
-       int docbookRow(Buffer const * buf, std::ostream & os, int row) const;
-       ///
-       int DocBook(Buffer const * buf, std::ostream & os) const;
-       ///
-       // helper function for Latex returns number of newlines
-       ///
-       int AsciiTopHLine(std::ostream &, int row,
-                         std::vector<unsigned int> const &) const;
        ///
-       int AsciiBottomHLine(std::ostream &, int row,
-                            std::vector<unsigned int> const &) const;
+       int latex(Buffer const *, std::ostream &, bool, bool) const;
        ///
-       int AsciiPrintCell(Buffer const *, std::ostream &,
-                          int cell, int row, int column,
-                          std::vector<unsigned int> const &) const;
+       int docBook(Buffer const * buf, std::ostream & os) const;
        ///
-       int Ascii(Buffer const *, std::ostream &) const;
+       int ascii(Buffer const *, std::ostream &, int const depth,
+                 bool onlydata, unsigned char delim) const;
        ///
        bool IsMultiColumn(int cell, bool real = false) const;
        ///
@@ -577,6 +546,39 @@ private:
        BoxType UseParbox(int cell) const;
        ///
        void setHeaderFooterRows(int header, int fheader, int footer, int lfooter);
+       ///
+       // helper function for Latex returns number of newlines
+       ///
+       int TeXTopHLine(std::ostream &, int row) const;
+       ///
+       int TeXBottomHLine(std::ostream &, int row) const;
+       ///
+       int TeXCellPreamble(std::ostream &, int cell) const;
+       ///
+       int TeXCellPostamble(std::ostream &, int cell) const;
+       ///
+       int TeXLongtableHeaderFooter(std::ostream &, Buffer const * buf,
+                                    bool fragile, bool fp) const;
+       ///
+       bool isValidRow(int const row) const;
+       ///
+       int TeXRow(std::ostream &, int const row, Buffer const * buf,
+                  bool fragile, bool fp) const;
+       ///
+       // helper function for ASCII returns number of newlines
+       ///
+       int asciiTopHLine(std::ostream &, int row,
+                         std::vector<unsigned int> const &) const;
+       ///
+       int asciiBottomHLine(std::ostream &, int row,
+                            std::vector<unsigned int> const &) const;
+       ///
+       int asciiPrintCell(Buffer const *, std::ostream &,
+                          int cell, int row, int column,
+                          std::vector<unsigned int> const &,
+                                          bool onlydata) const;
+       /// auxiliary function for docbook
+       int docbookRow(Buffer const * buf, std::ostream & os, int row) const;
 };
 
 #endif