GuiDocument.cpp: allow to use percent lengths for the paragraph skip separation; file format change

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30696 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Uwe Stöhr 2009-07-19 22:08:58 +00:00
parent d7e6c2a539
commit 6b970c0339
4 changed files with 56 additions and 13 deletions

View File

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

View File

@ -184,39 +184,39 @@ def latex_length(string):
percent = True
value = string[:i]
value = str(float(value)/100)
return value + "\\textwidth"
return "True," + value + "\\textwidth"
i = string.find("col%")
if i > -1:
percent = True
value = string[:i]
value = str(float(value)/100)
return value + "\\columnwidth"
return "True," + value + "\\columnwidth"
i = string.find("page%")
if i > -1:
percent = True
value = string[:i]
value = str(float(value)/100)
return value + "\\paperwidth"
return "True," + value + "\\paperwidth"
i = string.find("line%")
if i > -1:
percent = True
value = string[:i]
value = str(float(value)/100)
return value + "\\linewidth"
return "True," + value + "\\linewidth"
i = string.find("theight%")
if i > -1:
percent = True
value = string[:i]
value = str(float(value)/100)
return value + "\\textheight"
return "True," + value + "\\textheight"
i = string.find("pheight%")
if i > -1:
percent = True
value = string[:i]
value = str(float(value)/100)
return value + "\\paperheight"
return "True," + value + "\\paperheight"
if percent == False:
return string
return "False," + string
####################################################################
@ -808,6 +808,7 @@ def revert_paragraph_indentation(document):
" Revert custom paragraph indentation to preamble code "
i = 0
j = 0
k = 0
while True:
i = find_token(document.header, "\\paragraph_indentation", i)
if i == -1:
@ -823,13 +824,51 @@ def revert_paragraph_indentation(document):
j = document.header[i].find(" ")
length = document.header[i][j+1:]
# handle percent lengths
length = latex_length(length)
length = latex_length(length)
# latex_length returns "bool,length"
k = length.find(",")
length = length[k+1:]
add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
add_to_preamble(document, ["\\setlength{\\parindent}{" + length + "}"])
del document.header[i]
i = i + 1
def revert_percent_skip_lengths(document):
" Revert relative lengths for paragraph skip separation to preamble code "
i = 0
j = 0
k = 0
l = 0
while True:
i = find_token(document.header, "\\defskip", i)
if i == -1:
break
# only revert when a custom length was set and when
# it used a percent length
j = document.header[i].find("smallskip")
k = document.header[i].find("medskip")
l = document.header[i].find("bigskip")
if (j > -1) or (k > -1) or (l > -1):
break
else:
# search for the beginning of the value via the space
j = document.header[i].find(" ")
length = document.header[i][j+1:]
# handle percent lengths
length = latex_length(length)
# latex_length returns "bool,length"
l = length.find(",")
percent = length[:l]
length = length[l+1:]
if percent == "True":
add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
add_to_preamble(document, ["\\setlength{\\parskip}{" + length + "}"])
# set defskip to medskip as default
document.header[i] = "\\defskip medskip"
i = i + 1
##
# Conversion hub
#
@ -854,10 +893,12 @@ convert = [[346, []],
[362, []],
[363, []],
[364, []],
[365, []]
[365, []],
[366, []]
]
revert = [[364, [revert_paragraph_indentation]],
revert = [[365, [revert_percent_skip_lengths]],
[364, [revert_paragraph_indentation]],
[363, [revert_branch_filename]],
[362, [revert_longtable_align]],
[361, [revert_applemac]],

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

View File

@ -613,8 +613,6 @@ GuiDocument::GuiDocument(GuiView & lv)
textLayoutModule->skipCO->addItem(qt_("MedSkip"));
textLayoutModule->skipCO->addItem(qt_("BigSkip"));
textLayoutModule->skipCO->addItem(qt_("Length"));
// remove the %-items from the unit choice
textLayoutModule->skipLengthCO->noPercents();
textLayoutModule->lspacingCO->insertItem(
Spacing::Single, qt_("Single"));
textLayoutModule->lspacingCO->insertItem(