Am Freitag, 21. Januar 2005 17:14 schrieb Angus Leeming: > Option 1, Definitely. Without question.
Here comes the patch. Because it was related, I also treated the reproducible part of bug 922: Layout and font attributes should not be pasted into ERT insets, we only want the plain text. I disabled a lot of LFUNs so that changing of these attributes is not possible anymore. insetnewline does not make sense in ERT IMO, so I disabled it. newline insets in pasted text are converted to paragraph breaks in CutAndPaste.C. I would like to have this conversion in insertert.C, but this is unfortunately not possible. Comments? Georg
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/development/ChangeLog lyx-1.4-cvs/development/ChangeLog --- lyx-1.4-clean/development/ChangeLog 2005-01-24 20:13:25.000000000 +0100 +++ lyx-1.4-cvs/development/ChangeLog 2005-01-29 17:00:54.000000000 +0100 @@ -1,3 +1,7 @@ +2005-01-29 Georg Baum <[EMAIL PROTECTED]> + + * FORMAT: document change to format 241. + 2005-01-24 Jürgen Spitzmüller <[EMAIL PROTECTED]> * FORMAT: document change to format 240. diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/development/FORMAT lyx-1.4-cvs/development/FORMAT --- lyx-1.4-clean/development/FORMAT 2005-01-24 20:13:26.000000000 +0100 +++ lyx-1.4-cvs/development/FORMAT 2005-01-29 17:00:46.000000000 +0100 @@ -1,6 +1,21 @@ LyX file-format changes ----------------------- +2005-01-29 Georg Baum <[EMAIL PROTECTED]> + + * format incremented to 241. + + All following changes apply only to text in ERT insets. The + rationale is that text in ERT is simply ASCII text, and nothing more. + + * paragraph breaks are now a single newline in latex and not a + paragraph break anymore (bug 698). + * \newline is not allowed anymore, because it is redundant (see above) + * layouts other than Standard, paragraph parameters and font changes + are not allowed anymore. They never made sense and were ignored for + latex output, but now they can't be read or set anymore (bug 922). + + 2005-01-23 Jürgen Spitzmüller <[EMAIL PROTECTED]> * format incremented to 240. diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/lib/ChangeLog lyx-1.4-cvs/lib/ChangeLog --- lyx-1.4-clean/lib/ChangeLog 2005-01-24 20:13:30.000000000 +0100 +++ lyx-1.4-cvs/lib/ChangeLog 2005-01-29 17:06:05.000000000 +0100 @@ -1,4 +1,4 @@ -2005-01-15 Georg Baum <[EMAIL PROTECTED]> +2005-01-24 Jürgen Spitzmüller <[EMAIL PROTECTED]> * ui/classic.ui, ui/stdmenus.ui: add output-changes. diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/lib/lyx2lyx/ChangeLog lyx-1.4-cvs/lib/lyx2lyx/ChangeLog --- lyx-1.4-clean/lib/lyx2lyx/ChangeLog 2005-01-24 20:13:55.000000000 +0100 +++ lyx-1.4-cvs/lib/lyx2lyx/ChangeLog 2005-01-29 20:49:46.000000000 +0100 @@ -1,3 +1,9 @@ +2005-01-29 Georg Baum <[EMAIL PROTECTED]> + + * LyX.py: format up to 241 + * lyx_1_4.py (convert_ert_paragraphs, revert_ert_paragraphs): new + * lyx_1_4.py, LyX.py: handle new format 241 + 2005-01-24 Georg Baum <[EMAIL PROTECTED]> * LyX.py: format up to 240. diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/lib/lyx2lyx/lyx_1_4.py lyx-1.4-cvs/lib/lyx2lyx/lyx_1_4.py --- lyx-1.4-clean/lib/lyx2lyx/lyx_1_4.py 2005-01-24 20:13:55.000000000 +0100 +++ lyx-1.4-cvs/lib/lyx2lyx/lyx_1_4.py 2005-01-29 18:08:30.000000000 +0100 @@ -1552,6 +1680,122 @@ def revert_output_changes (file): ## +# Convert paragraph breaks and sanitize paragraphs +# +def convert_ert_paragraphs(file): + forbidden_settings = [ + # paragraph parameters + '\\paragraph_spacing', '\\labelwidthstring', + '\\start_of_appendix', '\\noindent', + '\\leftindent', '\\align', + # font settings + '\\family', '\\series', '\\shape', '\\size', + '\\emph', '\\numeric', '\\bar', '\\noun', + '\\color', '\\lang'] + i = 0 + while 1: + i = find_token(file.body, '\\begin_inset ERT', i) + if i == -1: + return + j = find_end_of_inset(file.body, i) + if j == -1: + file.warning("Malformed lyx file: Missing '\\end_inset'.") + i = i + 1 + continue + + # convert non-standard paragraphs to standard + k = i + while 1: + k = find_token(file.body, "\\begin_layout", k, j) + if k == -1: + break + file.body[k] = "\\begin_layout Standard" + k = k + 1 + + # remove all paragraph parameters and font settings + k = i + while k < j: + if (strip(file.body[k]) and + split(file.body[k])[0] in forbidden_settings): + del file.body[k] + j = j - 1 + else: + k = k + 1 + + # insert an empty paragraph before each paragraph but the first + k = i + first_pagraph = 1 + while 1: + k = find_token(file.body, "\\begin_layout Standard", k, j) + if k == -1: + break + if first_pagraph: + first_pagraph = 0 + k = k + 1 + continue + file.body[k:k] = ["\\begin_layout Standard", "", + "\\end_layout", ""] + k = k + 5 + j = j + 4 + + # convert \\newline to new paragraph + k = i + while 1: + k = find_token(file.body, "\\newline", k, j) + if k == -1: + break + file.body[k:k+1] = ["\\end_layout", "", "\\begin_layout Standard"] + k = k + 4 + j = j + 3 + i = i + 1 + + +## +# Remove double paragraph breaks +# +def revert_ert_paragraphs(file): + i = 0 + while 1: + i = find_token(file.body, '\\begin_inset ERT', i) + if i == -1: + return + j = find_end_of_inset(file.body, i) + if j == -1: + file.warning("Malformed lyx file: Missing '\\end_inset'.") + i = i + 1 + continue + + # replace paragraph breaks with \newline + k = i + while 1: + k = find_token(file.body, "\\end_layout", k, j) + l = find_token(file.body, "\\begin_layout", k, j) + if k == -1 or l == -1: + break + file.body[k:l+1] = ["\\newline"] + j = j - l + k + k = k + 1 + + # replace double \newlines with paragraph breaks + k = i + while 1: + k = find_token(file.body, "\\newline", k, j) + if k == -1: + break + l = k + 1 + while file.body[l] == "": + l = l + 1 + if strip(file.body[l]) and split(file.body[l])[0] == "\\newline": + file.body[k:l+1] = ["\\end_layout", "", + "\\begin_layout Standard"] + j = j - l + k + 2 + k = k + 3 + else: + k = k + 1 + i = i + 1 + + +## # Convertion hub # @@ -1575,9 +1834,11 @@ convert = [[223, [insert_tracking_change [237, [use_x_boolean]], [238, [update_latexaccents]], [239, [normalize_paragraph_params]], - [240, [convert_output_changes]]] + [240, [convert_output_changes]], + [241, [convert_ert_paragraphs]]] -revert = [[239, [revert_output_changes]], +revert = [[240, [revert_ert_paragraphs]], + [239, [revert_output_changes]], [238, []], [237, []], [236, [use_x_binary]], Nur in lyx-1.4-cvs/lib/lyx2lyx: lyx_1_4.pyc. diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/lib/lyx2lyx/LyX.py lyx-1.4-cvs/lib/lyx2lyx/LyX.py --- lyx-1.4-clean/lib/lyx2lyx/LyX.py 2005-01-24 20:13:55.000000000 +0100 +++ lyx-1.4-cvs/lib/lyx2lyx/LyX.py 2005-01-24 20:27:17.000000000 +0100 @@ -46,7 +46,7 @@ format_relation = [("0_10", [210], ["0. ("1_1_6fix3", [218], ["1.1.6fix3","1.1.6fix4","1.1"]), ("1_2", [220], ["1.2.0","1.2.1","1.2.3","1.2.4","1.2"]), ("1_3", [221], ["1.3.0","1.3.1","1.3.2","1.3.3","1.3.4","1.3.5","1.3"]), - ("1_4", range(223,241), ["1.4.0cvs","1.4"])] + ("1_4", range(223,242), ["1.4.0cvs","1.4"])] def formats_list(): diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/buffer.C lyx-1.4-cvs/src/buffer.C --- lyx-1.4-clean/src/buffer.C 2005-01-29 12:19:44.000000000 +0100 +++ lyx-1.4-cvs/src/buffer.C 2005-01-29 12:37:13.000000000 +0100 @@ -138,7 +144,7 @@ extern BufferList bufferlist; namespace { -int const LYX_FORMAT = 240; +int const LYX_FORMAT = 241; } // namespace anon diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/ChangeLog lyx-1.4-cvs/src/ChangeLog --- lyx-1.4-clean/src/ChangeLog 2005-01-29 12:15:43.000000000 +0100 +++ lyx-1.4-cvs/src/ChangeLog 2005-01-29 21:01:18.000000000 +0100 @@ -1,3 +1,11 @@ +2005-01-29 Georg Baum <[EMAIL PROTECTED]> + + * buffer.C: format up to 241. + * CutAndPaste.C (pasteSelectionHelper): convert newline to paragraph + break if pasting into ERT + * lyxfunc.C (getStatus): suppress mathpanel and + LFUN_DIALOG_SHOW_NEW_INSET in ERT + 2005-01-28 Jürgen Spitzmüller <[EMAIL PROTECTED]> * LaTeXFeatures.C (getAvailable): always clear packages_ list. diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/CutAndPaste.C lyx-1.4-cvs/src/CutAndPaste.C --- lyx-1.4-clean/src/CutAndPaste.C 2005-01-22 10:42:41.000000000 +0100 +++ lyx-1.4-cvs/src/CutAndPaste.C 2005-01-29 17:59:57.000000000 +0100 @@ -114,6 +114,21 @@ pasteSelectionHelper(Buffer const & buff // Now remove all out of the pars which is NOT allowed in the // new environment and set also another font if that is required. + // Convert newline to paragraph break in ERT inset. + // This should not be here! + if (pars[pit].inInset()->lyxCode() == InsetBase::ERT_CODE) { + for (ParagraphList::size_type i = 0; i < insertion.size(); ++i) { + for (pos_type j = 0; j < insertion[i].size(); ++j) { + if (insertion[i].isNewline(j)) { + insertion[i].erase(j); + breakParagraphConservative( + buffer.params(), + insertion, i, j); + } + } + } + } + // Make sure there is no class difference. lyx::cap::SwitchLayoutsBetweenClasses(textclass, tc, insertion, errorlist); @@ -145,10 +160,9 @@ pasteSelectionHelper(Buffer const & buff // Set the inset owner of this paragraph. tmpbuf->setInsetOwner(pars[pit].inInset()); for (pos_type i = 0; i < tmpbuf->size(); ++i) { - if (tmpbuf->getChar(i) == Paragraph::META_INSET) { - if (!pars[pit].insetAllowed(tmpbuf->getInset(i)->lyxCode())) - tmpbuf->erase(i--); - } + if (tmpbuf->getChar(i) == Paragraph::META_INSET && + !pars[pit].insetAllowed(tmpbuf->getInset(i)->lyxCode())) + tmpbuf->erase(i--); } } diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/lyxfunc.C lyx-1.4-cvs/src/lyxfunc.C --- lyx-1.4-clean/src/lyxfunc.C 2005-01-29 12:19:44.000000000 +0100 +++ lyx-1.4-cvs/src/lyxfunc.C 2005-01-29 20:34:50.000000000 +0100 @@ -93,6 +93,7 @@ using bv_funcs::freefont2string; +using lyx::support::AbsolutePath; using lyx::support::AddName; using lyx::support::AddPath; using lyx::support::bformat; @@ -485,7 +486,7 @@ FuncStatus LyXFunc::getStatus(FuncReques else if (name == "print") enable = Exporter::IsExportable(*buf, "dvi") && lyxrc.print_command != "none"; - else if (name == "character") + else if (name == "character" || name == "mathpanel") enable = cur.inset().lyxCode() != InsetBase::ERT_CODE; else if (name == "vclog") enable = buf->lyxvc().inUse(); @@ -494,6 +495,10 @@ FuncStatus LyXFunc::getStatus(FuncReques break; } + case LFUN_DIALOG_SHOW_NEW_INSET: + enable = cur.inset().lyxCode() != InsetBase::ERT_CODE; + break; + case LFUN_DIALOG_UPDATE: { string const name = cmd.getArg(0); if (!buf) @@ -538,7 +543,6 @@ FuncStatus LyXFunc::getStatus(FuncReques case LFUN_NOTIFY: case LFUN_GOTOFILEROW: case LFUN_GOTO_PARAGRAPH: - case LFUN_DIALOG_SHOW_NEW_INSET: case LFUN_DIALOG_SHOW_NEXT_INSET: case LFUN_DIALOG_HIDE: case LFUN_DIALOG_DISCONNECT_INSET: diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/ChangeLog lyx-1.4-cvs/src/insets/ChangeLog --- lyx-1.4-clean/src/insets/ChangeLog 2005-01-29 12:19:46.000000000 +0100 +++ lyx-1.4-cvs/src/insets/ChangeLog 2005-01-29 20:56:17.000000000 +0100 @@ -1,3 +1,10 @@ +2005-01-29 Georg Baum <[EMAIL PROTECTED]> + + * insetert.C (latex, linuxdoc, docbook): remove newline handling + * insetert.C (doDispatch): clean pasted paragraphs + * insetert.C (getStatus): suppress more lfuns + * insetert.C (insetAllowed): return always false + 2005-01-27 Lars Gullik Bjonnes <[EMAIL PROTECTED]> * Several files: use convert<> instead of atoi,strToXXX and friends diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/insetert.C lyx-1.4-cvs/src/insets/insetert.C --- lyx-1.4-clean/src/insets/insetert.C 2004-12-02 14:05:37.000000000 +0100 +++ lyx-1.4-cvs/src/insets/insetert.C 2005-01-29 20:36:10.000000000 +0100 @@ -16,6 +16,7 @@ #include "buffer.h" #include "bufferparams.h" #include "BufferView.h" +#include "cursor.h" #include "debug.h" #include "dispatchresult.h" #include "funcrequest.h" @@ -23,8 +24,11 @@ #include "gettext.h" #include "language.h" #include "LColor.h" +#include "LyXAction.h" #include "lyxlex.h" +#include "lyxtextclass.h" #include "metricsinfo.h" +#include "ParagraphParameters.h" #include "paragraph.h" #include "frontends/Alert.h" @@ -33,6 +37,7 @@ #include <sstream> using lyx::pos_type; +using lyx::support::token; using std::endl; using std::min; @@ -130,12 +135,7 @@ int InsetERT::latex(Buffer const &, ostr if (isDeletedText(*par, i)) continue; - if (par->isNewline(i)) { - os << '\n'; - ++lines; - } else { - os << par->getChar(i); - } + os << par->getChar(i); } ++par; if (par != end) { @@ -164,14 +164,8 @@ int InsetERT::linuxdoc(Buffer const &, o int lines = 0; while (par != end) { pos_type siz = par->size(); - for (pos_type i = 0; i < siz; ++i) { - if (par->isNewline(i)) { - os << '\n'; - ++lines; - } else { - os << par->getChar(i); - } - } + for (pos_type i = 0; i < siz; ++i) + os << par->getChar(i); ++par; if (par != end) { os << "\n"; @@ -192,14 +186,8 @@ int InsetERT::docbook(Buffer const &, os int lines = 0; while (par != end) { pos_type siz = par->size(); - for (pos_type i = 0; i < siz; ++i) { - if (par->isNewline(i)) { - os << '\n'; - ++lines; - } else { - os << par->getChar(i); - } - } + for (pos_type i = 0; i < siz; ++i) + os << par->getChar(i); ++par; if (par != end) { os << "\n"; @@ -222,7 +210,34 @@ void InsetERT::doDispatch(LCursor & cur, setStatus(st); break; } + case LFUN_PASTE: + case LFUN_PASTESELECTION: { + InsetCollapsable::doDispatch(cur, cmd); + // Since we can only store plain text, we must reset all + // attributes. + // FIXME: Change only the pasted paragraphs + + BufferParams const & bp = cur.buffer().params(); + LyXLayout_ptr const layout = + bp.getLyXTextClass().defaultLayout(); + LyXFont font = layout->font; + // We need to set the language for non-english documents + font.setLanguage(bp.language); + ParagraphList::iterator const end = paragraphs().end(); + for (ParagraphList::iterator par = paragraphs().begin(); + par != end; ++par) { + par->layout(layout); + // in case par had a manual label + par->setBeginOfBody(); + pos_type const siz = par->size(); + for (pos_type i = 0; i < siz; ++i) { + par->setFont(i, font); + } + par->params().clear(); + } + break; + } default: InsetCollapsable::doDispatch(cur, cmd); break; @@ -235,7 +250,36 @@ bool InsetERT::getStatus(LCursor & cur, { switch (cmd.action) { // suppress these - case LFUN_LAYOUT: + case LFUN_ACUTE: + case LFUN_BREVE: + case LFUN_CARON: + case LFUN_CEDILLA: + case LFUN_CIRCLE: + case LFUN_CIRCUMFLEX: + case LFUN_DOT: + case LFUN_GRAVE: + case LFUN_HUNG_UMLAUT: + case LFUN_MACRON: + case LFUN_OGONEK: + case LFUN_SPECIAL_CARON: + case LFUN_TIE: + case LFUN_TILDE: + case LFUN_UMLAUT: + case LFUN_UNDERBAR: + case LFUN_UNDERDOT: + case LFUN_APPENDIX: + case LFUN_BREAKLINE: + case LFUN_INSET_CAPTION: + case LFUN_DEPTH_MIN: + case LFUN_DEPTH_PLUS: + case LFUN_LDOTS: + case LFUN_END_OF_SENTENCE: + case LFUN_ENVIRONMENT_INSERT: + case LFUN_INSET_ERT: + case LFUN_FILE_INSERT: + case LFUN_INSET_FLOAT: + case LFUN_INSET_WIDE_FLOAT: + case LFUN_INSET_WRAP: case LFUN_BOLD: case LFUN_CODE: case LFUN_DEFAULT: @@ -250,12 +294,66 @@ bool InsetERT::getStatus(LCursor & cur, case LFUN_FONT_SIZE: case LFUN_FONT_STATE: case LFUN_UNDERLINE: + case LFUN_INSET_FOOTNOTE: + case LFUN_HFILL: + case LFUN_HTMLURL: + case LFUN_HYPHENATION: + case LFUN_LIGATURE_BREAK: + case LFUN_INDEX_INSERT: + case LFUN_INDEX_PRINT: + case LFUN_INSERT_LABEL: + case LFUN_INSET_OPTARG: + case LFUN_INSERT_BIBITEM: + case LFUN_INSERT_LINE: + case LFUN_INSERT_PAGEBREAK: + case LFUN_LANGUAGE: + case LFUN_LAYOUT: + case LFUN_LAYOUT_PARAGRAPH: + case LFUN_LAYOUT_TABULAR: + case LFUN_INSET_MARGINAL: + case LFUN_MATH_DISPLAY: + case LFUN_INSERT_MATH: + case LFUN_INSERT_MATRIX: + case LFUN_MATH_MODE: + case LFUN_MENU_OPEN_BY_NAME: + case LFUN_MENU_SEPARATOR: + case LFUN_INSERT_BRANCH: + case LFUN_INSERT_CHARSTYLE: + case LFUN_INSERT_NOTE: + case LFUN_INSERT_BOX: + case LFUN_GOTONOTE: + case LFUN_PARAGRAPH_SPACING: + case LFUN_QUOTE: + case LFUN_REF_GOTO: + case LFUN_REFERENCE_GOTO: + case LFUN_SPACE_INSERT: + case LFUN_GOTOFILEROW: + case LFUN_NOTIFY: + case LFUN_SETXY: + case LFUN_TABULAR_INSERT: + case LFUN_TOC_INSERT: + case LFUN_URL: + case LFUN_FLOAT_LIST: + case LFUN_INSET_INSERT: + case LFUN_PARAGRAPH_APPLY: + case LFUN_PARAGRAPH_UPDATE: + case LFUN_NOACTION: status.enabled(false); return true; + // this one is difficult to get right. As a half-baked + // solution, we consider only the first action of the sequence + case LFUN_SEQUENCE: { + // argument contains ';'-terminated commands + string const firstcmd = token(cmd.argument, ';', 0); + FuncRequest func(lyxaction.lookupFunc(firstcmd)); + func.origin = cmd.origin; + return getStatus(cur, func, status); + } + default: return InsetCollapsable::getStatus(cur, cmd, status); - } + } } @@ -265,9 +701,9 @@ void InsetERT::setButtonLabel() } -bool InsetERT::insetAllowed(InsetBase::Code code) const +bool InsetERT::insetAllowed(InsetBase::Code /* code */) const { - return code == InsetBase::NEWLINE_CODE; + return false; }