[Libreoffice-commits] core.git: 4 commits - sfx2/inc sfx2/Library_sfx.mk sfx2/Package_inc.mk sfx2/source

Rafael Dominguez venccsralph at gmail.com
Tue Mar 26 09:14:48 PDT 2013


 sfx2/Library_sfx.mk                          |   19 -
 sfx2/Package_inc.mk                          |    1 
 sfx2/inc/sfx2/templateabstractview.hxx       |   62 ++---
 sfx2/inc/sfx2/templatelocalview.hxx          |   14 -
 sfx2/inc/sfx2/templateproperties.hxx         |    1 
 sfx2/inc/sfx2/templateremoteview.hxx         |    4 
 sfx2/inc/sfx2/templateview.hxx               |   66 -----
 sfx2/inc/sfx2/thumbnailview.hxx              |    3 
 sfx2/inc/templatedlg.hxx                     |   22 +
 sfx2/source/control/templateabstractview.cxx |  194 +++++++---------
 sfx2/source/control/templatelocalview.cxx    |  304 ++++++++++++++++---------
 sfx2/source/control/templateremoteview.cxx   |   23 +
 sfx2/source/control/templateview.cxx         |  106 --------
 sfx2/source/control/thumbnailview.cxx        |   67 ++++-
 sfx2/source/doc/templatedlg.cxx              |  322 ++++++++++++---------------
 15 files changed, 570 insertions(+), 638 deletions(-)

New commits:
commit dda5fe60ff6dfd61f5f262c61e1d538d20e9c978
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Tue Mar 26 00:30:08 2013 -0430

    Syncronize thumbnails ids with SfxDocumentTemplates when moving.
    
    Change-Id: I9ee17e00f769ca16f566b1397d09b76a09273912

diff --git a/sfx2/inc/sfx2/templatelocalview.hxx b/sfx2/inc/sfx2/templatelocalview.hxx
index cf12ddc..7ea226c 100644
--- a/sfx2/inc/sfx2/templatelocalview.hxx
+++ b/sfx2/inc/sfx2/templatelocalview.hxx
@@ -56,9 +56,9 @@ public:
     bool removeTemplate (const sal_uInt16 nItemId, const sal_uInt16 nSrcItemId);
 
     bool moveTemplate (const ThumbnailViewItem* pItem, const sal_uInt16 nSrcItem,
-                       const sal_uInt16 nTargetItem, bool bCopy);
+                       const sal_uInt16 nTargetItem);
 
-    bool moveTemplates (const std::set<const ThumbnailViewItem*,selection_cmp_fn> &rItems, const sal_uInt16 nTargetItem, bool bCopy);
+    bool moveTemplates (const std::set<const ThumbnailViewItem*,selection_cmp_fn> &rItems, const sal_uInt16 nTargetItem);
 
     bool copyFrom (const sal_uInt16 nRegionItemId, const BitmapEx &rThumbnail, const OUString &rPath);
 
diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx
index 9bb94c3..ddab413 100644
--- a/sfx2/source/control/templatelocalview.cxx
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -289,11 +289,8 @@ bool TemplateLocalView::removeTemplate (const sal_uInt16 nItemId, const sal_uInt
 }
 
 bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_uInt16 nSrcItem,
-                                       const sal_uInt16 nTargetItem, bool bCopy)
+                                       const sal_uInt16 nTargetItem)
 {
-    bool bRet = true;
-    bool bRefresh = false;
-
     TemplateContainerItem *pTarget = NULL;
     TemplateContainerItem *pSrc = NULL;
 
@@ -313,16 +310,13 @@ bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_
 
         const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(pItem);
 
-        bool bOK;
+        bool bCopy = !mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnDocId);
 
         if (bCopy)
-            bOK = mpDocTemplates->Copy(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1);
-        else
-            bOK = mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1);
-
-        if (!bOK)
-            return false;
-
+        {
+            if (!mpDocTemplates->Copy(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnDocId))
+                return false;
+        }
         // move template to destination
 
         TemplateItemProperties aTemplateItem;
@@ -340,37 +334,45 @@ bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_
             // remove template from region cached data
 
             std::vector<TemplateItemProperties>::iterator aIter;
-            for (aIter = pSrc->maTemplates.begin(); aIter != pSrc->maTemplates.end(); ++aIter)
+            for (aIter = pSrc->maTemplates.begin(); aIter != pSrc->maTemplates.end();)
             {
-                if (aIter->nId == pViewItem->mnId)
+                if (aIter->nDocId == pViewItem->mnDocId)
+                {
+                    aIter = pSrc->maTemplates.erase(aIter);
+                }
+                else
                 {
-                    pSrc->maTemplates.erase(aIter);
+                    // Keep region document id syncronized with SfxDocumentTemplates
+                    if (aIter->nDocId > pViewItem->mnDocId)
+                        --aIter->nDocId;
 
-                    RemoveItem(pViewItem->mnId);
-                    break;
+                    ++aIter;
                 }
             }
-        }
 
-        bRefresh = true;
-    }
-    else
-        bRet = false;
+            // Keep view document id syncronized with SfxDocumentTemplates
+            std::vector<ThumbnailViewItem*>::iterator pItemIter = mItemList.begin();
+            for (; pItemIter != mItemList.end(); ++pItemIter)
+            {
+                if (static_cast<TemplateViewItem*>(*pItemIter)->mnDocId > pViewItem->mnDocId)
+                    --static_cast<TemplateViewItem*>(*pItemIter)->mnDocId;
+            }
+        }
 
-    if (bRefresh)
-    {
         lcl_updateThumbnails(pSrc);
         lcl_updateThumbnails(pTarget);
 
         CalculateItemPositions();
         Invalidate();
+
+        return true;
     }
 
-    return bRet;
+    return false;
 }
 
 bool TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, selection_cmp_fn> &rItems,
-                                      const sal_uInt16 nTargetItem, bool bCopy)
+                                      const sal_uInt16 nTargetItem)
 {
     bool ret = true;
     bool refresh = false;
@@ -400,17 +402,15 @@ bool TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, s
         {
             const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(*aSelIter);
 
-            bool bOK;
+            bool bCopy = !mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnDocId);
 
             if (bCopy)
-                bOK = mpDocTemplates->Copy(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1);
-            else
-                bOK = mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1);
-
-            if (!bOK)
             {
-                ret = false;
-                continue;
+                if (!mpDocTemplates->Copy(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnDocId))
+                {
+                    ret = false;
+                    continue;
+                }
             }
 
             // move template to destination
@@ -429,15 +429,30 @@ bool TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, s
             {
                 // remove template from region cached data
 
-                std::vector<TemplateItemProperties>::iterator pIter;
-                for (pIter = pSrc->maTemplates.begin(); pIter != pSrc->maTemplates.end(); ++pIter)
+                std::vector<TemplateItemProperties>::iterator pPropIter;
+                for (pPropIter = pSrc->maTemplates.begin(); pPropIter != pSrc->maTemplates.end();)
                 {
-                    if (pIter->nId == pViewItem->mnId)
+                    if (pPropIter->nDocId == pViewItem->mnDocId)
                     {
-                        pSrc->maTemplates.erase(pIter);
+                        pPropIter = pSrc->maTemplates.erase(pPropIter);
                         aItemIds.push_back(pViewItem->mnId);
-                        break;
                     }
+                    else
+                    {
+                        // Keep region document id syncronized with SfxDocumentTemplates
+                        if (pPropIter->nDocId > pViewItem->mnDocId)
+                            --pPropIter->nDocId;
+
+                        ++pPropIter;
+                    }
+                }
+
+                // Keep view document id syncronized with SfxDocumentTemplates
+                std::vector<ThumbnailViewItem*>::iterator pItemIter = mItemList.begin();
+                for (; pItemIter != mItemList.end(); ++pItemIter)
+                {
+                    if (static_cast<TemplateViewItem*>(*pItemIter)->mnDocId > pViewItem->mnDocId)
+                        --static_cast<TemplateViewItem*>(*pItemIter)->mnDocId;
                 }
             }
 
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index c86704d..6899cf6 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -1366,8 +1366,7 @@ void SfxTemplateManagerDlg::localMoveTo(sal_uInt16 nMenuId)
     {
         // Move templates to desired folder if for some reason move fails
         // try copying them.
-        if (!maView->moveTemplates(maSelTemplates,nItemId,false) &&
-                !maView->moveTemplates(maSelTemplates,nItemId,true))
+        if (!maView->moveTemplates(maSelTemplates,nItemId))
         {
             OUString aTemplateList;
 
@@ -1472,13 +1471,14 @@ void SfxTemplateManagerDlg::localSearchMoveTo(sal_uInt16 nMenuId)
         // Move templates to desired folder if for some reason move fails
         // try copying them.
         std::set<const ThumbnailViewItem*>::const_iterator aIter;
-        for (aIter = maSelTemplates.begin(); aIter != maSelTemplates.end(); ++aIter)
+        std::set<const ThumbnailViewItem*,selection_cmp_fn> aSelTemplates = maSelTemplates; //Copy to avoid invalidating an iterator
+
+        for (aIter = aSelTemplates.begin(); aIter != aSelTemplates.end(); ++aIter)
         {
             const TemplateSearchViewItem *pItem =
                     static_cast<const TemplateSearchViewItem*>(*aIter);
 
-            if(!maView->moveTemplate(pItem,pItem->mnRegionId+1,nItemId,false)
-                    && !maView->moveTemplate(pItem,pItem->mnRegionId+1,nItemId,true))
+            if(!maView->moveTemplate(pItem,pItem->mnRegionId+1,nItemId))
             {
                 if (aTemplateList.isEmpty())
                     aTemplateList = (*aIter)->maTitle;
commit 28d5ced7f9982257d263ffc3e550bd479a9542f8
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Mon Mar 25 22:32:32 2013 -0430

    Fix template manager item selection behaviour with mouse.
    
    Change-Id: Icf63454973b4044443eea1cc583fce3a78c5594d

diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx
index 6d66ed2..d7521b0 100644
--- a/sfx2/source/control/thumbnailview.cxx
+++ b/sfx2/source/control/thumbnailview.cxx
@@ -606,15 +606,22 @@ void ThumbnailView::MouseButtonDown( const MouseEvent& rMEvt )
         {
             if ( rMEvt.GetClicks() == 1 )
             {
-                if (pItem->isSelected() && rMEvt.IsMod1())
-                    pItem->setSelection(false);
+                if (rMEvt.IsMod1())
+                {
+                    //Keep selected item group state and just invert current desired one state
+                    pItem->setSelection(!pItem->isSelected());
+                }
                 else
                 {
-                    if (!pItem->isSelected() && !rMEvt.IsMod1())
-                        deselectItems( );
-
+                    //If we got a group of selected items deselect the rest and only keep the desired one
+                    //mark items as not selected to not fire unnecessary change state events.
+                    pItem->setSelection(false);
+                    deselectItems();
                     pItem->setSelection(true);
+                }
 
+                if (pItem->isSelected())
+                {
                     bool bClickOnTitle = pItem->getTextArea().IsInside(rMEvt.GetPosPixel());
                     pItem->setEditTitle(bClickOnTitle);
                 }
@@ -623,13 +630,11 @@ void ThumbnailView::MouseButtonDown( const MouseEvent& rMEvt )
                     DrawItem(pItem);
 
                 maItemStateHdl.Call(pItem);
+
+                //fire accessible event??
             }
             else if ( rMEvt.GetClicks() == 2 )
             {
-                // The mouse button down event 1 click right before is pointless
-                pItem->setSelection(false);
-                maItemStateHdl.Call(pItem);
-
                 Rectangle aRect(pItem->getDrawArea());
 
                 if (aRect.IsInside(rMEvt.GetPosPixel()))
commit 1c9f13f921cb5bf955b8568ffb5d14047738eef9
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Mon Mar 25 21:28:20 2013 -0430

    Deselect thumbnailview items when clearing the view.
    
    Change-Id: I8aa3f61d3ec7a8bf6195c5480b82d1dc1ecabc34

diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx
index c7c487e..6d66ed2 100644
--- a/sfx2/source/control/thumbnailview.cxx
+++ b/sfx2/source/control/thumbnailview.cxx
@@ -114,6 +114,16 @@ void ThumbnailView::ImplDeleteItems()
     for ( size_t i = 0; i < n; ++i )
     {
         ThumbnailViewItem *const pItem = mItemList[i];
+
+        // deselect all current selected items and fire events
+        if (pItem->isSelected())
+        {
+            pItem->setSelection(false);
+            maItemStateHdl.Call(pItem);
+
+            // fire accessible event???
+        }
+
         if ( pItem->isVisible() && ImplHasAccessibleListeners() )
         {
             ::com::sun::star::uno::Any aOldAny, aNewAny;
commit 448cc5e851acf5136bba01974e570fa0554d0371
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Mon Mar 25 20:49:29 2013 -0430

    Merge TemplateView into TemplateAbstractView class.
    
    Refactor TemplateView class into TemplateAbstractView so we
    only have one class that display template thumbnails and not
    a separate for folders and another for files. This will let
    us in the future be able to display file system hierarchies in
    case of the remote repositories and simplify the view handing
    logic.
    
    Change-Id: Iafc246eeff4c50c12ac9ebec9fe95dcc84991e9e

diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk
index 13617c5..bbc5ba0 100644
--- a/sfx2/Library_sfx.mk
+++ b/sfx2/Library_sfx.mk
@@ -71,12 +71,12 @@ $(eval $(call gb_Library_use_libraries,sfx,\
     ucbhelper \
     utl \
     vcl \
-	$(gb_UWINAPI) \
+    $(gb_UWINAPI) \
 ))
 
 $(eval $(call gb_Library_use_externals,sfx,\
-	boost_headers \
-	libxml2 \
+    boost_headers \
+    libxml2 \
 ))
 
 $(eval $(call gb_Library_add_exception_objects,sfx,\
@@ -140,7 +140,6 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
     sfx2/source/control/sorgitm \
     sfx2/source/control/statcach \
     sfx2/source/control/templateabstractview \
-    sfx2/source/control/templateview \
     sfx2/source/control/templateviewitem \
     sfx2/source/control/templatelocalview \
     sfx2/source/control/templatecontaineritem \
@@ -152,7 +151,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
     sfx2/source/control/unoctitm \
     sfx2/source/dialog/alienwarn \
     sfx2/source/dialog/basedlgs \
-	sfx2/source/dialog/checkin \
+    sfx2/source/dialog/checkin \
     sfx2/source/dialog/dinfdlg \
     sfx2/source/dialog/dinfedt \
     sfx2/source/dialog/dockwin \
@@ -298,11 +297,11 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
 ))
 
 $(eval $(call gb_Library_use_system_win32_libs,sfx,\
-	advapi32 \
-	gdi32 \
-	ole32 \
-	shell32 \
-	uuid \
+    advapi32 \
+    gdi32 \
+    ole32 \
+    shell32 \
+    uuid \
 ))
 
 endif
diff --git a/sfx2/Package_inc.mk b/sfx2/Package_inc.mk
index aa368b7..228cc62 100644
--- a/sfx2/Package_inc.mk
+++ b/sfx2/Package_inc.mk
@@ -120,7 +120,6 @@ $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templdlg.hxx,sfx2/templdlg.h
 $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templatelocnames.hrc,sfx2/templatelocnames.hrc))
 $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templateabstractview.hxx,sfx2/templateabstractview.hxx))
 $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templateinfodlg.hxx,sfx2/templateinfodlg.hxx))
-$(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templateview.hxx,sfx2/templateview.hxx))
 $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templatelocalview.hxx,sfx2/templatelocalview.hxx))
 $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templatecontaineritem.hxx,sfx2/templatecontaineritem.hxx))
 $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templateremoteview.hxx,sfx2/templateremoteview.hxx))
diff --git a/sfx2/inc/sfx2/templateabstractview.hxx b/sfx2/inc/sfx2/templateabstractview.hxx
index bfbd2aa..16a82e4 100644
--- a/sfx2/inc/sfx2/templateabstractview.hxx
+++ b/sfx2/inc/sfx2/templateabstractview.hxx
@@ -10,7 +10,10 @@
 #ifndef __SFX2_TEMPLATEABSTRACTVIEW_HXX__
 #define __SFX2_TEMPLATEABSTRACTVIEW_HXX__
 
+#include <sfx2/templateproperties.hxx>
 #include <sfx2/thumbnailview.hxx>
+#include <vcl/button.hxx>
+#include <vcl/fixed.hxx>
 
 //template thumbnail item defines
 #define TEMPLATE_ITEM_MAX_WIDTH 160
@@ -23,7 +26,6 @@
 #define TEMPLATE_THUMBNAIL_MAX_HEIGHT TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT - 2*TEMPLATE_ITEM_PADDING
 #define TEMPLATE_THUMBNAIL_MAX_WIDTH TEMPLATE_ITEM_MAX_WIDTH - 2*TEMPLATE_ITEM_PADDING
 
-class TemplateView;
 class SfxDocumentTemplates;
 
 enum FILTER_APPLICATION
@@ -80,63 +82,53 @@ public:
 
     virtual ~TemplateAbstractView ();
 
-    // Fill view with template folders thumbnails
-    virtual void Populate () { };
-
-    virtual void reload () { };
+    // Fill view with new item list
+    void insertItems (const std::vector<TemplateItemProperties> &rTemplates);
 
-    virtual void filterTemplatesByApp (const FILTER_APPLICATION &eApp);
-
-    virtual sal_uInt16 createRegion (const OUString &rName) = 0;
-
-    void showOverlay (bool bVisible);
-
-    void setItemDimensions (long ItemWidth, long ThumbnailHeight, long DisplayHeight, int itemPadding);
+    // Fill view with template folders thumbnails
+    virtual void Populate () { }
 
-    sal_uInt16 getOverlayRegionId () const;
+    virtual void reload () { }
 
-    const OUString& getOverlayName () const;
+    virtual void showRootRegion () = 0;
 
-    // Check if the overlay is visible or not.
-    bool isOverlayVisible () const;
+    virtual void showRegion (ThumbnailViewItem *pItem) = 0;
 
-    void deselectOverlayItems ();
+    virtual sal_uInt16 createRegion (const OUString &rName) = 0;
 
-    void sortOverlayItems (const boost::function<bool (const ThumbnailViewItem*,
-                                                       const ThumbnailViewItem*) > &func);
+    sal_uInt16 getCurRegionId () const;
 
-    virtual void filterTemplatesByKeyword (const OUString &rKeyword);
+    const OUString& getCurRegionName () const;
 
-    void setOverlayItemStateHdl (const Link &aLink) { maOverlayItemStateHdl = aLink; }
+    // Check if the root region is visible or not.
+    bool isNonRootRegionVisible () const;
 
-    void setOpenHdl (const Link &rLink);
+    void setOpenRegionHdl(const Link &rLink);
 
-    void setOverlayCloseHdl (const Link &rLink);
+    void setOpenTemplateHdl (const Link &rLink);
 
     static BitmapEx scaleImg (const BitmapEx &rImg, long width, long height);
 
-    static BitmapEx fetchThumbnail (const OUString &msURL, long width, long height);
+    static BitmapEx getDefaultThumbnail( const rtl::OUString& rPath );
 
-    virtual void Resize();
+    static BitmapEx fetchThumbnail (const OUString &msURL, long width, long height);
 
 protected:
 
-    virtual void Paint( const Rectangle& rRect );
-
-    virtual void DrawItem (ThumbnailViewItem *pItem);
-
-    DECL_LINK(OverlayItemStateHdl, const ThumbnailViewItem*);
+    DECL_LINK(ShowRootRegionHdl, void*);
 
     virtual void OnItemDblClicked(ThumbnailViewItem *pItem);
 
 protected:
 
-    TemplateView *mpItemView;
-    Link maOverlayItemStateHdl;
-    Link maOpenHdl;
+    sal_uInt16 mnCurRegionId;
+    OUString maCurRegionName;
+
+    PushButton maAllButton;
+    FixedText  maFTName;
 
-    bool mbFilteredResults;     // Flag keep track if overlay has been filtered so folders can get filtered too afterwards
-    FILTER_APPLICATION meFilterOption;
+    Link maOpenRegionHdl;
+    Link maOpenTemplateHdl;
 };
 
 #endif // __SFX2_TEMPLATEABSTRACTVIEW_HXX__
diff --git a/sfx2/inc/sfx2/templatelocalview.hxx b/sfx2/inc/sfx2/templatelocalview.hxx
index 5fc14c9..cf12ddc 100644
--- a/sfx2/inc/sfx2/templatelocalview.hxx
+++ b/sfx2/inc/sfx2/templatelocalview.hxx
@@ -13,7 +13,6 @@
 #include <set>
 
 #include <sfx2/templateabstractview.hxx>
-#include <sfx2/templateproperties.hxx>
 
 class SfxDocumentTemplates;
 class TemplateContainerItem;
@@ -26,6 +25,8 @@ namespace com {
 
 class SFX2_DLLPUBLIC TemplateLocalView : public TemplateAbstractView
 {
+    typedef bool (*selection_cmp_fn)(const ThumbnailViewItem*,const ThumbnailViewItem*);
+
 public:
 
     TemplateLocalView ( Window* pParent, const ResId& rResId, bool bDisableTransientChildren = false );
@@ -37,6 +38,12 @@ public:
 
     virtual void reload ();
 
+    virtual void showRootRegion ();
+
+    virtual void showRegion (ThumbnailViewItem *pItem);
+
+    sal_uInt16 getRegionId (size_t pos) const;
+
     std::vector<OUString> getFolderNames ();
 
     std::vector<TemplateItemProperties>
@@ -51,7 +58,7 @@ public:
     bool moveTemplate (const ThumbnailViewItem* pItem, const sal_uInt16 nSrcItem,
                        const sal_uInt16 nTargetItem, bool bCopy);
 
-    bool moveTemplates (std::set<const ThumbnailViewItem*> &rItems, const sal_uInt16 nTargetItem, bool bCopy);
+    bool moveTemplates (const std::set<const ThumbnailViewItem*,selection_cmp_fn> &rItems, const sal_uInt16 nTargetItem, bool bCopy);
 
     bool copyFrom (const sal_uInt16 nRegionItemId, const BitmapEx &rThumbnail, const OUString &rPath);
 
@@ -74,6 +81,7 @@ public:
 private:
 
     SfxDocumentTemplates *mpDocTemplates;
+    std::vector<TemplateContainerItem* > maRegions;
 };
 
 #endif // TEMPLATEFOLDERVIEW_HXX
diff --git a/sfx2/inc/sfx2/templateproperties.hxx b/sfx2/inc/sfx2/templateproperties.hxx
index 0760f60..1f109c5 100644
--- a/sfx2/inc/sfx2/templateproperties.hxx
+++ b/sfx2/inc/sfx2/templateproperties.hxx
@@ -15,6 +15,7 @@
 
 struct TemplateItemProperties
 {
+    bool aIsFolder;
     sal_uInt16 nId;         ///< Index for ThumbnailView
     sal_uInt16 nDocId;      ///< Index based on SfxTemplateDocument
     sal_uInt16 nRegionId;
diff --git a/sfx2/inc/sfx2/templateremoteview.hxx b/sfx2/inc/sfx2/templateremoteview.hxx
index 34da085..a2341c4 100644
--- a/sfx2/inc/sfx2/templateremoteview.hxx
+++ b/sfx2/inc/sfx2/templateremoteview.hxx
@@ -25,6 +25,10 @@ public:
 
     virtual ~TemplateRemoteView ();
 
+    virtual void showRootRegion ();
+
+    virtual void showRegion (ThumbnailViewItem *pItem);
+
     bool loadRepository (TemplateRepository* pRepository, bool bRefresh);
 
     virtual sal_uInt16 createRegion (const OUString &rName);
diff --git a/sfx2/inc/sfx2/templateview.hxx b/sfx2/inc/sfx2/templateview.hxx
deleted file mode 100644
index 104cb11..0000000
--- a/sfx2/inc/sfx2/templateview.hxx
+++ /dev/null
@@ -1,66 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Copyright 2012 LibreOffice contributors.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#ifndef TEMPLATEVIEW_HXX
-#define TEMPLATEVIEW_HXX
-
-#include <sfx2/templateproperties.hxx>
-#include <sfx2/thumbnailview.hxx>
-#include <vcl/button.hxx>
-#include <vcl/fixed.hxx>
-
-class Edit;
-class TemplateViewItem;
-
-class TemplateView : public ThumbnailView
-{
-public:
-
-    TemplateView (Window *pParent);
-
-    virtual ~TemplateView ();
-
-    void setId (const sal_uInt16 nId) { mnId = nId; }
-
-    sal_uInt16 getId () const { return mnId; }
-
-    void setName (const OUString &rName);
-
-    const OUString& getName () const { return maName; }
-
-    void InsertItems (const std::vector<TemplateItemProperties> &rTemplates);
-
-    void setCloseHdl (const Link &rLink) { maAllButton.SetClickHdl(rLink); }
-
-
-    // FIXME Kept only during the refactoring
-    void setOpenHdl (const Link &rLink) { maOpenHdl = rLink; }
-    virtual void OnItemDblClicked(ThumbnailViewItem *pItem) { maOpenHdl.Call(pItem); }
-    void setMasterView(TemplateAbstractView* pMasterView) { mpMasterView = pMasterView; }
-    virtual bool renameItem(ThumbnailViewItem* pItem, rtl::OUString sNewTitle);
-
-protected:
-
-    virtual void Resize ();
-
-private:
-
-    Link maOpenHdl;
-    TemplateAbstractView* mpMasterView;
-
-    PushButton maAllButton;
-    FixedText  maFTName;
-    sal_uInt16 mnId;
-    OUString maName;
-};
-
-#endif // TEMPLATEVIEW_HXX
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
-
diff --git a/sfx2/inc/sfx2/thumbnailview.hxx b/sfx2/inc/sfx2/thumbnailview.hxx
index c46a854..8d7f46a 100644
--- a/sfx2/inc/sfx2/thumbnailview.hxx
+++ b/sfx2/inc/sfx2/thumbnailview.hxx
@@ -183,6 +183,9 @@ public:
 
     void Clear();
 
+    // Change current thumbnail item list with new one (invalidates all pointers to a thumbnail item)
+    void updateItems(const std::vector<ThumbnailViewItem *> &items);
+
     size_t GetItemPos( sal_uInt16 nItemId ) const;
 
     sal_uInt16 GetItemId( size_t nPos ) const;
diff --git a/sfx2/inc/templatedlg.hxx b/sfx2/inc/templatedlg.hxx
index 0a6be50..894e70a 100644
--- a/sfx2/inc/templatedlg.hxx
+++ b/sfx2/inc/templatedlg.hxx
@@ -39,6 +39,8 @@ namespace com {
 
 class SfxTemplateManagerDlg : public ModelessDialog
 {
+    typedef bool (*selection_cmp_fn)(const ThumbnailViewItem*,const ThumbnailViewItem*);
+
 public:
 
     SfxTemplateManagerDlg (Window *parent = DIALOG_NO_PARENT);
@@ -51,29 +53,23 @@ public:
 
     DECL_LINK(ActivatePageHdl, void*);
 
-    static BitmapEx getDefaultThumbnail( const rtl::OUString& rPath );
-
 private:
 
-    virtual void MouseButtonDown( const MouseEvent& rMEvt );
-
     virtual void Resize ();
 
-    DECL_LINK(CloseOverlayHdl, void*);
-
     DECL_LINK(TBXViewHdl, void*);
     DECL_LINK(TBXActionHdl, void*);
     DECL_LINK(TBXTemplateHdl, void*);
     DECL_LINK(TBXDropdownHdl, ToolBox*);
 
-    DECL_LINK(TVFolderStateHdl, const ThumbnailViewItem*);
-    DECL_LINK(TVTemplateStateHdl, const ThumbnailViewItem*);
+    DECL_LINK(TVItemStateHdl, const ThumbnailViewItem*);
 
     DECL_LINK(MenuSelectHdl, Menu*);
     DECL_LINK(MoveMenuSelectHdl, Menu*);
     DECL_LINK(RepositoryMenuSelectHdl, Menu*);
     DECL_LINK(DefaultTemplateMenuSelectHdl, Menu*);
 
+    DECL_LINK(OpenRegionHdl, void*);
     DECL_LINK(OpenTemplateHdl, ThumbnailViewItem*);
 
     DECL_LINK(SearchUpdateHdl, void*);
@@ -85,8 +81,14 @@ private:
     void OnTemplateDelete ();
     void OnTemplateAsDefault ();
     void OnTemplateExport ();
+
+    void OnTemplateState (const ThumbnailViewItem *pItem);
+
     void OnFolderNew ();
     void OnFolderDelete ();
+
+    void OnRegionState (const ThumbnailViewItem *pItem);
+
     void OnRepositoryDelete ();
     void OnTemplateSaveAs ();
 
@@ -143,8 +145,8 @@ private:
     PopupMenu *mpRepositoryMenu;
     PopupMenu *mpTemplateDefaultMenu;
 
-    std::set<const ThumbnailViewItem*> maSelTemplates;
-    std::set<const ThumbnailViewItem*> maSelFolders;
+    std::set<const ThumbnailViewItem*,selection_cmp_fn> maSelTemplates;
+    std::set<const ThumbnailViewItem*,selection_cmp_fn> maSelFolders;
 
     bool mbIsSaveMode;  ///< Flag that indicates if we are in save mode or not.
     com::sun::star::uno::Reference< com::sun::star::frame::XModel > m_xModel;
diff --git a/sfx2/source/control/templateabstractview.cxx b/sfx2/source/control/templateabstractview.cxx
index b6cd646..baa72ee 100644
--- a/sfx2/source/control/templateabstractview.cxx
+++ b/sfx2/source/control/templateabstractview.cxx
@@ -8,10 +8,10 @@
  */
 
 #include <sfx2/templateabstractview.hxx>
-#include <sfx2/templatecontaineritem.hxx>
 
 #include <comphelper/processfactory.hxx>
-#include <sfx2/templateview.hxx>
+#include <sfx2/sfxresid.hxx>
+#include <sfx2/templatecontaineritem.hxx>
 #include <sfx2/templateviewitem.hxx>
 #include <tools/urlobj.hxx>
 #include <unotools/ucbstreamhelper.hxx>
@@ -24,6 +24,9 @@
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
 
+#include "../doc/doc.hrc"
+#include "templateview.hrc"
+
 bool ViewFilter_Application::isValid (const OUString &rPath) const
 {
     bool bRet = true;
@@ -115,113 +118,85 @@ bool ViewFilter_Keyword::operator ()(const ThumbnailViewItem *pItem)
 
 TemplateAbstractView::TemplateAbstractView (Window *pParent, WinBits nWinStyle, bool bDisableTransientChildren)
     : ThumbnailView(pParent,nWinStyle,bDisableTransientChildren),
-      mpItemView(new TemplateView(pParent)),
-      mbFilteredResults(false),
-      meFilterOption(FILTER_APP_WRITER)
+      mnCurRegionId(0),
+      maAllButton(this, SfxResId(BTN_ALL_TEMPLATES)),
+      maFTName(this, SfxResId(FT_NAME))
 {
-    mpItemView->setItemStateHdl(LINK(this,TemplateAbstractView,OverlayItemStateHdl));
+    maAllButton.Hide();
+    maAllButton.SetStyle(maAllButton.GetStyle() | WB_FLATBUTTON);
+    maAllButton.SetClickHdl(LINK(this,TemplateAbstractView,ShowRootRegionHdl));
+    maFTName.Hide();
 }
 
 TemplateAbstractView::TemplateAbstractView(Window *pParent, const ResId &rResId, bool bDisableTransientChildren)
     : ThumbnailView(pParent,rResId,bDisableTransientChildren),
-      mpItemView(new TemplateView(pParent)),
-      mbFilteredResults(false),
-      meFilterOption(FILTER_APP_WRITER)
+      mnCurRegionId(0),
+      maAllButton(this, SfxResId(BTN_ALL_TEMPLATES)),
+      maFTName(this, SfxResId(FT_NAME))
 {
-    mpItemView->setItemStateHdl(LINK(this,TemplateAbstractView,OverlayItemStateHdl));
+    maAllButton.Hide();
+    maAllButton.SetStyle(maAllButton.GetStyle() | WB_FLATBUTTON);
+    maAllButton.SetClickHdl(LINK(this,TemplateAbstractView,ShowRootRegionHdl));
+    maFTName.Hide();
 }
 
 TemplateAbstractView::~TemplateAbstractView ()
 {
-    delete mpItemView;
 }
 
-void TemplateAbstractView::setItemDimensions(long ItemWidth, long ThumbnailHeight, long DisplayHeight, int itemPadding)
+void TemplateAbstractView::insertItems(const std::vector<TemplateItemProperties> &rTemplates)
 {
-    ThumbnailView::setItemDimensions(ItemWidth,ThumbnailHeight,DisplayHeight,itemPadding);
-
-    mpItemView->setItemDimensions(ItemWidth,ThumbnailHeight,DisplayHeight,itemPadding);
-}
+    std::vector<ThumbnailViewItem*> aItems(rTemplates.size());
+    for (size_t i = 0, n = rTemplates.size(); i < n; ++i )
+    {
+        //TODO: CHECK IF THE ITEM IS A FOLDER OR NOT
+        TemplateViewItem *pChild = new TemplateViewItem(*this);
+        const TemplateItemProperties *pCur = &rTemplates[i];
+
+        pChild->mnId = pCur->nId;
+        pChild->mnDocId = pCur->nDocId;
+        pChild->mnRegionId = pCur->nRegionId;
+        pChild->maTitle = pCur->aName;
+        pChild->setPath(pCur->aPath);
+        pChild->maPreview1 = pCur->aThumbnail;
+
+        if ( pCur->aThumbnail.IsEmpty() )
+        {
+            // Use the default thumbnail if we have nothing else
+            pChild->maPreview1 = TemplateAbstractView::getDefaultThumbnail(pCur->aPath);
+        }
 
-sal_uInt16 TemplateAbstractView::getOverlayRegionId() const
-{
-    return mpItemView->getId();
-}
+        pChild->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
 
-const OUString &TemplateAbstractView::getOverlayName() const
-{
-    return mpItemView->getName();
-}
+        aItems[i] = pChild;
+    }
 
-bool TemplateAbstractView::isOverlayVisible () const
-{
-    return mpItemView->IsVisible();
+    updateItems(aItems);
 }
 
-void TemplateAbstractView::deselectOverlayItems()
+sal_uInt16 TemplateAbstractView::getCurRegionId() const
 {
-    mpItemView->deselectItems();
+    return mnCurRegionId;
 }
 
-void TemplateAbstractView::sortOverlayItems(const boost::function<bool (const ThumbnailViewItem*,
-                                                                        const ThumbnailViewItem*) > &func)
+const OUString &TemplateAbstractView::getCurRegionName() const
 {
-    mpItemView->sortItems(func);
+    return maCurRegionName;
 }
 
-void TemplateAbstractView::filterTemplatesByApp (const FILTER_APPLICATION &eApp)
+bool TemplateAbstractView::isNonRootRegionVisible () const
 {
-    meFilterOption = eApp;
-
-    if (mpItemView->IsVisible())
-    {
-        mbFilteredResults = true;
-        mpItemView->filterItems(ViewFilter_Application(eApp));
-    }
-    else
-    {
-        filterItems(ViewFilter_Application(eApp));
-    }
-}
-
-void TemplateAbstractView::showOverlay (bool bVisible)
-{
-    Show(!bVisible);
-    mpItemView->Show(bVisible);
-
-    mpItemView->SetPosSizePixel(GetPosPixel(), GetSizePixel());
-    mpItemView->SetStyle(GetStyle());
-
-    mpItemView->GrabFocus();
-
-    // Clear items is the overlay is closed.
-    if (!bVisible)
-    {
-        // Check if the folder view needs to be filtered
-        if (mbFilteredResults)
-        {
-            filterItems(ViewFilter_Application(meFilterOption));
-        }
-
-        mpItemView->Clear();
-    }
+    return mnCurRegionId;
 }
 
-void TemplateAbstractView::filterTemplatesByKeyword(const OUString &rKeyword)
+void TemplateAbstractView::setOpenRegionHdl(const Link &rLink)
 {
-    if (mpItemView->IsVisible())
-        mpItemView->filterItems(ViewFilter_Keyword(rKeyword));
+    maOpenRegionHdl = rLink;
 }
 
-void TemplateAbstractView::setOpenHdl(const Link &rLink)
+void TemplateAbstractView::setOpenTemplateHdl(const Link &rLink)
 {
-    maOpenHdl = rLink;
-    mpItemView->setOpenHdl(rLink);
-}
-
-void TemplateAbstractView::setOverlayCloseHdl(const Link &rLink)
-{
-    mpItemView->setCloseHdl(rLink);
+    maOpenTemplateHdl = rLink;
 }
 
 BitmapEx TemplateAbstractView::scaleImg (const BitmapEx &rImg, long width, long height)
@@ -259,6 +234,31 @@ BitmapEx TemplateAbstractView::scaleImg (const BitmapEx &rImg, long width, long
     return aImg;
 }
 
+BitmapEx TemplateAbstractView::getDefaultThumbnail( const OUString& rPath )
+{
+    INetURLObject aUrl(rPath);
+    OUString aExt = aUrl.getExtension();
+
+    BitmapEx aImg;
+    if ( aExt == "ott" || aExt == "stw" || aExt == "oth" || aExt == "dot" || aExt == "dotx" )
+    {
+        aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_TEXT ) );
+    }
+    else if ( aExt == "ots" || aExt == "stc" || aExt == "xlt" || aExt == "xltm" || aExt == "xltx" )
+    {
+        aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_SHEET ) );
+    }
+    else if ( aExt == "otp" || aExt == "sti" || aExt == "pot" || aExt == "potm" || aExt == "potx" )
+    {
+        aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_PRESENTATION ) );
+    }
+    else if ( aExt == "otg" || aExt == "std" )
+    {
+        aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_DRAWING ) );
+    }
+    return aImg;
+}
+
 BitmapEx TemplateAbstractView::fetchThumbnail (const OUString &msURL, long width, long height)
 {
     using namespace ::com::sun::star;
@@ -360,49 +360,29 @@ BitmapEx TemplateAbstractView::fetchThumbnail (const OUString &msURL, long width
     return TemplateAbstractView::scaleImg(aThumbnail,width,height);
 }
 
-void TemplateAbstractView::Resize()
-{
-    mpItemView->SetSizePixel(GetSizePixel());
-    ThumbnailView::Resize();
-}
-
-void TemplateAbstractView::Paint(const Rectangle &rRect)
+IMPL_LINK_NOARG(TemplateAbstractView, ShowRootRegionHdl)
 {
-    if (!mpItemView->IsVisible())
-        ThumbnailView::Paint(rRect);
-}
-
-void TemplateAbstractView::DrawItem(ThumbnailViewItem *pItem)
-{
-    if (!mpItemView->IsVisible())
-        ThumbnailView::DrawItem(pItem);
-}
-
-IMPL_LINK(TemplateAbstractView, OverlayItemStateHdl, const ThumbnailViewItem*, pItem)
-{
-    maOverlayItemStateHdl.Call((void*)pItem);
+    showRootRegion();
     return 0;
 }
 
 void TemplateAbstractView::OnItemDblClicked (ThumbnailViewItem *pItem)
 {
+    //Check if the item is a TemplateContainerItem (Folder) or a TemplateViewItem (File)
+
     TemplateContainerItem* pContainerItem = dynamic_cast<TemplateContainerItem*>(pItem);
     if ( pContainerItem )
     {
         // Fill templates
-        sal_uInt16 nRegionId = pContainerItem->mnId-1;
-
-        mpItemView->setId(nRegionId);
-        mpItemView->setName(pContainerItem->maTitle);
-        mpItemView->InsertItems(pContainerItem->maTemplates);
-
-        mpItemView->filterItems(ViewFilter_Application(meFilterOption));
 
-        showOverlay(true);
+        mnCurRegionId = pContainerItem->mnId-1;
+        maCurRegionName = pContainerItem->maTitle;
+        maFTName.SetText(maCurRegionName);
+        showRegion(pItem);
     }
     else
     {
-        maOpenHdl.Call(pItem);
+        maOpenTemplateHdl.Call(pItem);
     }
 }
 
diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx
index 0bb12dc..9bb94c3 100644
--- a/sfx2/source/control/templatelocalview.cxx
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -12,7 +12,6 @@
 #include <comphelper/processfactory.hxx>
 #include <sfx2/doctempl.hxx>
 #include <sfx2/templatecontaineritem.hxx>
-#include <sfx2/templateview.hxx>
 #include <sfx2/templateviewitem.hxx>
 #include <svl/inettype.hxx>
 #include <tools/urlobj.hxx>
@@ -36,17 +35,25 @@ TemplateLocalView::TemplateLocalView ( Window* pParent, const ResId& rResId, boo
     : TemplateAbstractView(pParent,rResId,bDisableTransientChildren),
       mpDocTemplates(new SfxDocumentTemplates)
 {
-    mpItemView->SetColor(GetSettings().GetStyleSettings().GetFieldColor());
-    mpItemView->setMasterView(this);
 }
 
 TemplateLocalView::~TemplateLocalView()
 {
+    for (size_t i = 0; i < maRegions.size(); ++i)
+        delete maRegions[i];
+
+    maRegions.clear();
+
     delete mpDocTemplates;
 }
 
 void TemplateLocalView::Populate ()
 {
+    for (size_t i = 0; i < maRegions.size(); ++i)
+        delete maRegions[i];
+
+    maRegions.clear();
+
     sal_uInt16 nCount = mpDocTemplates->GetRegionCount();
     for (sal_uInt16 i = 0; i < nCount; ++i)
     {
@@ -65,6 +72,7 @@ void TemplateLocalView::Populate ()
             OUString aURL = mpDocTemplates->GetPath(i,j);
 
             TemplateItemProperties aProperties;
+            aProperties.aIsFolder = false;          // Flat hierarchy for the local filesystem (no nested folders)
             aProperties.nId = j+1;
             aProperties.nDocId = j;
             aProperties.nRegionId = i;
@@ -79,46 +87,90 @@ void TemplateLocalView::Populate ()
 
         lcl_updateThumbnails(pItem);
 
-        mItemList.push_back(pItem);
+        maRegions.push_back(pItem);
     }
-
-    CalculateItemPositions();
-
-    if ( IsReallyVisible() && IsUpdateMode() )
-        Invalidate();
 }
 
 void TemplateLocalView::reload ()
 {
     mpDocTemplates->Update();
 
-    Clear();
-
     Populate();
 
-    if (mpItemView->IsVisible())
+    // Check if we are currently browsing a region or root folder
+    if (mnCurRegionId)
     {
-        sal_uInt16 nItemId = mpItemView->getId() + 1;
+        sal_uInt16 nItemId = mnCurRegionId + 1;
 
-        for (size_t i = 0; i < mItemList.size(); ++i)
+        for (size_t i = 0; i < maRegions.size(); ++i)
         {
-            if (mItemList[i]->mnId == nItemId)
+            if (maRegions[i]->mnId == nItemId)
             {
-                mpItemView->Clear();
-                mpItemView->InsertItems(static_cast<TemplateContainerItem*>(mItemList[i])->maTemplates);
+                showRegion(maRegions[i]);
                 break;
             }
         }
     }
+    else
+        showRootRegion();
+}
+
+void TemplateLocalView::showRootRegion()
+{
+    mnHeaderHeight = 0;
+    mnCurRegionId = 0;
+    maCurRegionName = OUString();
+
+    // Clone root region items so they dont get invalidated when we open another region
+    std::vector<ThumbnailViewItem*> items(maRegions.size());
+    for (int i = 0, n = maRegions.size(); i < n; ++i)
+    {
+        TemplateContainerItem *pCur = maRegions[i];
+        TemplateContainerItem *pItem = new TemplateContainerItem(*this);
+        pItem->mnId = pCur->mnId;
+        pItem->maTitle = pCur->maTitle;
+        pItem->maTemplates = pCur->maTemplates;
+        pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
+
+        items[i] = pItem;
+    }
+
+    maAllButton.Show(false);
+    maFTName.Show(false);
+
+    updateItems(items);
+
+    maOpenRegionHdl.Call(NULL);
+}
+
+void TemplateLocalView::showRegion(ThumbnailViewItem *pItem)
+{
+    mnHeaderHeight = maAllButton.GetSizePixel().getHeight() + maAllButton.GetPosPixel().Y() * 2;
+
+    mnCurRegionId = pItem->mnId-1;
+    maCurRegionName = pItem->maTitle;
+    maAllButton.Show(true);
+    maFTName.Show(true);
+
+    insertItems(reinterpret_cast<TemplateContainerItem*>(pItem)->maTemplates);
+
+    maOpenRegionHdl.Call(NULL);
+}
+
+sal_uInt16 TemplateLocalView::getRegionId(size_t pos) const
+{
+    assert(pos < maRegions.size());
+
+    return maRegions[pos]->mnId;
 }
 
 std::vector<OUString> TemplateLocalView::getFolderNames()
 {
-    size_t n = mItemList.size();
+    size_t n = maRegions.size();
     std::vector<OUString> ret(n);
 
     for (size_t i = 0; i < n; ++i)
-        ret[i] = mItemList[i]->maTitle;
+        ret[i] = maRegions[i]->maTitle;
 
     return ret;
 }
@@ -128,9 +180,9 @@ TemplateLocalView::getFilteredItems(const boost::function<bool (const TemplateIt
 {
     std::vector<TemplateItemProperties> aItems;
 
-    for (size_t i = 0; i < mItemList.size(); ++i)
+    for (size_t i = 0; i < maRegions.size(); ++i)
     {
-        TemplateContainerItem *pFolderItem = static_cast<TemplateContainerItem*>(mItemList[i]);
+        TemplateContainerItem *pFolderItem = static_cast<TemplateContainerItem*>(maRegions[i]);
 
         for (size_t j = 0; j < pFolderItem->maTemplates.size(); ++j)
         {
@@ -151,17 +203,23 @@ sal_uInt16 TemplateLocalView::createRegion(const OUString &rName)
 
     OUString aRegionName = rName;
 
+    // Insert to the region cache list and to the thumbnail item list
     TemplateContainerItem* pItem = new TemplateContainerItem( *this );
     pItem->mnId = nRegionId+1;
     pItem->maTitle = aRegionName;
     pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
 
+    maRegions.push_back(pItem);
+
+    pItem = new TemplateContainerItem(*this);
+    pItem->mnId = nRegionId + 1;
+    pItem->maTitle = aRegionName;
+    pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
+
     mItemList.push_back(pItem);
 
     CalculateItemPositions();
-
-    if ( IsReallyVisible() && IsUpdateMode() )
-        Invalidate();
+    Invalidate();
 
     return pItem->mnId;
 }
@@ -175,6 +233,18 @@ bool TemplateLocalView::removeRegion(const sal_uInt16 nItemId)
 
     RemoveItem(nItemId);
 
+    // Remove from the region cache list
+    std::vector<TemplateContainerItem*>::iterator it;
+    for ( it = maRegions.begin(); it != maRegions.end(); ++it )
+    {
+        if ( (*it)->mnId == nItemId )
+        {
+            delete *it;
+            maRegions.erase(it);
+            break;
+        }
+    }
+
     return true;
 }
 
@@ -182,11 +252,11 @@ bool TemplateLocalView::removeTemplate (const sal_uInt16 nItemId, const sal_uInt
 {
     sal_uInt16 nRegionId = nSrcItemId - 1;
 
-    for (size_t i = 0, n = mItemList.size(); i < n; ++i)
+    for (size_t i = 0, n = maRegions.size(); i < n; ++i)
     {
-        if (mItemList[i]->mnId == nSrcItemId)
+        if (maRegions[i]->mnId == nSrcItemId)
         {
-            TemplateContainerItem *pItem = static_cast<TemplateContainerItem*>(mItemList[i]);
+            TemplateContainerItem *pItem = static_cast<TemplateContainerItem*>(maRegions[i]);
             std::vector<TemplateItemProperties>::iterator pIter;
             for (pIter = pItem->maTemplates.begin(); pIter != pItem->maTemplates.end(); ++pIter)
             {
@@ -197,7 +267,7 @@ bool TemplateLocalView::removeTemplate (const sal_uInt16 nItemId, const sal_uInt
 
                     pIter = pItem->maTemplates.erase(pIter);
 
-                    mpItemView->RemoveItem(nItemId);
+                    RemoveItem(nItemId);
 
                     // Update Doc Idx for all templates that follow
                     for (; pIter != pItem->maTemplates.end(); ++pIter)
@@ -227,12 +297,12 @@ bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_
     TemplateContainerItem *pTarget = NULL;
     TemplateContainerItem *pSrc = NULL;
 
-    for (size_t i = 0, n = mItemList.size(); i < n; ++i)
+    for (size_t i = 0, n = maRegions.size(); i < n; ++i)
     {
-        if (mItemList[i]->mnId == nTargetItem)
-            pTarget = static_cast<TemplateContainerItem*>(mItemList[i]);
-        else if (mItemList[i]->mnId == nSrcItem)
-            pSrc = static_cast<TemplateContainerItem*>(mItemList[i]);
+        if (maRegions[i]->mnId == nTargetItem)
+            pTarget = static_cast<TemplateContainerItem*>(maRegions[i]);
+        else if (maRegions[i]->mnId == nSrcItem)
+            pSrc = static_cast<TemplateContainerItem*>(maRegions[i]);
     }
 
     if (pTarget && pSrc)
@@ -267,7 +337,7 @@ bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_
 
         if (!bCopy)
         {
-            // remove template from overlay and from cached data
+            // remove template from region cached data
 
             std::vector<TemplateItemProperties>::iterator aIter;
             for (aIter = pSrc->maTemplates.begin(); aIter != pSrc->maTemplates.end(); ++aIter)
@@ -276,7 +346,7 @@ bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_
                 {
                     pSrc->maTemplates.erase(aIter);
 
-                    mpItemView->RemoveItem(pViewItem->mnId);
+                    RemoveItem(pViewItem->mnId);
                     break;
                 }
             }
@@ -293,43 +363,39 @@ bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_
         lcl_updateThumbnails(pTarget);
 
         CalculateItemPositions();
-
-        if (IsReallyVisible() && IsUpdateMode())
-        {
-            Invalidate();
-            mpItemView->Invalidate();
-        }
+        Invalidate();
     }
 
     return bRet;
 }
 
-bool TemplateLocalView::moveTemplates(std::set<const ThumbnailViewItem *> &rItems,
-                                       const sal_uInt16 nTargetItem, bool bCopy)
+bool TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, selection_cmp_fn> &rItems,
+                                      const sal_uInt16 nTargetItem, bool bCopy)
 {
     bool ret = true;
     bool refresh = false;
 
-    sal_uInt16 nSrcRegionId = mpItemView->getId();
+    sal_uInt16 nSrcRegionId = mnCurRegionId;
     sal_uInt16 nSrcRegionItemId = nSrcRegionId + 1;
 
     TemplateContainerItem *pTarget = NULL;
     TemplateContainerItem *pSrc = NULL;
 
-    for (size_t i = 0, n = mItemList.size(); i < n; ++i)
+    for (size_t i = 0, n = maRegions.size(); i < n; ++i)
     {
-        if (mItemList[i]->mnId == nTargetItem)
-            pTarget = static_cast<TemplateContainerItem*>(mItemList[i]);
-        else if (mItemList[i]->mnId == nSrcRegionItemId)
-            pSrc = static_cast<TemplateContainerItem*>(mItemList[i]);
+        if (maRegions[i]->mnId == nTargetItem)
+            pTarget = static_cast<TemplateContainerItem*>(maRegions[i]);
+        else if (maRegions[i]->mnId == nSrcRegionItemId)
+            pSrc = static_cast<TemplateContainerItem*>(maRegions[i]);
     }
 
     if (pTarget && pSrc)
     {
         sal_uInt16 nTargetRegion = pTarget->mnId-1;
         sal_uInt16 nTargetIdx = mpDocTemplates->GetCount(nTargetRegion);    // Next Idx
+        std::vector<sal_uInt16> aItemIds;    // List of moved items ids (also prevents the invalidation of rItems iterators when we remove them as we go)
 
-        std::set<const ThumbnailViewItem*>::iterator aSelIter;
+        std::set<const ThumbnailViewItem*,selection_cmp_fn>::iterator aSelIter;
         for ( aSelIter = rItems.begin(); aSelIter != rItems.end(); ++aSelIter, ++nTargetIdx )
         {
             const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(*aSelIter);
@@ -361,7 +427,7 @@ bool TemplateLocalView::moveTemplates(std::set<const ThumbnailViewItem *> &rItem
 
             if (!bCopy)
             {
-                // remove template from overlay and from cached data
+                // remove template from region cached data
 
                 std::vector<TemplateItemProperties>::iterator pIter;
                 for (pIter = pSrc->maTemplates.begin(); pIter != pSrc->maTemplates.end(); ++pIter)
@@ -369,8 +435,7 @@ bool TemplateLocalView::moveTemplates(std::set<const ThumbnailViewItem *> &rItem
                     if (pIter->nId == pViewItem->mnId)
                     {
                         pSrc->maTemplates.erase(pIter);
-
-                        mpItemView->RemoveItem(pViewItem->mnId);
+                        aItemIds.push_back(pViewItem->mnId);
                         break;
                     }
                 }
@@ -378,20 +443,22 @@ bool TemplateLocalView::moveTemplates(std::set<const ThumbnailViewItem *> &rItem
 
             refresh = true;
         }
-    }
-    else
-        ret = false;
 
-    if (refresh)
-    {
-        lcl_updateThumbnails(pSrc);
-        lcl_updateThumbnails(pTarget);
+        // Remove items from the current view
+        for (std::vector<sal_uInt16>::iterator it = aItemIds.begin(); it != aItemIds.end(); ++it)
+            RemoveItem(*it);
 
-        CalculateItemPositions();
+        if (refresh)
+        {
+            lcl_updateThumbnails(pSrc);
+            lcl_updateThumbnails(pTarget);
 
-        Invalidate();
-        mpItemView->Invalidate();
+            CalculateItemPositions();
+            Invalidate();
+        }
     }
+    else
+        ret = false;
 
     return ret;
 }
@@ -401,15 +468,15 @@ bool TemplateLocalView::copyFrom(const sal_uInt16 nRegionItemId, const BitmapEx
 {
     sal_uInt16 nRegionId = nRegionItemId - 1;
 
-    for (size_t i = 0, n = mItemList.size(); i < n; ++i)
+    for (size_t i = 0, n = maRegions.size(); i < n; ++i)
     {
-        if (mItemList[i]->mnId == nRegionItemId)
+        if (maRegions[i]->mnId == nRegionItemId)
         {
             sal_uInt16 nId = 0;
             sal_uInt16 nDocId = 0;
 
             TemplateContainerItem *pRegionItem =
-                    static_cast<TemplateContainerItem*>(mItemList[i]);
+                    static_cast<TemplateContainerItem*>(maRegions[i]);
 
             if (!pRegionItem->maTemplates.empty())
             {
@@ -430,7 +497,7 @@ bool TemplateLocalView::copyFrom(const sal_uInt16 nRegionItemId, const BitmapEx
                 aTemplate.aPath = mpDocTemplates->GetPath(nRegionId,nDocId);
 
                 TemplateContainerItem *pItem =
-                        static_cast<TemplateContainerItem*>(mItemList[i]);
+                        static_cast<TemplateContainerItem*>(maRegions[i]);
 
                 pItem->maTemplates.push_back(aTemplate);
 
@@ -487,12 +554,12 @@ bool TemplateLocalView::exportTo(const sal_uInt16 nItemId, const sal_uInt16 nReg
 {
     sal_uInt16 nRegionId = nRegionItemId - 1;
 
-    for (size_t i = 0, n = mItemList.size(); i < n; ++i)
+    for (size_t i = 0, n = maRegions.size(); i < n; ++i)
     {
-        if (mItemList[i]->mnId == nRegionItemId)
+        if (maRegions[i]->mnId == nRegionItemId)
         {
             TemplateContainerItem *pRegItem =
-                    static_cast<TemplateContainerItem*>(mItemList[i]);
+                    static_cast<TemplateContainerItem*>(maRegions[i]);
 
             std::vector<TemplateItemProperties>::iterator aIter;
             for (aIter = pRegItem->maTemplates.begin(); aIter != pRegItem->maTemplates.end(); ++aIter)
@@ -519,11 +586,11 @@ bool TemplateLocalView::saveTemplateAs (sal_uInt16 nItemId,
 {
     bool bRet = false;
 
-    for (size_t i = 0, n = mItemList.size(); i < n; ++i)
+    for (size_t i = 0, n = maRegions.size(); i < n; ++i)
     {
-        if (mItemList[i]->mnId == nItemId)
+        if (maRegions[i]->mnId == nItemId)
         {
-            bRet = saveTemplateAs((const TemplateContainerItem*)mItemList[i],rModel,rName);
+            bRet = saveTemplateAs((const TemplateContainerItem*)maRegions[i],rModel,rName);
             break;
         }
     }
@@ -550,12 +617,12 @@ bool TemplateLocalView::saveTemplateAs(const TemplateContainerItem *pDstItem,
 
 bool TemplateLocalView::isTemplateNameUnique(const sal_uInt16 nRegionItemId, const OUString &rName) const
 {
-    for (size_t i = 0, n = mItemList.size(); i < n; ++i)
+    for (size_t i = 0, n = maRegions.size(); i < n; ++i)
     {
-        if (mItemList[i]->mnId == nRegionItemId)
+        if (maRegions[i]->mnId == nRegionItemId)
         {
             TemplateContainerItem *pRegItem =
-                    static_cast<TemplateContainerItem*>(mItemList[i]);
+                    static_cast<TemplateContainerItem*>(maRegions[i]);
 
             std::vector<TemplateItemProperties>::iterator aIter;
             for (aIter = pRegItem->maTemplates.begin(); aIter != pRegItem->maTemplates.end(); ++aIter)
diff --git a/sfx2/source/control/templateremoteview.cxx b/sfx2/source/control/templateremoteview.cxx
index b67b8aa..bf97393 100644
--- a/sfx2/source/control/templateremoteview.cxx
+++ b/sfx2/source/control/templateremoteview.cxx
@@ -11,7 +11,6 @@
 
 #include <comphelper/processfactory.hxx>
 #include <sfx2/templaterepository.hxx>
-#include <sfx2/templateview.hxx>
 #include <sfx2/templateviewitem.hxx>
 #include <svtools/imagemgr.hxx>
 #include <tools/urlobj.hxx>
@@ -47,8 +46,6 @@ enum
 TemplateRemoteView::TemplateRemoteView (Window *pParent, WinBits nWinStyle, bool bDisableTransientChildren)
     : TemplateAbstractView(pParent,nWinStyle,bDisableTransientChildren)
 {
-    mpItemView->SetColor(Color(COL_WHITE));
-
     Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
     Reference< XInteractionHandler > xGlobalInteractionHandler(
         InteractionHandler::createWithParent(xContext, 0), UNO_QUERY_THROW );
@@ -60,6 +57,16 @@ TemplateRemoteView::~TemplateRemoteView ()
 {
 }
 
+void TemplateRemoteView::showRootRegion()
+{
+    //TODO:
+}
+
+void TemplateRemoteView::showRegion(ThumbnailViewItem */*pItem*/)
+{
+    //TODO:
+}
+
 bool TemplateRemoteView::loadRepository (TemplateRepository* pItem, bool bRefresh)
 {
     if (!pItem)
@@ -67,13 +74,13 @@ bool TemplateRemoteView::loadRepository (TemplateRepository* pItem, bool bRefres
 
     if (!pItem->getTemplates().empty() && !bRefresh)
     {
-        mpItemView->InsertItems(pItem->getTemplates());
+        insertItems(pItem->getTemplates());
         return true;
     }
 
-    mpItemView->Clear();
-    mpItemView->setId(pItem->mnId);
-    mpItemView->setName(pItem->maTitle);
+    mnCurRegionId = pItem->mnId;
+    maCurRegionName = pItem->maTitle;
+    maFTName.SetText(maCurRegionName);
 
     OUString aURL = pItem->getURL();
 
@@ -140,7 +147,7 @@ bool TemplateRemoteView::loadRepository (TemplateRepository* pItem, bool bRefres
                 }
             }
 
-            mpItemView->InsertItems(aItems);
+            insertItems(aItems);
         }
     }
     catch( ucb::CommandAbortedException& )
diff --git a/sfx2/source/control/templateview.cxx b/sfx2/source/control/templateview.cxx
deleted file mode 100644
index a19c8c5..0000000
--- a/sfx2/source/control/templateview.cxx
+++ /dev/null
@@ -1,106 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Copyright 2012 LibreOffice contributors.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#include "templatedlg.hxx"
-#include <sfx2/templateview.hxx>
-#include <sfx2/templateabstractview.hxx>
-
-#include <basegfx/matrix/b2dhommatrixtools.hxx>
-#include <basegfx/point/b2dpoint.hxx>
-#include <basegfx/range/b2drange.hxx>
-#include <basegfx/vector/b2dvector.hxx>
-#include <drawinglayer/attribute/fillbitmapattribute.hxx>
-#include <drawinglayer/primitive2d/fillbitmapprimitive2d.hxx>
-#include <drawinglayer/primitive2d/textlayoutdevice.hxx>
-#include <drawinglayer/primitive2d/textprimitive2d.hxx>
-#include <drawinglayer/processor2d/baseprocessor2d.hxx>
-#include <sfx2/sfxresid.hxx>
-#include <sfx2/templateviewitem.hxx>
-#include <vcl/edit.hxx>
-
-#include "templateview.hrc"
-
-#define EDIT_HEIGHT 30
-
-using namespace basegfx;
-using namespace basegfx::tools;
-using namespace drawinglayer::attribute;
-using namespace drawinglayer::primitive2d;
-
-TemplateView::TemplateView (Window *pParent)
-    : ThumbnailView(pParent,WB_VSCROLL | WB_TABSTOP),
-      mpMasterView(NULL),
-      maAllButton(this, SfxResId(BTN_ALL_TEMPLATES)),
-      maFTName(this, SfxResId(FT_NAME)),
-      mnId(0)
-{
-    mnHeaderHeight = maAllButton.GetSizePixel().getHeight() + maAllButton.GetPosPixel().Y() * 2;
-    maAllButton.SetStyle(maAllButton.GetStyle() | WB_FLATBUTTON);
-}
-
-TemplateView::~TemplateView ()
-{
-}
-
-void TemplateView::setName (const OUString &rName)
-{
-    maName = rName;
-    maFTName.SetText(maName);
-}
-
-void TemplateView::InsertItems (const std::vector<TemplateItemProperties> &rTemplates)
-{
-    for (size_t i = 0, n = rTemplates.size(); i < n; ++i )
-    {
-        TemplateViewItem *pItem = new TemplateViewItem(*this);
-        const TemplateItemProperties *pCur = &rTemplates[i];
-
-        pItem->mnId = pCur->nId;
-        pItem->mnDocId = pCur->nDocId;
-        pItem->mnRegionId = pCur->nRegionId;
-        pItem->maTitle = pCur->aName;
-        pItem->setPath(pCur->aPath);
-        pItem->maPreview1 = pCur->aThumbnail;
-        if ( pCur->aThumbnail.IsEmpty() )
-        {
-            // Use the default thumbnail if we have nothing else
-            pItem->maPreview1 = SfxTemplateManagerDlg::getDefaultThumbnail( pItem->getPath() );
-        }
-        pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
-
-        mItemList.push_back(pItem);
-    }
-
-    CalculateItemPositions();
-
-    Invalidate();
-}
-
-void TemplateView::Resize()
-{
-    Size aWinSize = GetOutputSize();
-
-    // Set the buttons panel and buttons size
-    Size aNameSize = maFTName.GetSizePixel();
-    aNameSize.setWidth( aWinSize.getWidth() - maFTName.GetPosPixel().X());
-    maFTName.SetSizePixel(aNameSize);
-
-    ThumbnailView::Resize();
-}
-
-bool TemplateView::renameItem(ThumbnailViewItem* pItem, rtl::OUString sNewTitle)
-{
-    if (mpMasterView)
-        return mpMasterView->renameItem(pItem, sNewTitle);
-    return false;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
-
-
diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx
index 49ca699..c7c487e 100644
--- a/sfx2/source/control/thumbnailview.cxx
+++ b/sfx2/source/control/thumbnailview.cxx
@@ -257,9 +257,6 @@ void ThumbnailView::CalculateItemPositions ()
     if ( !mnLines )
         mnLines = 1;
 
-    // check if scroll is needed
-    mbScroll = mnLines > mnVisLines;
-
     if ( mnLines <= mnVisLines )
         mnFirstLine = 0;
     else
@@ -370,7 +367,11 @@ void ThumbnailView::CalculateItemPositions ()
     // arrange ScrollBar, set values and show it
     if ( mpScrBar )
     {
-        long nLines = (nCurCount+mnCols-1)/mnCols;
+        mnLines = (nCurCount+mnCols-1)/mnCols;
+
+        // check if scroll is needed
+        mbScroll = mnLines > mnVisLines;
+
 
         Point aPos( aWinSize.Width() - nScrBarWidth - mnScrBarOffset, mnHeaderHeight );
         Size aSize( nScrBarWidth - mnScrBarOffset, aWinSize.Height() - mnHeaderHeight );
@@ -383,7 +384,7 @@ void ThumbnailView::CalculateItemPositions ()
         if ( nPageSize < 1 )
             nPageSize = 1;
         mpScrBar->SetPageSize( nPageSize );
-        mpScrBar->Show( nLines > mnVisLines );
+        mpScrBar->Show( mbScroll );
     }
 
     // delete ScrollBar
@@ -596,12 +597,13 @@ void ThumbnailView::MouseButtonDown( const MouseEvent& rMEvt )
             if ( rMEvt.GetClicks() == 1 )
             {
                 if (pItem->isSelected() && rMEvt.IsMod1())
-                    DeselectItem( pItem->mnId );
+                    pItem->setSelection(false);
                 else
                 {
                     if (!pItem->isSelected() && !rMEvt.IsMod1())
                         deselectItems( );
-                    SelectItem( pItem->mnId );
+
+                    pItem->setSelection(true);
 
                     bool bClickOnTitle = pItem->getTextArea().IsInside(rMEvt.GetPosPixel());
                     pItem->setEditTitle(bClickOnTitle);
@@ -803,6 +805,13 @@ void ThumbnailView::RemoveItem( sal_uInt16 nItemId )
     if ( nPos < mItemList.size() ) {
         ValueItemList::iterator it = mItemList.begin();
         ::std::advance( it, nPos );
+
+        if ((*it)->isSelected())
+        {
+            (*it)->setSelection(false);
+            maItemStateHdl.Call(*it);
+        }
+
         delete *it;
         mItemList.erase( it );
     }
@@ -833,6 +842,21 @@ void ThumbnailView::Clear()
         Invalidate();
 }
 
+void ThumbnailView::updateItems (const std::vector<ThumbnailViewItem*> &items)
+{
+    ImplDeleteItems();
+
+    // reset variables
+    mnFirstLine     = 0;
+    mnHighItemId    = 0;
+
+    mItemList = items;
+
+    CalculateItemPositions();
+
+    Invalidate();
+}
+
 size_t ThumbnailView::GetItemPos( sal_uInt16 nItemId ) const
 {
     for ( size_t i = 0, n = mItemList.size(); i < n; ++i ) {
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index 93740f1..c86704d 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -100,6 +100,18 @@ private:
     OUString maKeyword;
 };
 
+/***
+ *
+ * Order items in ascending order (useful for the selection sets and move/copy operations since the associated ids
+ * change when processed by the SfxDocumentTemplates class so we want to process to ones with higher id first)
+ *
+ ***/
+
+static bool cmpSelectionItems (const ThumbnailViewItem *pItem1, const ThumbnailViewItem *pItem2)
+{
+    return pItem1->mnId > pItem2->mnId;
+}
+
 class TemplateManagerPage : public TabPage
 {
     private:
@@ -121,6 +133,8 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
       mpSearchView(new TemplateSearchView(&maTabPage)),
       maView(new TemplateLocalView(&maTabPage,SfxResId(TEMPLATE_VIEW))),
       mpOnlineView(new TemplateRemoteView(&maTabPage, WB_VSCROLL,false)),
+      maSelTemplates(cmpSelectionItems),
+      maSelFolders(cmpSelectionItems),
       mbIsSaveMode(false),
       mxDesktop( Desktop::create(comphelper::getProcessComponentContext()) ),
       mbIsSynced(false),
@@ -171,10 +185,9 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
                               TEMPLATE_ITEM_MAX_HEIGHT-TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT,
                               TEMPLATE_ITEM_PADDING);
 
-    maView->setItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVFolderStateHdl));
-    maView->setOverlayItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVTemplateStateHdl));
-    maView->setOpenHdl(LINK(this,SfxTemplateManagerDlg,OpenTemplateHdl));
-    maView->setOverlayCloseHdl(LINK(this,SfxTemplateManagerDlg,CloseOverlayHdl));
+    maView->setItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVItemStateHdl));
+    maView->setOpenRegionHdl(LINK(this,SfxTemplateManagerDlg,OpenRegionHdl));
+    maView->setOpenTemplateHdl(LINK(this,SfxTemplateManagerDlg,OpenTemplateHdl));
 
     // Set online view position and dimensions
     mpOnlineView->setItemMaxTextLength(TEMPLATE_ITEM_MAX_TEXT_LENGTH);
@@ -183,9 +196,9 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
                                     TEMPLATE_ITEM_MAX_HEIGHT-TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT,
                                     TEMPLATE_ITEM_PADDING);
 
-    mpOnlineView->setOverlayItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVTemplateStateHdl));
-    mpOnlineView->setOpenHdl(LINK(this,SfxTemplateManagerDlg,OpenTemplateHdl));
-    mpOnlineView->setOverlayCloseHdl(LINK(this,SfxTemplateManagerDlg,CloseOverlayHdl));
+    mpOnlineView->setItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVItemStateHdl));
+    mpOnlineView->setOpenRegionHdl(LINK(this,SfxTemplateManagerDlg,OpenRegionHdl));
+    mpOnlineView->setOpenTemplateHdl(LINK(this,SfxTemplateManagerDlg,OpenTemplateHdl));
 
     mpSearchView->setItemMaxTextLength(TEMPLATE_ITEM_MAX_TEXT_LENGTH);
 
@@ -193,7 +206,7 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
                                     TEMPLATE_ITEM_MAX_HEIGHT-TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT,
                                     TEMPLATE_ITEM_PADDING);
 
-    mpSearchView->setItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVTemplateStateHdl));
+    mpSearchView->setItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVItemStateHdl));
 
     maTabControl.SetActivatePageHdl(LINK(this,SfxTemplateManagerDlg,ActivatePageHdl));
 
@@ -215,9 +228,10 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
     createDefaultTemplateMenu();
 
     maView->Populate();
+    maView->showRootRegion();
     maView->Show();
 
-    mpCurView->filterTemplatesByApp(FILTER_APP_WRITER);
+    mpCurView->filterItems(ViewFilter_Application(FILTER_APP_WRITER));
 
     FreeResource();
 }
@@ -229,6 +243,17 @@ SfxTemplateManagerDlg::~SfxTemplateManagerDlg ()
     for (size_t i = 0, n = maRepositories.size(); i < n; ++i)
         delete maRepositories[i];
 
+    // Ignore view events since we are cleaning the object
+    maView->setItemStateHdl(Link());
+    maView->setOpenRegionHdl(Link());
+    maView->setOpenTemplateHdl(Link());
+
+    mpOnlineView->setItemStateHdl(Link());
+    mpOnlineView->setOpenRegionHdl(Link());
+    mpOnlineView->setOpenTemplateHdl(Link());
+
+    mpSearchView->setItemStateHdl(Link());
+
     delete mpSearchEdit;
     delete mpViewBar;
     delete mpActionBar;
@@ -245,7 +270,7 @@ void SfxTemplateManagerDlg::setSaveMode(bool bMode)
 {
     mbIsSaveMode = bMode;
     maTabControl.Clear();
-    mpCurView->filterTemplatesByApp(FILTER_APP_NONE);
+    mpCurView->filterItems(ViewFilter_Application(FILTER_APP_NONE));
 
     if (bMode)
     {
@@ -284,22 +309,10 @@ IMPL_LINK_NOARG(SfxTemplateManagerDlg,ActivatePageHdl)
             eFilter = FILTER_APP_DRAW;
             break;
     }
-    mpCurView->filterTemplatesByApp(eFilter);
+    mpCurView->filterItems(ViewFilter_Application(eFilter));
     return 0;
 }
 
-void SfxTemplateManagerDlg::MouseButtonDown( const MouseEvent& rMEvt )
-{
-    if (!maView->GetActiveClipRegion().IsInside(rMEvt.GetPosPixel()) && maView->isOverlayVisible())
-    {
-        maSelTemplates.clear();
-        mpTemplateBar->Hide();
-        mpViewBar->Show();
-
-        maView->showOverlay(false);
-    }
-}
-
 void SfxTemplateManagerDlg::Resize()
 {
     Size aWinSize = GetSizePixel();
@@ -354,21 +367,6 @@ void SfxTemplateManagerDlg::Resize()
     ModelessDialog::Resize();
 }
 
-IMPL_LINK_NOARG(SfxTemplateManagerDlg, CloseOverlayHdl)
-{
-    maSelTemplates.clear();
-    mpTemplateBar->Hide();
-    mpViewBar->Show();
-    mpActionBar->Show();
-
-    if (mpCurView == maView)
-        mpCurView->showOverlay(false);
-    else
-        switchMainView(true);
-
-    return 0;
-}
-
 IMPL_LINK_NOARG(SfxTemplateManagerDlg,TBXViewHdl)
 {
     switch(mpViewBar->GetCurItemId())
@@ -497,79 +495,14 @@ IMPL_LINK(SfxTemplateManagerDlg, TBXDropdownHdl, ToolBox*, pBox)
     return 0;
 }
 
-IMPL_LINK(SfxTemplateManagerDlg, TVFolderStateHdl, const ThumbnailViewItem*, pItem)
-{
-    if (pItem->isSelected())
-    {
-        if (maSelFolders.empty() && !mbIsSaveMode)
-        {
-            mpViewBar->ShowItem(TBI_TEMPLATE_IMPORT);
-            mpViewBar->ShowItem(TBI_TEMPLATE_FOLDER_DEL);
-        }
-
-        maSelFolders.insert(pItem);
-    }
-    else
-    {
-        maSelFolders.erase(pItem);
-
-        if (maSelFolders.empty() && !mbIsSaveMode)
-        {
-            mpViewBar->HideItem(TBI_TEMPLATE_IMPORT);
-            mpViewBar->HideItem(TBI_TEMPLATE_FOLDER_DEL);
-        }
-    }
-
-    return 0;
-}
-
-IMPL_LINK(SfxTemplateManagerDlg, TVTemplateStateHdl, const ThumbnailViewItem*, pItem)
+IMPL_LINK(SfxTemplateManagerDlg, TVItemStateHdl, const ThumbnailViewItem*, pItem)
 {
-    bool bInSelection = maSelTemplates.find(pItem) != maSelTemplates.end();
-    if (pItem->isSelected())
-    {
-        if (!mbIsSaveMode)
-        {
-            if (maSelTemplates.empty())
-            {
-                mpViewBar->Show(false);
-                mpActionBar->Show(false);
-                mpTemplateBar->Show();
-            }
-            else if (maSelTemplates.size() != 1 || !bInSelection)
-            {
-                mpTemplateBar->HideItem(TBI_TEMPLATE_EDIT);
-                mpTemplateBar->HideItem(TBI_TEMPLATE_PROPERTIES);
-                mpTemplateBar->HideItem(TBI_TEMPLATE_DEFAULT);
-            }
-        }
+    const TemplateContainerItem *pCntItem = dynamic_cast<const TemplateContainerItem*>(pItem);
 
-        if (!bInSelection)
-            maSelTemplates.insert(pItem);
-    }
+    if (pCntItem)
+        OnRegionState(pItem);
     else
-    {
-        if (bInSelection)
-        {
-            maSelTemplates.erase(pItem);
-
-            if (!mbIsSaveMode)
-            {
-                if (maSelTemplates.empty())
-                {
-                    mpTemplateBar->Show(false);
-                    mpViewBar->Show();
-                    mpActionBar->Show();
-                }
-                else if (maSelTemplates.size() == 1)
-                {
-                    mpTemplateBar->ShowItem(TBI_TEMPLATE_EDIT);
-                    mpTemplateBar->ShowItem(TBI_TEMPLATE_PROPERTIES);
-                    mpTemplateBar->ShowItem(TBI_TEMPLATE_DEFAULT);
-                }
-            }
-        }
-    }
+        OnTemplateState(pItem);
 
     return 0;
 }
@@ -581,10 +514,7 @@ IMPL_LINK(SfxTemplateManagerDlg, MenuSelectHdl, Menu*, pMenu)
     switch(nMenuId)
     {
     case MNI_ACTION_SORT_NAME:
-        if (maView->isOverlayVisible())
-            maView->sortOverlayItems(SortView_Name());
-        else
-            maView->sortItems(SortView_Name());
+        maView->sortItems(SortView_Name());
         break;
     case MNI_ACTION_REFRESH:
         mpCurView->reload();
@@ -663,10 +593,7 @@ IMPL_LINK(SfxTemplateManagerDlg, RepositoryMenuSelectHdl, Menu*, pMenu)
         }
 
         if (mpOnlineView->loadRepository(pRepository,false))
-        {
             switchMainView(false);
-            mpOnlineView->showOverlay(true);
-        }
     }
 
     return 0;
@@ -684,6 +611,18 @@ IMPL_LINK(SfxTemplateManagerDlg, DefaultTemplateMenuSelectHdl, Menu*, pMenu)
     return 0;
 }
 
+IMPL_LINK_NOARG(SfxTemplateManagerDlg, OpenRegionHdl)
+{
+    maSelFolders.clear();
+    maSelTemplates.clear();
+
+    mpTemplateBar->Hide();
+    mpViewBar->Show();
+    mpActionBar->Show();
+
+    return 0;
+}
+
 IMPL_LINK(SfxTemplateManagerDlg, OpenTemplateHdl, ThumbnailViewItem*, pItem)
 {
     if (!mbIsSaveMode)
@@ -715,7 +654,7 @@ IMPL_LINK(SfxTemplateManagerDlg, OpenTemplateHdl, ThumbnailViewItem*, pItem)
 IMPL_LINK_NOARG(SfxTemplateManagerDlg, SearchUpdateHdl)
 {
     // if the search view is hidden, hide the folder view and display search one
-    if (!mpCurView->isOverlayVisible() && !mpSearchView->IsVisible())
+    if (!mpCurView->isNonRootRegionVisible() && !mpSearchView->IsVisible())
     {
         mpSearchView->Clear();
         mpSearchView->Show();
@@ -726,9 +665,9 @@ IMPL_LINK_NOARG(SfxTemplateManagerDlg, SearchUpdateHdl)
 
     if (!aKeyword.isEmpty())
     {
-        if (mpCurView->isOverlayVisible())
+        if (mpCurView->isNonRootRegionVisible())
         {
-            mpCurView->filterTemplatesByKeyword(aKeyword);
+            mpCurView->filterItems(ViewFilter_Keyword(aKeyword));
         }
         else
         {
@@ -755,9 +694,9 @@ IMPL_LINK_NOARG(SfxTemplateManagerDlg, SearchUpdateHdl)
     }
     else
     {
-        if (mpCurView->isOverlayVisible())
+        if (mpCurView->isNonRootRegionVisible())
         {
-            mpCurView->filterTemplatesByApp(FILTER_APP_NONE);
+            mpCurView->filterItems(ViewFilter_Application(FILTER_APP_NONE));
         }
         else
         {
@@ -769,6 +708,80 @@ IMPL_LINK_NOARG(SfxTemplateManagerDlg, SearchUpdateHdl)
     return 0;
 }
 
+void SfxTemplateManagerDlg::OnRegionState (const ThumbnailViewItem *pItem)
+{
+    if (pItem->isSelected())
+    {
+        if (maSelFolders.empty() && !mbIsSaveMode)
+        {
+            mpViewBar->ShowItem(TBI_TEMPLATE_IMPORT);
+            mpViewBar->ShowItem(TBI_TEMPLATE_FOLDER_DEL);
+        }
+
+        maSelFolders.insert(pItem);
+    }
+    else
+    {
+        maSelFolders.erase(pItem);
+
+        if (maSelFolders.empty() && !mbIsSaveMode)
+        {
+            mpViewBar->HideItem(TBI_TEMPLATE_IMPORT);
+            mpViewBar->HideItem(TBI_TEMPLATE_FOLDER_DEL);
+        }
+    }
+}
+
+void SfxTemplateManagerDlg::OnTemplateState (const ThumbnailViewItem *pItem)
+{
+    bool bInSelection = maSelTemplates.find(pItem) != maSelTemplates.end();
+
+    if (pItem->isSelected())
+    {
+        if (!mbIsSaveMode)
+        {
+            if (maSelTemplates.empty())
+            {
+                mpViewBar->Show(false);
+                mpActionBar->Show(false);
+                mpTemplateBar->Show();
+            }
+            else if (maSelTemplates.size() != 1 || !bInSelection)
+            {
+                mpTemplateBar->HideItem(TBI_TEMPLATE_EDIT);
+                mpTemplateBar->HideItem(TBI_TEMPLATE_PROPERTIES);
+                mpTemplateBar->HideItem(TBI_TEMPLATE_DEFAULT);
+            }
+        }
+
+        if (!bInSelection)
+            maSelTemplates.insert(pItem);
+    }
+    else
+    {
+        if (bInSelection)
+        {
+            maSelTemplates.erase(pItem);
+
+            if (!mbIsSaveMode)
+            {
+                if (maSelTemplates.empty())
+                {
+                    mpTemplateBar->Show(false);
+                    mpViewBar->Show();
+                    mpActionBar->Show();
+                }
+                else if (maSelTemplates.size() == 1)
+                {
+                    mpTemplateBar->ShowItem(TBI_TEMPLATE_EDIT);
+                    mpTemplateBar->ShowItem(TBI_TEMPLATE_PROPERTIES);
+                    mpTemplateBar->ShowItem(TBI_TEMPLATE_DEFAULT);
+                }
+            }
+        }
+    }
+}
+
 void SfxTemplateManagerDlg::OnTemplateImport ()
 {
     sal_Int16 nDialogType =
@@ -909,10 +922,10 @@ void SfxTemplateManagerDlg::OnTemplateExport()
         }
         else
         {
-            // export templates from the current open overlay
+            // export templates from the current view
 
             sal_uInt16 i = 1;
-            sal_uInt16 nRegionItemId = maView->getOverlayRegionId() + 1;
+            sal_uInt16 nRegionItemId = maView->getCurRegionId() + 1;
 
             std::set<const ThumbnailViewItem*>::const_iterator pIter = maSelTemplates.begin();
             for (pIter = maSelTemplates.begin(); pIter != maSelTemplates.end(); ++pIter, ++i)
@@ -937,7 +950,7 @@ void SfxTemplateManagerDlg::OnTemplateExport()
                 }
             }
 
-            maView->deselectOverlayItems();
+            maView->deselectItems();
         }
 
         if (!aTemplateList.isEmpty())
@@ -986,8 +999,8 @@ void SfxTemplateManagerDlg::OnTemplateSearch ()
         mpSearchEdit->GrabFocus();
 
     // display all templates if we hide the search bar
-    if (bVisible && mpCurView->isOverlayVisible())
-        mpCurView->filterTemplatesByApp(FILTER_APP_NONE);
+    if (bVisible && mpCurView->isNonRootRegionVisible())
+        mpCurView->filterItems(ViewFilter_Application(FILTER_APP_NONE));
 }
 
 void SfxTemplateManagerDlg::OnTemplateEdit ()
@@ -1077,7 +1090,7 @@ void SfxTemplateManagerDlg::OnTemplateDelete ()
         std::set<const ThumbnailViewItem*>::const_iterator pIter;
         for (pIter = maSelTemplates.begin(); pIter != maSelTemplates.end();)
         {
-            if (maView->removeTemplate((*pIter)->mnId,maView->getOverlayRegionId()+1))
+            if (maView->removeTemplate((*pIter)->mnId,maView->getCurRegionId()+1))
                 maSelTemplates.erase(pIter++);
             else
             {
@@ -1176,9 +1189,9 @@ void SfxTemplateManagerDlg::OnFolderDelete()
 
 void SfxTemplateManagerDlg::OnRepositoryDelete()
 {
-    if(deleteRepository(mpOnlineView->getOverlayRegionId()))
+    if(deleteRepository(mpOnlineView->getCurRegionId()))
     {
-        // close overlay and switch to local view
+        // switch to local view
         switchMainView(true);
 
         createRepositoryMenu();
@@ -1189,7 +1202,7 @@ void SfxTemplateManagerDlg::OnTemplateSaveAs()
 {
     assert(m_xModel.is());
 
-    if (!maView->isOverlayVisible() && maSelFolders.empty())
+    if (!maView->isNonRootRegionVisible() && maSelFolders.empty())
     {
         ErrorBox(this, WB_OK,SfxResId(STR_MSG_ERROR_SELECT_FOLDER).toString()).Execute();
         return;
@@ -1207,21 +1220,21 @@ void SfxTemplateManagerDlg::OnTemplateSaveAs()
             OUString aQMsg(SfxResId(STR_QMSG_TEMPLATE_OVERWRITE).toString());
             QueryBox aQueryDlg(this,WB_YES_NO | WB_DEF_YES, OUString());
 
-            if (maView->isOverlayVisible())
+            if (maView->isNonRootRegionVisible())
             {
-                sal_uInt16 nRegionItemId = maView->getOverlayRegionId()+1;
+                sal_uInt16 nRegionItemId = maView->getCurRegionId()+1;
 
                 if (!maView->isTemplateNameUnique(nRegionItemId,aName))
                 {
                     aQMsg = aQMsg.replaceFirst("$1",aName);
-                    aQueryDlg.SetMessText(aQMsg.replaceFirst("$2",maView->getOverlayName()));
+                    aQueryDlg.SetMessText(aQMsg.replaceFirst("$2",maView->getCurRegionName()));
 
                     if (aQueryDlg.Execute() == RET_NO)
                         return;
                 }
 
                 if (!maView->saveTemplateAs(nRegionItemId,m_xModel,aName))
-                    aFolderList = maView->getOverlayName();
+                    aFolderList = maView->getCurRegionName();
             }
             else
             {
@@ -1346,7 +1359,7 @@ void SfxTemplateManagerDlg::localMoveTo(sal_uInt16 nMenuId)
     }
     else
     {
-        nItemId = maView->GetItemId(nMenuId-MNI_MOVE_FOLDER_BASE);
+        nItemId = maView->getRegionId(nMenuId-MNI_MOVE_FOLDER_BASE);
     }
 
     if (nItemId)
@@ -1395,7 +1408,7 @@ void SfxTemplateManagerDlg::remoteMoveTo(const sal_uInt16 nMenuId)
     }
     else
     {
-        nItemId = maView->GetItemId(nMenuId-MNI_MOVE_FOLDER_BASE);
+        nItemId = maView->getRegionId(nMenuId-MNI_MOVE_FOLDER_BASE);
     }
 
     if (nItemId)
@@ -1422,7 +1435,7 @@ void SfxTemplateManagerDlg::remoteMoveTo(const sal_uInt16 nMenuId)
         if (!aTemplateList.isEmpty())
         {
             OUString aMsg(SfxResId(STR_MSG_ERROR_REMOTE_MOVE).toString());
-            aMsg = aMsg.replaceFirst("$1",mpOnlineView->getOverlayName());
+            aMsg = aMsg.replaceFirst("$1",mpOnlineView->getCurRegionName());
             aMsg = aMsg.replaceFirst("$2",maView->GetItemText(nItemId));
             ErrorBox(this,WB_OK,aMsg.replaceFirst("$1",aTemplateList)).Execute();
         }
@@ -1449,7 +1462,7 @@ void SfxTemplateManagerDlg::localSearchMoveTo(sal_uInt16 nMenuId)
     }
     else
     {
-        nItemId = maView->GetItemId(nMenuId-MNI_MOVE_FOLDER_BASE);
+        nItemId = maView->getRegionId(nMenuId-MNI_MOVE_FOLDER_BASE);
     }
 
     if (nItemId)
@@ -1575,31 +1588,6 @@ void SfxTemplateManagerDlg::syncRepositories() const
     }
 }
 
-BitmapEx SfxTemplateManagerDlg::getDefaultThumbnail( const OUString& rPath )
-{
-    INetURLObject aUrl(rPath);
-    OUString aExt = aUrl.getExtension();
-
-    BitmapEx aImg;
-    if ( aExt == "ott" || aExt == "stw" || aExt == "oth" || aExt == "dot" || aExt == "dotx" )
-    {
-        aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_TEXT ) );
-    }
-    else if ( aExt == "ots" || aExt == "stc" || aExt == "xlt" || aExt == "xltm" || aExt == "xltx" )
-    {
-        aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_SHEET ) );
-    }
-    else if ( aExt == "otp" || aExt == "sti" || aExt == "pot" || aExt == "potm" || aExt == "potx" )
-    {
-        aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_PRESENTATION ) );
-    }
-    else if ( aExt == "otg" || aExt == "std" )
-    {
-        aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_DRAWING ) );
-    }
-    return aImg;
-}
-
 static bool lcl_getServiceName ( const OUString &rFileURL, OUString &rName )
 {
     bool bRet = false;


More information about the Libreoffice-commits mailing list