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 2a6dc9dfd84b278352608f475a600e866846af2e
Author:     Pranam Lashkari <[email protected]>
AuthorDate: Fri Oct 11 05:50:22 2024 +0400
Commit:     Caolán McNamara <[email protected]>
CommitDate: Mon Oct 14 15:47:54 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 <[email protected]>
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/sc/source/ui/condformat/condformatdlgentry.cxx 
b/sc/source/ui/condformat/condformatdlgentry.cxx
index c3219a130d96..9212dcfe1bdd 100644
--- a/sc/source/ui/condformat/condformatdlgentry.cxx
+++ b/sc/source/ui/condformat/condformatdlgentry.cxx
@@ -242,48 +242,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("");
+    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 5955304a86ca..47936bdc64d9 100644
--- a/sc/source/ui/condformat/condformateasydlg.cxx
+++ b/sc/source/ui/condformat/condformateasydlg.cxx
@@ -68,6 +68,7 @@ 
ConditionalFormatEasyDialog::ConditionalFormatEasyDialog(SfxBindings* pBindings,
     , mxNumberEntry(m_xBuilder->weld_entry("entryNumber"))
     , mxNumberEntry2(m_xBuilder->weld_entry("entryNumber2"))
     , mxAllInputs(m_xBuilder->weld_container("allInputs"))
+    , mxWarningLabel(m_xBuilder->weld_label("warning"))
     , mxRangeEntry(new formula::RefEdit(m_xBuilder->weld_entry("entryRange")))
     , mxButtonRangeEdit(new 
formula::RefButton(m_xBuilder->weld_button("rbassign")))
     , mxStyles(m_xBuilder->weld_combo_box("themeCombo"))
@@ -247,6 +248,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);
@@ -397,4 +400,14 @@ 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
diff --git a/sc/source/ui/condformat/condformathelper.cxx 
b/sc/source/ui/condformat/condformathelper.cxx
index 5c8fb2480744..a78047cdece2 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("");
+}
+
 /* 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 ea7833ef6227..f680229e58c1 100644
--- a/sc/uiconfig/scalc/ui/conditionaleasydialog.ui
+++ b/sc/uiconfig/scalc/ui/conditionaleasydialog.ui
@@ -188,6 +188,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>
@@ -251,7 +262,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>
@@ -278,7 +289,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