support for \linebreak:

- 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
This commit is contained in:
Uwe Stöhr 2007-11-25 18:34:37 +00:00
parent 88bd7779d8
commit 12f7869ac0
22 changed files with 122 additions and 33 deletions

View 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

View 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 \""

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View 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():

View 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]],

View 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"

View 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

View 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_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 },

View 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);

View 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);

View 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
@ -685,6 +685,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()) {
if (cur.pos() == cur.paragraph().size())
@ -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:

View 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:

View 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);
}

View 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

View 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()) {

View 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

View 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);

View 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:

View 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 {}