]> git.lyx.org Git - features.git/commitdiff
support for \linebreak:
authorUwe Stöhr <uwestoehr@web.de>
Sun, 25 Nov 2007 18:34:37 +0000 (18:34 +0000)
committerUwe Stöhr <uwestoehr@web.de>
Sun, 25 Nov 2007 18:34:37 +0000 (18:34 +0000)
- fileformat change
- tex2lyx support
- rename LFUN_BREAK_LINE to LFUN_NEW_LINE because this is what the lfun does and to avoid confusions
- new menu entry
- new shortcut C-S-Return

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21778 a592a061-630c-0410-9148-cb99ea01b6c8

22 files changed:
development/FORMAT
lib/bind/aqua.bind
lib/bind/cua.bind
lib/bind/emacs.bind
lib/bind/mac.bind
lib/bind/xemacs.bind
lib/lyx2lyx/LyX.py
lib/lyx2lyx/lyx_1_6.py
lib/ui/stdmenus.inc
src/Buffer.cpp
src/LyXAction.cpp
src/Paragraph.cpp
src/Text.cpp
src/Text3.cpp
src/insets/InsetCollapsable.cpp
src/insets/InsetNewline.cpp
src/insets/InsetNewline.h
src/insets/InsetTabular.cpp
src/lfuns.h
src/mathed/InsetMathGrid.cpp
src/mathed/InsetMathHull.cpp
src/tex2lyx/text.cpp

index df52bc23beea146af392ccaf093a5cffe5e0f304..298a787d9cb237a7d2048da5ef40f91523ffeeb8 100644 (file)
@@ -1,6 +1,9 @@
 LyX file-format changes
 -----------------------
 
+2007-11-24 Uwe Stöhr <uwestoehr@web.de>
+       * Format incremented to 301: support for \linebreak
+
 2007-11-23 Uwe Stöhr <uwestoehr@web.de>
        * Format incremented to 300: support for \pagebreak
 
index ef1aa67a7cc8e187f40329d0854a7b36ff26622d..1155449987cb8921a5a8ca0606c6ee4bee68012a 100644 (file)
@@ -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 \""
index 72a36382b98a46a43c88ee9f3372a116a16a4c5c..e3e7791267fb9ac57c878c0cf4b3c3867cedabc3 100644 (file)
 \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"
index 4b3a081f9759fc00bf7718597f74a8fa75fe6cfa..9760aa31d1db5e111b097f4df43ab5b94d728919 100644 (file)
 \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"
index e38e34a821ef3875e45dc0e2fe8c6b24d5dd08ef..1b36d07dc7bb386369f0580e90a4bd6827903990 100644 (file)
 \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"
index 519860d847b2ae6a95d172860fb502bf8582fe1d..69cd15a4a6fd02940b01c6a02789d85f274bc990 100644 (file)
 \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"
index e11be98bb5cbff222b2dde925571ded65c7b0d27..6cb03c5b3a7ff5746ffd99cabd781bb4713fea1c 100644 (file)
@@ -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():
index 58f41486e15879ce613fbc30ed529b15a0b01e71..1d191621da349c8259ff58b2d992e97972c50923 100644 (file)
@@ -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]],
index 72dbd6e1c94c9b7fd178d41e1940b3cef4cd1de1..dd7e64100847936cf740cb62afa33886e9e4c71d 100644 (file)
@@ -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"
index f1ed3ce59980040500489cf726d092cccefeaf52..526c4bae6b71b3e775a2021d75f717638de8e120 100644 (file)
@@ -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
 
index e159f91b3ff64d91db008ba438b9957453480ae4..4fbfdebebfbe24ea7e22ee686e15c7d61d0a9bf9 100644 (file)
@@ -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_NEW_LINE, "new-line", Noop, Edit },
+               { LFUN_NEXT_INSET_TOGGLE, "next-inset-toggle", ReadOnly, Edit },
                { LFUN_NOTE_INSERT, "note-insert", Noop, Edit },
-               { LFUN_BOX_INSERT, "box-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_NEXT_INSET_TOGGLE, "next-inset-toggle", ReadOnly, Edit },
                { 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 },
index 9b40ba90b308763671c7a6c65ddd8ef8b04dd38f..e0afc387287a49338842a7c00cdeec33d0a553ae 100644 (file)
@@ -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);
index 02224a6ddc1b1d5925f3a22402bfefdc93a4e2b9..c2ed96b2b274560d6aae70d2a45709410e0038a4 100644 (file)
@@ -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> inset(new InsetLinebreak);
+               inset->read(buf, lex);
+               par.insertInset(par.size(), inset.release(), font, change);
        } else if (token == "\\newline") {
                auto_ptr<Inset> inset(new InsetNewline);
                inset->read(buf, lex);
index 7b6a8f624ed4465e36177a3b889d204fa7eb86e3..0a0f92d6bd6cb0674dbf3b09991f753310b6810d 100644 (file)
@@ -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:
index 3be7346a8d066db530e1a7a5a234bee884641bed..bc5b76cb9d028b3afd7567437b9eced93e45f653 100644 (file)
@@ -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:
index 5a1af78d3e11d3082133a584ca9e5c805a5cdb1b..55214ac7765a72ba68b49cfaf71d1672ea1a76ed 100644 (file)
@@ -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);
 }
 
 
index a03da2d1970aa418f0532737ab675ba58d0e2dee..4e24da3e250c03989d9e2c97744b2a7ffe90d300 100644 (file)
@@ -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
 
index 16dbe1427ae190bd9b8ec14e5b486f337b0e9b08..b8a5847e8fc95412f773d06db068450c29a9aa27 100644 (file)
@@ -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()) {
index b6089f07571e6bee0a1a68d4db94b11ca71329ad..716d4c1b5ef44c2226e914dc9bbf6a0877051d75 100644 (file)
@@ -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
index eebcc990c7f1ad3e43baf8653f0eb0cbc5a414f0..f630fb2cff1026bcbffed564eeec148956857159 100644 (file)
@@ -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);
index 967843c48c8b07c75ab99f7eea277406c1bc360c..4df678a450c78bafe7246785d59ebb28edd42452 100644 (file)
@@ -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:
index f30c17ebd92dfe4162118123be3cffeccac9d23f..c6af71843360fbf572c080fecf545155e8c643be 100644 (file)
@@ -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 {}