summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorCédric Bosdonnat <cedric.bosdonnat@free.fr>2012-12-18 10:18:03 +0100
committerCédric Bosdonnat <cedric.bosdonnat@free.fr>2012-12-20 18:02:52 +0100
commit63b96d45415293ff1fe83d721c8d3ae6abc2e448 (patch)
tree3280da8204d577f14608719c4cd5ad6498611c01 /sfx2
parentfd1ae388b5171955a82f63b65b03a1c0105ade70 (diff)
Template Manager: one filtering code to rule them all
Change-Id: Ice3523a98b575b3dfd39ca6edf5fbacc1f229480
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/inc/sfx2/templateabstractview.hxx5
-rw-r--r--sfx2/inc/sfx2/templatelocalview.hxx4
-rw-r--r--sfx2/inc/sfx2/templateremoteview.hxx2
-rw-r--r--sfx2/source/control/templateabstractview.cxx63
-rw-r--r--sfx2/source/control/templatelocalview.cxx69
-rw-r--r--sfx2/source/control/templateremoteview.cxx6
6 files changed, 64 insertions, 85 deletions
diff --git a/sfx2/inc/sfx2/templateabstractview.hxx b/sfx2/inc/sfx2/templateabstractview.hxx
index a0cb1e070146..ca5118109a0d 100644
--- a/sfx2/inc/sfx2/templateabstractview.hxx
+++ b/sfx2/inc/sfx2/templateabstractview.hxx
@@ -85,7 +85,7 @@ public:
virtual void reload () { };
- virtual void filterTemplatesByApp (const FILTER_APPLICATION &eApp) = 0;
+ virtual void filterTemplatesByApp (const FILTER_APPLICATION &eApp);
virtual void showOverlay (bool bVisible) = 0;
@@ -131,6 +131,9 @@ protected:
TemplateView *mpItemView;
Link maOverlayItemStateHdl;
+
+ bool mbFilteredResults; // Flag keep track if overlay has been filtered so folders can get filtered too afterwards
+ FILTER_APPLICATION meFilterOption;
};
#endif // __SFX2_TEMPLATEABSTRACTVIEW_HXX__
diff --git a/sfx2/inc/sfx2/templatelocalview.hxx b/sfx2/inc/sfx2/templatelocalview.hxx
index c5a1f848c875..e11c42bdf24b 100644
--- a/sfx2/inc/sfx2/templatelocalview.hxx
+++ b/sfx2/inc/sfx2/templatelocalview.hxx
@@ -41,8 +41,6 @@ public:
virtual void showOverlay (bool bVisible);
- virtual void filterTemplatesByApp (const FILTER_APPLICATION &eApp);
-
std::vector<TemplateItemProperties>
getFilteredItems (const boost::function<bool (const TemplateItemProperties&) > &rFunc) const;
@@ -79,8 +77,6 @@ private:
private:
- bool mbFilteredResults; // Flag keep track if overlay has been filtered so folders can get filtered too afterwards
- FILTER_APPLICATION meFilterOption;
SfxDocumentTemplates *mpDocTemplates;
};
diff --git a/sfx2/inc/sfx2/templateremoteview.hxx b/sfx2/inc/sfx2/templateremoteview.hxx
index ad9546392172..bd1bf5cad34a 100644
--- a/sfx2/inc/sfx2/templateremoteview.hxx
+++ b/sfx2/inc/sfx2/templateremoteview.hxx
@@ -25,8 +25,6 @@ public:
virtual ~TemplateRemoteView ();
- virtual void filterTemplatesByApp (const FILTER_APPLICATION &eApp);
-
virtual void showOverlay (bool bVisible);
bool loadRepository (TemplateRepository* pRepository, bool bRefresh);
diff --git a/sfx2/source/control/templateabstractview.cxx b/sfx2/source/control/templateabstractview.cxx
index 2caeba348d12..6db997b0a79e 100644
--- a/sfx2/source/control/templateabstractview.cxx
+++ b/sfx2/source/control/templateabstractview.cxx
@@ -8,6 +8,7 @@
*/
#include <sfx2/templateabstractview.hxx>
+#include <sfx2/templatecontaineritem.hxx>
#include <comphelper/processfactory.hxx>
#include <sfx2/templateview.hxx>
@@ -51,9 +52,44 @@ bool ViewFilter_Application::isValid (const OUString &rPath) const
bool ViewFilter_Application::operator () (const ThumbnailViewItem *pItem)
{
- const TemplateViewItem *pTempItem = static_cast<const TemplateViewItem*>(pItem);
+ const TemplateViewItem *pTempItem = dynamic_cast<const TemplateViewItem*>(pItem);
+ if (pTempItem)
+ return isValid(pTempItem->getPath());
- return isValid(pTempItem->getPath());
+ TemplateContainerItem *pContainerItem = const_cast<TemplateContainerItem*>(dynamic_cast<const TemplateContainerItem*>(pItem));
+ if (pContainerItem)
+ {
+ std::vector<TemplateItemProperties> &rTemplates = pContainerItem->maTemplates;
+
+ size_t nVisCount = 0;
+
+ // Clear thumbnails
+ pContainerItem->maPreview1.Clear();
+ pContainerItem->maPreview2.Clear();
+
+ for (size_t i = 0, n = rTemplates.size(); i < n; ++i)
+ {
+ if (isValid(rTemplates[i].aPath))
+ {
+ ++nVisCount;
+ if ( pContainerItem->maPreview1.IsEmpty( ) )
+ {
+ pContainerItem->maPreview1 = TemplateAbstractView::scaleImg(rTemplates[i].aThumbnail,
+ TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
+ TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
+ }
+ else if ( pContainerItem->maPreview2.IsEmpty() )
+ {
+ pContainerItem->maPreview2 = TemplateAbstractView::scaleImg(rTemplates[i].aThumbnail,
+ TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
+ TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
+ }
+ }
+ }
+
+ return mApp != FILTER_APP_NONE ? nVisCount : true ;
+ }
+ return true;
}
bool ViewFilter_Keyword::operator ()(const ThumbnailViewItem *pItem)
@@ -65,14 +101,18 @@ bool ViewFilter_Keyword::operator ()(const ThumbnailViewItem *pItem)
TemplateAbstractView::TemplateAbstractView (Window *pParent, WinBits nWinStyle, bool bDisableTransientChildren)
: ThumbnailView(pParent,nWinStyle,bDisableTransientChildren),
- mpItemView(new TemplateView(this))
+ mpItemView(new TemplateView(this)),
+ mbFilteredResults(false),
+ meFilterOption(FILTER_APP_NONE)
{
mpItemView->setItemStateHdl(LINK(this,TemplateAbstractView,OverlayItemStateHdl));
}
TemplateAbstractView::TemplateAbstractView(Window *pParent, const ResId &rResId, bool bDisableTransientChildren)
: ThumbnailView(pParent,rResId,bDisableTransientChildren),
- mpItemView(new TemplateView(this))
+ mpItemView(new TemplateView(this)),
+ mbFilteredResults(false),
+ meFilterOption(FILTER_APP_NONE)
{
mpItemView->setItemStateHdl(LINK(this,TemplateAbstractView,OverlayItemStateHdl));
}
@@ -120,6 +160,21 @@ void TemplateAbstractView::sortOverlayItems(const boost::function<bool (const Th
mpItemView->sortItems(func);
}
+void TemplateAbstractView::filterTemplatesByApp (const FILTER_APPLICATION &eApp)
+{
+ meFilterOption = eApp;
+
+ if (mpItemView->IsVisible())
+ {
+ mbFilteredResults = true;
+ mpItemView->filterItems(ViewFilter_Application(eApp));
+ }
+ else
+ {
+ filterItems(ViewFilter_Application(eApp));
+ }
+}
+
void TemplateAbstractView::filterTemplatesByKeyword(const OUString &rKeyword)
{
if (mpItemView->IsVisible())
diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx
index 241020a1fdba..16dcc88a0498 100644
--- a/sfx2/source/control/templatelocalview.cxx
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -32,60 +32,8 @@ using namespace ::com::sun::star::frame;
static void lcl_updateThumbnails (TemplateContainerItem *pItem);
-class FolderFilter_Application : public ViewFilter_Application
-{
-public:
-
- FolderFilter_Application (FILTER_APPLICATION eApp)
- : ViewFilter_Application(eApp)
- {
- }
-
- bool operator () (const ThumbnailViewItem *pItem)
- {
- TemplateContainerItem *pFolderItem = (TemplateContainerItem*)pItem;
-
- std::vector<TemplateItemProperties> &rTemplates = pFolderItem->maTemplates;
-
- size_t nVisCount = 0;
-
- // Clear thumbnails
- pFolderItem->maPreview1.Clear();
- pFolderItem->maPreview2.Clear();
-
- for (size_t i = 0, n = rTemplates.size(); i < n; ++i)
- {
- if (isValid(rTemplates[i].aPath))
- {
- ++nVisCount;
- if ( pFolderItem->maPreview1.IsEmpty( ) )
- {
- pFolderItem->maPreview1 = TemplateAbstractView::scaleImg(rTemplates[i].aThumbnail,
- TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
- TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
- }
- else if ( pFolderItem->maPreview2.IsEmpty() )
- {
- pFolderItem->maPreview2 = TemplateAbstractView::scaleImg(rTemplates[i].aThumbnail,
- TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
- TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
- }
- }
- }
-
- return meApp != FILTER_APP_NONE ? nVisCount : true ;
- }
-
-
-private:
-
- FILTER_APPLICATION meApp;
-};
-
TemplateLocalView::TemplateLocalView ( Window* pParent, const ResId& rResId, bool bDisableTransientChildren)
: TemplateAbstractView(pParent,rResId,bDisableTransientChildren),
- mbFilteredResults(false),
- meFilterOption(FILTER_APP_NONE),
mpDocTemplates(new SfxDocumentTemplates)
{
mpItemView->SetColor(GetSettings().GetStyleSettings().GetFieldColor());
@@ -196,7 +144,7 @@ void TemplateLocalView::showOverlay (bool bVisible)
// Check if the folder view needs to be filtered
if (mbFilteredResults)
{
- filterItems(FolderFilter_Application(meFilterOption));
+ filterItems(ViewFilter_Application(meFilterOption));
mbFilteredResults = false;
meFilterOption = FILTER_APP_NONE;
@@ -206,21 +154,6 @@ void TemplateLocalView::showOverlay (bool bVisible)
}
}
-void TemplateLocalView::filterTemplatesByApp (const FILTER_APPLICATION &eApp)
-{
- meFilterOption = eApp;
-
- if (mpItemView->IsVisible())
- {
- mbFilteredResults = true;
- mpItemView->filterItems(ViewFilter_Application(eApp));
- }
- else
- {
- filterItems(FolderFilter_Application(eApp));
- }
-}
-
std::vector<TemplateItemProperties>
TemplateLocalView::getFilteredItems(const boost::function<bool (const TemplateItemProperties&) > &rFunc) const
{
diff --git a/sfx2/source/control/templateremoteview.cxx b/sfx2/source/control/templateremoteview.cxx
index ac00a0a811df..9f840533d855 100644
--- a/sfx2/source/control/templateremoteview.cxx
+++ b/sfx2/source/control/templateremoteview.cxx
@@ -60,12 +60,6 @@ TemplateRemoteView::~TemplateRemoteView ()
{
}
-void TemplateRemoteView::filterTemplatesByApp(const FILTER_APPLICATION &eApp)
-{
- if (mpItemView->IsVisible())
- mpItemView->filterItems(ViewFilter_Application(eApp));
-}
-
void TemplateRemoteView::showOverlay (bool bVisible)
{
mpItemView->Show(bVisible);