sw/UIConfig_swriter.mk                       |    1 
 sw/source/uibase/sidebar/CommentsPanel.cxx   |   71 ++++++++++++++++++++++++++-
 sw/source/uibase/sidebar/CommentsPanel.hxx   |   11 +++-
 sw/uiconfig/swriter/ui/commentcontextmenu.ui |   63 +++++++++++++++++++++++
 sw/uiconfig/swriter/ui/commentsthread.ui     |    1 
 sw/uiconfig/swriter/ui/commentwidget.ui      |    4 +
 6 files changed, 147 insertions(+), 4 deletions(-)

New commits:
commit 1bc03ef24fe3d1de6c2e2300a85d22b8e2cd2009
Author:     Mohit Marathe <[email protected]>
AuthorDate: Tue Jul 23 12:16:39 2024 +0530
Commit:     Sarper Akdemir <[email protected]>
CommitDate: Thu Sep 19 13:55:56 2024 +0200

    add context menu for comments & some other changes
    
    Besides adding a context menu for comments in the comments panel,
    this commit adds the ability to make comments editable only when
    needed (through the context menu)
    
    Change-Id: I208a6531ce56d7ee2d7ed50703178babda9c5a31
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170996
    Tested-by: Jenkins
    Reviewed-by: Sarper Akdemir <[email protected]>

diff --git a/sw/UIConfig_swriter.mk b/sw/UIConfig_swriter.mk
index a96ee9dd9749..d9df23bf27a4 100644
--- a/sw/UIConfig_swriter.mk
+++ b/sw/UIConfig_swriter.mk
@@ -288,6 +288,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/swriter,\
        sw/uiconfig/swriter/ui/commentspanel \
        sw/uiconfig/swriter/ui/commentsthread \
        sw/uiconfig/swriter/ui/commentwidget \
+       sw/uiconfig/swriter/ui/commentcontextmenu \
        sw/uiconfig/swriter/ui/a11ycheckissuespanel \
        sw/uiconfig/swriter/ui/poseditbox \
        sw/uiconfig/swriter/ui/sidebarwrap \
diff --git a/sw/source/uibase/sidebar/CommentsPanel.cxx 
b/sw/source/uibase/sidebar/CommentsPanel.cxx
index 03fea85534b7..ee502b0ee39d 100644
--- a/sw/source/uibase/sidebar/CommentsPanel.cxx
+++ b/sw/source/uibase/sidebar/CommentsPanel.cxx
@@ -46,6 +46,7 @@
 #include <editeng/outliner.hxx>
 #include <editeng/editeng.hxx>
 #include <svtools/ctrlbox.hxx>
+#include <vcl/event.hxx>
 
 #include <strings.hrc>
 #include <cmdid.h>
@@ -61,6 +62,7 @@ namespace sw::sidebar
 Comment::Comment(weld::Container* pParent, CommentsPanel& rCommentsPanel)
     : mxBuilder(Application::CreateBuilder(pParent, 
"modules/swriter/ui/commentwidget.ui"))
     , mxContainer(mxBuilder->weld_container("Comment"))
+    , mxExpander(mxBuilder->weld_expander("expander"))
     , mxAuthor(mxBuilder->weld_label("authorlabel"))
     , mxDate(mxBuilder->weld_label("datelabel"))
     , mxTime(mxBuilder->weld_label("timelabel"))
@@ -72,9 +74,43 @@ Comment::Comment(weld::Container* pParent, CommentsPanel& 
rCommentsPanel)
     , maTime(tools::Time::EMPTY)
     , mbResolved(false)
 {
+    mxTextView->set_editable(false);
+    mxTextView->set_tooltip_text("View Mode");
     mxTextView->connect_focus_out(LINK(this, Comment, OnFocusOut));
     mxResolve->connect_toggled(LINK(this, Comment, ResolveClicked));
     mxReply->connect_clicked(LINK(this, Comment, ReplyClicked));
+    mxExpander->connect_mouse_press(LINK(this, Comment, ContextMenuHdl));
+}
+
+IMPL_LINK(Comment, ContextMenuHdl, const MouseEvent&, rMEvt, bool)
+{
+    if (rMEvt.IsRight())
+    {
+        std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(
+            mxExpander.get(), 
u"modules/swriter/ui/commentcontextmenu.ui"_ustr));
+        std::unique_ptr<weld::Menu> 
xPopMenu(xBuilder->weld_menu(u"contextmenu"_ustr));
+        Point aPos = rMEvt.GetPosPixel();
+        OUString sId
+            = xPopMenu->popup_at_rect(mxExpander.get(), tools::Rectangle(aPos, 
Size(1, 1)));
+
+        if (sId == "edit")
+        {
+            this->makeEditable();
+            getTextView()->set_tooltip_text("Edit Mode");
+        }
+        else if (sId == "reply")
+            mrCommentsPanel.ReplyComment(this);
+        else if (sId == "delete")
+            mrCommentsPanel.DeleteComment(this);
+        else if (sId == "toggle_resolved")
+            mrCommentsPanel.ToggleResolved(this);
+        else if (sId == "delete_thread")
+            mrCommentsPanel.DeleteThread(this);
+        else if (sId == "resolve_thread")
+            mrCommentsPanel.ResolveThread(this);
+        return true;
+    }
+    return false;
 }
 
 OUString CommentsPanel::getReferenceText(SwTextNode* pTextNode, 
sw::mark::AnnotationMark* pMark)
@@ -119,7 +155,11 @@ void Comment::InitControls(const SwPostItField* 
pPostItField)
     mxTextView->set_text(msText);
 }
 
-IMPL_LINK_NOARG(Comment, OnFocusOut, weld::Widget&, void) { 
mrCommentsPanel.EditComment(this); }
+IMPL_LINK_NOARG(Comment, OnFocusOut, weld::Widget&, void)
+{
+    mrCommentsPanel.EditComment(this);
+    getTextView()->set_tooltip_text("View Mode");
+}
 
 IMPL_LINK_NOARG(Comment, ResolveClicked, weld::Toggleable&, void)
 {
@@ -457,6 +497,7 @@ void CommentsPanel::addComment(const SwFormatField* pField)
         pThread->getCommentBoxWidget()->reorder_child(pComment->get_widget(),
                                                       pThread->mnComments++);
         pComment->InitControls(pNote->GetPostItField());
+        pComment->getTextView()->set_tooltip_text("Edit Mode");
         mpAuthorSet.insert(pComment->GetAuthor());
         mpCommentsMap[nNoteId] = std::move(pComment);
     }
@@ -471,6 +512,7 @@ void CommentsPanel::addComment(const SwFormatField* pField)
         mpThreadsMap[nRootId] = std::move(pThread);
         setReferenceText(nRootId);
         pComment->InitControls(pNote->GetPostItField());
+        pComment->getTextView()->set_tooltip_text("Edit Mode");
         mpAuthorSet.insert(pComment->GetAuthor());
         mpCommentsMap[nNoteId] = std::move(pComment);
     }
@@ -559,12 +601,15 @@ void CommentsPanel::EditComment(Comment* pComment)
 {
     if (!pComment)
         return;
+    if (!pComment->mxTextView->get_editable())
+        return;
     const OUString sText = pComment->mxTextView->get_text();
 
     sw::annotation::SwAnnotationWin* pWin = getAnnotationWin(pComment);
     Outliner* pOutliner = pWin->GetOutliner();
     pOutliner->Clear();
     pOutliner->SetText(sText, pOutliner->GetParagraph(0));
+    pComment->mxTextView->set_editable(false);
 }
 
 void CommentsPanel::ToggleResolved(Comment* pComment)
@@ -583,6 +628,30 @@ void CommentsPanel::ReplyComment(Comment* pComment)
     pWin->ExecuteCommand(FN_REPLY);
 }
 
+void CommentsPanel::DeleteComment(Comment* pComment)
+{
+    if (!pComment)
+        return;
+    sw::annotation::SwAnnotationWin* pWin = getAnnotationWin(pComment);
+    pWin->ExecuteCommand(FN_DELETE_COMMENT);
+}
+
+void CommentsPanel::DeleteThread(Comment* pComment)
+{
+    if (!pComment)
+        return;
+    sw::annotation::SwAnnotationWin* pWin = getAnnotationWin(pComment);
+    pWin->ExecuteCommand(FN_DELETE_COMMENT_THREAD);
+}
+
+void CommentsPanel::ResolveThread(Comment* pComment)
+{
+    if (!pComment)
+        return;
+    sw::annotation::SwAnnotationWin* pWin = getAnnotationWin(pComment);
+    pWin->ExecuteCommand(FN_RESOLVE_NOTE_THREAD);
+}
+
 void CommentsPanel::populateAuthorComboBox()
 {
     mxFilterAuthor->clear();
diff --git a/sw/source/uibase/sidebar/CommentsPanel.hxx 
b/sw/source/uibase/sidebar/CommentsPanel.hxx
index 9902f35887d8..9bb2d2828783 100644
--- a/sw/source/uibase/sidebar/CommentsPanel.hxx
+++ b/sw/source/uibase/sidebar/CommentsPanel.hxx
@@ -19,6 +19,7 @@
 
 #pragma once
 
+#include <vcl/event.hxx>
 #include <annotationmark.hxx>
 #include <svtools/ctrlbox.hxx>
 #include <rtl/ustring.hxx>
@@ -57,6 +58,7 @@ class Comment final
 private:
     std::unique_ptr<weld::Builder> mxBuilder;
     std::unique_ptr<weld::Container> mxContainer;
+    std::unique_ptr<weld::Expander> mxExpander;
     std::unique_ptr<weld::Label> mxAuthor;
     std::unique_ptr<weld::Label> mxDate;
     std::unique_ptr<weld::Label> mxTime;
@@ -72,14 +74,18 @@ private:
     Date maDate;
     tools::Time maTime;
 
+    void makeEditable() { mxTextView->set_editable(true); }
+
 public:
     Comment(weld::Container* pParent, CommentsPanel& rCommentsPanel);
     ~Comment();
     weld::Widget* get_widget() const { return mxContainer.get(); }
+    weld::TextView* getTextView() const { return mxTextView.get(); }
 
     DECL_LINK(ReplyClicked, weld::Button&, void);
     DECL_LINK(ResolveClicked, weld::Toggleable&, void);
     DECL_LINK(OnFocusOut, weld::Widget&, void);
+    DECL_LINK(ContextMenuHdl, const MouseEvent&, bool);
 
     bool mbResolved;
 
@@ -127,10 +133,11 @@ public:
     void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
 
     void EditComment(Comment* pComment);
-
     void ToggleResolved(Comment* pComment);
-
     void ReplyComment(Comment* pComment);
+    void DeleteComment(Comment* pComment);
+    void DeleteThread(Comment* pComment);
+    void ResolveThread(Comment* pComment);
 
     DECL_LINK(FilterByAuthor, weld::ComboBox&, void);
     DECL_LINK(FilterByDate, SvtCalendarBox&, void);
diff --git a/sw/uiconfig/swriter/ui/commentcontextmenu.ui 
b/sw/uiconfig/swriter/ui/commentcontextmenu.ui
new file mode 100644
index 000000000000..675cc6c4e04b
--- /dev/null
+++ b/sw/uiconfig/swriter/ui/commentcontextmenu.ui
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.40.0 -->
+<interface domain="sw">
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkMenu" id="contextmenu">
+    <property name="visible">True</property>
+    <property name="can-focus">False</property>
+    <child>
+      <object class="GtkMenuItem" id="edit">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <property name="label" translatable="yes" 
context="contextmenu|edit">Edit</property>
+        <property name="use-underline">True</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkMenuItem" id="reply">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <property name="label" translatable="yes" 
context="contextmenu|reply">Reply</property>
+        <property name="use-underline">True</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkMenuItem" id="delete">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <property name="label" translatable="yes" 
context="contextmenu|delete">Delete</property>
+        <property name="use-underline">True</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkMenuItem" id="toggle_resolved">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <property name="label" translatable="yes" 
context="contextmenu|toggle_resolved">Toggle Resolved</property>
+        <property name="use-underline">True</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkSeparatorMenuItem" id="separator">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkMenuItem" id="delete_thread">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <property name="label" translatable="yes" 
context="contextmenu|delete_thread">Delete Thread</property>
+        <property name="use-underline">True</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkMenuItem" id="resolve_thread">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <property name="label" translatable="yes" 
context="contextmenu|resolve_thread">Resolve Thread</property>
+        <property name="use-underline">True</property>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/sw/uiconfig/swriter/ui/commentsthread.ui 
b/sw/uiconfig/swriter/ui/commentsthread.ui
index 9960a3fe63cb..ca5600fa767e 100644
--- a/sw/uiconfig/swriter/ui/commentsthread.ui
+++ b/sw/uiconfig/swriter/ui/commentsthread.ui
@@ -6,6 +6,7 @@
   <object class="GtkGrid" id="Thread">
     <property name="visible">True</property>
     <property name="can-focus">False</property>
+    <property name="margin-bottom">10</property>
     <child>
       <object class="GtkExpander">
         <property name="visible">True</property>
diff --git a/sw/uiconfig/swriter/ui/commentwidget.ui 
b/sw/uiconfig/swriter/ui/commentwidget.ui
index 7d0e66480eb4..5f5ba1172c8f 100644
--- a/sw/uiconfig/swriter/ui/commentwidget.ui
+++ b/sw/uiconfig/swriter/ui/commentwidget.ui
@@ -4,10 +4,12 @@
   <requires lib="gtk+" version="3.20"/>
   <!-- n-columns=1 n-rows=1 -->
   <object class="GtkGrid" id="Comment">
+    <property name="height-request">10</property>
     <property name="visible">True</property>
     <property name="can-focus">False</property>
+    <property name="margin-bottom">5</property>
     <child>
-      <object class="GtkExpander">
+      <object class="GtkExpander" id="expander">
         <property name="height-request">-1</property>
         <property name="visible">True</property>
         <property name="can-focus">True</property>

Reply via email to