sc/source/ui/condformat/condformatdlgentry.cxx | 26 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
New commits: commit c23c209a063273fda0670203bfbe3bf8ed6eb249 Author: Eike Rathke <er...@redhat.com> AuthorDate: Fri Sep 2 18:13:30 2022 +0200 Commit: Eike Rathke <er...@redhat.com> CommitDate: Fri Sep 2 19:15:44 2022 +0200 Resolves: tdf#150271 Further error checks of conditional formatting expression i.e. an obviously wrong or incomplete expression as far as the formula compiler can detect it sets the input field's error state, unless it's an unrecognized name that still displays the unquoted string warning. Change-Id: I54b5e32a1848acec246215a76cb19ec597630ecd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139269 Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Jenkins diff --git a/sc/source/ui/condformat/condformatdlgentry.cxx b/sc/source/ui/condformat/condformatdlgentry.cxx index 77175fa64c64..149a20e48a79 100644 --- a/sc/source/ui/condformat/condformatdlgentry.cxx +++ b/sc/source/ui/condformat/condformatdlgentry.cxx @@ -258,29 +258,37 @@ IMPL_LINK(ScConditionFrmtEntry, OnEdChanged, formula::RefEdit&, rRefEdit, void) } ScCompiler aComp( *mpDoc, maPos, mpDoc->GetGrammar() ); + aComp.SetExtendedErrorDetection( ScCompiler::ExtendedErrorDetection::EXTENDED_ERROR_DETECTION_NAME_BREAK); std::unique_ptr<ScTokenArray> ta(aComp.CompileString(aFormula)); - // Error, warn the user - if( ta->GetCodeError() != FormulaError::NONE || ( ta->GetLen() == 0 ) ) + // Error, warn the user if it is not an unknown name. + if (ta->GetCodeError() != FormulaError::NoName && (ta->GetCodeError() != FormulaError::NONE || ta->GetLen() == 0)) { rEdit.set_message_type(weld::EntryMessageType::Error); mxFtVal->set_label(ScResId(STR_VALID_DEFERROR)); return; } - // Recognized col/row name or string token, warn the user - formula::FormulaToken* token = ta->FirstToken(); - formula::StackVar t = token->GetType(); - OpCode op = token->GetOpCode(); - if( ( op == ocColRowName ) || - ( ( op == ocBad ) && ( t == formula::svString ) ) - ) + // Unrecognized name, warn the user; i.e. happens when starting to type and + // will go away once a valid name is completed. + if (ta->GetCodeError() == FormulaError::NoName) { rEdit.set_message_type(weld::EntryMessageType::Warning); mxFtVal->set_label(ScResId(STR_UNQUOTED_STRING)); return; } + // Generate RPN to detect further errors. + if (ta->GetLen() > 0) + aComp.CompileTokenArray(); + // Error, warn the user. + if (ta->GetCodeError() != FormulaError::NONE || (ta->GetCodeLen() == 0)) + { + rEdit.set_message_type(weld::EntryMessageType::Error); + mxFtVal->set_label(ScResId(STR_VALID_DEFERROR)); + return; + } + rEdit.set_message_type(weld::EntryMessageType::Normal); mxFtVal->set_label(""); }