sw/source/ui/table/instable.cxx | 71 +++++++------------------------------- sw/source/uibase/inc/instable.hxx | 7 --- 2 files changed, 14 insertions(+), 64 deletions(-)
New commits: commit 2f16debb36b6f92e9be8749bbfc466cd779aa162 Author: Vladislav Tarakanov <[email protected]> AuthorDate: Wed Dec 24 20:57:14 2025 +0400 Commit: Mike Kaganski <[email protected]> CommitDate: Thu Dec 25 06:05:58 2025 +0100 sw: Simplifying the "Insert Table" dialog The table creation dialog currently contains some confusing code related to converting a style index in the tree to a style index in the table. A magic number of 255 has been introduced, which has no connection to the objective limitations of the style list and requires separate processing when defining a style. This change merges the "- None -" style and the document's table styles into a single list. The "- None -" style is placed before all others, preserving the current behavior. This also removes the artificial limitation of 255 styles, expanding it to the maximum of size_t. Change-Id: Iac3be58d4473b184742fe5cb32ca4f1240f3d805 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196203 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/sw/source/ui/table/instable.cxx b/sw/source/ui/table/instable.cxx index b8a1e32ce611..36da6decf1f0 100644 --- a/sw/source/ui/table/instable.cxx +++ b/sw/source/ui/table/instable.cxx @@ -134,80 +134,37 @@ void SwInsTableDlg::InitAutoTableFormat() m_xTableTable.reset(new SwTableAutoFormatTable(SwModule::get()->GetAutoFormatTable())); // Add "- none -" style autoformat table. - m_xLbFormat->append_text(SwViewShell::GetShellRes()->aStrNone); // Insert to listbox + std::unique_ptr<SwTableAutoFormat> pNoneStyle( + new SwTableAutoFormat(TableStyleName(SwViewShell::GetShellRes()->aStrNone))); + pNoneStyle->DisableAll(); + m_xTableTable->InsertAutoFormat(0, std::move(pNoneStyle)); - // Add other styles of autoformat tables. - for (sal_uInt8 i = 0, nCount = static_cast<sal_uInt8>(m_xTableTable->size()); - i < nCount; i++) + for (size_t i = 0; i < m_xTableTable->size(); i++) { - SwTableAutoFormat const& rFormat = (*m_xTableTable)[ i ]; - m_xLbFormat->append_text(rFormat.GetName().toString()); - if (m_xTAutoFormat && rFormat.GetName() == m_xTAutoFormat->GetName()) - m_lbIndex = i; + m_xLbFormat->append_text((*m_xTableTable)[i].GetName().toString()); } - // Change this min variable if you add autotable manually. - minTableIndexInLb = 1; - maxTableIndexInLb = minTableIndexInLb + static_cast<sal_uInt8>(m_xTableTable->size()); - // 1 means default table style - // unfortunately when the table has a style sw/qa/uitest/writer_tests4/tdf115573.py fails - // because tables that have pre-applied style resets the style of the elements in their cells - // when a new row is inserted and the ui test above relies on that. - m_lbIndex = 0; - m_xLbFormat->select(m_lbIndex); - m_tbIndex = lbIndexToTableIndex(m_lbIndex); + m_xLbFormat->select(0); SelFormatHdl( *m_xLbFormat ); } -sal_uInt8 SwInsTableDlg::lbIndexToTableIndex( const sal_uInt8 listboxIndex ) -{ - if( minTableIndexInLb != maxTableIndexInLb && - minTableIndexInLb <= listboxIndex && - listboxIndex < maxTableIndexInLb ) - { - return listboxIndex - minTableIndexInLb; - } - - return 255; -} - IMPL_LINK_NOARG(SwInsTableDlg, SelFormatHdl, weld::TreeView&, void) { // Get index of selected item from the listbox - m_lbIndex = static_cast<sal_uInt8>(m_xLbFormat->get_selected_index()); - m_tbIndex = lbIndexToTableIndex( m_lbIndex ); - - // To understand this index mapping, look InitAutoTableFormat function to - // see how listbox item is implemented. - if( m_tbIndex < 255 ) - m_aWndPreview.NotifyChange( (*m_xTableTable)[m_tbIndex] ); - else - { - SwTableAutoFormat aTmp( TableStyleName(SwViewShell::GetShellRes()->aStrNone) ); - aTmp.DisableAll(); - - m_aWndPreview.NotifyChange( aTmp ); - } + size_t styleIdx = m_xLbFormat->get_selected_index(); + m_aWndPreview.NotifyChange((*m_xTableTable)[styleIdx]); } IMPL_LINK_NOARG(SwInsTableDlg, OKHdl, weld::Button&, void) { - if( m_tbIndex < 255 ) - m_pShell->SetTableStyle((*m_xTableTable)[m_tbIndex]); + size_t styleIdx = m_xLbFormat->get_selected_index(); + m_pShell->SetTableStyle((*m_xTableTable)[styleIdx]); - if( m_tbIndex < 255 ) - { - if( m_xTAutoFormat ) - *m_xTAutoFormat = (*m_xTableTable)[ m_tbIndex ]; - else - m_xTAutoFormat.reset(new SwTableAutoFormat( (*m_xTableTable)[ m_tbIndex ] )); - } + if( m_xTAutoFormat ) + *m_xTAutoFormat = (*m_xTableTable)[styleIdx]; else - { - m_xTAutoFormat.reset(new SwTableAutoFormat( TableStyleName(SwViewShell::GetShellRes()->aStrNone) )); - m_xTAutoFormat->DisableAll(); - } + m_xTAutoFormat.reset(new SwTableAutoFormat((*m_xTableTable)[styleIdx])); m_xDialog->response(RET_OK); } diff --git a/sw/source/uibase/inc/instable.hxx b/sw/source/uibase/inc/instable.hxx index 7c1a03881930..e8476e14d0cd 100644 --- a/sw/source/uibase/inc/instable.hxx +++ b/sw/source/uibase/inc/instable.hxx @@ -41,10 +41,6 @@ class SwInsTableDlg final : public SfxDialogController std::unique_ptr<SwTableAutoFormatTable> m_xTableTable; std::unique_ptr<SwTableAutoFormat> m_xTAutoFormat; - sal_uInt8 m_lbIndex; - sal_uInt8 m_tbIndex; - sal_uInt8 minTableIndexInLb; - sal_uInt8 maxTableIndexInLb; sal_Int64 m_nEnteredValRepeatHeaderNF; AutoFormatPreview m_aWndPreview; @@ -63,9 +59,6 @@ class SwInsTableDlg final : public SfxDialogController std::unique_ptr<weld::CustomWeld> m_xWndPreview; std::unique_ptr<weld::Frame> m_xStyleFrame; - // Returns 255 if mapping is not possible. - // This means there cannot be more than 255 autotable style. - sal_uInt8 lbIndexToTableIndex(const sal_uInt8 listboxIndex); void InitAutoTableFormat(); DECL_LINK(TextFilterHdl, OUString&, bool);
