summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2019-07-09 10:06:29 +0200
committerSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2019-07-09 10:51:08 +0200
commit7a0164f0d82d91e2ac481d74cdacfe9a7ad6080f (patch)
tree1288992250b6d2dd5c55c9f952a14146436ca31c /sd
parent60f7236293bc3bd4a9b2962a5f1f9af6f2998808 (diff)
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@cib.de>
Diffstat (limited to 'sd')
-rw-r--r--sd/source/ui/inc/DrawViewShell.hxx3
-rw-r--r--sd/source/ui/view/drviews2.cxx32
-rw-r--r--sd/source/ui/view/drviewsf.cxx71
3 files changed, 44 insertions, 62 deletions
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: */