tdf#132869 - Show the error message in a tooltip
In the define name dialog, the input itself should show the error
message in a tooltip. In addition, the possibility to test the tooltip
text in python was added.
Change-Id: I9bd7d2b2be8300aa366971f8a1f115e8ae19fb98
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113513
Tested-by: Jenkins
Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
diff --git a/sc/qa/uitest/range_name/tdf86214.py b/sc/qa/uitest/range_name/tdf86214.py
index d529a47..48817e0 100644
--- a/sc/qa/uitest/range_name/tdf86214.py
+++ b/sc/qa/uitest/range_name/tdf86214.py
@@ -39,16 +39,18 @@ class InvalidNames(UITestCase):
select_all(xEdit)
type_text(xEdit, name)
new_text = get_state_as_dict(xLabel)["Text"]
self.assertNotEqual(success_text, new_text)
# tdf#132869 - Without the fix in place, this test would have failed with
# - Expected: "Invalid name. Start with a letter, use only letters, numbers and underscore."
# - Actual : ""
self.assertNotEqual(success_text, get_state_as_dict(xEdit)["QuickHelpText"])
self.assertEqual(get_state_as_dict(xAddBtn)["Enabled"], "false")
select_all(xEdit)
type_text(xEdit, "valid_name")
new_text = get_state_as_dict(xLabel)["Text"]
self.assertEqual(success_text, new_text)
self.assertEqual(success_text, get_state_as_dict(xLabel)["Text"])
self.assertEqual(success_text, get_state_as_dict(xEdit)["QuickHelpText"])
self.assertEqual(get_state_as_dict(xAddBtn)["Enabled"], "true")
self.ui_test.close_dialog_through_button(xAddBtn)
diff --git a/sc/source/ui/namedlg/namedefdlg.cxx b/sc/source/ui/namedlg/namedefdlg.cxx
index 25ff6e1..6580266 100644
--- a/sc/source/ui/namedlg/namedefdlg.cxx
+++ b/sc/source/ui/namedlg/namedefdlg.cxx
@@ -120,6 +120,9 @@ bool ScNameDefDlg::IsNameValid()
OUString aScope = m_xLbScope->get_active_text();
OUString aName = m_xEdName->get_text();
bool bIsNameValid = true;
OUString aHelpText = maStrInfoDefault;
ScRangeName* pRangeName = nullptr;
if(aScope == maGlobalNameStr)
{
@@ -131,46 +134,39 @@ bool ScNameDefDlg::IsNameValid()
}
ScRangeData::IsNameValidType eType;
m_xFtInfo->set_label_type(weld::LabelType::Normal);
if ( aName.isEmpty() )
{
m_xBtnAdd->set_sensitive(false);
m_xFtInfo->set_label(maStrInfoDefault);
return false;
bIsNameValid = false;
}
else if ((eType = ScRangeData::IsNameValid(aName, mrDoc))
!= ScRangeData::IsNameValidType::NAME_VALID)
{
m_xFtInfo->set_label_type(weld::LabelType::Error);
if (eType == ScRangeData::IsNameValidType::NAME_INVALID_BAD_STRING)
{
m_xFtInfo->set_label(maErrInvalidNameStr);
aHelpText = maErrInvalidNameStr;
}
else if (eType == ScRangeData::IsNameValidType::NAME_INVALID_CELL_REF)
{
m_xFtInfo->set_label(maErrInvalidNameCellRefStr);
aHelpText = maErrInvalidNameCellRefStr;
}
m_xBtnAdd->set_sensitive(false);
return false;
bIsNameValid = false;
}
else if (pRangeName->findByUpperName(ScGlobal::getCharClassPtr()->uppercase(aName)))
{
m_xFtInfo->set_label_type(weld::LabelType::Error);
m_xFtInfo->set_label(maErrNameInUse);
m_xBtnAdd->set_sensitive(false);
return false;
aHelpText = maErrNameInUse;
bIsNameValid = false;
}
if (!IsFormulaValid())
{
m_xFtInfo->set_label_type(weld::LabelType::Error);
m_xBtnAdd->set_sensitive(false);
return false;
bIsNameValid = false;
}
m_xFtInfo->set_label(maStrInfoDefault);
m_xBtnAdd->set_sensitive(true);
return true;
m_xEdName->set_tooltip_text(aHelpText);
m_xEdName->set_message_type(bIsNameValid || aName.isEmpty() ? weld::EntryMessageType::Normal
: weld::EntryMessageType::Error);
m_xBtnAdd->set_sensitive(bIsNameValid);
return bIsNameValid;
}
void ScNameDefDlg::AddPushed()
diff --git a/vcl/source/uitest/uiobject.cxx b/vcl/source/uitest/uiobject.cxx
index fc72053..4d8390e 100644
--- a/vcl/source/uitest/uiobject.cxx
+++ b/vcl/source/uitest/uiobject.cxx
@@ -785,6 +785,7 @@ StringMap EditUIObject::get_state()
{
StringMap aMap = WindowUIObject::get_state();
aMap["MaxTextLength"] = OUString::number(mxEdit->GetMaxTextLen());
aMap["QuickHelpText"] = mxEdit->GetQuickHelpText();
aMap["SelectedText"] = mxEdit->GetSelected();
aMap["Text"] = mxEdit->GetText();