From ea37831cfb454bfac18be6ec0c47e2b0897b77be Mon Sep 17 00:00:00 2001 From: Dekel Tsur Date: Sat, 18 Aug 2001 15:01:09 +0000 Subject: [PATCH] Few fixes for inserERT/insetNote git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2548 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/ChangeLog | 13 +++++++++ src/insets/insetert.C | 60 +++++++++++++++++++++++++++++++++++++++--- src/insets/insetert.h | 2 ++ src/insets/insetnote.C | 11 ++++++-- src/insets/insetnote.h | 10 ++++--- 5 files changed, 86 insertions(+), 10 deletions(-) diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 27f4ab5c95..54397c0a91 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,16 @@ +2001-08-18 Dekel Tsur + + * insetert.C (latex): Fix output for multiple paragraphs. + (write): New code for writing paragraph data. + (read): Set font after reading the inset. + (localDispatch): Call set_latex_font() for more cases. + + * insetnote.h: Add empty validate method. + * insetert.h: Ditto + + * insetnote.C (InsetNote): Set language to the language of the + document. + 2001-08-16 Juergen Vigna * insettext.C: implemented the new FINISHED states. diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 4780c868ee..4b93756d86 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -137,6 +137,24 @@ void InsetERT::read(Buffer const * buf, LyXLex & lex) } } inset.read(buf, lex); + +#ifndef INHERIT_LANG + LyXFont font(LyXFont::ALL_INHERIT, latex_language); +#else + LyXFont font(LyXFont::ALL_INHERIT); +#endif + + font.setFamily(LyXFont::TYPEWRITER_FAMILY); + font.setColor(LColor::latex); + Paragraph * par = inset.paragraph(); + while (par) { + Paragraph::size_type siz = par->size(); + for (Paragraph::size_type i = 0; i < siz; ++i) { + par->setFont(i, font); + } + par = par->next(); + } + if (!token_found) { if (collapsed_) { status(0, Collapsed); @@ -167,7 +185,33 @@ void InsetERT::write(Buffer const * buf, ostream & os) const os << getInsetName() << "\n" << "status "<< st << "\n"; - inset.writeParagraphData(buf, os); + //inset.writeParagraphData(buf, os); + string const layout = + textclasslist.NameOfLayout(buf->params.textclass, 0); + Paragraph * par = inset.paragraph(); + while (par) { + os << "\n\\layout " << layout << "\n"; + Paragraph::size_type siz = par->size(); + for (Paragraph::size_type i = 0; i < siz; ++i) { + Paragraph::value_type c = par->getChar(i); + switch (c) { + case Paragraph::META_INSET: + case Paragraph::META_HFILL: + lyxerr << "Element is not allowed in insertERT" + << std::endl; + case Paragraph::META_NEWLINE: + os << "\n\\newline \n"; + break; + case '\\': + os << "\n\\backslash \n"; + break; + default: + os << c; + break; + } + } + par = par->next(); + } } @@ -272,9 +316,9 @@ int InsetERT::latex(Buffer const *, std::ostream & os, bool /*fragile*/, { Paragraph * par = inset.paragraph(); while (par) { - Paragraph::size_type siz = inset.paragraph()->size(); - for (Paragraph::size_type i = 0; i != siz; ++i) { - char c = inset.paragraph()->getChar(i); + Paragraph::size_type siz = par->size(); + for (Paragraph::size_type i = 0; i < siz; ++i) { + Paragraph::value_type c = par->getChar(i); switch (c) { case Paragraph::META_NEWLINE: os << '\n'; @@ -285,6 +329,8 @@ int InsetERT::latex(Buffer const *, std::ostream & os, bool /*fragile*/, } } par = par->next(); + if (par) + os << "\n\n"; } return 1; @@ -329,6 +375,12 @@ InsetERT::localDispatch(BufferView * bv, kb_action action, string const & arg) switch(action) { case LFUN_BREAKPARAGRAPH: case LFUN_BREAKPARAGRAPHKEEPLAYOUT: + case LFUN_BACKSPACE: + case LFUN_BACKSPACE_SKIP: + case LFUN_DELETE: + case LFUN_DELETE_SKIP: + case LFUN_DELETE_LINE_FORWARD: + case LFUN_CUT: set_latex_font(bv); break; diff --git a/src/insets/insetert.h b/src/insets/insetert.h index 69a3a155fd..4120b8d5f0 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -80,6 +80,8 @@ public: /// int docBook(Buffer const *, std::ostream &) const; /// + void validate(LaTeXFeatures &) const {} + /// UpdatableInset::RESULT localDispatch(BufferView *, kb_action, string const &); /// diff --git a/src/insets/insetnote.C b/src/insets/insetnote.C index 7fa321f801..476e5595b6 100644 --- a/src/insets/insetnote.C +++ b/src/insets/insetnote.C @@ -59,6 +59,7 @@ Inset * InsetNote::clone(Buffer const &, bool same_id) const } +// This constructor is used for reading old InsetInfo InsetNote::InsetNote(Buffer const * buf, string const & contents, bool collapsed) : InsetCollapsable(collapsed) @@ -67,8 +68,14 @@ InsetNote::InsetNote(Buffer const * buf, string const & contents, Paragraph * par = inset.paragraph(); Paragraph::size_type pos = 0; - buf->insertStringAsLines(par, pos, LyXFont(LyXFont::ALL_INHERIT), - strip(contents, '\n')); + LyXFont font(LyXFont::ALL_INHERIT, buf->params.language); + + // Since XForms doesn't support RTL, we can assume that old notes + // in RTL documents are written in English. + if (font.language()->RightToLeft()) + font.setLanguage(default_language); + + buf->insertStringAsLines(par, pos, font, strip(contents, '\n')); } diff --git a/src/insets/insetnote.h b/src/insets/insetnote.h index 5d5a7b16db..5def38e637 100644 --- a/src/insets/insetnote.h +++ b/src/insets/insetnote.h @@ -32,14 +32,16 @@ public: /// constructor with initial contents InsetNote(Buffer const *, string const & contents, bool collapsed); /// - virtual string const editMessage() const; + string const editMessage() const; /// - virtual Inset::Code lyxCode() const { return Inset::IGNORE_CODE; } + Inset::Code lyxCode() const { return Inset::IGNORE_CODE; } /// - virtual void write(Buffer const *, std::ostream &) const; + void write(Buffer const *, std::ostream &) const; /// - virtual int latex(Buffer const *, std::ostream &, bool, bool) const + int latex(Buffer const *, std::ostream &, bool, bool) const { return 0; } + /// + void validate(LaTeXFeatures &) const {} private: /// used by the constructors void init(); -- 2.39.2