]> git.lyx.org Git - features.git/commitdiff
Get rid of "CharStyle:", "Custom:", and "Element:" prefixes, per a
authorRichard Heck <rgheck@comcast.net>
Tue, 12 Oct 2010 14:46:17 +0000 (14:46 +0000)
committerRichard Heck <rgheck@comcast.net>
Tue, 12 Oct 2010 14:46:17 +0000 (14:46 +0000)
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
lib/lyx2lyx/lyx_2_0.py
lib/scripts/layout2layout.py
po/lyx_pot.py
src/Buffer.cpp
src/TextClass.cpp
src/frontends/qt4/Menus.cpp
src/insets/InsetFlex.cpp
src/insets/InsetFlex.h

index c30a27b07daa7326201b83b9ca5c9a30a41ec339..dac5b023e02c30ced7aa776e03aebea91d143073 100644 (file)
@@ -2,10 +2,10 @@
 # Author : Martin vermeer <martin.vermeer@hut.fi>
 # Character Styles definition
 
-Format 28
+Format 29
 
 # Error fallback:
-InsetLayout CharStyle
+InsetLayout Flex
        LyxType               end
        LabelString           "UNDEFINED"
        Font
index 45015937d2dfc8b7d965be281bf5ef7336cafca8..b653bbe910abdf118c7309cca15d6578f0d51ab1 100644 (file)
@@ -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]],
index 9c7129d7ca1cd54d63b1ebe186d65230ef15abb2..02ce4e3713b5f2815193a2f5edb297d3da9499bd 100644 (file)
@@ -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])
index 842040776d1a47792c2b515ef9b0f81cff4dcef8..b559aec97e25e8cc0b8e6d89d4da016165d84c5b 100755 (executable)
@@ -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:
index 91fc9fdd4d4b78cd1a7ce4b5d6fb5480b45fc7b8..204d9045b0a9233047027f442bac79336e99c11a 100644 (file)
@@ -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<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
index fad437724e55ae55b362ac4d1df4f347a11c228f..3e74b801dbc2ccd5d912e26bd549dc08b17082c2 100644 (file)
@@ -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 {
 
index bc0f469bf24008259dc8a8716539f99e7adad8d6..93550577eff575e81eaafd4e15d554b430fc95bb 100644 (file)
@@ -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))));
index 757accaeab8be19051d806f8d382022728194aed..2fd3a21037b31e8e4a8ebf7accb633b7e6894667 100644 (file)
@@ -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();
index caee6bcab7c92385825c3451babce11264beafee..5799b65f77a55ff9b9fe7210f405dc2c7a6fbb9e 100644 (file)
@@ -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; }
        ///