From 97aa558caca65a79a6fd57504564b51819f8cd79 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Uwe=20St=C3=B6hr?= Date: Fri, 23 Nov 2007 02:10:00 +0000 Subject: [PATCH] support for \pagebreak: - rename former "pagebreak" to "newpage" since it produces a \newpage - new LFUN - menu entry - tex2lyx support - fileformat change git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21732 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/FORMAT | 3 ++ development/scons/scons_manifest.py | 4 +-- lib/configure.py | 18 ++++------ lib/lyx2lyx/LyX.py | 2 +- lib/lyx2lyx/lyx_1_6.py | 17 +++++++-- lib/ui/stdmenus.inc | 1 + src/Buffer.cpp | 2 +- src/LyXAction.cpp | 1 + src/Makefile.am | 4 +-- src/Text.cpp | 4 ++- src/Text3.cpp | 2 ++ src/factory.cpp | 5 ++- src/insets/Inset.cpp | 2 +- src/insets/InsetCaption.cpp | 2 +- src/insets/InsetCode.h | 2 +- src/insets/InsetCollapsable.cpp | 1 + .../{InsetPagebreak.cpp => InsetNewpage.cpp} | 18 +++++----- .../{InsetPagebreak.h => InsetNewpage.h} | 36 +++++++++++++------ src/insets/InsetTabular.h | 2 +- src/lfuns.h | 1 + src/mathed/InsetMathGrid.cpp | 4 +-- src/mathed/InsetMathGrid.h | 2 +- src/mathed/MathParser.cpp | 6 ++-- src/tex2lyx/table.cpp | 2 +- src/tex2lyx/text.cpp | 6 ++-- 25 files changed, 92 insertions(+), 55 deletions(-) rename src/insets/{InsetPagebreak.cpp => InsetNewpage.cpp} (76%) rename src/insets/{InsetPagebreak.h => InsetNewpage.h} (71%) diff --git a/development/FORMAT b/development/FORMAT index 373616ef21..df52bc23be 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,6 +1,9 @@ LyX file-format changes ----------------------- +2007-11-23 Uwe Stöhr + * Format incremented to 300: support for \pagebreak + 2007-11-01 Uwe Stöhr * Format incremented to 299: support for hyperlink types diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index aa29f08150..88bc63ace1 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -1012,10 +1012,10 @@ src_insets_header_files = Split(''' InsetListingsParams.h InsetMarginal.h InsetNewline.h + InsetNewpage.h InsetNomencl.h InsetNote.h InsetOptArg.h - InsetPagebreak.h InsetQuotes.h InsetRef.h InsetSpace.h @@ -1068,10 +1068,10 @@ src_insets_files = Split(''' InsetListingsParams.cpp InsetMarginal.cpp InsetNewline.cpp + InsetNewpage.cpp InsetNomencl.cpp InsetNote.cpp InsetOptArg.cpp - InsetPagebreak.cpp InsetQuotes.cpp InsetRef.cpp InsetSpace.cpp diff --git a/lib/configure.py b/lib/configure.py index 4ab4fa837b..210aad99b7 100644 --- a/lib/configure.py +++ b/lib/configure.py @@ -198,17 +198,14 @@ def checkDTLtools(): def checkLatex(dtl_tools): ''' Check latex, return lyx_check_config ''' - path, LATEX = checkProg('a Latex2e program', ['platex $$i', 'latex $$i', 'latex2e $$i']) - path, PPLATEX = checkProg('a DVI postprocessing program', ['pplatex $$i']) - # use LATEX to convert from latex to dvi if PPLATEX is not available - if PPLATEX == '': - PPLATEX = LATEX if dtl_tools: # Windows only: DraftDVI - addToRC(r'''\converter latex dvi2 "%s" "latex" -\converter dvi2 dvi "python -tt $$s/scripts/clean_dvi.py $$i $$o" ""''' % PPLATEX) + converter_entry = r'''\converter latex dvi2 "%%" "latex" +\converter dvi2 dvi "python -tt $$s/scripts/clean_dvi.py $$i $$o" ""''' else: - addToRC(r'\converter latex dvi "%s" "latex"' % PPLATEX) + converter_entry = r'\converter latex dvi "%%" "latex"' + path, LATEX = checkProg('a Latex2e program', ['pplatex $$i', 'platex $$i', 'latex $$i', 'latex2e $$i'], + rc_entry = [converter_entry]) # no latex if LATEX != '': # Check if latex is usable @@ -854,7 +851,4 @@ Options: bool_docbook, bool_linuxdoc) checkModulesConfig() #lyx_check_config and LATEX != '') removeTempFiles() - # The return error code can be 256. Because most systems expect an error code - # in the range 0-127, 256 can be interpretted as 'success'. Because we expect - # a None for success, 'ret is not None' is used to exit. - sys.exit(ret is not None) + sys.exit(ret) diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index 377397f6b4..e11be98bb5 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,300), minor_versions("1.6" , 0))] # Uwe: Hyperlink types + ("1_6", range(277,301), minor_versions("1.6" , 0))] # Uwe: \pagebreak def formats_list(): diff --git a/lib/lyx2lyx/lyx_1_6.py b/lib/lyx2lyx/lyx_1_6.py index b9291d0ea6..58f41486e1 100644 --- a/lib/lyx2lyx/lyx_1_6.py +++ b/lib/lyx2lyx/lyx_1_6.py @@ -788,6 +788,17 @@ def revert_hyperlinktype(document): i = i + 1 +def revert_pagebreak(document): + 'Reverts pagebreak to newpage' + i = 0 + while True: + i = find_token(document.body, "\\pagebreak", i) + if i == -1: + return + document.body[i] = document.body[i].replace("\\pagebreak", "\\newpage") + i = i + 1 + + ## # Conversion hub # @@ -815,10 +826,12 @@ convert = [[277, [fix_wrong_tables]], [296, [convert_include]], [297, [convert_usorbian]], [298, []], - [299, []] + [299, []], + [300, []] ] -revert = [[298, [revert_hyperlinktype]], +revert = [[299, [revert_pagebreak]], + [298, [revert_hyperlinktype]], [297, [revert_macro_optional_params]], [296, [revert_albanian, revert_lowersorbian, revert_uppersorbian]], [295, [revert_include]], diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc index 309b3da976..72dbd6e1c9 100644 --- a/lib/ui/stdmenus.inc +++ b/lib/ui/stdmenus.inc @@ -362,6 +362,7 @@ Menuset Item "Ligature Break|k" "ligature-break-insert" Item "Line Break|B" "break-line" Separator + Item "New Page|N" "newpage-insert" Item "Page Break|a" "pagebreak-insert" Item "Clear Page|C" "clearpage-insert" Item "Clear Double Page|D" "cleardoublepage-insert" diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 95920be888..4b64d52b2a 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -153,7 +153,7 @@ namespace os = support::os; namespace { -int const LYX_FORMAT = 299; // Uwe: Hyperlink types +int const LYX_FORMAT = 300; // Uwe: \pagebreak } // namespace anon diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 9551e8abe1..e159f91b3f 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -206,6 +206,7 @@ void LyXAction::init() { LFUN_BIBTEX_DATABASE_ADD, "bibtex-database-add", Noop, Edit }, { LFUN_BIBTEX_DATABASE_DEL, "bibtex-database-del", Noop, Edit }, { LFUN_LINE_INSERT, "line-insert", Noop, Edit }, + { LFUN_NEWPAGE_INSERT, "newpage-insert", Noop, Edit }, { LFUN_PAGEBREAK_INSERT, "pagebreak-insert", Noop, Edit }, { LFUN_LANGUAGE, "language", Noop, Edit }, { LFUN_LAYOUT, "layout", Noop, Layout }, diff --git a/src/Makefile.am b/src/Makefile.am index ef28719ca8..278a4b5af7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -525,10 +525,10 @@ SOURCEFILESINSETS = \ insets/InsetListingsParams.cpp \ insets/InsetMarginal.cpp \ insets/InsetNewline.cpp \ + insets/InsetNewpage.cpp \ insets/InsetNomencl.cpp \ insets/InsetNote.cpp \ insets/InsetOptArg.cpp \ - insets/InsetPagebreak.cpp \ insets/InsetQuotes.cpp \ insets/InsetRef.cpp \ insets/InsetSpace.cpp \ @@ -581,10 +581,10 @@ HEADERFILESINSETS = \ insets/InsetListingsParams.h \ insets/InsetMarginal.h \ insets/InsetNewline.h \ + insets/InsetNewpage.h \ insets/InsetNomencl.h \ insets/InsetNote.h \ insets/InsetOptArg.h \ - insets/InsetPagebreak.h \ insets/InsetQuotes.h \ insets/InsetRef.h \ insets/InsetSpace.h \ diff --git a/src/Text.cpp b/src/Text.cpp index 0af0731f89..02224a6ddc 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -58,7 +58,7 @@ #include "insets/InsetHFill.h" #include "insets/InsetLine.h" #include "insets/InsetNewline.h" -#include "insets/InsetPagebreak.h" +#include "insets/InsetNewpage.h" #include "insets/InsetOptArg.h" #include "insets/InsetSpace.h" #include "insets/InsetSpecialChar.h" @@ -245,6 +245,8 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex, } else if (token == "\\lyxline") { par.insertInset(par.size(), new InsetLine, font, change); } else if (token == "\\newpage") { + par.insertInset(par.size(), new InsetNewpage, font, change); + } else if (token == "\\pagebreak") { par.insertInset(par.size(), new InsetPagebreak, font, change); } else if (token == "\\clearpage") { par.insertInset(par.size(), new InsetClearPage, font, change); diff --git a/src/Text3.cpp b/src/Text3.cpp index f400794e98..7b6a8f624e 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -1384,6 +1384,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) case LFUN_TOC_INSERT: case LFUN_HFILL_INSERT: case LFUN_LINE_INSERT: + case LFUN_NEWPAGE_INSERT: case LFUN_PAGEBREAK_INSERT: case LFUN_CLEARPAGE_INSERT: case LFUN_CLEARDOUBLEPAGE_INSERT: @@ -2110,6 +2111,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_DATE_INSERT: case LFUN_SELF_INSERT: case LFUN_LINE_INSERT: + case LFUN_NEWPAGE_INSERT: case LFUN_PAGEBREAK_INSERT: case LFUN_CLEARPAGE_INSERT: case LFUN_CLEARDOUBLEPAGE_INSERT: diff --git a/src/factory.cpp b/src/factory.cpp index b8d79a5537..4649f15180 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -46,7 +46,7 @@ #include "insets/InsetBox.h" #include "insets/InsetBranch.h" #include "insets/InsetOptArg.h" -#include "insets/InsetPagebreak.h" +#include "insets/InsetNewpage.h" #include "insets/InsetRef.h" #include "insets/InsetSpace.h" #include "insets/InsetTabular.h" @@ -93,6 +93,9 @@ Inset * createInset(Buffer & buf, FuncRequest const & cmd) case LFUN_LINE_INSERT: return new InsetLine; + case LFUN_NEWPAGE_INSERT: + return new InsetNewpage; + case LFUN_PAGEBREAK_INSERT: return new InsetPagebreak; diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index e2213ef51d..952aa0a2a2 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -105,7 +105,7 @@ static TranslatorMap const build_translator() InsetName("listings", LISTINGS_CODE), InsetName("info", INFO_CODE), InsetName("collapsable", COLLAPSABLE_CODE), - InsetName("pagebreak", PAGEBREAK_CODE), + InsetName("newpage", NEWPAGE_CODE), }; std::size_t const insetnames_size = diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp index e343baa01b..37a7051c40 100644 --- a/src/insets/InsetCaption.cpp +++ b/src/insets/InsetCaption.cpp @@ -186,7 +186,7 @@ bool InsetCaption::insetAllowed(InsetCode code) const case TABULAR_CODE: case WRAP_CODE: case CAPTION_CODE: - case PAGEBREAK_CODE: + case NEWPAGE_CODE: return false; default: return InsetText::insetAllowed(code); diff --git a/src/insets/InsetCode.h b/src/insets/InsetCode.h index cd6e9e6b4a..6a3f1bc15f 100644 --- a/src/insets/InsetCode.h +++ b/src/insets/InsetCode.h @@ -118,7 +118,7 @@ enum InsetCode { /// NOMENCL_PRINT_CODE, /// - PAGEBREAK_CODE, + NEWPAGE_CODE, /// LISTINGS_CODE, /// diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index 35e0736e09..3be7346a8d 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -691,6 +691,7 @@ bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_LABEL_INSERT: case LFUN_LIGATURE_BREAK_INSERT: case LFUN_LINE_INSERT: + case LFUN_NEWPAGE_INSERT: case LFUN_PAGEBREAK_INSERT: case LFUN_LAYOUT: case LFUN_LAYOUT_PARAGRAPH: diff --git a/src/insets/InsetPagebreak.cpp b/src/insets/InsetNewpage.cpp similarity index 76% rename from src/insets/InsetPagebreak.cpp rename to src/insets/InsetNewpage.cpp index 5e2f9d7b70..a804d01866 100644 --- a/src/insets/InsetPagebreak.cpp +++ b/src/insets/InsetNewpage.cpp @@ -1,5 +1,5 @@ /** - * \file InsetPagebreak.cpp + * \file InsetNewpage.cpp * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -10,7 +10,7 @@ #include -#include "InsetPagebreak.h" +#include "InsetNewpage.h" #include "debug.h" #include "gettext.h" @@ -30,19 +30,19 @@ namespace lyx { using frontend::Painter; -void InsetPagebreak::read(Buffer const &, Lexer &) +void InsetNewpage::read(Buffer const &, Lexer &) { /* Nothing to read */ } -void InsetPagebreak::write(Buffer const &, std::ostream & os) const +void InsetNewpage::write(Buffer const &, std::ostream & os) const { os << "\n" << getCmdName() << '\n'; } -void InsetPagebreak::metrics(MetricsInfo & mi, Dimension & dim) const +void InsetNewpage::metrics(MetricsInfo & mi, Dimension & dim) const { dim.asc = defaultRowHeight(); dim.des = defaultRowHeight(); @@ -52,7 +52,7 @@ void InsetPagebreak::metrics(MetricsInfo & mi, Dimension & dim) const } -void InsetPagebreak::draw(PainterInfo & pi, int x, int y) const +void InsetNewpage::draw(PainterInfo & pi, int x, int y) const { FontInfo font; font.setColor(Color_pagebreak); @@ -78,7 +78,7 @@ void InsetPagebreak::draw(PainterInfo & pi, int x, int y) const } -int InsetPagebreak::latex(Buffer const &, odocstream & os, +int InsetNewpage::latex(Buffer const &, odocstream & os, OutputParams const &) const { os << from_ascii(getCmdName()) << "{}"; @@ -86,7 +86,7 @@ int InsetPagebreak::latex(Buffer const &, odocstream & os, } -int InsetPagebreak::plaintext(Buffer const &, odocstream & os, +int InsetNewpage::plaintext(Buffer const &, odocstream & os, OutputParams const &) const { os << '\n'; @@ -94,7 +94,7 @@ int InsetPagebreak::plaintext(Buffer const &, odocstream & os, } -int InsetPagebreak::docbook(Buffer const &, odocstream & os, +int InsetNewpage::docbook(Buffer const &, odocstream & os, OutputParams const &) const { os << '\n'; diff --git a/src/insets/InsetPagebreak.h b/src/insets/InsetNewpage.h similarity index 71% rename from src/insets/InsetPagebreak.h rename to src/insets/InsetNewpage.h index 0d793fc5aa..6473149a13 100644 --- a/src/insets/InsetPagebreak.h +++ b/src/insets/InsetNewpage.h @@ -1,6 +1,6 @@ // -*- C++ -*- /** - * \file InsetPagebreak.h + * \file InsetNewpage.h * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -9,8 +9,8 @@ * Full author contact details are available in file CREDITS. */ -#ifndef INSET_PAGEBREAK_H -#define INSET_PAGEBREAK_H +#ifndef INSET_NEWPAGE_H +#define INSET_NEWPAGE_H #include "Inset.h" @@ -19,11 +19,11 @@ namespace lyx { -class InsetPagebreak : public Inset { +class InsetNewpage : public Inset { public: - InsetPagebreak() {} + InsetNewpage() {} - InsetCode lyxCode() const { return PAGEBREAK_CODE; } + InsetCode lyxCode() const { return NEWPAGE_CODE; } void metrics(MetricsInfo &, Dimension &) const; @@ -46,10 +46,26 @@ public: DisplayType display() const { return AlignCenter; } - virtual docstring insetLabel() const { return _("Page Break"); } + virtual docstring insetLabel() const { return _("New Page"); } virtual std::string getCmdName() const { return "\\newpage"; } +private: + virtual Inset * clone() const + { + return new InsetNewpage; + } +}; + + +class InsetPagebreak : public InsetNewpage { +public: + InsetPagebreak() {} + + docstring insetLabel() const { return _("Page Break"); } + + std::string getCmdName() const { return "\\pagebreak"; } + private: virtual Inset * clone() const { @@ -58,7 +74,7 @@ private: }; -class InsetClearPage : public InsetPagebreak { +class InsetClearPage : public InsetNewpage { public: InsetClearPage() {} @@ -74,7 +90,7 @@ private: }; -class InsetClearDoublePage : public InsetPagebreak { +class InsetClearDoublePage : public InsetNewpage { public: InsetClearDoublePage() {} @@ -91,4 +107,4 @@ private: } // namespace lyx -#endif // INSET_PAGEBREAK_H +#endif // INSET_NEWPAGE_H diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h index 3020aede59..8950077de2 100644 --- a/src/insets/InsetTabular.h +++ b/src/insets/InsetTabular.h @@ -539,7 +539,7 @@ public: bool endfoot; /// row of endlastfoot bool endlastfoot; - /// row for a pagebreak + /// row for a newpage bool newpage; }; /// diff --git a/src/lfuns.h b/src/lfuns.h index 7d4563d3e4..b6089f0757 100644 --- a/src/lfuns.h +++ b/src/lfuns.h @@ -339,6 +339,7 @@ enum kb_action { LFUN_BOX_INSERT, LFUN_LINE_INSERT, // 240 + LFUN_NEWPAGE_INSERT, // uwestoehr 20071124 LFUN_PAGEBREAK_INSERT, LFUN_REPEAT, LFUN_FINISHED_LEFT, diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index f357c2e43c..eebcc990c7 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -86,7 +86,7 @@ InsetMathGrid::CellInfo::CellInfo() InsetMathGrid::RowInfo::RowInfo() - : lines_(0), skip_(0), allow_pagebreak_(true) + : lines_(0), skip_(0), allow_newpage_(true) {} @@ -649,7 +649,7 @@ docstring InsetMathGrid::eolString(row_type row, bool emptyline, bool fragile) c if (!rowinfo_[row].crskip_.zero()) eol += '[' + from_utf8(rowinfo_[row].crskip_.asLatexString()) + ']'; - else if(!rowinfo_[row].allow_pagebreak_) + else if(!rowinfo_[row].allow_newpage_) eol += '*'; // make sure an upcoming '[' does not break anything diff --git a/src/mathed/InsetMathGrid.h b/src/mathed/InsetMathGrid.h index 7663d3ec2c..da309998d1 100644 --- a/src/mathed/InsetMathGrid.h +++ b/src/mathed/InsetMathGrid.h @@ -63,7 +63,7 @@ public: /// extra distance between lines int skip_; /// Is a page break allowed after this row? - bool allow_pagebreak_; + bool allow_newpage_; }; // additional per-row information diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp index 1d27f65f3e..9193e666a7 100644 --- a/src/mathed/MathParser.cpp +++ b/src/mathed/MathParser.cpp @@ -112,7 +112,7 @@ bool stared(docstring const & s) * environments like "equation" that have a fixed number of rows. */ bool addRow(InsetMathGrid & grid, InsetMathGrid::row_type & cellrow, - docstring const & vskip, bool allow_pagebreak = true) + docstring const & vskip, bool allow_newpage_ = true) { ++cellrow; if (cellrow == grid.nrows()) { @@ -129,14 +129,14 @@ bool addRow(InsetMathGrid & grid, InsetMathGrid::row_type & cellrow, lyxerr << "ignoring extra row"; if (!vskip.empty()) lyxerr << " with extra space " << to_utf8(vskip); - if (!allow_pagebreak) + if (!allow_newpage_) lyxerr << " with no page break allowed"; lyxerr << '.' << endl; return false; } } grid.vcrskip(Length(to_utf8(vskip)), cellrow - 1); - grid.rowinfo(cellrow - 1).allow_pagebreak_ = allow_pagebreak; + grid.rowinfo(cellrow - 1).allow_newpage_ = allow_newpage_; return true; } diff --git a/src/tex2lyx/table.cpp b/src/tex2lyx/table.cpp index 35de97af6a..2fa33955e7 100644 --- a/src/tex2lyx/table.cpp +++ b/src/tex2lyx/table.cpp @@ -87,7 +87,7 @@ public: /// These are for longtabulars only /// row type (head, foot, firsthead etc.) LTRowType type; - /// row for a pagebreak + /// row for a newpage bool newpage; }; diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index f49012a559..2385831302 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -2290,10 +2290,10 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, } else if (t.cs() == "newpage" || - t.cs() == "clearpage" || - t.cs() == "cleardoublepage") { + t.cs() == "pagebreak" || + t.cs() == "clearpage" || + t.cs() == "cleardoublepage") { context.check_layout(os); - // FIXME: what about \\pagebreak? os << "\n\\" << t.cs() << "\n"; skip_braces(p); // eat {} } -- 2.39.5