[Libreoffice-commits] core.git: editeng/source include/editeng sc/sdi sc/source sc/uiconfig

Samuel Mehrbrodt (via logerrit) logerrit at kemper.freedesktop.org
Mon Jul 15 09:33:05 UTC 2019


 editeng/source/editeng/editview.cxx      |   28 ++++++++++++++++++++++++++++
 editeng/source/outliner/outlvw.cxx       |   25 +------------------------
 include/editeng/editview.hxx             |    3 +++
 sc/sdi/drtxtob.sdi                       |    4 +++-
 sc/sdi/editsh.sdi                        |    4 +++-
 sc/source/ui/drawfunc/drtxtob.cxx        |   23 ++++++++++++++++++++++-
 sc/source/ui/view/editsh.cxx             |   24 ++++++++++++++++++++++++
 sc/uiconfig/scalc/popupmenu/celledit.xml |    3 ++-
 sc/uiconfig/scalc/popupmenu/drawtext.xml |    2 ++
 9 files changed, 88 insertions(+), 28 deletions(-)

New commits:
commit 040f348ee00a0d01653b3071be3d9886a08f87fe
Author:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Fri Jul 12 15:30:12 2019 +0200
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Mon Jul 15 11:32:02 2019 +0200

    tdf#62561 Add remove/edit hyperlink to calc context menu
    
    Change-Id: Idb1b96dc4e95be40a796f9178975207099101b87
    Reviewed-on: https://gerrit.libreoffice.org/75497
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>

diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx
index c0ad8484af5d..637f36a73cba 100644
--- a/editeng/source/editeng/editview.cxx
+++ b/editeng/source/editeng/editview.cxx
@@ -1225,6 +1225,34 @@ const SvxFieldItem* EditView::GetFieldAtSelection() const
     return nullptr;
 }
 
+const SvxFieldData* EditView::GetFieldAtCursor()
+{
+    const SvxFieldItem* pFieldItem = GetFieldAtSelection();
+    if (pFieldItem)
+    {
+        // Make sure the whole field is selected
+        ESelection aSel = GetSelection();
+        if (aSel.nStartPos == aSel.nEndPos)
+        {
+            aSel.nEndPos++;
+            SetSelection(aSel);
+        }
+    }
+    if (!pFieldItem)
+    {
+        // Cursor probably behind the field - extend selection to select the field
+        ESelection aSel = GetSelection();
+        if (aSel.nStartPos == aSel.nEndPos)
+        {
+            aSel.nStartPos--;
+            SetSelection(aSel);
+            pFieldItem = GetFieldAtSelection();
+        }
+    }
+
+    return pFieldItem ? pFieldItem->GetField() : nullptr;
+}
+
 void EditView::SetInvalidateMore( sal_uInt16 nPixel )
 {
     pImpEditView->SetInvalidateMore( nPixel );
diff --git a/editeng/source/outliner/outlvw.cxx b/editeng/source/outliner/outlvw.cxx
index 43efbbb1615c..670807932277 100644
--- a/editeng/source/outliner/outlvw.cxx
+++ b/editeng/source/outliner/outlvw.cxx
@@ -1319,30 +1319,7 @@ const SvxFieldItem* OutlinerView::GetFieldAtSelection() const
 
 const SvxFieldData* OutlinerView::GetFieldAtCursor()
 {
-    const SvxFieldItem* pFieldItem = GetFieldAtSelection();
-    if (pFieldItem)
-    {
-        // Make sure the whole field is selected
-        ESelection aSel = GetSelection();
-        if (aSel.nStartPos == aSel.nEndPos)
-        {
-            aSel.nEndPos++;
-            SetSelection(aSel);
-        }
-    }
-    if (!pFieldItem)
-    {
-        // Cursor probably behind the field - extend selection to select the field
-        ESelection aSel = GetSelection();
-        if (aSel.nStartPos == aSel.nEndPos)
-        {
-            aSel.nStartPos--;
-            SetSelection(aSel);
-            pFieldItem = GetFieldAtSelection();
-        }
-    }
-
-    return pFieldItem ? pFieldItem->GetField() : nullptr;
+    return pEditView->GetFieldAtCursor();
 }
 
 void OutlinerView::SetInvalidateMore( sal_uInt16 nPixel )
diff --git a/include/editeng/editview.hxx b/include/editeng/editview.hxx
index 15ac187cdfa5..9adb6bacdca8 100644
--- a/include/editeng/editview.hxx
+++ b/include/editeng/editview.hxx
@@ -29,6 +29,7 @@
 #include <vcl/errcode.hxx>
 #include <vcl/vclptr.hxx>
 #include <editeng/editstat.hxx>
+#include <editeng/flditem.hxx>
 #include <svl/languageoptions.hxx>
 #include <editeng/editdata.hxx>
 #include <com/sun/star/uno/Reference.h>
@@ -276,6 +277,8 @@ public:
     const SvxFieldItem* GetField( const Point& rPos, sal_Int32* pnPara = nullptr, sal_Int32* pnPos = nullptr ) const;
 
     const SvxFieldItem* GetFieldAtSelection() const;
+    /// Select and return the field at the current cursor position
+    const SvxFieldData* GetFieldAtCursor();
 
     void            SetInvalidateMore( sal_uInt16 nPixel );
     sal_uInt16      GetInvalidateMore() const;
diff --git a/sc/sdi/drtxtob.sdi b/sc/sdi/drtxtob.sdi
index e1a7f4aa09d1..89be1b24c3ee 100644
--- a/sc/sdi/drtxtob.sdi
+++ b/sc/sdi/drtxtob.sdi
@@ -129,7 +129,9 @@ interface TableDrawText
 
     SID_HYPERLINK_SETLINK   [ ExecMethod = Execute; Export = FALSE; ]
     SID_HYPERLINK_GETLINK   [ StateMethod = GetState; Export = FALSE; ]
-        SID_OPEN_HYPERLINK      [ ExecMethod = Execute; StateMethod = GetState; Export = FALSE; ]
+    SID_OPEN_HYPERLINK      [ ExecMethod = Execute; StateMethod = GetState; Export = FALSE; ]
+    SID_EDIT_HYPERLINK      [ ExecMethod = Execute; StateMethod = GetState; Export = FALSE; ]
+    SID_REMOVE_HYPERLINK    [ ExecMethod = Execute; StateMethod = GetState; Export = FALSE; ]
     SID_ENABLE_HYPHENATION  [ ExecMethod = Execute; StateMethod = GetState; Export = FALSE; ]
 
     SID_TEXTDIRECTION_LEFT_TO_RIGHT     [ ExecMethod = Execute; StateMethod = GetAttrState; Export = FALSE; ]
diff --git a/sc/sdi/editsh.sdi b/sc/sdi/editsh.sdi
index 9e1e5d4a0509..5718fc63407e 100644
--- a/sc/sdi/editsh.sdi
+++ b/sc/sdi/editsh.sdi
@@ -78,7 +78,9 @@ interface TableText
 
     SID_HYPERLINK_SETLINK   [ ExecMethod = Execute; Export = FALSE; ]
     SID_HYPERLINK_GETLINK   [ StateMethod = GetState; Export = FALSE; ]
-        SID_OPEN_HYPERLINK      [ ExecMethod = Execute; StateMethod = GetState; Export = FALSE; ]
+    SID_OPEN_HYPERLINK      [ ExecMethod = Execute; StateMethod = GetState; Export = FALSE; ]
+    SID_EDIT_HYPERLINK      [ ExecMethod = Execute; StateMethod = GetState; Export = FALSE; ]
+    SID_REMOVE_HYPERLINK      [ ExecMethod = Execute; StateMethod = GetState; Export = FALSE; ]
 
     SID_TRANSLITERATE_SENTENCE_CASE [ ExecMethod = ExecuteTrans; StateMethod = GetState;  Export = FALSE; ]
     SID_TRANSLITERATE_TITLE_CASE    [ ExecMethod = ExecuteTrans; StateMethod = GetState;  Export = FALSE; ]
diff --git a/sc/source/ui/drawfunc/drtxtob.cxx b/sc/source/ui/drawfunc/drtxtob.cxx
index c37b8f11e7ed..877434afee80 100644
--- a/sc/source/ui/drawfunc/drtxtob.cxx
+++ b/sc/source/ui/drawfunc/drtxtob.cxx
@@ -35,6 +35,7 @@
 #include <editeng/lrspitem.hxx>
 #include <editeng/lspcitem.hxx>
 #include <editeng/ulspitem.hxx>
+#include <editeng/urlfieldhelper.hxx>
 #include <svx/hlnkitem.hxx>
 #include <svx/svdoutl.hxx>
 #include <svx/sdooitm.hxx>
@@ -328,6 +329,20 @@ void ScDrawTextObjectBar::Execute( SfxRequest &rReq )
             }
             break;
 
+        case SID_EDIT_HYPERLINK:
+            {
+                // Ensure the field is selected first
+                pOutView->GetFieldAtCursor();
+                pViewData->GetViewShell()->GetViewFrame()->GetDispatcher()->Execute(SID_HYPERLINK_DIALOG);
+            }
+            break;
+
+        case SID_REMOVE_HYPERLINK:
+            {
+                URLFieldHelper::RemoveURLField(pOutliner, pOutView);
+            }
+            break;
+
         case SID_ENABLE_HYPHENATION:
         case SID_TEXTDIRECTION_LEFT_TO_RIGHT:
         case SID_TEXTDIRECTION_TOP_TO_BOTTOM:
@@ -406,7 +421,9 @@ void ScDrawTextObjectBar::GetState( SfxItemSet& rSet )
         rSet.Put(aHLinkItem);
     }
 
-    if ( rSet.GetItemState( SID_OPEN_HYPERLINK ) != SfxItemState::UNKNOWN )
+    if (rSet.GetItemState(SID_OPEN_HYPERLINK) != SfxItemState::UNKNOWN
+        || rSet.GetItemState(SID_EDIT_HYPERLINK) != SfxItemState::UNKNOWN
+        || rSet.GetItemState(SID_REMOVE_HYPERLINK) != SfxItemState::UNKNOWN)
     {
         SdrView* pView = pViewData->GetScDrawView();
         OutlinerView* pOutView = pView->GetTextEditOutlinerView();
@@ -421,7 +438,11 @@ void ScDrawTextObjectBar::GetState( SfxItemSet& rSet )
             }
         }
         if( !bEnable )
+        {
             rSet.DisableItem( SID_OPEN_HYPERLINK );
+            rSet.DisableItem( SID_EDIT_HYPERLINK );
+            rSet.DisableItem( SID_REMOVE_HYPERLINK );
+        }
     }
 
     if( rSet.GetItemState( SID_TRANSLITERATE_HALFWIDTH ) != SfxItemState::UNKNOWN )
diff --git a/sc/source/ui/view/editsh.cxx b/sc/source/ui/view/editsh.cxx
index f458a0a75b8e..c2e3e3a4c118 100644
--- a/sc/source/ui/view/editsh.cxx
+++ b/sc/source/ui/view/editsh.cxx
@@ -45,6 +45,7 @@
 #include <editeng/wghtitem.hxx>
 #include <sfx2/basedlgs.hxx>
 #include <sfx2/bindings.hxx>
+#include <sfx2/dispatch.hxx>
 #include <sfx2/msg.hxx>
 #include <sfx2/objface.hxx>
 #include <sfx2/objsh.hxx>
@@ -627,6 +628,27 @@ void ScEditShell::Execute( SfxRequest& rReq )
                         ScGlobal::OpenURL( pURLField->GetURL(), pURLField->GetTargetFrame() );
                     return;
                 }
+        case SID_EDIT_HYPERLINK:
+            {
+                // Ensure the field is selected first
+                pEditView->GetFieldAtCursor();
+                pViewData->GetViewShell()->GetViewFrame()->GetDispatcher()->Execute(
+                    SID_HYPERLINK_DIALOG);
+            }
+        break;
+        case SID_REMOVE_HYPERLINK:
+            {
+                // Ensure the field is selected first
+                pEditView->GetFieldAtCursor();
+                const SvxURLField* pURLField = GetURLField();
+                if (pURLField)
+                {
+                    ESelection aSel = pEditView->GetSelection();
+                    pEditView->GetEditEngine()->QuickInsertText(pURLField->GetRepresentation(), aSel);
+                }
+
+            }
+        break;
 
         case FN_INSERT_SOFT_HYPHEN:
             lclInsertCharacter( pTableView, pTopView, CHAR_SHY );
@@ -752,6 +774,8 @@ void ScEditShell::GetState( SfxItemSet& rSet )
                 break;
 
             case SID_OPEN_HYPERLINK:
+            case SID_EDIT_HYPERLINK:
+            case SID_REMOVE_HYPERLINK:
                 {
                     if ( !GetURLField() )
                         rSet.DisableItem( nWhich );
diff --git a/sc/uiconfig/scalc/popupmenu/celledit.xml b/sc/uiconfig/scalc/popupmenu/celledit.xml
index ea0aed174520..526b47df2453 100644
--- a/sc/uiconfig/scalc/popupmenu/celledit.xml
+++ b/sc/uiconfig/scalc/popupmenu/celledit.xml
@@ -25,7 +25,8 @@
   </menu:menu>
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:OpenHyperlinkOnCursor"/>
-  <menu:menuitem menu:id=".uno:HyperlinkDialog"/>
+  <menu:menuitem menu:id=".uno:EditHyperlink"/>
+  <menu:menuitem menu:id=".uno:RemoveHyperlink"/>
   <menu:menuitem menu:id=".uno:ThesaurusFromContext"/>
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:ResetAttributes"/>
diff --git a/sc/uiconfig/scalc/popupmenu/drawtext.xml b/sc/uiconfig/scalc/popupmenu/drawtext.xml
index b070b3231df3..d05b1bf8a57d 100644
--- a/sc/uiconfig/scalc/popupmenu/drawtext.xml
+++ b/sc/uiconfig/scalc/popupmenu/drawtext.xml
@@ -24,6 +24,8 @@
   <menu:menuitem menu:id=".uno:ParagraphDialog"/>
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:OpenHyperlinkOnCursor"/>
+  <menu:menuitem menu:id=".uno:EditHyperlink"/>
+  <menu:menuitem menu:id=".uno:RemoveHyperlink"/>
   <menu:menuitem menu:id=".uno:ThesaurusFromContext"/>
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:StandardTextAttributes"/>


More information about the Libreoffice-commits mailing list