[Libreoffice-commits] core.git: sw/inc sw/source

Ashod Nakashian ashod.nakashian at collabora.co.uk
Wed Oct 25 02:52:51 UTC 2017


 sw/inc/editsh.hxx                 |    5 +++
 sw/source/core/edit/eddel.cxx     |    5 +++
 sw/source/core/edit/edfcol.cxx    |   55 ++++++++++++++++++++++++++++++--------
 sw/source/uibase/docvw/edtwin.cxx |    4 +-
 4 files changed, 56 insertions(+), 13 deletions(-)

New commits:
commit 141279127b4c9ced4d86af245e1d780c473cd5bb
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Fri Oct 20 23:45:03 2017 +0400

    TSCP: support removing paragraph metadata fields
    
    Currently only backspace is supported. No undo yet.
    
    Change-Id: I9a384d19bbaaaab05093d0d4ba74f089c6a4fae1
    Reviewed-on: https://gerrit.libreoffice.org/43630
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx
index 7a74b987e3e7..05648c40102d 100644
--- a/sw/inc/editsh.hxx
+++ b/sw/inc/editsh.hxx
@@ -388,6 +388,11 @@ public:
     /// Currently there are two variants: signature and classification.
     bool IsCursorInParagraphMetadataField() const;
 
+    /// Removes the paragraph metadata field at the current cursor, if any.
+    /// Returns true iff a paragraph metadata field was removed.
+    /// Currently there are two variants: signature and classification.
+    bool RemoveParagraphMetadataFieldAtCursor(const bool bBackspaceNotDel);
+
     void Insert2(SwField const &, const bool bForceExpandHints);
 
     void UpdateFields( SwField & );   ///< One single field.
diff --git a/sw/source/core/edit/eddel.cxx b/sw/source/core/edit/eddel.cxx
index 0254f2633681..a0e1c4bd6646 100644
--- a/sw/source/core/edit/eddel.cxx
+++ b/sw/source/core/edit/eddel.cxx
@@ -142,6 +142,11 @@ long SwEditShell::Delete()
         EndAllAction();
         nRet = 1;
     }
+    else
+    {
+        nRet = RemoveParagraphMetadataFieldAtCursor(true) ? 1 : 0;
+    }
+
     return nRet;
 }
 
diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx
index 8767a27d3588..939344960775 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -1513,31 +1513,64 @@ void SwEditShell::ValidateParagraphSignatures(bool updateDontRemove)
     }
 }
 
-bool SwEditShell::IsCursorInParagraphMetadataField() const
+uno::Reference<text::XTextField> lcl_GetParagraphMetadataFieldAtIndex(const SwDocShell* pDocSh, SwTextNode* pNode, const sal_uLong index)
 {
-    SwTextNode* pNode = GetCursor()->Start()->nNode.GetNode().GetTextNode();
-    if (pNode != nullptr)
+    uno::Reference<text::XTextField> xTextField;
+    if (pNode != nullptr && pDocSh != nullptr)
     {
-        SwTextAttr* pAttr = pNode->GetTextAttrAt(GetCursor()->Start()->nContent.GetIndex(), RES_TXTATR_METAFIELD);
+        SwTextAttr* pAttr = pNode->GetTextAttrAt(index, RES_TXTATR_METAFIELD);
         SwTextMeta* pTextMeta = static_txtattr_cast<SwTextMeta*>(pAttr);
         if (pTextMeta != nullptr)
         {
             SwFormatMeta& rFormatMeta(static_cast<SwFormatMeta&>(pTextMeta->GetAttr()));
             if (::sw::Meta* pMeta = rFormatMeta.GetMeta())
             {
-                if (const SwDocShell* pDocSh = GetDoc()->GetDocShell())
+                const css::uno::Reference<css::rdf::XResource> xSubject(pMeta->MakeUnoObject(), uno::UNO_QUERY);
+                uno::Reference<frame::XModel> xModel = pDocSh->GetBaseModel();
+                const std::map<OUString, OUString> aStatements = SwRDFHelper::getStatements(xModel, MetaNS, xSubject);
+                if (aStatements.find(ParagraphSignatureRDFName) != aStatements.end() ||
+                    aStatements.find(ParagraphClassificationNameRDFName) != aStatements.end())
                 {
-                    const css::uno::Reference<css::rdf::XResource> xSubject(pMeta->MakeUnoObject(), uno::UNO_QUERY);
-                    uno::Reference<frame::XModel> xModel = pDocSh->GetBaseModel();
-                    const std::map<OUString, OUString> aStatements = SwRDFHelper::getStatements(xModel, MetaNS, xSubject);
-                    if (aStatements.find(ParagraphSignatureRDFName) != aStatements.end() ||
-                        aStatements.find(ParagraphClassificationNameRDFName) != aStatements.end())
-                        return true;
+                    xTextField = uno::Reference<text::XTextField>(xSubject, uno::UNO_QUERY);
                 }
             }
         }
     }
 
+    return xTextField;
+}
+
+bool SwEditShell::IsCursorInParagraphMetadataField() const
+{
+    SwTextNode* pNode = GetCursor()->Start()->nNode.GetNode().GetTextNode();
+    const sal_uLong index = GetCursor()->Start()->nContent.GetIndex();
+    uno::Reference<text::XTextField> xField = lcl_GetParagraphMetadataFieldAtIndex(GetDoc()->GetDocShell(), pNode, index);
+    return xField.is();
+}
+
+bool SwEditShell::RemoveParagraphMetadataFieldAtCursor(const bool bBackspaceNotDel)
+{
+    SwTextNode* pNode = GetCursor()->Start()->nNode.GetNode().GetTextNode();
+    sal_uLong index = GetCursor()->Start()->nContent.GetIndex();
+    uno::Reference<text::XTextField> xField = lcl_GetParagraphMetadataFieldAtIndex(GetDoc()->GetDocShell(), pNode, index);
+    if (!xField.is())
+    {
+        // Try moving the cursor to see if we're _facing_ a metafield or not,
+        // as opposed to being within one.
+        if (bBackspaceNotDel)
+            index--; // Backspace moves left
+        else
+            index++; // Delete moves right
+
+        xField = lcl_GetParagraphMetadataFieldAtIndex(GetDoc()->GetDocShell(), pNode, index);
+    }
+
+    if (xField.is())
+    {
+        lcl_RemoveParagraphMetadataField(xField);
+        return true;
+    }
+
     return false;
 }
 
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index 1744dac0999c..803e959499df 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -1844,7 +1844,7 @@ KEYINPUT_CHECKTABLE_INSDEL:
                         if (rSh.IsInFrontOfLabel() && rSh.NumOrNoNum())
                             eKeyState = SwKeyState::NumOrNoNum;
                     }
-                    else
+                    else if (!rSh.IsCursorInParagraphMetadataField())
                     {
                         ScopedVclPtrInstance<MessageDialog>(this, "InfoReadonlyDialog",
                             "modules/swriter/ui/inforeadonlydialog.ui")->Execute();
@@ -2020,7 +2020,7 @@ KEYINPUT_CHECKTABLE_INSDEL:
                             }
                         }
                     }
-                    else
+                    else if (!rSh.IsCursorInParagraphMetadataField())
                     {
                         ScopedVclPtrInstance<MessageDialog>(this, "InfoReadonlyDialog",
                             "modules/swriter/ui/inforeadonlydialog.ui")->Execute();


More information about the Libreoffice-commits mailing list