Skip to content

Commit

Permalink
Implement search feature in the Kayboard tab
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mrkara authored and Katarina Behrens committed Jun 19, 2017
1 parent 379196b commit 3667beb
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 127 deletions.
71 changes: 71 additions & 0 deletions cui/source/customize/acccfg.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -755,6 +760,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 );

Expand All @@ -771,6 +777,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);
Expand All @@ -792,6 +801,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);

Expand Down Expand Up @@ -837,6 +851,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();
Expand Down Expand Up @@ -1037,6 +1052,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
Expand Down Expand Up @@ -1115,6 +1135,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 );
}
Expand Down Expand Up @@ -1502,4 +1535,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: */
69 changes: 38 additions & 31 deletions cui/source/inc/acccfg.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <svtools/treelistbox.hxx>
#include <sfx2/tabdlg.hxx>
#include <sfx2/basedlgs.hxx>
#include <i18nutil/searchopt.hxx>
#include "cfgutil.hxx"

class SfxMacroInfoItem;
Expand Down Expand Up @@ -111,47 +112,53 @@ private:
const SfxStringItem* m_pFontItem;
sfx2::FileDialogHelper* m_pFileDlg;

VclPtr<SfxAccCfgTabListBox_Impl> m_pEntriesBox;
VclPtr<RadioButton> m_pOfficeButton;
VclPtr<RadioButton> m_pModuleButton;
VclPtr<PushButton> m_pChangeButton;
VclPtr<PushButton> m_pRemoveButton;
VclPtr<SfxConfigGroupListBox> m_pGroupLBox;
VclPtr<SfxConfigFunctionListBox> m_pFunctionBox;
VclPtr<SvTreeListBox> m_pKeyBox;
VclPtr<PushButton> m_pLoadButton;
VclPtr<PushButton> m_pSaveButton;
VclPtr<PushButton> m_pResetButton;
OUString aLoadAccelConfigStr;
OUString aSaveAccelConfigStr;
OUString aFilterAllStr;
OUString aFilterCfgStr;
SfxStylesInfo_Impl m_aStylesInfo;
bool m_bStylesInfoInitialized;

css::uno::Reference< css::uno::XComponentContext > m_xContext;
css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xGlobal;
css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xModule;
css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xAct;
css::uno::Reference< css::container::XNameAccess > m_xUICmdDescription;
css::uno::Reference< css::frame::XFrame > m_xFrame;
VclPtr<SfxAccCfgTabListBox_Impl> m_pEntriesBox;
VclPtr<RadioButton> m_pOfficeButton;
VclPtr<RadioButton> m_pModuleButton;
VclPtr<PushButton> m_pChangeButton;
VclPtr<PushButton> m_pRemoveButton;
VclPtr<SfxConfigGroupListBox> m_pGroupLBox;
VclPtr<SfxConfigFunctionListBox> m_pFunctionBox;
VclPtr<SvTreeListBox> m_pKeyBox;
VclPtr<Edit> m_pSearchEdit;
VclPtr<PushButton> m_pLoadButton;
VclPtr<PushButton> m_pSaveButton;
VclPtr<PushButton> m_pResetButton;
OUString aLoadAccelConfigStr;
OUString aSaveAccelConfigStr;
OUString aFilterAllStr;
OUString aFilterCfgStr;
SfxStylesInfo_Impl m_aStylesInfo;
bool m_bStylesInfoInitialized;

css::uno::Reference< css::uno::XComponentContext > m_xContext;
css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xGlobal;
css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xModule;
css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xAct;
css::uno::Reference< css::container::XNameAccess > m_xUICmdDescription;
css::uno::Reference< css::frame::XFrame > m_xFrame;

OUString m_sModuleLongName;
OUString m_sModuleShortName;
OUString m_sModuleUIName;

DECL_LINK(ChangeHdl, Button *, void);
DECL_LINK(RemoveHdl, Button *, void);
DECL_LINK(SelectHdl, SvTreeListBox*, void );
DECL_LINK(Save, Button *, void);
DECL_LINK(Load, Button *, void);
DECL_LINK(Default, Button *, void);
DECL_LINK(RadioHdl, Button *, void);
// For search
i18nutil::SearchOptions2 m_options;

DECL_LINK(ChangeHdl, Button *, void);
DECL_LINK(RemoveHdl, Button *, void);
DECL_LINK(SelectHdl, SvTreeListBox*, void);
DECL_LINK(SearchUpdateHdl, Edit&, void);
DECL_LINK(Save, Button *, void);
DECL_LINK(Load, Button *, void);
DECL_LINK(Default, Button *, void);
DECL_LINK(RadioHdl, Button *, void);

DECL_LINK(LoadHdl, sfx2::FileDialogHelper *, void);
DECL_LINK(SaveHdl, sfx2::FileDialogHelper *, void);

OUString GetLabel4Command(const OUString& rCommand);
SvTreeListEntry* applySearchFilter(OUString& rSearchTerm, SvTreeListBox* rListBox);
void InitAccCfg();
sal_uLong MapKeyCodeToPos( const vcl::KeyCode &rCode ) const;
void StartFileDialog( WinBits nBits, const OUString& rTitle );
Expand Down
Loading

0 comments on commit 3667beb

Please sign in to comment.