From d4634167cc2fa047c5f88d78e46b63459cdd0c85 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Tue, 12 Oct 2010 14:46:17 +0000 Subject: [PATCH] Get rid of "CharStyle:", "Custom:", and "Element:" prefixes, per a suggestion of JMarc's. Docs to follow. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35608 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/layouts/stdcharstyles.inc | 4 +- lib/lyx2lyx/lyx_2_0.py | 112 +++++++++++++++++++++++++++++++++- lib/scripts/layout2layout.py | 24 +++++++- po/lyx_pot.py | 6 +- src/Buffer.cpp | 2 +- src/TextClass.cpp | 2 +- src/frontends/qt4/Menus.cpp | 5 +- src/insets/InsetFlex.cpp | 6 ++ src/insets/InsetFlex.h | 4 +- 9 files changed, 151 insertions(+), 14 deletions(-) diff --git a/lib/layouts/stdcharstyles.inc b/lib/layouts/stdcharstyles.inc index c30a27b07d..dac5b023e0 100644 --- a/lib/layouts/stdcharstyles.inc +++ b/lib/layouts/stdcharstyles.inc @@ -2,10 +2,10 @@ # Author : Martin vermeer # Character Styles definition -Format 28 +Format 29 # Error fallback: -InsetLayout CharStyle +InsetLayout Flex LyxType end LabelString "UNDEFINED" Font diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index 45015937d2..b653bbe910 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -2056,6 +2056,110 @@ def revert_mathrsfs(document): i += 1 +def convert_flexnames(document): + "Convert \\begin_inset Flex Custom:Style to \\begin_inset Flex Style and similarly for CharStyle and Element." + + i = 0 + rx = re.compile(r'^\\begin_inset Flex (?:Custom|CharStyle|Element):(.+)$') + while True: + i = find_token(document.body, "\\begin_inset Flex", i) + if i == -1: + return + m = rx.match(document.body[i]) + if m: + document.body[i] = "\\begin_inset Flex " + m.group(1) + i += 1 + + +flex_insets = [ + ["Alert", "CharStyle:Alert"], + ["Code", "CharStyle:Code"], + ["Concepts", "CharStyle:Concepts"], + ["E-Mail", "CharStyle:E-Mail"], + ["Emph", "CharStyle:Emph"], + ["Expression", "CharStyle:Expression"], + ["Initial", "CharStyle:Initial"], + ["Institute", "CharStyle:Institute"], + ["Meaning", "CharStyle:Meaning"], + ["Noun", "CharStyle:Noun"], + ["Strong", "CharStyle:Strong"], + ["Structure", "CharStyle:Structure"], + ["ArticleMode", "Custom:ArticleMode"], + ["Endnote", "Custom:Endnote"], + ["Glosse", "Custom:Glosse"], + ["PresentationMode", "Custom:PresentationMode"], + ["Tri-Glosse", "Custom:Tri-Glosse"] +] + +flex_elements = [ + ["Abbrev", "Element:Abbrev"], + ["CCC-Code", "Element:CCC-Code"], + ["Citation-number", "Element:Citation-number"], + ["City", "Element:City"], + ["Code", "Element:Code"], + ["CODEN", "Element:CODEN"], + ["Country", "Element:Country"], + ["Day", "Element:Day"], + ["Directory", "Element:Directory"], + ["Dscr", "Element:Dscr"], + ["Email", "Element:Email"], + ["Emph", "Element:Emph"], + ["Filename", "Element:Filename"], + ["Firstname", "Element:Firstname"], + ["Fname", "Element:Fname"], + ["GuiButton", "Element:GuiButton"], + ["GuiMenu", "Element:GuiMenu"], + ["GuiMenuItem", "Element:GuiMenuItem"], + ["ISSN", "Element:ISSN"], + ["Issue-day", "Element:Issue-day"], + ["Issue-months", "Element:Issue-months"], + ["Issue-number", "Element:Issue-number"], + ["KeyCap", "Element:KeyCap"], + ["KeyCombo", "Element:KeyCombo"], + ["Keyword", "Element:Keyword"], + ["Literal", "Element:Literal"], + ["MenuChoice", "Element:MenuChoice"], + ["Month", "Element:Month"], + ["Orgdiv", "Element:Orgdiv"], + ["Orgname", "Element:Orgname"], + ["Postcode", "Element:Postcode"], + ["SS-Code", "Element:SS-Code"], + ["SS-Title", "Element:SS-Title"], + ["State", "Element:State"], + ["Street", "Element:Street"], + ["Surname", "Element:Surname"], + ["Volume", "Element:Volume"], + ["Year", "Element:Year"] +] + + +def revert_flexnames(document): + if document.backend == "latex": + flexlist = flex_insets + else: + flexlist = flex_elements + + rx = re.compile(r'^\\begin_inset Flex\s+(.+)$') + i = 0 + while True: + i = find_token(document.body, "\\begin_inset Flex", i) + if i == -1: + return + m = rx.match(document.body[i]) + if not m: + document.warning("Illegal flex inset: " + document.body[i]) + i += 1 + continue + + style = m.group(1) + for f in flexlist: + if f[0] == style: + document.body[i] = "\\begin_inset Flex " + f[1] + break + + i += 1 + + def convert_mathdots(document): " Load mathdots automatically " while True: @@ -2293,10 +2397,12 @@ convert = [[346, []], [399, [convert_mathdots]], [400, [convert_rule]], [401, []], - [402, [convert_bibtexClearpage]] - ] + [402, [convert_bibtexClearpage]], + [403, [convert_flexnames]] +] -revert = [[401, []], +revert = [[402, [revert_flexnames]], + [401, []], [400, [revert_diagram]], [399, [revert_rule]], [398, [revert_mathdots]], diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py index 9c7129d7ca..02ce4e3713 100644 --- a/lib/scripts/layout2layout.py +++ b/lib/scripts/layout2layout.py @@ -100,6 +100,10 @@ import os, re, string, sys # Incremented to format 28, 6 August 2010 by lasgouttes # Added ParbreakIsNewline tag for Layout and InsetLayout. +# Incremented to format 29, 10 August 2010 by rgh +# Changed Custom:Style, CharStyle:Style, and Element:Style +# uniformly to Flex:Style. + # Do not forget to document format change in Customization # Manual (section "Declaring a new text class"). @@ -107,7 +111,7 @@ import os, re, string, sys # development/tools/updatelayouts.sh script to update all # layout files to the new format. -currentFormat = 28 +currentFormat = 29 def usage(prog_name): @@ -191,6 +195,9 @@ def convert(lines): re_Type = re.compile(r'\s*Type\s+(\w+)', re.IGNORECASE) re_Builtin = re.compile(r'^(\s*)LaTeXBuiltin\s+(\w*)', re.IGNORECASE) re_True = re.compile(r'^\s*(?:true|1)\s*$', re.IGNORECASE) + re_InsetLayout = re.compile(r'^\s*InsetLayout\s+(?:Custom|CharStyle|Element):(\S+)\s*$') + # with quotes + re_QInsetLayout = re.compile(r'^\s*InsetLayout\s+"(?:Custom|CharStyle|Element):([^"]+)"\s*$') # counters for sectioning styles (hardcoded in 1.3) counters = {"part" : "\\Roman{part}", @@ -279,10 +286,21 @@ def convert(lines): i += 1 continue + if format == 28: + match = re_InsetLayout.match(lines[i]) + if match: + lines[i] = "InsetLayout Flex:" + match.group(1) + else: + match = re_QInsetLayout.match(lines[i]) + if match: + lines[i] = "InsetLayout \"Flex:" + match.group(1) + "\"" + i += 1 + continue + # Only new features if format >= 24 and format <= 27: - i += 1 - continue + i += 1 + continue if format == 23: match = re_Float.match(lines[i]) diff --git a/po/lyx_pot.py b/po/lyx_pot.py index 842040776d..b559aec97e 100755 --- a/po/lyx_pot.py +++ b/po/lyx_pot.py @@ -84,7 +84,8 @@ def layouts_l10n(input_files, output, base): ListName = re.compile(r'\s*ListName\s+(.*)') CategoryName = re.compile(r'\s*Category\s+(.*)') NameRE = re.compile(r'DeclareLyXModule.*{(.*)}') - InsetLayout = re.compile(r'^InsetLayout\s+(.*)') + InsetLayout = re.compile(r'^InsetLayout\s+\"?(.*)\"?') + FlexCheck = re.compile(r'^Flex:(.*)') DescBegin = re.compile(r'#+\s*DescriptionBegin\s*$') DescEnd = re.compile(r'#+\s*DescriptionEnd\s*$') Category = re.compile(r'#Category: (.*)$') @@ -172,6 +173,9 @@ def layouts_l10n(input_files, output, base): string = res.group(1) string = string.replace('_', ' ') writeString(out, src, base, lineno, string) + m = FlexCheck.search(string) + if m: + writeString(out, src, base, lineno, m.group(1)) continue res = Category.search(line) if res != None: diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 91fc9fdd4d..204d9045b0 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -127,7 +127,7 @@ namespace { // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -int const LYX_FORMAT = 402; // uwestoehr: fix for bug 1881 +int const LYX_FORMAT = 403; // rgh: Dummy format for InsetFlex name conversion typedef map DepClean; typedef map > RefCache; diff --git a/src/TextClass.cpp b/src/TextClass.cpp index fad437724e..3e74b801db 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -60,7 +60,7 @@ namespace lyx { // development/updatelayouts.sh script, to update the format of // all of our layout files. // -int const LAYOUT_FORMAT = 28; +int const LAYOUT_FORMAT = 29; namespace { diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index bc0f469bf2..93550577ef 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -1090,7 +1090,10 @@ void MenuDefinition::expandFlexInsert( TextClass::InsetLayouts::const_iterator end = insetLayouts.end(); for (; cit != end; ++cit) { if (cit->second.lyxtype() == type) { - docstring const label = cit->first; + docstring label = cit->first; + // we remove the "Flex:" prefix, if it is present + if (prefixIs(label, from_utf8("Flex:"))) + label = label.substr(5); addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(translateIfPossible(label)), FuncRequest(LFUN_FLEX_INSERT, Lexer::quoteString(label)))); diff --git a/src/insets/InsetFlex.cpp b/src/insets/InsetFlex.cpp index 757accaeab..2fd3a21037 100644 --- a/src/insets/InsetFlex.cpp +++ b/src/insets/InsetFlex.cpp @@ -42,6 +42,12 @@ InsetFlex::InsetFlex(InsetFlex const & in) {} +docstring InsetFlex::name() const +{ + return from_utf8("Flex:" + name_); +} + + InsetLayout::InsetDecoration InsetFlex::decoration() const { InsetLayout::InsetDecoration const dec = getLayout().decoration(); diff --git a/src/insets/InsetFlex.h b/src/insets/InsetFlex.h index caee6bcab7..5799b65f77 100644 --- a/src/insets/InsetFlex.h +++ b/src/insets/InsetFlex.h @@ -25,7 +25,7 @@ public: /// InsetFlex(Buffer *, std::string const & layoutName); /// - docstring name() const { return from_utf8(name_); } + docstring name() const; /// InsetCode lyxCode() const { return FLEX_CODE; } /// Default looks @@ -33,7 +33,7 @@ public: /// void write(std::ostream &) const; /// should paragraph indendation be ommitted in any case? - bool neverIndent() const { return true; } + bool neverIndent() const { return true; } /// bool hasSettings() const { return false; } /// -- 2.39.2