Resolves: tdf#140361 use the DisableEditHyperlink state as of menu launch time
at context menu popup time set if the EditHyperlink entry should be
disabled and use that state if queried about it if EditHyperlink is
dispatched from the menu. So ignoring where the mouse currently happens
to be when the menu was dismissed.
The dispatch is done async, if at all, so also trigger an async Query
with Invalidate so at least one Query is ensured to reset the stored
state
similar to tdf#137445 which was for impress/draw
Change-Id: I43a144f1ac0a4db89cc5ab0ebeeae744719f5958
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117653
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/sc/source/ui/inc/editsh.hxx b/sc/source/ui/inc/editsh.hxx
index fe56777..5fb8a3c 100644
--- a/sc/source/ui/inc/editsh.hxx
+++ b/sc/source/ui/inc/editsh.hxx
@@ -42,6 +42,12 @@ private:
bool bPastePossible;
bool bIsInsertMode;
// tdf#140361 at context menu popup time set if the EditHyperlink entry
// should be disabled and use that state if queried about it if
// EditHyperlink is dispatched from the menu. So ignoring where the mouse
// currently happens to be when the menu was dismissed.
std::optional<bool> moAtContextMenu_DisableEditHyperlink;
const SvxURLField* GetURLField();
ScInputHandler* GetMyInputHdl();
@@ -73,6 +79,12 @@ public:
void GetUndoState(SfxItemSet &rSet);
OUString GetSelectionText( bool bWholeWord );
/// return true if "Edit Hyperlink" in context menu should be disabled
bool ShouldDisableEditHyperlink() const;
/// force "Edit Hyperlink" to true, with the expectation that SID_EDIT_HYPERLINK is
/// later Invalidated to reset it back to its natural value
void EnableEditHyperlink();
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/tabvwsh.hxx b/sc/source/ui/inc/tabvwsh.hxx
index 7a5ddf4..77afb12 100644
--- a/sc/source/ui/inc/tabvwsh.hxx
+++ b/sc/source/ui/inc/tabvwsh.hxx
@@ -399,6 +399,12 @@ public:
void ClearFormEditData();
ScFormEditData* GetFormEditData() { return mpFormEditData.get(); }
/// return true if "Edit Hyperlink" in context menu should be disabled
bool ShouldDisableEditHyperlink() const;
/// force "Edit Hyperlink" to true, with the expectation that SID_EDIT_HYPERLINK is
/// later Invalidated to reset it back to its natural value
void EnableEditHyperlink();
virtual tools::Rectangle getLOKVisibleArea() const override;
};
diff --git a/sc/source/ui/view/editsh.cxx b/sc/source/ui/view/editsh.cxx
index 83c042b..98bf88d 100644
--- a/sc/source/ui/view/editsh.cxx
+++ b/sc/source/ui/view/editsh.cxx
@@ -711,6 +711,16 @@ static void lcl_DisableAll( SfxItemSet& rSet ) // disable all slots
}
}
bool ScEditShell::ShouldDisableEditHyperlink() const
{
return !rViewData.HasEditView(rViewData.GetActivePart()) || !URLFieldHelper::IsCursorAtURLField(*pEditView);
}
void ScEditShell::EnableEditHyperlink()
{
moAtContextMenu_DisableEditHyperlink = false;
}
void ScEditShell::GetState( SfxItemSet& rSet )
{
// When deactivating the view, edit mode is stopped, but the EditShell is left active
@@ -776,7 +786,18 @@ void ScEditShell::GetState( SfxItemSet& rSet )
case SID_COPY_HYPERLINK_LOCATION:
case SID_REMOVE_HYPERLINK:
{
if (!URLFieldHelper::IsCursorAtURLField(*pEditView))
bool bDisableEditHyperlink;
if (!moAtContextMenu_DisableEditHyperlink)
bDisableEditHyperlink = ShouldDisableEditHyperlink();
else
{
// tdf#140361 if a popup menu was active, use the state as of when the popup was launched and then drop
// moAtContextMenu_DisableEditHyperlink
bDisableEditHyperlink = *moAtContextMenu_DisableEditHyperlink;
moAtContextMenu_DisableEditHyperlink.reset();
}
if (bDisableEditHyperlink)
rSet.DisableItem (nWhich);
}
break;
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 3211e5a..b6412ae 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -3097,7 +3097,21 @@ void ScGridWindow::Command( const CommandEvent& rCEvt )
if (!bDone)
{
// tdf#140361 at this context menu popup time get what the
// DisableEditHyperlink would be for this position
bool bShouldDisableEditHyperlink = mrViewData.GetViewShell()->ShouldDisableEditHyperlink();
SfxDispatcher::ExecutePopup( this, &aMenuPos );
if (!bShouldDisableEditHyperlink)
{
SfxBindings& rBindings = mrViewData.GetBindings();
// tdf#140361 set what the menu popup state for this was
mrViewData.GetViewShell()->EnableEditHyperlink();
// ensure moAtContextMenu_DisableEditHyperlink will be cleared
// in the case that EditHyperlink is not dispatched by the menu
rBindings.Invalidate(SID_EDIT_HYPERLINK);
}
}
}
diff --git a/sc/source/ui/view/tabvwshe.cxx b/sc/source/ui/view/tabvwshe.cxx
index 84b883a..418aa6e 100644
--- a/sc/source/ui/view/tabvwshe.cxx
+++ b/sc/source/ui/view/tabvwshe.cxx
@@ -115,6 +115,26 @@ OUString ScTabViewShell::GetSelectionText( bool bWholeWord )
return aStrSelection;
}
bool ScTabViewShell::ShouldDisableEditHyperlink() const
{
bool bRet = false;
if (pEditShell && pEditShell.get() == GetMySubShell())
{
bRet = pEditShell->ShouldDisableEditHyperlink();
}
return bRet;
}
void ScTabViewShell::EnableEditHyperlink()
{
if (pEditShell && pEditShell.get() == GetMySubShell())
{
pEditShell->EnableEditHyperlink();
}
}
void ScTabViewShell::InsertURL( const OUString& rName, const OUString& rURL, const OUString& rTarget,
sal_uInt16 nMode )
{
diff --git a/sd/source/ui/inc/DrawViewShell.hxx b/sd/source/ui/inc/DrawViewShell.hxx
index 288cf24..d981645 100644
--- a/sd/source/ui/inc/DrawViewShell.hxx
+++ b/sd/source/ui/inc/DrawViewShell.hxx
@@ -497,7 +497,10 @@ private:
void ConfigureAppBackgroundColor( svtools::ColorConfig* pColorConfig = nullptr );
/// return true if "Edit Hyperlink" in context menu should be disabled
bool ShouldDisableEditHyperlink();
bool ShouldDisableEditHyperlink() const;
/// force "Edit Hyperlink" to true, with the expectation that SID_EDIT_HYPERLINK is
/// later Invalidated to reset it back to its natural value
void EnableEditHyperlink();
// The colour of the area behind the slide (used to be called "Wiese")
Color mnAppBackgroundColor;
diff --git a/sd/source/ui/view/drviews4.cxx b/sd/source/ui/view/drviews4.cxx
index 2baed56..ad5d741 100644
--- a/sd/source/ui/view/drviews4.cxx
+++ b/sd/source/ui/view/drviews4.cxx
@@ -832,7 +832,7 @@ void DrawViewShell::Command(const CommandEvent& rCEvt, ::sd::Window* pWin)
{
SfxBindings& rBindings = GetViewFrame()->GetBindings();
// tdf#137445 set what the menu popup state for this was
moAtContextMenu_DisableEditHyperlink = bShouldDisableEditHyperlink;
EnableEditHyperlink();
// ensure moAtContextMenu_DisableEditHyperlink will be cleared
// in the case that EditHyperlink is not dispatched by the menu
rBindings.Invalidate(SID_EDIT_HYPERLINK);
@@ -845,6 +845,11 @@ void DrawViewShell::Command(const CommandEvent& rCEvt, ::sd::Window* pWin)
}
}
void DrawViewShell::EnableEditHyperlink()
{
moAtContextMenu_DisableEditHyperlink = false;
}
void DrawViewShell::ShowMousePosInfo(const ::tools::Rectangle& rRect,
::sd::Window const * pWin)
{
diff --git a/sd/source/ui/view/drviews7.cxx b/sd/source/ui/view/drviews7.cxx
index 1419108..dcc57a2 100644
--- a/sd/source/ui/view/drviews7.cxx
+++ b/sd/source/ui/view/drviews7.cxx
@@ -282,7 +282,7 @@ void DrawViewShell::GetMarginProperties( SfxItemSet &rSet )
}
}
bool DrawViewShell::ShouldDisableEditHyperlink()
bool DrawViewShell::ShouldDisableEditHyperlink() const
{
if (!mpDrawView)
return true;