lib/lyx2lyx/lyx_1_5.py: fix revert of listings insets

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18262 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2007-05-11 02:28:14 +00:00
parent 486ca0c750
commit a8e9fe82d0
9 changed files with 56 additions and 16 deletions

View File

@ -1391,6 +1391,9 @@ lstinline[language=Delphi]{var i = 10;}
i = find_token(document.body, '\\begin_inset listings', i)
if i == -1:
break
else:
if not '\\usepackage{listings}' in document.preamble:
document.preamble.append('\\usepackage{listings}')
j = find_end_of_inset(document.body, i + 1)
if j == -1:
# this should not happen
@ -1410,31 +1413,41 @@ lstinline[language=Delphi]{var i = 10;}
k = line + 1
# looking for the oneline code for lstinline
for line in range(i + 2, j + 1):
if document.body[line].startswith(r'\begin_layout'):
inlinecode = document.body[line+1]
if document.body[line].startswith(r'\end_layout'):
inlinecode = document.body[line - 1]
break
if len(params) > 0:
params = '[%s]' % params
if inline == 'true':
document.body[i:(j+1)] = [r'\begin_inset ERT'
document.body[i:(j+1)] = [r'\begin_inset ERT',
'status %s' % status,
r'\begin_layout Standard',
'',
'',
r'\backslash',
'lstinline[%s]{%s}' % (params, inlinecode),
'lstinline%s{%s}' % (params, inlinecode),
r'\end_layout',
'',
r'\end_inset']
else:
document.body[i: k] = [r'\begin_inset ERT',
document.body[i: j+1] = [r'\begin_inset ERT',
'status %s' % status,
'',
r'\begin_layout Standard',
'',
'',
r'\backslash',
r'lstlisting[%s]{' % params,
r'begin{lstlisting}%s' % params,
r'\end_layout'
]
] + document.body[k : j - 1] + \
['',
r'\begin_layout Standard',
'',
r'\backslash',
'end{lstlisting}',
r'\end_layout',
'',
r'\end_inset']
def revert_include_listings(document):
@ -1464,6 +1477,9 @@ lstinputlisting{file}[opt]
i = find_token(document.body, r'\begin_inset Include \lstinputlisting', i)
if i == -1:
break
else:
if not '\\usepackage{listings}' in document.preamble:
document.preamble.append('\\usepackage{listings}')
j = find_end_of_inset(document.body, i + 1)
if j == -1:
# this should not happen

View File

@ -298,6 +298,7 @@ Color::Color()
{ graphicsbg, N_("graphics background"), "graphicsbg", "linen", "graphicsbg" },
{ mathmacrobg, N_("Math macro background"), "mathmacrobg", "linen", "mathmacrobg" },
{ mathframe, N_("math frame"), "mathframe", "Magenta", "mathframe" },
{ mathcorners, N_("math corners"), "mathcorners", "linen", "mathcorners" },
{ mathline, N_("math line"), "mathline", "Blue", "mathline" },
{ captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
{ collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },

View File

@ -123,8 +123,10 @@ public:
mathbg,
/// Macro math inset background color
mathmacrobg,
/// Math inset frame color
/// Math inset frame color under focus
mathframe,
/// Math inset frame color not under focus
mathcorners,
/// Math line color
mathline,

View File

@ -117,12 +117,12 @@ static TranslatorMap const build_translator()
/// pretty arbitrary dimensions
Inset::Inset()
: dim_(10, 10, 10), background_color_(Color::background)
: dim_(10, 10, 10), background_color_(Color::background), redraw_background_(true)
{}
Inset::Inset(Inset const & inset)
: dim_(inset.dim_), background_color_(inset.background_color_)
: dim_(inset.dim_), background_color_(inset.background_color_), redraw_background_(true)
{}
@ -288,7 +288,7 @@ void Inset::metricsMarkers2(Dimension & dim, int framesize) const
void Inset::drawMarkers(PainterInfo & pi, int x, int y) const
{
Color::color pen_color = editing(pi.base.bv)?
Color::mathframe : Color::background;
Color::mathframe : Color::mathcorners;
int const t = x + width() - 1;
int const d = y + descent();
@ -303,7 +303,7 @@ void Inset::drawMarkers(PainterInfo & pi, int x, int y) const
void Inset::drawMarkers2(PainterInfo & pi, int x, int y) const
{
Color::color pen_color = editing(pi.base.bv)?
Color::mathframe : Color::background;
Color::mathframe : Color::mathcorners;
drawMarkers(pi, x, y);
int const t = x + width() - 1;

View File

@ -192,6 +192,9 @@ public:
/// is called when the mouse enter or leave this inset
/// return true if this inset needs repaint
virtual bool setMouseHover(bool) { return false; }
/// tells an inset to redraw background
virtual void setRedrawBackground(bool rd) const { redraw_background_ = rd; }
bool redrawBackground() const { return redraw_background_; }
/// request "external features"
virtual void validate(LaTeXFeatures &) const {}
@ -489,6 +492,8 @@ private:
* of the header file.
*/
int background_color_;
mutable bool redraw_background_;
};

View File

@ -214,7 +214,7 @@ public:
void mathmlize(MathStream &) const;
///
//void octave(OctaveStream &) const;
/// tells an inset to redraw background
protected:
virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
///

View File

@ -48,6 +48,7 @@
#include "insets/RenderPreview.h"
#include "insets/InsetLabel.h"
#include "frontends/Painter.h"
#include "graphics/PreviewImage.h"
#include "graphics/PreviewLoader.h"
@ -169,7 +170,7 @@ InsetMathHull::InsetMathHull()
InsetMathHull::InsetMathHull(HullType type)
: InsetMathGrid(getCols(type), 1), type_(type), nonum_(1), label_(1),
: InsetMathGrid(getCols(type), 1), type_(type), nonum_(1), label_(1),
preview_(new RenderPreview(this))
{
initMath();
@ -179,7 +180,7 @@ InsetMathHull::InsetMathHull(HullType type)
InsetMathHull::InsetMathHull(InsetMathHull const & other)
: InsetMathGrid(other),
type_(other.type_), nonum_(other.nonum_), label_(other.label_),
type_(other.type_), nonum_(other.nonum_), label_(other.label_),
preview_(new RenderPreview(this))
{}
@ -333,7 +334,15 @@ bool InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
{
// setRedrawBackground(false);
use_preview_ = previewState(pi.base.bv);
/*Cursor & cur = pi.base.bv->cursor();
if (!editing(pi.base.bv) || !cur.selection() || &cur.inset() != this)
*/
lyxerr << "redraw " << x << " " << y << " " << width() << " " << redrawBackground() << std::endl;
if (redrawBackground())
pi.pain.fillRectangle(x + 1, y - ascent() + 1, width() - 2,
ascent() + descent() - 1, Color::mathbg);
if (use_preview_) {
// one pixel gap in front

View File

@ -15,6 +15,7 @@
#include "InsetMathGrid.h"
#include <boost/scoped_ptr.hpp>
#include "debug.h"
namespace lyx {
@ -120,7 +121,6 @@ public:
///
static int displayMargin() { return 12; }
protected:
InsetMathHull(InsetMathHull const &);
@ -183,6 +183,8 @@ private:
boost::scoped_ptr<RenderPreview> preview_;
///
mutable bool use_preview_;
///
/// mutable bool redraw_background_;
//
// Incorporate me
//

View File

@ -310,6 +310,8 @@ void MathData::draw(PainterInfo & pi, int x, int y) const
|| x >= bv. workWidth())
return;
for (size_t i = 0, n = size(); i != n; ++i) {
MathAtom const & at = operator[](i);
#if 0
@ -331,7 +333,10 @@ void MathData::draw(PainterInfo & pi, int x, int y) const
#endif
bv.coordCache().insets().add(at.nucleus(), x, y);
at->drawSelection(pi, x, y);
at->setRedrawBackground(false);
lyxerr << "selection draw " << x << " " << y << " " << at->redrawBackground() << std::endl;
at->draw(pi, x, y);
//at->setRedrawBackground(true);
x += at->width();
}
}