sw/inc/doc.hxx                 |    2 ++
 sw/source/core/doc/doc.cxx     |   24 ++++++++++++++++++++++++
 sw/source/core/inc/rolbck.hxx  |    2 +-
 sw/source/core/undo/unattr.cxx |   26 ++++++++++++++++++++++++++
 4 files changed, 53 insertions(+), 1 deletion(-)

New commits:
commit 4eb955f2436ef1c8979bd10d28a77adde3966dd6
Author:     Jim Raykowski <rayk...@gmail.com>
AuthorDate: Sat Dec 17 00:21:28 2022 -0900
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Jan 16 18:46:52 2023 +0000

    tdf#140666 Make delete reference possible from the Navigator
    
    This patch makes it possible to delete a reference without having to do
    the steps given in the help.
    
    "References are fields. To remove a reference, delete the field. If you
    set a longer text as a reference and you do not want to re-enter it
    after deleting the reference, select the text and copy it to the
    clipboard. You can then reinsert it as "unformatted text" at the same
    position using the command Edit - Paste special. The text remains
    intact while the reference is deleted."
    
    (cherry picked from commit 9d387cc1e7848848c41f29ad91fee44ade79f678)
    
    Conflicts:
            sw/source/uibase/utlui/content.cxx
            sw/uiconfig/swriter/ui/navigatorcontextmenu.ui
    
    Change-Id: If363340288de25aacbc28acd5858ce275f309af6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145559
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 72025d5160e1..3abf8e4e9536 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1309,6 +1309,8 @@ public:
      If array pointer is 0 return only whether a RefMark is set in document. */
     sal_uInt16 GetRefMarks( std::vector<OUString>* = nullptr ) const;
 
+    void DeleteFormatRefMark(const SwFormatRefMark* pFormatRefMark);
+
     // Insert label. If a FlyFormat is created, return it.
     SwFlyFrameFormat* InsertLabel( const SwLabelType eType, const OUString 
&rText, const OUString& rSeparator,
                     const OUString& rNumberingSeparator,
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index 571a9bb75c4c..938986058a72 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -68,6 +68,8 @@
 #include <pam.hxx>
 #include <ndtxt.hxx>
 #include <swundo.hxx>
+#include <rolbck.hxx>
+#include <UndoAttribute.hxx>
 #include <UndoCore.hxx>
 #include <UndoTable.hxx>
 #include <pagedesc.hxx>
@@ -1114,6 +1116,28 @@ sal_uInt16 SwDoc::GetRefMarks( std::vector<OUString>* 
pNames ) const
     return nCount;
 }
 
+void SwDoc::DeleteFormatRefMark(const SwFormatRefMark* pFormatRefMark)
+{
+    const SwTextRefMark* pTextRefMark = pFormatRefMark->GetTextRefMark();
+    SwTextNode& rTextNd = const_cast<SwTextNode&>(pTextRefMark->GetTextNode());
+    std::unique_ptr<SwRegHistory> aRegHistory;
+    if (GetIDocumentUndoRedo().DoesUndo())
+    {
+        SwUndoResetAttr* pUndo = new SwUndoResetAttr(SwPosition(rTextNd, 
pTextRefMark->GetStart()),
+                                                     RES_TXTATR_REFMARK);
+        GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndo>(pUndo));
+        aRegHistory.reset(new SwRegHistory(rTextNd, &pUndo->GetHistory()));
+        rTextNd.GetpSwpHints()->Register(aRegHistory.get());
+    }
+    rTextNd.DeleteAttribute(const_cast<SwTextRefMark*>(pTextRefMark));
+    if (GetIDocumentUndoRedo().DoesUndo())
+    {
+        if (rTextNd.GetpSwpHints())
+            rTextNd.GetpSwpHints()->DeRegister();
+    }
+    getIDocumentState().SetModified();
+}
+
 static bool lcl_SpellAndGrammarAgain( SwNode* pNd, void* pArgs )
 {
     SwTextNode *pTextNode = pNd->GetTextNode();
diff --git a/sw/source/core/inc/rolbck.hxx b/sw/source/core/inc/rolbck.hxx
index 75554884341e..fb03e76fa8ea 100644
--- a/sw/source/core/inc/rolbck.hxx
+++ b/sw/source/core/inc/rolbck.hxx
@@ -160,7 +160,7 @@ class SwHistorySetRefMark final : public SwHistoryHint
 public:
     SwHistorySetRefMark( const SwTextRefMark* pTextHt, SwNodeOffset nNode );
     virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) override;
-
+    const OUString& GetRefName() {return m_RefName;}
 };
 
 class SwHistorySetTOXMark final : public SwHistoryHint
diff --git a/sw/source/core/undo/unattr.cxx b/sw/source/core/undo/unattr.cxx
index 9d279860c086..bb2cdcaa34bb 100644
--- a/sw/source/core/undo/unattr.cxx
+++ b/sw/source/core/undo/unattr.cxx
@@ -55,6 +55,7 @@
 #include <charfmt.hxx>
 #include <calbck.hxx>
 #include <frameformats.hxx>
+#include <editsh.hxx>
 
 SwUndoFormatAttrHelper::SwUndoFormatAttrHelper(SwFormat& rFormat, bool 
bSvDrwPt)
     : SwClient(&rFormat)
@@ -575,6 +576,10 @@ void SwUndoResetAttr::UndoImpl(::sw::UndoRedoContext & 
rContext)
             pTNd->DontExpandFormat( aIdx, false );
         }
     }
+    else if (m_nFormatId == RES_TXTATR_REFMARK)
+    {
+        rDoc.GetEditShell()->SwViewShell::UpdateFields();
+    }
 
     AddUndoRedoPaM(rContext);
 }
@@ -626,6 +631,27 @@ void SwUndoResetAttr::RedoImpl(::sw::UndoRedoContext & 
rContext)
         }
     }
     break;
+    case RES_TXTATR_REFMARK:
+    {
+        SfxItemPool::Item2Range aRange = 
rDoc.GetAttrPool().GetItemSurrogates(RES_TXTATR_REFMARK);
+        SwHistoryHint* pHistoryHint = GetHistory()[0];
+        if (pHistoryHint && HSTRY_SETREFMARKHNT == pHistoryHint->Which())
+        {
+            for (const SfxPoolItem* pItem : aRange)
+            {
+                assert(dynamic_cast<const SwFormatRefMark*>(pItem));
+                const auto pFormatRefMark = static_cast<const 
SwFormatRefMark*>(pItem);
+                if 
(static_cast<SwHistorySetRefMark*>(pHistoryHint)->GetRefName() ==
+                        pFormatRefMark->GetRefName())
+                {
+                    rDoc.DeleteFormatRefMark(pFormatRefMark);
+                    rDoc.GetEditShell()->SwViewShell::UpdateFields();
+                    break;
+                }
+            }
+        }
+    }
+    break;
     }
 }
 

Reply via email to