sw/source/uibase/sidebar/CommentsPanel.cxx |   80 ++++++++++++++++++++++++++++-
 sw/source/uibase/sidebar/CommentsPanel.hxx |   16 +++++
 sw/uiconfig/swriter/ui/commentspanel.ui    |   33 +++++++++--
 3 files changed, 120 insertions(+), 9 deletions(-)

New commits:
commit 8d70677c621959d1788e8ffa41641db06ef3cdb2
Author:     Mohit Marathe <mohitmara...@proton.me>
AuthorDate: Mon Jul 15 17:27:10 2024 +0530
Commit:     Sarper Akdemir <sarper.akde...@allotropia.de>
CommitDate: Thu Sep 19 13:44:39 2024 +0200

    filter by author & time
    
    Change-Id: Ia32a9a3672e3e3a81245e67e388218559120e449
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170497
    Reviewed-by: Sarper Akdemir <sarper.akde...@allotropia.de>
    Tested-by: Jenkins

diff --git a/sw/source/uibase/sidebar/CommentsPanel.cxx 
b/sw/source/uibase/sidebar/CommentsPanel.cxx
index 86f38f17829d..de4726f0a372 100644
--- a/sw/source/uibase/sidebar/CommentsPanel.cxx
+++ b/sw/source/uibase/sidebar/CommentsPanel.cxx
@@ -43,6 +43,7 @@
 #include <tools/link.hxx>
 #include <editeng/outliner.hxx>
 #include <editeng/editeng.hxx>
+#include <svtools/ctrlbox.hxx>
 
 #include <strings.hrc>
 #include <cmdid.h>
@@ -136,7 +137,8 @@ CommentsPanel::CommentsPanel(weld::Widget* pParent)
     : PanelLayout(pParent, "CommentsPanel", 
"modules/swriter/ui/commentspanel.ui")
     , mpPostItMgr(nullptr)
     , mxFilterAuthor(m_xBuilder->weld_combo_box("filter_author"))
-    , mxFilterTime(m_xBuilder->weld_combo_box("filter_time"))
+    , mxFilterDate(new 
SvtCalendarBox(m_xBuilder->weld_menu_button("filter_date"), true))
+    , mxResetDate(m_xBuilder->weld_button("reset"))
     , mxShowTime(m_xBuilder->weld_check_button("show_time"))
     , mxShowResolved(m_xBuilder->weld_check_button("show_resolved"))
     , mxShowReference(m_xBuilder->weld_check_button("show_reference"))
@@ -144,6 +146,9 @@ CommentsPanel::CommentsPanel(weld::Widget* pParent)
     , mxSortbyTime(m_xBuilder->weld_radio_button("sortby_time"))
     , mxThreadsContainer(m_xBuilder->weld_box("comment_threads"))
 {
+    mxFilterAuthor->connect_changed(LINK(this, CommentsPanel, FilterByAuthor));
+    mxFilterDate->connect_activated(LINK(this, CommentsPanel, FilterByDate));
+    mxResetDate->connect_clicked(LINK(this, CommentsPanel, ResetDate));
     mxSortbyPosition->connect_toggled(LINK(this, CommentsPanel, SortHdl));
     mxSortbyTime->connect_toggled(LINK(this, CommentsPanel, SortHdl));
 
@@ -367,6 +372,7 @@ void CommentsPanel::populateComments()
                 
pThread->getCommentBoxWidget()->reorder_child(pComment->get_widget(),
                                                               
pThread->mnComments++);
                 pComment->InitControls(pPostItField);
+                mpAuthorSet.insert(pComment->GetAuthor());
                 mpCommentsMap[nId] = std::move(pComment);
                 continue;
             }
@@ -384,6 +390,7 @@ void CommentsPanel::populateComments()
                 
pThread->getCommentBoxWidget()->reorder_child(pComment->get_widget(),
                                                               
pThread->mnComments++);
                 pComment->InitControls(pCurrent->GetPostItField());
+                mpAuthorSet.insert(pComment->GetAuthor());
                 mpCommentsMap[nId] = std::move(pComment);
                 sw::annotation::SwAnnotationWin* next
                     = mpPostItMgr->GetNextPostIt(KEY_PAGEDOWN, pCurrent);
@@ -400,10 +407,12 @@ void CommentsPanel::populateComments()
             
pThread->getCommentBoxWidget()->reorder_child(pComment->get_widget(),
                                                           
pThread->mnComments++);
             pComment->InitControls(pPostItField);
+            mpAuthorSet.insert(pComment->GetAuthor());
             mpCommentsMap[nId] = std::move(pComment);
         }
         mpThreadsMap[nRootId] = std::move(pThread);
     }
+    populateAuthorComboBox();
 }
 
 void CommentsPanel::addComment(const SwFormatField* pField)
@@ -431,6 +440,7 @@ void CommentsPanel::addComment(const SwFormatField* pField)
         pThread->getCommentBoxWidget()->reorder_child(pComment->get_widget(),
                                                       pThread->mnComments++);
         pComment->InitControls(pNote->GetPostItField());
+        mpAuthorSet.insert(pComment->GetAuthor());
         mpCommentsMap[nNoteId] = std::move(pComment);
     }
     // If a new thread is created
@@ -443,6 +453,7 @@ void CommentsPanel::addComment(const SwFormatField* pField)
                                                       pThread->mnComments++);
         mpThreadsMap[nRootId] = std::move(pThread);
         pComment->InitControls(pNote->GetPostItField());
+        mpAuthorSet.insert(pComment->GetAuthor());
         mpCommentsMap[nNoteId] = std::move(pComment);
     }
     populateComments();
@@ -539,6 +550,73 @@ void CommentsPanel::ReplyComment(Comment* pComment)
     pWin->ExecuteCommand(FN_REPLY);
 }
 
+void CommentsPanel::populateAuthorComboBox()
+{
+    mxFilterAuthor->clear();
+    if (mpAuthorSet.empty())
+        return;
+    mxFilterAuthor->append_text("All");
+    for (const OUString& rAuthor : mpAuthorSet)
+    {
+        mxFilterAuthor->append_text(rAuthor);
+    }
+    mxFilterAuthor->set_active_text("All");
+}
+
+IMPL_LINK_NOARG(CommentsPanel, FilterByAuthor, weld::ComboBox&, void)
+{
+    OUString sAuthor = mxFilterAuthor->get_active_text();
+    if (sAuthor == "All")
+    {
+        for (auto & [ nId, pComment ] : mpCommentsMap)
+        {
+            if (!mbResetDate && mxFilterDate->get_date() != 
pComment->GetDate())
+                continue;
+            pComment->get_widget()->set_visible(true);
+        }
+    }
+    else
+    {
+        for (auto & [ nId, pComment ] : mpCommentsMap)
+        {
+            if (sAuthor == pComment->GetAuthor())
+            {
+                if (!mbResetDate && mxFilterDate->get_date() != 
pComment->GetDate())
+                    continue;
+                pComment->get_widget()->set_visible(true);
+            }
+            else
+            {
+                pComment->get_widget()->set_visible(false);
+            }
+        }
+    }
+}
+
+IMPL_LINK_NOARG(CommentsPanel, FilterByDate, SvtCalendarBox&, void)
+{
+    Date aDate(mxFilterDate->get_date());
+    for (auto & [ nId, pComment ] : mpCommentsMap)
+    {
+        if (aDate == pComment->GetDate())
+        {
+            pComment->get_widget()->set_visible(true);
+        }
+        else
+        {
+            pComment->get_widget()->set_visible(false);
+        }
+    }
+    FilterByAuthor(*mxFilterAuthor);
+}
+
+IMPL_LINK_NOARG(CommentsPanel, ResetDate, weld::Button&, void)
+{
+    mbResetDate = true;
+    FilterByAuthor(*mxFilterAuthor);
+    mbResetDate = false;
+}
+
 CommentsPanel::~CommentsPanel() {}
 
 void CommentsPanel::NotifyItemUpdate(const sal_uInt16 /*nSid*/, const 
SfxItemState /* eState */,
diff --git a/sw/source/uibase/sidebar/CommentsPanel.hxx 
b/sw/source/uibase/sidebar/CommentsPanel.hxx
index 9c214d88bb56..d5e22c6ef076 100644
--- a/sw/source/uibase/sidebar/CommentsPanel.hxx
+++ b/sw/source/uibase/sidebar/CommentsPanel.hxx
@@ -19,6 +19,8 @@
 
 #pragma once
 
+#include <svtools/ctrlbox.hxx>
+#include <rtl/ustring.hxx>
 #include <memory>
 
 #include <sfx2/sidebar/PanelLayout.hxx>
@@ -33,6 +35,7 @@
 #include <tools/date.hxx>
 #include <tools/datetime.hxx>
 #include <tools/time.hxx>
+#include <svtools/ctrlbox.hxx>
 
 class SwWrtShell;
 class SwView;
@@ -81,6 +84,8 @@ public:
 
     void InitControls(const SwPostItField* pPostItField);
     void SetCommentText(OUString sText) { msText = sText; }
+    OUString GetAuthor() { return msAuthor; }
+    Date GetDate() { return maDate; }
 };
 
 class Thread final
@@ -126,6 +131,9 @@ public:
 
     void ReplyComment(Comment* pComment);
 
+    DECL_LINK(FilterByAuthor, weld::ComboBox&, void);
+    DECL_LINK(FilterByDate, SvtCalendarBox&, void);
+    DECL_LINK(ResetDate, weld::Button&, void);
     DECL_LINK(SortHdl, weld::Toggleable&, void);
 
     // utility functions
@@ -137,8 +145,11 @@ private:
 
     std::unordered_map<sal_uInt32, std::unique_ptr<Thread>> mpThreadsMap;
     std::unordered_map<sal_uInt32, std::unique_ptr<Comment>> mpCommentsMap;
+    std::unordered_set<OUString> mpAuthorSet;
+
     std::unique_ptr<weld::ComboBox> mxFilterAuthor;
-    std::unique_ptr<weld::ComboBox> mxFilterTime;
+    std::unique_ptr<SvtCalendarBox> mxFilterDate;
+    std::unique_ptr<weld::Button> mxResetDate;
     std::unique_ptr<weld::CheckButton> mxShowTime;
     std::unique_ptr<weld::CheckButton> mxShowResolved;
     std::unique_ptr<weld::CheckButton> mxShowReference;
@@ -147,6 +158,7 @@ private:
     std::unique_ptr<weld::Box> mxThreadsContainer;
 
     sal_uInt16 mnThreads = 0;
+    bool mbResetDate = false;
 
     // utility functions
     sw::annotation::SwAnnotationWin* getRootCommentWin(const SwFormatField* 
pField);
@@ -162,6 +174,8 @@ private:
     void deleteComment(sal_uInt32 nId);
     void setResolvedStatus(sw::annotation::SwAnnotationWin* pAnnotationWin);
     static void editComment(SwPostItField* pPostItField, Comment* pComment);
+
+    void populateAuthorComboBox();
 };
 
 } //end of namespace sw::sidebar
diff --git a/sw/uiconfig/swriter/ui/commentspanel.ui 
b/sw/uiconfig/swriter/ui/commentspanel.ui
index 739e5f18a38c..005ecd47f5cf 100644
--- a/sw/uiconfig/swriter/ui/commentspanel.ui
+++ b/sw/uiconfig/swriter/ui/commentspanel.ui
@@ -181,7 +181,7 @@
                   </packing>
                 </child>
                 <child>
-                  <!-- n-columns=2 n-rows=2 -->
+                  <!-- n-columns=3 n-rows=2 -->
                   <object class="GtkGrid" id="filter_options">
                     <property name="visible">True</property>
                     <property name="can-focus">False</property>
@@ -203,14 +203,14 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="label_time">
+                      <object class="GtkLabel" id="label_date">
                         <property name="visible">True</property>
                         <property name="can-focus">False</property>
                         <property name="halign">start</property>
                         <property name="hexpand">True</property>
-                        <property name="label" translatable="yes" 
context="commentspanel|label_time">Time</property>
+                        <property name="label" translatable="yes" 
context="commentspanel|label_time">Date</property>
                         <property name="use-underline">True</property>
-                        <property name="mnemonic-widget">filter_time</property>
+                        <property name="mnemonic-widget">filter_date</property>
                       </object>
                       <packing>
                         <property name="left-attach">1</property>
@@ -229,16 +229,35 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkComboBoxText" id="filter_time">
+                      <object class="GtkMenuButton" id="filter_date">
                         <property name="visible">True</property>
-                        <property name="can-focus">False</property>
-                        <property name="hexpand">True</property>
+                        <property name="can-focus">True</property>
+                        <property name="focus-on-click">False</property>
+                        <property name="receives-default">True</property>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </object>
                       <packing>
                         <property name="left-attach">0</property>
                         <property name="top-attach">1</property>
                       </packing>
                     </child>
+                    <child>
+                      <object class="GtkButton" id="reset">
+                        <property name="label" translatable="yes" 
context="commentspanel|label_author">Reset</property>
+                        <property name="visible">True</property>
+                        <property name="can-focus">True</property>
+                        <property name="receives-default">True</property>
+                      </object>
+                      <packing>
+                        <property name="left-attach">2</property>
+                        <property name="top-attach">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </object>
                   <packing>
                     <property name="left-attach">1</property>

Reply via email to