Merge the two linebreak insets into one.

* src/Buffer.cpp:
	- file format change to 324
* development/FORMAT:
	- document file format change

* src/insets/InsetNewline.{cpp,h}:
	- the former two separate derivates are now merged into one inset
	  with proper Params and Mailer. This simplifies the structure and allows for
	  switching between the two kinds.

* src/Text3.cpp:
	- The newline insets are now being generated with 
	   newline-insert [newline|linebreak]

* src/factory.cpp:
* src/Text.cpp:
	- Newline inset is now a proper inset with opening and closing tag.

* src/FuncCode.h:
* src/LyXAction.cpp:
* src/Text3.cpp:
* src/insets/InsetCollapsable.cpp:
* src/insets/InsetTabular.cpp:
* src/mathed/InsetMathGrid.cpp:
* src/mathed/InsetMathHull.cpp:
	- remove LFUN_NEW_LINE, LFUN_LINE_BREAK,
	  add LFUN_NEWLINE_INSERT

* lib/lyx2lyx/LyX.py:
* lib/lyx2lyx/lyx_1_6.py:
	- conversion and reversion routines for newline insets.

* lib/ui/stdmenus.inc:
* lib/ui/stdcontext.inc
	- adapt menu and add context menu to switch between newpage variants.

* lib/bind/*.bind:
	- adapt to new lfuns.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23966 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2008-03-26 08:10:01 +00:00
parent 30c7f6f019
commit c876a2e7c7
22 changed files with 383 additions and 148 deletions

View File

@ -1,6 +1,9 @@
LyX file-format changes
-----------------------
2008-03-25 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* Format incremented to 324: merge the two newline insets.
2008-03-25 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* Format incremented to 323: merge the diverse newpage insets.

View File

@ -28,8 +28,8 @@
\bind "M-~S-i s k" "specialchar-insert ligature-break"
\bind "M-~S-i s b" "space-insert protected"
\bind "C-S-slash" "specialchar-insert slash"
\bind "M-~S-i s l" "new-line"
\bind "M-~S-i s r" "line-break"
\bind "M-~S-i s l" "newline-insert newline"
\bind "M-~S-i s r" "newline-insert linebreak"
\bind "M-~S-i s i" "specialchar-insert dots"
\bind "M-~S-i s e" "specialchar-insert end-of-sentence-period"
\bind "M-~S-i s q" "self-insert \""

View File

@ -206,8 +206,8 @@
\bind "C-Delete" "word-delete-forward"
\bind "C-BackSpace" "word-delete-backward"
\bind "M-Return" "break-paragraph inverse"
\bind "C-Return" "new-line"
\bind "C-S-Return" "line-break"
\bind "C-Return" "newline-insert newline"
\bind "C-S-Return" "newline-insert linebreak"
\bind "C-k" "line-delete-forward"
\bind "C-space" "space-insert protected"
\bind "C-M-space" "space-insert normal"

View File

@ -210,8 +210,8 @@
\bind "M-d" "word-delete-forward"
\bind "C-BackSpace" "word-delete-backward"
\bind "M-Return" "break-paragraph inverse"
\bind "C-Return" "new-line"
\bind "C-S-Return" "line-break"
\bind "C-Return" "newline-insert newline"
\bind "C-S-Return" "newline-insert linebreak"
\bind "C-S-L" "specialchar-insert ligature-break"
\bind "C-space" "space-insert protected"
\bind "C-M-space" "space-insert normal"

View File

@ -180,8 +180,8 @@
\bind "M-Delete" "word-delete-forward"
\bind "M-BackSpace" "word-delete-backward"
\bind "M-Return" "break-paragraph inverse"
\bind "C-Return" "new-line"
\bind "C-S-Return" "line-break"
\bind "C-Return" "newline-insert newline"
\bind "C-S-Return" "newline-insert linebreak"
\bind "C-k" "line-delete-forward"
\bind "M-space" "space-insert protected"
\bind "C-M-space" "space-insert normal"

View File

@ -221,8 +221,8 @@
\bind "M-d" "word-delete-forward"
\bind "C-BackSpace" "word-delete-backward"
\bind "M-Return" "break-paragraph inverse"
\bind "C-Return" "new-line"
\bind "C-S-Return" "line-break"
\bind "C-Return" "newline-insert newline"
\bind "C-S-Return" "newline-insert linebreak"
\bind "C-S-L" "specialchar-insert ligature-break"
\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,324), minor_versions("1.6" , 0))]
("1_6", range(277,325), minor_versions("1.6" , 0))]
def formats_list():

View File

@ -1695,6 +1695,41 @@ def revert_pagebreaks(document):
document.body[i] = document.body[i].replace('\\begin_inset Newpage cleardoublepage', '\\cleardoublepage')
def convert_linebreaks(document):
' Convert inline Newline insets to new format '
i = 0
while True:
i = find_token(document.body, '\\newline', i)
if i == -1:
break
document.body[i:i+1] = ['\\begin_inset Newline newline',
'\\end_inset']
i = 0
while True:
i = find_token(document.body, '\\linebreak', i)
if i == -1:
break
document.body[i:i+1] = ['\\begin_inset Newline linebreak',
'\\end_inset']
def revert_linebreaks(document):
' Revert \\begin_inset Newline to previous inline format '
i = 0
while True:
i = find_token(document.body, '\\begin_inset Newline', 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 Newline inset.")
continue
del document.body[j]
document.body[i] = document.body[i].replace('\\begin_inset Newline newline', '\\newline')
document.body[i] = document.body[i].replace('\\begin_inset Newline linebreak', '\\linebreak')
##
# Conversion hub
#
@ -1746,10 +1781,12 @@ convert = [[277, [fix_wrong_tables]],
[320, []],
[321, [convert_tablines]],
[322, []],
[323, [convert_pagebreaks]]
[323, [convert_pagebreaks]],
[324, [convert_linebreaks]]
]
revert = [[322, [revert_pagebreaks]],
revert = [[323, [revert_linebreaks]],
[322, [revert_pagebreaks]],
[321, [revert_local_layout]],
[320, [revert_tablines]],
[319, [revert_protected_hfill]],

View File

@ -147,6 +147,14 @@ Menuset
Item "Clear Double Page|D" "next-inset-modify newpage cleardoublepage"
End
#
# InsetNewline context menu
#
Menu "context-newline"
Item "Ragged Line Break|R" "next-inset-modify newline newline"
Item "Justified Line Break|J" "next-inset-modify newline linebreak"
End
#
# Edit context menu
#

View File

@ -372,8 +372,8 @@ Menuset
Separator
Item "Hyphenation Point|H" "specialchar-insert hyphenation"
Item "Ligature Break|k" "specialchar-insert ligature-break"
Item "New Line|e" "new-line"
Item "Line Break|B" "line-break"
Item "Ragged Line Break|R" "newline-insert newline"
Item "Justified Line Break|J" "newline-insert linebreak"
Separator
Item "New Page|N" "newpage-insert newpage"
Item "Page Break|a" "newpage-insert pagebreak"

View File

@ -116,7 +116,7 @@ namespace os = support::os;
namespace {
int const LYX_FORMAT = 323;
int const LYX_FORMAT = 324;
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;

View File

@ -103,318 +103,317 @@ enum FuncCode
LFUN_CHAR_DELETE_FORWARD,
// 60
LFUN_CHAR_DELETE_BACKWARD,
LFUN_NEW_LINE,
LFUN_LINE_BREAK, // uwestoehr 20071125
LFUN_NEWLINE_INSERT, // renamed: JSpitzm, 20080325
LFUN_BREAK_PARAGRAPH,
LFUN_QUOTE_INSERT,
// 65
LFUN_ACCENT_CIRCUMFLEX,
// 65
LFUN_MATH_SUBSCRIPT,
LFUN_MATH_SUPERSCRIPT,
LFUN_ACCENT_GRAVE,
LFUN_ACCENT_ACUTE,
// 70
LFUN_ACCENT_TILDE,
// 70
LFUN_ACCENT_CEDILLA,
LFUN_ACCENT_MACRON,
LFUN_ACCENT_UNDERBAR,
LFUN_ACCENT_UNDERDOT,
// 75
LFUN_ACCENT_CIRCLE,
// 75
LFUN_ACCENT_TIE,
LFUN_ACCENT_BREVE,
LFUN_ACCENT_CARON,
LFUN_ACCENT_SPECIAL_CARON,
// 80
LFUN_ACCENT_HUNGARIAN_UMLAUT,
// 80
LFUN_ACCENT_UMLAUT,
LFUN_ACCENT_DOT,
LFUN_ACCENT_OGONEK,
LFUN_SELF_INSERT,
// 85
LFUN_GETBUFNAME,
// 85
LFUN_SERVER_GET_XY,
LFUN_SERVER_SET_XY,
LFUN_SERVER_CHAR_AFTER,
LFUN_LINEATCURSOR,
// 90
LFUN_SERVER_GET_LAYOUT,
// 90
LFUN_SERVER_GET_FONT,
LFUN_SERVER_GET_NAME,
LFUN_SERVER_NOTIFY,
LFUN_SERVER_GOTO_FILE_ROW,
// 95
LFUN_NOTE_INSERT,
// 95
LFUN_ENVIRONMENT_INSERT, // unused as of 20060905
LFUN_KEYMAP_OFF,
LFUN_KEYMAP_PRIMARY,
LFUN_KEYMAP_SECONDARY,
// 100
LFUN_KEYMAP_TOGGLE,
// 100
LFUN_MATH_INSERT,
LFUN_MATH_MATRIX,
LFUN_MATH_LIMITS,
LFUN_MATH_DELIM, // Alejandro 180696
// 105
LFUN_MATH_DISPLAY, // Alejandro 180696
// 105
LFUN_MATH_MODE, // Alejandro 040696
LFUN_MATH_NUMBER_TOGGLE,
LFUN_MATH_NUMBER_LINE_TOGGLE,
LFUN_MATH_SIZE, // Alejandro 150896
// 110
LFUN_MATH_MACRO, // ale970510
// 110
LFUN_MATH_EXTERN, // Andre' 20010424
LFUN_MATH_MUTATE, // Andre' 20010523
LFUN_MATH_IMPORT_SELECTION, // Andre' 20010704
LFUN_MATH_SPACE, // Andre' 20010725
// 115
LFUN_WORD_DELETE_FORWARD,
// 115
LFUN_WORD_DELETE_BACKWARD,
LFUN_LINE_DELETE,
LFUN_MARK_OFF,
LFUN_MARK_ON,
// 120
LFUN_LAYOUT,
// 120
LFUN_LAYOUT_PARAGRAPH,
LFUN_DROP_LAYOUTS_CHOICE, // used in bindings as of 20071228
LFUN_FONT_TYPEWRITER, // changed from FONT_CODE 20070920
LFUN_FONT_SANS,
// 125
LFUN_FONT_DEFAULT,
// 125
LFUN_FONT_UNDERLINE,
LFUN_FONT_SIZE,
LFUN_FONT_STATE,
LFUN_WORD_UPCASE,
// 130
LFUN_WORD_LOWCASE,
// 130
LFUN_WORD_CAPITALIZE,
LFUN_LABEL_INSERT,
LFUN_DEPTH_DECREMENT,
LFUN_DEPTH_INCREMENT,
// 135
LFUN_MENU_OPEN, // used in bindings as of 20060905
// 135
LFUN_CANCEL,
LFUN_META_PREFIX,
LFUN_COMMAND_EXECUTE,
LFUN_FILE_INSERT,
// 140
LFUN_FILE_INSERT_PLAINTEXT, // CFO-G 1997-11-19
// 140
LFUN_FILE_INSERT_PLAINTEXT_PARA,// Levon 2001-02-14
LFUN_FILE_OPEN,
LFUN_PARAGRAPH_UP, // Asger 1996-10-01
LFUN_PARAGRAPH_UP_SELECT, // Asger 1996-10-01
// 145
LFUN_PARAGRAPH_DOWN, // Asger 1996-10-01
// 145
LFUN_PARAGRAPH_DOWN_SELECT, // Asger 1996-10-01
LFUN_BREAK_PARAGRAPH_SKIP,
LFUN_DELETE_BACKWARD_SKIP,
LFUN_DELETE_FORWARD_SKIP,
// 150
LFUN_BUFFER_NEW_TEMPLATE, // Asger 1997-02-02
// 150
LFUN_BUFFER_RELOAD, // Asger 1997-02-02
LFUN_RECONFIGURE,
LFUN_INDEX_PRINT, // Lgb 97-02-27
LFUN_CELL_SPLIT,
// 155
LFUN_BUFFER_CHILD_OPEN, // Ale 970528
// 155
LFUN_TOC_INSERT, // Lgb 97-05-27
LFUN_FLOAT_LIST, // Lgb 20010503
LFUN_BUFFER_TOGGLE_READ_ONLY, // Lgb 97-05-27
LFUN_VC_REGISTER, // Lgb 97-07-01
// 160
LFUN_VC_CHECK_IN, // Lgb 97-07-01
// 160
LFUN_VC_CHECK_OUT, // Lgb 97-07-01
LFUN_VC_REVERT, // Lgb 97-07-01
LFUN_VC_UNDO_LAST, // Lgb 97-07-01
LFUN_BUFFER_EXPORT, // Lgb 97-07-29
// 165
LFUN_LABEL_GOTO, // Ale 970806
// 165
LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE, // ARRae 971202
LFUN_BUFFER_CHKTEX, // Asger 971030
LFUN_HYPERLINK_INSERT, // CFO-G 971121
LFUN_WORD_FIND_FORWARD, // Etienne 980216
// 170
LFUN_WORD_FIND_BACKWARD, // Etienne 980220
// 170
LFUN_APPENDIX, // ettrich 980505
LFUN_BUFFER_IMPORT, // Asger 980724
LFUN_COMMAND_SEQUENCE, // Andre' 991111
LFUN_PREFERENCES_SAVE,
// 175
LFUN_HELP_OPEN, // Jug 990627
// 175
LFUN_DATE_INSERT, // jdblair 20000131
LFUN_LANGUAGE, // Dekel 20000203
LFUN_ERT_INSERT, // Jug 20000218
LFUN_FOOTNOTE_INSERT, // Jug 20000307
// 180
LFUN_PARAGRAPH_SPACING, // Lgb 20000411
// 180
LFUN_TABULAR_INSERT, // Jug 20000412
LFUN_LOFVIEW, // Dekel 20000519
LFUN_LOTVIEW, // Dekel 20000519
LFUN_LOAVIEW, // Dekel 20000519
// 185
LFUN_SET_COLOR, // SLior 20000611
// 185
LFUN_MARGINALNOTE_INSERT, // Lgb 20000626
LFUN_FLOAT_INSERT, // Lgb 20000627
LFUN_FLOAT_WIDE_INSERT, // Lgb 20010531
LFUN_CAPTION_INSERT, // Lgb 20000718; inactive as of 20060905
// 190
LFUN_BUFFER_SWITCH,
// 190
LFUN_TABULAR_FEATURE, // Jug 20000728
LFUN_LAYOUT_TABULAR, // Jug 20000731
LFUN_BUFFER_UPDATE, // Dekel 20000805
LFUN_INDEX_INSERT, // Angus 20000803
// 195
LFUN_SCREEN_FONT_UPDATE, // ARRae 20000813
// 195
LFUN_PARAGRAPH_GOTO, // Dekel 20000826
LFUN_REFERENCE_NEXT, // Dekel 20010114
LFUN_BOOKMARK_SAVE,
LFUN_BOOKMARK_GOTO,
// 200
LFUN_SELECT_FILE_SYNC, // Levon 20010214
// 200
LFUN_MESSAGE, // Lgb 20010408; for scripting purposes, output in minibuffer
LFUN_CHARS_TRANSPOSE, // Lgb 20010425
LFUN_ESCAPE, // Lgb 20010517
LFUN_THESAURUS_ENTRY, // Levon 20010720
// 205
LFUN_OPTIONAL_INSERT, // Martin 12 Aug 2002
// 205
LFUN_MOUSE_PRESS, // André 9 Aug 2002
LFUN_MOUSE_MOTION, // André 9 Aug 2002
LFUN_MOUSE_RELEASE, // André 9 Aug 2002
LFUN_MOUSE_DOUBLE, // André 9 Aug 2002
// 210
LFUN_MOUSE_TRIPLE, // André 9 Aug 2002
// 210
LFUN_WRAP_INSERT, // Dekel 7 Apr 2002
LFUN_CHANGES_TRACK, // Levon 20021001 (cool date !)
LFUN_CHANGES_MERGE, // Levon 20021016
LFUN_CHANGE_ACCEPT, // Levon 20021016
// 215
LFUN_CHANGE_REJECT, // Levon 20021016
// 215
LFUN_ALL_CHANGES_ACCEPT, // Levon 20021016
LFUN_ALL_CHANGES_REJECT, // Levon 20021016
LFUN_BIBITEM_INSERT, // André 14 Feb 2003
LFUN_DIALOG_SHOW,
// 220
LFUN_DIALOG_SHOW_NEW_INSET,
// 220
LFUN_DIALOG_UPDATE,
LFUN_DIALOG_HIDE,
LFUN_DIALOG_TOGGLE, // JSpitzm 20070430
LFUN_DIALOG_DISCONNECT_INSET,
// 225
LFUN_INSET_APPLY,
// 225
LFUN_INSET_INSERT,
LFUN_INSET_MODIFY,
LFUN_INSET_DIALOG_UPDATE,
LFUN_INSET_SETTINGS,
// 230
LFUN_PARAGRAPH_PARAMS_APPLY,
// 230
LFUN_PARAGRAPH_UPDATE,
LFUN_EXTERNAL_EDIT,
LFUN_BRANCH_INSERT,
LFUN_BOX_INSERT,
// 235
LFUN_LINE_INSERT,
// 235
LFUN_NEWPAGE_INSERT, // uwestoehr, 20071124
LFUN_REPEAT,
LFUN_FINISHED_LEFT,
LFUN_FINISHED_RIGHT,
// 240
LFUN_FLEX_INSERT,
// 240
LFUN_WORD_FIND,
LFUN_WORD_REPLACE,
LFUN_BUFFER_EXPORT_CUSTOM,
LFUN_BUFFER_PRINT,
// 245
LFUN_NEXT_INSET_TOGGLE,
// 245
LFUN_ALL_INSETS_TOGGLE,
LFUN_BUFFER_LANGUAGE,
LFUN_TEXTCLASS_APPLY,
LFUN_TEXTCLASS_LOAD,
// 250
LFUN_BUFFER_SAVE_AS_DEFAULT,
// 250
LFUN_BUFFER_PARAMS_APPLY,
LFUN_LYXRC_APPLY,
LFUN_GRAPHICS_EDIT,
LFUN_BUFFER_NEXT,
// 255
LFUN_BUFFER_PREVIOUS,
// 255
LFUN_STATISTICS,
LFUN_CHANGES_OUTPUT, // jspitzm 20050121
LFUN_BIBTEX_DATABASE_ADD,
LFUN_BIBTEX_DATABASE_DEL,
// 260
LFUN_CITATION_INSERT,
// 260
LFUN_OUTLINE_UP,
LFUN_OUTLINE_DOWN,
LFUN_OUTLINE_IN,
LFUN_OUTLINE_OUT,
// 265
LFUN_PARAGRAPH_MOVE_DOWN,
// 265
LFUN_PARAGRAPH_MOVE_UP,
LFUN_BUFFER_TOGGLE_COMPRESSION, // bpeng 20060427
LFUN_MATH_BIGDELIM,
LFUN_CLIPBOARD_PASTE,
// 270
LFUN_INSET_DISSOLVE, // jspitzm 20060807
// 270
LFUN_CHANGE_NEXT,
LFUN_WINDOW_NEW, // Abdel 20061021
LFUN_WINDOW_CLOSE, // Abdel 20061023
LFUN_UNICODE_INSERT, // Lgb 20061022
// 275
LFUN_BOOKMARK_CLEAR, // bpeng 20061031
// 275
LFUN_NOMENCL_INSERT, // Ugras
LFUN_NOMENCL_PRINT, // Ugras
LFUN_LISTING_INSERT, // Herbert 20011110, bpeng 20070502
LFUN_TOOLBAR_TOGGLE, // Edwin 20070521
// 280
LFUN_BUFFER_WRITE_ALL, // rgh, gpothier 200707XX
// 280
LFUN_PARAGRAPH_PARAMS,
LFUN_LAYOUT_MODULES_CLEAR,
LFUN_LAYOUT_MODULE_ADD,
LFUN_LAYOUT_RELOAD,
// 285
LFUN_MASTER_BUFFER_VIEW, // Tommaso, 20070920
// 285
LFUN_MASTER_BUFFER_UPDATE, // Tommaso, 20070920
LFUN_INFO_INSERT, // bpeng, 20071007
LFUN_CALL, // broider, 20071002
LFUN_BUFFER_TOGGLE_EMBEDDING, // bpeng, 20071021
// 290
LFUN_CHAR_LEFT, // dov, 20071022
// 290
LFUN_CHAR_LEFT_SELECT, // dov, 20071022
LFUN_CHAR_RIGHT, // dov, 20071022
LFUN_CHAR_RIGHT_SELECT, // dov, 20071022
LFUN_FINISHED_BACKWARD, // dov, 20071022
// 295
LFUN_FINISHED_FORWARD, // dov, 20071022
// 295
LFUN_WORD_LEFT, // dov, 20071028
LFUN_WORD_LEFT_SELECT, // dov, 20071028
LFUN_WORD_RIGHT, // dov, 20071028
LFUN_WORD_RIGHT_SELECT, // dov, 20071028
// 300
LFUN_MATH_MACRO_FOLD,
// 300
LFUN_MATH_MACRO_UNFOLD,
LFUN_MATH_MACRO_ADD_PARAM,
LFUN_MATH_MACRO_REMOVE_PARAM,
LFUN_MATH_MACRO_APPEND_GREEDY_PARAM,
// 305
LFUN_MATH_MACRO_REMOVE_GREEDY_PARAM,
// 305
LFUN_MATH_MACRO_MAKE_OPTIONAL,
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,
// 310
LFUN_IN_MATHMACROTEMPLATE,
LFUN_SCROLL,
LFUN_UI_TOGGLE,
LFUN_SPLIT_VIEW,
// 315
LFUN_CLOSE_TAB_GROUP,
// 315
LFUN_COMPLETION_POPUP,
LFUN_COMPLETION_INLINE,
LFUN_COMPLETION_COMPLETE,
LFUN_NEXT_INSET_MODIFY, // JSpitzm 20080323
// 320
LFUN_LASTACTION // end of the table
// 320
};

View File

@ -554,11 +554,18 @@ void LyXAction::init()
{ 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 },
{ LFUN_NEW_LINE, "new-line", Noop, Edit },
/*!
* \var lyx::FuncCode lyx::LFUN_NEWLINE_INSERT
* \li Action: Inserts a line break or new line.
* \li Syntax: newline-insert<ARG>
* \li Params: <ARG>: <newline|linebreak> default: newline
* \li Origin: JSpitzm, 25 Mar 2008
* \endvar
*/
{ LFUN_NEWLINE_INSERT, "newline-insert", Noop, Edit },
/*!
* \var lyx::FuncCode lyx::LFUN_COPY

View File

@ -206,14 +206,6 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
font, change);
} else if (token == "\\backslash") {
par.appendChar('\\', font, change);
} else if (token == "\\linebreak") {
auto_ptr<Inset> inset(new InsetLinebreak);
inset->read(lex);
par.insertInset(par.size(), inset.release(), font, change);
} else if (token == "\\newline") {
auto_ptr<Inset> inset(new InsetNewline);
inset->read(lex);
par.insertInset(par.size(), inset.release(), font, change);
} else if (token == "\\LyXTable") {
auto_ptr<Inset> inset(new InsetTabular(buf));
inset->read(lex);

View File

@ -658,36 +658,24 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
break;
}
case LFUN_NEW_LINE: {
// 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 InsetNewline);
cur.posForward();
moveCursor(cur, false);
}
case LFUN_NEWLINE_INSERT: {
InsetNewlineParams inp;
docstring arg = cmd.argument();
// this avoids a double undo
// FIXME: should not be needed, ideally
if (!cur.selection())
cur.recordUndo();
cap::replaceSelection(cur);
if (arg == "linebreak")
inp.kind = InsetNewlineParams::LINEBREAK;
else
inp.kind = InsetNewlineParams::NEWLINE;
cur.insert(new InsetNewline(inp));
cur.posForward();
moveCursor(cur, false);
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())
@ -2120,6 +2108,11 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
enable = (cur.paragraph().layout().toclevel != Layout::NOT_IN_TOC);
break;
case LFUN_NEWLINE_INSERT:
// LaTeX restrictions (labels or empty par)
enable = (cur.pos() > cur.paragraph().beginOfBody());
break;
case LFUN_WORD_DELETE_FORWARD:
case LFUN_WORD_DELETE_BACKWARD:
case LFUN_LINE_DELETE:
@ -2151,9 +2144,7 @@ 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_NEW_LINE:
case LFUN_CHAR_DELETE_FORWARD:
case LFUN_DELETE_FORWARD_SKIP:
case LFUN_CHAR_DELETE_BACKWARD:

View File

@ -40,6 +40,7 @@
#include "insets/InsetLabel.h"
#include "insets/InsetLine.h"
#include "insets/InsetMarginal.h"
#include "insets/InsetNewline.h"
#include "insets/InsetNewpage.h"
#include "insets/InsetNote.h"
#include "insets/InsetBox.h"
@ -541,6 +542,8 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
inset.reset(new InsetMarginal(buf));
} else if (tmptok == "Newpage") {
inset.reset(new InsetNewpage);
} else if (tmptok == "Newline") {
inset.reset(new InsetNewline);
} else if (tmptok == "OptArg") {
inset.reset(new InsetOptArg(buf));
} else if (tmptok == "Float") {

View File

@ -656,7 +656,7 @@ bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_BIBITEM_INSERT:
case LFUN_BOX_INSERT:
case LFUN_BRANCH_INSERT:
case LFUN_NEW_LINE:
case LFUN_NEWLINE_INSERT:
case LFUN_CAPTION_INSERT:
case LFUN_DEPTH_DECREMENT:
case LFUN_DEPTH_INCREMENT:

View File

@ -4,6 +4,7 @@
* Licence details can be found in the file COPYING.
*
* \author John Levon
* \author Jürgen Spitzmüller
*
* Full author contact details are available in file CREDITS.
*/
@ -12,7 +13,10 @@
#include "InsetNewline.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "Dimension.h"
#include "Lexer.h"
#include "MetricsInfo.h"
#include "OutputParams.h"
@ -27,16 +31,55 @@ using namespace std;
namespace lyx {
InsetNewline::InsetNewline()
{}
void InsetNewline::read(Lexer &)
void InsetNewlineParams::write(ostream & os) const
{
/* Nothing to read */
string command;
switch (kind) {
case InsetNewlineParams::NEWLINE:
os << "newline";
break;
case InsetNewlineParams::LINEBREAK:
os << "linebreak";
break;
}
}
void InsetNewlineParams::read(Lexer & lex)
{
lex.next();
string const command = lex.getString();
if (command == "newline")
kind = InsetNewlineParams::NEWLINE;
else if (command == "linebreak")
kind = InsetNewlineParams::LINEBREAK;
else
lex.printError("InsetNewline: 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 InsetNewline::write(ostream & os) const
{
os << "\n" << getLyXName() << '\n';
os << "Newline ";
params_.write(os);
}
void InsetNewline::read(Lexer & lex)
{
params_.read(lex);
}
@ -49,9 +92,72 @@ void InsetNewline::metrics(MetricsInfo & mi, Dimension & dim) const
}
void InsetNewline::doDispatch(Cursor & cur, FuncRequest & cmd)
{
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
InsetNewlineParams params;
InsetNewlineMailer::string2params(to_utf8(cmd.argument()), params);
params_.kind = params.kind;
break;
}
default:
Inset::doDispatch(cur, cmd);
break;
}
}
bool InsetNewline::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & status) const
{
switch (cmd.action) {
// we handle these
case LFUN_INSET_MODIFY:
if (cmd.getArg(0) == "newline") {
InsetNewlineParams params;
InsetNewlineMailer::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);
}
}
ColorCode InsetNewline::ColorName() const
{
switch (params_.kind) {
case InsetNewlineParams::NEWLINE:
return Color_eolmarker;
break;
case InsetNewlineParams::LINEBREAK:
return Color_pagebreak;
break;
default:
return Color_eolmarker;
break;
}
}
int InsetNewline::latex(odocstream & os, OutputParams const &) const
{
os << from_ascii(getCmdName()) << '\n';
switch (params_.kind) {
case InsetNewlineParams::NEWLINE:
os << "\\\\\n";
break;
case InsetNewlineParams::LINEBREAK:
os << "\\linebreak{}\n";
break;
default:
os << "\\\\\n";
break;
}
return 0;
}
@ -114,22 +220,84 @@ void InsetNewline::draw(PainterInfo & pi, int x, int y) const
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);
if (params_.kind == InsetNewlineParams::LINEBREAK) {
yp[2] = int(y - 0.500 * asc * 0.75);
if (pi.ltr_pos) {
xp[0] = int(x + 1.3 * wid);
xp[1] = int(x + 2 * wid);
xp[2] = int(x + 2 * wid);
} else {
xp[0] = int(x - 0.3 * wid);
xp[1] = int(x - wid);
xp[2] = int(x - wid);
}
pi.pain.lines(xp, yp, 3, ColorName());
yp[0] = int(y - 0.875 * asc * 0.75);
yp[1] = int(y - 0.500 * asc * 0.75);
yp[2] = int(y - 0.125 * asc * 0.75);
int const text_start = int(x + 2 * wid);
pi.pain.rectText(text_start, yp[0] + d, insetLabel(), font,
Color_none, Color_none);
if (pi.ltr_pos) {
xp[0] = int(x + 2 * wid * 0.813);
xp[1] = int(x + 2 * wid);
xp[2] = int(x + 2 * wid * 0.813);
} else {
xp[0] = int(x - wid * 0.625);
xp[1] = int(x - wid);
xp[2] = int(x - wid * 0.625);
}
pi.pain.lines(xp, yp, 3, ColorName());
}
}
bool InsetNewline::isSpace() const
docstring InsetNewline::contextMenu(BufferView const &, int, int) const
{
return true;
return from_ascii("context-newline");
}
string const InsetNewlineMailer::name_ = "newline";
InsetNewlineMailer::InsetNewlineMailer(InsetNewline & inset)
: inset_(inset)
{}
string const InsetNewlineMailer::inset2string(Buffer const &) const
{
return params2string(inset_.params());
}
void InsetNewlineMailer::string2params(string const & in, InsetNewlineParams & params)
{
params = InsetNewlineParams();
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("InsetNewlineMailer", in, 1, name_);
params.read(lex);
}
string const InsetNewlineMailer::params2string(InsetNewlineParams const & params)
{
ostringstream data;
data << name_ << ' ';
params.write(data);
return data.str();
}

View File

@ -13,6 +13,7 @@
#define INSET_NEWLINE_H
#include "Inset.h"
#include "MailInset.h"
#include "support/docstring.h"
#include "support/gettext.h"
@ -20,11 +21,35 @@
namespace lyx {
class InsetNewlineParams {
public:
/// The different kinds of spaces we support
enum Kind {
///
NEWLINE,
///
LINEBREAK
};
///
InsetNewlineParams() : kind(NEWLINE) {}
///
void write(std::ostream & os) const;
///
void read(Lexer & lex);
///
Kind kind;
};
class InsetNewline : public Inset
{
public:
///
InsetNewline() {}
InsetNewline();
///
InsetNewline(InsetNewlineParams par) { params_.kind = par.kind; }
///
InsetNewlineParams params() const { return params_; }
///
InsetCode lyxCode() const { return NEWLINE_CODE; }
///
@ -41,43 +66,45 @@ public:
void read(Lexer & lex);
///
void write(std::ostream & os) const;
/// We don't need \begin_inset and \end_inset
bool directWrite() const { return true; }
/// is this equivalent to a space (which is BTW different from
/// a line separator)?
bool isSpace() const;
bool isSpace() const { return true; }
///
docstring insetLabel() const { return docstring(); }
ColorCode ColorName() const;
///
std::string getLyXName() const { return "\\newline"; }
///
std::string getCmdName() const { return "\\\\"; }
///
ColorCode ColorName() const { return Color_eolmarker; }
virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
private:
///
Inset * clone() const { return new InsetNewline(*this); }
///
void doDispatch(Cursor & cur, FuncRequest & cmd);
///
bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
///
InsetNewlineParams params_;
};
class InsetLinebreak : public InsetNewline
{
class InsetNewlineMailer : public MailInset {
public:
///
InsetLinebreak() {}
InsetNewlineMailer(InsetNewline & inset);
///
docstring insetLabel() const { return _("line break"); }
virtual Inset & inset() const { return inset_; }
///
std::string getLyXName() const { return "\\linebreak"; }
virtual std::string const & name() const { return name_; }
///
std::string getCmdName() const { return "\\linebreak{}"; }
virtual std::string const inset2string(Buffer const &) const;
///
ColorCode ColorName() const { return Color_pagebreak; }
static void string2params(std::string const &, InsetNewlineParams &);
///
static std::string const params2string(InsetNewlineParams const &);
private:
///
Inset * clone() const { return new InsetLinebreak(*this); }
static std::string const name_;
///
InsetNewline & inset_;
};

View File

@ -3708,7 +3708,7 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
}
// disable in non-fixed-width cells
case LFUN_NEW_LINE:
case LFUN_NEWLINE_INSERT:
case LFUN_BREAK_PARAGRAPH:
case LFUN_BREAK_PARAGRAPH_SKIP: {
if (tabular.getPWidth(cur.idx()).zero()) {

View File

@ -1093,7 +1093,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
}
break;
case LFUN_NEW_LINE: {
case LFUN_NEWLINE_INSERT: {
cur.recordUndoInset();
row_type const r = cur.row();
addRow(r);

View File

@ -1126,7 +1126,7 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
// just swallow this
break;
case LFUN_NEW_LINE:
case LFUN_NEWLINE_INSERT:
// some magic for the common case
if (type_ == hullSimple || type_ == hullEquation) {
cur.recordUndoInset();
@ -1285,7 +1285,7 @@ bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_FINISHED_LEFT:
case LFUN_UP:
case LFUN_DOWN:
case LFUN_NEW_LINE:
case LFUN_NEWLINE_INSERT:
case LFUN_MATH_EXTERN:
case LFUN_MATH_MUTATE:
case LFUN_MATH_DISPLAY: