diff options
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/inc/sfx2/doctempl.hxx | 3 | ||||
-rw-r--r-- | sfx2/source/doc/doctdlg.cxx | 5 | ||||
-rw-r--r-- | sfx2/source/doc/doctempl.cxx | 200 | ||||
-rw-r--r-- | sfx2/source/doc/docvor.cxx | 8 | ||||
-rw-r--r-- | sfx2/source/doc/new.cxx | 5 |
5 files changed, 75 insertions, 146 deletions
diff --git a/sfx2/inc/sfx2/doctempl.hxx b/sfx2/inc/sfx2/doctempl.hxx index b60ac9581792..df1d9f0c71bf 100644 --- a/sfx2/inc/sfx2/doctempl.hxx +++ b/sfx2/inc/sfx2/doctempl.hxx @@ -93,9 +93,6 @@ public: int nCount, const ::rtl::OUString& rString); - void EnableRegionSorting(bool isRegionSortingEnabled = true); - void EnableTemplateSorting(bool isTemplateSortingEnabled = true); - sal_Bool Copy(sal_uInt16 nTargetRegion, sal_uInt16 nTargetIdx, sal_uInt16 nSourceRegion, diff --git a/sfx2/source/doc/doctdlg.cxx b/sfx2/source/doc/doctdlg.cxx index c0f83a05cd8c..2b616182153d 100644 --- a/sfx2/source/doc/doctdlg.cxx +++ b/sfx2/source/doc/doctdlg.cxx @@ -73,8 +73,6 @@ SfxDocumentTemplateDlg::SfxDocumentTemplateDlg( Window * pParent, SfxDocumentTem aNameEd.SetModifyHdl(LINK(this, SfxDocumentTemplateDlg, NameModify)); aOkBt.SetClickHdl(LINK(this, SfxDocumentTemplateDlg, OkHdl)); aEditBt.SetClickHdl(LINK(this, SfxDocumentTemplateDlg, EditHdl)); - aRegionLb.SetStyle(aRegionLb.GetStyle() | WB_SORT); - aTemplateLb.SetStyle(aTemplateLb.GetStyle() | WB_SORT); Init(); } @@ -109,9 +107,6 @@ void SfxDocumentTemplateDlg::Init() if(!pTemplates->IsConstructed()) pTemplates->Construct(); - pTemplates->EnableRegionSorting(); - pTemplates->EnableTemplateSorting(); - const sal_uInt16 nCount = pTemplates->GetRegionCount(); for(sal_uInt16 i = 0; i < nCount; ++i) aRegionLb.InsertEntry(pTemplates->GetFullRegionName(i)); diff --git a/sfx2/source/doc/doctempl.cxx b/sfx2/source/doc/doctempl.cxx index d990d258763f..3f86df01ed6a 100644 --- a/sfx2/source/doc/doctempl.cxx +++ b/sfx2/source/doc/doctempl.cxx @@ -37,6 +37,7 @@ #include <vcl/settings.hxx> #include <unotools/localedatawrapper.hxx> #include <unotools/pathoptions.hxx> +#include <tools/resary.hxx> #include <tools/string.hxx> #include <tools/urlobj.hxx> #include <svtools/ehdl.hxx> @@ -101,7 +102,6 @@ using namespace ::ucbhelper; #include <unotools/ucbhelper.hxx> #include <vector> -#include <algorithm> using ::std::vector; using ::std::advance; @@ -170,13 +170,6 @@ public: sal_Bool DeleteObjectShell(); }; -class TemplateEntryCompare -{ -public: - bool operator()( DocTempl_EntryData_Impl* pA, DocTempl_EntryData_Impl* pB ) const - { return 0 > pA->Compare( pB->GetTitle() ); } -}; - } using namespace ::DocTempl; @@ -190,7 +183,6 @@ class RegionData_Impl OUString maTitle; OUString maOwnURL; OUString maTargetURL; - bool mbSortingEnabled; private: size_t GetEntryPos( const OUString& rTitle, @@ -221,20 +213,11 @@ public: size_t *pPos = NULL ); void DeleteEntry( size_t nIndex ); - void EnableSorting( bool isSortingEnabled = true ); - int Compare( const OUString& rTitle ) const { return maTitle.compareTo( rTitle ); } int Compare( RegionData_Impl* pCompareWith ) const; }; -class RegionCompare -{ -public: - bool operator()( RegionData_Impl* pA, RegionData_Impl* pB ) const - { return 0 > pA->Compare( pB ); } -}; - typedef vector< RegionData_Impl* > RegionList_Impl; // ------------------------------------------------------------------------ @@ -246,10 +229,9 @@ class SfxDocTemplate_Impl : public SvRefBase ::osl::Mutex maMutex; OUString maRootURL; + OUString maStandardGroup; RegionList_Impl maRegions; sal_Bool mbConstructed; - bool mbRegionSortingEnabled; - bool mbTemplateSortingEnabled; uno::Reference< XAnyCompareFactory > m_rCompareFactory; @@ -275,13 +257,6 @@ public: void Rescan(); - void EnableRegionSorting( bool isRegionSortingEnabled = true ); - void EnableTemplateSorting( bool isTemplateSortingEnabled = true ) - { mbTemplateSortingEnabled = isTemplateSortingEnabled; } - - bool IsRegionSortingEnabled() const { return mbRegionSortingEnabled; } - bool IsTemplateSortingEnabled() const { return mbTemplateSortingEnabled; } - void DeleteRegion( size_t nIndex ); size_t GetRegionCount() const @@ -645,28 +620,6 @@ OUString SfxDocumentTemplates::ConvertResourceString ( //------------------------------------------------------------------------ -/** Enables or disables the sorting of regions. - @param isRegionSortingEnabled - Whether to sort regions or not. -*/ -void SfxDocumentTemplates::EnableRegionSorting( bool isRegionSortingEnabled ) -{ - pImp->EnableRegionSorting( isRegionSortingEnabled ); -} - -//------------------------------------------------------------------------ - -/** Enables or disables the sorting of templates inside regions. - @param isTemplateSortingEnabled - Whether to sort templates or not. -*/ -void SfxDocumentTemplates::EnableTemplateSorting( bool isTemplateSortingEnabled ) -{ - pImp->EnableTemplateSorting( isTemplateSortingEnabled ); -} - -//------------------------------------------------------------------------ - sal_Bool SfxDocumentTemplates::CopyOrMove ( sal_uInt16 nTargetRegion, // Target Region Index @@ -1155,7 +1108,6 @@ sal_Bool SfxDocumentTemplates::InsertDir if ( xTemplates->addGroup( rText ) ) { RegionData_Impl* pNewRegion = new RegionData_Impl( pImp, rText ); - pNewRegion->EnableSorting( pImp->IsTemplateSortingEnabled() ); if ( ! pImp->InsertRegion( pNewRegion, nRegion ) ) { @@ -1215,10 +1167,6 @@ sal_Bool SfxDocumentTemplates::SetName pRegion->SetTitle( rName ); pRegion->SetTargetURL( aEmpty ); pRegion->SetHierarchyURL( aEmpty ); - - // force resorting if needed - pImp->EnableRegionSorting( pImp->IsRegionSortingEnabled() ); - return sal_True; } } @@ -1239,10 +1187,6 @@ sal_Bool SfxDocumentTemplates::SetName pEntry->SetTitle( rName ); pEntry->SetTargetURL( aEmpty ); pEntry->SetHierarchyURL( aEmpty ); - - // force resorting if needed - pRegion->EnableSorting( pImp->IsTemplateSortingEnabled() ); - return sal_True; } } @@ -1762,9 +1706,8 @@ const OUString& DocTempl_EntryData_Impl::GetTargetURL() RegionData_Impl::RegionData_Impl( const SfxDocTemplate_Impl* pParent, const OUString& rTitle ) { - maTitle = rTitle; - mpParent = pParent; - mbSortingEnabled = false; + maTitle = rTitle; + mpParent = pParent; } // ----------------------------------------------------------------------- @@ -1778,37 +1721,62 @@ RegionData_Impl::~RegionData_Impl() // ----------------------------------------------------------------------- size_t RegionData_Impl::GetEntryPos( const OUString& rTitle, sal_Bool& rFound ) const { - if ( mbSortingEnabled ) - { - DocTempl_EntryData_Impl aToFind( NULL, rTitle ); - vector< DocTempl_EntryData_Impl* >::const_iterator aPlaceToInsert = - ::std::lower_bound( maEntries.begin(), maEntries.end(), - &aToFind, TemplateEntryCompare() ); +#if 1 // Don't use binary search today + size_t i; + size_t nCount = maEntries.size(); - rFound = aPlaceToInsert != maEntries.end() && - 0 == (*aPlaceToInsert)->Compare( rTitle ); + for ( i=0; i<nCount; i++ ) + { + DocTempl_EntryData_Impl *pData = maEntries[ i ]; - return ::std::distance( maEntries.begin(), aPlaceToInsert ); + if ( pData->Compare( rTitle ) == 0 ) + { + rFound = sal_True; + return i; + } } - else + + rFound = sal_False; + return i; + +#else + // use binary search to find the correct position + // in the maEntries list + + int nCompVal = 1; + size_t nStart = 0; + size_t nEnd = maEntries.size() - 1; + size_t nMid; + + DocTempl_EntryData_Impl* pMid; + + rFound = sal_False; + + while ( nCompVal && ( nStart <= nEnd ) ) { - size_t i; - size_t nCount = maEntries.size(); + nMid = ( nEnd - nStart ) / 2 + nStart; + pMid = maEntries[ nMid ]; - for ( i=0; i<nCount; i++ ) - { - DocTempl_EntryData_Impl *pData = maEntries[ i ]; + nCompVal = pMid->Compare( rTitle ); - if ( pData->Compare( rTitle ) == 0 ) - { - rFound = sal_True; - return i; - } - } + if ( nCompVal < 0 ) // pMid < pData + nStart = nMid + 1; + else + nEnd = nMid - 1; + } - rFound = sal_False; - return i; + if ( nCompVal == 0 ) + { + rFound = sal_True; + } + else + { + if ( nCompVal < 0 ) // pMid < pData + nMid++; } + + return nMid; +#endif } // ----------------------------------------------------------------------- @@ -1822,20 +1790,23 @@ void RegionData_Impl::AddEntry( const OUString& rTitle, INetURLObject::ENCODE_ALL ); OUString aLinkURL = aLinkObj.GetMainURL( INetURLObject::NO_DECODE ); + DocTempl_EntryData_Impl* pEntry; sal_Bool bFound = sal_False; size_t nPos = GetEntryPos( rTitle, bFound ); - if ( !bFound ) + if ( bFound ) + { + pEntry = maEntries[ nPos ]; + } + else { - if ( !mbSortingEnabled && pPos ) + if ( pPos ) nPos = *pPos; - DocTempl_EntryData_Impl* pEntry = new DocTempl_EntryData_Impl( this, rTitle ); + pEntry = new DocTempl_EntryData_Impl( this, rTitle ); pEntry->SetTargetURL( rTargetURL ); pEntry->SetHierarchyURL( aLinkURL ); - - if ( nPos < maEntries.size() ) - { + if ( nPos < maEntries.size() ) { vector< DocTempl_EntryData_Impl* >::iterator it = maEntries.begin(); advance( it, nPos ); maEntries.insert( it, pEntry ); @@ -1927,15 +1898,6 @@ void RegionData_Impl::DeleteEntry( size_t nIndex ) } // ----------------------------------------------------------------------- -void RegionData_Impl::EnableSorting( bool isSortingEnabled ) -{ - mbSortingEnabled = isSortingEnabled; - - if ( mbSortingEnabled ) - ::std::sort( maEntries.begin(), maEntries.end(), TemplateEntryCompare() ); -} - -// ----------------------------------------------------------------------- int RegionData_Impl::Compare( RegionData_Impl* pCompare ) const { int nCompare = maTitle.compareTo( pCompare->maTitle ); @@ -1947,8 +1909,6 @@ int RegionData_Impl::Compare( RegionData_Impl* pCompare ) const SfxDocTemplate_Impl::SfxDocTemplate_Impl() : mbConstructed( sal_False ) -, mbRegionSortingEnabled( false ) -, mbTemplateSortingEnabled( false ) , mnLockCounter( 0 ) { } @@ -2017,7 +1977,6 @@ void SfxDocTemplate_Impl::AddRegion( const OUString& rTitle, { RegionData_Impl* pRegion; pRegion = new RegionData_Impl( this, rTitle ); - pRegion->EnableSorting( mbTemplateSortingEnabled ); if ( ! InsertRegion( pRegion ) ) { @@ -2140,6 +2099,11 @@ sal_Bool SfxDocTemplate_Impl::Construct( ) mbConstructed = sal_True; maRootURL = aRootContent->getIdentifier()->getContentIdentifier(); + ResStringArray aLongNames( SfxResId( TEMPLATE_LONG_NAMES_ARY ) ); + + if ( aLongNames.Count() ) + maStandardGroup = aLongNames.GetString( 0 ); + Content aTemplRoot( aRootContent, aCmdEnv ); CreateFromHierarchy( aTemplRoot ); @@ -2170,23 +2134,18 @@ sal_Bool SfxDocTemplate_Impl::InsertRegion( RegionData_Impl *pNew, size_t nPos ) if ( maRegions[ i ]->Compare( pNew ) == 0 ) return sal_False; - if ( mbRegionSortingEnabled ) + size_t newPos = nPos; + if ( pNew->GetTitle() == maStandardGroup ) + newPos = 0; + + if ( newPos < maRegions.size() ) { - RegionList_Impl::iterator aPlaceToInsert = - ::std::upper_bound( maRegions.begin(), maRegions.end(), pNew, RegionCompare() ); - maRegions.insert( aPlaceToInsert, pNew ); + RegionList_Impl::iterator it = maRegions.begin(); + advance( it, newPos ); + maRegions.insert( it, pNew ); } else - { - if ( nPos < maRegions.size() ) - { - RegionList_Impl::iterator it = maRegions.begin(); - advance( it, nPos ); - maRegions.insert( it, pNew ); - } - else - maRegions.push_back( pNew ); - } + maRegions.push_back( pNew ); return sal_True; } @@ -2218,15 +2177,6 @@ void SfxDocTemplate_Impl::Rescan() } // ----------------------------------------------------------------------- -void SfxDocTemplate_Impl::EnableRegionSorting( bool isRegionSortingEnabled ) -{ - mbRegionSortingEnabled = isRegionSortingEnabled; - - if ( mbRegionSortingEnabled ) - ::std::sort( maRegions.begin(), maRegions.end(), RegionCompare() ); -} - -// ----------------------------------------------------------------------- sal_Bool SfxDocTemplate_Impl::GetTitleFromURL( const OUString& rURL, OUString& aTitle ) { diff --git a/sfx2/source/doc/docvor.cxx b/sfx2/source/doc/docvor.cxx index b67d273f0a2c..f881a380cfeb 100644 --- a/sfx2/source/doc/docvor.cxx +++ b/sfx2/source/doc/docvor.cxx @@ -217,12 +217,6 @@ SfxOrganizeDlg_Impl::SfxOrganizeDlg_Impl( SfxTemplateOrganizeDlg* pParent, pFileDlg ( NULL ) { - // Enable sorting in the listboxes - aLeftLb.GetModel()->SetSortMode( SortAscending ); - aRightLb.GetModel()->SetSortMode( SortAscending ); - aLeftLb.GetModel()->SetCompareHdl( LINK( &aLeftLb, SvTreeListBox, DefaultCompare ) ); - aRightLb.GetModel()->SetCompareHdl( LINK( &aRightLb, SvTreeListBox, DefaultCompare ) ); - // update the SfxDocumentTemplates the manager works with if ( aMgr.GetTemplates() ) // should never fail, but who knows .... { @@ -232,8 +226,6 @@ SfxOrganizeDlg_Impl::SfxOrganizeDlg_Impl( SfxTemplateOrganizeDlg* pParent, pWaitObjectRange = pDialog; WaitObject aWaitCursor( pWaitObjectRange ); - const_cast< SfxDocumentTemplates* >( aMgr.GetTemplates() )->EnableRegionSorting(); - const_cast< SfxDocumentTemplates* >( aMgr.GetTemplates() )->EnableTemplateSorting(); const_cast< SfxDocumentTemplates* >( aMgr.GetTemplates() )->Update( sal_True /* be smart */ ); // this const_cast is a hack - but the alternative would be to // * have a method which returns the templates non-const diff --git a/sfx2/source/doc/new.cxx b/sfx2/source/doc/new.cxx index d09978c482e4..95b7bd48c4c1 100644 --- a/sfx2/source/doc/new.cxx +++ b/sfx2/source/doc/new.cxx @@ -559,14 +559,9 @@ SfxNewFileDialog_Impl::SfxNewFileDialog_Impl( aTemplateLb.SetSelectHdl(LINK(this, SfxNewFileDialog_Impl, TemplateSelect)); aTemplateLb.SetDoubleClickHdl(LINK(this, SfxNewFileDialog_Impl, DoubleClick)); - aTemplateLb.SetStyle(aTemplateLb.GetStyle() | WB_SORT); - aRegionLb.SetStyle(aRegionLb.GetStyle() | WB_SORT); - // update the template configuration if necessary { WaitObject aWaitCursor( pAntiImplP->GetParent() ); - aTemplates.EnableRegionSorting(); - aTemplates.EnableTemplateSorting(); aTemplates.Update( sal_True /* be smart */ ); } // fill the list boxes |