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 | |
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>
-rw-r--r-- | sw/source/ui/fldui/fldref.cxx | 129 | ||||
-rw-r--r-- | sw/source/ui/fldui/fldref.hxx | 8 | ||||
-rw-r--r-- | sw/uiconfig/swriter/ui/fldrefpage.ui | 167 |
3 files changed, 207 insertions, 97 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# diff --git a/sw/uiconfig/swriter/ui/fldrefpage.ui b/sw/uiconfig/swriter/ui/fldrefpage.ui index 347555abacb2..618eecb0127b 100644 --- a/sw/uiconfig/swriter/ui/fldrefpage.ui +++ b/sw/uiconfig/swriter/ui/fldrefpage.ui @@ -1,7 +1,31 @@ <?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.18.3 --> <interface> - <!-- interface-requires gtk+ 3.0 --> - <!-- interface-requires LibreOffice 1.0 --> + <requires lib="gtk+" version="3.0"/> + <requires lib="LibreOffice" version="1.0"/> + <object class="GtkListStore" id="liststore1"> + <columns> + <!-- column-name gchararray1 --> + <column type="gchararray"/> + </columns> + <data> + <row> + <col id="0" translatable="yes">Bookmarks</col> + </row> + <row> + <col id="0" translatable="yes">Footnotes</col> + </row> + <row> + <col id="0" translatable="yes">Endnotes</col> + </row> + <row> + <col id="0" translatable="yes">Headings</col> + </row> + <row> + <col id="0" translatable="yes">Numbered Paragraphs</col> + </row> + </data> + </object> <object class="GtkBox" id="FieldRefPage"> <property name="visible">True</property> <property name="can_focus">False</property> @@ -117,8 +141,6 @@ <packing> <property name="left_attach">0</property> <property name="top_attach">0</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> @@ -127,7 +149,63 @@ <property name="can_focus">False</property> <property name="vexpand">True</property> <property name="orientation">vertical</property> - <property name="spacing">12</property> + <property name="spacing">6</property> + <child> + <object class="GtkGrid" id="grid3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="row_spacing">6</property> + <child> + <object class="GtkBox" id="box3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="margin_left">5</property> + <property name="margin_right">5</property> + <child> + <object class="GtkLabel" id="label4"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="margin_right">5</property> + <property name="label" translatable="yes">Selection</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <placeholder/> + </child> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + </packing> + </child> + <child> + <object class="GtkEntry" id="filter"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="hexpand">True</property> + <property name="shadow_type">out</property> + <property name="placeholder_text" translatable="yes">Filter Selection</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> <child> <object class="GtkFrame" id="selectframe"> <property name="visible">True</property> @@ -136,7 +214,7 @@ <property name="vexpand">True</property> <property name="label_xalign">0</property> <property name="shadow_type">none</property> - <child> + <child type="label"> <object class="GtkAlignment" id="alignment2"> <property name="visible">True</property> <property name="can_focus">False</property> @@ -185,7 +263,7 @@ </child> <child type="label"> <object class="GtkLabel" id="label2"> - <property name="visible">True</property> + <property name="visible">False</property> <property name="can_focus">False</property> <property name="xalign">0</property> <property name="label" translatable="yes">S_election</property> @@ -199,32 +277,17 @@ <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="position">0</property> + <property name="position">1</property> </packing> </child> <child> <object class="GtkGrid" id="grid1"> <property name="visible">True</property> <property name="can_focus">False</property> + <property name="margin_top">6</property> <property name="row_spacing">6</property> <property name="column_spacing">12</property> <child> - <object class="GtkLabel" id="nameft"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">Na_me</property> - <property name="use_underline">True</property> - <property name="mnemonic_widget">name</property> - </object> - <packing> - <property name="left_attach">0</property> - <property name="top_attach">0</property> - <property name="width">1</property> - <property name="height">1</property> - </packing> - </child> - <child> <object class="GtkLabel" id="valueft"> <property name="visible">True</property> <property name="sensitive">False</property> @@ -237,46 +300,52 @@ <packing> <property name="left_attach">0</property> <property name="top_attach">1</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> - <object class="GtkEntry" id="name"> + <object class="GtkEntry" id="value"> <property name="visible">True</property> + <property name="sensitive">False</property> <property name="can_focus">True</property> <property name="hexpand">True</property> <property name="invisible_char">•</property> - <property name="invisible_char_set">True</property> </object> <packing> <property name="left_attach">1</property> + <property name="top_attach">1</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="nameft"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Na_me</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">name</property> + </object> + <packing> + <property name="left_attach">0</property> <property name="top_attach">0</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> - <object class="GtkEntry" id="value"> + <object class="GtkEntry" id="name"> <property name="visible">True</property> - <property name="sensitive">False</property> <property name="can_focus">True</property> <property name="hexpand">True</property> <property name="invisible_char">•</property> - <property name="invisible_char_set">True</property> </object> <packing> <property name="left_attach">1</property> - <property name="top_attach">1</property> - <property name="width">1</property> - <property name="height">1</property> + <property name="top_attach">0</property> </packing> </child> </object> <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="position">1</property> + <property name="position">2</property> </packing> </child> </object> @@ -284,7 +353,6 @@ <property name="left_attach">1</property> <property name="top_attach">0</property> <property name="width">2</property> - <property name="height">1</property> </packing> </child> </object> @@ -295,29 +363,6 @@ </packing> </child> </object> - <object class="GtkListStore" id="liststore1"> - <columns> - <!-- column-name gchararray1 --> - <column type="gchararray"/> - </columns> - <data> - <row> - <col id="0" translatable="yes">Bookmarks</col> - </row> - <row> - <col id="0" translatable="yes">Footnotes</col> - </row> - <row> - <col id="0" translatable="yes">Endnotes</col> - </row> - <row> - <col id="0" translatable="yes">Headings</col> - </row> - <row> - <col id="0" translatable="yes">Numbered Paragraphs</col> - </row> - </data> - </object> <object class="GtkSizeGroup" id="sizegroup1"> <property name="mode">both</property> <property name="ignore_hidden">True</property> |