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
This commit is contained in:
Jürgen Vigna 2001-12-27 15:54:25 +00:00
parent 4333f89d72
commit 9987ffaee8
11 changed files with 166 additions and 108 deletions

View 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>

View 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";

View 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,

View 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

View 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;
///

View 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

View 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;
///

View 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;
}

View 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();

View 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

View 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 latex(Buffer const *, std::ostream &, bool, bool) const;
///
int TeXBottomHLine(std::ostream &, int row) const;
int docBook(Buffer const * buf, std::ostream & os) 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 AsciiPrintCell(Buffer const *, std::ostream &,
int cell, int row, int column,
std::vector<unsigned int> const &) 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