From c876a2e7c720a8dc4bc92ff4a437b769f327e904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Wed, 26 Mar 2008 08:10:01 +0000 Subject: [PATCH] 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 --- development/FORMAT | 3 + lib/bind/aqua.bind | 4 +- lib/bind/cua.bind | 4 +- lib/bind/emacs.bind | 4 +- lib/bind/mac.bind | 4 +- lib/bind/xemacs.bind | 4 +- lib/lyx2lyx/LyX.py | 2 +- lib/lyx2lyx/lyx_1_6.py | 41 ++++++- lib/ui/stdcontext.inc | 8 ++ lib/ui/stdmenus.inc | 4 +- src/Buffer.cpp | 2 +- src/FuncCode.h | 107 +++++++++-------- src/LyXAction.cpp | 11 +- src/Text.cpp | 8 -- src/Text3.cpp | 49 ++++---- src/factory.cpp | 3 + src/insets/InsetCollapsable.cpp | 2 +- src/insets/InsetNewline.cpp | 198 +++++++++++++++++++++++++++++--- src/insets/InsetNewline.h | 65 ++++++++--- src/insets/InsetTabular.cpp | 2 +- src/mathed/InsetMathGrid.cpp | 2 +- src/mathed/InsetMathHull.cpp | 4 +- 22 files changed, 383 insertions(+), 148 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index e4d2f3140f..611206f40f 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,6 +1,9 @@ LyX file-format changes ----------------------- +2008-03-25 Jürgen Spitzmüller + * Format incremented to 324: merge the two newline insets. + 2008-03-25 Jürgen Spitzmüller * Format incremented to 323: merge the diverse newpage insets. diff --git a/lib/bind/aqua.bind b/lib/bind/aqua.bind index 0ad38ef398..9a9297ead9 100644 --- a/lib/bind/aqua.bind +++ b/lib/bind/aqua.bind @@ -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 \"" diff --git a/lib/bind/cua.bind b/lib/bind/cua.bind index 58134b530e..92dc54f7bc 100644 --- a/lib/bind/cua.bind +++ b/lib/bind/cua.bind @@ -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" diff --git a/lib/bind/emacs.bind b/lib/bind/emacs.bind index 38155c8ca9..f738872a84 100644 --- a/lib/bind/emacs.bind +++ b/lib/bind/emacs.bind @@ -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" diff --git a/lib/bind/mac.bind b/lib/bind/mac.bind index b94636d5c7..72c408e76d 100644 --- a/lib/bind/mac.bind +++ b/lib/bind/mac.bind @@ -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" diff --git a/lib/bind/xemacs.bind b/lib/bind/xemacs.bind index cae0069ae6..2ace4cbefb 100644 --- a/lib/bind/xemacs.bind +++ b/lib/bind/xemacs.bind @@ -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" diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index f6471e9357..d2ba008d21 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,324), minor_versions("1.6" , 0))] + ("1_6", range(277,325), minor_versions("1.6" , 0))] def formats_list(): diff --git a/lib/lyx2lyx/lyx_1_6.py b/lib/lyx2lyx/lyx_1_6.py index 84740ddd26..bcbb436d3b 100644 --- a/lib/lyx2lyx/lyx_1_6.py +++ b/lib/lyx2lyx/lyx_1_6.py @@ -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]], diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc index e15d9bdae4..beb37e026b 100644 --- a/lib/ui/stdcontext.inc +++ b/lib/ui/stdcontext.inc @@ -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 # diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc index 1c2f29fcc2..e6e86798af 100644 --- a/lib/ui/stdmenus.inc +++ b/lib/ui/stdmenus.inc @@ -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" diff --git a/src/Buffer.cpp b/src/Buffer.cpp index e4592b56f0..d248051ae6 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -116,7 +116,7 @@ namespace os = support::os; namespace { -int const LYX_FORMAT = 323; +int const LYX_FORMAT = 324; typedef map DepClean; typedef map > RefCache; diff --git a/src/FuncCode.h b/src/FuncCode.h index 05ab36edf7..6425751ff5 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -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 }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index cfc8252d13..0022131c91 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -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 + * \li Params: : default: newline + * \li Origin: JSpitzm, 25 Mar 2008 + * \endvar + */ + { LFUN_NEWLINE_INSERT, "newline-insert", Noop, Edit }, /*! * \var lyx::FuncCode lyx::LFUN_COPY diff --git a/src/Text.cpp b/src/Text.cpp index a9b111b635..8db7ef65aa 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -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(new InsetLinebreak); - inset->read(lex); - par.insertInset(par.size(), inset.release(), font, change); - } else if (token == "\\newline") { - auto_ptr inset(new InsetNewline); - inset->read(lex); - par.insertInset(par.size(), inset.release(), font, change); } else if (token == "\\LyXTable") { auto_ptr inset(new InsetTabular(buf)); inset->read(lex); diff --git a/src/Text3.cpp b/src/Text3.cpp index 9ba4950284..da7b62a95b 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -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: diff --git a/src/factory.cpp b/src/factory.cpp index 8d11825f80..75b3eaea74 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -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") { diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index e2b7f8a9f7..3ec4414d78 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -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: diff --git a/src/insets/InsetNewline.cpp b/src/insets/InsetNewline.cpp index d1e8283696..72faac733b 100644 --- a/src/insets/InsetNewline.cpp +++ b/src/insets/InsetNewline.cpp @@ -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(); } diff --git a/src/insets/InsetNewline.h b/src/insets/InsetNewline.h index 04c2e241e2..50a08face7 100644 --- a/src/insets/InsetNewline.h +++ b/src/insets/InsetNewline.h @@ -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_; }; diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 1a3a845962..2eb80ecb0e 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -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()) { diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index 0298a40756..a63a456921 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -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); diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index eef8a32d08..366dd01a0d 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -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: