desktop/source/lib/init.cxx                                         |    1 
 officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu |   14 
 sfx2/source/control/unoctitm.cxx                                    |    1 
 sw/CppunitTest_sw_uibase_shells.mk                                  |    1 
 sw/inc/cmdid.h                                                      |    1 
 sw/qa/uibase/shells/textsh1.cxx                                     |  158 
++++++++++
 sw/sdi/_textsh.sdi                                                  |    6 
 sw/sdi/swriter.sdi                                                  |   14 
 sw/source/uibase/shells/textsh1.cxx                                 |   21 +
 sw/uiconfig/sglobal/popupmenu/text.xml                              |    1 
 sw/uiconfig/sweb/popupmenu/text.xml                                 |    1 
 sw/uiconfig/swform/popupmenu/text.xml                               |    1 
 sw/uiconfig/swreport/popupmenu/text.xml                             |    1 
 sw/uiconfig/swriter/popupmenu/text.xml                              |    1 
 sw/uiconfig/swxform/popupmenu/text.xml                              |    1 
 15 files changed, 223 insertions(+)

New commits:
commit ffc25dbd35f3eaccc965ccfc6389bb7c4c3b536f
Author:     codewithvk <[email protected]>
AuthorDate: Wed Nov 6 17:56:14 2024 +0530
Commit:     Miklos Vajna <[email protected]>
CommitDate: Wed Nov 6 15:39:49 2024 +0100

    Add unit tests for .uno:DeleteContentControl command
    
    - Added tests for deleting Rich Text, Checkbox, Dropdown, and Date content 
controls.
    - TODO: Add test for Picture content control.
    
    Signed-off-by: codewithvk <[email protected]>
    Change-Id: Icf423ab85d6a28c6c33412677fd1eb44d0ae94f2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176138
    Reviewed-by: Miklos Vajna <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/sw/CppunitTest_sw_uibase_shells.mk 
b/sw/CppunitTest_sw_uibase_shells.mk
index 2affe0205e7d..fdd8a8d7ce7b 100644
--- a/sw/CppunitTest_sw_uibase_shells.mk
+++ b/sw/CppunitTest_sw_uibase_shells.mk
@@ -16,6 +16,7 @@ $(eval $(call 
gb_CppunitTest_use_common_precompiled_header,sw_uibase_shells))
 $(eval $(call gb_CppunitTest_add_exception_objects,sw_uibase_shells, \
     sw/qa/uibase/shells/textfld \
     sw/qa/uibase/shells/textsh \
+    sw/qa/uibase/shells/textsh1 \
     sw/qa/uibase/shells/shells \
 ))
 
diff --git a/sw/qa/uibase/shells/textsh1.cxx b/sw/qa/uibase/shells/textsh1.cxx
new file mode 100644
index 000000000000..91db84d1a2e7
--- /dev/null
+++ b/sw/qa/uibase/shells/textsh1.cxx
@@ -0,0 +1,158 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <swmodeltestbase.hxx>
+
+#include <comphelper/propertyvalue.hxx>
+#include <comphelper/propertysequence.hxx>
+#include <comphelper/sequence.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/bindings.hxx>
+
+#include <docary.hxx>
+#include <docsh.hxx>
+#include <frmmgr.hxx>
+#include <wrtsh.hxx>
+#include <formatflysplit.hxx>
+#include <view.hxx>
+#include <cmdid.h>
+#include <formatcontentcontrol.hxx>
+#include <ndtxt.hxx>
+#include <textcontentcontrol.hxx>
+
+namespace
+{
+/// Covers sw/source/uibase/shells/textsh1.cxx fixes.
+class Test : public SwModelTestBase
+{
+public:
+    Test()
+        : SwModelTestBase("/sw/qa/uibase/shells/data/")
+    {
+    }
+};
+
+CPPUNIT_TEST_FIXTURE(Test, testDeleteRichTextContentControl)
+{
+    // Given an empty document
+    createSwDoc();
+    SwDoc* pDoc = getSwDoc();
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+
+    // When inserting a content control:
+    pWrtShell->InsertContentControl(SwContentControlType::RICH_TEXT);
+
+    // Then verify that the content control has been inserted
+    SwTextNode* pTextNode = 
pWrtShell->GetCursor()->GetPointNode().GetTextNode();
+    CPPUNIT_ASSERT(pTextNode->GetTextAttrForCharAt(0, 
RES_TXTATR_CONTENTCONTROL));
+
+    // And verify that there is text in the document
+    size_t nTextNodeLength = pTextNode->GetText().getLength();
+    CPPUNIT_ASSERT(nTextNodeLength > 0);
+
+    // And the content control manager has one content control
+    SwContentControlManager& rManager = pDoc->GetContentControlManager();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rManager.GetCount());
+
+    // When deleting the content control
+    dispatchCommand(mxComponent, ".uno:DeleteContentControl", {});
+
+    // Then verify that there are no content controls
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), rManager.GetCount());
+    CPPUNIT_ASSERT(!pTextNode->GetTextAttrForCharAt(0, 
RES_TXTATR_CONTENTCONTROL));
+    CPPUNIT_ASSERT_EQUAL(nTextNodeLength, 
static_cast<size_t>(pTextNode->GetText().getLength()));
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testDeleteCheckboxContentControl)
+{
+    // Given an empty document
+    createSwDoc();
+    SwDoc* pDoc = getSwDoc();
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+
+    // When inserting a content control:
+    pWrtShell->InsertContentControl(SwContentControlType::CHECKBOX);
+
+    // Then verify that a checkbox content control exists in the document
+    SwTextNode* pTextNode = 
pWrtShell->GetCursor()->GetPointNode().GetTextNode();
+    SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, 
RES_TXTATR_CONTENTCONTROL);
+    auto pTextContentControl = 
static_txtattr_cast<SwTextContentControl*>(pAttr);
+    auto& rFormatContentControl
+        = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr());
+    std::shared_ptr<SwContentControl> pContentControl = 
rFormatContentControl.GetContentControl();
+    CPPUNIT_ASSERT(pContentControl->GetCheckbox());
+
+    // And the content control manager has one content control
+    SwContentControlManager& rManager = pDoc->GetContentControlManager();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rManager.GetCount());
+
+    // When deleting the content control
+    dispatchCommand(mxComponent, ".uno:DeleteContentControl", {});
+
+    // Then verify that there are no content controls
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), rManager.GetCount());
+    CPPUNIT_ASSERT(!pTextNode->GetTextAttrForCharAt(0, 
RES_TXTATR_CONTENTCONTROL));
+
+    // And verify that text remains in the document
+    size_t nTextNodeLength = pTextNode->GetText().getLength();
+    CPPUNIT_ASSERT(nTextNodeLength > 0);
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testDeleteDropdownContentControl)
+{
+    // Create a document with a dropdown content control
+    createSwDoc();
+    SwDoc* pDoc = getSwDoc();
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->InsertContentControl(SwContentControlType::DROP_DOWN_LIST);
+
+    // Then verify that the content control manager has one content control
+    SwContentControlManager& rManager = pDoc->GetContentControlManager();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rManager.GetCount());
+
+    // When deleting the content control
+    dispatchCommand(mxComponent, ".uno:DeleteContentControl", {});
+
+    // Then verify that there are no content controls
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), rManager.GetCount());
+    SwTextNode* pTextNode = 
pWrtShell->GetCursor()->GetPointNode().GetTextNode();
+    CPPUNIT_ASSERT(!pTextNode->GetTextAttrForCharAt(0, 
RES_TXTATR_CONTENTCONTROL));
+
+    // And verify that text remains in the document
+    size_t nTextNodeLength = pTextNode->GetText().getLength();
+    CPPUNIT_ASSERT(nTextNodeLength > 0);
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testDeleteDateContentControl)
+{
+    // Create a document with a date content control
+    createSwDoc();
+    SwDoc* pDoc = getSwDoc();
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->InsertContentControl(SwContentControlType::DATE);
+
+    // Then verify that the content control manager has one content control
+    SwContentControlManager& rManager = pDoc->GetContentControlManager();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rManager.GetCount());
+
+    // When deleting the content control
+    dispatchCommand(mxComponent, ".uno:DeleteContentControl", {});
+
+    // Then verify that there are no content controls
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), rManager.GetCount());
+    SwTextNode* pTextNode = 
pWrtShell->GetCursor()->GetPointNode().GetTextNode();
+    CPPUNIT_ASSERT(!pTextNode->GetTextAttrForCharAt(0, 
RES_TXTATR_CONTENTCONTROL));
+
+    // And verify that text remains in the document
+    size_t nTextNodeLength = pTextNode->GetText().getLength();
+    CPPUNIT_ASSERT(nTextNodeLength > 0);
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 5d4ae3db293b0f9c46cbc09d0391806e1ed7b362
Author:     codewithvk <[email protected]>
AuthorDate: Fri Nov 1 19:28:51 2024 +0530
Commit:     Miklos Vajna <[email protected]>
CommitDate: Wed Nov 6 15:39:43 2024 +0100

    sw: add .uno:DeleteContentControl command
    
    This command removes formatting for content controls such as rich text, 
checkbox, dropdown, picture, and date controls. It deletes only the content 
control formatting, not the actual content of the section.
    
    Here are some todos:
            - Add test case for delete
            - undo/redo for this uno command
    
    Change-Id: Ib1b3b62ff7d62fd971472eff49a58c5afd786dc8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175927
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 39c6ab4002ff..439dbcb7a848 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -4029,6 +4029,7 @@ static void doc_iniUnoCommands ()
         u".uno:Protect"_ustr,
         u".uno:UnsetCellsReadOnly"_ustr,
         u".uno:ContentControlProperties"_ustr,
+        u".uno:DeleteContentControl"_ustr,
         u".uno:InsertCheckboxContentControl"_ustr,
         u".uno:InsertContentControl"_ustr,
         u".uno:InsertDateContentControl"_ustr,
diff --git 
a/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu 
b/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu
index 7720e9fe024f..3c541c1c8eea 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu
@@ -567,6 +567,20 @@
           <value>1</value>
         </prop>
       </node>
+      <node oor:name=".uno:DeleteContentControl" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">Delete Content Control</value>
+        </prop>
+        <prop oor:name="ContextLabel" oor:type="xs:string">
+          <value xml:lang="en-US">Delete Content Control</value>
+        </prop>
+        <prop oor:name="PopupLabel" oor:type="xs:string">
+          <value xml:lang="en-US">Delete Content Control</value>
+        </prop>
+        <prop oor:name="Properties" oor:type="xs:int">
+          <value>1</value>
+        </prop>
+      </node>
       <node oor:name=".uno:SetReminder" oor:op="replace">
         <prop oor:name="Label" oor:type="xs:string">
           <value xml:lang="en-US">Set Reminder</value>
diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
index e898f565f8ff..daac2ba3ac6c 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -1294,6 +1294,7 @@ constexpr auto handlers = 
frozen::make_unordered_map<std::u16string_view, Payloa
     { u"Protect", EnabledPayload },
     { u"UnsetCellsReadOnly", EnabledPayload },
     { u"ContentControlProperties", EnabledPayload },
+    { u"DeleteContentControl", EnabledPayload },
     { u"InsertCheckboxContentControl", EnabledPayload },
     { u"InsertContentControl", EnabledPayload },
     { u"InsertDateContentControl", EnabledPayload },
diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h
index e9796f028f6f..398d0eaa22e2 100644
--- a/sw/inc/cmdid.h
+++ b/sw/inc/cmdid.h
@@ -338,6 +338,7 @@ class SwUINumRuleItem;
 #define FN_DELETE_BOOKMARKS (FN_INSERT2 + 39)
 #define FN_DELETE_FIELDS (FN_INSERT2 + 40)
 #define FN_DELETE_SECTIONS (FN_INSERT2 + 41)
+#define FN_DELETE_CONTENT_CONTROL (FN_INSERT2 + 42) /* Delete content control 
formatting */
 
 // Region: Format
 #define FN_AUTOFORMAT_APPLY     (FN_FORMAT + 1 ) /* apply autoformat options */
diff --git a/sw/sdi/_textsh.sdi b/sw/sdi/_textsh.sdi
index 8c9aef9be2a1..d40c58ea6ba7 100644
--- a/sw/sdi/_textsh.sdi
+++ b/sw/sdi/_textsh.sdi
@@ -1880,6 +1880,12 @@ interface BaseText
         DisableFlags="SfxDisableFlags::SwOnProtectedCursor";
     ]
 
+    FN_DELETE_CONTENT_CONTROL
+    [
+        ExecMethod = Execute ;
+        StateMethod = GetState ;
+    ]
+
     FN_DELETE_FIELDS
     [
         ExecMethod = Execute ;
diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi
index 0068641cb3b6..82471bf14022 100644
--- a/sw/sdi/swriter.sdi
+++ b/sw/sdi/swriter.sdi
@@ -2651,6 +2651,20 @@ SfxVoidItem DeleteSections FN_DELETE_SECTIONS
     GroupId = SfxGroupId::Controls;
 ]
 
+SfxVoidItem DeleteContentControl FN_DELETE_CONTENT_CONTROL
+
+[
+    AutoUpdate = FALSE,
+    FastCall = FALSE,
+    ReadOnlyDoc = FALSE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+
+    GroupId = SfxGroupId::Controls;
+]
+
 SfxVoidItem DeleteFields FN_DELETE_FIELDS
 (SfxStringItem TypeName FN_PARAM_1, SfxStringItem NamePrefix FN_PARAM_2)
 [
diff --git a/sw/source/uibase/shells/textsh1.cxx 
b/sw/source/uibase/shells/textsh1.cxx
index 75506fbe863d..66a92416f3b0 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -70,6 +70,8 @@
 #include <swdtflvr.hxx>
 #include <swundo.hxx>
 #include <reffld.hxx>
+#include <textcontentcontrol.hxx>
+#include <txatbase.hxx>
 #include <docsh.hxx>
 #include <inputwin.hxx>
 #include <chrdlgmodes.hxx>
@@ -79,6 +81,7 @@
 #include <fldmgr.hxx>
 #include <strings.hrc>
 #include <paratr.hxx>
+#include <ndtxt.hxx>
 #include <vcl/svapp.hxx>
 #include <sfx2/app.hxx>
 #include <breakit.hxx>
@@ -554,6 +557,18 @@ void DeleteSections(SfxRequest& rReq, SwWrtShell& rWrtSh)
     }
 }
 
+void DeleteContentControl( SwWrtShell& rWrtSh )
+{
+    SwTextContentControl* pTextContentControl = 
rWrtSh.CursorInsideContentControl();
+    if (pTextContentControl) {
+        const SwFormatContentControl& rFormatContentControl = 
pTextContentControl->GetContentControl();
+        const std::shared_ptr<SwContentControl>& pContentControl = 
rFormatContentControl.GetContentControl();
+        pContentControl->SetReadWrite(true);
+        pTextContentControl->Delete(true);
+    }
+}
+
+
 void UpdateBookmarks(SfxRequest& rReq, SwWrtShell& rWrtSh)
 {
     if 
(rWrtSh.getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS))
@@ -1355,6 +1370,11 @@ void SwTextShell::Execute(SfxRequest &rReq)
             DeleteSections(rReq, rWrtSh);
             break;
         }
+        case FN_DELETE_CONTENT_CONTROL:
+        {
+            DeleteContentControl( rWrtSh );
+            break;
+        }
         case FN_SET_REMINDER:
         {
             // collect and sort navigator reminder names
@@ -4060,6 +4080,7 @@ void SwTextShell::GetState( SfxItemSet &rSet )
                 rSet.Put(SfxBoolItem(nWhich, bProtected));
             }
             break;
+            case FN_DELETE_CONTENT_CONTROL:
             case FN_CONTENT_CONTROL_PROPERTIES:
             {
                 if (!GetShell().CursorInsideContentControl())
diff --git a/sw/uiconfig/sglobal/popupmenu/text.xml 
b/sw/uiconfig/sglobal/popupmenu/text.xml
index 7170b7db12aa..209510f5fe6c 100644
--- a/sw/uiconfig/sglobal/popupmenu/text.xml
+++ b/sw/uiconfig/sglobal/popupmenu/text.xml
@@ -24,6 +24,7 @@
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:FieldDialog"/>
   <menu:menuitem menu:id=".uno:ContentControlProperties"/>
+  <menu:menuitem menu:id=".uno:DeleteContentControl"/>
   <menu:menuitem menu:id=".uno:EditFootnote"/>
   <menu:menuitem menu:id=".uno:IndexEntryDialog"/>
   <menu:menuitem menu:id=".uno:AuthoritiesEntryDialog"/>
diff --git a/sw/uiconfig/sweb/popupmenu/text.xml 
b/sw/uiconfig/sweb/popupmenu/text.xml
index 7170b7db12aa..209510f5fe6c 100644
--- a/sw/uiconfig/sweb/popupmenu/text.xml
+++ b/sw/uiconfig/sweb/popupmenu/text.xml
@@ -24,6 +24,7 @@
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:FieldDialog"/>
   <menu:menuitem menu:id=".uno:ContentControlProperties"/>
+  <menu:menuitem menu:id=".uno:DeleteContentControl"/>
   <menu:menuitem menu:id=".uno:EditFootnote"/>
   <menu:menuitem menu:id=".uno:IndexEntryDialog"/>
   <menu:menuitem menu:id=".uno:AuthoritiesEntryDialog"/>
diff --git a/sw/uiconfig/swform/popupmenu/text.xml 
b/sw/uiconfig/swform/popupmenu/text.xml
index 7170b7db12aa..209510f5fe6c 100644
--- a/sw/uiconfig/swform/popupmenu/text.xml
+++ b/sw/uiconfig/swform/popupmenu/text.xml
@@ -24,6 +24,7 @@
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:FieldDialog"/>
   <menu:menuitem menu:id=".uno:ContentControlProperties"/>
+  <menu:menuitem menu:id=".uno:DeleteContentControl"/>
   <menu:menuitem menu:id=".uno:EditFootnote"/>
   <menu:menuitem menu:id=".uno:IndexEntryDialog"/>
   <menu:menuitem menu:id=".uno:AuthoritiesEntryDialog"/>
diff --git a/sw/uiconfig/swreport/popupmenu/text.xml 
b/sw/uiconfig/swreport/popupmenu/text.xml
index 4b31d6d34f7d..e99e2653a3a1 100644
--- a/sw/uiconfig/swreport/popupmenu/text.xml
+++ b/sw/uiconfig/swreport/popupmenu/text.xml
@@ -29,6 +29,7 @@
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:FieldDialog"/>
   <menu:menuitem menu:id=".uno:ContentControlProperties"/>
+  <menu:menuitem menu:id=".uno:DeleteContentControl"/>
   <menu:menuitem menu:id=".uno:EditFootnote"/>
   <menu:menuitem menu:id=".uno:IndexEntryDialog"/>
   <menu:menuitem menu:id=".uno:AuthoritiesEntryDialog"/>
diff --git a/sw/uiconfig/swriter/popupmenu/text.xml 
b/sw/uiconfig/swriter/popupmenu/text.xml
index 75ccb4e6db14..9b62d6978e02 100644
--- a/sw/uiconfig/swriter/popupmenu/text.xml
+++ b/sw/uiconfig/swriter/popupmenu/text.xml
@@ -25,6 +25,7 @@
   <menu:menuitem menu:id=".uno:UpdateSelectedField"/>
   <menu:menuitem menu:id=".uno:FieldDialog"/>
   <menu:menuitem menu:id=".uno:ContentControlProperties"/>
+  <menu:menuitem menu:id=".uno:DeleteContentControl"/>
   <menu:menuitem menu:id=".uno:EditFootnote"/>
   <menu:menuitem menu:id=".uno:IndexEntryDialog"/>
   <menu:menuitem menu:id=".uno:AuthoritiesEntryDialog"/>
diff --git a/sw/uiconfig/swxform/popupmenu/text.xml 
b/sw/uiconfig/swxform/popupmenu/text.xml
index 199f69eac465..004b2f3717f2 100644
--- a/sw/uiconfig/swxform/popupmenu/text.xml
+++ b/sw/uiconfig/swxform/popupmenu/text.xml
@@ -24,6 +24,7 @@
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:FieldDialog"/>
   <menu:menuitem menu:id=".uno:ContentControlProperties"/>
+  <menu:menuitem menu:id=".uno:DeleteContentControl"/>
   <menu:menuitem menu:id=".uno:EditFootnote"/>
   <menu:menuitem menu:id=".uno:IndexEntryDialog"/>
   <menu:menuitem menu:id=".uno:AuthoritiesEntryDialog"/>

Reply via email to