From: Jürgen Vigna Date: Thu, 27 Dec 2001 15:54:25 +0000 (+0000) Subject: More ascii-export fixes and when making copy of single tabular cells now the X-Git-Tag: 1.6.10~20117 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=9987ffaee8932c18807af7f6ce076eb57f0a54cf;p=features.git More ascii-export fixes and when making copy of single tabular cells now the 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 --- diff --git a/src/ChangeLog b/src/ChangeLog index d211cea8db..6c465017a4 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2001-12-27 Juergen Vigna + * 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 diff --git a/src/buffer.C b/src/buffer.C index 3ba5c45093..e789579d21 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -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"; diff --git a/src/buffer.h b/src/buffer.h index 9d097efc5a..cd8c55d7cf 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -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, diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 7dbfa4c436..423970a702 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,15 @@ +2001-12-27 Juergen Vigna + + * 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 * insettext.C (insetMotionNotify): added a mouse_x & mouse_y position diff --git a/src/insets/inset.h b/src/insets/inset.h index 8e070260b1..bc0ed0aae8 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -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; /// diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 8a0ab06fb5..7a04702f9e 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -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 diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 3a53cce625..4d1a94fcbb 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -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; /// diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index fe7630bbc0..6e68763d7d 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -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 << "\n"; ret++; } - ret+= tabular->DocBook(buf,os); + ret+= tabular->docBook(buf,os); if (!master) { os << "\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; } diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 4133732325..f46f8d4f67 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -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(); diff --git a/src/tabular.C b/src/tabular.C index 2bde383bd6..80dfcbcfc0 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -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 const & clen) const +//-- +// ASCII export function and helpers +//-- +int LyXTabular::asciiTopHLine(ostream & os, int row, + vector 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 const & clen) const +int LyXTabular::asciiBottomHLine(ostream & os, int row, + vector 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 const & clen) const +int LyXTabular::asciiPrintCell(Buffer const * buf, ostream & os, + int cell, int row, int column, + vector 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 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 diff --git a/src/tabular.h b/src/tabular.h index ada0609fa5..cb4ffb4162 100644 --- a/src/tabular.h +++ b/src/tabular.h @@ -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 const &) const; /// - int AsciiBottomHLine(std::ostream &, int row, - std::vector 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 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 const &) const; + /// + int asciiBottomHLine(std::ostream &, int row, + std::vector const &) const; + /// + int asciiPrintCell(Buffer const *, std::ostream &, + int cell, int row, int column, + std::vector const &, + bool onlydata) const; + /// auxiliary function for docbook + int docbookRow(Buffer const * buf, std::ostream & os, int row) const; }; #endif