]> git.lyx.org Git - features.git/commitdiff
Add a "List of Changes" in the Navigator. The list is updated only when the document...
authorAbdelrazak Younes <younes@lyx.org>
Tue, 30 Sep 2008 11:06:34 +0000 (11:06 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Tue, 30 Sep 2008 11:06:34 +0000 (11:06 +0000)
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
src/Changes.h
src/Paragraph.cpp
src/Paragraph.h
src/TocBackend.cpp
src/TocBackend.h
src/frontends/qt4/TocWidget.cpp
src/frontends/qt4/qt_helpers.cpp
src/insets/InsetText.cpp

index c2677736cd68713a7f964584b39ac958921f44f2..1456db561c2d4971834f78dd3c8f7439be249f34 100644 (file)
 
 #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 <ostream>
@@ -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
index 631419bc3065d71963d4ae9957c36c79aa934f68..09ac0aa0fe7d3dd52271f2a1574ab23693d9a432 100644 (file)
@@ -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:
index 7c9780e1ae2874bb02af9723f03e24c83562e549..5f138fead8d2e678c41cc4244e263fa6c750f4e1 100644 (file)
@@ -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(), /**/);
index 6fdb27017765955175ae263450220195b476fe07..6e0657d0f2eeda474dff529dd32b2fab01495201 100644 (file)
@@ -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;
        ///
index 4ffa35571b5c2cc7d682a0c716191e7bb42b2cca..2da31fca17f278015c03bc2e0757ceda2983be08 100644 (file)
@@ -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);
index 1e5b031a73cdfe251ad44d6b547461fe817ceb67..131c3df74816fcc75f1545d9ca37bba703090492 100644 (file)
@@ -76,6 +76,10 @@ class Toc : public std::vector<TocItem>
 public:
        typedef std::vector<TocItem>::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;
index 1667091ffd1adbe485712260dc3d80190ae0ed70..b854c4d935be87483061656765aedf21e6075b88 100644 (file)
@@ -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";
 }
 
 
index 395eb4edf92bf338cf0eb2a6e66cd88c360fecd4..5c4e7387e6ad1da31d14a459e452e8d36773bf52 100644 (file)
@@ -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))
index 56e9d8f0318f7995c74bbbb687742e682d185fb0..142d21b6127b5d9af139775c0fd37aef60d7c100 100644 (file)
@@ -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());
        }
 }