cui/source/inc/numfmt.hxx | 5 +++-- cui/source/tabpages/numfmt.cxx | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 6 deletions(-)
New commits: commit cf40efa7518fb78c6ec12a6fa2c0fef284fa2a87 Author: Eike Rathke <er...@redhat.com> AuthorDate: Sun Oct 4 00:57:08 2020 +0200 Commit: Eike Rathke <er...@redhat.com> CommitDate: Sun Oct 4 11:31:54 2020 +0200 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 <er...@redhat.com> Tested-by: Jenkins diff --git a/cui/source/inc/numfmt.hxx b/cui/source/inc/numfmt.hxx index a3368003859d..a89e6ff2d355 100644 --- a/cui/source/inc/numfmt.hxx +++ b/cui/source/inc/numfmt.hxx @@ -76,12 +76,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 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); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits