summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Rabi <prabi@caesar.elte.hu>2011-09-14 22:00:19 +0200
committerAndras Timar <atimar@suse.com>2011-09-14 22:25:53 +0200
commit0c113d825da98a8038cb4359cd86e765eef0b915 (patch)
tree9de740b4990e95f0c59c7e1e8dd557c28adc70cb
parentb6cccb9e77111254932ebcf96f883aab04cb3f56 (diff)
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.
-rw-r--r--sd/source/ui/dlg/TemplateScanner.cxx39
-rw-r--r--sd/source/ui/dlg/dlgass.cxx1
-rw-r--r--sd/source/ui/inc/TemplateScanner.hxx39
3 files changed, 77 insertions, 2 deletions
diff --git a/sd/source/ui/dlg/TemplateScanner.cxx b/sd/source/ui/dlg/TemplateScanner.cxx
index d1b75d04a957..b30f8720a7a4 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 9e4498730157..6090ef0a7da1 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 86c862a298cf..f44c042cae18 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.
*/