officecfg/registry/schema/org/openoffice/Office/Common.xcs |    7 ++
 sw/inc/strings.hrc                                         |    6 ++
 sw/source/uibase/docvw/PostItMgr.cxx                       |   34 +++++++++++++
 3 files changed, 46 insertions(+), 1 deletion(-)

New commits:
commit 70e9083c0e511ae845a43b6ceaf9e79ee47ab880
Author:     Heiko Tietze <tietze.he...@gmail.com>
AuthorDate: Wed Jan 22 15:38:02 2025 +0100
Commit:     Heiko Tietze <heiko.tie...@documentfoundation.org>
CommitDate: Fri Jan 24 10:11:27 2025 +0100

    Resolves tdf#164586 - Confirm 'Delete all comments'
    
    Option Common::Misc::QueryDeleteAllComments added but
    with default false to keep the familiar workflow and
    to prevent macros to fails
    
    Change-Id: I9424d900d226b7b757701f5f16209a0241adf7cf
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180596
    Reviewed-by: Heiko Tietze <heiko.tie...@documentfoundation.org>
    Tested-by: Jenkins

diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs 
b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
index 61dba68ab1af..b457d92e02c9 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
@@ -5388,12 +5388,17 @@
           <value>-1</value>
       </prop>
       <prop oor:name="QuerySetInsMode" oor:type="xs:boolean" 
oor:nillable="false">
-        <!-- UIHints: Tools - Options - General -->
         <info>
           <desc>Determines whether to query when switching into the overwrite 
mode.</desc>
         </info>
         <value>true</value>
       </prop>
+      <prop oor:name="QueryDeleteAllComments" oor:type="xs:boolean" 
oor:nillable="false">
+        <info>
+          <desc>Determines whether to confirm delete all comments or all by 
user.</desc>
+        </info>
+        <value>false</value>
+      </prop>
       <prop oor:name="PerformFileExtCheck" oor:type="xs:boolean" 
oor:nillable="false">
         <!-- UIHints: Tools - Options - General -->
         <info>
diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc
index 633efd926094..2a478f49afea 100644
--- a/sw/inc/strings.hrc
+++ b/sw/inc/strings.hrc
@@ -1552,6 +1552,12 @@
 #define STR_QUERY_INSMODE_TITLE NC_("STR_QUERY_INSMODE_TITLE", "You are 
switching to the overwrite mode")
 #define STR_QUERY_INSMODE_TEXT NC_("STR_QUERY_INSMODE_TEXT", "The overwrite 
mode allows to type over text. It is indicated by a block cursor and at the 
statusbar. Press Insert again to switch back.")
 #define STR_QUERY_INSMODE_QUESTION NC_("STR_QUERY_INSMODE_QUESTION", "Do you 
want to continue?")
+
+// To translators: title and question for confirmation whether to delete all 
comments / all comments by author; text intentionally empty
+#define STR_QUERY_DELALLCOMMENTS_TITLE NC_("STR_QUERY_DELALLCOMMENTS_TITLE", 
"Confirm delete")
+#define STR_QUERY_DELALLCOMMENTS_QUESTION 
NC_("STR_QUERY_DELALLCOMMENTS_QUESTION", "Are you sure you want to delete all 
comments?")
+#define STR_QUERY_DELALLCOMMENTSAUTHOR_QUESTION 
NC_("STR_QUERY_DELALLCOMMENTS_QUESTION", "Are you sure you want to delete all 
comments by %AUTHOR?")
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx 
b/sw/source/uibase/docvw/PostItMgr.cxx
index 97098f197283..5e3ccb5857ef 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -82,6 +82,8 @@
 #include <annotsh.hxx>
 #include <swabstdlg.hxx>
 #include <pagefrm.hxx>
+#include <officecfg/Office/Common.hxx>
+
 #include <memory>
 
 // distance between Anchor Y and initial note position
@@ -1584,11 +1586,40 @@ void SwPostItMgr::RemoveSidebarWin()
     PreparePageContainer();
 }
 
+static bool ConfirmDeleteAll(SwView& pView, const OUString& sText)
+{
+    const bool bAsk = 
officecfg::Office::Common::Misc::QueryDeleteAllComments::get();
+    bool bConfirm = true;
+    if (bAsk)
+    {
+        VclAbstractDialogFactory* pFact = VclAbstractDialogFactory::Create();
+        auto pDlg
+            = pFact->CreateQueryDialog(pView.GetFrameWeld(),
+                                       
SwResId(STR_QUERY_DELALLCOMMENTS_TITLE), sText, "", true);
+        sal_Int32 nResult = pDlg->Execute();
+        if (pDlg->ShowAgain() == false)
+        {
+            std::shared_ptr<comphelper::ConfigurationChanges> xChanges(
+                comphelper::ConfigurationChanges::create());
+            
officecfg::Office::Common::Misc::QueryDeleteAllComments::set(false, xChanges);
+            xChanges->commit();
+        }
+        bConfirm = (nResult == RET_YES);
+        pDlg->disposeOnce();
+    }
+    return bConfirm;
+}
+
 // copy to new vector, otherwise RemoveItem would operate and delete stuff on 
mvPostItFields as well
 // RemoveItem will clean up the core field and visible postit if necessary
 // we cannot just delete everything as before, as postits could move into 
change tracking
 void SwPostItMgr::Delete(const OUString& rAuthor)
 {
+    OUString sQuestion = SwResId(STR_QUERY_DELALLCOMMENTSAUTHOR_QUESTION);
+    sQuestion = sQuestion.replaceAll("%AUTHOR", rAuthor);
+    if (!ConfirmDeleteAll(mpWrtShell->GetView(), sQuestion))
+        return;
+
     mpWrtShell->StartAllAction();
     if (HasActiveSidebarWin() && (GetActiveSidebarWin()->GetAuthor() == 
rAuthor))
     {
@@ -1719,6 +1750,9 @@ void SwPostItMgr::ToggleResolvedForThread(sal_uInt32 
nPostItId)
 
 void SwPostItMgr::Delete()
 {
+    if (!ConfirmDeleteAll(mpWrtShell->GetView(), 
SwResId(STR_QUERY_DELALLCOMMENTS_QUESTION)))
+        return;
+
     mpWrtShell->StartAllAction();
     SetActiveSidebarWin(nullptr);
     SwRewriter aRewriter;

Reply via email to