diff options
author | Andreas Heinisch <andreas.heinisch@yahoo.de> | 2019-08-04 10:01:27 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-08-04 12:55:18 +0200 |
commit | a1b700a787e2f5bb46f7b39a704aed7c3c81bed9 (patch) | |
tree | 0fa2be02d926c8b07ff4dcde5e4890133e68a81e /basctl | |
parent | 893d22e11b78cc0d34af7d96d0ff2d0c3a34f9fb (diff) |
tdf#93476 Sort Macro library list after creating/importing a macro
Improved GetMergedLibraryNames: Create only one list and sort it at the
end
Change-Id: Id02aa994fe3b8fcaad115c0e3fcaca56601ee8bf
Reviewed-on: https://gerrit.libreoffice.org/76911
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'basctl')
-rw-r--r-- | basctl/source/basicide/basobj2.cxx | 52 |
1 files changed, 19 insertions, 33 deletions
diff --git a/basctl/source/basicide/basobj2.cxx b/basctl/source/basicide/basobj2.cxx index 801be80507b4..9160637a015a 100644 --- a/basctl/source/basicide/basobj2.cxx +++ b/basctl/source/basicide/basobj2.cxx @@ -29,6 +29,7 @@ #include <basic/sbmeth.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/string.hxx> +#include <comphelper/sequence.hxx> #include <framework/documentundoguard.hxx> #include <sal/log.hxx> #include <tools/diagnose_ex.h> @@ -93,55 +94,40 @@ bool IsValidSbxName( const OUString& rName ) Sequence< OUString > GetMergedLibraryNames( const Reference< script::XLibraryContainer >& xModLibContainer, const Reference< script::XLibraryContainer >& xDlgLibContainer ) { - // create a sorted list of module library names - auto const sort = comphelper::string::NaturalStringSorter( - comphelper::getProcessComponentContext(), - Application::GetSettings().GetUILanguageTag().getLocale()); - std::vector<OUString> aModLibList; + // create a list of module library names + std::vector<OUString> aLibList; if ( xModLibContainer.is() ) { Sequence< OUString > aModLibNames = xModLibContainer->getElementNames(); sal_Int32 nModLibCount = aModLibNames.getLength(); const OUString* pModLibNames = aModLibNames.getConstArray(); for ( sal_Int32 i = 0 ; i < nModLibCount ; i++ ) - aModLibList.push_back( pModLibNames[ i ] ); - std::sort(aModLibList.begin(), aModLibList.end(), - [&sort](const OUString& rLHS, const OUString& rRHS) { - return sort.compare(rLHS, rRHS) < 0; - }); + aLibList.push_back( pModLibNames[ i ] ); } - // create a sorted list of dialog library names - std::vector<OUString> aDlgLibList; + // create a list of dialog library names if ( xDlgLibContainer.is() ) { Sequence< OUString > aDlgLibNames = xDlgLibContainer->getElementNames(); sal_Int32 nDlgLibCount = aDlgLibNames.getLength(); const OUString* pDlgLibNames = aDlgLibNames.getConstArray(); for ( sal_Int32 i = 0 ; i < nDlgLibCount ; i++ ) - aDlgLibList.push_back( pDlgLibNames[ i ] ); - std::sort(aDlgLibList.begin(), aDlgLibList.end(), - [&sort](const OUString& rLHS, const OUString& rRHS) { - return sort.compare(rLHS, rRHS) < 0; - }); + aLibList.push_back( pDlgLibNames[ i ] ); } - // merge both lists - std::vector<OUString> aLibList( aModLibList.size() + aDlgLibList.size() ); - std::merge(aModLibList.begin(), aModLibList.end(), aDlgLibList.begin(), aDlgLibList.end(), - aLibList.begin(), [&sort](const OUString& rLHS, const OUString& rRHS) { - return sort.compare(rLHS, rRHS) < 0; - }); - std::vector<OUString>::iterator aIterEnd = std::unique( aLibList.begin(), aLibList.end() ); // move unique elements to the front - aLibList.erase( aIterEnd, aLibList.end() ); // remove duplicates - - // copy to sequence - sal_Int32 nLibCount = aLibList.size(); - Sequence< OUString > aSeqLibNames( nLibCount ); - for ( sal_Int32 i = 0 ; i < nLibCount ; i++ ) - aSeqLibNames.getArray()[ i ] = aLibList[ i ]; - - return aSeqLibNames; + // sort list + auto const sort = comphelper::string::NaturalStringSorter( + comphelper::getProcessComponentContext(), + Application::GetSettings().GetUILanguageTag().getLocale()); + std::sort(aLibList.begin(), aLibList.end(), + [&sort](const OUString& rLHS, const OUString& rRHS) { + return sort.compare(rLHS, rRHS) < 0; + }); + // remove duplicates + std::vector<OUString>::iterator aIterEnd = std::unique( aLibList.begin(), aLibList.end() ); + aLibList.erase( aIterEnd, aLibList.end() ); + + return comphelper::containerToSequence(aLibList); } bool RenameModule ( |