[Libreoffice-commits] core.git: Branch 'feature/gsoc17-revamp-customize-dialog' - cui/source cui/uiconfig

Muhammet Kara muhammet.kara at pardus.org.tr
Mon Aug 21 16:10:46 UTC 2017


 cui/source/customize/CommandCategoryListBox.cxx |   37 ++++++++++++++++++++----
 cui/source/customize/SvxMenuConfigPage.cxx      |    4 +-
 cui/source/customize/SvxToolbarConfigPage.cxx   |    4 +-
 cui/source/customize/cfg.cxx                    |   12 +++++++
 cui/source/inc/CommandCategoryListBox.hxx       |   10 +++++-
 cui/source/inc/cfg.hxx                          |    2 +
 cui/uiconfig/ui/menuassignpage.ui               |    3 +
 7 files changed, 62 insertions(+), 10 deletions(-)

New commits:
commit ce7db1fa9a1d1f2e9ef6ab535449353805887a24
Author: Muhammet Kara <muhammet.kara at pardus.org.tr>
Date:   Fri Aug 18 16:22:31 2017 +0300

    Implement Search/Filter feature in the Customize dialog
    
    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 at libreoffice.org>
    Reviewed-by: Katarina Behrens <Katarina.Behrens at cib.de>

diff --git a/cui/source/customize/CommandCategoryListBox.cxx b/cui/source/customize/CommandCategoryListBox.cxx
index c1abd3fe7d05..50542739c82e 100644
--- a/cui/source/customize/CommandCategoryListBox.cxx
+++ b/cui/source/customize/CommandCategoryListBox.cxx
@@ -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);
@@ -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 );
 
@@ -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);
@@ -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& )
                     {
@@ -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:
diff --git a/cui/source/customize/SvxMenuConfigPage.cxx b/cui/source/customize/SvxMenuConfigPage.cxx
index 336a769cea5e..3031973dbe12 100644
--- a/cui/source/customize/SvxMenuConfigPage.cxx
+++ b/cui/source/customize/SvxMenuConfigPage.cxx
@@ -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 )
diff --git a/cui/source/customize/SvxToolbarConfigPage.cxx b/cui/source/customize/SvxToolbarConfigPage.cxx
index df92295c5444..39d5393afdad 100644
--- a/cui/source/customize/SvxToolbarConfigPage.cxx
+++ b/cui/source/customize/SvxToolbarConfigPage.cxx
@@ -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 )
diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx
index dba72f22101b..af9c832ba482 100644
--- a/cui/source/customize/cfg.cxx
+++ b/cui/source/customize/cfg.cxx
@@ -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");
 
@@ -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()
@@ -1164,6 +1168,7 @@ SvxConfigPage::~SvxConfigPage()
 void SvxConfigPage::dispose()
 {
     m_pTopLevelListBox.clear();
+    m_pSearchEdit.clear();
     m_pCommandCategoryListBox.clear();
     m_pContents.clear();
     m_pEntries.clear();
@@ -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();
diff --git a/cui/source/inc/CommandCategoryListBox.hxx b/cui/source/inc/CommandCategoryListBox.hxx
index 5afc4ce798d8..a3480af6ae48 100644
--- a/cui/source/inc/CommandCategoryListBox.hxx
+++ b/cui/source/inc/CommandCategoryListBox.hxx
@@ -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
@@ -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;
@@ -44,7 +48,8 @@ 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);
 
     /**
@@ -52,7 +57,8 @@ public:
         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
diff --git a/cui/source/inc/cfg.hxx b/cui/source/inc/cfg.hxx
index c568cab194cd..32efcc717b1f 100644
--- a/cui/source/inc/cfg.hxx
+++ b/cui/source/inc/cfg.hxx
@@ -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;
 
diff --git a/cui/uiconfig/ui/menuassignpage.ui b/cui/uiconfig/ui/menuassignpage.ui
index 3eb6837c6992..9ad40abc03c9 100644
--- a/cui/uiconfig/ui/menuassignpage.ui
+++ b/cui/uiconfig/ui/menuassignpage.ui
@@ -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>


More information about the Libreoffice-commits mailing list