[Libreoffice-commits] core.git: sd/source

Samuel Mehrbrodt (via logerrit) logerrit at kemper.freedesktop.org
Tue Jul 9 08:52:12 UTC 2019


 sd/source/ui/inc/DrawViewShell.hxx |    3 +
 sd/source/ui/view/drviews2.cxx     |   32 +---------------
 sd/source/ui/view/drviewsf.cxx     |   71 +++++++++++++++++++------------------
 3 files changed, 44 insertions(+), 62 deletions(-)

New commits:
commit 7a0164f0d82d91e2ac481d74cdacfe9a7ad6080f
Author:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Tue Jul 9 10:06:29 2019 +0200
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Tue Jul 9 10:51:08 2019 +0200

    tdf#111707 Move duplicated code into shared method
    
    Change-Id: I4b61ed876410662b5f85be0032b2fc8def456dd9
    Reviewed-on: https://gerrit.libreoffice.org/75286
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>

diff --git a/sd/source/ui/inc/DrawViewShell.hxx b/sd/source/ui/inc/DrawViewShell.hxx
index 713cac92c2fc..64bcabc7cc9c 100644
--- a/sd/source/ui/inc/DrawViewShell.hxx
+++ b/sd/source/ui/inc/DrawViewShell.hxx
@@ -485,6 +485,9 @@ private:
 
     void ConfigureAppBackgroundColor( svtools::ColorConfig* pColorConfig = nullptr );
 
+    // Select and return the field at the current cursor position
+    const SvxFieldData* GetFieldAtCursor();
+
     // The colour of the area behind the slide (used to be called "Wiese")
     Color mnAppBackgroundColor;
 };
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index 988fae4fc746..0cc9fef0a426 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -1154,37 +1154,11 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
                 OutlinerView* pOLV = mpDrawView->GetTextEditOutlinerView();
                 if (pOutl && pOLV)
                 {
-                    const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
-                    if (pFieldItem)
+                    const SvxFieldData* pField = GetFieldAtCursor();
+                    if( auto pUrlField = dynamic_cast< const SvxURLField *>( pField ) )
                     {
-                        // Make sure the whole field is selected
                         ESelection aSel = pOLV->GetSelection();
-                        if (aSel.nStartPos == aSel.nEndPos)
-                        {
-                            aSel.nEndPos++;
-                            pOLV->SetSelection(aSel);
-                        }
-                    }
-                    if (!pFieldItem)
-                    {
-                        // Cursor probably behind the field - extend selection to select the field
-                        ESelection aSel = pOLV->GetSelection();
-                        if (aSel.nStartPos == aSel.nEndPos)
-                        {
-                            aSel.nStartPos--;
-                            pOLV->SetSelection(aSel);
-                            pFieldItem = pOLV->GetFieldAtSelection();
-                        }
-                    }
-
-                    if (pFieldItem)
-                    {
-                        ESelection aSel = pOLV->GetSelection();
-                        const SvxFieldData* pField = pFieldItem->GetField();
-                        if( auto pUrlField = dynamic_cast< const SvxURLField *>( pField ) )
-                        {
-                            pOutl->QuickInsertText(pUrlField->GetRepresentation(), aSel);
-                        }
+                        pOutl->QuickInsertText(pUrlField->GetRepresentation(), aSel);
                     }
                 }
             }
diff --git a/sd/source/ui/view/drviewsf.cxx b/sd/source/ui/view/drviewsf.cxx
index dc6d8f97c3f2..4ae044433f0f 100644
--- a/sd/source/ui/view/drviewsf.cxx
+++ b/sd/source/ui/view/drviewsf.cxx
@@ -89,41 +89,14 @@ void DrawViewShell::GetCtrlState(SfxItemSet &rSet)
 
         if (pOLV)
         {
-            bool bField = false;
-            const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
-            if (pFieldItem)
+            const SvxFieldData* pField = GetFieldAtCursor();
+            if( auto pUrlField = dynamic_cast< const SvxURLField *>( pField ) )
             {
-                // Make sure the whole field is selected
-                ESelection aSel = pOLV->GetSelection();
-                if (aSel.nStartPos == aSel.nEndPos)
-                {
-                    aSel.nEndPos++;
-                    pOLV->SetSelection(aSel);
-                }
-            }
-            if (!pFieldItem)
-            {
-                // Cursor probably behind the field - extend selection to select the field
-                ESelection aSel = pOLV->GetSelection();
-                if (aSel.nStartPos == aSel.nEndPos)
-                {
-                    aSel.nStartPos--;
-                    pOLV->SetSelection(aSel);
-                    pFieldItem = pOLV->GetFieldAtSelection();
-                }
+                aHLinkItem.SetName(pUrlField->GetRepresentation());
+                aHLinkItem.SetURL(pUrlField->GetURL());
+                aHLinkItem.SetTargetFrame(pUrlField->GetTargetFrame());
             }
-            if (pFieldItem)
-            {
-                const SvxFieldData* pField = pFieldItem->GetField();
-                if( auto pUrlField = dynamic_cast< const SvxURLField *>( pField ) )
-                {
-                    aHLinkItem.SetName(pUrlField->GetRepresentation());
-                    aHLinkItem.SetURL(pUrlField->GetURL());
-                    aHLinkItem.SetTargetFrame(pUrlField->GetTargetFrame());
-                    bField = true;
-                }
-            }
-            if (!bField)
+            else
             {
                 // use selected text as name for urls
                 OUString sReturn = pOLV->GetSelected();
@@ -823,6 +796,38 @@ bool DrawViewShell::HasSelection(bool bText) const
     return bReturn;
 }
 
+const SvxFieldData* DrawViewShell::GetFieldAtCursor()
+{
+    OutlinerView* pOLV = mpDrawView->GetTextEditOutlinerView();
+    if (!pOLV)
+        return nullptr;
+
+    const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
+    if (pFieldItem)
+    {
+        // Make sure the whole field is selected
+        ESelection aSel = pOLV->GetSelection();
+        if (aSel.nStartPos == aSel.nEndPos)
+        {
+            aSel.nEndPos++;
+            pOLV->SetSelection(aSel);
+        }
+    }
+    if (!pFieldItem)
+    {
+        // Cursor probably behind the field - extend selection to select the field
+        ESelection aSel = pOLV->GetSelection();
+        if (aSel.nStartPos == aSel.nEndPos)
+        {
+            aSel.nStartPos--;
+            pOLV->SetSelection(aSel);
+            pFieldItem = pOLV->GetFieldAtSelection();
+        }
+    }
+
+    return pFieldItem ? pFieldItem->GetField() : nullptr;
+}
+
 } // end of namespace sd
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list