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.Mehrbrodt@cib.de>
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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: */
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -1195,8 +1195,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();
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -511,7 +511,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;
|
||||
|
||||
@@ -535,10 +535,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;
|
||||
|
||||
@@ -981,7 +978,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;
|
||||
|
||||
Reference in New Issue
Block a user