[Libreoffice-commits] .: 2 commits - sfx2/inc sfx2/source

Stephan Bergmann sbergmann at kemper.freedesktop.org
Tue Jan 10 23:21:13 PST 2012


 sfx2/inc/sfx2/doctempl.hxx       |    3 
 sfx2/source/doc/doctdlg.cxx      |    5 
 sfx2/source/doc/doctempl.cxx     |  200 ++++++++++++++-------------------------
 sfx2/source/doc/doctemplates.cxx |    3 
 sfx2/source/doc/docvor.cxx       |    8 -
 sfx2/source/doc/new.cxx          |    5 
 6 files changed, 77 insertions(+), 147 deletions(-)

New commits:
commit d506bc43f6982b33e42b3449cad059075f8faca1
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Tue Jan 10 16:38:24 2012 +0100

    Hide bogus "Untitled already exists" errors...
    
    ...when adding multiple new template regions in a row in
    SfxOrganizeDlg_Impl.

diff --git a/sfx2/source/doc/doctemplates.cxx b/sfx2/source/doc/doctemplates.cxx
index dcaaeca..fce978c 100644
--- a/sfx2/source/doc/doctemplates.cxx
+++ b/sfx2/source/doc/doctemplates.cxx
@@ -873,7 +873,8 @@ sal_Bool SfxDocTplService_Impl::CreateNewUniqueFolderWithPrefix( const ::rtl::OU
     INetURLObject aDirPath( aPath );
 
     Content aParent;
-       if ( Content::create( aDirPath.GetMainURL( INetURLObject::NO_DECODE ), maCmdEnv, aParent ) )
+    uno::Reference< XCommandEnvironment > aQuietEnv;
+       if ( Content::create( aDirPath.GetMainURL( INetURLObject::NO_DECODE ), aQuietEnv, aParent ) )
        {
         for ( sal_Int32 nInd = 0; nInd < 32000; nInd++ )
         {
commit 4a8e458b45dd063a82825e252366f678aec23921
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Tue Jan 10 16:04:58 2012 +0100

    fdo#43532 Partial revert of "...template names appear... correct word order"
    
    Sorting the sfx2-based list boxes does not work as SfxDocumentTemplates uses a
    different collating order (plain Unicode code points) than the list boxes, so
    that e.g. "en-US" comes last in SfxDocumentTemplates but not in the list boxes.
    Even with that fixed, insertions into SfxOrganizeDlg_Impl would still not work
    right.
    
    This reverts the sfx2 parts of commits 50b7733fa41879a62d35cab64da59b109e1a8502
    and df59068902b294b7b344af0c20da196cc64aaced.

diff --git a/sfx2/inc/sfx2/doctempl.hxx b/sfx2/inc/sfx2/doctempl.hxx
index b60ac95..df1d9f0 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 c0f83a0..2b61618 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 8a194f8..d3878d9 100644
--- a/sfx2/source/doc/doctempl.cxx
+++ b/sfx2/source/doc/doctempl.cxx
@@ -36,6 +36,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>
@@ -100,7 +101,6 @@ using namespace ::ucbhelper;
 #include <unotools/ucbhelper.hxx>
 
 #include <vector>
-#include <algorithm>
 using ::std::vector;
 using ::std::advance;
 
@@ -169,13 +169,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;
@@ -189,7 +182,6 @@ class RegionData_Impl
     OUString                    maTitle;
     OUString                    maOwnURL;
     OUString                    maTargetURL;
-    bool                        mbSortingEnabled;
 
 private:
     size_t                      GetEntryPos( const OUString& rTitle,
@@ -220,20 +212,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;
 
 // ------------------------------------------------------------------------
@@ -245,10 +228,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;
 
@@ -274,13 +256,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
@@ -644,28 +619,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
@@ -1154,7 +1107,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 ) )
         {
@@ -1214,10 +1166,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;
         }
     }
@@ -1238,10 +1186,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;
         }
     }
@@ -1761,9 +1705,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;
 }
 
 // -----------------------------------------------------------------------
@@ -1777,37 +1720,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
 }
 
 // -----------------------------------------------------------------------
@@ -1821,20 +1789,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 )
     {
-        if ( !mbSortingEnabled && pPos )
+        pEntry = maEntries[ nPos ];
+    }
+    else
+    {
+        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 );
@@ -1926,15 +1897,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 );
@@ -1946,8 +1908,6 @@ int RegionData_Impl::Compare( RegionData_Impl* pCompare ) const
 
 SfxDocTemplate_Impl::SfxDocTemplate_Impl()
 : mbConstructed( sal_False )
-, mbRegionSortingEnabled( false )
-, mbTemplateSortingEnabled( false )
 , mnLockCounter( 0 )
 {
 }
@@ -2016,7 +1976,6 @@ void SfxDocTemplate_Impl::AddRegion( const OUString& rTitle,
 {
     RegionData_Impl* pRegion;
     pRegion = new RegionData_Impl( this, rTitle );
-    pRegion->EnableSorting( mbTemplateSortingEnabled );
 
     if ( ! InsertRegion( pRegion ) )
     {
@@ -2139,6 +2098,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 );
 
@@ -2169,23 +2133,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;
 }
@@ -2217,15 +2176,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 c0f9390..4f56e82 100644
--- a/sfx2/source/doc/docvor.cxx
+++ b/sfx2/source/doc/docvor.cxx
@@ -216,12 +216,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 ....
     {
@@ -231,8 +225,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 6938099..da13a06 100644
--- a/sfx2/source/doc/new.cxx
+++ b/sfx2/source/doc/new.cxx
@@ -560,14 +560,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


More information about the Libreoffice-commits mailing list