On Mon, Jul 28, 2003 at 10:13:00AM +0300, Martin Vermeer spake thusly: ... > > BTW, did you see my latest corrections on the document dialog/branches tab, > > which disables some buttons when the browsers are empty? > > http://www.mail-archive.com/[EMAIL PROTECTED]/msg59332.html > > Yes, those are the ones I have in my local copy (good work!). I > simplified FormDocument a little further after that still: replaced > all_branches_ etc. by a class instantiation branchlist_. Attached. > > Martin Another further improvement: the .lyx document format. I changed it to (e.g.):
\branch English \selection 0 \end_branch \branch German \selection 1 \end_branch \branch French \selection 1 \end_branch which you must admit looks cleaner than the '|'-separated strings! Also a \color line is already foreseen :-) The change to BranchList needed is the addition of begin() and end() methods. Changes attached. Martin
Index: BranchList.h =================================================================== RCS file: BranchList.h diff -N BranchList.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ BranchList.h 28 Jul 2003 08:02:01 -0000 @@ -0,0 +1,120 @@ +// -*- C++ -*- +/** + * \file BranchList.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * \author Martin Vermeer + * + * Full author contact details are available in file CREDITS + * + * + * \class Branch + * + * A class describing a 'branch', i.e., a named alternative for + * selectively outputting some parts of a document while suppressing + * other parts. + * + * A branch has a name, can either be selected or not, and uses a + * user-specifyable background colour. All these can be set and + * queried. + * + * \class BranchList + * + * A class containing a vector of all defined branches within a + * document. Has methods for selecting or deselecting branches by + * name, for outputting a '|'-separated string of all elements or only + * the selected ones, and for adding and removing elements. + */ + + +#ifndef BRANCHES_H +#define BRANCHES_H + +#include "LString.h" +#include <list> + +class Branch { +public: + /// + string getBranch() const; + /// + void setBranch(string const &); + /// + bool getSelected() const; + /// + void setSelected(bool); + /// + string getColor() const; + /// + void setColor(string const &); + + +private: + /// + string branch_; + /// + bool selected_; + /// + string color_; +}; + +namespace { + +class match { +public: + typedef Branch first_argument_type; + typedef string second_argument_type; + typedef bool result_type; + + bool operator()(Branch const & br, string const & s) const { + return (br.getBranch() == s); + } +}; + +} // namespace anon + +class BranchList { +public: + /// + BranchList() { separator_ = "|"; }; + + /// + typedef std::list<Branch> List; + + /// + void clear(); + /// + List::const_iterator begin() const { return list.begin(); }; + /// + List::const_iterator end() const { return list.end(); }; + /// + string getColor(string const &) const; + /// + void setColor(string const &, string const &); + /// Select/deselect multiple branches given in '|'-separated string + void setSelected(string const &, bool); + /// Add multiple branches to list + void add(string const &); + /// Assign color names to branches in order given + void setAllColors(string const &); + /// remove a branch from list by name + void remove(string const &); + /// return whether this branch is selected + bool selected(string const &) const; + /// return, as a '|'-separated string, all branch names + string allBranches() const; + /// + string allSelected() const; + /// + string allColors() const; + /// + string separator() const; + +private: + /// + List list; + /// + string separator_; +}; + +#endif Index: bufferparams.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/bufferparams.C,v retrieving revision 1.58 diff -u -p -r1.58 bufferparams.C --- bufferparams.C 26 Jul 2003 23:04:34 -0000 1.58 +++ bufferparams.C 28 Jul 2003 08:02:01 -0000 @@ -191,6 +191,25 @@ string const BufferParams::readToken(LyX } else if (token == "\\tracking_changes") { lex.nextToken(); tracking_changes = lex.getInteger(); + } else if (token == "\\branch") { + lex.nextToken(); + string branch = lex.getString(); + branchlist.add(branch); + while (true) { + lex.nextToken(); + string const tok = lex.getString(); + if (tok == "\\end_branch") + break; + if (tok == "\\selection") { + lex.nextToken(); + branchlist.setSelected(branch, lex.getInteger()); + } + // not yet operational + if (tok == "\\color") { + lex.nextToken(); + branchlist.setColor(branch, lex.getString()); + } + } } else if (token == "\\author") { lex.nextToken(); istringstream ss(STRCONV(lex.getString())); @@ -379,6 +398,16 @@ void BufferParams::writeFile(ostream & o << "\n\\use_numerical_citations " << use_numerical_citations << "\n\\paperorientation " << string_orientation[orientation] << '\n'; + + std::list<Branch>::const_iterator it = branchlist.begin(); + std::list<Branch>::const_iterator end = branchlist.end(); + for (; it != end; ++it) { + os << "\\branch " << it->getBranch() + << "\n\\selection " << it->getSelected() + << "\n\\end_branch" + << "\n"; + } + if (!paperwidth.empty()) os << "\\paperwidth " << VSpace(paperwidth).asLyXCommand() << '\n';
pgp00000.pgp
Description: PGP signature