This should work, shouldn't it? Why doesn't it? The conditional where the insets are created is entered as witnessed by the lyxerr.
The insets don't even show up on screen; yet they appear to save correctly using the write method. Also latex works, but not right. I have experimented by creating the inset as a standalone, in an arbitrary text location, using a minibuffer command; that works great. But now I want it tied to section etc. and make the label the section number. But that seems to be an entirely different thing. I use insetbib/bibkey as my model, but it appears not suitable. What am I missing? Martin
Index: text2.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/text2.C,v retrieving revision 1.243 diff -u -p -r1.243 text2.C --- text2.C 2002/08/07 16:31:45 1.243 +++ text2.C 2002/08/09 18:04:25 @@ -39,6 +39,7 @@ #include "insets/insetspecialchar.h" #include "insets/insettext.h" #include "insets/insetfloat.h" +#include "insets/insetshorttitle.h" #include "support/LAssert.h" #include "support/textutils.h" @@ -408,6 +409,8 @@ Inset * LyXText::getInset() const Inset * inset = 0; if (cursor.pos() == 0 && cursor.par()->bibkey) { inset = cursor.par()->bibkey; + } else if (cursor.pos()== 0 && cursor.par()->shorttitle) { + inset = cursor.par()->shorttitle; } else if (cursor.pos() < cursor.par()->size() && cursor.par()->isInset(cursor.pos())) { inset = cursor.par()->getInset(cursor.pos()); @@ -1313,7 +1319,13 @@ void LyXText::setCounter(Buffer const * s << par->counters().numberLabel(par->counters().sects[i], numbertype, langtype, head); - par->params().labelString(par->params().labelString() +s.str().c_str()); + if (!par->shorttitle) { + par->shorttitle = new InsetShortTitle(buf->params); + lyxerr << "par->shorttitle " << s.str() << endl; + par->shorttitle->setLabel(s.str()); + } + + // par->params().labelString(par->params().labelString() + +s.str().c_str()); // We really want to remove the c_str as soon as // possible...
// -*- C++ -*- /* This file is part of* * ====================================================== * * LyX, The Document Processor * * Copyright 1995 Matthias Ettrich * Copyright 1995-2001 The LyX Team * * ====================================================== */ #ifndef INSETSHORTTITLE_H #define INSETSHORTTITLE_H #ifdef __GNUG__ #pragma interface #endif #include "insettext.h" #include "insetcollapsable.h" class InsetShortTitle : public InsetCollapsable { public: InsetShortTitle(BufferParams const &); /// InsetShortTitle(InsetShortTitle const &, bool same_id = false); Inset * clone(Buffer const &, bool same_id = false) const; /// void draw(BufferView *, LyXFont const &, int, float &, bool) ; /// EDITABLE editable() const { return IS_EDITABLE; } /// Inset::Code lyxCode() const { return Inset::SHORTTITLE_CODE; } /// void edit(BufferView *, int, int, mouse_button::state); /// void edit(BufferView * bv, bool front = true); /// string const editMessage() const; /// int latex(Buffer const *, std::ostream &) const; /// void write(Buffer const * buf, ostream & os) const; /// //int ascii(Buffer const *, std::ostream &, int linelen) const; /// //int linuxdoc(Buffer const *, std::ostream &) const; /// //int docbook(Buffer const *, std::ostream &) const; }; #endif
/* This file is part of * ====================================================== * * LyX, The Document Processor * * Copyright 1995 Matthias Ettrich * Copyright 1995-2001 The LyX Team. * * ====================================================== */ #include <config.h> #ifdef __GNUG__ #pragma implementation #endif #include "insetshorttitle.h" #include "support/LOstream.h" #include "frontends/Alert.h" #include "support/lstrings.h" //frontStrip, strip #include "lyxtext.h" #include "buffer.h" #include "gettext.h" #include "BufferView.h" #include "support/lstrings.h" using std::ostream; using std::vector; using std::pair; /* Shorttitle. Used to insert a short version of sectioning header etc. * automatically */ InsetShortTitle::InsetShortTitle(BufferParams const & ins) : InsetCollapsable(ins, false) { } InsetShortTitle::InsetShortTitle(InsetShortTitle const & in, bool same_id) : InsetCollapsable(in, same_id) { } Inset * InsetShortTitle::clone(Buffer const &, bool same_id) const { return new InsetShortTitle(*this, same_id); } void InsetShortTitle::draw(BufferView * bv, LyXFont const & f, int baseline, float & x, bool cleared) { //InsetText::setDrawFrame(bv, ALWAYS); InsetCollapsable::draw(bv, f, baseline, x, cleared); } void InsetShortTitle::edit(BufferView * bv, int x, int y, mouse_button::state button) { InsetCollapsable::edit(bv, x, y, button); } void InsetShortTitle::edit(BufferView * bv, bool) { edit(bv, 0, 0, mouse_button::none); } string const InsetShortTitle::editMessage() const { return _("Opened Short Title Inset"); } void InsetShortTitle::write(Buffer const * buf, ostream & os) const { os << "\\begin_inset ShortTitle" << "\n"; InsetCollapsable::write(buf, os); os << "\\end_inset" << "\n"; } int InsetShortTitle::latex(Buffer const * buf, ostream & os) const { int i(0); if (!buf) { os << '['; i = inset.latex(buf, os, false, false); //InsetCollapsable::write(buf, os); os << ']'; } return i + 2; } /* Dunno what to do with these, if anything -- MV * int InsetShortTitle::ascii(Buffer const *, ostream & os, int) const { os << "<" << getContents() << ">"; return 0; } int InsetShortTitle::linuxdoc(Buffer const *, ostream & os) const { os << "<label id=\"" << getContents() << "\" >"; return 0; } int InsetShortTitle::docbook(Buffer const *, ostream & os) const { os << "<anchor id=\"" << getContents() << "\">"; return 0; } */
msg42333/pgp00000.pgp
Description: PGP signature