mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Merge the diverse newpage insets into one.
* src/Buffer.cpp: - file format change to 323 * development/FORMAT: - document file format change * src/insets/InsetNewpage.cpp: - the former four separate derivates are now merged into one inset with proper Params and Mailer. This simplifies the structure and allows for switching between the various kinds. * factory.cpp: - The newpage insets are now being generated with newpage-insert [newpage|pagebreak|clearpage|cleardoublepage] * src/Text.cpp: - Newpage inset is now a proper inset with opening and closing tag. * src/FuncCode.h: * src/LyXAction.cpp: * src/Text3.cpp: * src/insets/InsetCollapsable.cpp: - remove LFUN_PAGEBREAK_INSERT, LFUN_CLEARPAGE_INSERT and LFUN_CLEARDOUBLEPAGE_INSERT * lib/lyx2lyx/LyX.py: * lib/lyx2lyx/lyx_1_6.py: - conversion and reversion routines for newpage insets. * lib/ui/stdmenus.inc: - adapt menu and add context menu to switch between newpage variants. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23942 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
c2ac470567
commit
d2a4c97ab8
@ -1,6 +1,9 @@
|
||||
LyX file-format changes
|
||||
-----------------------
|
||||
|
||||
2008-03-25 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
|
||||
* Format incremented to 323: merge the diverse newpage insets.
|
||||
|
||||
2008-03-24 Richard Heck <rgheck@comcast.net>
|
||||
* Format incremented to 322: local layout
|
||||
|
||||
|
@ -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,323), minor_versions("1.6" , 0))] # rgh: local layout
|
||||
("1_6", range(277,324), minor_versions("1.6" , 0))]
|
||||
|
||||
|
||||
def formats_list():
|
||||
|
@ -1645,6 +1645,32 @@ def revert_local_layout(document):
|
||||
document.header[i : j + 1] = []
|
||||
|
||||
|
||||
def convert_pagebreaks(document):
|
||||
' Convert inline Newpage insets to new format '
|
||||
for i in range(len(document.body)):
|
||||
document.body[i] = document.body[i].replace('\\newpage', '\\begin_inset Newpage newpage\n\\end_inset')
|
||||
document.body[i] = document.body[i].replace('\\pagebreak', '\\begin_inset Newpage pagebreak\n\\end_inset')
|
||||
document.body[i] = document.body[i].replace('\\clearpage', '\\begin_inset Newpage clearpage\n\\end_inset')
|
||||
document.body[i] = document.body[i].replace('\\cleardoublepage', '\\begin_inset Newpage cleardoublepage\n\\end_inset')
|
||||
|
||||
|
||||
def revert_pagebreaks(document):
|
||||
' Revert \\begin_inset Newpage to previous inline format '
|
||||
i = 0
|
||||
while True:
|
||||
i = find_token(document.body, '\\begin_inset Newpage', i)
|
||||
if i == -1:
|
||||
return
|
||||
j = find_end_of_inset(document.body, i)
|
||||
if j == -1:
|
||||
document.warning("Malformed LyX document: Could not find end of Newpage inset.")
|
||||
continue
|
||||
del document.body[j]
|
||||
document.body[i] = document.body[i].replace('\\begin_inset Newpage newpage', '\\newpage')
|
||||
document.body[i] = document.body[i].replace('\\begin_inset Newpage pagebreak', '\\pagebreak')
|
||||
document.body[i] = document.body[i].replace('\\begin_inset Newpage clearpage', '\\clearpage')
|
||||
document.body[i] = document.body[i].replace('\\begin_inset Newpage cleardoublepage', '\\cleardoublepage')
|
||||
|
||||
|
||||
##
|
||||
# Conversion hub
|
||||
@ -1696,10 +1722,12 @@ convert = [[277, [fix_wrong_tables]],
|
||||
[319, [convert_spaceinset, convert_hfill]],
|
||||
[320, []],
|
||||
[321, [convert_tablines]],
|
||||
[322, []]
|
||||
[322, []],
|
||||
[323, [convert_pagebreaks]]
|
||||
]
|
||||
|
||||
revert = [[321, [revert_local_layout]],
|
||||
revert = [[322, [revert_pagebreaks]],
|
||||
[321, [revert_local_layout]],
|
||||
[320, [revert_tablines]],
|
||||
[319, [revert_protected_hfill]],
|
||||
[318, [revert_spaceinset, revert_hfills, revert_hspace]],
|
||||
|
@ -375,10 +375,10 @@ Menuset
|
||||
Item "New Line|e" "new-line"
|
||||
Item "Line Break|B" "line-break"
|
||||
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"
|
||||
Item "New Page|N" "newpage-insert newpage"
|
||||
Item "Page Break|a" "newpage-insert pagebreak"
|
||||
Item "Clear Page|C" "newpage-insert clearpage"
|
||||
Item "Clear Double Page|D" "newpage-insert cleardoublepage"
|
||||
End
|
||||
|
||||
Menu "insert_math"
|
||||
@ -658,6 +658,16 @@ Menuset
|
||||
Item "Custom|C" "command-sequence next-inset-modify vspace 1in; next-inset-toggle"
|
||||
End
|
||||
|
||||
#
|
||||
# InsetNewpage context menu
|
||||
#
|
||||
Menu "context-newpage"
|
||||
Item "New Page|N" "next-inset-modify newpage newpage"
|
||||
Item "Page Break|a" "next-inset-modify newpage pagebreak"
|
||||
Item "Clear Page|C" "next-inset-modify newpage clearpage"
|
||||
Item "Clear Double Page|D" "next-inset-modify newpage cleardoublepage"
|
||||
End
|
||||
|
||||
#
|
||||
# Edit context menu
|
||||
#
|
||||
|
@ -116,7 +116,7 @@ namespace os = support::os;
|
||||
|
||||
namespace {
|
||||
|
||||
int const LYX_FORMAT = 322; // rgh: local layout
|
||||
int const LYX_FORMAT = 323;
|
||||
|
||||
typedef map<string, bool> DepClean;
|
||||
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
|
||||
|
@ -313,110 +313,107 @@ enum FuncCode
|
||||
LFUN_BOX_INSERT,
|
||||
// 235
|
||||
LFUN_LINE_INSERT,
|
||||
LFUN_NEWPAGE_INSERT, // uwestoehr 20071124
|
||||
LFUN_PAGEBREAK_INSERT,
|
||||
LFUN_NEWPAGE_INSERT, // uwestoehr, 20071124
|
||||
LFUN_REPEAT,
|
||||
LFUN_FINISHED_LEFT,
|
||||
// 240
|
||||
LFUN_FINISHED_RIGHT,
|
||||
// 240
|
||||
LFUN_FLEX_INSERT,
|
||||
LFUN_WORD_FIND,
|
||||
LFUN_WORD_REPLACE,
|
||||
LFUN_BUFFER_EXPORT_CUSTOM,
|
||||
// 245
|
||||
LFUN_BUFFER_PRINT,
|
||||
// 245
|
||||
LFUN_NEXT_INSET_TOGGLE,
|
||||
LFUN_ALL_INSETS_TOGGLE,
|
||||
LFUN_BUFFER_LANGUAGE,
|
||||
LFUN_TEXTCLASS_APPLY,
|
||||
// 250
|
||||
LFUN_TEXTCLASS_LOAD,
|
||||
// 250
|
||||
LFUN_BUFFER_SAVE_AS_DEFAULT,
|
||||
LFUN_BUFFER_PARAMS_APPLY,
|
||||
LFUN_LYXRC_APPLY,
|
||||
LFUN_GRAPHICS_EDIT,
|
||||
// 255
|
||||
LFUN_BUFFER_NEXT,
|
||||
// 255
|
||||
LFUN_BUFFER_PREVIOUS,
|
||||
LFUN_STATISTICS,
|
||||
LFUN_CHANGES_OUTPUT, // jspitzm 20050121
|
||||
LFUN_BIBTEX_DATABASE_ADD,
|
||||
// 260
|
||||
LFUN_BIBTEX_DATABASE_DEL,
|
||||
// 260
|
||||
LFUN_CITATION_INSERT,
|
||||
LFUN_OUTLINE_UP,
|
||||
LFUN_OUTLINE_DOWN,
|
||||
LFUN_OUTLINE_IN,
|
||||
// 265
|
||||
LFUN_OUTLINE_OUT,
|
||||
// 265
|
||||
LFUN_PARAGRAPH_MOVE_DOWN,
|
||||
LFUN_PARAGRAPH_MOVE_UP,
|
||||
LFUN_BUFFER_TOGGLE_COMPRESSION, // bpeng 20060427
|
||||
LFUN_MATH_BIGDELIM,
|
||||
// 270
|
||||
LFUN_CLIPBOARD_PASTE,
|
||||
// 270
|
||||
LFUN_INSET_DISSOLVE, // jspitzm 20060807
|
||||
LFUN_CHANGE_NEXT,
|
||||
LFUN_WINDOW_NEW, // Abdel 20061021
|
||||
LFUN_WINDOW_CLOSE, // Abdel 20061023
|
||||
// 275
|
||||
LFUN_UNICODE_INSERT, // Lgb 20061022
|
||||
// 275
|
||||
LFUN_BOOKMARK_CLEAR, // bpeng 20061031
|
||||
LFUN_NOMENCL_INSERT, // Ugras
|
||||
LFUN_NOMENCL_PRINT, // Ugras
|
||||
LFUN_CLEARPAGE_INSERT, // Ugras 20061125
|
||||
// 280
|
||||
LFUN_CLEARDOUBLEPAGE_INSERT, // Ugras 20061125
|
||||
LFUN_LISTING_INSERT, // Herbert 20011110, bpeng 20070502
|
||||
LFUN_TOOLBAR_TOGGLE, // Edwin 20070521
|
||||
// 280
|
||||
LFUN_BUFFER_WRITE_ALL, // rgh, gpothier 200707XX
|
||||
LFUN_PARAGRAPH_PARAMS,
|
||||
// 285
|
||||
LFUN_LAYOUT_MODULES_CLEAR,
|
||||
LFUN_LAYOUT_MODULE_ADD,
|
||||
LFUN_LAYOUT_RELOAD,
|
||||
// 285
|
||||
LFUN_MASTER_BUFFER_VIEW, // Tommaso, 20070920
|
||||
LFUN_MASTER_BUFFER_UPDATE, // Tommaso, 20070920
|
||||
// 290
|
||||
LFUN_INFO_INSERT, // bpeng, 20071007
|
||||
LFUN_CALL, // broider, 20071002
|
||||
LFUN_BUFFER_TOGGLE_EMBEDDING, // bpeng, 20071021
|
||||
// 290
|
||||
LFUN_CHAR_LEFT, // dov, 20071022
|
||||
LFUN_CHAR_LEFT_SELECT, // dov, 20071022
|
||||
// 295
|
||||
LFUN_CHAR_RIGHT, // dov, 20071022
|
||||
LFUN_CHAR_RIGHT_SELECT, // dov, 20071022
|
||||
LFUN_FINISHED_BACKWARD, // dov, 20071022
|
||||
// 295
|
||||
LFUN_FINISHED_FORWARD, // dov, 20071022
|
||||
LFUN_WORD_LEFT, // dov, 20071028
|
||||
// 300
|
||||
LFUN_WORD_LEFT_SELECT, // dov, 20071028
|
||||
LFUN_WORD_RIGHT, // dov, 20071028
|
||||
LFUN_WORD_RIGHT_SELECT, // dov, 20071028
|
||||
// 300
|
||||
LFUN_MATH_MACRO_FOLD,
|
||||
LFUN_MATH_MACRO_UNFOLD,
|
||||
// 305
|
||||
LFUN_MATH_MACRO_ADD_PARAM,
|
||||
LFUN_MATH_MACRO_REMOVE_PARAM,
|
||||
LFUN_MATH_MACRO_APPEND_GREEDY_PARAM,
|
||||
// 305
|
||||
LFUN_MATH_MACRO_REMOVE_GREEDY_PARAM,
|
||||
LFUN_MATH_MACRO_MAKE_OPTIONAL,
|
||||
// 310
|
||||
LFUN_MATH_MACRO_MAKE_NONOPTIONAL,
|
||||
LFUN_MATH_MACRO_ADD_OPTIONAL_PARAM,
|
||||
LFUN_MATH_MACRO_REMOVE_OPTIONAL_PARAM,
|
||||
// 310
|
||||
LFUN_MATH_MACRO_ADD_GREEDY_OPTIONAL_PARAM,
|
||||
LFUN_IN_MATHMACROTEMPLATE,
|
||||
// 315
|
||||
LFUN_SCROLL,
|
||||
LFUN_UI_TOGGLE,
|
||||
LFUN_SPLIT_VIEW,
|
||||
// 315
|
||||
LFUN_CLOSE_TAB_GROUP,
|
||||
LFUN_COMPLETION_POPUP,
|
||||
// 320
|
||||
LFUN_COMPLETION_INLINE,
|
||||
LFUN_COMPLETION_COMPLETE,
|
||||
LFUN_NEXT_INSET_MODIFY, // JSpitzm 20080323
|
||||
// 320
|
||||
LFUN_LASTACTION // end of the table
|
||||
};
|
||||
|
||||
|
@ -292,19 +292,12 @@ void LyXAction::init()
|
||||
/*!
|
||||
* \var lyx::FuncCode lyx::LFUN_NEWPAGE_INSERT
|
||||
* \li Action: Inserts a new page.
|
||||
* \li Syntax: newpage-insert
|
||||
* \li Syntax: newpage-insert<ARG>
|
||||
* \li Params: <ARG>: <newpage|pagebreak|clearpage|cleardoublepage> default: newpage
|
||||
* \li Origin: uwestoehr, 24 Nov 2007
|
||||
* \endvar
|
||||
*/
|
||||
{ LFUN_NEWPAGE_INSERT, "newpage-insert", Noop, Edit },
|
||||
/*!
|
||||
* \var lyx::FuncCode lyx::LFUN_PAGEBREAK_INSERT
|
||||
* \li Action: Inserts a pagebreak.
|
||||
* \li Syntax: pagebreak-insert
|
||||
* \li Origin: poenitz, Oct 27 2003
|
||||
* \endvar
|
||||
*/
|
||||
{ LFUN_PAGEBREAK_INSERT, "pagebreak-insert", Noop, Edit },
|
||||
/*!
|
||||
* \var lyx::FuncCode lyx::LFUN_MARGINALNOTE_INSERT
|
||||
* \li Action: Inserts a marginal note.
|
||||
@ -378,8 +371,6 @@ void LyXAction::init()
|
||||
* \endvar
|
||||
*/
|
||||
{ LFUN_SPECIALCHAR_INSERT, "specialchar-insert", Noop, Edit },
|
||||
{ LFUN_CLEARPAGE_INSERT, "clearpage-insert", Noop, Edit },
|
||||
{ LFUN_CLEARDOUBLEPAGE_INSERT, "cleardoublepage-insert", Noop, Edit },
|
||||
{ LFUN_TOC_INSERT, "toc-insert", Noop, Edit },
|
||||
{ LFUN_APPENDIX, "appendix", Noop, Edit },
|
||||
|
||||
|
@ -220,14 +220,6 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
|
||||
par.insertInset(par.size(), inset.release(), font, change);
|
||||
} 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);
|
||||
} 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") {
|
||||
|
@ -1418,9 +1418,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
|
||||
case LFUN_TOC_INSERT:
|
||||
case LFUN_LINE_INSERT:
|
||||
case LFUN_NEWPAGE_INSERT:
|
||||
case LFUN_PAGEBREAK_INSERT:
|
||||
case LFUN_CLEARPAGE_INSERT:
|
||||
case LFUN_CLEARDOUBLEPAGE_INSERT:
|
||||
// do nothing fancy
|
||||
doInsertInset(cur, this, cmd, false, false);
|
||||
cur.posForward();
|
||||
@ -2156,9 +2153,6 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
case LFUN_SELF_INSERT:
|
||||
case LFUN_LINE_INSERT:
|
||||
case LFUN_NEWPAGE_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:
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "insets/InsetLabel.h"
|
||||
#include "insets/InsetLine.h"
|
||||
#include "insets/InsetMarginal.h"
|
||||
#include "insets/InsetNewpage.h"
|
||||
#include "insets/InsetNote.h"
|
||||
#include "insets/InsetBox.h"
|
||||
#include "insets/InsetBranch.h"
|
||||
@ -85,17 +86,19 @@ Inset * createInsetHelper(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;
|
||||
|
||||
case LFUN_CLEARPAGE_INSERT:
|
||||
return new InsetClearPage;
|
||||
|
||||
case LFUN_CLEARDOUBLEPAGE_INSERT:
|
||||
return new InsetClearDoublePage;
|
||||
case LFUN_NEWPAGE_INSERT: {
|
||||
string const name = cmd.getArg(0);
|
||||
InsetNewpageParams inp;
|
||||
if (name.empty() || name == "newpage")
|
||||
inp.kind = InsetNewpageParams::NEWPAGE;
|
||||
else if (name == "pagebreak")
|
||||
inp.kind = InsetNewpageParams::PAGEBREAK;
|
||||
else if (name == "clearpage")
|
||||
inp.kind = InsetNewpageParams::CLEARPAGE;
|
||||
else if (name == "cleardoublepage")
|
||||
inp.kind = InsetNewpageParams::CLEARDOUBLEPAGE;
|
||||
return new InsetNewpage(inp);
|
||||
}
|
||||
|
||||
case LFUN_FLEX_INSERT: {
|
||||
string s = cmd.getArg(0);
|
||||
@ -536,6 +539,8 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
|
||||
inset.reset(new InsetFoot(buf));
|
||||
} else if (tmptok == "Marginal") {
|
||||
inset.reset(new InsetMarginal(buf));
|
||||
} else if (tmptok == "Newpage") {
|
||||
inset.reset(new InsetNewpage);
|
||||
} else if (tmptok == "OptArg") {
|
||||
inset.reset(new InsetOptArg(buf));
|
||||
} else if (tmptok == "Float") {
|
||||
|
@ -680,8 +680,6 @@ bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
case LFUN_BRANCH_INSERT:
|
||||
case LFUN_NEW_LINE:
|
||||
case LFUN_CAPTION_INSERT:
|
||||
case LFUN_CLEARPAGE_INSERT:
|
||||
case LFUN_CLEARDOUBLEPAGE_INSERT:
|
||||
case LFUN_DEPTH_DECREMENT:
|
||||
case LFUN_DEPTH_INCREMENT:
|
||||
case LFUN_ENVIRONMENT_INSERT:
|
||||
@ -714,7 +712,6 @@ bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
case LFUN_LABEL_INSERT:
|
||||
case LFUN_LINE_INSERT:
|
||||
case LFUN_NEWPAGE_INSERT:
|
||||
case LFUN_PAGEBREAK_INSERT:
|
||||
case LFUN_LAYOUT:
|
||||
case LFUN_LAYOUT_PARAGRAPH:
|
||||
case LFUN_LAYOUT_TABULAR:
|
||||
|
@ -4,6 +4,7 @@
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author André Pönitz
|
||||
* \author Jürgen Spitzmüller
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
@ -12,7 +13,10 @@
|
||||
|
||||
#include "InsetNewpage.h"
|
||||
|
||||
#include "FuncRequest.h"
|
||||
#include "FuncStatus.h"
|
||||
#include "Text.h"
|
||||
#include "Lexer.h"
|
||||
#include "MetricsInfo.h"
|
||||
#include "OutputParams.h"
|
||||
#include "TextMetrics.h"
|
||||
@ -30,15 +34,71 @@ using namespace std;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
void InsetNewpage::read( Lexer &)
|
||||
InsetNewpage::InsetNewpage()
|
||||
{}
|
||||
|
||||
|
||||
InsetNewpage::InsetNewpage(InsetNewpageParams par)
|
||||
{
|
||||
/* Nothing to read */
|
||||
params_.kind = par.kind;
|
||||
}
|
||||
|
||||
void InsetNewpageParams::write(ostream & os) const
|
||||
{
|
||||
string command;
|
||||
switch (kind) {
|
||||
case InsetNewpageParams::NEWPAGE:
|
||||
os << "newpage";
|
||||
break;
|
||||
case InsetNewpageParams::PAGEBREAK:
|
||||
os << "pagebreak";
|
||||
break;
|
||||
case InsetNewpageParams::CLEARPAGE:
|
||||
os << "clearpage";
|
||||
break;
|
||||
case InsetNewpageParams::CLEARDOUBLEPAGE:
|
||||
os << "cleardoublepage";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void InsetNewpageParams::read(Lexer & lex)
|
||||
{
|
||||
lex.next();
|
||||
string const command = lex.getString();
|
||||
|
||||
if (command == "newpage")
|
||||
kind = InsetNewpageParams::NEWPAGE;
|
||||
else if (command == "pagebreak")
|
||||
kind = InsetNewpageParams::PAGEBREAK;
|
||||
else if (command == "clearpage")
|
||||
kind = InsetNewpageParams::CLEARPAGE;
|
||||
else if (command == "cleardoublepage")
|
||||
kind = InsetNewpageParams::CLEARDOUBLEPAGE;
|
||||
else
|
||||
lex.printError("InsetNewpage: Unknown kind: `$$Token'");
|
||||
|
||||
string token;
|
||||
lex >> token;
|
||||
if (!lex)
|
||||
return;
|
||||
if (token != "\\end_inset")
|
||||
lex.printError("Missing \\end_inset at this point. "
|
||||
"Read: `$$Token'");
|
||||
}
|
||||
|
||||
|
||||
void InsetNewpage::write(ostream & os) const
|
||||
{
|
||||
os << "\n" << getCmdName() << '\n';
|
||||
os << "Newpage ";
|
||||
params_.write(os);
|
||||
}
|
||||
|
||||
|
||||
void InsetNewpage::read(Lexer & lex)
|
||||
{
|
||||
params_.read(lex);
|
||||
}
|
||||
|
||||
|
||||
@ -80,9 +140,106 @@ void InsetNewpage::draw(PainterInfo & pi, int x, int y) const
|
||||
}
|
||||
|
||||
|
||||
void InsetNewpage::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
{
|
||||
switch (cmd.action) {
|
||||
|
||||
case LFUN_INSET_MODIFY: {
|
||||
InsetNewpageParams params;
|
||||
InsetNewpageMailer::string2params(to_utf8(cmd.argument()), params);
|
||||
params_.kind = params.kind;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
Inset::doDispatch(cur, cmd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool InsetNewpage::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
FuncStatus & status) const
|
||||
{
|
||||
switch (cmd.action) {
|
||||
// we handle these
|
||||
case LFUN_INSET_MODIFY:
|
||||
if (cmd.getArg(0) == "newpage") {
|
||||
InsetNewpageParams params;
|
||||
InsetNewpageMailer::string2params(to_utf8(cmd.argument()), params);
|
||||
status.setOnOff(params_.kind == params.kind);
|
||||
} else
|
||||
status.enabled(true);
|
||||
return true;
|
||||
default:
|
||||
return Inset::getStatus(cur, cmd, status);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
docstring InsetNewpage::insetLabel() const
|
||||
{
|
||||
switch (params_.kind) {
|
||||
case InsetNewpageParams::NEWPAGE:
|
||||
return _("New Page");
|
||||
break;
|
||||
case InsetNewpageParams::PAGEBREAK:
|
||||
return _("Page Break");
|
||||
break;
|
||||
case InsetNewpageParams::CLEARPAGE:
|
||||
return _("Clear Page");
|
||||
break;
|
||||
case InsetNewpageParams::CLEARDOUBLEPAGE:
|
||||
return _("Clear Double Page");
|
||||
break;
|
||||
default:
|
||||
return _("New Page");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ColorCode InsetNewpage::ColorName() const
|
||||
{
|
||||
switch (params_.kind) {
|
||||
case InsetNewpageParams::NEWPAGE:
|
||||
return Color_newpage;
|
||||
break;
|
||||
case InsetNewpageParams::PAGEBREAK:
|
||||
return Color_pagebreak;
|
||||
break;
|
||||
case InsetNewpageParams::CLEARPAGE:
|
||||
return Color_newpage;
|
||||
break;
|
||||
case InsetNewpageParams::CLEARDOUBLEPAGE:
|
||||
return Color_newpage;
|
||||
break;
|
||||
default:
|
||||
return Color_newpage;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int InsetNewpage::latex(odocstream & os, OutputParams const &) const
|
||||
{
|
||||
os << from_ascii(getCmdName()) << "{}";
|
||||
switch (params_.kind) {
|
||||
case InsetNewpageParams::NEWPAGE:
|
||||
os << "\\newpage{}";
|
||||
break;
|
||||
case InsetNewpageParams::PAGEBREAK:
|
||||
os << "\\pagebreak{}";
|
||||
break;
|
||||
case InsetNewpageParams::CLEARPAGE:
|
||||
os << "\\clearpage{}";
|
||||
break;
|
||||
case InsetNewpageParams::CLEARDOUBLEPAGE:
|
||||
os << "\\cleardoublepage{}";
|
||||
break;
|
||||
default:
|
||||
os << "\\newpage{}";
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -101,4 +258,52 @@ int InsetNewpage::docbook(odocstream & os, OutputParams const &) const
|
||||
}
|
||||
|
||||
|
||||
docstring InsetNewpage::contextMenu(BufferView const &, int, int) const
|
||||
{
|
||||
return from_ascii("context-newpage");
|
||||
}
|
||||
|
||||
|
||||
string const InsetNewpageMailer::name_ = "newpage";
|
||||
|
||||
|
||||
InsetNewpageMailer::InsetNewpageMailer(InsetNewpage & inset)
|
||||
: inset_(inset)
|
||||
{}
|
||||
|
||||
|
||||
string const InsetNewpageMailer::inset2string(Buffer const &) const
|
||||
{
|
||||
return params2string(inset_.params());
|
||||
}
|
||||
|
||||
|
||||
void InsetNewpageMailer::string2params(string const & in, InsetNewpageParams & params)
|
||||
{
|
||||
params = InsetNewpageParams();
|
||||
if (in.empty())
|
||||
return;
|
||||
|
||||
istringstream data(in);
|
||||
Lexer lex(0,0);
|
||||
lex.setStream(data);
|
||||
|
||||
string name;
|
||||
lex >> name;
|
||||
if (!lex || name != name_)
|
||||
return print_mailer_error("InsetNewpageMailer", in, 1, name_);
|
||||
|
||||
params.read(lex);
|
||||
}
|
||||
|
||||
|
||||
string const InsetNewpageMailer::params2string(InsetNewpageParams const & params)
|
||||
{
|
||||
ostringstream data;
|
||||
data << name_ << ' ';
|
||||
params.write(data);
|
||||
return data.str();
|
||||
}
|
||||
|
||||
|
||||
} // namespace lyx
|
||||
|
@ -13,6 +13,7 @@
|
||||
#define INSET_NEWPAGE_H
|
||||
|
||||
#include "Inset.h"
|
||||
#include "MailInset.h"
|
||||
|
||||
#include "support/docstring.h"
|
||||
#include "support/gettext.h"
|
||||
@ -20,11 +21,41 @@
|
||||
|
||||
namespace lyx {
|
||||
|
||||
class InsetNewpageParams {
|
||||
public:
|
||||
/// The different kinds of spaces we support
|
||||
enum Kind {
|
||||
///
|
||||
NEWPAGE,
|
||||
///
|
||||
PAGEBREAK,
|
||||
///
|
||||
CLEARPAGE,
|
||||
///
|
||||
CLEARDOUBLEPAGE
|
||||
};
|
||||
///
|
||||
InsetNewpageParams() : kind(NEWPAGE) {}
|
||||
///
|
||||
void write(std::ostream & os) const;
|
||||
///
|
||||
void read(Lexer & lex);
|
||||
///
|
||||
Kind kind;
|
||||
};
|
||||
|
||||
|
||||
class InsetNewpage : public Inset
|
||||
{
|
||||
public:
|
||||
///
|
||||
InsetNewpage() {}
|
||||
InsetNewpage();
|
||||
|
||||
///
|
||||
explicit
|
||||
InsetNewpage(InsetNewpageParams par);
|
||||
///
|
||||
InsetNewpageParams params() const { return params_; }
|
||||
///
|
||||
InsetCode lyxCode() const { return NEWPAGE_CODE; }
|
||||
///
|
||||
@ -38,71 +69,48 @@ public:
|
||||
///
|
||||
int docbook(odocstream &, OutputParams const &) const;
|
||||
///
|
||||
void read(Lexer & lex);
|
||||
void read(Lexer & lex);
|
||||
///
|
||||
void write(std::ostream & os) const;
|
||||
/// We don't need \begin_inset and \end_inset
|
||||
bool directWrite() const { return true; }
|
||||
///
|
||||
DisplayType display() const { return AlignCenter; }
|
||||
///
|
||||
docstring insetLabel() const { return _("New Page"); }
|
||||
docstring insetLabel() const;
|
||||
///
|
||||
std::string getCmdName() const { return "\\newpage"; }
|
||||
ColorCode ColorName() const;
|
||||
///
|
||||
ColorCode ColorName() const { return Color_newpage; }
|
||||
virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
|
||||
private:
|
||||
///
|
||||
Inset * clone() const { return new InsetNewpage(*this); }
|
||||
///
|
||||
void doDispatch(Cursor & cur, FuncRequest & cmd);
|
||||
///
|
||||
bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
|
||||
///
|
||||
InsetNewpageParams params_;
|
||||
};
|
||||
|
||||
|
||||
class InsetPagebreak : public InsetNewpage
|
||||
{
|
||||
class InsetNewpageMailer : public MailInset {
|
||||
public:
|
||||
///
|
||||
InsetPagebreak() {}
|
||||
InsetNewpageMailer(InsetNewpage & inset);
|
||||
///
|
||||
docstring insetLabel() const { return _("Page Break"); }
|
||||
virtual Inset & inset() const { return inset_; }
|
||||
///
|
||||
std::string getCmdName() const { return "\\pagebreak"; }
|
||||
virtual std::string const & name() const { return name_; }
|
||||
///
|
||||
ColorCode ColorName() const { return Color_pagebreak; }
|
||||
virtual std::string const inset2string(Buffer const &) const;
|
||||
///
|
||||
static void string2params(std::string const &, InsetNewpageParams &);
|
||||
///
|
||||
static std::string const params2string(InsetNewpageParams const &);
|
||||
private:
|
||||
///
|
||||
Inset * clone() const { return new InsetPagebreak(*this); }
|
||||
};
|
||||
|
||||
|
||||
class InsetClearPage : public InsetNewpage
|
||||
{
|
||||
public:
|
||||
static std::string const name_;
|
||||
///
|
||||
InsetClearPage() {}
|
||||
///
|
||||
docstring insetLabel() const { return _("Clear Page"); }
|
||||
///
|
||||
std::string getCmdName() const { return "\\clearpage"; }
|
||||
|
||||
private:
|
||||
///
|
||||
Inset * clone() const { return new InsetClearPage(*this); }
|
||||
};
|
||||
|
||||
|
||||
class InsetClearDoublePage : public InsetNewpage
|
||||
{
|
||||
public:
|
||||
///
|
||||
InsetClearDoublePage() {}
|
||||
///
|
||||
docstring insetLabel() const { return _("Clear Double Page"); }
|
||||
///
|
||||
std::string getCmdName() const { return "\\cleardoublepage"; }
|
||||
|
||||
private:
|
||||
///
|
||||
Inset * clone() const { return new InsetClearDoublePage(*this); }
|
||||
InsetNewpage & inset_;
|
||||
};
|
||||
|
||||
} // namespace lyx
|
||||
|
Loading…
Reference in New Issue
Block a user