Add inset clearpage and cleardoublepage, from Urgas

* src/insets/insetert.C
	* src/text3.C
	* src/lfuns.h
	* src/factory.C
	* src/tex2lyx/text.C
	* src/text.C
	* src/LyXAction.C: add and handle LFUN_CLEARPAGE_INSET and LFUN_CLEARDOUBLEPAGE_INSET
	* src/insets/insetpagebreak.h/C: extend InsetPageBreak
	* lib/lyx2lyx/lyx_1_5.py: file format change
	* lib/ui/stdmenus.ui: add menu items


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16037 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2006-11-25 15:09:01 +00:00
parent 70e134e536
commit 7b031e5d86
11 changed files with 112 additions and 12 deletions

View File

@ -603,6 +603,45 @@ def revert_esint(document):
if (use_esint == 2):
document.preamble.append('\\usepackage{esint}')
def revert_clearpage(document):
" clearpage -> ERT"
i = 0
while 1:
i = find_token(document.body, "\\clearpage", i)
if i == -1:
break
document.body[i:i+1] = ['\\begin_inset ERT',
'status collapsed',
'',
'\\begin_layout %s' % document.default_layout,
'',
'',
'\\backslash',
'clearpage',
'\\end_layout',
'',
'\\end_inset']
i = i + 1
def revert_cleardoublepage(document):
" cleardoublepage -> ERT"
i = 0
while 1:
i = find_token(document.body, "\\cleardoublepage", i)
if i == -1:
break
document.body[i:i+1] = ['\\begin_inset ERT',
'status collapsed',
'',
'\\begin_layout %s' % document.default_layout,
'',
'',
'\\backslash',
'cleardoublepage',
'\\end_layout',
'',
'\\end_inset']
i = i + 1
##
# Conversion hub
@ -619,7 +658,8 @@ convert = [[246, []],
[253, []],
[254, [convert_esint]]]
revert = [[253, [revert_esint]],
revert = [[254, [revert_clearpage, revert_cleardoublepage]],
[253, [revert_esint]],
[252, [revert_nomenclature, revert_printnomenclature]],
[251, [revert_commandparams]],
[250, [revert_cs_label]],

View File

@ -334,6 +334,8 @@ Menuset
Item "Ligature Break|k" "ligature-break-insert"
Item "Line Break|B" "break-line"
Item "Page Break|a" "pagebreak-insert"
Item "Clear Page" "clearpage-insert"
Item "Clear Double Page" "cleardoublepage-insert"
End
Menu "insert_math"

View File

@ -369,6 +369,8 @@ void LyXAction::init()
{ LFUN_TOOLBAR_TOGGLE_STATE, "", NoBuffer },
{ LFUN_NOMENCL_INSERT, "nomencl-insert", Noop },
{ LFUN_NOMENCL_PRINT, "nomencl-print", Noop },
{ LFUN_CLEARPAGE_INSERT, "clearpage-insert", Noop },
{ LFUN_CLEARDOUBLEPAGE_INSERT, "cleardoublepage-insert", Noop },
{ LFUN_NOACTION, "", Noop }
};

View File

@ -88,6 +88,12 @@ InsetBase * createInset(BufferView * bv, FuncRequest const & cmd)
case LFUN_PAGEBREAK_INSERT:
return new InsetPagebreak;
case LFUN_CLEARPAGE_INSERT:
return new InsetClearPage;
case LFUN_CLEARDOUBLEPAGE_INSERT:
return new InsetClearDoublePage;
case LFUN_CHARSTYLE_INSERT: {
string s = cmd.getArg(0);
LyXTextClass tclass = params.getLyXTextClass();

View File

@ -322,6 +322,8 @@ bool InsetERT::getStatus(LCursor & cur, FuncRequest const & cmd,
case LFUN_BIBITEM_INSERT:
case LFUN_LINE_INSERT:
case LFUN_PAGEBREAK_INSERT:
case LFUN_CLEARPAGE_INSERT:
case LFUN_CLEARDOUBLEPAGE_INSERT:
case LFUN_LANGUAGE:
case LFUN_LAYOUT:
case LFUN_LAYOUT_PARAGRAPH:

View File

@ -38,7 +38,7 @@ void InsetPagebreak::read(Buffer const &, LyXLex &)
void InsetPagebreak::write(Buffer const &, ostream & os) const
{
os << "\n\\newpage\n";
os << "\n" << getCmdName() << '\n';
}
@ -53,7 +53,7 @@ void InsetPagebreak::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetPagebreak::draw(PainterInfo & pi, int x, int y) const
{
static docstring const label = _("Page Break");
docstring const label = _(insetLabel());
LyXFont font;
font.setColor(LColor::pagebreak);
@ -80,7 +80,7 @@ void InsetPagebreak::draw(PainterInfo & pi, int x, int y) const
int InsetPagebreak::latex(Buffer const &, odocstream & os,
OutputParams const &) const
{
os << "\\newpage{}";
os << from_ascii(getCmdName()) << "{}";
return 0;
}

View File

@ -20,7 +20,6 @@ namespace lyx {
class InsetPagebreak : public InsetOld {
public:
InsetPagebreak() {}
InsetBase::Code lyxCode() const { return InsetBase::LINE_CODE; }
@ -29,7 +28,7 @@ public:
void draw(PainterInfo & pi, int x, int y) const;
int latex(Buffer const &, odocstream &,
virtual int latex(Buffer const &, odocstream &,
OutputParams const &) const;
int plaintext(Buffer const &, odocstream &,
@ -40,11 +39,16 @@ public:
void read(Buffer const &, LyXLex & lex);
void write(Buffer const & buf, std::ostream & os) const;
virtual void write(Buffer const & buf, std::ostream & os) const;
/// We don't need \begin_inset and \end_inset
bool directWrite() const { return true; }
bool display() const { return true; }
virtual std::string insetLabel() const { return "Page Break"; }
virtual std::string getCmdName() const { return "\\newpage"; }
private:
virtual std::auto_ptr<InsetBase> doClone() const
{
@ -53,6 +57,37 @@ private:
};
class InsetClearPage : public InsetPagebreak {
public:
InsetClearPage() {}
std::string insetLabel() const { return "Clear Page"; }
std::string getCmdName() const { return "\\clearpage"; }
private:
virtual std::auto_ptr<InsetBase> doClone() const
{
return std::auto_ptr<InsetBase>(new InsetClearPage);
}
};
class InsetClearDoublePage : public InsetPagebreak {
public:
InsetClearDoublePage() {}
std::string insetLabel() const { return "Clear Double Page"; }
std::string getCmdName() const { return "\\cleardoublepage"; }
private:
virtual std::auto_ptr<InsetBase> doClone() const
{
return std::auto_ptr<InsetBase>(new InsetClearDoublePage);
}
};
} // namespace lyx
#endif // INSET_NEWLINE_H

View File

@ -377,6 +377,9 @@ enum kb_action {
LFUN_TOOLBAR_TOGGLE_STATE, // bpeng 20061101
LFUN_NOMENCL_INSERT, // Ugras
LFUN_NOMENCL_PRINT, // Ugras
LFUN_CLEARPAGE_INSERT, // Ugras 20061125
//290
LFUN_CLEARDOUBLEPAGE_INSERT, // ugras 20061125
LFUN_LASTACTION // end of the table
};

View File

@ -2216,10 +2216,12 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
skip_braces(p);
}
else if (t.cs() == "newpage") {
else if (t.cs() == "newpage" ||
t.cs() == "clearpage" ||
t.cs() == "cleardoublepage") {
context.check_layout(os);
// FIXME: what about \\clearpage and \\pagebreak?
os << "\n\\newpage\n";
// FIXME: what about \\pagebreak?
os << "\n\\" << t.cs() << "\n";
skip_braces(p); // eat {}
}

View File

@ -316,6 +316,10 @@ void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex,
par.insertInset(par.size(), new InsetLine, font, change);
} else if (token == "\\newpage") {
par.insertInset(par.size(), new InsetPagebreak, font, change);
} else if (token == "\\clearpage") {
par.insertInset(par.size(), new InsetClearPage, font, change);
} else if (token == "\\cleardoublepage") {
par.insertInset(par.size(), new InsetClearDoublePage, font, change);
} else if (token == "\\change_unchanged") {
change = Change(Change::UNCHANGED);
} else if (token == "\\change_inserted") {

View File

@ -1187,6 +1187,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
case LFUN_HFILL_INSERT:
case LFUN_LINE_INSERT:
case LFUN_PAGEBREAK_INSERT:
case LFUN_CLEARPAGE_INSERT:
case LFUN_CLEARDOUBLEPAGE_INSERT:
// do nothing fancy
doInsertInset(cur, this, cmd, false, false);
cur.posRight();
@ -1804,6 +1806,8 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
case LFUN_SELF_INSERT:
case LFUN_LINE_INSERT:
case LFUN_PAGEBREAK_INSERT:
case LFUN_CLEARPAGE_INSERT:
case LFUN_CLEARDOUBLEPAGE_INSERT:
case LFUN_MATH_DISPLAY:
case LFUN_MATH_IMPORT_SELECTION:
case LFUN_MATH_MODE: