diff options
author | Muhammet Kara <muhammet.kara@pardus.org.tr> | 2017-06-13 11:44:22 +0300 |
---|---|---|
committer | Muhammet Kara <muhammet.kara@pardus.org.tr> | 2017-06-28 18:52:43 +0200 |
commit | 1ec4082d7adb1cbce0b4eed3c45fe2fcba258333 (patch) | |
tree | f79a8a9c54d27364db5e9739b4b0c6356c927926 /cui/source/customize | |
parent | make it possible for calc tests to use ScDocument without BootstrapFixture (diff) | |
download | core-1ec4082d7adb1cbce0b4eed3c45fe2fcba258333.tar.gz core-1ec4082d7adb1cbce0b4eed3c45fe2fcba258333.zip |
Implement search feature in the Kayboard tab
of the Customize dialog.
Once you type a search term in the box, non-matching functions
are filtered out in the current category. The filter operation
takes place, and updates as you type.
If user changes category while there is still a search term
in the box, the filter is also applied to the newly selected
category.
Change-Id: I5ef086af60e0f339af6a113fa6a52555d4f765d9
Reviewed-on: https://gerrit.libreoffice.org/38814
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de>
(cherry picked from commit 3667beb986e8c03c925566a585b0504c7943fede)
Reviewed-on: https://gerrit.libreoffice.org/39356
Reviewed-by: Muhammet Kara <muhammet.kara@pardus.org.tr>
Diffstat (limited to 'cui/source/customize')
-rw-r--r-- | cui/source/customize/acccfg.cxx | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/cui/source/customize/acccfg.cxx b/cui/source/customize/acccfg.cxx index 23bb736d3319..ce1c0d552004 100644 --- a/cui/source/customize/acccfg.cxx +++ b/cui/source/customize/acccfg.cxx @@ -58,6 +58,11 @@ #include <com/sun/star/ui/XUIConfigurationManager.hpp> #include <com/sun/star/ui/dialogs/TemplateDescription.hpp> +// include search util +#include <com/sun/star/util/SearchFlags.hpp> +#include <com/sun/star/util/SearchAlgorithms2.hpp> +#include <unotools/textsearch.hxx> + // include other projects #include <comphelper/processfactory.hxx> #include <svtools/acceleratorexecute.hxx> @@ -753,6 +758,7 @@ SfxAcceleratorConfigPage::SfxAcceleratorConfigPage( vcl::Window* pParent, const aSize = LogicToPixel(Size(80, 91), MapUnit::MapAppFont); m_pKeyBox->set_width_request(aSize.Width()); m_pKeyBox->set_height_request(aSize.Height()); + get(m_pSearchEdit, "searchEntry"); aFilterAllStr = SfxResId( STR_SFX_FILTERNAME_ALL ); @@ -769,6 +775,9 @@ SfxAcceleratorConfigPage::SfxAcceleratorConfigPage( vcl::Window* pParent, const m_pOfficeButton->SetClickHdl( LINK( this, SfxAcceleratorConfigPage, RadioHdl )); m_pModuleButton->SetClickHdl( LINK( this, SfxAcceleratorConfigPage, RadioHdl )); + m_pSearchEdit->SetUpdateDataHdl ( LINK( this, SfxAcceleratorConfigPage, SearchUpdateHdl )); + m_pSearchEdit->EnableUpdateData(); + // initialize Entriesbox m_pEntriesBox->SetStyle(m_pEntriesBox->GetStyle()|WB_HSCROLL|WB_CLIPCHILDREN); m_pEntriesBox->SetSelectionMode(SelectionMode::Single); @@ -790,6 +799,11 @@ SfxAcceleratorConfigPage::SfxAcceleratorConfigPage( vcl::Window* pParent, const nNewTab = nNewTab + 5; // additional space m_pEntriesBox->SetTab( 1, nNewTab ); + //Initialize search util + m_options.AlgorithmType2 = util::SearchAlgorithms2::ABSOLUTE; + m_options.transliterateFlags |= TransliterationFlags::IGNORE_CASE; + m_options.searchFlag |= (util::SearchFlags::REG_NOT_BEGINOFLINE | + util::SearchFlags::REG_NOT_ENDOFLINE); // initialize GroupBox m_pGroupLBox->SetFunctionListBox(m_pFunctionBox); @@ -835,6 +849,7 @@ void SfxAcceleratorConfigPage::dispose() m_pGroupLBox.clear(); m_pFunctionBox.clear(); m_pKeyBox.clear(); + m_pSearchEdit.clear(); m_pLoadButton.clear(); m_pSaveButton.clear(); m_pResetButton.clear(); @@ -1031,6 +1046,11 @@ void SfxAcceleratorConfigPage::ResetConfig() m_pEntriesBox->Clear(); } +IMPL_LINK_NOARG(SfxAcceleratorConfigPage, SearchUpdateHdl, Edit&, void) +{ + m_pGroupLBox->GetSelectHdl().Call( m_pGroupLBox ); +} + IMPL_LINK_NOARG(SfxAcceleratorConfigPage, Load, Button*, void) { // ask for filename, where we should load the new config data from @@ -1109,6 +1129,19 @@ IMPL_LINK( SfxAcceleratorConfigPage, SelectHdl, SvTreeListBox*, pListBox, void ) else if ( pListBox == m_pGroupLBox ) { m_pGroupLBox->GroupSelected(); + + // Pause redraw (Do not redraw at each removal) + m_pFunctionBox->SetUpdateMode(false); + // Apply the search filter to the functions list + OUString aSearchTerm( m_pSearchEdit->GetText() ); + SvTreeListEntry* aMatchFound = applySearchFilter(aSearchTerm, m_pFunctionBox); + // Resume redraw + m_pFunctionBox->SetUpdateMode(true); + if (aMatchFound) + m_pFunctionBox->Select(aMatchFound); + else + m_pKeyBox->Clear(); + if ( !m_pFunctionBox->FirstSelected() ) m_pChangeButton->Enable( false ); } @@ -1486,4 +1519,42 @@ OUString SfxAcceleratorConfigPage::GetLabel4Command(const OUString& sCommand) return sCommand; } +/* + * Remove entries which doesn't contain the search term + */ +SvTreeListEntry* SfxAcceleratorConfigPage::applySearchFilter(OUString& rSearchTerm, SvTreeListBox* rListBox) +{ + if ( rSearchTerm.isEmpty() || !rListBox ) + { + return nullptr; + } + + SvTreeListEntry* pFirstMatch = nullptr; + SvTreeListEntry* pEntry = rListBox->First(); + + m_options.searchString = rSearchTerm; + utl::TextSearch textSearch( m_options ); + + while(pEntry) + { + OUString aStr = rListBox->GetEntryText(pEntry); + SvTreeListEntry* pNextEntry = rListBox->Next(pEntry); + sal_Int32 aStartPos = 0; + sal_Int32 aEndPos = aStr.getLength(); + + if (!textSearch.SearchForward( aStr, &aStartPos, &aEndPos )) + { + rListBox->GetModel()->Remove(pEntry); + } + else if (!pFirstMatch) + { + pFirstMatch = pEntry; + } + + pEntry = pNextEntry; + } + + return pFirstMatch; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |