From ddcd36d9d6191bfba7dea179067767a9ee192608 Mon Sep 17 00:00:00 2001 From: tagezi Date: Wed, 14 Nov 2018 00:30:45 +0300 Subject: tdf#39593 deduplicate code in TreeListBox Separates filling treelist for macros and dialogs to function Change-Id: I5803b94617ed6136f97be922c9da9d705f30b9b0 Reviewed-on: https://gerrit.libreoffice.org/63346 Tested-by: Jenkins Reviewed-by: Katarina Behrens --- basctl/source/basicide/bastype2.cxx | 75 +++++++++++++------------------------ basctl/source/inc/bastype2.hxx | 15 ++++---- 2 files changed, 33 insertions(+), 57 deletions(-) (limited to 'basctl') diff --git a/basctl/source/basicide/bastype2.cxx b/basctl/source/basicide/bastype2.cxx index fb7843658f40..8066cf2f8814 100644 --- a/basctl/source/basicide/bastype2.cxx +++ b/basctl/source/basicide/bastype2.cxx @@ -316,23 +316,7 @@ void TreeListBox::ImpCreateLibSubEntries( SvTreeListEntry* pLibRootEntry, const if ( nMode & BrowseMode::Subs ) { Sequence< OUString > aNames = GetMethodNames( rDocument, rLibName, aModName ); - sal_Int32 nCount = aNames.getLength(); - const OUString* pNames = aNames.getConstArray(); - - for ( sal_Int32 j = 0 ; j < nCount ; j++ ) - { - OUString aName = pNames[ j ]; - SvTreeListEntry* pEntry = FindEntry( pModuleEntry, aName, OBJ_TYPE_METHOD ); - if ( !pEntry ) - { - AddEntry( - aName, - Image(BitmapEx(RID_BMP_MACRO)), - pModuleEntry, false, - o3tl::make_unique( - OBJ_TYPE_METHOD)); - } - } + FillTreeListBox( pModuleEntry, aNames, OBJ_TYPE_METHOD, RID_BMP_MACRO ); } } } @@ -355,22 +339,7 @@ void TreeListBox::ImpCreateLibSubEntries( SvTreeListEntry* pLibRootEntry, const { // get a sorted list of dialog names Sequence< OUString > aDlgNames( rDocument.getObjectNames( E_DIALOGS, rLibName ) ); - sal_Int32 nDlgCount = aDlgNames.getLength(); - const OUString* pDlgNames = aDlgNames.getConstArray(); - - for ( sal_Int32 i = 0 ; i < nDlgCount ; i++ ) - { - OUString aDlgName = pDlgNames[ i ]; - SvTreeListEntry* pDialogEntry = FindEntry( pLibRootEntry, aDlgName, OBJ_TYPE_DIALOG ); - if ( !pDialogEntry ) - { - AddEntry( - aDlgName, - Image(BitmapEx(RID_BMP_DIALOG)), - pLibRootEntry, false, - o3tl::make_unique(OBJ_TYPE_DIALOG)); - } - } + FillTreeListBox( pLibRootEntry, aDlgNames, OBJ_TYPE_DIALOG, RID_BMP_DIALOG ); } catch (const container::NoSuchElementException& ) { @@ -472,22 +441,7 @@ void TreeListBox::ImpCreateLibSubSubEntriesInVBAMode( SvTreeListEntry* pLibSubRo if ( nMode & BrowseMode::Subs ) { Sequence< OUString > aNames = GetMethodNames( rDocument, rLibName, aModName ); - sal_Int32 nCount = aNames.getLength(); - const OUString* pNames = aNames.getConstArray(); - - for ( sal_Int32 j = 0 ; j < nCount ; j++ ) - { - OUString aName = pNames[ j ]; - SvTreeListEntry* pEntry = FindEntry( pModuleEntry, aName, OBJ_TYPE_METHOD ); - if ( !pEntry ) - { - AddEntry( - aName, - Image(BitmapEx(RID_BMP_MACRO)), - pModuleEntry, false, - o3tl::make_unique(OBJ_TYPE_METHOD)); - } - } + FillTreeListBox( pModuleEntry, aNames, OBJ_TYPE_METHOD, RID_BMP_MACRO ); } } } @@ -691,6 +645,29 @@ bool TreeListBox::IsEntryProtected( SvTreeListEntry* pEntry ) return bProtected; } +//Fills up treelist for macros and dialogs +void TreeListBox::FillTreeListBox( SvTreeListEntry* pRootEntry, const Sequence< OUString >& rNames, + const EntryType& eType, const OUString& aBmpMacro ) +{ + sal_Int32 nCount = rNames.getLength(); + const OUString* pNames = rNames.getConstArray(); + + for ( sal_Int32 j = 0 ; j < nCount ; j++ ) + { + OUString aName = pNames[ j ]; + SvTreeListEntry* pEntry = FindEntry( pRootEntry, aName, eType ); + + if ( !pEntry ) + { + AddEntry( + aName, + Image(BitmapEx( aBmpMacro )), + pRootEntry, false, + o3tl::make_unique( eType )); + } + } +} + SvTreeListEntry* TreeListBox::AddEntry( OUString const& rText, const Image& rImage, diff --git a/basctl/source/inc/bastype2.hxx b/basctl/source/inc/bastype2.hxx index 8e699aafc7fc..5dccdb17bb09 100644 --- a/basctl/source/inc/bastype2.hxx +++ b/basctl/source/inc/bastype2.hxx @@ -49,6 +49,7 @@ namespace o3tl { namespace basctl { +using namespace ::com::sun::star::uno; enum EntryType { @@ -149,16 +150,12 @@ public: EntryType eType ); - ScriptDocument const& GetDocument() const { return m_aDocument; } - - LibraryLocation GetLocation() const { return m_eLocation; } - - const OUString& GetLibName() const { return m_aLibName; } + ScriptDocument const& GetDocument() const { return m_aDocument; } + LibraryLocation GetLocation() const { return m_eLocation; } + const OUString& GetLibName() const { return m_aLibName; } const OUString& GetLibSubName() const { return m_aLibSubName; } - - const OUString& GetName() const { return m_aName; } - + const OUString& GetName() const { return m_aName; } const OUString& GetMethodName() const { return m_aMethodName; } void SetMethodName( const OUString& aMethodName ) { m_aMethodName = aMethodName; } @@ -235,6 +232,8 @@ public: static ItemType ConvertType (EntryType eType); bool IsValidEntry( SvTreeListEntry* pEntry ); + void FillTreeListBox( SvTreeListEntry* pRootEntry, const Sequence< OUString >& rNames, + const EntryType& eType, const OUString& aBmpMacro ); SvTreeListEntry* AddEntry( const OUString& rText, const Image& rImage, SvTreeListEntry* pParent, bool bChildrenOnDemand, -- cgit v1.2.3