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

Muhammet Kara muhammet.kara at pardus.org.tr
Fri Aug 25 09:54:19 UTC 2017


 cui/source/customize/SvxMenuConfigPage.cxx    |   33 +++++++++
 cui/source/customize/SvxToolbarConfigPage.cxx |   90 ++++++++++++++++++++++++++
 cui/source/customize/cfg.cxx                  |    4 +
 cui/source/inc/SvxConfigPageHelper.hxx        |    5 +
 cui/source/inc/SvxMenuConfigPage.hxx          |    3 
 cui/source/inc/SvxToolbarConfigPage.hxx       |    3 
 cui/source/inc/cfg.hxx                        |    3 
 cui/uiconfig/ui/menuassignpage.ui             |    4 -
 8 files changed, 143 insertions(+), 2 deletions(-)

New commits:
commit fbe32573281c873f159e380a454e52147d15f932
Author: Muhammet Kara <muhammet.kara at pardus.org.tr>
Date:   Tue Aug 22 21:50:46 2017 +0300

    Make toolbar/menu addition/removal functional again in the Customize dialog
    
    "+" and "-" buttons next to the menu/toolbar listbox can be used
    to add new toolbars/menus or remove existing toolbars/menus.
    
    Most of the code was borrowed from the previous implementation,
    and adapted to fit the current structure.
    
    Change-Id: I7e7f51a46251c2d010154f2a0bab3bb20280bf7c
    Reviewed-on: https://gerrit.libreoffice.org/41431
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Katarina Behrens <Katarina.Behrens at cib.de>

diff --git a/cui/source/customize/SvxMenuConfigPage.cxx b/cui/source/customize/SvxMenuConfigPage.cxx
index decf6a9d251b..c07b057f7f34 100644
--- a/cui/source/customize/SvxMenuConfigPage.cxx
+++ b/cui/source/customize/SvxMenuConfigPage.cxx
@@ -119,6 +119,11 @@ SvxMenuConfigPage::SvxMenuConfigPage(vcl::Window *pParent, const SfxItemSet& rSe
     m_pContentsListBox->SetSelectHdl(
         LINK( this, SvxMenuConfigPage, SelectMenuEntry ) );
 
+    m_pPlusBtn->SetClickHdl(
+        LINK( this, SvxMenuConfigPage, AddMenuHdl ) );
+    m_pMinusBtn->SetClickHdl(
+        LINK( this, SvxMenuConfigPage, RemoveMenuHdl ) );
+
     m_pCommandCategoryListBox->SetSelectHdl(
         LINK( this, SvxMenuConfigPage, SelectCategory ) );
 
@@ -133,6 +138,13 @@ SvxMenuConfigPage::SvxMenuConfigPage(vcl::Window *pParent, const SfxItemSet& rSe
     m_pResetBtn->SetClickHdl(
         LINK( this, SvxMenuConfigPage, ResetMenuHdl ) );
 
+    if ( !bIsMenuBar )
+    {
+        // Context menus cannot be added/removed
+        m_pPlusBtn->Hide();
+        m_pMinusBtn->Hide();
+    }
+
 }
 
 SvxMenuConfigPage::~SvxMenuConfigPage()
@@ -280,6 +292,9 @@ IMPL_LINK_NOARG( SvxMenuConfigPage, SelectMenu, ListBox&, void )
 
     if ( pMenuData )
     {
+        // Built-in menus cannot be deleted
+        m_pMinusBtn->Enable( pMenuData->IsDeletable() );
+
         SvxEntries* pEntries = pMenuData->GetEntries();
         SvxEntries::const_iterator iter = pEntries->begin();
 
@@ -293,6 +308,24 @@ IMPL_LINK_NOARG( SvxMenuConfigPage, SelectMenu, ListBox&, void )
     UpdateButtonStates();
 }
 
+IMPL_LINK_NOARG( SvxMenuConfigPage, AddMenuHdl, Button *, void )
+{
+    VclPtrInstance<SvxMainMenuOrganizerDialog> pDialog(
+        nullptr, GetSaveInData()->GetEntries(), nullptr, true );
+
+    if ( pDialog->Execute() == RET_OK )
+    {
+        GetSaveInData()->SetEntries( pDialog->GetEntries() );
+        ReloadTopLevelListBox( pDialog->GetSelectedEntry() );
+        GetSaveInData()->SetModified();
+    }
+}
+
+IMPL_LINK_NOARG( SvxMenuConfigPage, RemoveMenuHdl, Button *, void )
+{
+    DeleteSelectedTopLevel();
+}
+
 IMPL_LINK_NOARG( SvxMenuConfigPage, SelectCategory, ListBox&, void )
 {
     OUString aSearchTerm( m_pSearchEdit->GetText() );
diff --git a/cui/source/customize/SvxToolbarConfigPage.cxx b/cui/source/customize/SvxToolbarConfigPage.cxx
index fdf1837952d7..c6aa393d40cc 100644
--- a/cui/source/customize/SvxToolbarConfigPage.cxx
+++ b/cui/source/customize/SvxToolbarConfigPage.cxx
@@ -128,6 +128,11 @@ SvxToolbarConfigPage::SvxToolbarConfigPage(vcl::Window *pParent, const SfxItemSe
     m_pCommandCategoryListBox->SetSelectHdl(
         LINK( this, SvxToolbarConfigPage, SelectCategory ) );
 
+    m_pPlusBtn->SetClickHdl(
+        LINK( this, SvxToolbarConfigPage, AddToolbarHdl ) );
+    m_pMinusBtn->SetClickHdl(
+        LINK( this, SvxToolbarConfigPage, RemoveToolbarHdl ) );
+
     m_pMoveUpButton->SetClickHdl ( LINK( this, SvxToolbarConfigPage, MoveHdl) );
     m_pMoveDownButton->SetClickHdl ( LINK( this, SvxToolbarConfigPage, MoveHdl) );
     // Always enable Up and Down buttons
@@ -329,6 +334,79 @@ IMPL_LINK_NOARG( SvxToolbarConfigPage, SelectToolbarEntry, SvTreeListBox *, void
     UpdateButtonStates();
 }
 
+IMPL_LINK_NOARG( SvxToolbarConfigPage, AddToolbarHdl, Button *, void )
+{
+    OUString prefix = CuiResId( RID_SVXSTR_NEW_TOOLBAR );
+
+    OUString aNewName =
+        SvxConfigPageHelper::generateCustomName( prefix, GetSaveInData()->GetEntries() );
+
+    OUString aNewURL =
+        SvxConfigPageHelper::generateCustomURL( GetSaveInData()->GetEntries() );
+
+    VclPtrInstance< SvxNewToolbarDialog > pNameDialog( nullptr, aNewName );
+
+    // Reflect the actual m_pSaveInListBox into the new toolbar dialog
+    for ( sal_Int32 i = 0; i < m_pSaveInListBox->GetEntryCount(); ++i )
+    {
+        SaveInData* pData =
+            static_cast<SaveInData*>(m_pSaveInListBox->GetEntryData( i ));
+
+        const sal_Int32 nInsertPos =
+            pNameDialog->m_pSaveInListBox->InsertEntry( m_pSaveInListBox->GetEntry( i ) );
+
+        pNameDialog->m_pSaveInListBox->SetEntryData( nInsertPos, pData );
+    }
+
+    pNameDialog->m_pSaveInListBox->SelectEntryPos(
+        m_pSaveInListBox->GetSelectEntryPos() );
+
+    if ( pNameDialog->Execute() == RET_OK )
+    {
+        aNewName = pNameDialog->GetName();
+
+        // Where to save the new toolbar? (i.e. Modulewise or documentwise)
+        sal_Int32 nInsertPos = pNameDialog->m_pSaveInListBox->GetSelectEntryPos();
+
+        ToolbarSaveInData* pData =
+            static_cast<ToolbarSaveInData*>(
+                pNameDialog->m_pSaveInListBox->GetEntryData( nInsertPos ) );
+
+        if ( GetSaveInData() != pData )
+        {
+            m_pSaveInListBox->SelectEntryPos( nInsertPos );
+            m_pSaveInListBox->GetSelectHdl().Call(*m_pSaveInListBox);
+        }
+
+        SvxConfigEntry* pToolbar =
+            new SvxConfigEntry( aNewName, aNewURL, true );
+
+        pToolbar->SetUserDefined();
+        pToolbar->SetMain();
+
+        pData->CreateToolbar( pToolbar );
+
+        nInsertPos = m_pTopLevelListBox->InsertEntry( pToolbar->GetName() );
+        m_pTopLevelListBox->SetEntryData( nInsertPos, pToolbar );
+        m_pTopLevelListBox->SelectEntryPos( nInsertPos );
+        m_pTopLevelListBox->GetSelectHdl().Call(*m_pTopLevelListBox);
+
+        pData->SetModified();
+    }
+}
+
+IMPL_LINK_NOARG( SvxToolbarConfigPage, RemoveToolbarHdl, Button *, void )
+{
+    SvxConfigEntry* pToolbar = GetTopLevelSelection();
+
+    if ( pToolbar && pToolbar->IsDeletable() )
+    {
+        DeleteSelectedTopLevel();
+        UpdateButtonStates();
+    }
+
+}
+
 IMPL_LINK_NOARG( SvxToolbarConfigPage, SelectCategory, ListBox&, void )
 {
     OUString aSearchTerm( m_pSearchEdit->GetText() );
@@ -436,8 +514,20 @@ IMPL_LINK_NOARG( SvxToolbarConfigPage, SelectToolbar, ListBox&, void )
     if ( pToolbar == nullptr )
     {
         //TODO: Disable related buttons
+        m_pPlusBtn->Enable( false );
+        m_pMinusBtn->Enable( false );
+        m_pInsertBtn->Enable( false );
+        m_pResetBtn->Enable( false );
+
         return;
     }
+    else
+    {
+        m_pPlusBtn->Enable();
+        m_pMinusBtn->Enable( pToolbar->IsDeletable() );
+        m_pInsertBtn->Enable();
+        m_pResetBtn->Enable();
+    }
 
     SvxEntries* pEntries = pToolbar->GetEntries();
     SvxEntries::const_iterator iter = pEntries->begin();
diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx
index 8965d4094fe2..f37bae121971 100644
--- a/cui/source/customize/cfg.cxx
+++ b/cui/source/customize/cfg.cxx
@@ -1155,6 +1155,8 @@ SvxConfigPage::SvxConfigPage(vcl::Window *pParent, const SfxItemSet& rSet)
     get(m_pRemoveCommandButton, "remove");
 
     get(m_pTopLevelListBox, "toplevellist");
+    get(m_pPlusBtn, "plusbtn");
+    get(m_pMinusBtn, "minusbtn");
     get(m_pContents, "contents");
     get(m_pMoveUpButton, "up");
     get(m_pMoveDownButton, "down");
@@ -1185,6 +1187,8 @@ SvxConfigPage::~SvxConfigPage()
 void SvxConfigPage::dispose()
 {
     m_pTopLevelListBox.clear();
+    m_pPlusBtn.clear();
+    m_pMinusBtn.clear();
     m_pSearchEdit.clear();
     m_pCommandCategoryListBox.clear();
     m_pContents.clear();
diff --git a/cui/source/inc/SvxConfigPageHelper.hxx b/cui/source/inc/SvxConfigPageHelper.hxx
index 4b83b1c7dfd6..6484d8f313b4 100644
--- a/cui/source/inc/SvxConfigPageHelper.hxx
+++ b/cui/source/inc/SvxConfigPageHelper.hxx
@@ -47,6 +47,11 @@ public:
         SvxEntries* entries,
         sal_Int32 suffix = 1 );
     static sal_uInt32   generateRandomValue();
+    /**
+        Generates a custom resource URL for a new toolbar.
+        Typically something like: private:resource/toolbar/custom_toolbar_########
+        The last 8 letters are randomly generated alphanumeric characters.
+    */
     static OUString     generateCustomURL( SvxEntries* entries );
 
     static OUString GetModuleName( const OUString& aModuleId );
diff --git a/cui/source/inc/SvxMenuConfigPage.hxx b/cui/source/inc/SvxMenuConfigPage.hxx
index 56365d79aa93..f0b0bcafa247 100644
--- a/cui/source/inc/SvxMenuConfigPage.hxx
+++ b/cui/source/inc/SvxMenuConfigPage.hxx
@@ -54,6 +54,9 @@ private:
     DECL_LINK( SelectMenu, ListBox&, void );
     DECL_LINK( SelectMenuEntry, SvTreeListBox *, void );
 
+    DECL_LINK( AddMenuHdl, Button *, void );
+    DECL_LINK( RemoveMenuHdl, Button *, void );
+
     DECL_LINK( SelectCategory, ListBox&, void );
 
     DECL_LINK( AddCommandHdl, Button *, void );
diff --git a/cui/source/inc/SvxToolbarConfigPage.hxx b/cui/source/inc/SvxToolbarConfigPage.hxx
index 471d9bc0d6d3..07cae0dab56d 100644
--- a/cui/source/inc/SvxToolbarConfigPage.hxx
+++ b/cui/source/inc/SvxToolbarConfigPage.hxx
@@ -55,6 +55,9 @@ private:
     DECL_LINK( SelectToolbarEntry, SvTreeListBox*, void );
     DECL_LINK( MoveHdl, Button *, void );
 
+    DECL_LINK( AddToolbarHdl, Button *, void );
+    DECL_LINK( RemoveToolbarHdl, Button *, void );
+
     DECL_LINK( SelectCategory, ListBox&, void );
 
     DECL_LINK( AddCommandHdl, Button *, void );
diff --git a/cui/source/inc/cfg.hxx b/cui/source/inc/cfg.hxx
index 50558a537eab..bddd41a4307b 100644
--- a/cui/source/inc/cfg.hxx
+++ b/cui/source/inc/cfg.hxx
@@ -396,6 +396,9 @@ protected:
     // Right side of the dialog where the contents of the selected
     // menu or toolbar are displayed
     VclPtr<ListBox>                            m_pTopLevelListBox;
+    // Used to add and remove toolbars/menus
+    VclPtr<PushButton>                         m_pPlusBtn;
+    VclPtr<PushButton>                         m_pMinusBtn;
     VclPtr<VclFrame>                           m_pContents;
     VclPtr<VclContainer>                       m_pEntries;
     VclPtr<SvTreeListBox>                      m_pContentsListBox;
diff --git a/cui/uiconfig/ui/menuassignpage.ui b/cui/uiconfig/ui/menuassignpage.ui
index 6093fb2ab644..571cc2c8e073 100644
--- a/cui/uiconfig/ui/menuassignpage.ui
+++ b/cui/uiconfig/ui/menuassignpage.ui
@@ -262,7 +262,7 @@
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkButton" id="add1">
+                          <object class="GtkButton" id="plusbtn">
                             <property name="label" translatable="yes">+</property>
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
@@ -276,7 +276,7 @@
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkButton" id="remove1">
+                          <object class="GtkButton" id="minusbtn">
                             <property name="label" translatable="yes">-</property>
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>


More information about the Libreoffice-commits mailing list