From 5ce39aa8b5afb1fa88c39797cea6d4e5da5dafe3 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Tue, 30 Sep 2008 11:06:34 +0000 Subject: [PATCH] Add a "List of Changes" in the Navigator. The list is updated only when the document structure is reset or when the update button is clicked. Some work is needed to track more finely individual changes as we do for sections. Changes::addToToc(): New method to insert changes sorted by authors. The symbols 0x2702 and 0x270d are used to represent deletion and insertion. TocBackend::item(): new method to lookup for a given item. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26639 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Changes.cpp | 45 +++++++++++++++++++++++++++++++- src/Changes.h | 7 +++-- src/Paragraph.cpp | 7 +++++ src/Paragraph.h | 5 +++- src/TocBackend.cpp | 14 ++++++++++ src/TocBackend.h | 4 +++ src/frontends/qt4/TocWidget.cpp | 2 +- src/frontends/qt4/qt_helpers.cpp | 2 ++ src/insets/InsetText.cpp | 3 +++ 9 files changed, 84 insertions(+), 5 deletions(-) diff --git a/src/Changes.cpp b/src/Changes.cpp index c2677736cd..1456db561c 100644 --- a/src/Changes.cpp +++ b/src/Changes.cpp @@ -15,11 +15,14 @@ #include "Changes.h" #include "Author.h" +#include "Buffer.h" #include "BufferParams.h" #include "LaTeXFeatures.h" +#include "Paragraph.h" +#include "TocBackend.h" #include "support/debug.h" - +#include "support/gettext.h" #include "support/lassert.h" #include @@ -381,4 +384,44 @@ void Changes::checkAuthors(AuthorList const & authorList) authorList.get(it->change.author).setUsed(true); } + +void Changes::addToToc(DocIterator const & cdit, Buffer const & buffer) const +{ + if (table_.empty()) + return; + + Toc & change_list = buffer.tocBackend().toc("change"); + AuthorList const & author_list = buffer.params().authors(); + DocIterator dit = cdit; + + ChangeTable::const_iterator it = table_.begin(); + ChangeTable::const_iterator const itend = table_.end(); + for (; it != itend; ++it) { + docstring str; + switch (it->change.type) { + case Change::UNCHANGED: + continue; + case Change::DELETED: + // 0x2702 is a scissors symbol in the Dingbats unicode group. + str.push_back(0x2702); + break; + case Change::INSERTED: + // 0x2702 is the hand writting symbol in the Dingbats unicode group. + str.push_back(0x270d); + break; + } + dit.pos() = it->range.start; + str += " " + dit.paragraph().asString(it->range.start, it->range.end); + docstring const & author = author_list.get(it->change.author).name(); + Toc::const_iterator it = change_list.item(0, author); + if (it == change_list.end()) { + change_list.push_back(TocItem(dit, 0, author)); + change_list.push_back(TocItem(dit, 1, str)); + } else { + it++; + change_list.insert(it, TocItem(dit, 1, str)); + } + } +} + } // namespace lyx diff --git a/src/Changes.h b/src/Changes.h index 631419bc30..09ac0aa0fe 100644 --- a/src/Changes.h +++ b/src/Changes.h @@ -27,6 +27,8 @@ namespace lyx { class AuthorList; +class Buffer; +class DocIterator; class Change { public: @@ -92,8 +94,6 @@ public: /// return true if there is a change in the given range (excluding end) bool isChanged(pos_type start, pos_type end) const; - /// - /// output latex to mark a transition between two change types /// returns length of text outputted static int latexMarkChange(odocstream & os, BufferParams const & bparams, @@ -106,6 +106,9 @@ public: /// void checkAuthors(AuthorList const & authorList); + /// + void addToToc(DocIterator const & cdit, Buffer const & buffer) const; + private: class Range { public: diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 7c9780e1ae..5f138fead8 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -279,6 +279,13 @@ Paragraph::Private::Private(Private const & p, Paragraph * owner, } +void Paragraph::addChangesToToc(DocIterator const & cdit, + Buffer const & buf) const +{ + d->changes_.addToToc(cdit, buf); +} + + bool Paragraph::isChanged(pos_type start, pos_type end) const { LASSERT(start >= 0 && start <= size(), /**/); diff --git a/src/Paragraph.h b/src/Paragraph.h index 6fdb270177..6e0657d0f2 100644 --- a/src/Paragraph.h +++ b/src/Paragraph.h @@ -33,6 +33,7 @@ class Change; class Counters; class Cursor; class CursorSlice; +class DocIterator; class DocumentClass; class Inset; class InsetBibitem; @@ -47,7 +48,7 @@ class OutputParams; class PainterInfo; class ParagraphParameters; class TexRow; - +class Toc; class FontSpan { public: @@ -99,6 +100,8 @@ public: /// int id() const; + /// + void addChangesToToc(DocIterator const & cdit, Buffer const & buf) const; /// Language const * getParLanguage(BufferParams const &) const; /// diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index 4ffa35571b..2da31fca17 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -203,6 +203,20 @@ TocIterator Toc::item(DocIterator const & dit) const } +TocIterator Toc::item(int depth, docstring const & str) const +{ + if (empty()) + return end(); + TocIterator it = begin(); + TocIterator itend = end(); + for (; it != itend; --it) { + if (it->depth() == depth && it->str() == str) + break; + } + return it; +} + + void TocBackend::writePlaintextTocList(string const & type, odocstream & os) const { TocList::const_iterator cit = tocs_.find(type); diff --git a/src/TocBackend.h b/src/TocBackend.h index 1e5b031a73..131c3df748 100644 --- a/src/TocBackend.h +++ b/src/TocBackend.h @@ -76,6 +76,10 @@ class Toc : public std::vector public: typedef std::vector::const_iterator const_iterator; const_iterator item(DocIterator const & dit) const; + /// Look for a TocItem given its depth and string. + /// \return The first matching item. + /// \retval end() if no item was found. + const_iterator item(int depth, docstring const & str) const; }; typedef Toc::const_iterator TocIterator; diff --git a/src/frontends/qt4/TocWidget.cpp b/src/frontends/qt4/TocWidget.cpp index 1667091ffd..b854c4d935 100644 --- a/src/frontends/qt4/TocWidget.cpp +++ b/src/frontends/qt4/TocWidget.cpp @@ -242,7 +242,7 @@ static bool canNavigate(QString const & type) // and efficient way with the label type because Toc::item() do a linear // seatch. Even if fixed, it might even not be desirable to do so if we // want to support drag&drop of labels and references. - return type != "label"; + return type != "label" && type != "change"; } diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp index 395eb4edf9..5c4e7387e6 100644 --- a/src/frontends/qt4/qt_helpers.cpp +++ b/src/frontends/qt4/qt_helpers.cpp @@ -498,6 +498,8 @@ QString guiName(string const & type, BufferParams const & bp) return qt_("Labels and References"); if (type == "branch") return qt_("List of Branches"); + if (type == "change") + return qt_("List of Changes"); FloatList const & floats = bp.documentClass().floats(); if (floats.typeExist(type)) diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 56e9d8f031..142d21b612 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -498,6 +498,9 @@ void InsetText::addToToc(DocIterator const & cdit) tocstring = par.asString(AS_STR_LABEL); toc.push_back(TocItem(dit, toclevel - min_toclevel, tocstring)); } + + // And now the list of changes. + par.addChangesToToc(dit, buffer()); } } -- 2.39.2