On Mon, Oct 01, 2007 at 01:21:12PM -0400, Richard Heck wrote: > Jürgen Spitzmüller wrote: > >John Levon wrote: > > > >>You remember that far back too :) > >> > >I do. And I'm pinning all my hope on Richard and Martin, so that this > >crucial feature will eventually become reality. I really hope this will > >make it into 1.6.0. > > > Document-internal layout is fairly easy to do now. Here's the recipe: > (i) Add the internal layout to BufferParams, mimicking what's there for > preamble; it'll need to be read and written > (\begin_layout...\end_layout?), for example, and don't forget the > "Format" line at the beginning; (ii) borrow the preamble bit from the > Document>Settings UI to get a simple UI for document internal > layout---you enter it as text; (iii) re-factor TextClass::read() so that > its successors can read from a file or a stream---so in particular it > can read the string from BufferParams; (iv) slightly modify > BufferParams::makeTextClass() so that it adds the document-internal > layout at the end (if such there is). There's a danger here, namely, > that the user enters layout that throws errors, but I think we handle > this properly. If not, that can be fixed. > > Ultimately, we'd prefer to have a better UI for editing the > document-internal layout. But that's a different issue, and having SOME > way of making document-internal layout is a start. > > Richard
Here's what I dragged up. Primitive, based on a charstyle implementation long gone. I now see that the "buffer charstyles" were entered in the minibuffer starting with an underscore character, like charstyle-insert _mystyle Ah well. It's a start. - Martin
Index: insets/insetcharstyle.C =================================================================== --- insets/insetcharstyle.C (revision 13327) +++ insets/insetcharstyle.C (working copy) @@ -48,7 +48,7 @@ setInsetName("CharStyle"); setInlined(); setDrawFrame(false); - has_label_ = true; + has_label_ = params_.latextype != "fontstyle"; } @@ -104,6 +104,7 @@ void InsetCharStyle::setDefined(CharStyles::iterator cs) { params_.latextype = cs->latextype; + has_label_ = params_.latextype != "fontstyle"; params_.latexname = cs->latexname; params_.latexparam = cs->latexparam; params_.font = cs->font; @@ -261,15 +262,26 @@ int InsetCharStyle::latex(Buffer const & buf, ostream & os, OutputParams const & runparams) const { - if (!undefined()) { - os << "\\" << params_.latexname; - if (!params_.latexparam.empty()) - os << params_.latexparam; - os << "{"; + int i = 0; + if (params_.latextype == "fontstyle") { + params_.font.latexWriteStartChanges(os, + LyXFont(LyXFont::ALL_SANE), + LyXFont(LyXFont::ALL_SANE)); + i = InsetText::latex(buf, os, runparams); + params_.font.latexWriteEndChanges(os, + LyXFont(LyXFont::ALL_SANE), + LyXFont(LyXFont::ALL_SANE)); + } else if (params_.latextype == "command") { + if (!undefined()) { + os << "\\" << params_.latexname; + if (!params_.latexparam.empty()) + os << params_.latexparam; + os << "{"; + } + i = InsetText::latex(buf, os, runparams); + if (!undefined()) + os << "}"; } - int i = InsetText::latex(buf, os, runparams); - if (!undefined()) - os << "}"; return i; } @@ -327,6 +339,8 @@ { // Force inclusion of preamble snippet in layout file features.require(params_.type); + if (params_.font.color() != LColor::none) + features.require("color"); InsetText::validate(features); } Index: factory.C =================================================================== --- factory.C (revision 13312) +++ factory.C (working copy) @@ -90,8 +90,28 @@ CharStyles::iterator found_cs = tclass.charstyle(s); if (found_cs != tclass.charstyles().end()) return new InsetCharStyle(params, found_cs); - else - return new InsetCharStyle(params, s); + else { + found_cs = params.charstyle(s); + if (found_cs != params.charstyles().end()) + return new InsetCharStyle(params, found_cs); + else if (s[0] == '_') { + // Insert here new buffer style into list... + InsetCharStyle * inset = + new InsetCharStyle(params, s); + CharStyle cs; + cs.name = s; + cs.latexname = s; + cs.latextype = "fontstyle"; + cs.font = bv->cursor().getFont(); + CharStyles & css = const_cast<CharStyles &>(params.charstyles()); + if (params.charstyle(cs.name) == css.end()) + css.push_back(cs); + //inset->setDefined(css.end() - 1); + inset->setDefined(params.charstyle(cs.name)); + return inset; + } else + return new InsetCharStyle(params, s); + } } case LFUN_INSERT_NOTE: { @@ -410,8 +430,15 @@ if (found_cs != tclass.charstyles().end()) inset.reset(new InsetCharStyle(buf.params(), found_cs)); else { + CharStyles::iterator found_cs + = buf.params().charstyle(s); + if (found_cs != buf.params().charstyles().end()) + inset.reset(new InsetCharStyle(buf.params(), found_cs)); + else { + // "Undefined" inset inset.reset(new InsetCharStyle(buf.params(), s)); + } } } else if (tmptok == "Branch") { inset.reset(new InsetBranch(buf.params(), Index: CutAndPaste.C =================================================================== --- CutAndPaste.C (revision 13339) +++ CutAndPaste.C (working copy) @@ -388,26 +389,28 @@ if (it->lyxCode() == InsetBase::CHARSTYLE_CODE) { InsetCharStyle & inset = static_cast<InsetCharStyle &>(*it); - string const name = inset.params().type; - CharStyles::iterator const found_cs = - tclass2.charstyle(name); - if (found_cs == tclass2.charstyles().end()) { - // The character style is undefined in tclass2 - inset.setUndefined(); - string const s = bformat(_( - "Character style %1$s is " - "undefined because of class " - "conversion from\n%2$s to %3$s"), - name, tclass1.name(), tclass2.name()); - // To warn the user that something had to be done. - errorlist.push_back(ErrorItem( - _("Undefined character style"), - s, it.paragraph().id(), - it.pos(), it.pos() + 1)); - } else if (inset.undefined()) { - // The character style is undefined in - // tclass1 and is defined in tclass2 - inset.setDefined(found_cs); + // Ignore per-document charstyles: + if (inset.params().latextype != "fontstyle") { + string const name = inset.params().type; + CharStyles::iterator const found_cs = tclass2.charstyle(name); + if (found_cs == tclass2.charstyles().end()) { + // The character style is undefined in tclass2 + inset.setUndefined(); + string const s = bformat(_( + "Character style %1$s is " + "undefined because of class " + "conversion from\n%2$s to %3$s"), + name, tclass1.name(), tclass2.name()); + // To warn the user that something had to be done. + errorlist.push_back(ErrorItem( + _("Undefined character style"), + s, it.paragraph().id(), + it.pos(), it.pos() + 1)); + } else if (inset.undefined()) { + // The character style is undefined in + // tclass1 and is defined in tclass2 + inset.setDefined(found_cs); + } } } } Index: bufferparams.C =================================================================== --- bufferparams.C (revision 13312) +++ bufferparams.C (working copy) @@ -245,6 +245,9 @@ AuthorList authorlist; BranchList branchlist; + /// CharStyles defined in this buffer + CharStyles charstyles; + boost::array<Bullet, 4> temp_bullets; boost::array<Bullet, 4> user_defined_bullets; Spacing spacing; @@ -344,6 +347,32 @@ } +CharStyles & BufferParams::charstyles() +{ + return pimpl_->charstyles; +} + + +CharStyles const & BufferParams::charstyles() const +{ + return pimpl_->charstyles; +} + + +CharStyles::iterator BufferParams::charstyle(string const & s) const +{ + CharStyles::iterator cs = + const_cast<CharStyles &>(charstyles()).begin(); + CharStyles::iterator csend = + const_cast<CharStyles &>(charstyles()).end(); + for (; cs != csend; ++cs) { + if (cs->name == s) + return cs; + } + return csend; +} + + Bullet & BufferParams::temp_bullet(lyx::size_type const index) { BOOST_ASSERT(index < 4); @@ -488,6 +517,15 @@ } } + } else if (token == "\\charstyle") { + lex.next(); + CharStyle cs; + cs.name = lex.getString(); + cs.latextype = "fontstyle"; + cs.latexname = cs.name; + cs.font.lyxRead(lex); + if (charstyle(cs.name) == charstyles().end()) + charstyles().push_back(cs); } else if (token == "\\author") { lex.eatLine(); istringstream ss(lex.getString()); @@ -605,7 +643,15 @@ << "\n\\end_branch" << "\n"; } - + CharStyles::const_iterator cit = charstyles().begin(); + CharStyles::const_iterator cend = charstyles().end(); + for (; cit != cend; ++cit) { + os << "\\charstyle " << cit->name; + // Output font info here + cit->font.lyxWriteChanges(LyXFont(LyXFont::ALL_SANE), os); + os << "\\endfont" + << "\n"; + } if (!paperwidth.empty()) os << "\\paperwidth " << VSpace(paperwidth).asLyXCommand() << '\n'; Index: text3.C =================================================================== --- text3.C (revision 13328) +++ text3.C (working copy) @@ -1665,8 +1665,7 @@ break; case LFUN_INSERT_CHARSTYLE: code = InsetBase::CHARSTYLE_CODE; - if (cur.buffer().params().getLyXTextClass().charstyles().empty()) - enable = false; + enable = true; break; case LFUN_INSERT_BOX: code = InsetBase::BOX_CODE; Index: bufferparams.h =================================================================== --- bufferparams.h (revision 13312) +++ bufferparams.h (working copy) @@ -161,6 +161,11 @@ /// BranchList: BranchList & branchlist(); BranchList const & branchlist() const; + /// CharStyles: + CharStyles & charstyles(); + CharStyles const & charstyles() const; + /// Retrieve element of name s: + CharStyles::iterator charstyle(std::string const & s) const; /// std::string inputenc; /// Index: lyxfont.C =================================================================== --- lyxfont.C (revision 13312) +++ lyxfont.C (working copy) @@ -628,7 +628,9 @@ bool finished = false; while (!finished && lex.isOK() && !error) { lex.next(); - string const tok = ascii_lowercase(lex.getString()); + string tok = ascii_lowercase(lex.getString()); + if (tok[0] == '\\') + tok = tok.substr(1); if (tok.empty()) { continue; Index: MenuBackend.C =================================================================== --- MenuBackend.C (revision 13312) +++ MenuBackend.C (working copy) @@ -601,6 +601,17 @@ FuncRequest(LFUN_INSERT_CHARSTYLE, cit->name)), view); } + tomenu.add(MenuItem(MenuItem::Separator)); + CharStyles & charstyles2 = view->buffer()->params().charstyles(); + cit = charstyles2.begin(); + end = charstyles2.end(); + for (; cit != end; ++cit) { + string const label = cit->name; + tomenu.add(MenuItem(MenuItem::Command, label, + FuncRequest(LFUN_INSERT_CHARSTYLE, + cit->name)), view); + } + }