sc/inc/validat.hxx | 3 ++- sc/source/core/data/validat.cxx | 27 ++++++++++++++------------- sc/source/ui/app/inputhdl.cxx | 25 +++++++++++++++---------- sc/source/ui/inc/inputhdl.hxx | 2 ++ 4 files changed, 33 insertions(+), 24 deletions(-)
New commits: commit 495be2dcb34d22af59a2028d3a686a0d48774166 Author: Pranam Lashkari <lpra...@collabora.com> AuthorDate: Mon Dec 30 02:20:22 2024 +0530 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Sun Jan 12 18:15:54 2025 +0100 sc: make data validy error dialog async (invalid value error) Change-Id: Icd077776b26e21b226b4dee5beb1a5ff6dcf301a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179509 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sc/inc/validat.hxx b/sc/inc/validat.hxx index 72f277d2852f..9089f1d0272d 100644 --- a/sc/inc/validat.hxx +++ b/sc/inc/validat.hxx @@ -161,7 +161,8 @@ public: OUString& rStrResult, double& nVal, sal_uInt32& nFormat, bool& bIsVal) const; // TRUE -> break - bool DoError(weld::Window* pParent, const OUString& rInput, const ScAddress& rPos) const; + void DoError(weld::Window* pParent, const OUString& rInput, const ScAddress& rPos, + std::function<void(bool forget)> callback) const; void DoCalcError( ScFormulaCell* pCell ) const; bool IsEmpty() const; diff --git a/sc/source/core/data/validat.cxx b/sc/source/core/data/validat.cxx index 4239636ebb0e..aa18f6fa5219 100644 --- a/sc/source/core/data/validat.cxx +++ b/sc/source/core/data/validat.cxx @@ -247,10 +247,10 @@ bool ScValidationData::DoScript( const ScAddress& rPos, const OUString& rInput, // Macro not found (only with input) { //TODO: different error message, if found, but not bAllowed ?? - std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pParent, + std::shared_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pParent, VclMessageType::Warning, VclButtonsType::Ok, ScResId(STR_VALID_MACRONOTFOUND))); - xBox->run(); + xBox->runAsync(xBox, [] (sal_uInt32){ }); } return bScriptReturnedFalse; @@ -353,10 +353,10 @@ bool ScValidationData::DoMacro( const ScAddress& rPos, const OUString& rInput, if ( !bDone && !pCell ) // Macro not found (only with input) { //TODO: different error message, if found, but not bAllowed ?? - std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pParent, + std::shared_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pParent, VclMessageType::Warning, VclButtonsType::Ok, ScResId(STR_VALID_MACRONOTFOUND))); - xBox->run(); + xBox->runAsync(xBox, [](sal_uInt32) {}); } return bRet; @@ -375,14 +375,16 @@ IMPL_STATIC_LINK_NOARG(ScValidationData, InstallLOKNotifierHdl, void*, vcl::ILib // true -> abort -bool ScValidationData::DoError(weld::Window* pParent, const OUString& rInput, - const ScAddress& rPos) const +void ScValidationData::DoError(weld::Window* pParent, const OUString& rInput, const ScAddress& rPos, + std::function<void(bool forget)> callback) const { - if ( eErrorStyle == SC_VALERR_MACRO ) - return DoMacro(rPos, rInput, nullptr, pParent); + if ( eErrorStyle == SC_VALERR_MACRO ) { + DoMacro(rPos, rInput, nullptr, pParent); + return; + } if (!bShowError) - return true; + return; // Output error message @@ -409,7 +411,7 @@ bool ScValidationData::DoError(weld::Window* pParent, const OUString& rInput, break; } - std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pParent, eType, + std::shared_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pParent, eType, eStyle, aMessage, SfxViewShell::Current())); xBox->set_title(aTitle); xBox->SetInstallLOKNotifierHdl(LINK(nullptr, ScValidationData, InstallLOKNotifierHdl)); @@ -426,9 +428,8 @@ bool ScValidationData::DoError(weld::Window* pParent, const OUString& rInput, break; } - short nRet = xBox->run(); - - return ( eErrorStyle == SC_VALERR_STOP || nRet == RET_CANCEL ); + xBox->runAsync(xBox, [&, callback](sal_uInt32 result) + { callback(eErrorStyle == SC_VALERR_STOP || result == RET_CANCEL); }); } bool ScValidationData::IsDataValidCustom( diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx index 5131639bf7b6..16663dd67889 100644 --- a/sc/source/ui/app/inputhdl.cxx +++ b/sc/source/ui/app/inputhdl.cxx @@ -3138,13 +3138,6 @@ void ScInputHandler::EnterHandler( ScEnterMode nBlockMode, bool bBeforeSavingInL ImplCreateEditEngine(); - bool bMatrix = ( nBlockMode == ScEnterMode::MATRIX ); - - SfxApplication* pSfxApp = SfxGetpApp(); - std::unique_ptr<EditTextObject> pObject; - std::unique_ptr<ScPatternAttr> pCellAttrs; - bool bForget = false; // Remove due to validity? - OUString aString = GetEditText(mpEditEngine.get()); OUString aPreAutoCorrectString(aString); EditView* pActiveView = pTopView ? pTopView : pTableView; @@ -3213,12 +3206,24 @@ void ScInputHandler::EnterHandler( ScEnterMode nBlockMode, bool bBeforeSavingInL return; } - if (pData->DoError(pActiveViewSh->GetFrameWeld(), aString, aCursorPos)) - bForget = true; // Do not take over input - + pData->DoError( + pActiveViewSh->GetFrameWeld(), aString, aCursorPos, + [this, nBlockMode, aString, aPreAutoCorrectString](bool bForget) + { EnterHandler2(nBlockMode, bForget, aString, aPreAutoCorrectString); }); + return; } } } + EnterHandler2(nBlockMode, false, aString, aPreAutoCorrectString); +} + +void ScInputHandler::EnterHandler2(ScEnterMode nBlockMode, bool bForget, OUString aString, + OUString aPreAutoCorrectString) +{ + std::unique_ptr<EditTextObject> pObject; + std::unique_ptr<ScPatternAttr> pCellAttrs; + bool bMatrix = (nBlockMode == ScEnterMode::MATRIX); + SfxApplication* pSfxApp = SfxGetpApp(); // Check for input into DataPilot table if ( bModified && !bForget ) diff --git a/sc/source/ui/inc/inputhdl.hxx b/sc/source/ui/inc/inputhdl.hxx index 3067dd819397..ed77cf2db72a 100644 --- a/sc/source/ui/inc/inputhdl.hxx +++ b/sc/source/ui/inc/inputhdl.hxx @@ -198,6 +198,8 @@ public: bool KeyInput( const KeyEvent& rKEvt, bool bStartEdit ); void EnterHandler( ScEnterMode nBlockMode = ScEnterMode::NORMAL, bool bBeforeSavingInLOK = false ); + void EnterHandler2(ScEnterMode nBlockMode, bool bForget, OUString aString, + OUString aPreAutoCorrectString); void CancelHandler(); void SetReference( const ScRange& rRef, const ScDocument& rDoc ); void AddRefEntry();