summaryrefslogtreecommitdiff
path: root/cui
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2020-10-04 00:57:08 +0200
committerCaolán McNamara <caolanm@redhat.com>2020-10-04 15:17:30 +0200
commit893bdbe8ff9fcf96ca212f72d080bad141a5d99e (patch)
tree11f05d2e74a1f72359013cba6b3ac7030a28597c /cui
parent40927b3792450142966cc7b5137ec6f084680d30 (diff)
Fix format comment handling in number format dialog
Clicking any format in the Format list could had applied the default 'User-defined' comment to that format. Also an edited comment for an already existing format when clicking on another format applied the new comment to that other format. Sometimes 'User-defined' was displayed instead of a real comment. Change-Id: I452d41f2860affed2475737e3bc925db687d96c2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103907 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins (cherry picked from commit cf40efa7518fb78c6ec12a6fa2c0fef284fa2a87) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103801 Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'cui')
-rw-r--r--cui/source/inc/numfmt.hxx5
-rw-r--r--cui/source/tabpages/numfmt.cxx35
2 files changed, 34 insertions, 6 deletions
diff --git a/cui/source/inc/numfmt.hxx b/cui/source/inc/numfmt.hxx
index 54796c63b736..1be328d9414e 100644
--- a/cui/source/inc/numfmt.hxx
+++ b/cui/source/inc/numfmt.hxx
@@ -77,12 +77,13 @@ public:
private:
std::unique_ptr<SvxNumberInfoItem> pNumItem;
std::unique_ptr<SvxNumberFormatShell> pNumFmtShell;
- sal_uLong nInitFormat;
+ sal_uLong nInitFormat;
+ short m_nLbFormatSelPosEdComment;
bool bNumItemFlag; ///< for handling with DocShell
bool bOneAreaFlag;
bool bLegacyAutomaticCurrency;
- short nFixedCategory;
+ short nFixedCategory;
OUString sAutomaticLangEntry;
OUString sAutomaticCurrencyEntry;
diff --git a/cui/source/tabpages/numfmt.cxx b/cui/source/tabpages/numfmt.cxx
index 4297cd52241e..5e3e4252a05b 100644
--- a/cui/source/tabpages/numfmt.cxx
+++ b/cui/source/tabpages/numfmt.cxx
@@ -195,6 +195,7 @@ SvxNumberFormatTabPage::SvxNumberFormatTabPage(weld::Container* pPage, weld::Dia
const SfxItemSet& rCoreAttrs)
: SfxTabPage(pPage, pController, "cui/ui/numberingformatpage.ui", "NumberingFormatPage", &rCoreAttrs)
, nInitFormat(ULONG_MAX)
+ , m_nLbFormatSelPosEdComment(SELPOS_NONE)
, bLegacyAutomaticCurrency(false)
, sAutomaticLangEntry(CuiResId(RID_SVXSTR_AUTO_ENTRY))
, m_xFtCategory(m_xBuilder->weld_label("categoryft"))
@@ -1166,6 +1167,18 @@ IMPL_LINK(SvxNumberFormatTabPage, SelFormatListBoxHdl_Impl, weld::ComboBox&, rLb
void SvxNumberFormatTabPage::SelFormatHdl_Impl(weld::Widget* pLb)
{
+ if (m_nLbFormatSelPosEdComment != SELPOS_NONE)
+ {
+ // Click handler is called before focus change handler, so finish
+ // comment editing of previous format, otherwise a new format will have
+ // the old comment displayed after LostFocusHdl_Impl() is called
+ // later. Also, clicking into another category invalidates the format
+ // list and SvxNumberFormatShell::SetComment4Entry() could either
+ // access a wrong format from aCurEntryList[nEntry] or crash there if
+ // the new vector has less elements.
+ LostFocusHdl_Impl(*pLb);
+ }
+
if (pLb == m_xCbSourceFormat.get())
{
EnableBySourceFormat_Impl(); // enable/disable everything else
@@ -1424,6 +1437,10 @@ bool SvxNumberFormatTabPage::Click_Impl(weld::Button& rIB)
{
if (!m_xEdComment->get_visible())
{
+ if (!m_xIbAdd->get_sensitive())
+ // Editing for existing format.
+ m_nLbFormatSelPosEdComment = m_xLbFormat->get_selected_index();
+
m_xEdComment->set_text(m_xFtComment->get_label());
m_xEdComment->show();
m_xFtComment->hide();
@@ -1432,6 +1449,7 @@ bool SvxNumberFormatTabPage::Click_Impl(weld::Button& rIB)
else
{
m_xEdFormat->grab_focus();
+ m_xFtComment->set_label( m_xEdComment->get_text());
m_xEdComment->hide();
m_xFtComment->show();
}
@@ -1600,13 +1618,22 @@ IMPL_LINK_NOARG(SvxNumberFormatTabPage, LostFocusHdl_Impl, weld::Widget&, void)
{
if (!pNumFmtShell)
return;
- m_xFtComment->set_label(m_xEdComment->get_text());
+
+ const bool bAddSensitive = m_xIbAdd->get_sensitive();
+ if (bAddSensitive || m_nLbFormatSelPosEdComment != SELPOS_NONE)
+ // Comment editing was possible.
+ m_xFtComment->set_label(m_xEdComment->get_text());
+
m_xEdComment->hide();
m_xFtComment->show();
- if(!m_xIbAdd->get_sensitive())
+ if (m_nLbFormatSelPosEdComment != SELPOS_NONE)
+ {
+ // Save edited comment of existing format.
+ pNumFmtShell->SetComment4Entry( m_nLbFormatSelPosEdComment, m_xEdComment->get_text());
+ m_nLbFormatSelPosEdComment = SELPOS_NONE;
+ }
+ if (!bAddSensitive)
{
- sal_uInt16 nSelPos = m_xLbFormat->get_selected_index();
- pNumFmtShell->SetComment4Entry(nSelPos, m_xEdComment->get_text());
// String for user defined, if present
OUString sEntry = m_xLbCategory->n_children() > 1 ? m_xLbCategory->get_text(1) : OUString();
m_xEdComment->set_text(sEntry);