diff --git a/development/FORMAT b/development/FORMAT index df52bc23be..298a787d9c 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,6 +1,9 @@ LyX file-format changes ----------------------- +2007-11-24 Uwe Stöhr + * Format incremented to 301: support for \linebreak + 2007-11-23 Uwe Stöhr * Format incremented to 300: support for \pagebreak diff --git a/lib/bind/aqua.bind b/lib/bind/aqua.bind index ef1aa67a7c..1155449987 100644 --- a/lib/bind/aqua.bind +++ b/lib/bind/aqua.bind @@ -26,7 +26,8 @@ \bind "M-~S-i s p" "hyphenation-point-insert" \bind "M-~S-i s k" "ligature-break-insert" \bind "M-~S-i s b" "protected-space-insert" -\bind "M-~S-i s l" "break-line" +\bind "M-~S-i s l" "new-line" +\bind "M-~S-i s r" "line-break" \bind "M-~S-i s i" "dots-insert" \bind "M-~S-i s e" "end-of-sentence-period-insert" \bind "M-~S-i s q" "self-insert \"" diff --git a/lib/bind/cua.bind b/lib/bind/cua.bind index 72a36382b9..e3e7791267 100644 --- a/lib/bind/cua.bind +++ b/lib/bind/cua.bind @@ -196,7 +196,8 @@ \bind "C-Delete" "word-delete-forward" \bind "C-BackSpace" "word-delete-backward" \bind "M-Return" "break-paragraph inverse" -\bind "C-Return" "break-line" +\bind "C-Return" "new-line" +\bind "C-S-Return" "line-break" \bind "C-k" "line-delete-forward" \bind "C-space" "space-insert protected" \bind "C-M-space" "space-insert normal" diff --git a/lib/bind/emacs.bind b/lib/bind/emacs.bind index 4b3a081f97..9760aa31d1 100644 --- a/lib/bind/emacs.bind +++ b/lib/bind/emacs.bind @@ -209,7 +209,8 @@ \bind "M-d" "word-delete-forward" \bind "C-BackSpace" "word-delete-backward" \bind "M-Return" "break-paragraph inverse" -\bind "C-Return" "break-line" +\bind "C-Return" "new-line" +\bind "C-S-Return" "line-break" \bind "C-S-L" "ligature-break-insert" \bind "C-space" "space-insert protected" \bind "C-M-space" "space-insert normal" diff --git a/lib/bind/mac.bind b/lib/bind/mac.bind index e38e34a821..1b36d07dc7 100644 --- a/lib/bind/mac.bind +++ b/lib/bind/mac.bind @@ -178,7 +178,8 @@ \bind "M-Delete" "word-delete-forward" \bind "M-BackSpace" "word-delete-backward" \bind "M-Return" "break-paragraph inverse" -\bind "C-Return" "break-line" +\bind "C-Return" "new-line" +\bind "C-S-Return" "line-break" \bind "C-k" "line-delete-forward" \bind "M-space" "space-insert protected" \bind "C-M-space" "space-insert normal" diff --git a/lib/bind/xemacs.bind b/lib/bind/xemacs.bind index 519860d847..69cd15a4a6 100644 --- a/lib/bind/xemacs.bind +++ b/lib/bind/xemacs.bind @@ -220,7 +220,8 @@ \bind "M-d" "word-delete-forward" \bind "C-BackSpace" "word-delete-backward" \bind "M-Return" "break-paragraph inverse" -\bind "C-Return" "break-line" +\bind "C-Return" "new-line" +\bind "C-S-Return" "line-break" \bind "C-S-L" "ligature-break-insert" \bind "C-space" "space-insert protected" \bind "C-M-space" "space-insert normal" diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index e11be98bb5..6cb03c5b3a 100644 --- a/lib/lyx2lyx/LyX.py +++ b/lib/lyx2lyx/LyX.py @@ -80,7 +80,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)), ("1_3", [221], minor_versions("1.3" , 7)), ("1_4", range(222,246), minor_versions("1.4" , 5)), ("1_5", range(246,277), minor_versions("1.5" , 2)), - ("1_6", range(277,301), minor_versions("1.6" , 0))] # Uwe: \pagebreak + ("1_6", range(277,302), minor_versions("1.6" , 0))] # Uwe: \linebreak def formats_list(): diff --git a/lib/lyx2lyx/lyx_1_6.py b/lib/lyx2lyx/lyx_1_6.py index 58f41486e1..1d191621da 100644 --- a/lib/lyx2lyx/lyx_1_6.py +++ b/lib/lyx2lyx/lyx_1_6.py @@ -799,6 +799,17 @@ def revert_pagebreak(document): i = i + 1 +def revert_linebreak(document): + 'Reverts linebreak to newline' + i = 0 + while True: + i = find_token(document.body, "\\linebreak", i) + if i == -1: + return + document.body[i] = document.body[i].replace("\\linebreak", "\\newline") + i = i + 1 + + ## # Conversion hub # @@ -827,10 +838,12 @@ convert = [[277, [fix_wrong_tables]], [297, [convert_usorbian]], [298, []], [299, []], - [300, []] + [300, []], + [301, []] ] -revert = [[299, [revert_pagebreak]], +revert = [[300, [revert_linebreak]], + [299, [revert_pagebreak]], [298, [revert_hyperlinktype]], [297, [revert_macro_optional_params]], [296, [revert_albanian, revert_lowersorbian, revert_uppersorbian]], diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc index 72dbd6e1c9..dd7e641008 100644 --- a/lib/ui/stdmenus.inc +++ b/lib/ui/stdmenus.inc @@ -360,7 +360,8 @@ Menuset Separator Item "Hyphenation Point|H" "hyphenation-point-insert" Item "Ligature Break|k" "ligature-break-insert" - Item "Line Break|B" "break-line" + Item "New Line|w" "new-line" + Item "Line Break|B" "line-break" Separator Item "New Page|N" "newpage-insert" Item "Page Break|a" "pagebreak-insert" diff --git a/src/Buffer.cpp b/src/Buffer.cpp index f1ed3ce599..526c4bae6b 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -153,7 +153,7 @@ namespace os = support::os; namespace { -int const LYX_FORMAT = 300; // Uwe: \pagebreak +int const LYX_FORMAT = 301; // Uwe: \linebreak } // namespace anon diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index e159f91b3f..4fbfdebebf 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -105,7 +105,6 @@ void LyXAction::init() { LFUN_BOOKMARK_GOTO, "bookmark-goto", NoBuffer, Edit }, { LFUN_BOOKMARK_SAVE, "bookmark-save", ReadOnly, Edit }, { LFUN_BOOKMARK_CLEAR, "bookmark-clear", NoBuffer, Edit }, - { LFUN_BREAK_LINE, "break-line", Noop, Edit }, { LFUN_BREAK_PARAGRAPH, "break-paragraph", Noop, Edit }, { LFUN_BREAK_PARAGRAPH_SKIP, "break-paragraph-skip", Noop, Edit }, { LFUN_BUILD_PROGRAM, "build-program", ReadOnly, Buffer }, @@ -214,6 +213,7 @@ void LyXAction::init() { LFUN_LAYOUT_TABULAR, "layout-tabular", Noop, Layout }, { LFUN_LINE_BEGIN, "line-begin", ReadOnly | NoUpdate, Edit }, { LFUN_LINE_BEGIN_SELECT, "line-begin-select", ReadOnly | SingleParUpdate, Edit }, + { LFUN_LINE_BREAK, "line-break", Noop, Edit }, { LFUN_LINE_DELETE, "line-delete-forward", Noop, Edit }, // there is no line-delete-backward { LFUN_LINE_END, "line-end", ReadOnly | NoUpdate, Edit }, { LFUN_LINE_END_SELECT, "line-end-select", ReadOnly | SingleParUpdate, Edit }, @@ -256,13 +256,14 @@ void LyXAction::init() { LFUN_MENU_OPEN, "menu-open", NoBuffer, Buffer }, { LFUN_MENU_SEPARATOR_INSERT, "menu-separator-insert", Noop, Edit }, { LFUN_META_PREFIX, "meta-prefix", NoBuffer, System }, - { LFUN_BRANCH_INSERT, "branch-insert", Noop, Edit }, - { LFUN_FLEX_INSERT, "flex-insert", Noop, Edit }, - { LFUN_NOTE_INSERT, "note-insert", Noop, Edit }, - { LFUN_BOX_INSERT, "box-insert", Noop, Edit }, - { LFUN_NOTE_NEXT, "note-next", ReadOnly, Edit }, - { LFUN_INSET_TOGGLE, "", ReadOnly, Hidden }, + { LFUN_NEW_LINE, "new-line", Noop, Edit }, { LFUN_NEXT_INSET_TOGGLE, "next-inset-toggle", ReadOnly, Edit }, + { LFUN_NOTE_INSERT, "note-insert", Noop, Edit }, + { LFUN_NOTE_NEXT, "note-next", ReadOnly, Edit }, + { LFUN_BRANCH_INSERT, "branch-insert", Noop, Edit }, + { LFUN_BOX_INSERT, "box-insert", Noop, Edit }, + { LFUN_FLEX_INSERT, "flex-insert", Noop, Edit }, + { LFUN_INSET_TOGGLE, "", ReadOnly, Hidden }, { LFUN_ALL_INSETS_TOGGLE, "all-insets-toggle", ReadOnly, Edit }, { LFUN_PARAGRAPH_DOWN, "paragraph-down", ReadOnly | NoUpdate, Edit }, { LFUN_PARAGRAPH_DOWN_SELECT, "paragraph-down-select", ReadOnly, Edit }, diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 9b40ba90b3..e0afc38728 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -702,7 +702,6 @@ void Paragraph::Private::latexInset(Buffer const & buf, if (runparams.moving_arg) os << "\\protect "; - os << "\\\\\n"; } texrow.newline(); texrow.start(owner_->id(), i + 1); diff --git a/src/Text.cpp b/src/Text.cpp index 02224a6ddc..c2ed96b2b2 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -232,6 +232,10 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex, } } else if (token == "\\backslash") { par.appendChar('\\', font, change); + } else if (token == "\\linebreak") { + auto_ptr inset(new InsetLinebreak); + inset->read(buf, lex); + par.insertInset(par.size(), inset.release(), font, change); } else if (token == "\\newline") { auto_ptr inset(new InsetNewline); inset->read(buf, lex); diff --git a/src/Text3.cpp b/src/Text3.cpp index 7b6a8f624e..0a0f92d6bd 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -670,7 +670,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) break; } - case LFUN_BREAK_LINE: { + case LFUN_NEW_LINE: { // Not allowed by LaTeX (labels or empty par) if (cur.pos() > cur.paragraph().beginOfBody()) { // this avoids a double undo @@ -684,6 +684,21 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) } break; } + + case LFUN_LINE_BREAK: { + // Not allowed by LaTeX (labels or empty par) + if (cur.pos() > cur.paragraph().beginOfBody()) { + // this avoids a double undo + // FIXME: should not be needed, ideally + if (!cur.selection()) + cur.recordUndo(); + cap::replaceSelection(cur); + cur.insert(new InsetLinebreak); + cur.posForward(); + moveCursor(cur, false); + } + break; + } case LFUN_CHAR_DELETE_FORWARD: if (!cur.selection()) { @@ -2089,8 +2104,9 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_PARAGRAPH_UP: case LFUN_PARAGRAPH_DOWN: case LFUN_LINE_BEGIN: + case LFUN_LINE_BREAK: case LFUN_LINE_END: - case LFUN_BREAK_LINE: + case LFUN_NEW_LINE: case LFUN_CHAR_DELETE_FORWARD: case LFUN_DELETE_FORWARD_SKIP: case LFUN_CHAR_DELETE_BACKWARD: diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index 3be7346a8d..bc5b76cb9d 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -651,7 +651,7 @@ bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_BIBITEM_INSERT: case LFUN_BOX_INSERT: case LFUN_BRANCH_INSERT: - case LFUN_BREAK_LINE: + case LFUN_NEW_LINE: case LFUN_CAPTION_INSERT: case LFUN_CLEARPAGE_INSERT: case LFUN_CLEARDOUBLEPAGE_INSERT: diff --git a/src/insets/InsetNewline.cpp b/src/insets/InsetNewline.cpp index 5a1af78d3e..55214ac776 100644 --- a/src/insets/InsetNewline.cpp +++ b/src/insets/InsetNewline.cpp @@ -20,6 +20,8 @@ #include "frontends/FontMetrics.h" #include "frontends/Painter.h" +#include "support/docstring.h" + namespace lyx { @@ -35,7 +37,7 @@ void InsetNewline::read(Buffer const &, Lexer &) void InsetNewline::write(Buffer const &, ostream & os) const { - os << "\n\\newline\n"; + os << "\n" << getLyXName() << '\n'; } @@ -48,10 +50,10 @@ void InsetNewline::metrics(MetricsInfo & mi, Dimension & dim) const } -int InsetNewline::latex(Buffer const &, odocstream &, +int InsetNewline::latex(Buffer const &, odocstream & os, OutputParams const &) const { - lyxerr << "Eek, calling InsetNewline::latex !" << endl; + os << from_ascii(getCmdName()) << '\n'; return 0; } @@ -74,6 +76,9 @@ int InsetNewline::docbook(Buffer const &, odocstream & os, void InsetNewline::draw(PainterInfo & pi, int x, int y) const { + FontInfo font; + font.setColor(ColorName()); + frontend::FontMetrics const & fm = theFontMetrics(pi.base.font); int const wid = fm.width('n'); int const asc = fm.maxAscent(); @@ -95,7 +100,7 @@ void InsetNewline::draw(PainterInfo & pi, int x, int y) const xp[2] = int(x + wid * 0.625); } - pi.pain.lines(xp, yp, 3, Color_eolmarker); + pi.pain.lines(xp, yp, 3, ColorName()); yp[0] = int(y - 0.500 * asc * 0.75); yp[1] = int(y - 0.500 * asc * 0.75); @@ -111,7 +116,18 @@ void InsetNewline::draw(PainterInfo & pi, int x, int y) const xp[2] = int(x); } - pi.pain.lines(xp, yp, 3, Color_eolmarker); + pi.pain.lines(xp, yp, 3, ColorName()); + + // add label text behind the newline marker to divide from \newline + int w = 0; + int a = 0; + int d = 0; + theFontMetrics(font).rectText(insetLabel(), w, a, d); + + int const text_start = int(x + 2 * wid); + + pi.pain.rectText(text_start, yp[0] + d, insetLabel(), font, + Color_none, Color_none); } diff --git a/src/insets/InsetNewline.h b/src/insets/InsetNewline.h index a03da2d197..4e24da3e25 100644 --- a/src/insets/InsetNewline.h +++ b/src/insets/InsetNewline.h @@ -14,6 +14,7 @@ #include "Inset.h" +#include "gettext.h" namespace lyx { @@ -37,12 +38,21 @@ public: virtual void read(Buffer const &, Lexer & lex); - virtual void write(Buffer const & buf, std::ostream & os) const; + virtual void write(Buffer const &, std::ostream & os) const; /// We don't need \begin_inset and \end_inset virtual bool directWrite() const { return true; } /// is this equivalent to a space (which is BTW different from // a line separator)? bool isSpace() const; + + virtual docstring insetLabel() const { return _(""); } + + virtual std::string getLyXName() const { return "\\newline"; } + + virtual std::string getCmdName() const { return "\\\\"; } + + virtual ColorCode ColorName() const { return Color_eolmarker; } + private: virtual Inset * clone() const { @@ -50,6 +60,25 @@ private: } }; +class InsetLinebreak : public InsetNewline { +public: + InsetLinebreak() {} + + docstring insetLabel() const { return _("line break"); } + + std::string getLyXName() const { return "\\linebreak"; } + + std::string getCmdName() const { return "\\linebreak{}"; } + + ColorCode ColorName() const { return Color_pagebreak; } + +private: + virtual Inset * clone() const + { + return new InsetLinebreak; + } +}; + } // namespace lyx diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 16dbe1427a..b8a5847e8f 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -3769,7 +3769,7 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd, } // disable in non-fixed-width cells - case LFUN_BREAK_LINE: + case LFUN_NEW_LINE: case LFUN_BREAK_PARAGRAPH: case LFUN_BREAK_PARAGRAPH_SKIP: { if (tabular.getPWidth(cur.idx()).zero()) { diff --git a/src/lfuns.h b/src/lfuns.h index b6089f0757..716d4c1b5e 100644 --- a/src/lfuns.h +++ b/src/lfuns.h @@ -125,7 +125,8 @@ enum kb_action { // 60 LFUN_CHAR_DELETE_FORWARD, LFUN_CHAR_DELETE_BACKWARD, - LFUN_BREAK_LINE, + LFUN_NEW_LINE, + LFUN_LINE_BREAK, LFUN_BREAK_PARAGRAPH, LFUN_QUOTE_INSERT, // 65 diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index eebcc990c7..f630fb2cff 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -1117,7 +1117,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd) } break; - case LFUN_BREAK_LINE: { + case LFUN_NEW_LINE: { cur.recordUndoInset(); row_type const r = cur.row(); addRow(r); diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 967843c48c..4df678a450 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -1045,7 +1045,7 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd) // just swallow this break; - case LFUN_BREAK_LINE: + case LFUN_NEW_LINE: // some magic for the common case if (type_ == hullSimple || type_ == hullEquation) { cur.recordUndoInset(); @@ -1176,7 +1176,7 @@ bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_DOWN: status.enabled(true); return true; - case LFUN_BREAK_LINE: + case LFUN_NEW_LINE: case LFUN_MATH_NUMBER: case LFUN_MATH_NONUMBER: case LFUN_MATH_EXTERN: diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index f30c17ebd9..c6af718433 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -2207,7 +2207,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, } } - else if (t.cs() == "newline") { + else if (t.cs() == "newline" || + t.cs() == "linebreak") { context.check_layout(os); os << "\n\\" << t.cs() << "\n"; skip_braces(p); // eat {}