editeng/source/misc/urlfieldhelper.cxx |   28 +++++++++++++++++-----------
 include/editeng/urlfieldhelper.hxx     |    5 +++--
 sc/source/ui/drawfunc/drtxtob.cxx      |    6 ++----
 sc/source/ui/view/editsh.cxx           |   17 +++++------------
 sd/source/ui/view/drviews2.cxx         |    3 +--
 sd/source/ui/view/drviews7.cxx         |   15 +++------------
 sd/source/ui/view/drviewsf.cxx         |    2 +-
 sw/source/uibase/shells/drwtxtex.cxx   |    7 ++-----
 8 files changed, 34 insertions(+), 49 deletions(-)

New commits:
commit f7d4d2a7a824801796c54debaf70c6e0efb76a89
Author:     Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
AuthorDate: Thu Dec 5 09:58:10 2019 +0100
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
CommitDate: Fri Dec 6 08:17:40 2019 +0100

    Fix "Open Hyperlink" context menu in sc
    
    Change-Id: I05fce087d20123447c1e5bd0f27db8d1c9ef3641
    Reviewed-on: https://gerrit.libreoffice.org/84518
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
    (cherry picked from commit 069a45e661086d1014855ca4f7ad384ba5752bb6)
    Reviewed-on: https://gerrit.libreoffice.org/84577

diff --git a/sc/source/ui/view/editsh.cxx b/sc/source/ui/view/editsh.cxx
index 80a7bf1cdea2..61888c663ef4 100644
--- a/sc/source/ui/view/editsh.cxx
+++ b/sc/source/ui/view/editsh.cxx
@@ -623,7 +623,7 @@ void ScEditShell::Execute( SfxRequest& rReq )
                 {
                     const SvxURLField* pURLField = GetURLField();
                     if ( pURLField )
-                        ScGlobal::OpenURL( pURLField->GetURL(), 
pURLField->GetTargetFrame() );
+                        ScGlobal::OpenURL( pURLField->GetURL(), 
pURLField->GetTargetFrame(), true );
                     return;
                 }
         case SID_EDIT_HYPERLINK:
commit 64233bbaa0e91ddf14d59ae7547df6bbfa60adcc
Author:     Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
AuthorDate: Wed Dec 4 15:19:00 2019 +0100
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
CommitDate: Fri Dec 6 08:17:10 2019 +0100

    tdf#128666 Only enable hyperlink actions when just the field is selected
    
    Change-Id: I984df967877a47fb9f89c3626737348a87d3ffa5
    Reviewed-on: https://gerrit.libreoffice.org/84418
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
    (cherry picked from commit f31c3ebb60e4678eb09e377b638b368531df47dc)
    Reviewed-on: https://gerrit.libreoffice.org/84571

diff --git a/editeng/source/misc/urlfieldhelper.cxx 
b/editeng/source/misc/urlfieldhelper.cxx
index 6df7171e14c0..564bc54e781e 100644
--- a/editeng/source/misc/urlfieldhelper.cxx
+++ b/editeng/source/misc/urlfieldhelper.cxx
@@ -11,27 +11,33 @@
 
 #include <editeng/flditem.hxx>
 #include <editeng/editview.hxx>
+#include <editeng/editeng.hxx>
 
-void URLFieldHelper::RemoveURLField(Outliner* pOutl, const OutlinerView* pOLV)
+void URLFieldHelper::RemoveURLField(EditView& pEditView)
 {
-    if (!pOutl || !pOLV)
-        return;
-
-    const SvxFieldData* pField = pOLV->GetFieldAtCursor();
+    pEditView.SelectFieldAtCursor();
+    const SvxFieldData* pField = pEditView.GetFieldAtCursor();
     if (auto pUrlField = dynamic_cast<const SvxURLField*>(pField))
     {
-        ESelection aSel = pOLV->GetSelection();
-        pOutl->QuickInsertText(pUrlField->GetRepresentation(), aSel);
-        pOLV->GetEditView().Invalidate();
+        ESelection aSel = pEditView.GetSelection();
+        
pEditView.GetEditEngine()->QuickInsertText(pUrlField->GetRepresentation(), 
aSel);
+        pEditView.Invalidate();
     }
 }
 
-bool URLFieldHelper::IsCursorAtURLField(const OutlinerView* pOLV)
+bool URLFieldHelper::IsCursorAtURLField(const EditView& pEditView)
 {
-    if (!pOLV)
+    // tdf#128666 Make sure only URL field (or nothing) is selected
+    ESelection aSel = pEditView.GetSelection();
+    auto nSelectedParas = aSel.nEndPara - aSel.nStartPara;
+    auto nSelectedChars = aSel.nEndPos - aSel.nStartPos;
+    bool bIsValidSelection
+        = nSelectedParas == 0
+          && (nSelectedChars == 0 || nSelectedChars == 1 || nSelectedChars == 
-1);
+    if (!bIsValidSelection)
         return false;
 
-    const SvxFieldData* pField = pOLV->GetFieldAtCursor();
+    const SvxFieldData* pField = pEditView.GetFieldAtCursor();
     if (dynamic_cast<const SvxURLField*>(pField))
         return true;
 
diff --git a/include/editeng/urlfieldhelper.hxx 
b/include/editeng/urlfieldhelper.hxx
index 547e2654ea9b..e6c7c92935a4 100644
--- a/include/editeng/urlfieldhelper.hxx
+++ b/include/editeng/urlfieldhelper.hxx
@@ -12,12 +12,13 @@
 #include <sal/config.h>
 #include <editeng/editengdllapi.h>
 #include <editeng/outliner.hxx>
+#include <editeng/editview.hxx>
 
 class EDITENG_DLLPUBLIC URLFieldHelper
 {
 public:
-    static void RemoveURLField(Outliner* pOutl, const OutlinerView* pOLV);
-    static bool IsCursorAtURLField(const OutlinerView* pOLV);
+    static void RemoveURLField(EditView& pEditView);
+    static bool IsCursorAtURLField(const EditView& pEditView);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/sc/source/ui/drawfunc/drtxtob.cxx 
b/sc/source/ui/drawfunc/drtxtob.cxx
index daf58d072eea..6cc27d4368c3 100644
--- a/sc/source/ui/drawfunc/drtxtob.cxx
+++ b/sc/source/ui/drawfunc/drtxtob.cxx
@@ -326,8 +326,7 @@ void ScDrawTextObjectBar::Execute( SfxRequest &rReq )
         case SID_REMOVE_HYPERLINK:
             {
                 // Ensure the field is selected first
-                pOutView->SelectFieldAtCursor();
-                URLFieldHelper::RemoveURLField(pOutliner, pOutView);
+                URLFieldHelper::RemoveURLField(pOutView->GetEditView());
             }
             break;
 
@@ -412,8 +411,7 @@ void ScDrawTextObjectBar::GetState( SfxItemSet& rSet )
         || rSet.GetItemState(SID_REMOVE_HYPERLINK) != SfxItemState::UNKNOWN)
     {
         SdrView* pView = pViewData->GetScDrawView();
-        OutlinerView* pOutView = pView->GetTextEditOutlinerView();
-        if( !URLFieldHelper::IsCursorAtURLField(pOutView) )
+        if( 
!URLFieldHelper::IsCursorAtURLField(pView->GetTextEditOutlinerView()->GetEditView())
 )
         {
             rSet.DisableItem( SID_OPEN_HYPERLINK );
             rSet.DisableItem( SID_EDIT_HYPERLINK );
diff --git a/sc/source/ui/view/editsh.cxx b/sc/source/ui/view/editsh.cxx
index ebcde629df8b..80a7bf1cdea2 100644
--- a/sc/source/ui/view/editsh.cxx
+++ b/sc/source/ui/view/editsh.cxx
@@ -33,6 +33,7 @@
 #include <editeng/flditem.hxx>
 #include <editeng/flstitem.hxx>
 #include <editeng/fontitem.hxx>
+#include <editeng/urlfieldhelper.hxx>
 #include <svx/hlnkitem.hxx>
 #include <vcl/EnumContext.hxx>
 #include <editeng/postitem.hxx>
@@ -646,15 +647,7 @@ void ScEditShell::Execute( SfxRequest& rReq )
         break;
         case SID_REMOVE_HYPERLINK:
             {
-                // Ensure the field is selected first
-                pEditView->SelectFieldAtCursor();
-                const SvxURLField* pURLField = GetURLField();
-                if (pURLField)
-                {
-                    ESelection aSel = pEditView->GetSelection();
-                    
pEditView->GetEditEngine()->QuickInsertText(pURLField->GetRepresentation(), 
aSel);
-                }
-
+                URLFieldHelper::RemoveURLField(*pEditView);
             }
         break;
 
@@ -786,8 +779,8 @@ void ScEditShell::GetState( SfxItemSet& rSet )
             case SID_COPY_HYPERLINK_LOCATION:
             case SID_REMOVE_HYPERLINK:
                 {
-                    if ( !GetURLField() )
-                        rSet.DisableItem( nWhich );
+                    if (!URLFieldHelper::IsCursorAtURLField(*pEditView))
+                        rSet.DisableItem (nWhich);
                 }
                 break;
 
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index 2be1ccd2c6c2..b2ba46958b5d 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -1200,8 +1200,7 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
                 OutlinerView* pOutView = mpDrawView->GetTextEditOutlinerView();
                 if (pOutView)
                     pOutView->SelectFieldAtCursor();
-                
URLFieldHelper::RemoveURLField(mpDrawView->GetTextEditOutliner(),
-                                               
mpDrawView->GetTextEditOutlinerView());
+                URLFieldHelper::RemoveURLField(pOutView->GetEditView());
             }
         }
         Cancel();
diff --git a/sd/source/ui/view/drviews7.cxx b/sd/source/ui/view/drviews7.cxx
index 7372d2327ff0..0874a587a3a1 100644
--- a/sd/source/ui/view/drviews7.cxx
+++ b/sd/source/ui/view/drviews7.cxx
@@ -33,6 +33,7 @@
 #include <editeng/flditem.hxx>
 #include <editeng/outlobj.hxx>
 #include <editeng/sizeitem.hxx>
+#include <editeng/urlfieldhelper.hxx>
 #include <officecfg/Office/Impress.hxx>
 #include <svx/svxids.hrc>
 #include <svx/svdpagv.hxx>
@@ -1449,18 +1450,8 @@ void DrawViewShell::GetMenuState( SfxItemSet &rSet )
         if( mpDrawView->IsTextEdit() )
         {
             OutlinerView* pOLV = mpDrawView->GetTextEditOutlinerView();
-            if (pOLV)
-            {
-                const SvxFieldItem* pFieldItem = 
pOLV->GetFieldUnderMousePointer();
-                if (!pFieldItem)
-                    pFieldItem = pOLV->GetFieldAtSelection();
-                if (pFieldItem)
-                {
-                    const SvxFieldData* pField = pFieldItem->GetField();
-                    if (dynamic_cast<const SvxURLField*>(pField))
-                        bDisableEditHyperlink = false;
-                }
-            }
+            if (pOLV && 
URLFieldHelper::IsCursorAtURLField(pOLV->GetEditView()))
+                bDisableEditHyperlink = false;
         }
         else
         {
diff --git a/sd/source/ui/view/drviewsf.cxx b/sd/source/ui/view/drviewsf.cxx
index 565283ce1c3a..5533c62510b8 100644
--- a/sd/source/ui/view/drviewsf.cxx
+++ b/sd/source/ui/view/drviewsf.cxx
@@ -505,7 +505,7 @@ void DrawViewShell::GetAttrState( SfxItemSet& rSet )
 
             case SID_REMOVE_HYPERLINK:
             {
-                if 
(!URLFieldHelper::IsCursorAtURLField(mpDrawView->GetTextEditOutlinerView()))
+                if 
(!URLFieldHelper::IsCursorAtURLField(mpDrawView->GetTextEditOutlinerView()->GetEditView()))
                     rSet.DisableItem(nWhich);
             }
             break;
diff --git a/sw/source/uibase/shells/drwtxtex.cxx 
b/sw/source/uibase/shells/drwtxtex.cxx
index d91e90b94d25..fc1f4175357d 100644
--- a/sw/source/uibase/shells/drwtxtex.cxx
+++ b/sw/source/uibase/shells/drwtxtex.cxx
@@ -536,10 +536,7 @@ void SwDrawTextShell::Execute( SfxRequest &rReq )
 
         case SID_REMOVE_HYPERLINK:
         {
-            // Ensure the field is selected first
-            pOLV->SelectFieldAtCursor();
-            URLFieldHelper::RemoveURLField(pSdrView->GetTextEditOutliner(),
-                                           pOLV);
+            URLFieldHelper::RemoveURLField(pOLV->GetEditView());
         }
         break;
 
@@ -979,7 +976,7 @@ void SwDrawTextShell::GetState(SfxItemSet& rSet)
             case SID_OPEN_HYPERLINK:
             case SID_COPY_HYPERLINK_LOCATION:
             {
-                if (!URLFieldHelper::IsCursorAtURLField(pOLV))
+                if (!URLFieldHelper::IsCursorAtURLField(pOLV->GetEditView()))
                     rSet.DisableItem(nWhich);
             }
             break;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to