sw/source/ui/fldui/fldtdlg.cxx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
New commits: commit 85d099bd3680d517f1a76faf3eb720a9cb8e140f Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Tue Sep 27 16:21:02 2022 +0200 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Tue Sep 27 21:18:03 2022 +0200 sw: SwFieldDlg disable Insert button if shell cursor is in input field Lots of content including fields cannot be inserted into an input field, and if there is already a selection when clicking the insert button, the selection will be deleted but then inserting the field will fail. Just disable the button, as is already done if the cursor is in a protected section. Change-Id: Ib01cf378441582668a9dd4c76900062b906ff09c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140660 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sw/source/ui/fldui/fldtdlg.cxx b/sw/source/ui/fldui/fldtdlg.cxx index 53e5a51c6eaf..a3886591a4c2 100644 --- a/sw/source/ui/fldui/fldtdlg.cxx +++ b/sw/source/ui/fldui/fldtdlg.cxx @@ -189,8 +189,9 @@ void SwFieldDlg::ReInitDlg() if(!pActiveView) return; const SwWrtShell& rSh = pActiveView->GetWrtShell(); - GetOKButton().set_sensitive(!rSh.IsReadOnlyAvailable() || - !rSh.HasReadonlySel()); + GetOKButton().set_sensitive(( !rSh.IsReadOnlyAvailable() + || !rSh.HasReadonlySel()) + && !SwCursorShell::PosInsideInputField(*rSh.GetCursor()->GetPoint())); ReInitTabPage("document"); ReInitTabPage("variables"); @@ -223,8 +224,10 @@ void SwFieldDlg::Activate() bool bHtmlMode = (::GetHtmlMode(static_cast<SwDocShell*>(SfxObjectShell::Current())) & HTMLMODE_ON) != 0; const SwWrtShell& rSh = pView->GetWrtShell(); - GetOKButton().set_sensitive(!rSh.IsReadOnlyAvailable() || - !rSh.HasReadonlySel()); + GetOKButton().set_sensitive(( !rSh.IsReadOnlyAvailable() + || !rSh.HasReadonlySel()) + && !SwCursorShell::PosInsideInputField(*rSh.GetCursor()->GetPoint())); + ReInitTabPage("variables", true); @@ -243,8 +246,11 @@ void SwFieldDlg::EnableInsert(bool bEnable) OSL_ENSURE(pView, "no view found"); if( !pView || (pView->GetWrtShell().IsReadOnlyAvailable() && - pView->GetWrtShell().HasReadonlySel()) ) + pView->GetWrtShell().HasReadonlySel()) + || SwCursorShell::PosInsideInputField(*pView->GetWrtShell().GetCursor()->GetPoint())) + { bEnable = false; + } } GetOKButton().set_sensitive(bEnable); }