+2000-09-26 Juergen Vigna <jug@sad.it>
+
+ * src/buffer.C (asciiParagraph): new function.
+ (writeFileAscii): new function with parameter ostream.
+ (writeFileAscii): use now asciiParagraph.
+
+ * various inset files: added the linelen parameter to the Ascii-func.
+
+ * src/tabular.C (Write): fixed error in writing file introduced by
+ the last changes from Lars.
+
+ * lib/bind/menus.bind: removed not supported functions.
+
+ * src/insets/insettext.C (Ascii): implemented this function.
+
+ * src/insets/lyxinset.h (Ascii): added linelen parameter.
+
+ * src/tabular.C (write_attribute[int,string,bool]): new functions.
+ (Write): use of the write_attribute functions.
+
+ * src/bufferlist.C (close): fixed reasking question!
+
2000-09-26 Lars Gullik Bjønnes <larsbj@lyx.org>
* src/support/unlink.C src/support/remove.C src/support/mkdir.C:
\bind "M-l c" "layout-character"
\bind "M-l p" "layout-paragraph"
\bind "M-l d" "layout-document"
-\bind "M-l a" "layout-paper"
-\bind "M-l e" "layout-table"
-\bind "M-l q" "layout-quotes"
\bind "M-l m" "font-emph"
\bind "M-l n" "font-noun"
\bind "M-l b" "font-bold"
\bind "M-l l" "layout-preamble"
\bind "M-l s" "layout-save-default"
\bind "M-l space" "menu-open Layout"
-\bind "M-l i" "buffer-itemize-bullets-select"
\bind "M-l x" "appendix"
#
#include "frontends/Dialogs.h"
#include "encoding.h"
#include "exporter.h"
+#include "Lsstream.h"
using std::ostream;
using std::ofstream;
}
+#if 0
void Buffer::writeFileAscii(string const & fname, int linelen)
{
Inset * inset;
ofs << "\n";
}
+//----------------------------------------------------------------------------
+#else
+//----------------------------------------------------------------------------
+string const Buffer::asciiParagraph(LyXParagraph const * par, int linelen) const
+{
+ ostringstream buffer;
+ LyXFont font1, font2;
+ Inset const * inset;
+ char c, footnoteflag = 0, depth = 0;
+ string tmp;
+ LyXParagraph::size_type i;
+ int j;
+ int ltype = 0;
+ int ltype_depth = 0;
+ int actcell = 0;
+ int currlinelen = 0;
+ bool ref_printed = false;
+ string fname1 = TmpFileName();
+
+ int noparbreak = 0;
+ int islatex = 0;
+ if (
+#ifndef NEW_INSETS
+ par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
+#endif
+ !par->previous
+#ifndef NEW_INSETS
+ || par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE
+#endif
+ ){
+#ifndef NEW_INSETS
+ /* begins a footnote environment ? */
+ if (footnoteflag != par->footnoteflag) {
+ footnoteflag = par->footnoteflag;
+ if (footnoteflag) {
+ j = strlen(string_footnotekinds[par->footnotekind])+4;
+ if ((linelen > 0) &&
+ ((currlinelen + j) > linelen)) {
+ buffer << "\n";
+ currlinelen = 0;
+ }
+ buffer <<
+ "([" <<
+ string_footnotekinds[par->footnotekind] <<
+ "] ";
+ currlinelen += j;
+ }
+ }
+#endif
+ /* begins or ends a deeper area ?*/
+ if (depth != par->depth) {
+ if (par->depth > depth) {
+ while (par->depth > depth) {
+ ++depth;
+ }
+ }
+ else {
+ while (par->depth < depth) {
+ --depth;
+ }
+ }
+ }
+
+ /* First write the layout */
+ tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
+ if (tmp == "Itemize") {
+ ltype = 1;
+ ltype_depth = depth+1;
+ } else if (tmp == "Enumerate") {
+ ltype = 2;
+ ltype_depth = depth+1;
+ } else if (strstr(tmp.c_str(), "ection")) {
+ ltype = 3;
+ ltype_depth = depth+1;
+ } else if (strstr(tmp.c_str(), "aragraph")) {
+ ltype = 4;
+ ltype_depth = depth+1;
+ } else if (tmp == "Description") {
+ ltype = 5;
+ ltype_depth = depth+1;
+ } else if (tmp == "Abstract") {
+ ltype = 6;
+ ltype_depth = 0;
+ } else if (tmp == "Bibliography") {
+ ltype = 7;
+ ltype_depth = 0;
+ } else {
+ ltype = 0;
+ ltype_depth = 0;
+ }
+
+ /* maybe some vertical spaces */
+
+ /* the labelwidthstring used in lists */
+
+ /* some lines? */
+
+ /* some pagebreaks? */
+
+ /* noindent ? */
+
+ /* what about the alignment */
+ } else {
+#ifndef NEW_INSETS
+ /* dummy layout, that means a footnote ended */
+ footnoteflag = LyXParagraph::NO_FOOTNOTE;
+ buffer << ") ";
+ noparbreak = 1;
+#else
+ lyxerr << "Should this ever happen?" << endl;
+#endif
+ }
+
+ font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
+ actcell = 0;
+ for (i = 0; i < par->size(); ++i) {
+ if (!i && !footnoteflag && !noparbreak){
+ buffer << "\n\n";
+ for(j = 0; j < depth; ++j)
+ buffer << " ";
+ currlinelen = depth * 2;
+ switch(ltype) {
+ case 0: /* Standard */
+ case 4: /* (Sub)Paragraph */
+ case 5: /* Description */
+ break;
+ case 6: /* Abstract */
+ buffer << "Abstract\n\n";
+ break;
+ case 7: /* Bibliography */
+ if (!ref_printed) {
+ buffer << "References\n\n";
+ ref_printed = true;
+ }
+ break;
+ default:
+ buffer << par->labelstring << " ";
+ break;
+ }
+ if (ltype_depth > depth) {
+ for(j = ltype_depth - 1; j > depth; --j)
+ buffer << " ";
+ currlinelen += (ltype_depth-depth)*2;
+ }
+ }
+ font2 = par->GetFontSettings(params, i);
+ if (font1.latex() != font2.latex()) {
+ if (font2.latex() == LyXFont::OFF)
+ islatex = 0;
+ else
+ islatex = 1;
+ } else {
+ islatex = 0;
+ }
+ c = par->GetChar(i);
+ if (islatex)
+ continue;
+ switch (c) {
+ case LyXParagraph::META_INSET:
+ if ((inset = par->GetInset(i))) {
+ if (!inset->Ascii(this, buffer)) {
+ string dummy;
+ string s = rsplit(buffer.str(),
+ dummy, '\n');
+ currlinelen += s.length();
+ } else {
+ // to be sure it breaks paragraph
+ currlinelen += linelen;
+ }
+ }
+ break;
+ case LyXParagraph::META_NEWLINE:
+ buffer << "\n";
+ for(j = 0; j < depth; ++j)
+ buffer << " ";
+ currlinelen = depth * 2;
+ if (ltype_depth > depth) {
+ for(j = ltype_depth;
+ j > depth; --j)
+ buffer << " ";
+ currlinelen += (ltype_depth - depth) * 2;
+ }
+ break;
+ case LyXParagraph::META_HFILL:
+ buffer << "\t";
+ break;
+ case '\\':
+ buffer << "\\";
+ break;
+ default:
+ if ((linelen > 0) && (currlinelen > (linelen - 10)) &&
+ (c == ' ') && ((i + 2) < par->size()))
+ {
+ buffer << "\n";
+ for(j = 0; j < depth; ++j)
+ buffer << " ";
+ currlinelen = depth * 2;
+ if (ltype_depth > depth) {
+ for(j = ltype_depth;
+ j > depth; --j)
+ buffer << " ";
+ currlinelen += (ltype_depth-depth)*2;
+ }
+ } else if (c != '\0')
+ buffer << c;
+ else if (c == '\0')
+ lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
+ ++currlinelen;
+ break;
+ }
+ }
+ return buffer.str();
+}
+
+
+void Buffer::writeFileAscii(string const & fname, int linelen)
+{
+ ofstream ofs(fname.c_str());
+ if (!ofs) {
+ WriteFSAlert(_("Error: Cannot write file:"), fname);
+ return;
+ }
+ writeFileAscii(ofs, linelen);
+}
+
+
+void Buffer::writeFileAscii(ostream & ofs, int linelen)
+{
+ LyXParagraph * par = paragraph;
+ while (par) {
+ ofs << asciiParagraph(par, linelen);
+ par = par->next;
+ }
+ ofs << "\n";
+}
+#endif
void Buffer::makeLaTeXFile(string const & fname,
string const & original_path,
///
void writeFileAscii(string const & , int);
-
+ void writeFileAscii(std::ostream &, int);
+ string const asciiParagraph(LyXParagraph const *, int linelen) const;
///
void makeLaTeXFile(string const & filename,
string const & original_path,
reask = !MenuWriteAs(buf);
else if (buf->save()) {
lastfiles->newFile(buf->fileName());
+ reask = false;
} else {
if (buf->getUser())
AllowInput(buf->getUser());
}
-int InsetFig::Ascii(Buffer const *, ostream &) const
+int InsetFig::Ascii(Buffer const *, ostream &, int) const
{
return 0;
}
///
int Latex(Buffer const *, std::ostream &, bool fragile, bool free_space) const;
///
- int Ascii(Buffer const *, std::ostream &) const;
+ int Ascii(Buffer const *, std::ostream &, int linelen) const;
///
int Linuxdoc(Buffer const *, std::ostream &) const;
///
int Latex(Buffer const *, std::ostream &,
bool fragile, bool free_spc) const;
///
- int Ascii(Buffer const *, std::ostream &) const { return 0; }
+ int Ascii(Buffer const *, std::ostream &, int) const { return 0; }
///
int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
///
}
-int InsetCommand::Ascii(Buffer const *, ostream &) const
+int InsetCommand::Ascii(Buffer const *, ostream &, int) const
{
return 0;
}
virtual int Latex(Buffer const *, std::ostream &,
bool fragile, bool free_spc) const;
///
- int Ascii(Buffer const *, std::ostream &) const;
+ int Ascii(Buffer const *, std::ostream &, int linelen) const;
///
virtual int Linuxdoc(Buffer const *, std::ostream &) const;
///
///
int Latex(Buffer const *, std::ostream &, bool, bool) const { return 0; }
///
- int Ascii(Buffer const *, std::ostream &) const { return 0; }
+ int Ascii(Buffer const *, std::ostream &, int) const { return 0; }
///
int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
///
}
-int InsetExternal::Ascii(Buffer const * buf, std::ostream & os) const
+int InsetExternal::Ascii(Buffer const * buf, std::ostream & os, int) const
{
return write("Ascii", buf, os);
}
virtual int Latex(Buffer const *, std::ostream &, bool fragile,
bool free_spc) const;
///
- virtual int Ascii(Buffer const *, std::ostream &) const;
+ virtual int Ascii(Buffer const *, std::ostream &, int linelen) const;
///
virtual int Linuxdoc(Buffer const *, std::ostream &) const;
///
}
-int InsetGraphics::Ascii(Buffer const *, ostream &) const
+int InsetGraphics::Ascii(Buffer const *, ostream &, int) const
{
// No graphics in ascii output.
return 0;
int Latex(Buffer const *, std::ostream &,
bool fragile, bool free_spc) const;
///
- int Ascii(Buffer const *, std::ostream &) const;
+ int Ascii(Buffer const *, std::ostream &, int linelen) const;
///
int Linuxdoc(Buffer const *, std::ostream &) const;
///
}
-int InsetInfo::Ascii(Buffer const *, ostream &) const
+int InsetInfo::Ascii(Buffer const *, ostream &, int) const
{
return 0;
}
int Latex(Buffer const *, std::ostream &,
bool fragile, bool free_spc) const;
///
- int Ascii(Buffer const *, std::ostream &) const;
+ int Ascii(Buffer const *, std::ostream &, int linelen) const;
///
int Linuxdoc(Buffer const *, std::ostream &) const;
///
}
-int InsetLatexAccent::Ascii(Buffer const *, ostream & os) const
+int InsetLatexAccent::Ascii(Buffer const *, ostream & os, int) const
{
os << contents;
return 0;
int Latex(Buffer const *, std::ostream &,
bool fragile, bool free_spc) const;
///
- int Ascii(Buffer const *, std::ostream &) const;
+ int Ascii(Buffer const *, std::ostream &, int linelen) const;
///
int Linuxdoc(Buffer const *, std::ostream &) const;
///
}
-int InsetQuotes::Ascii(Buffer const *, ostream & os) const
+int InsetQuotes::Ascii(Buffer const *, ostream & os, int) const
{
os << "\"";
return 0;
int Latex(Buffer const *, std::ostream &,
bool fragile, bool free_spc) const;
///
- int Ascii(Buffer const *, std::ostream &) const;
+ int Ascii(Buffer const *, std::ostream &, int linelen) const;
///
int Linuxdoc(Buffer const *, std::ostream &) const;
///
return 0;
}
-int InsetSpecialChar::Ascii(Buffer const *, ostream & os) const
+int InsetSpecialChar::Ascii(Buffer const *, ostream & os, int) const
{
switch (kind) {
case HYPHENATION: break;
int InsetSpecialChar::Linuxdoc(Buffer const * buf, ostream & os) const
{
- return Ascii(buf, os);
+ return Ascii(buf, os, 0);
}
int InsetSpecialChar::DocBook(Buffer const * buf, ostream & os) const
{
- return Ascii(buf, os);
+ return Ascii(buf, os, 0);
}
int Latex(Buffer const *, std::ostream &,
bool fragile, bool free_spc) const;
///
- int Ascii(Buffer const *, std::ostream &) const;
+ int Ascii(Buffer const *, std::ostream &, int linelen) const;
///
int Linuxdoc(Buffer const *, std::ostream &) const;
///
}
-int InsetTabular::Ascii(Buffer const * buf, ostream & os) const
+int InsetTabular::Ascii(Buffer const * buf, ostream & os, int) const
{
// This should be changed to a real ascii export
return tabular->Latex(buf, os, false, false);
///
int Latex(Buffer const *, std::ostream &, bool, bool) const;
///
- int Ascii(Buffer const *, std::ostream &) const;
+ int Ascii(Buffer const *, std::ostream &, int linelen) const;
///
int Linuxdoc(Buffer const *, std::ostream &) const;
///
InsetText::~InsetText()
{
for(Cache::const_iterator cit=cache.begin(); cit != cache.end(); ++cit)
- deleteLyXText((*cit).first);
+ delete (*cit).second;
+// deleteLyXText((*cit).first);
LyXParagraph * p = par->next;
delete par;
while(p) {
}
+int InsetText::Ascii(Buffer const * buf, ostream & os, int linelen) const
+{
+ LyXParagraph * p = par;
+ while (p) {
+ os << buf->asciiParagraph(p, linelen);
+ p = p->next;
+ }
+ os << "\n";
+}
+
+
void InsetText::Validate(LaTeXFeatures & features) const
{
LyXParagraph * p = par;
int Latex(Buffer const *, std::ostream &,
bool fragile, bool free_spc) const;
///
- int Ascii(Buffer const *, std::ostream &) const { return 0; }
+ int Ascii(Buffer const *, std::ostream &, int linelen) const;
///
int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
///
virtual int Latex(Buffer const *, std::ostream &, bool fragile,
bool free_spc) const = 0;
///
- virtual int Ascii(Buffer const *, std::ostream &) const = 0;
+ virtual int Ascii(Buffer const *, std::ostream &, int linelen=0) const = 0;
///
virtual int Linuxdoc(Buffer const *, std::ostream &) const = 0;
///
}
-int InsetFormula::Ascii(Buffer const *, ostream & os) const
+int InsetFormula::Ascii(Buffer const *, ostream & os, int) const
{
par->Write(os, false);
return 0;
int InsetFormula::Linuxdoc(Buffer const * buf, ostream & os) const
{
- return Ascii(buf, os);
+ return Ascii(buf, os, 0);
}
int InsetFormula::DocBook(Buffer const * buf, ostream & os) const
{
- return Ascii(buf, os);
+ return Ascii(buf, os, 0);
}
int Latex(Buffer const *, std::ostream &,
bool fragile, bool free_spc) const;
///
- int Ascii(Buffer const *, std::ostream &) const;
+ int Ascii(Buffer const *, std::ostream &, int linelen) const;
///
int Linuxdoc(Buffer const *, std::ostream &) const;
///
int InsetFormulaMacro::Linuxdoc(Buffer const * buf, ostream & os) const
{
- return Ascii(buf, os);
+ return Ascii(buf, os, 0);
}
int InsetFormulaMacro::DocBook(Buffer const * buf, ostream & os) const
{
- return Ascii(buf, os);
+ return Ascii(buf, os, 0);
}
}
+const string write_attribute(const string name, const int value)
+{
+ string str = " " + name + "=\"" + tostr(value) + "\"";
+ return str;
+}
+
+
+const string write_attribute(string name, const string & value)
+{
+ string str = " " + name + "=\"" + value + "\"";
+ return str;
+}
+
+
+const string write_attribute(string name, const bool value)
+{
+ string str = " " + name + "=\"" + tostr((int)value) + "\"";
+ return str;
+}
+
+
void LyXTabular::Write(Buffer const * buf, ostream & os) const
{
// header line
- os << "<LyXTabular version=1 rows=" << rows_
- << " columns=" << columns_ << ">\n";
+ os << "<LyXTabular" <<
+ write_attribute("version", 1) <<
+ write_attribute("rows", rows_) <<
+ write_attribute("columns", columns_) <<
+ ">\n";
// global longtable options
- os << "<Features rotate=" << rotate
- << " islongtable=" << is_long_tabular
- << " endhead=" << endhead
- << " endfirsthead=" << endfirsthead
- << " endfoot=" << endfoot
- << " endlastfoot=" << endlastfoot << ">\n\n";
+ os << "<Features" <<
+ write_attribute("rotate", rotate) <<
+ write_attribute("islongtable", is_long_tabular) <<
+ write_attribute("endhead", endhead) <<
+ write_attribute("endfirsthead", endfirsthead) <<
+ write_attribute("endfoot", endfoot) <<
+ write_attribute("endlastfoot", endlastfoot) <<
+ ">\n\n";
for (int i = 0; i < rows_; ++i) {
- os << "<Row topline=" << row_info[i].top_line
- << " bottomline=" << row_info[i].bottom_line
- << " newpage=" << row_info[i].newpage << ">\n";
+ os << "<Row" <<
+ write_attribute("topline", row_info[i].top_line) <<
+ write_attribute("bottomline", row_info[i].bottom_line) <<
+ write_attribute("newpage", row_info[i].newpage) <<
+ ">\n";
for (int j = 0; j < columns_; ++j) {
if (!i) {
- os << "<Column alignment=" << column_info[j].alignment
- << " valignment=" << column_info[j].valignment
- << " leftline=" << column_info[j].left_line
- << " rightline=" << column_info[j].right_line
- << " width=\"" << VSpace(column_info[j].p_width).asLyXCommand()
- << "\" special=\"" << column_info[j].align_special
- << "\"\n>";
+ os << "<Column" <<
+ write_attribute("alignment", column_info[j].alignment) <<
+ write_attribute("valignment", column_info[j].valignment) <<
+ write_attribute("leftline", column_info[j].left_line) <<
+ write_attribute("rightline", column_info[j].right_line) <<
+ write_attribute("width", VSpace(column_info[j].p_width).asLyXCommand()) <<
+ write_attribute("special", column_info[j].align_special) <<
+ ">\n";
} else {
os << "<Column>\n";
}
- os << "<Cell multicolumn=" << cell_info[i][j].multicolumn
- << " alignment=" << cell_info[i][j].alignment
- << " valignment=" << cell_info[i][j].valignment
- << " topline=" << cell_info[i][j].top_line
- << " bottomline=" << cell_info[i][j].bottom_line
- << " leftline=" << cell_info[i][j].left_line
- << " rightline=" << cell_info[i][j].right_line
- << " rotate=" << cell_info[i][j].rotate
- << " usebox=" << (int)cell_info[i][j].usebox
- << " width=\"" << cell_info[i][j].p_width
- << "\" special=\"" << cell_info[i][j].align_special
- << "\">\n";
+ os << "<Cell" <<
+ write_attribute("multicolumn", cell_info[i][j].multicolumn) <<
+ write_attribute("alignment", cell_info[i][j].alignment) <<
+ write_attribute("valignment", cell_info[i][j].valignment) <<
+ write_attribute("topline", cell_info[i][j].top_line) <<
+ write_attribute("bottomline", cell_info[i][j].bottom_line) <<
+ write_attribute("leftline", cell_info[i][j].left_line) <<
+ write_attribute("rightline", cell_info[i][j].right_line) <<
+ write_attribute("rotate", cell_info[i][j].rotate) <<
+ write_attribute("usebox", (int)cell_info[i][j].usebox) <<
+ write_attribute("width", cell_info[i][j].p_width) <<
+ write_attribute("special", cell_info[i][j].align_special) <<
+ ">\n";
os << "\\begin_inset ";
cell_info[i][j].inset.Write(buf, os);
os << "\n\\end_inset \n"
<< "</Cell>\n"
- << "</Column\n>";
+ << "</Column>\n";
}
os << "</Row>\n";
}