allow the usage of relative lengths in the HSpace and the VSpace dialog; file format change

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30710 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Uwe Stöhr 2009-07-20 11:22:51 +00:00
parent 57d6ceb90c
commit efd4f71fbd
5 changed files with 91 additions and 10 deletions

View File

@ -1,6 +1,10 @@
LyX file-format changes
-----------------------
2009-07-20 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 367: allow to use percent lengths for
vertical and horizontal spaces.
2009-07-20 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 366: allow to use percent lengths for the
paragraph skip separation.

View File

@ -93,7 +93,7 @@ def put_cmd_in_ert(string):
for rep in unicode_reps:
string = string.replace(rep[1], rep[0].replace('\\\\', '\\'))
string = string.replace('\\', "\\backslash\n")
string = "\\begin_inset ERT\nstatus collapsed\n\\begin_layout Standard\n" \
string = "\\begin_inset ERT\nstatus collapsed\n\\begin_layout Plain Layout\n" \
+ string + "\n\\end_layout\n\\end_inset"
return string
@ -864,6 +864,87 @@ def revert_percent_skip_lengths(document):
i = i + 1
def revert_percent_vspace_lengths(document):
" Revert relative VSpace lengths to ERT "
i = 0
while True:
i = find_token(document.body, "\\begin_inset VSpace", i)
if i == -1:
break
# only revert when a custom length was set and when
# it used a percent length
j = document.body[i].find("defskip")
k = document.body[i].find("smallskip")
l = document.body[i].find("medskip")
m = document.body[i].find("bigskip")
n = document.body[i].find("vfill")
if (j > -1) or (k > -1) or (l > -1) or (m > -1) or (n > -1):
break
else:
# search for the beginning of the value via the last space
o = document.body[i].rfind(" ")
length = document.body[i][o+1:]
# check if the space has a star (protected space)
p = document.body[i].rfind("*")
if p > -1:
length = length[:-1]
# handle percent lengths
length = latex_length(length)
# latex_length returns "bool,length"
q = length.find(",")
percent = length[:q]
length = length[q+1:]
# revert the VSpace inset to ERT
if percent == "True":
if p > -1:
subst = [put_cmd_in_ert("\\vspace*{" + length + "}")]
else:
subst = [put_cmd_in_ert("\\vspace{" + length + "}")]
document.body[i:i+2] = subst
i = i + 1
def revert_percent_hspace_lengths(document):
" Revert relative HSpace lengths to ERT "
i = 0
j = 0
while True:
i = find_token(document.body, "\\begin_inset space \hspace{}", i)
if i == -1:
j = find_token(document.body, "\\begin_inset space \hspace*{}", j)
if j == -1:
break
else:
star = True
i = j
else:
star = False
# only revert when a custom length was set and when
# it used a percent length
o = document.body[i+1].find("\\length")
if o == -1:
document.warning("Error: Cannot find lenght for \\hspace!")
break
# search for the beginning of the value via the space
k = document.body[i+1].find(" ")
length = document.body[i+1][k+1:]
# handle percent lengths
length = latex_length(length)
# latex_length returns "bool,length"
m = length.find(",")
percent = length[:m]
length = length[m+1:]
# revert the HSpace inset to ERT
if percent == "True":
if star == True:
subst = [put_cmd_in_ert("\\hspace*{" + length + "}")]
else:
subst = [put_cmd_in_ert("\\hspace{" + length + "}")]
document.body[i:i+3] = subst
i = i + 2
j = i
##
# Conversion hub
#
@ -889,10 +970,12 @@ convert = [[346, []],
[363, []],
[364, []],
[365, []],
[366, []]
[366, []],
[367, []]
]
revert = [[365, [revert_percent_skip_lengths]],
revert = [[366, [revert_percent_vspace_lengths, revert_percent_hspace_lengths]],
[365, [revert_percent_skip_lengths]],
[364, [revert_paragraph_indentation]],
[363, [revert_branch_filename]],
[362, [revert_longtable_align]],

View 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 = 366; // uwestoehr: percent lengths for the paragraph skip separation
int const LYX_FORMAT = 367; // uwestoehr: percent lengths for the VSpace dialog
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;

View File

@ -74,9 +74,6 @@ GuiHSpace::GuiHSpace(GuiView & lv, bool math)
// initialize the length validator
bc().addCheckedLineEdit(valueLE, valueL);
// remove the %-items from the unit choice
unitCO->noPercents();
}

View File

@ -75,9 +75,6 @@ GuiVSpace::GuiVSpace(GuiView & lv)
// initialize the length validator
bc().addCheckedLineEdit(valueLE, valueL);
// remove the %-items from the unit choice
unitCO->noPercents();
}