diff options
author | Eike Rathke <erack@redhat.com> | 2020-10-04 00:57:08 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2020-10-04 11:31:54 +0200 |
commit | cf40efa7518fb78c6ec12a6fa2c0fef284fa2a87 (patch) | |
tree | 33a04b0e85842a3f6d9c5558013b0998460a37d0 /cui/source/tabpages | |
parent | 16fc984bda55febdbc54bae7b34c5dc07dca7b41 (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
Diffstat (limited to 'cui/source/tabpages')
-rw-r--r-- | cui/source/tabpages/numfmt.cxx | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/cui/source/tabpages/numfmt.cxx b/cui/source/tabpages/numfmt.cxx index 18df998b492c..9cefae5d85ae 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); |