[Libreoffice-commits] .: sd/source

Andras Timar timar at kemper.freedesktop.org
Wed Sep 14 13:25:23 PDT 2011


 sd/source/ui/dlg/TemplateScanner.cxx |   39 ++++++++++++++++++++++++++++++++++-
 sd/source/ui/dlg/dlgass.cxx          |    1 
 sd/source/ui/inc/TemplateScanner.hxx |   39 ++++++++++++++++++++++++++++++++++-
 3 files changed, 77 insertions(+), 2 deletions(-)

New commits:
commit 0c113d825da98a8038cb4359cd86e765eef0b915
Author: Peter Rabi <prabi at caesar.elte.hu>
Date:   Wed Sep 14 22:00:19 2011 +0200

    Fix of localised template name problems in Impress part 1
    
    Template entries now appear in the correct word order
    in their representation in TemplateScanner. That makes
    dlgass template listboxes work as expected.
    Contributed under license LGPLv3+/MPL.

diff --git a/sd/source/ui/dlg/TemplateScanner.cxx b/sd/source/ui/dlg/TemplateScanner.cxx
index d1b75d0..b30f872 100644
--- a/sd/source/ui/dlg/TemplateScanner.cxx
+++ b/sd/source/ui/dlg/TemplateScanner.cxx
@@ -33,6 +33,7 @@
 
 #include <comphelper/processfactory.hxx>
 #include <comphelper/documentconstants.hxx>
+#include <comphelper/string.hxx>
 
 #include <tools/debug.hxx>
 #include <osl/mutex.hxx>
@@ -142,6 +143,40 @@ int Classify (const ::rtl::OUString&, const ::rtl::OUString& rsURL)
 namespace sd
 {
 
+TemplateEntryCompare::TemplateEntryCompare():
+    mpStringSorter(new comphelper::string::NaturalStringSorter(
+                       ::comphelper::getProcessComponentContext(),
+                       Application::GetSettings().GetLocale())) {}
+
+bool TemplateEntryCompare::operator()(TemplateEntry* pA, TemplateEntry* pB) const
+{
+    return 0 > mpStringSorter->compare(pA->msTitle, pB->msTitle);
+}
+
+void TemplateDir::EnableSorting(bool bSortingEnabled)
+{
+    mbSortingEnabled = bSortingEnabled;
+    if (mbSortingEnabled)
+    {
+        if (mpEntryCompare.get() == NULL)
+            mpEntryCompare.reset(new TemplateEntryCompare);
+
+        ::std::sort(maEntries.begin(), maEntries.end(), *mpEntryCompare);
+    }
+}
+
+void TemplateDir::InsertEntry(TemplateEntry* pNewEntry)
+{
+    if (mbSortingEnabled)
+    {
+        ::std::vector<TemplateEntry*>::iterator aPlaceToInsert =
+            ::std::upper_bound(maEntries.begin(), maEntries.end(), pNewEntry, *mpEntryCompare);
+        maEntries.insert(aPlaceToInsert, pNewEntry);
+    }
+    else
+        maEntries.push_back(pNewEntry);
+}
+
 class TemplateScanner::FolderDescriptorList
     : public ::std::multiset<FolderDescriptor,FolderDescriptor::Comparator>
 {
@@ -152,6 +187,7 @@ TemplateScanner::TemplateScanner (void)
       maFolderContent(),
       mpTemplateDirectory(NULL),
       maFolderList(),
+      mbEntrySortingEnabled(false),
       mpLastAddedEntry(NULL),
       mpFolderDescriptors(new FolderDescriptorList()),
       mxTemplateRoot(),
@@ -268,7 +304,7 @@ TemplateScanner::State TemplateScanner::ScanEntry (void)
                     ::rtl::OUString sLocalisedTitle = SfxDocumentTemplates::ConvertResourceString(
                         STR_TEMPLATE_NAME1_DEF, STR_TEMPLATE_NAME1, NUM_TEMPLATE_NAMES, sTitle );
                     mpLastAddedEntry = new TemplateEntry(sLocalisedTitle, sTargetURL);
-                    mpTemplateDirectory->maEntries.push_back(mpLastAddedEntry);
+                    mpTemplateDirectory->InsertEntry(mpLastAddedEntry);
                 }
             }
 
@@ -390,6 +426,7 @@ TemplateScanner::State TemplateScanner::ScanFolder (void)
             mpTemplateDirectory = new TemplateDir (sTitle, sTargetDir);
             if (mpTemplateDirectory != NULL)
             {
+                mpTemplateDirectory->EnableSorting(mbEntrySortingEnabled);
                 // Continue with scanning all entries in the folder.
                 eNextState = INITIALIZE_ENTRY_SCAN;
             }
diff --git a/sd/source/ui/dlg/dlgass.cxx b/sd/source/ui/dlg/dlgass.cxx
index 9e44987..6090ef0 100644
--- a/sd/source/ui/dlg/dlgass.cxx
+++ b/sd/source/ui/dlg/dlgass.cxx
@@ -865,6 +865,7 @@ void AssistentDlgImpl::ProvideTemplates (void)
     if ( ! mbTemplatesReady)
     {
         TemplateScanner aScanner;
+        aScanner.EnableEntrySorting();
         aScanner.Scan ();
         TemplateScanDone (aScanner.GetFolderList());
 
diff --git a/sd/source/ui/inc/TemplateScanner.hxx b/sd/source/ui/inc/TemplateScanner.hxx
index 86c862a..f44c042 100644
--- a/sd/source/ui/inc/TemplateScanner.hxx
+++ b/sd/source/ui/inc/TemplateScanner.hxx
@@ -37,6 +37,7 @@
 
 #include <vector>
 #include <boost/scoped_ptr.hpp>
+#include <boost/shared_ptr.hpp>
 
 namespace com { namespace sun { namespace star { namespace ucb {
 class XContent;
@@ -47,6 +48,10 @@ namespace com { namespace sun { namespace star { namespace sdbc {
 class XResultSet;
 } } } }
 
+namespace comphelper { namespace string {
+class NaturalStringSorter;
+} }
+
 namespace sd {
 
 /** Representation of a template or layout file.
@@ -64,17 +69,40 @@ public:
 
 
 
+/** Functor that compares two TemplateEntries based on their titles
+*/
+class TemplateEntryCompare
+{
+public:
+    TemplateEntryCompare();
+    bool operator()(TemplateEntry* pA, TemplateEntry* pB) const;
+
+private:
+    ::boost::shared_ptr<comphelper::string::NaturalStringSorter> mpStringSorter;
+};
+
+
+
+
 /** Representation of a template or layout folder.
 */
 class TemplateDir
 {
 public:
     TemplateDir (const String& rsRegion, const String& rsUrl )
-        :   msRegion(rsRegion), msUrl(rsUrl), maEntries() {}
+        :   msRegion(rsRegion), msUrl(rsUrl), maEntries(),
+            mbSortingEnabled(false), mpEntryCompare(NULL) {}
 
     String msRegion;
     String msUrl;
     ::std::vector<TemplateEntry*> maEntries;
+
+    void EnableSorting(bool bSortingEnabled = true);
+    void InsertEntry(TemplateEntry* pNewEntry);
+
+private:
+    bool mbSortingEnabled;
+    ::boost::scoped_ptr<TemplateEntryCompare> mpEntryCompare;
 };
 
 
@@ -133,6 +161,11 @@ public:
     */
     const TemplateEntry* GetLastAddedEntry (void) const;
 
+    /** Set wether to sort the template entries inside the regions.
+    */
+    void EnableEntrySorting (bool isEntrySortingEnabled = true)
+        {mbEntrySortingEnabled = isEntrySortingEnabled;}
+
 private:
     /** The current state determines which step will be executed next by
         RunNextStep().
@@ -157,6 +190,10 @@ private:
     */
      std::vector<TemplateDir*> maFolderList;
 
+    /** Weather the template entries have to be sorted.
+    */
+    bool mbEntrySortingEnabled;
+
     /** This member points into the maFolderList to the member that was most
         recently added.
     */


More information about the Libreoffice-commits mailing list