diff options
author | akki95 <akshaydeepiitr@gmail.com> | 2016-02-08 09:11:06 +0530 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2016-02-19 09:43:19 +0000 |
commit | bebd483511a0a83532dc37e76e8ba76a67dd921f (patch) | |
tree | 243f7855ed9c89517d4280fc5c44c938f4be9169 /sw/source/ui/fldui | |
parent | 8779459b1a619fc09e60d4c7ee9b86803383f5d0 (diff) |
tdf#32364 - Add a "filter" to Insert > Field > Other > Cross reference tab
-> Modified fldrefpage.ui using Glade to include filter GTK textbox.
-> Added related code in fldref.cxx and fldref.hxx
-> Modified UpdateSubType() code: Added a parameter and code to get the desired result.
Change-Id: I3044c9d38b5f0a984ddcd0f27d075a86abaae7fe
Reviewed-on: https://gerrit.libreoffice.org/22197
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'sw/source/ui/fldui')
-rw-r--r-- | sw/source/ui/fldui/fldref.cxx | 129 | ||||
-rw-r--r-- | sw/source/ui/fldui/fldref.hxx | 8 |
2 files changed, 101 insertions, 36 deletions
diff --git a/sw/source/ui/fldui/fldref.cxx b/sw/source/ui/fldui/fldref.cxx index 3110167c41a0..216f4d738898 100644 --- a/sw/source/ui/fldui/fldref.cxx +++ b/sw/source/ui/fldui/fldref.cxx @@ -32,6 +32,8 @@ #include <IDocumentMarkAccess.hxx> #include <ndtxt.hxx> +#include <comphelper/string.hxx> + #include <svtools/treelistentry.hxx> #define REFFLDFLAG 0x4000 @@ -66,6 +68,7 @@ SwFieldRefPage::SwFieldRefPage(vcl::Window* pParent, const SfxItemSet& rCoreSet get(m_pNameFT, "nameft"); get(m_pNameED, "name"); get(m_pValueED, "value"); + get(m_pFilterED, "filter"); sBookmarkText = m_pTypeLB->GetEntry(0); sFootnoteText = m_pTypeLB->GetEntry(1); @@ -90,6 +93,7 @@ SwFieldRefPage::SwFieldRefPage(vcl::Window* pParent, const SfxItemSet& rCoreSet m_pSelectionToolTipLB->set_width_request(nWidth*2); m_pNameED->SetModifyHdl(LINK(this, SwFieldRefPage, ModifyHdl)); + m_pFilterED->SetModifyHdl( LINK( this, SwFieldRefPage, ModifyHdl_Impl ) ); m_pTypeLB->SetDoubleClickHdl (LINK(this, SwFieldRefPage, ListBoxInsertHdl)); m_pTypeLB->SetSelectHdl (LINK(this, SwFieldRefPage, TypeHdl)); @@ -120,10 +124,17 @@ void SwFieldRefPage::dispose() m_pFormatLB.clear(); m_pNameFT.clear(); m_pNameED.clear(); + m_pFilterED.clear(); m_pValueED.clear(); SwFieldPage::dispose(); } +IMPL_LINK_NOARG_TYPED(SwFieldRefPage, ModifyHdl_Impl, Edit&, void) +{ + OUString sFilter = comphelper::string::strip(m_pFilterED->GetText(), ' '); + UpdateSubType(sFilter); +} + // #i83479# void SwFieldRefPage::SaveSelectedTextNode() { @@ -284,6 +295,7 @@ void SwFieldRefPage::Reset(const SfxItemSet* ) m_pFormatLB->SaveValue(); m_pNameED->SaveValue(); m_pValueED->SaveValue(); + m_pFilterED->SetText(OUString()); } } @@ -381,6 +393,7 @@ IMPL_LINK_NOARG_TYPED(SwFieldRefPage, TypeHdl, ListBox&, void) { m_pNameED->SetText(aEmptyOUStr); m_pValueED->SetText(aEmptyOUStr); + m_pFilterED->SetText(aEmptyOUStr); } switch (nTypeId) @@ -420,6 +433,7 @@ IMPL_LINK_NOARG_TYPED(SwFieldRefPage, TypeHdl, ListBox&, void) SubTypeHdl(); ModifyHdl(*m_pNameED); + ModifyHdl(*m_pFilterED); } } @@ -476,8 +490,8 @@ void SwFieldRefPage::SubTypeHdl() } } -// renew types in SelectionLB -void SwFieldRefPage::UpdateSubType() +// renew types in SelectionLB after filtering +void SwFieldRefPage::UpdateSubType(OUString filterString) { SwWrtShell *pSh = GetWrtShell(); if(!pSh) @@ -518,7 +532,13 @@ void SwFieldRefPage::UpdateSubType() { const ::sw::mark::IMark* pBkmk = ppMark->get(); if(IDocumentMarkAccess::MarkType::BOOKMARK == IDocumentMarkAccess::GetType(*pBkmk)) - m_pSelectionLB->InsertEntry( pBkmk->GetName() ); + { + bool isSubstring = MatchSubstring(pBkmk->GetName(), filterString); + if(isSubstring) + { + m_pSelectionLB->InsertEntry( pBkmk->GetName() ); + } + } } if (IsFieldEdit()) sOldSel = pRefField->GetSetRefName(); @@ -531,7 +551,11 @@ void SwFieldRefPage::UpdateSubType() for( size_t n = 0; n < nCnt; ++n ) { - m_pSelectionLB->InsertEntry( aArr[ n ]->sDlgEntry ); + bool isSubstring = MatchSubstring(aArr[ n ]->sDlgEntry, filterString); + if(isSubstring) + { + m_pSelectionLB->InsertEntry( aArr[ n ]->sDlgEntry ); + } if (IsFieldEdit() && pRefField->GetSeqNo() == aArr[ n ]->nSeqNo) sOldSel = aArr[n]->sDlgEntry; } @@ -544,7 +568,11 @@ void SwFieldRefPage::UpdateSubType() for( size_t n = 0; n < nCnt; ++n ) { - m_pSelectionLB->InsertEntry( aArr[ n ]->sDlgEntry ); + bool isSubstring = MatchSubstring(aArr[ n ]->sDlgEntry, filterString); + if(isSubstring) + { + m_pSelectionLB->InsertEntry( aArr[ n ]->sDlgEntry ); + } if (IsFieldEdit() && pRefField->GetSeqNo() == aArr[ n ]->nSeqNo) sOldSel = aArr[n]->sDlgEntry; } @@ -559,21 +587,26 @@ void SwFieldRefPage::UpdateSubType() bool bCertainTextNodeSelected( false ); for ( size_t nOutlIdx = 0; nOutlIdx < maOutlineNodes.size(); ++nOutlIdx ) { - SvTreeListEntry* pEntry = m_pSelectionToolTipLB->InsertEntry( - pIDoc->getOutlineText( nOutlIdx, true, true, false ) ); - pEntry->SetUserData( reinterpret_cast<void*>(nOutlIdx) ); - if ( ( IsFieldEdit() && - pRefField->GetReferencedTextNode() == maOutlineNodes[nOutlIdx] ) || - mpSavedSelectedTextNode == maOutlineNodes[nOutlIdx] ) + SvTreeListEntry* pEntry = nullptr; + bool isSubstring = MatchSubstring(pIDoc->getOutlineText( nOutlIdx, true, true, false ), filterString); + if(isSubstring) { - m_pSelectionToolTipLB->Select( pEntry ); - sOldSel.clear(); - bCertainTextNodeSelected = true; - } - else if ( !bCertainTextNodeSelected && mnSavedSelectedPos == nOutlIdx ) - { - m_pSelectionToolTipLB->Select( pEntry ); - sOldSel.clear(); + pEntry = m_pSelectionToolTipLB->InsertEntry( + pIDoc->getOutlineText( nOutlIdx, true, true, false ) ); + pEntry->SetUserData( reinterpret_cast<void*>(nOutlIdx) ); + if ( ( IsFieldEdit() && + pRefField->GetReferencedTextNode() == maOutlineNodes[nOutlIdx] ) || + mpSavedSelectedTextNode == maOutlineNodes[nOutlIdx] ) + { + m_pSelectionToolTipLB->Select( pEntry ); + sOldSel.clear(); + bCertainTextNodeSelected = true; + } + else if ( !bCertainTextNodeSelected && mnSavedSelectedPos == nOutlIdx ) + { + m_pSelectionToolTipLB->Select( pEntry ); + sOldSel.clear(); + } } } } @@ -586,21 +619,26 @@ void SwFieldRefPage::UpdateSubType() bool bCertainTextNodeSelected( false ); for ( size_t nNumItemIdx = 0; nNumItemIdx < maNumItems.size(); ++nNumItemIdx ) { - SvTreeListEntry* pEntry = m_pSelectionToolTipLB->InsertEntry( - pIDoc->getListItemText( *maNumItems[nNumItemIdx], true, true ) ); - pEntry->SetUserData( reinterpret_cast<void*>(nNumItemIdx) ); - if ( ( IsFieldEdit() && - pRefField->GetReferencedTextNode() == maNumItems[nNumItemIdx]->GetTextNode() ) || - mpSavedSelectedTextNode == maNumItems[nNumItemIdx]->GetTextNode() ) - { - m_pSelectionToolTipLB->Select( pEntry ); - sOldSel.clear(); - bCertainTextNodeSelected = true; - } - else if ( !bCertainTextNodeSelected && mnSavedSelectedPos == nNumItemIdx ) + SvTreeListEntry* pEntry = nullptr; + bool isSubstring = MatchSubstring(pIDoc->getListItemText( *maNumItems[nNumItemIdx], true, true ), filterString); + if(isSubstring) { - m_pSelectionToolTipLB->Select( pEntry ); - sOldSel.clear(); + pEntry = m_pSelectionToolTipLB->InsertEntry( + pIDoc->getListItemText( *maNumItems[nNumItemIdx], true, true ) ); + pEntry->SetUserData( reinterpret_cast<void*>(nNumItemIdx) ); + if ( ( IsFieldEdit() && + pRefField->GetReferencedTextNode() == maNumItems[nNumItemIdx]->GetTextNode() ) || + mpSavedSelectedTextNode == maNumItems[nNumItemIdx]->GetTextNode() ) + { + m_pSelectionToolTipLB->Select( pEntry ); + sOldSel.clear(); + bCertainTextNodeSelected = true; + } + else if ( !bCertainTextNodeSelected && mnSavedSelectedPos == nNumItemIdx ) + { + m_pSelectionToolTipLB->Select( pEntry ); + sOldSel.clear(); + } } } } @@ -621,7 +659,11 @@ void SwFieldRefPage::UpdateSubType() const size_t nCnt = pType->GetSeqFieldList( aArr ); for( size_t n = 0; n < nCnt; ++n ) { - m_pSelectionLB->InsertEntry( aArr[ n ]->sDlgEntry ); + bool isSubstring = MatchSubstring(aArr[ n ]->sDlgEntry, filterString); + if(isSubstring) + { + m_pSelectionLB->InsertEntry( aArr[ n ]->sDlgEntry ); + } if (IsFieldEdit() && sOldSel.isEmpty() && aArr[ n ]->nSeqNo == pRefField->GetSeqNo()) sOldSel = aArr[ n ]->sDlgEntry; @@ -637,7 +679,13 @@ void SwFieldRefPage::UpdateSubType() std::vector<OUString> aLst; GetFieldMgr().GetSubTypes(nTypeId, aLst); for(size_t i = 0; i < aLst.size(); ++i) - m_pSelectionLB->InsertEntry(aLst[i]); + { + bool isSubstring = MatchSubstring( aLst[i] , filterString ); + if(isSubstring) + { + m_pSelectionLB->InsertEntry(aLst[i]); + } + } if (IsFieldEdit()) sOldSel = pRefField->GetSetRefName(); @@ -683,6 +731,17 @@ void SwFieldRefPage::UpdateSubType() } } +bool SwFieldRefPage::MatchSubstring( OUString list_string, OUString substr ) +{ + if(substr.isEmpty()) + return true; + list_string = list_string.toAsciiLowerCase(); + substr = substr.toAsciiLowerCase(); + if(list_string.indexOf(substr) >= 0) + return true; + return false; +} + sal_Int32 SwFieldRefPage::FillFormatLB(sal_uInt16 nTypeId) { OUString sOldSel; diff --git a/sw/source/ui/fldui/fldref.hxx b/sw/source/ui/fldui/fldref.hxx index f06f114d6585..51a6cc5d48b5 100644 --- a/sw/source/ui/fldui/fldref.hxx +++ b/sw/source/ui/fldui/fldref.hxx @@ -44,6 +44,7 @@ class SwFieldRefPage : public SwFieldPage VclPtr<FixedText> m_pNameFT; VclPtr<Edit> m_pNameED; VclPtr<Edit> m_pValueED; + VclPtr<Edit> m_pFilterED; OUString sBookmarkText; OUString sFootnoteText; OUString sEndnoteText; @@ -64,9 +65,14 @@ class SwFieldRefPage : public SwFieldPage DECL_LINK_TYPED(SubTypeListBoxHdl, ListBox&, void); DECL_LINK_TYPED(SubTypeTreeListBoxHdl, SvTreeListBox*, void); DECL_LINK_TYPED(ModifyHdl, Edit&, void); + DECL_LINK_TYPED(ModifyHdl_Impl, Edit&, void); + void SubTypeHdl(); - void UpdateSubType(); + void UpdateSubType(OUString filterString = OUString()); + + bool MatchSubstring( OUString list_string, OUString substr ); + sal_Int32 FillFormatLB(sal_uInt16 nTypeId); // #i83479# |