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 <Katarina.Behrens@cib.de>
diff --git a/basctl/source/basicide/bastype2.cxx b/basctl/source/basicide/bastype2.cxx
index fb78436..8066cf2 100644
--- a/basctl/source/basicide/bastype2.cxx
+++ b/basctl/source/basicide/bastype2.cxx
@@ -316,23 +316,7 @@
                        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<Entry>(
                                            OBJ_TYPE_METHOD));
                                }
                            }
                            FillTreeListBox( pModuleEntry, aNames, OBJ_TYPE_METHOD, RID_BMP_MACRO );
                        }
                    }
                }
@@ -355,22 +339,7 @@
            {
                // 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<Entry>(OBJ_TYPE_DIALOG));
                    }
                }
                FillTreeListBox( pLibRootEntry, aDlgNames, OBJ_TYPE_DIALOG, RID_BMP_DIALOG );
            }
            catch (const container::NoSuchElementException& )
            {
@@ -472,22 +441,7 @@
            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<Entry>(OBJ_TYPE_METHOD));
                    }
                }
                FillTreeListBox( pModuleEntry, aNames, OBJ_TYPE_METHOD, RID_BMP_MACRO );
            }
        }
    }
@@ -691,6 +645,29 @@
    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<Entry>( 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 8e699aa..5dccdb1 100644
--- a/basctl/source/inc/bastype2.hxx
+++ b/basctl/source/inc/bastype2.hxx
@@ -49,6 +49,7 @@

namespace basctl
{
using namespace ::com::sun::star::uno;

enum EntryType
{
@@ -149,16 +150,12 @@
        EntryType eType
    );

    ScriptDocument const&   GetDocument() const { return m_aDocument; }
    ScriptDocument const&   GetDocument()   const { return m_aDocument; }
    LibraryLocation         GetLocation()   const { return m_eLocation; }

    LibraryLocation         GetLocation() const { return m_eLocation; }

    const OUString&         GetLibName() const { return m_aLibName; }

    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 @@
    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,