summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Raykowski <raykowj@gmail.com>2022-12-17 00:21:28 -0900
committerJim Raykowski <raykowj@gmail.com>2022-12-27 06:33:36 +0000
commit9d387cc1e7848848c41f29ad91fee44ade79f678 (patch)
tree374362a3bdbf1149b95ed782cec9f2028c491135
parent033b22412ceccfac1150f9acd1758952d3cabf44 (diff)
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." Change-Id: If363340288de25aacbc28acd5858ce275f309af6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144406 Tested-by: Jenkins Reviewed-by: Jim Raykowski <raykowj@gmail.com>
-rw-r--r--sw/inc/doc.hxx2
-rw-r--r--sw/source/core/doc/doc.cxx24
-rw-r--r--sw/source/core/inc/rolbck.hxx2
-rw-r--r--sw/source/core/undo/unattr.cxx26
-rw-r--r--sw/source/uibase/utlui/content.cxx32
-rw-r--r--sw/uiconfig/swriter/ui/navigatorcontextmenu.ui10
6 files changed, 93 insertions, 3 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 80aa234cc6e3..8412f1aebf63 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1312,6 +1312,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 0c00640cc10c..07f54882fbdd 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>
@@ -1115,6 +1117,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 1497da7e7b89..3d3b224d03a5 100644
--- a/sw/source/core/inc/rolbck.hxx
+++ b/sw/source/core/inc/rolbck.hxx
@@ -159,7 +159,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 19929658e342..d8dc236c92e2 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)
@@ -571,6 +572,10 @@ void SwUndoResetAttr::UndoImpl(::sw::UndoRedoContext & rContext)
if( pTNd )
pTNd->DontExpandFormat( m_nSttContent, false );
}
+ else if (m_nFormatId == RES_TXTATR_REFMARK)
+ {
+ rDoc.GetEditShell()->SwViewShell::UpdateFields();
+ }
AddUndoRedoPaM(rContext);
}
@@ -621,6 +626,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;
}
}
diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx
index f68d6f089da6..c2220ad77f19 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -380,7 +380,7 @@ SwContentType::SwContentType(SwWrtShell* pShell, ContentTypeId nType, sal_uInt8
break;
case ContentTypeId::REFERENCE:
m_bEdit = false;
- m_bDelete = false;
+ m_bDelete = true;
break;
case ContentTypeId::URLFIELD:
m_bEdit = true;
@@ -1906,6 +1906,7 @@ IMPL_LINK(SwContentTree, CommandHdl, const CommandEvent&, rCEvt, bool)
bRemoveDeleteOLEObjectEntry = true,
bRemoveDeleteBookmarkEntry = true,
bRemoveDeleteHyperlinkEntry = true,
+ bRemoveDeleteReferenceEntry = true,
bRemoveDeleteIndexEntry= true,
bRemoveDeleteCommentEntry = true,
bRemoveDeleteDrawingObjectEntry = true,
@@ -2063,6 +2064,9 @@ IMPL_LINK(SwContentTree, CommandHdl, const CommandEvent&, rCEvt, bool)
case ContentTypeId::URLFIELD:
bRemoveDeleteHyperlinkEntry = false;
break;
+ case ContentTypeId::REFERENCE:
+ bRemoveDeleteReferenceEntry = false;
+ break;
case ContentTypeId::INDEX:
bRemoveDeleteIndexEntry = false;
break;
@@ -2204,6 +2208,8 @@ IMPL_LINK(SwContentTree, CommandHdl, const CommandEvent&, rCEvt, bool)
xPop->remove("deletebookmark");
if (bRemoveDeleteHyperlinkEntry)
xPop->remove("deletehyperlink");
+ if (bRemoveDeleteReferenceEntry)
+ xPop->remove("deletereference");
if (bRemoveDeleteIndexEntry)
xPop->remove("deleteindex");
if (bRemoveDeleteCommentEntry)
@@ -2221,6 +2227,7 @@ IMPL_LINK(SwContentTree, CommandHdl, const CommandEvent&, rCEvt, bool)
bRemoveDeleteOLEObjectEntry &&
bRemoveDeleteBookmarkEntry &&
bRemoveDeleteHyperlinkEntry &&
+ bRemoveDeleteReferenceEntry &&
bRemoveDeleteIndexEntry &&
bRemoveDeleteCommentEntry &&
bRemoveDeleteDrawingObjectEntry &&
@@ -4866,6 +4873,7 @@ void SwContentTree::ExecuteContextMenuAction(const OString& rSelectedPopupEntry)
rSelectedPopupEntry == "deleteoleobject" ||
rSelectedPopupEntry == "deletebookmark" ||
rSelectedPopupEntry == "deletehyperlink" ||
+ rSelectedPopupEntry == "deletereference" ||
rSelectedPopupEntry == "deleteindex" ||
rSelectedPopupEntry == "deletecomment" ||
rSelectedPopupEntry == "deletedrawingobject" ||
@@ -5396,6 +5404,28 @@ void SwContentTree::EditEntry(const weld::TreeIter& rEntry, EditEntryMode nMode)
nSlot = SID_EDIT_HYPERLINK;
break;
case ContentTypeId::REFERENCE:
+ {
+ if(nMode == EditEntryMode::DELETE)
+ {
+ const OUString& rName = pCnt->GetName();
+ for (SfxPoolItem* pItem :
+ m_pActiveShell->GetDoc()->GetAttrPool().GetItemSurrogates(RES_TXTATR_REFMARK))
+ {
+ assert(dynamic_cast<const SwFormatRefMark*>(pItem));
+ const auto pFormatRefMark = static_cast<const SwFormatRefMark*>(pItem);
+ if (!pFormatRefMark)
+ continue;
+ const SwTextRefMark* pTextRef = pFormatRefMark->GetTextRefMark();
+ if (pTextRef && &pTextRef->GetTextNode().GetNodes() ==
+ &m_pActiveShell->GetNodes() && rName == pFormatRefMark->GetRefName())
+ {
+ m_pActiveShell->GetDoc()->DeleteFormatRefMark(pFormatRefMark);
+ m_pActiveShell->SwViewShell::UpdateFields();
+ break;
+ }
+ }
+ }
+ }
break;
case ContentTypeId::TEXTFIELD:
{
diff --git a/sw/uiconfig/swriter/ui/navigatorcontextmenu.ui b/sw/uiconfig/swriter/ui/navigatorcontextmenu.ui
index 09e844553f24..519104ba5fdb 100644
--- a/sw/uiconfig/swriter/ui/navigatorcontextmenu.ui
+++ b/sw/uiconfig/swriter/ui/navigatorcontextmenu.ui
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.38.2 -->
+<!-- Generated with glade 3.40.0 -->
<interface domain="sw">
<requires lib="gtk+" version="3.20"/>
<object class="GtkMenu" id="navmenu">
@@ -193,6 +193,14 @@
</object>
</child>
<child>
+ <object class="GtkMenuItem" id="deletereference">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="label" translatable="yes" context="navigatorcontextmenu|STR_DELETE_REFERENCE">Delete Reference</property>
+ <accelerator key="Delete" signal="activate"/>
+ </object>
+ </child>
+ <child>
<object class="GtkMenuItem" id="deleteindex">
<property name="visible">True</property>
<property name="can-focus">False</property>