]> git.lyx.org Git - lyx.git/blob - lib/scripts/prefs2prefs_lfuns.py
* layouttranslations.review - review of all langs.
[lyx.git] / lib / scripts / prefs2prefs_lfuns.py
1 # -*- coding: utf-8 -*-
2
3 # file prefs2prefs-lfuns.py
4 # This file is part of LyX, the document processor.
5 # Licence details can be found in the file COPYING.
6
7 # author Richard Heck
8
9 # Full author contact details are available in file CREDITS
10
11 # This file houses conversion information for the bind and ui files,
12 # i.e., for files where we are converting lfuns.
13
14 # The converter functions take a line as argument and return a list: 
15 #       (Bool, NewLine), 
16 # where the Bool says if  we've modified anything and the NewLine is 
17 # the new line, if so, which will be used to replace the old line.
18
19
20 import sys, re
21
22 ###########################################################
23 #
24 # Actual converter functions
25 #
26 # These accept a line as argument and should return a list:
27 #  (bool, newline)
28 # where the bool indicates whether we changed anything. If not,
29 # one normally returns: (False, []).
30
31 no_match = (False, [])
32
33 def simple_renaming(line, old, new):
34         if line.find(old) == -1:
35                 return no_match
36         line = line.replace(old, new)
37         return (True, line)
38
39
40 def next_inset_modify(line):
41         return simple_renaming(line, "next-inset-modify", "inset-modify")
42
43
44 def next_inset_toggle(line):
45         return simple_renaming(line, "next-inset-toggle", "inset-toggle")
46
47
48 def optional_insert(line):
49         return simple_renaming(line, "optional-insert", "argument-insert")
50
51
52 re_nm = re.compile(r'^(.*)notes-mutate\s+(\w+)\s+(\w+)(.*)$')
53 def notes_mutate(line):
54         m = re_nm.search(line)
55         if not m:
56                 return no_match
57
58         prefix = m.group(1)
59         source = m.group(2)
60         target = m.group(3)
61         suffix = m.group(4)
62         newline = prefix + "inset-forall Note:" + source + \
63                 " inset-modify note Note " + target + suffix
64         return (True, newline)
65
66
67 re_ait = re.compile(r'^(.*)all-insets-toggle\s+(\w+)(?:\s+(\w+))?(.*)$')
68 def all_insets_toggle(line):
69         m = re_ait.search(line)
70         if not m:
71                 return no_match
72
73         prefix = m.group(1)
74         action = m.group(2)
75         target = m.group(3) 
76         suffix = m.group(4)
77
78         # we need to transform the target to match the inset layout names
79         # this will not be perfect
80         if target == "ert":
81                 target = "ERT"
82         elif target == None:
83                 target = "*"
84         elif target == "tabular":
85                 # There does not seem to be an InsetLayout for tables, so
86                 # I do not know what to do here. If anyone does, then please
87                 # fix this. For now, we just have to remove this line.
88                 return (True, "")
89         else:
90                 target = target.capitalize()
91         
92         newline = prefix + "inset-forall " + target + " inset-toggle " + \
93                 action + suffix
94         return (True, newline)
95
96
97 re_li = re.compile(r'^(.*)\bline-insert\b(.*)$')
98 def line_insert(line):
99         m = re_li.search(line)
100         if not m: 
101                 return no_match
102         newline = m.group(1) + \
103                 "inset-insert line rule height 0.25ex width 100col% \\end_inset" + \
104                 m.group(2)
105         return (True, newline)
106
107
108 def toc_insert(line):
109         return simple_renaming(line, "toc-insert", "inset-insert toc")
110
111
112 re_ps = re.compile(r'^(.*)paragraph-spacing\s+(default|single|onehalf|double)\b(.*)$')
113 re_psother = re.compile(r'^(.*)paragraph-spacing\s+other\s+(\d+\.\d?|\d?\.\d+|\d+)(.*)$')
114 def paragraph_spacing(line):
115         # possible args: default, single, onehalf, double, other FLOAT
116         m = re_ps.search(line)
117         if m:
118                 arg = m.group(2)
119                 newline = m.group(1) + "paragraph-params \\paragraph-spacing " + arg + \
120                         m.group(3)
121                 return (True, newline)
122
123         m = re_psother.search(line)
124         if not m:
125                 return no_match
126
127         arg = m.group(2)
128         newline = m.group(1) + "paragraph-params \\paragraph-spacing other " + \
129                 arg + m.group(3)
130         return (True, newline)
131
132
133 def tabular_feature(line):
134         return simple_renaming(line, "tabular-feature", "inset-modify tabular")
135
136 re_Bar2bar = re.compile(r'^(\\(?:bind|unbind))\s+"([^"]*)Bar"(\s+"[^"]+")')
137 def Bar2bar(line):
138         m = re_Bar2bar.search(line)
139         if not m:
140                 return no_match
141
142         btype = m.group(1)
143         mod = m.group(2)
144         rest = m.group(3)
145         newline = btype + " \"" + mod + "bar\"" + rest
146         return (True, newline)
147
148 def paragraph_break(line):
149         return simple_renaming(line, "break-paragraph", "paragraph-break")
150
151 def tab_group_close(line):
152         return simple_renaming(line, "close-tab-group", "tab-group-close")
153
154 def view_split(line):
155         return simple_renaming(line, "split-view", "view-split")
156
157 def label_copy_as_reference(line):
158         return simple_renaming(line, "copy-label-as-reference", "label-copy-as-reference")
159
160 #
161 #
162 ###########################################################
163
164
165 # Conversion chain
166
167 conversions = [
168         [  1, [ # this will be a long list of conversions to format 1, LyX 2.0
169                 next_inset_toggle,
170                 next_inset_modify,
171                 optional_insert,
172                 notes_mutate,
173                 all_insets_toggle,
174                 line_insert,
175                 toc_insert,
176                 paragraph_spacing,
177                 tabular_feature,
178                 Bar2bar
179         ]],
180         [  2, [ # list of conversions to format 2, LyX 2.1
181                 paragraph_break,
182                 tab_group_close,
183                 view_split,
184                 label_copy_as_reference
185         ]],
186 ]
187