Jean-Marc Lasgouttes schrieb:
http://bugzilla.lyx.org/show_bug.cgi?id=3764

I do not like this patch very much, actually %-| The name AuthorActive
is ugly, the class definition in Author.h is weird (but better IMO
than including <map> everywhere).
Jean-Marc,

I think I found a smarter solution that produces less clutter. Please see the attached patch. What do you think?

I wasted almost the complete evening on const-vs-nonconst issues - now I know why Java doesn't have it :-( Please feel free to fine-tune the patch as you like.

BTW: This patch (as well as yours) is not that bad after all. Actually, it turns out that the number of authors does NOT increase with each load-save cycle. I did not realize that identical author entry will be merged when the file is reloaded.

Have a nice evening!

Michael
Index: src/Author.h
===================================================================
--- src/Author.h	(Revision 18982)
+++ src/Author.h	(Arbeitskopie)
@@ -26,7 +26,7 @@
 	Author() {}
 
 	Author(docstring const & name, docstring const & email)
-		: name_(name), email_(email) {}
+		: name_(name), email_(email), used_(true) {}
 
 	docstring const name() const {
 		return name_;
@@ -36,12 +36,22 @@
 		return email_;
 	}
 
+	void setUsed(bool used) {
+		used_ = used;
+	}
+
+	bool isUsed() const {
+		return used_;
+	}
+
 	friend std::istream & operator>>(std::istream & os, Author & a);
 
 private:
 	docstring name_;
 
 	docstring email_;
+
+	bool used_;
 };
 
 
@@ -53,13 +63,13 @@
 
 	void record(int id, Author const & a);
 
-	Author const & get(int id) const;
+	Author & get(int id);
 
 	typedef std::map<int, Author> Authors;
 
-	Authors::const_iterator begin() const;
+	Authors::iterator begin();
 
-	Authors::const_iterator end() const;
+	Authors::iterator end();
 
 private:
 	int last_id_;
Index: src/Changes.cpp
===================================================================
--- src/Changes.cpp	(Revision 18982)
+++ src/Changes.cpp	(Arbeitskopie)
@@ -357,4 +357,13 @@
 }
 
 
+void Changes::checkAuthors(AuthorList & authorList)
+{
+	ChangeTable::const_iterator it = table_.begin();
+	ChangeTable::const_iterator endit = table_.end();
+	for ( ; it != endit ; ++it) 
+		if (it->change.type != Change::UNCHANGED)
+			authorList.get(it->change.author).setUsed(true);
+}
+
 } // namespace lyx
Index: src/BufferParams.h
===================================================================
--- src/BufferParams.h	(Revision 18982)
+++ src/BufferParams.h	(Arbeitskopie)
@@ -242,8 +242,7 @@
 	bool compressed;
 
 	/// the author list for the document
-	AuthorList & authors();
-	AuthorList const & authors() const;
+	AuthorList & authors() const;
 
 	/// map of the file's author IDs to buffer author IDs
 	std::vector<unsigned int> author_map;
Index: src/support/userinfo.cpp
===================================================================
--- src/support/userinfo.cpp	(Revision 18982)
+++ src/support/userinfo.cpp	(Arbeitskopie)
@@ -36,11 +36,6 @@
 
 docstring const user_name()
 {
-	//FIXME: quick fix wrt bug #3764; only Anonymous is detected now.
-	//The code after should be used only after user approval.
-	return from_ascii("Anonymous");
-	
-	
 #if defined (_WIN32)
 
 	char name[UNLEN + 1];
Index: src/Paragraph.cpp
===================================================================
--- src/Paragraph.cpp	(Revision 18982)
+++ src/Paragraph.cpp	(Arbeitskopie)
@@ -219,6 +219,8 @@
 	/// for recording and looking up changes
 	Changes changes_;
 
+	friend class Paragraph;
+
 	/// Who owns us?
 	Paragraph * owner_;
 };
@@ -2670,4 +2672,10 @@
 	return 1;
 }
 
+
+void Paragraph::checkAuthors(AuthorList & authorList)
+{
+	pimpl_->changes_.checkAuthors(authorList);
+}
+
 } // namespace lyx
Index: src/Changes.h
===================================================================
--- src/Changes.h	(Revision 18982)
+++ src/Changes.h	(Arbeitskopie)
@@ -17,6 +17,7 @@
 
 #include "support/docstream.h"
 #include "support/lyxtime.h"
+#include "author.h"
 
 #include <vector>
 
@@ -85,6 +86,9 @@
 	static void lyxMarkChange(std::ostream & os, int & column,
 		Change const & old, Change const & change);
 
+	///
+	void checkAuthors(AuthorList & authorList);
+
 private:
 	class Range {
 	public:
Index: src/Author.cpp
===================================================================
--- src/Author.cpp	(Revision 18982)
+++ src/Author.cpp	(Arbeitskopie)
@@ -80,21 +80,21 @@
 }
 
 
-Author const & AuthorList::get(int id) const
+Author & AuthorList::get(int id)
 {
-	Authors::const_iterator it(authors_.find(id));
+	Authors::iterator it(authors_.find(id));
 	BOOST_ASSERT(it != authors_.end());
 	return it->second;
 }
 
 
-AuthorList::Authors::const_iterator AuthorList::begin() const
+AuthorList::Authors::iterator AuthorList::begin()
 {
 	return authors_.begin();
 }
 
 
-AuthorList::Authors::const_iterator AuthorList::end() const
+AuthorList::Authors::iterator AuthorList::end() 
 {
 	return authors_.end();
 }
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp	(Revision 18982)
+++ src/Buffer.cpp	(Arbeitskopie)
@@ -846,6 +846,20 @@
 	    << "\\lyxformat " << LYX_FORMAT << "\n"
 	    << "\\begin_document\n";
 
+
+	/// For each author, set 'used' to true if there is a change
+	/// by this author in the document; otherwise set it to 'false'.
+	AuthorList::Authors::iterator a_it = pimpl_->params.authors().begin();
+	AuthorList::Authors::iterator a_end = pimpl_->params.authors().end();
+	for (; a_it != a_end; ++a_it) {
+		a_it->second.setUsed(false);
+	}
+	ParIterator const end = par_iterator_end();
+	ParIterator it = par_iterator_begin();
+	for ( ; it != end; ++it) {
+		it->checkAuthors(pimpl_->params.authors());
+	}
+
 	// now write out the buffer parameters.
 	ofs << "\\begin_header\n";
 	params().writeFile(ofs);
Index: src/Paragraph.h
===================================================================
--- src/Paragraph.h	(Revision 18982)
+++ src/Paragraph.h	(Arbeitskopie)
@@ -368,6 +368,10 @@
 	/// was previously past that position. Return 0 otherwise.
 	int checkBiblio(bool track_changes);
 
+	/// For each author, set 'used' to true if there is a change
+	/// by this author in the paragraph.
+	void checkAuthors(AuthorList & authorList);
+
 public:
 	///
 	InsetList insetlist;
Index: src/BufferParams.cpp
===================================================================
--- src/BufferParams.cpp	(Revision 18982)
+++ src/BufferParams.cpp	(Arbeitskopie)
@@ -373,18 +373,12 @@
 }
 
 
-AuthorList & BufferParams::authors()
+AuthorList & BufferParams::authors() const
 {
 	return pimpl_->authorlist;
 }
 
 
-AuthorList const & BufferParams::authors() const
-{
-	return pimpl_->authorlist;
-}
-
-
 BranchList & BufferParams::branchlist()
 {
 	return pimpl_->branchlist;
@@ -766,7 +760,10 @@
 	AuthorList::Authors::const_iterator a_it = pimpl_->authorlist.begin();
 	AuthorList::Authors::const_iterator a_end = pimpl_->authorlist.end();
 	for (; a_it != a_end; ++a_it) {
-		os << "\\author " << a_it->second << "\n";
+		if (a_it->second.isUsed())
+			os << "\\author " << a_it->second << "\n";
+		else
+			os << "\\author " << Author() << "\n";
 	}
 }
 

Reply via email to