It is attached.. I have simplified by removing \clearpage stuff, since
you have done it nicely. I hope I did not forget any files for the
patch, which is a possibility since my working version is a mess. :-)
\linebreak code is functional, but should be hidden in GUI. The reason
is I had no time to write a new draw() function for the \linebreak.
therefore I used the one written for \newline. Other than that, users
can use it from command-buffer with no problem. It would be better put
this patch now (If Jose approves), so there will be no file format
change for lyx-1.5 series.
Thanks a lot.
Ugras
On 11/27/06, Bo Peng <[EMAIL PROTECTED]> wrote:
> last and very IMPORTANT: I have sent a better patch in a separate mail
> including a new feature "\linebreak", which was also asked in the same
> mail that clearpage asked. I will be glad if you people review that
> patch, be volunteer to support this feature (so, Jose can put it for
> alpha), and commit, of course..
That patch seems to be lost in my mails. Could you please re-generate
one against the latest svn and sent it again?
Sorry for the inconvenience.
Bo
Index: src/insets/insetbase.C
===================================================================
--- src/insets/insetbase.C (revision 16071)
+++ src/insets/insetbase.C (working copy)
@@ -87,6 +87,7 @@
InsetName("environment", InsetBase::ENVIRONMENT_CODE),
InsetName("hfill", InsetBase::HFILL_CODE),
InsetName("newline", InsetBase::NEWLINE_CODE),
+ InsetName("linebreak", InsetBase::LINEBREAK_CODE),
InsetName("line", InsetBase::LINE_CODE),
InsetName("branch", InsetBase::BRANCH_CODE),
InsetName("box", InsetBase::BOX_CODE),
Index: src/insets/insetbase.h
===================================================================
--- src/insets/insetbase.h (revision 16071)
+++ src/insets/insetbase.h (working copy)
@@ -327,7 +327,9 @@
///
NOMENCL_CODE, // 45
///
- NOMENCL_PRINT_CODE
+ NOMENCL_PRINT_CODE,
+ ///
+ LINEBREAK_CODE
};
/** returns the Code corresponding to the \c name.
Index: src/insets/insetnewline.C
===================================================================
--- src/insets/insetnewline.C (revision 16071)
+++ src/insets/insetnewline.C (working copy)
@@ -122,6 +122,17 @@
{
return true;
}
+void InsetLineBreak::write(Buffer const &, ostream & os) const
+{
+ os << "\n\\linebreak\n";
+}
+int InsetLineBreak::latex(Buffer const &, odocstream & os,
+ OutputParams const &) const
+{
+ os << "\\linebreak{}";
+ return 0;
+}
+
} // namespace lyx
Index: src/insets/insetnewline.h
===================================================================
--- src/insets/insetnewline.h (revision 16071)
+++ src/insets/insetnewline.h (working copy)
@@ -54,6 +54,23 @@
};
+class InsetLineBreak : public InsetNewline {
+public:
+ InsetLineBreak() {}
+
+ InsetBase::Code lyxCode() const { return InsetBase::LINEBREAK_CODE; }
+
+ int latex(Buffer const &, odocstream &,
+ OutputParams const &) const;
+
+ void write(Buffer const & buf, std::ostream & os) const;
+private:
+ virtual std::auto_ptr<InsetBase> doClone() const
+ {
+ return std::auto_ptr<InsetBase>(new InsetLineBreak);
+ }
+};
+
} // namespace lyx
#endif // INSET_NEWLINE_H
Index: src/insets/insetert.C
===================================================================
--- src/insets/insetert.C (revision 16071)
+++ src/insets/insetert.C (working copy)
@@ -285,6 +285,7 @@
case LFUN_ACCENT_UNDERDOT:
case LFUN_APPENDIX:
case LFUN_BREAK_LINE:
+ case LFUN_BREAK_LINEBREAK:
case LFUN_CAPTION_INSERT:
case LFUN_DEPTH_DECREMENT:
case LFUN_DEPTH_INCREMENT:
Index: src/lfuns.h
===================================================================
--- src/lfuns.h (revision 16071)
+++ src/lfuns.h (working copy)
@@ -380,6 +380,7 @@
LFUN_CLEARPAGE_INSERT, // Ugras 20061125
//290
LFUN_CLEARDOUBLEPAGE_INSERT, // ugras 20061125
+ LFUN_BREAK_LINEBREAK,
LFUN_LASTACTION // end of the table
};
Index: src/LyXAction.C
===================================================================
--- src/LyXAction.C (revision 16071)
+++ src/LyXAction.C (working copy)
@@ -369,6 +369,7 @@
{ LFUN_TOOLBAR_TOGGLE_STATE, "", NoBuffer },
{ LFUN_NOMENCL_INSERT, "nomencl-insert", Noop },
{ LFUN_NOMENCL_PRINT, "nomencl-print", Noop },
+ { LFUN_BREAK_LINEBREAK, "linebreak-insert", Noop },
{ LFUN_CLEARPAGE_INSERT, "clearpage-insert", Noop },
{ LFUN_CLEARDOUBLEPAGE_INSERT, "cleardoublepage-insert", Noop },
Index: src/text3.C
===================================================================
--- src/text3.C (revision 16071)
+++ src/text3.C (working copy)
@@ -561,6 +561,17 @@
break;
}
+ case LFUN_BREAK_LINEBREAK: {
+ // Not allowed by LaTeX (labels or empty par)
+ if (cur.pos() > cur.paragraph().beginOfBody()) {
+ cap::replaceSelection(cur);
+ cur.insert(new InsetLineBreak);
+ cur.posRight();
+ moveCursor(cur, false);
+ }
+ break;
+ }
+
case LFUN_CHAR_DELETE_FORWARD:
if (!cur.selection()) {
if (cur.pos() == cur.paragraph().size())
@@ -1850,6 +1861,7 @@
case LFUN_BUFFER_BEGIN_SELECT:
case LFUN_BUFFER_END_SELECT:
case LFUN_UNICODE_INSERT:
+ case LFUN_BREAK_LINEBREAK:
// these are handled in our dispatch()
enable = true;
break;
Index: src/text.C
===================================================================
--- src/text.C (revision 16071)
+++ src/text.C (working copy)
@@ -306,6 +306,10 @@
auto_ptr<InsetBase> inset(new InsetNewline);
inset->read(buf, lex);
par.insertInset(par.size(), inset.release(), font, change);
+ } else if (token == "\\linebreak") {
+ auto_ptr<InsetBase> inset(new InsetLineBreak);
+ inset->read(buf, lex);
+ par.insertInset(par.size(), inset.release(), font, change);
} else if (token == "\\LyXTable") {
auto_ptr<InsetBase> inset(new InsetTabular(buf));
inset->read(buf, lex);
Index: src/paragraph.C
===================================================================
--- src/paragraph.C (revision 16071)
+++ src/paragraph.C (working copy)
@@ -1259,7 +1259,8 @@
bool Paragraph::isNewline(pos_type pos) const
{
return isInset(pos)
- && getInset(pos)->lyxCode() == InsetBase::NEWLINE_CODE;
+ && (getInset(pos)->lyxCode() == InsetBase::NEWLINE_CODE ||
+ getInset(pos)->lyxCode() == InsetBase::LINEBREAK_CODE);
}
Index: lib/lyx2lyx/lyx_1_5.py
===================================================================
--- lib/lyx2lyx/lyx_1_5.py (revision 16071)
+++ lib/lyx2lyx/lyx_1_5.py (working copy)
@@ -603,6 +603,25 @@
if (use_esint == 2):
document.preamble.append('\\usepackage{esint}')
+def revert_linebreak(document):
+ " linebreak -> ERT"
+ i = 0
+ while 1:
+ i = find_token(document.body, "\\linebreak", i)
+ if i == -1:
+ break
+ document.body[i:i+1] = ['\\begin_inset ERT',
+ 'status collapsed',
+ '',
+ '\\begin_layout %s' % document.default_layout,
+ '',
+ '',
+ '\\backslash',
+ 'linebreak',
+ '\\end_layout',
+ '',
+ '\\end_inset']
+ i = i + 1
def revert_clearpage(document):
" clearpage -> ERT"
@@ -662,7 +681,7 @@
[254, [convert_esint]],
[255, []]]
-revert = [[254, [revert_clearpage, revert_cleardoublepage]],
+revert = [[254, [revert_clearpage, revert_cleardoublepage, revert_linebreak]],
[253, [revert_esint]],
[252, [revert_nomenclature, revert_printnomenclature]],
[251, [revert_commandparams]],