From f58638c704b0b4ac66e5f88431901977cc7801be Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Thu, 7 Jan 2016 21:25:17 +0000 Subject: [PATCH] New LFUN tabular-feature: convert "inset-modify tabular" in LyX files * Increase LyX format * New function convert_info_insets in lyx2lyx_tools.py Use this function in the future for future updates of info insets * Convert "inset-modify tabular" to "tabular-feature" in info insets * Remove icon naming hack regarding "inset-modify tabular" --- development/FORMAT | 5 +++++ lib/lyx2lyx/LyX.py | 2 +- lib/lyx2lyx/lyx2lyx_tools.py | 23 +++++++++++++++++++++++ lib/lyx2lyx/lyx_2_2.py | 18 ++++++++++++++++-- src/frontends/qt4/GuiApplication.cpp | 14 -------------- src/version.h | 4 ++-- 6 files changed, 47 insertions(+), 19 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index 0c8a98cbe1..a36855bbf4 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -11,6 +11,11 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx. ----------------------- +2016-01-26 Guillaume Munch + * Format incremented to 506 + No new parameters. + Convert "inset-modify tabular" to "tabular-feature" in Info insets. + 2016-01-26 Uwe Stöhr * Format incremented to 505 No new parameters. diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index 047dc9be5a..b2b57313ce 100644 --- a/lib/lyx2lyx/LyX.py +++ b/lib/lyx2lyx/LyX.py @@ -86,7 +86,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)), ("1_6", list(range(277,346)), minor_versions("1.6" , 10)), ("2_0", list(range(346,414)), minor_versions("2.0" , 8)), ("2_1", list(range(414,475)), minor_versions("2.1" , 0)), - ("2_2", list(range(475,506)), minor_versions("2.2" , 0)) + ("2_2", list(range(475,507)), minor_versions("2.2" , 0)) ] #################################################################### diff --git a/lib/lyx2lyx/lyx2lyx_tools.py b/lib/lyx2lyx/lyx2lyx_tools.py index 14732296cc..f63f402616 100644 --- a/lib/lyx2lyx/lyx2lyx_tools.py +++ b/lib/lyx2lyx/lyx2lyx_tools.py @@ -69,6 +69,11 @@ latex_length(slen): (bool, length), where the bool tells us if it was a percentage, and the length is the LaTeX representation. +convert_info_insets(document, type, func): + Applies func to the argument of all info insets matching certain types + type : the type to match. This can be a regular expression. + func : function from string to string to apply to the "arg" field of + the info insets. ''' import re @@ -503,3 +508,21 @@ def str2bool(s): "'true' goes to True, case-insensitively, and we strip whitespace." s = s.strip().lower() return s == "true" + + +def convert_info_insets(document, type, func): + "Convert info insets matching type using func." + i = 0 + type_re = re.compile(r'^type\s+"(%s)"$' % type) + arg_re = re.compile(r'^arg\s+"(.*)"$') + while True: + i = find_token(document.body, "\\begin_inset Info", i) + if i == -1: + return + t = type_re.match(document.body[i + 1]) + if t: + arg = arg_re.match(document.body[i + 2]) + if arg: + new_arg = func(arg.group(1)) + document.body[i + 2] = 'arg "%s"' % new_arg + i += 3 diff --git a/lib/lyx2lyx/lyx_2_2.py b/lib/lyx2lyx/lyx_2_2.py index 48962c3d26..d3f836a840 100644 --- a/lib/lyx2lyx/lyx_2_2.py +++ b/lib/lyx2lyx/lyx_2_2.py @@ -31,7 +31,7 @@ import sys, os # del_token, check_token, get_option_value from lyx2lyx_tools import add_to_preamble, put_cmd_in_ert, get_ert, lyx2latex, \ - lyx2verbatim, length_in_bp + lyx2verbatim, length_in_bp, convert_info_insets # insert_to_preamble, latex_length, revert_flex_inset, \ # revert_font_attrs, hex2ratio, str2bool @@ -2305,6 +2305,18 @@ def convert_ACM_siggraph(document): document.body[1:1] = note +def convert_info_tabular_feature(document): + def f(arg): + return arg.replace("inset-modify tabular", "tabular-feature") + convert_info_insets(document, "shortcut(s)?|icon", f) + + +def revert_info_tabular_feature(document): + def f(arg): + return arg.replace("tabular-feature", "inset-modify tabular") + convert_info_insets(document, "shortcut(s)?|icon", f) + + ## # Conversion hub # @@ -2344,10 +2356,12 @@ convert = [ [502, []], [503, []], [504, [convert_save_props]], - [505, [convert_ACM_siggraph]] + [505, [convert_ACM_siggraph]], + [506, [convert_info_tabular_feature]] ] revert = [ + [505, [revert_info_tabular_feature]], [504, [revert_save_props]], [503, [revert_save_props]], [502, [revert_verbatim_star]], diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 82bbd60d46..12f99d5597 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -486,23 +486,9 @@ QString iconName(FuncRequest const & f, bool unknown) docstring firstcom; docstring dummy = split(f.argument(), firstcom, ';'); name1 = toqstr(firstcom); - // FIXME: we should remove all references to "inset-modify tabular" - // icons and shortcuts in all manuals - name1.replace("inset-modify tabular", "tabular-feature"); name1.replace(' ', '_'); break; } - case LFUN_INSET_MODIFY: { - // FIXME: we should remove all references to "inset-modify tabular" - // icons and shortcuts in all manuals - string inset_name; - string const command = split(to_utf8(f.argument()), inset_name, ' '); - if (inset_name == "tabular") { - name1 = "tabular-feature "+ toqstr(command); - name1.replace(' ', '_'); - break; - } - } default: name2 = toqstr(lyxaction.getActionName(f.action())); name1 = name2; diff --git a/src/version.h b/src/version.h index 5155341c59..9a377391d2 100644 --- a/src/version.h +++ b/src/version.h @@ -32,8 +32,8 @@ extern char const * const lyx_version_info; // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -#define LYX_FORMAT_LYX 505 // uwestoehr: new format for ACM siggraaph -#define LYX_FORMAT_TEX2LYX 505 +#define LYX_FORMAT_LYX 506 // guillaume munch: convert "inset-modify tabular" +#define LYX_FORMAT_TEX2LYX 506 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #ifndef _MSC_VER -- 2.39.5