Add literal param to InsetInclude

This is used by lstinput

File format change.

Fixes: #10544.
This commit is contained in:
Juergen Spitzmueller 2018-02-23 08:58:16 +01:00
parent ed331bedd6
commit e0a5babde7
8 changed files with 397 additions and 267 deletions

View File

@ -7,6 +7,11 @@ changes happened in particular if possible. A good example would be
-----------------------
2018-02-23 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* format incremented to 545: Add "literal" param to inset include
This is used by the lstinput caption.
2017-06-06 Enrico Forestieri <forenr@lyx.org>
* Format incremented to 544: support for minted.
The listings inset now supports also the minted package.

View File

@ -1,6 +1,6 @@
# This file is part of lyx2lyx
# -*- coding: utf-8 -*-
# Copyright (C) 2002-2015 The LyX Team
# Copyright (C) 2002-2018 The LyX Team
# Copyright (C) 2002-2004 Dekel Tsur <dekel@lyx.org>
# Copyright (C) 2002-2006 José Matos <jamatos@lyx.org>
#
@ -92,8 +92,9 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)),
("1_6", list(range(277,346)), minor_versions("1.6" , 10)),
("2_0", list(range(346,414)), minor_versions("2.0" , 8)),
("2_1", list(range(414,475)), minor_versions("2.1" , 5)),
("2_2", list(range(475,509)), minor_versions("2.2" , 0)),
("2_3", (), minor_versions("2.3" , 0))
("2_2", list(range(475,509)), minor_versions("2.2" , 4)),
("2_3", list(range(509,545)), minor_versions("2.3" , 0)),
("2_4", (), minor_versions("2.4" , 0))
]
####################################################################

View File

@ -34,6 +34,7 @@ dist_lyx2lyx_PYTHON = \
lyx_2_1.py \
lyx_2_2.py \
lyx_2_3.py \
lyx_2_4.py \
profiling.py \
test_parser_tools.py

105
lib/lyx2lyx/lyx_2_4.py Normal file
View File

@ -0,0 +1,105 @@
# -*- coding: utf-8 -*-
# This file is part of lyx2lyx
# Copyright (C) 2018 The LyX team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" Convert files to the file format generated by lyx 2.4"""
import re, string
import unicodedata
import sys, os
# Uncomment only what you need to import, please.
from parser_tools import (find_end_of_inset, find_token)
# del_token, del_value, del_complete_lines,
# find_complete_lines, find_end_of, find_end_of_layout,
# find_re, find_substring, find_token_backwards,
# get_containing_inset, get_containing_layout, get_bool_value, get_value,
# get_quoted_value, is_in_inset, set_bool_value
# find_tokens, find_token_exact, check_token, get_option_value
#from lyx2lyx_tools import (add_to_preamble, put_cmd_in_ert, revert_font_attrs,
# insert_to_preamble, latex_length)
# get_ert, lyx2latex, lyx2verbatim, length_in_bp, convert_info_insets
# revert_flex_inset, hex2ratio, str2bool
####################################################################
# Private helper functions
###############################################################################
###
### Conversion and reversion routines
###
###############################################################################
def convert_lst_literalparam(document):
" Add param literal to include inset "
i = 0
while True:
i = find_token(document.body, '\\begin_inset CommandInset include', i)
if i == -1:
break
j = find_end_of_inset(document.body, i)
if j == -1:
document.warning("Malformed LyX document: Can't find end of command inset at line %d" % i)
i += 1
continue
while i < j and document.body[i].strip() != '':
i += 1
document.body.insert(i, "literal \"true\"")
def revert_lst_literalparam(document):
" Remove param literal from include inset "
i = 0
while True:
i = find_token(document.body, '\\begin_inset CommandInset include', i)
if i == -1:
break
j = find_end_of_inset(document.body, i)
if j == -1:
document.warning("Malformed LyX document: Can't find end of include inset at line %d" % i)
i += 1
continue
k = find_token(document.body, 'literal', i, j)
if k == -1:
i += 1
continue
del document.body[k]
##
# Conversion hub
#
supported_versions = ["2.4.0", "2.4"]
convert = [
[545, [convert_lst_literalparam]]
]
revert = [
[544, [revert_lst_literalparam]]
]
if __name__ == "__main__":
pass

View File

@ -64,6 +64,7 @@ GuiInclude::GuiInclude(GuiView & lv)
connect(previewCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
connect(captionLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
connect(labelLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
connect(literalCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
connect(listingsED, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
connect(listingsED, SIGNAL(textChanged()), this, SLOT(setListingsMsg()));
connect(bypassCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
@ -227,6 +228,7 @@ void GuiInclude::paramsToDialog(InsetCommandParams const & icp)
string extra = getStringFromVector(pars);
listingsED->setPlainText(toqstr(InsetListingsParams(extra).separatedParams()));
}
literalCB->setChecked(icp["literal"] == "true");
// Make sure that the bc is in the INITIAL state
if (bc().policy().buttonStatus(ButtonPolicy::OKAY))
@ -265,6 +267,8 @@ void GuiInclude::applyView()
else
params_.setCmdName("verbatiminput");
}
params_["literal"] = literalCB->isChecked()
? from_ascii("true") : from_ascii("false");
}

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>IncludeUi</class>
<widget class="QDialog" name="IncludeUi">
@ -5,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>371</width>
<height>374</height>
<width>363</width>
<height>470</height>
</rect>
</property>
<property name="windowTitle">
@ -15,247 +16,7 @@
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="3" column="0" colspan="6" >
<widget class="QGroupBox" name="listingsGB" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title" >
<string>Listing Parameters</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="3" column="1" >
<widget class="QTextEdit" name="listingsED" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2" >
<widget class="QCheckBox" name="bypassCB" >
<property name="toolTip" >
<string>Check it to enter parameters that are not recognizable by LyX</string>
</property>
<property name="text" >
<string>&amp;Bypass validation</string>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QLineEdit" name="captionLE" >
<property name="minimumSize" >
<size>
<width>150</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="captionLabel" >
<property name="text" >
<string>C&amp;aption:</string>
</property>
<property name="buddy" >
<cstring>captionLE</cstring>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QLineEdit" name="labelLE" />
</item>
<item row="1" column="0" >
<widget class="QLabel" name="labelLabel" >
<property name="text" >
<string>La&amp;bel:</string>
</property>
<property name="buddy" >
<cstring>labelLE</cstring>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2" >
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Mo&amp;re parameters</string>
</property>
<property name="buddy" >
<cstring>listingsED</cstring>
</property>
</widget>
</item>
<item row="3" column="0" >
<widget class="QTextBrowser" name="listingsTB" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>120</width>
<height>16777215</height>
</size>
</property>
<property name="cursor" >
<cursor>0</cursor>
</property>
<property name="focusPolicy" >
<enum>Qt::NoFocus</enum>
</property>
<property name="acceptDrops" >
<bool>true</bool>
</property>
<property name="frameShape" >
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow" >
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth" >
<number>0</number>
</property>
<property name="acceptRichText" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0" colspan="6" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QCheckBox" name="visiblespaceCB" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Underline spaces in generated output</string>
</property>
<property name="text" >
<string>&amp;Mark spaces in output</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="previewCB" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Show LaTeX preview</string>
</property>
<property name="text" >
<string>&amp;Show preview</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0" colspan="6" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB" >
<property name="text" >
<string>&amp;OK</string>
</property>
<property name="default" >
<bool>true</bool>
</property>
<property name="autoDefault" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closePB" >
<property name="text" >
<string>&amp;Close</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="filenameLA">
<property name="toolTip">
@ -269,13 +30,23 @@
</property>
</widget>
</item>
<item row="0" column="1" colspan="4" >
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="filenameED">
<property name="toolTip">
<string>File name to include</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QPushButton" name="browsePB">
<property name="toolTip">
<string>Select a file</string>
</property>
<property name="text">
<string>&amp;Browse...</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="TextLabel1">
<property name="text">
@ -318,7 +89,7 @@
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0">
<size>
<width>28</width>
<height>28</height>
@ -326,17 +97,7 @@
</property>
</spacer>
</item>
<item row="0" column="5" >
<widget class="QPushButton" name="browsePB" >
<property name="toolTip" >
<string>Select a file</string>
</property>
<property name="text" >
<string>&amp;Browse...</string>
</property>
</widget>
</item>
<item row="1" column="5" >
<item row="1" column="4">
<widget class="QPushButton" name="editPB">
<property name="toolTip">
<string>Edit the file</string>
@ -346,6 +107,259 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="5">
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="visiblespaceCB">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Underline spaces in generated output</string>
</property>
<property name="text">
<string>&amp;Mark spaces in output</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="previewCB">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Show LaTeX preview</string>
</property>
<property name="text">
<string>&amp;Show preview</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0" colspan="5">
<widget class="QGroupBox" name="listingsGB">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Listing Parameters</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QLineEdit" name="labelLE"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelLabel">
<property name="text">
<string>&amp;Label:</string>
</property>
<property name="buddy">
<cstring>labelLE</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QTextEdit" name="listingsED">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QTextBrowser" name="listingsTB">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>120</width>
<height>16777215</height>
</size>
</property>
<property name="cursor" stdset="0">
<cursorShape>ArrowCursor</cursorShape>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="acceptRichText">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="captionLabel">
<property name="text">
<string>&amp;Caption:</string>
</property>
<property name="buddy">
<cstring>captionLE</cstring>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="captionLE">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="bypassCB">
<property name="toolTip">
<string>Check it to enter parameters that are not recognizable by LyX</string>
</property>
<property name="text">
<string>&amp;Bypass validation</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>&amp;More parameters</string>
</property>
<property name="buddy">
<cstring>listingsED</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="literalCB">
<property name="toolTip">
<string>Pass content of the `Caption' field literally to LaTeX. Check this if you want to enter LaTeX code.</string>
</property>
<property name="text">
<string>Li&amp;teral</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="4" column="0" colspan="3">
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB">
<property name="text">
<string>&amp;OK</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closePB">
<property name="text">
<string>&amp;Close</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<tabstops>

View File

@ -224,6 +224,7 @@ ParamInfo const & InsetInclude::findInfo(string const & /* cmdName */)
if (param_info_.empty()) {
param_info_.add("filename", ParamInfo::LATEX_REQUIRED);
param_info_.add("lstparams", ParamInfo::LATEX_OPTIONAL);
param_info_.add("literal", ParamInfo::LYX_INTERNAL);
}
return param_info_;
}
@ -631,9 +632,8 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
language = opts[i].substr(9);
opts.erase(opts.begin() + i--);
} else if (prefixIs(opts[i], from_ascii("caption="))) {
// FIXME We should use HANDLING_LATEXIFY here,
// but that's a file format change (see #10455).
caption = opts[i].substr(8);
caption = params().prepareCommand(runparams, opts[i].substr(8),
ParamInfo::HANDLING_LATEXIFY);
opts.erase(opts.begin() + i--);
if (!use_minted)
latexed_opts.push_back(from_ascii("caption=") + caption);

View File

@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
#define LYX_FORMAT_LYX 544 // ef: minted support
#define LYX_FORMAT_TEX2LYX 544
#define LYX_FORMAT_LYX 545 // spitz: literal for include
#define LYX_FORMAT_TEX2LYX 545
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
#ifndef _MSC_VER