diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2022-07-11 13:59:16 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-07-12 07:22:32 +0200 |
commit | faa88099d842b83365fa86a661dc56f0031a9b29 (patch) | |
tree | f60dc7c0c77873f6a15e6ca1d2780cc3f4d11e8b /sw/source/uibase/dbui/dbmgr.cxx | |
parent | 86977309bf5ff716ecf74e337a70f0f7f8edb5cd (diff) |
tdf#149947: simplify filter list creation
Change-Id: Ic44d217a5593cc8694bc2f2f2e19e0c66d3ae9a5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136957
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sw/source/uibase/dbui/dbmgr.cxx')
-rw-r--r-- | sw/source/uibase/dbui/dbmgr.cxx | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx index 0d526bab42c3..15a1105e47b5 100644 --- a/sw/source/uibase/dbui/dbmgr.cxx +++ b/sw/source/uibase/dbui/dbmgr.cxx @@ -2784,40 +2784,44 @@ OUString SwDBManager::LoadAndRegisterDataSource(weld::Window* pParent, SwDocShel OUString sFilterAll(SwResId(STR_FILTER_ALL)); OUString sFilterAllData(SwResId(STR_FILTER_ALL_DATA)); - OUString sFilterSXB(SwResId(STR_FILTER_SXB)); - OUString sFilterSXC(SwResId(STR_FILTER_SXC)); - OUString sFilterSXW(SwResId(STR_FILTER_SXW)); - OUString sFilterDBF(SwResId(STR_FILTER_DBF)); - OUString sFilterXLS(SwResId(STR_FILTER_XLS)); - OUString sFilterDOC(SwResId(STR_FILTER_DOC)); - OUString sFilterTXT(SwResId(STR_FILTER_TXT)); - OUString sFilterCSV(SwResId(STR_FILTER_CSV)); + + const std::vector<std::pair<OUString, OUString>> filters{ + { SwResId(STR_FILTER_SXB), "*.odb" }, + { SwResId(STR_FILTER_SXC), "*.ods;*.sxc" }, + { SwResId(STR_FILTER_SXW), "*.odt;*.sxw" }, + { SwResId(STR_FILTER_DBF), "*.dbf" }, + { SwResId(STR_FILTER_XLS), "*.xls;*.xlsx" }, + { SwResId(STR_FILTER_DOC), "*.doc;*.docx" }, + { SwResId(STR_FILTER_TXT), "*.txt" }, + { SwResId(STR_FILTER_CSV), "*.csv" }, #ifdef _WIN32 - OUString sFilterMDB(SwResId(STR_FILTER_MDB)); - OUString sFilterACCDB(SwResId(STR_FILTER_ACCDB)); + { SwResId(STR_FILTER_MDB), "*.mdb;*.mde" }, + { SwResId(STR_FILTER_ACCDB), "*.accdb;*.accde" }, #endif + }; + + OUStringBuffer sAllDataFilter; + for (const auto& [name, filter] : filters) + { + (void)name; + if (!sAllDataFilter.isEmpty()) + sAllDataFilter.append(';'); + sAllDataFilter.append(filter); + } + xFP->appendFilter( sFilterAll, "*" ); - xFP->appendFilter( sFilterAllData, "*.ods;*.sxc;*.odt;*.sxw;*.dbf;*.xls;*.xlsx;*.doc;*.docx;*.txt;*.csv"); - - xFP->appendFilter( sFilterSXB, "*.odb" ); - xFP->appendFilter( sFilterSXC, "*.ods;*.sxc" ); - xFP->appendFilter( sFilterSXW, "*.odt;*.sxw" ); - xFP->appendFilter( sFilterDBF, "*.dbf" ); - xFP->appendFilter( sFilterXLS, "*.xls;*.xlsx" ); - xFP->appendFilter( sFilterDOC, "*.doc;*.docx" ); - xFP->appendFilter( sFilterTXT, "*.txt" ); - xFP->appendFilter( sFilterCSV, "*.csv" ); -#ifdef _WIN32 - xFP->appendFilter(sFilterMDB, "*.mdb;*.mde"); - xFP->appendFilter(sFilterACCDB, "*.accdb;*.accde"); -#endif + xFP->appendFilter( sFilterAllData, sAllDataFilter.makeStringAndClear()); + + // Similar to sfx2::addExtension from sfx2/source/dialog/filtergrouping.cxx + for (const auto& [name, filter] : filters) + xFP->appendFilter(name + " (" + filter + ")", filter); xFP->setCurrentFilter( sFilterAll ) ; OUString sFind; if( ERRCODE_NONE == aDlgHelper.Execute() ) { uno::Reference< beans::XPropertySet > aSettings; - const INetURLObject aURL( xFP->getSelectedFiles().getConstArray()[0] ); + const INetURLObject aURL( xFP->getSelectedFiles()[0] ); const DBConnURIType type = GetDBunoType( aURL ); if( DBConnURIType::FLAT == type ) |