sc/source/ui/condformat/condformatdlgentry.cxx |   43 ----------------------
 sc/source/ui/condformat/condformateasydlg.cxx  |   13 ++++++
 sc/source/ui/condformat/condformathelper.cxx   |   48 +++++++++++++++++++++++++
 sc/source/ui/inc/condformateasydlg.hxx         |    2 +
 sc/source/ui/inc/condformathelper.hxx          |    1 
 sc/uiconfig/scalc/ui/conditionaleasydialog.ui  |   15 ++++++-
 6 files changed, 78 insertions(+), 44 deletions(-)

New commits:
commit 2ac55839b4fd6d4c13c8e1d92350a6ddaebb35d5
Author:     Pranam Lashkari <lpra...@collabora.com>
AuthorDate: Fri Oct 11 05:50:22 2024 +0400
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Oct 15 09:23:04 2024 +0200

    sc: give warning about condition input in easy condition dialog
    
    Change-Id: I3cea0ae966951b5ff554f4ce9aeec5a1ed11ca13
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174779
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174906
    Tested-by: Jenkins

diff --git a/sc/source/ui/condformat/condformatdlgentry.cxx 
b/sc/source/ui/condformat/condformatdlgentry.cxx
index d23b254829e2..f04706364cac 100644
--- a/sc/source/ui/condformat/condformatdlgentry.cxx
+++ b/sc/source/ui/condformat/condformatdlgentry.cxx
@@ -248,48 +248,7 @@ ScFormatEntry* 
ScConditionFrmtEntry::createConditionEntry() const
 IMPL_LINK(ScConditionFrmtEntry, OnEdChanged, formula::RefEdit&, rRefEdit, void)
 {
     weld::Entry& rEdit = *rRefEdit.GetWidget();
-    OUString aFormula = rEdit.get_text();
-
-    if( aFormula.isEmpty() )
-    {
-        mxFtVal->set_label(ScResId(STR_ENTER_VALUE));
-        return;
-    }
-
-    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 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;
-    }
-
-    // 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(u""_ustr);
+    ScCondFormatHelper::ValidateInputField(rEdit, *mxFtVal, mpDoc, maPos);
 }
 
 void ScConditionFrmtEntry::Select()
diff --git a/sc/source/ui/condformat/condformateasydlg.cxx 
b/sc/source/ui/condformat/condformateasydlg.cxx
index 7da0f8a7419e..7040a9cf2d79 100644
--- a/sc/source/ui/condformat/condformateasydlg.cxx
+++ b/sc/source/ui/condformat/condformateasydlg.cxx
@@ -78,6 +78,7 @@ 
ConditionalFormatEasyDialog::ConditionalFormatEasyDialog(SfxBindings* pBindings,
     , mxNumberEntry(m_xBuilder->weld_entry(u"entryNumber"_ustr))
     , mxNumberEntry2(m_xBuilder->weld_entry(u"entryNumber2"_ustr))
     , mxAllInputs(m_xBuilder->weld_container(u"allInputs"_ustr))
+    , mxWarningLabel(m_xBuilder->weld_label(u"warning"_ustr))
     , mxRangeEntry(new 
formula::RefEdit(m_xBuilder->weld_entry(u"entryRange"_ustr)))
     , mxButtonRangeEdit(new 
formula::RefButton(m_xBuilder->weld_button(u"rbassign"_ustr)))
     , mxStyles(m_xBuilder->weld_combo_box(u"themeCombo"_ustr))
@@ -257,6 +258,8 @@ 
ConditionalFormatEasyDialog::ConditionalFormatEasyDialog(SfxBindings* pBindings,
     mxButtonOk->connect_clicked(LINK(this, ConditionalFormatEasyDialog, 
ButtonPressed));
     mxButtonCancel->connect_clicked(LINK(this, ConditionalFormatEasyDialog, 
ButtonPressed));
     mxStyles->connect_changed(LINK(this, ConditionalFormatEasyDialog, 
StyleSelectHdl));
+    mxNumberEntry->connect_changed(LINK(this, ConditionalFormatEasyDialog, 
OnEdChanged));
+    mxNumberEntry2->connect_changed(LINK(this, ConditionalFormatEasyDialog, 
OnEdChanged));
 
     ScRangeList aRange;
     mpViewData->GetMarkData().FillRangeListWithMarks(&aRange, false);
@@ -409,6 +412,16 @@ IMPL_LINK_NOARG(ConditionalFormatEasyDialog, 
StyleSelectHdl, weld::ComboBox&, vo
     ScCondFormatHelper::StyleSelect(mpParent, *mxStyles, 
&(mpViewData->GetDocument()), maWdPreview);
 }
 
+IMPL_LINK(ConditionalFormatEasyDialog, OnEdChanged, weld::Entry&, rEntry, void)
+{
+    ScCondFormatHelper::ValidateInputField(rEntry, *mxWarningLabel, 
mpDocument, maPosition);
+
+    if (!mxWarningLabel->get_label().isEmpty())
+        mxWarningLabel->show();
+    else
+        mxWarningLabel->hide();
+}
+
 } // namespace sc
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/sc/source/ui/condformat/condformathelper.cxx 
b/sc/source/ui/condformat/condformathelper.cxx
index 03623db407d1..2d37a10f3365 100644
--- a/sc/source/ui/condformat/condformathelper.cxx
+++ b/sc/source/ui/condformat/condformathelper.cxx
@@ -23,6 +23,8 @@
 #include <sfx2/frame.hxx>
 #include <tabvwsh.hxx>
 #include <svx/fntctrl.hxx>
+#include <compiler.hxx>
+#include <globstr.hrc>
 
 namespace {
 
@@ -323,4 +325,50 @@ void ScCondFormatHelper::UpdateStyleList(weld::ComboBox& 
rLbStyle, const ScDocum
     rLbStyle.set_active_text(aSelectedStyle);
 }
 
+void ScCondFormatHelper::ValidateInputField(weld::Entry& rEntry, weld::Label& 
rLabel, ScDocument* pDoc, ScAddress& rPos)
+{
+    OUString aFormula = rEntry.get_text();
+
+    if( aFormula.isEmpty() )
+    {
+        rLabel.set_label(ScResId(STR_ENTER_VALUE));
+        return;
+    }
+
+    ScCompiler aComp( *pDoc, rPos, pDoc->GetGrammar() );
+    aComp.SetExtendedErrorDetection( 
ScCompiler::ExtendedErrorDetection::EXTENDED_ERROR_DETECTION_NAME_BREAK);
+    std::unique_ptr<ScTokenArray> ta(aComp.CompileString(aFormula));
+
+    // Error, warn the user if it is not an unknown name.
+    if (ta->GetCodeError() != FormulaError::NoName && (ta->GetCodeError() != 
FormulaError::NONE || ta->GetLen() == 0))
+    {
+        rEntry.set_message_type(weld::EntryMessageType::Error);
+        rLabel.set_label(ScResId(STR_VALID_DEFERROR));
+        return;
+    }
+
+    // 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)
+    {
+        rEntry.set_message_type(weld::EntryMessageType::Warning);
+        rLabel.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))
+    {
+        rEntry.set_message_type(weld::EntryMessageType::Error);
+        rLabel.set_label(ScResId(STR_VALID_DEFERROR));
+        return;
+    }
+
+    rEntry.set_message_type(weld::EntryMessageType::Normal);
+    rLabel.set_label(u""_ustr);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/condformateasydlg.hxx 
b/sc/source/ui/inc/condformateasydlg.hxx
index d9eb8b5cd49f..8bc21215b178 100644
--- a/sc/source/ui/inc/condformateasydlg.hxx
+++ b/sc/source/ui/inc/condformateasydlg.hxx
@@ -34,6 +34,7 @@ public:
 
     DECL_LINK(ButtonPressed, weld::Button&, void);
     DECL_LINK(StyleSelectHdl, weld::ComboBox&, void);
+    DECL_LINK(OnEdChanged, weld::Entry&, void);
 
 private:
     void SetDescription(std::u16string_view rCondition);
@@ -52,6 +53,7 @@ private:
     std::unique_ptr<weld::Entry> mxNumberEntry;
     std::unique_ptr<weld::Entry> mxNumberEntry2;
     std::unique_ptr<weld::Container> mxAllInputs;
+    std::unique_ptr<weld::Label> mxWarningLabel;
     std::unique_ptr<formula::RefEdit> mxRangeEntry;
     std::unique_ptr<formula::RefButton> mxButtonRangeEdit;
     std::unique_ptr<weld::ComboBox> mxStyles;
diff --git a/sc/source/ui/inc/condformathelper.hxx 
b/sc/source/ui/inc/condformathelper.hxx
index b1ff300b1a88..f3bd7b2a2013 100644
--- a/sc/source/ui/inc/condformathelper.hxx
+++ b/sc/source/ui/inc/condformathelper.hxx
@@ -38,6 +38,7 @@ public:
                                          const ScDocument* pDoc, 
SvxFontPrevWindow& rWdPreview);
     static SC_DLLPUBLIC void FillStyleListBox(const ScDocument* pDocument, 
weld::ComboBox& rCombo);
     static SC_DLLPUBLIC void UpdateStyleList(weld::ComboBox& rLbStyle, const 
ScDocument* pDoc);
+    static SC_DLLPUBLIC void ValidateInputField(weld::Entry& rEntry, 
weld::Label& label, ScDocument* pDoc, ScAddress& rPos);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/uiconfig/scalc/ui/conditionaleasydialog.ui 
b/sc/uiconfig/scalc/ui/conditionaleasydialog.ui
index 0f3348bc5c8e..ac5a056eba35 100644
--- a/sc/uiconfig/scalc/ui/conditionaleasydialog.ui
+++ b/sc/uiconfig/scalc/ui/conditionaleasydialog.ui
@@ -221,6 +221,17 @@
                 <property name="position">0</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkLabel" id="warning">
+                <property name="visible">False</property>
+                <property name="can-focus">False</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
             <child>
               <object class="GtkFrame">
                 <property name="visible">True</property>
@@ -290,7 +301,7 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">True</property>
-                <property name="position">1</property>
+                <property name="position">2</property>
               </packing>
             </child>
             <child>
@@ -317,7 +328,7 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">True</property>
-                <property name="position">2</property>
+                <property name="position">3</property>
               </packing>
             </child>
           </object>

Reply via email to