diff options
author | Eike Rathke <erack@redhat.com> | 2022-09-02 18:13:30 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2022-09-02 19:15:44 +0200 |
commit | c23c209a063273fda0670203bfbe3bf8ed6eb249 (patch) | |
tree | fa4fd7b869e479630f3a79a80b89bb98db7e6bb2 | |
parent | 7d5beaabeac4e474512337b086690257daeefc96 (diff) |
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 <erack@redhat.com>
Tested-by: Jenkins
-rw-r--r-- | sc/source/ui/condformat/condformatdlgentry.cxx | 26 |
1 files changed, 17 insertions, 9 deletions
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(""); } |