diff options
author | Rafael Dominguez <venccsralph@gmail.com> | 2012-08-02 21:11:18 -0430 |
---|---|---|
committer | Rafael Dominguez <venccsralph@gmail.com> | 2012-08-02 22:24:32 -0430 |
commit | 5918b4b1808afdf85682d471024d6ae1f20fd8eb (patch) | |
tree | b4933df88bd7d3215089b0be27558596b4087814 | |
parent | 3fa5a70375083e5f201d6b62f418e9778446e2f5 (diff) |
Filter overlay templates by a search keyword.
Change-Id: I8bcb193d1400c32b6292fd109422d22dbf8b1eb9
-rw-r--r-- | sfx2/inc/sfx2/templateabstractview.hxx | 17 | ||||
-rw-r--r-- | sfx2/source/control/templateabstractview.cxx | 13 | ||||
-rw-r--r-- | sfx2/source/doc/templatedlg.cxx | 52 |
3 files changed, 63 insertions, 19 deletions
diff --git a/sfx2/inc/sfx2/templateabstractview.hxx b/sfx2/inc/sfx2/templateabstractview.hxx index a4b1daf13ce7..1907e5c2142c 100644 --- a/sfx2/inc/sfx2/templateabstractview.hxx +++ b/sfx2/inc/sfx2/templateabstractview.hxx @@ -40,6 +40,21 @@ private: FILTER_APPLICATION mApp; }; +class ViewFilter_Keyword +{ +public: + + ViewFilter_Keyword (const OUString &rKeyword) + : maKeyword(rKeyword) + {} + + bool operator () (const ThumbnailViewItem *pItem); + +private: + + OUString maKeyword; +}; + class SFX2_DLLPUBLIC TemplateAbstractView : public ThumbnailView { public: @@ -65,6 +80,8 @@ public: void sortOverlayItems (const boost::function<bool (const ThumbnailViewItem*, const ThumbnailViewItem*) > &func); + virtual void filterTemplatesByKeyword (const OUString &rKeyword); + void setOverlayItemStateHdl (const Link &aLink) { maOverlayItemStateHdl = aLink; } void setOverlayDblClickHdl (const Link &rLink); diff --git a/sfx2/source/control/templateabstractview.cxx b/sfx2/source/control/templateabstractview.cxx index fbe2378f4298..0554c9d58ba8 100644 --- a/sfx2/source/control/templateabstractview.cxx +++ b/sfx2/source/control/templateabstractview.cxx @@ -49,6 +49,13 @@ bool ViewFilter_Application::operator () (const ThumbnailViewItem *pItem) return true; } +bool ViewFilter_Keyword::operator ()(const ThumbnailViewItem *pItem) +{ + assert(pItem); + + return pItem->maTitle.matchIgnoreAsciiCase(maKeyword); +} + TemplateAbstractView::TemplateAbstractView (Window *pParent, WinBits nWinStyle, bool bDisableTransientChildren) : ThumbnailView(pParent,nWinStyle,bDisableTransientChildren), mpItemView(new TemplateView(this)) @@ -84,6 +91,12 @@ void TemplateAbstractView::sortOverlayItems(const boost::function<bool (const Th mpItemView->sortItems(func); } +void TemplateAbstractView::filterTemplatesByKeyword(const OUString &rKeyword) +{ + if (mpItemView->IsVisible()) + mpItemView->filterItems(ViewFilter_Keyword(rKeyword)); +} + void TemplateAbstractView::setOverlayDblClickHdl(const Link &rLink) { mpItemView->setDblClickHdl(rLink); diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx index d3eff745ded9..9982f5d51556 100644 --- a/sfx2/source/doc/templatedlg.cxx +++ b/sfx2/source/doc/templatedlg.cxx @@ -624,7 +624,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 (!mpSearchView->IsVisible()) + if (!mpCurView->isOverlayVisible() && !mpSearchView->IsVisible()) { mpSearchView->Clear(); mpSearchView->Show(); @@ -635,30 +635,44 @@ IMPL_LINK_NOARG(SfxTemplateManagerDlg, SearchUpdateHdl) if (!aKeyword.isEmpty()) { - mpSearchView->Clear(); - - std::vector<TemplateItemProperties> aItems = - maView->getFilteredItems(SearchView_Keyword(aKeyword)); - - size_t nCounter = 0; - for (size_t i = 0; i < aItems.size(); ++i) + if (mpCurView->isOverlayVisible()) { - TemplateItemProperties *pItem = &aItems[i]; - - mpSearchView->AppendItem(++nCounter,pItem->nRegionId, - pItem->nId-1, - pItem->aName, - maView->GetItemText(pItem->nRegionId+1), - pItem->aPath, - pItem->aThumbnail); + mpCurView->filterTemplatesByKeyword(aKeyword); } + else + { + mpSearchView->Clear(); + + std::vector<TemplateItemProperties> aItems = + maView->getFilteredItems(SearchView_Keyword(aKeyword)); + + size_t nCounter = 0; + for (size_t i = 0; i < aItems.size(); ++i) + { + TemplateItemProperties *pItem = &aItems[i]; + + mpSearchView->AppendItem(++nCounter,pItem->nRegionId, + pItem->nId-1, + pItem->aName, + maView->GetItemText(pItem->nRegionId+1), + pItem->aPath, + pItem->aThumbnail); + } - mpSearchView->Invalidate(); + mpSearchView->Invalidate(); + } } else { - mpSearchView->Hide(); - mpCurView->Show(); + if (mpCurView->isOverlayVisible()) + { + mpCurView->filterTemplatesByApp(FILTER_APP_NONE); + } + else + { + mpSearchView->Hide(); + mpCurView->Show(); + } } return 0; |