Skip to content

Commit

Permalink
Implement Search/Filter feature in the Customize dialog
Browse files Browse the repository at this point in the history
Now commands in the list (left box) are filtered/updated
in the Menu, Context Menu, and the Toolbar tabs as you type.

Instead of filling the box, and then removing non-matching
items (as in the current search feature in the keyboard tab),
we filter out items during the Fill process, and don't add them
to the sequence att all. This should give a performance boost
to the filter operations.

Change-Id: I473596a2c897f1cd96a7d55fd3ab11ee3db39863
Reviewed-on: https://gerrit.libreoffice.org/41321
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de>
  • Loading branch information
mrkara authored and Katarina Behrens committed Aug 21, 2017
1 parent bfb7ab0 commit ce7db1f
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 10 deletions.
37 changes: 32 additions & 5 deletions cui/source/customize/CommandCategoryListBox.cxx
Expand Up @@ -25,15 +25,27 @@
#include <com/sun/star/ui/theUICategoryDescription.hpp>
#include <vcl/builderfactory.hxx>

// include search util
#include <com/sun/star/util/SearchFlags.hpp>
#include <com/sun/star/util/SearchAlgorithms2.hpp>
#include <unotools/textsearch.hxx>

#include "dialmgr.hxx"
#include "strings.hrc"
#include <comphelper/sequenceashashmap.hxx>
#include <o3tl/make_unique.hxx>
#include <i18nutil/searchopt.hxx>

CommandCategoryListBox::CommandCategoryListBox(vcl::Window* pParent, WinBits nStyle)
: ListBox( pParent, nStyle)
{
SetDropDownLineCount(25);

//Initialize search util
m_searchOptions.AlgorithmType2 = css::util::SearchAlgorithms2::ABSOLUTE;
m_searchOptions.transliterateFlags |= TransliterationFlags::IGNORE_CASE;
m_searchOptions.searchFlag |= (css::util::SearchFlags::REG_NOT_BEGINOFLINE
| css::util::SearchFlags::REG_NOT_ENDOFLINE);
}

VCL_BUILDER_FACTORY(CommandCategoryListBox);
Expand Down Expand Up @@ -126,11 +138,25 @@ void CommandCategoryListBox::Init(

void CommandCategoryListBox::FillFunctionsList(
const css::uno::Sequence<css::frame::DispatchInformation>& xCommands,
const VclPtr<SfxConfigFunctionListBox>& pFunctionListBox)
const VclPtr<SfxConfigFunctionListBox>& pFunctionListBox,
const OUString& filterTerm )
{
// Setup search filter parameters
m_searchOptions.searchString = filterTerm;
utl::TextSearch textSearch( m_searchOptions );

for (const auto & rInfo : xCommands)
{
OUString sUIName = MapCommand2UIName(rInfo.Command);
OUString sUIName = MapCommand2UIName(rInfo.Command);
sal_Int32 aStartPos = 0;
sal_Int32 aEndPos = sUIName.getLength();

// Apply the search filter
if (!filterTerm.isEmpty()
&& !textSearch.SearchForward( sUIName, &aStartPos, &aEndPos ) )
{
continue;
}

SvTreeListEntry* pFuncEntry = pFunctionListBox->InsertEntry(sUIName );

Expand Down Expand Up @@ -169,7 +195,8 @@ OUString CommandCategoryListBox::MapCommand2UIName(const OUString& sCommand)
return sUIName;
}

void CommandCategoryListBox::categorySelected( const VclPtr<SfxConfigFunctionListBox>& pFunctionListBox )
void CommandCategoryListBox::categorySelected( const VclPtr<SfxConfigFunctionListBox>& pFunctionListBox,
const OUString& filterTerm )
{
SfxGroupInfo_Impl *pInfo = static_cast<SfxGroupInfo_Impl*>(GetSelectEntryData());
pFunctionListBox->SetUpdateMode(false);
Expand All @@ -195,7 +222,7 @@ void CommandCategoryListBox::categorySelected( const VclPtr<SfxConfigFunctionLis
{
lCommands = xProvider->getConfigurableDispatchInformation(
pCurrentInfo->nUniqueID );
FillFunctionsList( lCommands, pFunctionListBox );
FillFunctionsList( lCommands, pFunctionListBox, filterTerm );
}
catch( css::container::NoSuchElementException& )
{
Expand All @@ -213,7 +240,7 @@ void CommandCategoryListBox::categorySelected( const VclPtr<SfxConfigFunctionLis
xProvider (m_xFrame, css::uno::UNO_QUERY_THROW);
css::uno::Sequence< css::frame::DispatchInformation > lCommands =
xProvider->getConfigurableDispatchInformation(nGroup);
FillFunctionsList( lCommands, pFunctionListBox );
FillFunctionsList( lCommands, pFunctionListBox, filterTerm );
break;
}
case SfxCfgKind::GROUP_SCRIPTCONTAINER:
Expand Down
4 changes: 3 additions & 1 deletion cui/source/customize/SvxMenuConfigPage.cxx
Expand Up @@ -289,7 +289,9 @@ IMPL_LINK_NOARG( SvxMenuConfigPage, SelectMenu, ListBox&, void )

IMPL_LINK_NOARG( SvxMenuConfigPage, SelectCategory, ListBox&, void )
{
m_pCommandCategoryListBox->categorySelected( m_pFunctions );
OUString aSearchTerm( m_pSearchEdit->GetText() );

m_pCommandCategoryListBox->categorySelected( m_pFunctions, aSearchTerm );
}

IMPL_LINK_NOARG( SvxMenuConfigPage, AddCommandHdl, Button *, void )
Expand Down
4 changes: 3 additions & 1 deletion cui/source/customize/SvxToolbarConfigPage.cxx
Expand Up @@ -321,7 +321,9 @@ IMPL_LINK_NOARG( SvxToolbarConfigPage, SelectToolbarEntry, SvTreeListBox *, void

IMPL_LINK_NOARG( SvxToolbarConfigPage, SelectCategory, ListBox&, void )
{
m_pCommandCategoryListBox->categorySelected( m_pFunctions );
OUString aSearchTerm( m_pSearchEdit->GetText() );

m_pCommandCategoryListBox->categorySelected( m_pFunctions, aSearchTerm );
}

IMPL_LINK_NOARG( SvxToolbarConfigPage, AddCommandHdl, Button *, void )
Expand Down
12 changes: 12 additions & 0 deletions cui/source/customize/cfg.cxx
Expand Up @@ -1132,6 +1132,7 @@ SvxConfigPage::SvxConfigPage(vcl::Window *pParent, const SfxItemSet& rSet)
, m_pContentsListBox(nullptr)
, m_pSelectorDlg(nullptr)
{
get(m_pSearchEdit, "searchEntry");
get(m_pCommandCategoryListBox, "commandcategorylist");
get(m_pFunctions, "functions");

Expand All @@ -1154,6 +1155,9 @@ SvxConfigPage::SvxConfigPage(vcl::Window *pParent, const SfxItemSet& rSet)

m_pDescriptionField->SetControlBackground( GetSettings().GetStyleSettings().GetDialogColor() );
m_pDescriptionField->EnableCursor( false );

m_pSearchEdit->SetUpdateDataHdl ( LINK( this, SvxConfigPage, SearchUpdateHdl ));
m_pSearchEdit->EnableUpdateData();
}

SvxConfigPage::~SvxConfigPage()
Expand All @@ -1164,6 +1168,7 @@ SvxConfigPage::~SvxConfigPage()
void SvxConfigPage::dispose()
{
m_pTopLevelListBox.clear();
m_pSearchEdit.clear();
m_pCommandCategoryListBox.clear();
m_pContents.clear();
m_pEntries.clear();
Expand Down Expand Up @@ -1745,6 +1750,13 @@ IMPL_LINK( SvxConfigPage, MoveHdl, Button *, pButton, void )
MoveEntry(pButton == m_pMoveUpButton);
}

IMPL_LINK_NOARG(SvxConfigPage, SearchUpdateHdl, Edit&, void)
{
OUString aSearchTerm( m_pSearchEdit->GetText() );

m_pCommandCategoryListBox->categorySelected( m_pFunctions, aSearchTerm );
}

void SvxConfigPage::MoveEntry( bool bMoveUp )
{
SvTreeListEntry *pSourceEntry = m_pContentsListBox->FirstSelected();
Expand Down
10 changes: 8 additions & 2 deletions cui/source/inc/CommandCategoryListBox.hxx
Expand Up @@ -20,6 +20,7 @@
#define INCLUDED_CUI_SOURCE_INC_COMMANDCATEGORYLISTBOX_HXX

#include <vcl/lstbox.hxx>
#include <i18nutil/searchopt.hxx>
#include "cfgutil.hxx"

class CommandCategoryListBox : public ListBox
Expand All @@ -32,6 +33,9 @@ class CommandCategoryListBox : public ListBox
css::uno::Reference< css::container::XNameAccess > m_xModuleCategoryInfo;
css::uno::Reference< css::container::XNameAccess > m_xUICmdDescription;

// For search
i18nutil::SearchOptions2 m_searchOptions;

public:
CommandCategoryListBox( vcl::Window* pParent, WinBits nBits = WB_BORDER | WB_DROPDOWN );
virtual ~CommandCategoryListBox() override;
Expand All @@ -44,15 +48,17 @@ public:
const OUString& sModuleLongName);
void FillFunctionsList(
const css::uno::Sequence< css::frame::DispatchInformation >& xCommands,
const VclPtr<SfxConfigFunctionListBox>& pFunctionListBox);
const VclPtr<SfxConfigFunctionListBox>& pFunctionListBox,
const OUString& filterTerm = OUString() );
OUString MapCommand2UIName(const OUString& sCommand);

/**
Signals that a command category has been selected.
And updates the functions list box to include
the commands in the selected category.
*/
void categorySelected( const VclPtr<SfxConfigFunctionListBox>& pFunctionListBox );
void categorySelected( const VclPtr<SfxConfigFunctionListBox>& pFunctionListBox,
const OUString& filterTerm = OUString() );
};

#endif // INCLUDED_CUI_SOURCE_INC_COMMANDCATEGORYLISTBOX_HXX
Expand Down
2 changes: 2 additions & 0 deletions cui/source/inc/cfg.hxx
Expand Up @@ -379,11 +379,13 @@ private:

DECL_LINK( SelectSaveInLocation, ListBox&, void );
DECL_LINK( AsyncInfoMsg, void*, void );
DECL_LINK( SearchUpdateHdl, Edit&, void );

protected:

// Left side of the dialog where command categories and the available
// commands in them are displayed as a searchable list
VclPtr<Edit> m_pSearchEdit;
VclPtr<CommandCategoryListBox> m_pCommandCategoryListBox;
VclPtr<SfxConfigFunctionListBox> m_pFunctions;

Expand Down
3 changes: 2 additions & 1 deletion cui/uiconfig/ui/menuassignpage.ui
Expand Up @@ -487,10 +487,11 @@
</packing>
</child>
<child>
<object class="GtkEntry">
<object class="GtkEntry" id="searchEntry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_bottom">5</property>
<property name="placeholder_text" translatable="yes">Type to search</property>
</object>
<packing>
<property name="left_attach">1</property>
Expand Down

0 comments on commit ce7db1f

Please sign in to comment.