cui/source/customize/acccfg.cxx    |   71 +++++++++++++
 cui/source/inc/acccfg.hxx          |   69 +++++++------
 cui/uiconfig/ui/accelconfigpage.ui |  196 ++++++++++++++++++-------------------
 3 files changed, 209 insertions(+), 127 deletions(-)

New commits:
commit 3667beb986e8c03c925566a585b0504c7943fede
Author: Muhammet Kara <muhammet.k...@pardus.org.tr>
Date:   Tue Jun 13 11:44:22 2017 +0300

    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 <c...@libreoffice.org>
    Reviewed-by: Katarina Behrens <katarina.behr...@cib.de>

diff --git a/cui/source/customize/acccfg.cxx b/cui/source/customize/acccfg.cxx
index ebfc9e0b2014..14c69002373f 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>
@@ -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 );
 
@@ -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);
@@ -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);
 
@@ -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();
@@ -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
@@ -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 );
     }
@@ -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: */
diff --git a/cui/source/inc/acccfg.hxx b/cui/source/inc/acccfg.hxx
index ded5f76078dc..58eccff05e00 100644
--- a/cui/source/inc/acccfg.hxx
+++ b/cui/source/inc/acccfg.hxx
@@ -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;
@@ -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 );
diff --git a/cui/uiconfig/ui/accelconfigpage.ui 
b/cui/uiconfig/ui/accelconfigpage.ui
index a66e293f889a..68e17b4b01c6 100644
--- a/cui/uiconfig/ui/accelconfigpage.ui
+++ b/cui/uiconfig/ui/accelconfigpage.ui
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.16.1 -->
+<!-- Generated with glade 3.20.0 -->
 <interface>
   <requires lib="gtk+" version="3.10"/>
-  <!-- interface-requires LibreOffice 1.0 -->
+  <requires lib="LibreOffice" version="1.0"/>
   <object class="GtkGrid" id="AccelConfigPage">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -60,8 +60,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>
@@ -211,16 +209,12 @@
           <packing>
             <property name="left_attach">1</property>
             <property name="top_attach">0</property>
-            <property name="width">1</property>
-            <property name="height">1</property>
           </packing>
         </child>
       </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>
@@ -240,110 +234,122 @@
             <property name="top_padding">6</property>
             <property name="left_padding">12</property>
             <child>
-              <object class="GtkGrid" id="grid1">
+              <object class="GtkBox">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="hexpand">True</property>
-                <property name="vexpand">True</property>
-                <property name="row_spacing">6</property>
-                <property name="column_spacing">12</property>
-                <child>
-                  <object class="GtkLabel" id="label23">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="xalign">0</property>
-                    <property name="label" 
translatable="yes">_Category</property>
-                    <property name="use_underline">True</property>
-                    <property name="mnemonic_widget">category:border</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>
+                <property name="orientation">vertical</property>
                 <child>
-                  <object class="GtkLabel" id="label24">
+                  <object class="GtkEntry" id="searchEntry">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="xalign">0</property>
-                    <property name="label" 
translatable="yes">_Function</property>
-                    <property name="use_underline">True</property>
-                    <property name="mnemonic_widget">function:border</property>
+                    <property name="can_focus">True</property>
+                    <property name="placeholder_text" translatable="yes">Type 
to search</property>
                   </object>
                   <packing>
-                    <property name="left_attach">1</property>
-                    <property name="top_attach">0</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkLabel" id="label25">
+                  <object class="GtkGrid" id="grid1">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="xalign">0</property>
-                    <property name="label" translatable="yes">_Keys</property>
-                    <property name="use_underline">True</property>
-                    <property name="mnemonic_widget">keys:border</property>
-                  </object>
-                  <packing>
-                    <property name="left_attach">2</property>
-                    <property name="top_attach">0</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="cuilo-SfxConfigGroupListBox" 
id="category:border">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
                     <property name="hexpand">True</property>
                     <property name="vexpand">True</property>
-                    <child internal-child="selection">
-                      <object class="GtkTreeSelection" id="ConfigGroup 
ListBox-selection"/>
+                    <property name="row_spacing">6</property>
+                    <property name="column_spacing">12</property>
+                    <child>
+                      <object class="GtkLabel" id="label23">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" 
translatable="yes">_Category</property>
+                        <property name="use_underline">True</property>
+                        <property 
name="mnemonic_widget">category:border</property>
+                        <property name="xalign">0</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">0</property>
+                      </packing>
                     </child>
-                  </object>
-                  <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="cuilo-SfxConfigFunctionListBox" 
id="function:border">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="hexpand">True</property>
-                    <property name="vexpand">True</property>
-                    <child internal-child="selection">
-                      <object class="GtkTreeSelection" id="ConfigGroupFunction 
ListBox-selection"/>
+                    <child>
+                      <object class="GtkLabel" id="label24">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" 
translatable="yes">_Function</property>
+                        <property name="use_underline">True</property>
+                        <property 
name="mnemonic_widget">function:border</property>
+                        <property name="xalign">0</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="top_attach">0</property>
+                      </packing>
                     </child>
-                  </object>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="top_attach">1</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="svtlo-SvTreeListBox" id="keys:border">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="hexpand">True</property>
-                    <property name="vexpand">True</property>
-                    <child internal-child="selection">
-                      <object class="GtkTreeSelection" id="Tree 
List-selection"/>
+                    <child>
+                      <object class="GtkLabel" id="label25">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" 
translatable="yes">_Keys</property>
+                        <property name="use_underline">True</property>
+                        <property name="mnemonic_widget">keys:border</property>
+                        <property name="xalign">0</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">2</property>
+                        <property name="top_attach">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="cuilo-SfxConfigGroupListBox" 
id="category:border">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="hexpand">True</property>
+                        <property name="vexpand">True</property>
+                        <child internal-child="selection">
+                          <object class="GtkTreeSelection" id="ConfigGroup 
ListBox-selection"/>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="cuilo-SfxConfigFunctionListBox" 
id="function:border">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="hexpand">True</property>
+                        <property name="vexpand">True</property>
+                        <child internal-child="selection">
+                          <object class="GtkTreeSelection" 
id="ConfigGroupFunction ListBox-selection"/>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="top_attach">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="svtlo-SvTreeListBox" id="keys:border">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="hexpand">True</property>
+                        <property name="vexpand">True</property>
+                        <child internal-child="selection">
+                          <object class="GtkTreeSelection" id="Tree 
List-selection"/>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="left_attach">2</property>
+                        <property name="top_attach">1</property>
+                      </packing>
                     </child>
                   </object>
                   <packing>
-                    <property name="left_attach">2</property>
-                    <property name="top_attach">1</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">1</property>
                   </packing>
                 </child>
               </object>
@@ -364,8 +370,6 @@
       <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>
   </object>
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to