on the way to a usable insetenv

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6975 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-05-19 07:12:09 +00:00
parent a9d83a8583
commit ff98dcea08
15 changed files with 142 additions and 119 deletions

View File

@ -1,7 +1,24 @@
2003-05-19 André Pönitz <poenitz@gmx.net>
* buffer.C:
* lyxlayout.[Ch]:
* lyxtextclass.[Ch]:
* paragraph.C:
* paragraph_funcs.[Ch]:
* text2.C:
* text3.C: more insetenv work
2003-05-16 Alfredo Braunstein <abraunst@libero.it>
* ParagraphParameters.C (params2string): small bug fixed
2003-05-16 André Pönitz <poenitz@gmx.net>
* debug.C:
* bufferview_funcs.C: patch from Kornel Benko to prevent
crash when _(...) is called twice in a statement
2003-05-16 André Pönitz <poenitz@gmx.net>
* BufferView.C:

View File

@ -1046,7 +1046,7 @@ void Buffer::makeLaTeXFile(ostream & os,
texrow.newline();
}
latexParagraphs(this, paragraphs, paragraphs.begin(), paragraphs.end(), os, texrow);
latexParagraphs(this, paragraphs, os, texrow, false);
// add this just in case after all the paragraphs
os << endl;

View File

@ -1,11 +1,16 @@
2003-05-16 André Pönitz <poenitz@gmx.net>
2003-05-19 André Pönitz <poenitz@gmx.net>
* insetenv.[Ch]:
* insettext.C: more insetenv
2003-05-16 André Pönitz <poenitz@gmx.net>
* insetcommand.C:
* insetminimpage.[Ch]:
* insetcollapsable.[Ch]: fix #832
2003-05-16 André Pönitz <poenitz@gmx.net>
2003-05-16 André Pönitz <poenitz@gmx.net>
* inset.[Ch]:
* insetbibitem.[Ch]:
@ -31,7 +36,7 @@
* inseturl.[Ch]:
* updatableinset.[Ch]: edit() -> LFUN_INSET_EDIT
2003-05-13 André Pönitz <poenitz@gmx.net>
2003-05-13 André Pönitz <poenitz@gmx.net>
* insetbibitem.C:
* insetcollapsable.C:
@ -53,7 +58,7 @@
* insetwrap.C: STRCONV
2003-05-12 André Pönitz <poenitz@gmx.net>
2003-05-12 André Pönitz <poenitz@gmx.net>
* insetcaption.C:
* insetexternal.C:
@ -67,7 +72,7 @@
* insettext.C:
* insetwwrap.C: boost::format -> bformat all over the place
2003-05-05 André Pönitz <poenitz@gmx.net>
2003-05-05 André Pönitz <poenitz@gmx.net>
* insettext.h: add missing #include <map>
@ -92,7 +97,7 @@
* insetfloat.h:
* insetfloat.C: remove unneeded type() function
2003-05-05 André Pönitz <poenitz@gmx.net>
2003-05-05 André Pönitz <poenitz@gmx.net>
* inset.h:
* insettext.[Ch]:
@ -113,7 +118,7 @@
hideInsetCursor(), toggleInsetCursor(), isCursorVisible(). Add
getCursor(). Remove explicit cursor hides.
2003-05-02 André Pönitz <poenitz@gmx.net>
2003-05-02 André Pönitz <poenitz@gmx.net>
* insettext.C: remove unneeded &*
@ -129,11 +134,11 @@
(setFont): ditto
(tabularFeatures): ditto
2003-04-29 André Pönitz <poenitz@gmx.net>
2003-04-29 André Pönitz <poenitz@gmx.net>
* inset.h: introduce "haveParagraph" from Lars' parlist-14-b.
2003-04-28 André Pönitz <poenitz@gmx.net>
2003-04-28 André Pönitz <poenitz@gmx.net>
* insettext.[Ch]: part of Lars' Paragraph * -> ParagraphList::iterator
Changes
@ -155,7 +160,7 @@
* insettabular.C (string2params): ditto
* insetwrap.C (string2params): ditto
2003-04-24 André Pönitz <poenitz@gmx.net>
2003-04-24 André Pönitz <poenitz@gmx.net>
* insetref.C: support for eqref
@ -409,7 +414,7 @@
* insettext.C (edit): replace Dialogs::updateParagraph with
BufferView::dispatch(LFUN_PARAGRAPH_UPDATE).
2003-03-13 André Pönitz <poenitz@gmx.net>
2003-03-13 André Pönitz <poenitz@gmx.net>
* Makefile.am: insert insetenv
@ -439,7 +444,7 @@
* insettext.C: name change to readToken()
2003-03-11 André Pönitz <poenitz@gmx.net>
2003-03-11 André Pönitz <poenitz@gmx.net>
* Makefile.am: insert insethfill
@ -754,7 +759,7 @@
* insetinclude.C (loadIfNeeded): ensure loading also works when
child document is under version control.
2003-02-17 André Pönitz <poenitz@gmx.net>
2003-02-17 André Pönitz <poenitz@gmx.net>
* insetbib.[Ch]: Adjust access to bibkeys
@ -955,7 +960,7 @@
* insetcite.C (getNatbibLabel): correct logic of when and when not to
reload the BibTeX keys.
2002-10-11 André Pönitz <poenitz@gmx.net>
2002-10-11 André Pönitz <poenitz@gmx.net>
* insettext.h: handle LFUN_PRIOR/NEXT

View File

@ -14,6 +14,7 @@
#include "insetenv.h"
#include "gettext.h"
#include "lyxtextclass.h"
#include "paragraph_funcs.h"
#include "lyxlayout.h"
#include "bufferparams.h"
#include "support/LOstream.h"
@ -26,24 +27,16 @@ using std::endl;
InsetEnvironment::InsetEnvironment
(BufferParams const & bp, string const & name)
: InsetText(bp)
: InsetText(bp), layout_(bp.getLyXTextClass()[name])
{
//setLabel(name);
setInsetName(name);
autoBreakRows = true;
drawFrame_ = ALWAYS;
// needs more stuff in lyxlayout. coming in later patches.
//LyXTextClass const & tc = bp.getLyXTextClass();
//LyXLayout_ptr const & layout = tc.getEnv(name);
//header_ = layout->latexheader;
//footer_ = layout->latexfooter;
header_ = "\\begin{" + name + "}";
footer_ = "\\end{" + name + "}";
}
InsetEnvironment::InsetEnvironment(InsetEnvironment const & in, bool same_id)
: InsetText(in, same_id), header_(in.header_), footer_(in.footer_)
: InsetText(in, same_id), layout_(in.layout_)
{}
@ -73,10 +66,18 @@ string const InsetEnvironment::editMessage() const
int InsetEnvironment::latex(Buffer const * buf,
ostream & os, bool fragile, bool fp) const
ostream & os, bool fragile, bool) const
{
os << header_;
int i = InsetText::latex(buf, os, fragile, fp);
os << footer_;
return i;
os << layout_->latexheader;
TexRow texrow;
latexParagraphs(buf, paragraphs, os, texrow, fragile,
layout_->latexparagraph);
os << layout_->latexfooter;
return texrow.rows();
}
LyXLayout_ptr const & InsetEnvironment::layout() const
{
return layout_;
}

View File

@ -13,6 +13,7 @@
#define INSETENVIRONMENT_H
#include "insettext.h"
#include "lyxlayout_ptr_fwd.h"
class InsetEnvironment : public InsetText {
public:
@ -37,6 +38,8 @@ public:
///
bool isTextInset() const { return true; }
///
LyXLayout_ptr const & layout() const;
///
bool needFullRow() const { return true; }
/** returns true if, when outputing LaTeX, font changes should
be closed before generating this inset. This is needed for
@ -44,10 +47,8 @@ public:
bool noFontChange() const { return true; }
private:
/// LaTeX footer
string header_;
/// LaTeX footer
string footer_;
/// the layout
LyXLayout_ptr layout_;
};
#endif

View File

@ -1467,13 +1467,10 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & cmd)
}
int InsetText::latex(Buffer const * buf, ostream & os,
bool moving_arg, bool) const
int InsetText::latex(Buffer const * buf, ostream & os, bool fragile, bool) const
{
TexRow texrow;
latexParagraphs(buf, paragraphs,
paragraphs.begin(), paragraphs.end(),
os, texrow, moving_arg);
latexParagraphs(buf, paragraphs, os, texrow, fragile);
return texrow.rows();
}

View File

@ -59,6 +59,7 @@ enum LayoutTags {
LT_LATEXTYPE,
LT_LATEXHEADER,
LT_LATEXFOOTER,
LT_LATEXPARAGRAPH,
LT_LEFTMARGIN,
LT_NEED_PROTECT,
LT_NEWLINE,
@ -107,6 +108,7 @@ LyXLayout::LyXLayout ()
newline_allowed = true;
free_spacing = false;
pass_thru = false;
is_environment = false;
}
@ -140,6 +142,7 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
{ "latexfooter", LT_LATEXFOOTER },
{ "latexheader", LT_LATEXHEADER },
{ "latexname", LT_LATEXNAME },
{ "latexparagraph", LT_LATEXPARAGRAPH },
{ "latexparam", LT_LATEXPARAM },
{ "latextype", LT_LATEXTYPE },
{ "leftmargin", LT_LEFTMARGIN },
@ -236,24 +239,29 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
}
break;
case LT_MARGIN: // Margin style definition.
case LT_MARGIN: // margin style definition.
readMargin(lexrc);
break;
case LT_LATEXTYPE: // Latex style definition.
case LT_LATEXTYPE: // LaTeX style definition.
readLatexType(lexrc);
break;
case LT_LATEXHEADER: // Latex style definition.
case LT_LATEXHEADER: // header for environments
lexrc.next();
latexheader = lexrc.getString();
break;
case LT_LATEXFOOTER: // Latex style definition.
case LT_LATEXFOOTER: // footer for environments
lexrc.next();
latexfooter = lexrc.getString();
break;
case LT_LATEXPARAGRAPH:
lexrc.next();
latexparagraph = lexrc.getString();
break;
case LT_INTITLE:
intitle = lexrc.next() && lexrc.getInteger();
break;

View File

@ -136,10 +136,14 @@ public:
bool free_spacing;
///
bool pass_thru;
///
bool is_environment;
/// for new environment insets
string latexheader;
/// for new environment insets
string latexfooter;
/// for new environment insets
string latexparagraph;
/** true when the fragile commands in the paragraph need to be
\protect'ed. */

View File

@ -215,6 +215,7 @@ bool LyXTextClass::Read(string const & filename, bool merge)
}
break;
case TC_ENVIRONMENT:
case TC_STYLE:
if (lexrc.next()) {
string const name = subst(lexrc.getString(),
@ -225,6 +226,8 @@ bool LyXTextClass::Read(string const & filename, bool merge)
} else {
LyXLayout lay;
lay.setName(name);
if (le == TC_ENVIRONMENT)
lay.is_environment = true;
if (!(error = do_readStyle(lexrc, lay)))
layoutlist_.push_back
(boost::shared_ptr<LyXLayout>(new LyXLayout(lay)));
@ -243,29 +246,6 @@ bool LyXTextClass::Read(string const & filename, bool merge)
}
break;
case TC_ENVIRONMENT:
if (lexrc.next()) {
string const name = subst(lexrc.getString(),
'_', ' ');
if (hasLayout(name)) {
LyXLayout * lay = operator[](name).get();
error = do_readStyle(lexrc, *lay);
} else {
LyXLayout lay;
lay.setName(name);
if (!(error = do_readStyle(lexrc, lay)))
envlist_.push_back
(boost::shared_ptr<LyXLayout>(new LyXLayout(lay)));
else
lexrc.printError("Problems reading environment: `$$Token'.");
}
}
else {
lexrc.printError("No name given for style: `$$Token'.");
error = true;
}
break;
case TC_NOSTYLE:
if (lexrc.next()) {
string const style = subst(lexrc.getString(),
@ -772,6 +752,7 @@ bool LyXTextClass::hasLayout(string const & n) const
}
LyXLayout_ptr const & LyXTextClass::operator[](string const & n) const
{
lyx::Assert(!n.empty());
@ -796,6 +777,9 @@ LyXLayout_ptr const & LyXTextClass::operator[](string const & n) const
lyxerr << "We failed to find the layout '" << name
<< "' in the layout list. You MUST investigate!"
<< endl;
for (LayoutList::const_iterator it = layoutlist_.begin();
it != layoutlist_.end(); ++it)
lyxerr << " " << it->get()->name() << endl;
// we require the name to exist
lyx::Assert(false);
@ -808,27 +792,6 @@ LyXLayout_ptr const & LyXTextClass::operator[](string const & n) const
}
LyXLayout_ptr const & LyXTextClass::getEnv(string const & name) const
{
lyx::Assert(!name.empty());
if (name.empty())
lyxerr << "LyXTextClass::getEnv() called with empty n" << endl;
LayoutList::const_iterator cit =
find_if(envlist_.begin(), envlist_.end(), compare_name(name));
if (cit == envlist_.end()) {
lyxerr << "We failed to find the environment '" << name
<< "' in the layout list. You MUST investigate!"
<< endl;
// we require the name to exist
lyx::Assert(false);
}
return *cit;
}
bool LyXTextClass::delete_layout(string const & name)
{

View File

@ -65,8 +65,6 @@ public:
///
LyXLayout_ptr const & operator[](string const & vname) const;
///
LyXLayout_ptr const & getEnv(string const & vname) const;
/// Sees to that the textclass structure has been loaded
bool load() const;
@ -155,8 +153,6 @@ private:
///
bool delete_layout(string const &);
///
bool delete_env(string const &);
///
bool do_readStyle(LyXLex &, LyXLayout &);
/// Layout file name
string name_;
@ -210,9 +206,6 @@ private:
/// Paragraph styles used in this layout
LayoutList layoutlist_;
/// Environment styles used in this layout
LayoutList envlist_;
/// available types of float, eg. figure, algorithm.
boost::shared_ptr<FloatList> floatlist_;

View File

@ -29,6 +29,7 @@
#include "insets/insetbibitem.h"
#include "insets/insetoptarg.h"
#include "insets/insetenv.h"
#include "support/filetools.h"
#include "support/lstrings.h"
@ -1405,6 +1406,9 @@ int Paragraph::id() const
LyXLayout_ptr const & Paragraph::layout() const
{
Inset * inset = inInset();
if (inset && inset->lyxCode() == Inset::ENVIRONMENT_CODE)
return static_cast<InsetEnvironment*>(inset)->layout();
return layout_;
}

View File

@ -237,8 +237,7 @@ bool isFirstInSequence(ParagraphList::iterator pit,
}
int getEndLabel(ParagraphList::iterator p,
ParagraphList const & plist)
int getEndLabel(ParagraphList::iterator p, ParagraphList const & plist)
{
ParagraphList::iterator pit = p;
Paragraph::depth_type par_depth = p->getDepth();
@ -280,7 +279,8 @@ TeXOnePar(Buffer const * buf,
ParagraphList const & paragraphs,
ParagraphList::iterator pit,
ostream & os, TexRow & texrow,
bool moving_arg);
bool moving_arg,
string const & everypar = string());
ParagraphList::iterator
@ -436,9 +436,11 @@ TeXOnePar(Buffer const * buf,
ParagraphList const & paragraphs,
ParagraphList::iterator pit,
ostream & os, TexRow & texrow,
bool moving_arg)
bool moving_arg,
string const & everypar)
{
lyxerr[Debug::LATEX] << "TeXOnePar... " << &*pit << endl;
lyxerr[Debug::LATEX] << "TeXOnePar... " << &*pit << " '" << everypar
<< "'" << endl;
BufferParams const & bparams = buf->params;
Inset const * in = pit->inInset();
@ -559,6 +561,7 @@ TeXOnePar(Buffer const * buf,
break;
}
os << everypar;
bool need_par = pit->simpleTeXOnePar(buf, bparams,
outerFont(pit, paragraphs),
os, texrow, moving_arg);
@ -682,15 +685,16 @@ TeXOnePar(Buffer const * buf,
//
void latexParagraphs(Buffer const * buf,
ParagraphList const & paragraphs,
ParagraphList::iterator par,
ParagraphList::iterator endpar,
ostream & ofs,
ostream & os,
TexRow & texrow,
bool moving_arg)
bool moving_arg,
string const & everypar)
{
bool was_title = false;
bool already_title = false;
LyXTextClass const & tclass = buf->params.getLyXTextClass();
ParagraphList::iterator par = paragraphs.begin();
ParagraphList::iterator endpar = paragraphs.end();
// if only_body
while (par != endpar) {
@ -710,7 +714,7 @@ void latexParagraphs(Buffer const * buf,
} else if (!was_title) {
was_title = true;
if (tclass.titletype() == TITLE_ENVIRONMENT) {
ofs << "\\begin{"
os << "\\begin{"
<< tclass.titlename()
<< "}\n";
texrow.newline();
@ -718,11 +722,11 @@ void latexParagraphs(Buffer const * buf,
}
} else if (was_title && !already_title) {
if (tclass.titletype() == TITLE_ENVIRONMENT) {
ofs << "\\end{" << tclass.titlename()
os << "\\end{" << tclass.titlename()
<< "}\n";
}
else {
ofs << "\\" << tclass.titlename()
os << "\\" << tclass.titlename()
<< "\n";
}
texrow.newline();
@ -730,25 +734,30 @@ void latexParagraphs(Buffer const * buf,
was_title = false;
}
if (layout->isEnvironment() ||
if (layout->is_environment) {
par = TeXOnePar(buf, paragraphs, par, os, texrow,
moving_arg, everypar);
} else if (layout->isEnvironment() ||
!par->params().leftIndent().zero())
{
par = TeXEnvironment(buf, paragraphs, par, ofs, texrow);
par = TeXEnvironment(buf, paragraphs, par, os, texrow);
} else {
par = TeXOnePar(buf, paragraphs, par, ofs, texrow, moving_arg);
par = TeXOnePar(buf, paragraphs, par, os, texrow,
moving_arg, everypar);
}
} else {
par = TeXOnePar(buf, paragraphs, par, ofs, texrow, moving_arg);
par = TeXOnePar(buf, paragraphs, par, os, texrow,
moving_arg, everypar);
}
}
// It might be that we only have a title in this document
if (was_title && !already_title) {
if (tclass.titletype() == TITLE_ENVIRONMENT) {
ofs << "\\end{" << tclass.titlename()
os << "\\end{" << tclass.titlename()
<< "}\n";
}
else {
ofs << "\\" << tclass.titlename()
os << "\\" << tclass.titlename()
<< "\n";
}
texrow.newline();

View File

@ -63,11 +63,10 @@ int getEndLabel(ParagraphList::iterator pit,
void latexParagraphs(Buffer const * buf,
ParagraphList const & paragraphs,
ParagraphList::iterator par,
ParagraphList::iterator endpar,
std::ostream & ofs,
TexRow & texrow,
bool moving_arg = false);
bool moving_arg,
string const & everypar = string());
/// read a paragraph from a .lyx file. Returns number of unrecognised tokens
int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex);

View File

@ -35,6 +35,7 @@
#include "paragraph_funcs.h"
#include "insets/insetbibitem.h"
#include "insets/insetenv.h"
#include "insets/insetfloat.h"
#include "insets/insetwrap.h"
@ -425,22 +426,41 @@ LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
// set layout over selection and make a total rebreak of those paragraphs
void LyXText::setLayout(string const & layout)
{
LyXCursor tmpcursor = cursor; /* store the current cursor */
LyXCursor tmpcursor = cursor; // store the current cursor
// if there is no selection just set the layout
// of the current paragraph */
// of the current paragraph
if (!selection.set()) {
selection.start = cursor; // dummy selection
selection.end = cursor;
}
// special handling of new environment insets
BufferParams const & params = bv()->buffer()->params;
LyXLayout_ptr const & lyxlayout = params.getLyXTextClass()[layout];
if (lyxlayout->is_environment) {
// move everything in a new environment inset
lyxerr << "setting layout " << layout << endl;
bv()->owner()->dispatch(FuncRequest(LFUN_HOME));
bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL));
bv()->owner()->dispatch(FuncRequest(LFUN_CUT));
Inset * inset = new InsetEnvironment(params, layout);
if (bv()->insertInset(inset)) {
//inset->edit(bv());
//bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
}
else
delete inset;
return;
}
ParagraphList::iterator endpit = setLayout(cursor, selection.start,
selection.end, layout);
redoParagraphs(selection.start, endpit);
// we have to reset the selection, because the
// geometry could have changed
setCursor(selection.start.par(),
selection.start.pos(), false);
setCursor(selection.start.par(), selection.start.pos(), false);
selection.cursor = cursor;
setCursor(selection.end.par(), selection.end.pos(), false);
updateCounters();

View File

@ -1124,6 +1124,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
}
bool change_layout = (current_layout != layout);
if (!change_layout && selection.set() &&
selection.start.par() != selection.end.par())
{
@ -1137,6 +1138,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
++spit;
}
}
if (change_layout) {
current_layout = layout;
update();