[Libreoffice-commits] core.git: svx/source svx/uiconfig

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Feb 7 20:59:41 UTC 2019


 svx/source/form/datanavi.cxx       |  151 ++++++++++++++-----------------------
 svx/source/inc/datanavi.hxx        |   24 ++---
 svx/uiconfig/ui/namespacedialog.ui |   94 ++++++++++++-----------
 3 files changed, 119 insertions(+), 150 deletions(-)

New commits:
commit 950bdd703bb4430526598a132897a6b77cb21005
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Thu Feb 7 17:15:52 2019 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Thu Feb 7 21:59:13 2019 +0100

    weld NamespaceItemDialog
    
    Change-Id: If2029eaae250ed3ee4ab56dae7ec67c2deba3ab8
    Reviewed-on: https://gerrit.libreoffice.org/67515
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/svx/source/form/datanavi.cxx b/svx/source/form/datanavi.cxx
index 85a4a70eb0cf..6b241324b353 100644
--- a/svx/source/form/datanavi.cxx
+++ b/svx/source/form/datanavi.cxx
@@ -2812,8 +2812,8 @@ namespace svxform
         {
             SAL_WARN( "svx.form", "AddDataItemDialog::EditHdl(): exception caught" );
         }
-        ScopedVclPtrInstance< NamespaceItemDialog > aDlg( this, xNameContnr );
-        aDlg->Execute();
+        NamespaceItemDialog aDlg(this, xNameContnr);
+        aDlg.run();
         try
         {
             m_xBinding->setPropertyValue( PN_BINDING_NAMESPACES, makeAny( xNameContnr ) );
@@ -2866,123 +2866,91 @@ namespace svxform
         m_pResultWin->SetText( sResult );
     }
 
-    NamespaceItemDialog::NamespaceItemDialog(
-        AddConditionDialog* _pCondDlg,
-            Reference< XNameContainer >& _rContainer )
-        : ModalDialog( _pCondDlg, "NamespaceDialog",
-            "svx/ui/namespacedialog.ui" )
-        , m_pConditionDlg(_pCondDlg)
-        , m_rNamespaces(_rContainer)
+    NamespaceItemDialog::NamespaceItemDialog(AddConditionDialog* pCondDlg, Reference<XNameContainer>& rContainer)
+        : GenericDialogController(pCondDlg->GetFrameWeld(), "svx/ui/namespacedialog.ui", "NamespaceDialog")
+        , m_pConditionDlg(pCondDlg)
+        , m_rNamespaces(rContainer)
+        , m_xNamespacesList(m_xBuilder->weld_tree_view("namespaces"))
+        , m_xAddNamespaceBtn(m_xBuilder->weld_button("add"))
+        , m_xEditNamespaceBtn(m_xBuilder->weld_button("edit"))
+        , m_xDeleteNamespaceBtn(m_xBuilder->weld_button("delete"))
+        , m_xOKBtn(m_xBuilder->weld_button("ok"))
     {
-        get(m_pAddNamespaceBtn, "add");
-        get(m_pEditNamespaceBtn, "edit");
-        get(m_pDeleteNamespaceBtn, "delete");
-        get(m_pOKBtn, "ok");
+        m_xNamespacesList->set_size_request(m_xNamespacesList->get_approximate_digit_width() * 80,
+                                            m_xNamespacesList->get_height_rows(8));
+
+        std::vector<int> aWidths;
+        aWidths.push_back(m_xNamespacesList->get_approximate_digit_width() * 20);
+        m_xNamespacesList->set_column_fixed_widths(aWidths);
 
-        SvSimpleTableContainer* pNamespacesListContainer =
-            get<SvSimpleTableContainer>("namespaces");
-        Size aControlSize(175, 72);
-        aControlSize = LogicToPixel(aControlSize, MapMode(MapUnit::MapAppFont));
-        pNamespacesListContainer->set_width_request(aControlSize.Width());
-        pNamespacesListContainer->set_height_request(aControlSize.Height());
-        m_pNamespacesList = VclPtr<SvSimpleTable>::Create(*pNamespacesListContainer, 0);
-
-        static long aTabPositions[]= { 0, 35, 200 };
-        m_pNamespacesList->SvSimpleTable::SetTabs( SAL_N_ELEMENTS(aTabPositions), aTabPositions );
-        OUString sHeader = get<FixedText>("prefix")->GetText();
-        sHeader += "\t";
-        sHeader += get<FixedText>("url")->GetText();
-        m_pNamespacesList->InsertHeaderEntry(
-            sHeader, HEADERBAR_APPEND, HeaderBarItemBits::LEFT /*| HeaderBarItemBits::FIXEDPOS | HeaderBarItemBits::FIXED*/ );
-
-        m_pNamespacesList->SetSelectHdl( LINK( this, NamespaceItemDialog, SelectHdl ) );
-        Link<Button*,void> aLink = LINK( this, NamespaceItemDialog, ClickHdl );
-        m_pAddNamespaceBtn->SetClickHdl( aLink );
-        m_pEditNamespaceBtn->SetClickHdl( aLink );
-        m_pDeleteNamespaceBtn->SetClickHdl( aLink );
-        m_pOKBtn->SetClickHdl( LINK( this, NamespaceItemDialog, OKHdl ) );
+        m_xNamespacesList->connect_changed( LINK( this, NamespaceItemDialog, SelectHdl ) );
+        Link<weld::Button&,void> aLink = LINK( this, NamespaceItemDialog, ClickHdl );
+        m_xAddNamespaceBtn->connect_clicked( aLink );
+        m_xEditNamespaceBtn->connect_clicked( aLink );
+        m_xDeleteNamespaceBtn->connect_clicked( aLink );
+        m_xOKBtn->connect_clicked( LINK( this, NamespaceItemDialog, OKHdl ) );
 
         LoadNamespaces();
-        SelectHdl( m_pNamespacesList );
+        SelectHdl(*m_xNamespacesList);
     }
 
-
     NamespaceItemDialog::~NamespaceItemDialog()
     {
-        disposeOnce();
-    }
-
-    void NamespaceItemDialog::dispose()
-    {
-        m_pNamespacesList.disposeAndClear();
-        m_pAddNamespaceBtn.clear();
-        m_pEditNamespaceBtn.clear();
-        m_pDeleteNamespaceBtn.clear();
-        m_pOKBtn.clear();
-        m_pConditionDlg.clear();
-        ModalDialog::dispose();
     }
 
-
-    IMPL_LINK_NOARG( NamespaceItemDialog, SelectHdl, SvTreeListBox *, void)
+    IMPL_LINK_NOARG( NamespaceItemDialog, SelectHdl, weld::TreeView&, void)
     {
-        bool bEnable = ( m_pNamespacesList->FirstSelected() != nullptr );
-        m_pEditNamespaceBtn->Enable( bEnable );
-        m_pDeleteNamespaceBtn->Enable( bEnable );
+        bool bEnable = m_xNamespacesList->get_selected_index() != -1;
+        m_xEditNamespaceBtn->set_sensitive( bEnable );
+        m_xDeleteNamespaceBtn->set_sensitive( bEnable );
     }
 
-
-    IMPL_LINK( NamespaceItemDialog, ClickHdl, Button *, pButton, void )
+    IMPL_LINK( NamespaceItemDialog, ClickHdl, weld::Button&, rButton, void )
     {
-        PushButton* pBtn = static_cast<PushButton*>(pButton);
-        if ( m_pAddNamespaceBtn == pBtn )
+        if (m_xAddNamespaceBtn.get() == &rButton)
         {
-            ManageNamespaceDialog aDlg(GetFrameWeld(), m_pConditionDlg, false);
+            ManageNamespaceDialog aDlg(m_xDialog.get(), m_pConditionDlg, false);
             if (aDlg.run() == RET_OK)
             {
-                OUString sEntry = aDlg.GetPrefix();
-                sEntry += "\t";
-                sEntry += aDlg.GetURL();
-                m_pNamespacesList->InsertEntry( sEntry );
+                m_xNamespacesList->append_text(aDlg.GetPrefix());
+                int nRow = m_xNamespacesList->n_children();
+                m_xNamespacesList->set_text(nRow - 1, aDlg.GetURL(), 1);
             }
         }
-        else if ( m_pEditNamespaceBtn == pBtn )
+        else if (m_xEditNamespaceBtn.get() == &rButton)
         {
-            ManageNamespaceDialog aDlg(GetFrameWeld(), m_pConditionDlg, true);
-            SvTreeListEntry* pEntry = m_pNamespacesList->FirstSelected();
-            DBG_ASSERT( pEntry, "NamespaceItemDialog::ClickHdl(): no entry" );
-            OUString sPrefix( SvTabListBox::GetEntryText( pEntry, 0 ) );
-            aDlg.SetNamespace(
-                sPrefix,
-                SvTabListBox::GetEntryText( pEntry, 1 ) );
+            ManageNamespaceDialog aDlg(m_xDialog.get(), m_pConditionDlg, true);
+            int nEntry = m_xNamespacesList->get_selected_index();
+            DBG_ASSERT( nEntry != -1, "NamespaceItemDialog::ClickHdl(): no entry" );
+            OUString sPrefix(m_xNamespacesList->get_text(nEntry, 0));
+            aDlg.SetNamespace(sPrefix, m_xNamespacesList->get_text(nEntry, 1));
             if (aDlg.run() == RET_OK)
             {
                 // if a prefix was changed, mark the old prefix as 'removed'
                 if( sPrefix != aDlg.GetPrefix() )
                     m_aRemovedList.push_back( sPrefix );
 
-                m_pNamespacesList->SetEntryText( aDlg.GetPrefix(), pEntry, 0 );
-                m_pNamespacesList->SetEntryText( aDlg.GetURL(), pEntry, 1 );
+                m_xNamespacesList->set_text(nEntry, aDlg.GetPrefix(), 0);
+                m_xNamespacesList->set_text(nEntry, aDlg.GetURL(), 1);
             }
         }
-        else if ( m_pDeleteNamespaceBtn == pBtn )
+        else if (m_xDeleteNamespaceBtn.get() == &rButton)
         {
-            SvTreeListEntry* pEntry = m_pNamespacesList->FirstSelected();
-            DBG_ASSERT( pEntry, "NamespaceItemDialog::ClickHdl(): no entry" );
-            OUString sPrefix( SvTabListBox::GetEntryText( pEntry, 0 ) );
+            int nEntry = m_xNamespacesList->get_selected_index();
+            DBG_ASSERT( nEntry != -1, "NamespaceItemDialog::ClickHdl(): no entry" );
+            OUString sPrefix(m_xNamespacesList->get_text(nEntry, 0));
             m_aRemovedList.push_back( sPrefix );
-            m_pNamespacesList->GetModel()->Remove( pEntry );
+            m_xNamespacesList->remove(nEntry);
         }
         else
         {
             SAL_WARN( "svx.form", "NamespaceItemDialog::ClickHdl(): invalid button" );
         }
 
-        SelectHdl( m_pNamespacesList );
+        SelectHdl(*m_xNamespacesList);
     }
 
-
-    IMPL_LINK_NOARG(NamespaceItemDialog, OKHdl, Button*, void)
+    IMPL_LINK_NOARG(NamespaceItemDialog, OKHdl, weld::Button&, void)
     {
         try
         {
@@ -2991,12 +2959,11 @@ namespace svxform
             for( i = 0; i < nRemovedCount; ++i )
                 m_rNamespaces->removeByName( m_aRemovedList[i] );
 
-            sal_Int32 nEntryCount = m_pNamespacesList->GetEntryCount();
+            sal_Int32 nEntryCount = m_xNamespacesList->n_children();
             for( i = 0; i < nEntryCount; ++i )
             {
-                SvTreeListEntry* pEntry = m_pNamespacesList->GetEntry(i);
-                OUString sPrefix( SvTabListBox::GetEntryText( pEntry, 0 ) );
-                OUString sURL( SvTabListBox::GetEntryText( pEntry, 1 ) );
+                OUString sPrefix(m_xNamespacesList->get_text(i, 0));
+                OUString sURL(m_xNamespacesList->get_text(i, 1));
 
                 if ( m_rNamespaces->hasByName( sPrefix ) )
                     m_rNamespaces->replaceByName( sPrefix, makeAny( sURL ) );
@@ -3009,14 +2976,14 @@ namespace svxform
             SAL_WARN( "svx.form", "NamespaceItemDialog::OKHdl(): exception caught" );
         }
         // and close the dialog
-        EndDialog( RET_OK );
+        m_xDialog->response(RET_OK);
     }
 
-
     void NamespaceItemDialog::LoadNamespaces()
     {
         try
         {
+            int nRow = 0;
             Sequence< OUString > aAllNames = m_rNamespaces->getElementNames();
             const OUString* pAllNames = aAllNames.getConstArray();
             const OUString* pAllNamesEnd = pAllNames + aAllNames.getLength();
@@ -3027,13 +2994,11 @@ namespace svxform
                 if ( m_rNamespaces->hasByName( sPrefix ) )
                 {
                     Any aAny = m_rNamespaces->getByName( sPrefix );
-                    if ( aAny >>= sURL )
+                    if (aAny >>= sURL)
                     {
-                        OUString sEntry( sPrefix );
-                        sEntry += "\t";
-                        sEntry += sURL;
-
-                        m_pNamespacesList->InsertEntry( sEntry );
+                        m_xNamespacesList->append_text(sPrefix);
+                        m_xNamespacesList->set_text(nRow, sURL, 1);
+                        ++nRow;
                     }
                 }
             }
diff --git a/svx/source/inc/datanavi.hxx b/svx/source/inc/datanavi.hxx
index d448f999bd49..facd9fbefe2c 100644
--- a/svx/source/inc/datanavi.hxx
+++ b/svx/source/inc/datanavi.hxx
@@ -481,32 +481,30 @@ namespace svxform
         }
     };
 
-
-    class NamespaceItemDialog : public ModalDialog
+    class NamespaceItemDialog : public weld::GenericDialogController
     {
     private:
-        VclPtr<SvSimpleTable>      m_pNamespacesList;
-        VclPtr<PushButton>         m_pAddNamespaceBtn;
-        VclPtr<PushButton>         m_pEditNamespaceBtn;
-        VclPtr<PushButton>         m_pDeleteNamespaceBtn;
-        VclPtr<OKButton>           m_pOKBtn;
-
         VclPtr<AddConditionDialog> m_pConditionDlg;
         std::vector< OUString >    m_aRemovedList;
 
         css::uno::Reference< css::container::XNameContainer >&
                                    m_rNamespaces;
 
-        DECL_LINK(    SelectHdl, SvTreeListBox*, void );
-        DECL_LINK(    ClickHdl, Button*, void );
-        DECL_LINK(    OKHdl, Button*, void);
+        std::unique_ptr<weld::TreeView> m_xNamespacesList;
+        std::unique_ptr<weld::Button> m_xAddNamespaceBtn;
+        std::unique_ptr<weld::Button> m_xEditNamespaceBtn;
+        std::unique_ptr<weld::Button> m_xDeleteNamespaceBtn;
+        std::unique_ptr<weld::Button> m_xOKBtn;
+
+        DECL_LINK(SelectHdl, weld::TreeView&, void);
+        DECL_LINK(ClickHdl, weld::Button&, void);
+        DECL_LINK(OKHdl, weld::Button&, void);
 
         void                LoadNamespaces();
 
     public:
-        NamespaceItemDialog( AddConditionDialog* pParent, css::uno::Reference< css::container::XNameContainer >& _rContainer );
+        NamespaceItemDialog(AddConditionDialog* pParent, css::uno::Reference< css::container::XNameContainer >& _rContainer);
         virtual ~NamespaceItemDialog() override;
-        virtual void dispose() override;
     };
 
     class ManageNamespaceDialog : public weld::GenericDialogController
diff --git a/svx/uiconfig/ui/namespacedialog.ui b/svx/uiconfig/ui/namespacedialog.ui
index f110b1e6a539..9542213eb9ae 100644
--- a/svx/uiconfig/ui/namespacedialog.ui
+++ b/svx/uiconfig/ui/namespacedialog.ui
@@ -1,14 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.18.3 -->
+<!-- Generated with glade 3.22.1 -->
 <interface domain="svx">
   <requires lib="gtk+" version="3.18"/>
-  <requires lib="LibreOffice" version="1.0"/>
+  <object class="GtkTreeStore" id="liststore1">
+    <columns>
+      <!-- column-name text -->
+      <column type="gchararray"/>
+      <!-- column-name text2 -->
+      <column type="gchararray"/>
+      <!-- column-name id -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
   <object class="GtkDialog" id="NamespaceDialog">
     <property name="can_focus">False</property>
     <property name="border_width">6</property>
     <property name="title" translatable="yes" context="namespacedialog|NamespaceDialog">Namespaces for Forms</property>
     <property name="resizable">False</property>
     <property name="type_hint">dialog</property>
+    <child>
+      <placeholder/>
+    </child>
     <child internal-child="vbox">
       <object class="GtkBox" id="dialog-vbox1">
         <property name="can_focus">False</property>
@@ -150,59 +162,53 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkGrid" id="grid2">
+                      <object class="GtkScrolledWindow">
                         <property name="visible">True</property>
-                        <property name="can_focus">False</property>
+                        <property name="can_focus">True</property>
                         <property name="hexpand">True</property>
                         <property name="vexpand">True</property>
-                        <property name="row_spacing">6</property>
+                        <property name="shadow_type">in</property>
                         <child>
-                          <object class="GtkGrid" id="grid3">
-                            <property name="can_focus">False</property>
-                            <property name="no_show_all">True</property>
-                            <property name="column_homogeneous">True</property>
+                          <object class="GtkTreeView" id="namespaces">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">True</property>
+                            <property name="hexpand">True</property>
+                            <property name="vexpand">True</property>
+                            <property name="model">liststore1</property>
+                            <property name="search_column">0</property>
+                            <property name="headers_visible">True</property>
+                            <property name="show_expanders">False</property>
+                            <child internal-child="selection">
+                              <object class="GtkTreeSelection" id="Macro Library List-selection2"/>
+                            </child>
                             <child>
-                              <object class="GtkLabel" id="prefix">
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="label" translatable="yes" context="namespacedialog|prefix">Prefix</property>
+                              <object class="GtkTreeViewColumn" id="treeviewcolumn3">
+                                <property name="resizable">True</property>
+                                <property name="spacing">6</property>
+                                <property name="title" translatable="yes" context="namespacedialog|prefix">Prefix</property>
+                                <child>
+                                  <object class="GtkCellRendererText" id="cellrenderer1"/>
+                                  <attributes>
+                                    <attribute name="text">0</attribute>
+                                  </attributes>
+                                </child>
                               </object>
-                              <packing>
-                                <property name="left_attach">0</property>
-                                <property name="top_attach">0</property>
-                              </packing>
                             </child>
                             <child>
-                              <object class="GtkLabel" id="url">
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="label" translatable="yes" context="namespacedialog|url">URL</property>
+                              <object class="GtkTreeViewColumn" id="treeviewcolumn4">
+                                <property name="resizable">True</property>
+                                <property name="spacing">6</property>
+                                <property name="title" translatable="yes" context="namespacedialog|url">URL</property>
+                                <child>
+                                  <object class="GtkCellRendererText" id="cellrenderer2"/>
+                                  <attributes>
+                                    <attribute name="text">1</attribute>
+                                  </attributes>
+                                </child>
                               </object>
-                              <packing>
-                                <property name="left_attach">1</property>
-                                <property name="top_attach">0</property>
-                              </packing>
-                            </child>
-                          </object>
-                          <packing>
-                            <property name="left_attach">0</property>
-                            <property name="top_attach">0</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="svtlo-SvSimpleTableContainer" id="namespaces">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="hexpand">True</property>
-                            <property name="vexpand">True</property>
-                            <child internal-child="selection">
-                              <object class="GtkTreeSelection" id="Simple Table Container-selection1"/>
                             </child>
                           </object>
-                          <packing>
-                            <property name="left_attach">0</property>
-                            <property name="top_attach">1</property>
-                          </packing>
                         </child>
                       </object>
                       <packing>


More information about the Libreoffice-commits mailing list