Kaydet (Commit) 69e890b1 authored tarafından Caolán McNamara's avatar Caolán McNamara

weld ODatasourceSelectDialog

Change-Id: I33a45f6d68c4a6cba63301dbb6c94ea661365a9a
Reviewed-on: https://gerrit.libreoffice.org/68651
Tested-by: Jenkins
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 4a88213b
......@@ -310,16 +310,16 @@ namespace dbaui
aProfiles.insert(pArray[index]);
// execute the select dialog
ScopedVclPtrInstance< ODatasourceSelectDialog > aSelector(GetParent(), aProfiles);
ODatasourceSelectDialog aSelector(GetFrameWeld(), aProfiles);
OUString sOldProfile=getURLNoPrefix();
if (!sOldProfile.isEmpty())
aSelector->Select(sOldProfile);
aSelector.Select(sOldProfile);
else
aSelector->Select(xMozillaBootstrap->getDefaultProfile(profileType));
aSelector.Select(xMozillaBootstrap->getDefaultProfile(profileType));
if ( RET_OK == aSelector->Execute() )
setURLNoPrefix(aSelector->GetSelected());
if (RET_OK == aSelector.run())
setURLNoPrefix(aSelector.GetSelected());
break;
}
case ::dbaccess::DST_FIREBIRD:
......
......@@ -168,11 +168,11 @@ namespace dbaui
{
aEnumeration.getDatasourceNames(aOdbcDatasources);
// execute the select dialog
ScopedVclPtrInstance< ODatasourceSelectDialog > aSelector(GetParent(), aOdbcDatasources);
ODatasourceSelectDialog aSelector(GetFrameWeld(), aOdbcDatasources);
if (!_sCurr.isEmpty())
aSelector->Select(_sCurr);
if ( RET_OK == aSelector->Execute() )
_sReturn = aSelector->GetSelected();
aSelector.Select(_sCurr);
if (RET_OK == aSelector.run())
_sReturn = aSelector.GetSelected();
}
return true;
}
......
......@@ -42,115 +42,101 @@ using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::comphelper;
ODatasourceSelectDialog::ODatasourceSelectDialog(vcl::Window* _pParent, const std::set<OUString>& _rDatasources)
: ModalDialog(_pParent, "ChooseDataSourceDialog",
"dbaccess/ui/choosedatasourcedialog.ui")
ODatasourceSelectDialog::ODatasourceSelectDialog(weld::Window* _pParent, const std::set<OUString>& _rDatasources)
: GenericDialogController(_pParent, "dbaccess/ui/choosedatasourcedialog.ui", "ChooseDataSourceDialog")
, m_xDatasource(m_xBuilder->weld_tree_view("treeview"))
, m_xOk(m_xBuilder->weld_button("ok"))
, m_xCancel(m_xBuilder->weld_button("cancel"))
, m_xManageDatasources(m_xBuilder->weld_button("organize"))
{
get(m_pDatasource, "treeview");
m_pDatasource->set_height_request(m_pDatasource->GetTextHeight() * 6);
get(m_pOk, "ok");
get(m_pCancel, "cancel");
m_xDatasource->set_size_request(-1, m_xDatasource->get_height_rows(6));
fillListBox(_rDatasources);
#ifdef HAVE_ODBC_ADMINISTRATION
get(m_pManageDatasources, "organize");
m_pManageDatasources->Show();
// allow ODBC datasource management
m_pManageDatasources->Show();
m_pManageDatasources->Enable();
m_pManageDatasources->SetClickHdl(LINK(this,ODatasourceSelectDialog,ManageClickHdl));
m_xManageDatasources->show();
m_xManageDatasources->set_sensitive(true);
m_xManageDatasources->connect_clicked(LINK(this,ODatasourceSelectDialog,ManageClickHdl));
#endif
m_pDatasource->SetDoubleClickHdl(LINK(this,ODatasourceSelectDialog,ListDblClickHdl));
m_xDatasource->connect_row_activated(LINK(this,ODatasourceSelectDialog,ListDblClickHdl));
}
ODatasourceSelectDialog::~ODatasourceSelectDialog()
{
disposeOnce();
}
void ODatasourceSelectDialog::dispose()
{
m_pDatasource.clear();
m_pOk.clear();
m_pCancel.clear();
#if defined HAVE_ODBC_ADMINISTRATION
m_pManageDatasources.clear();
#endif
ModalDialog::dispose();
}
IMPL_LINK( ODatasourceSelectDialog, ListDblClickHdl, ListBox&, rListBox, void )
IMPL_LINK(ODatasourceSelectDialog, ListDblClickHdl, weld::TreeView&, rListBox, void)
{
if (rListBox.GetSelectedEntryCount())
EndDialog(RET_OK);
if (rListBox.n_children())
m_xDialog->response(RET_OK);
}
bool ODatasourceSelectDialog::Close()
short ODatasourceSelectDialog::run()
{
short nRet = GenericDialogController::run();
#ifdef HAVE_ODBC_ADMINISTRATION
if ( m_pODBCManagement.get() && m_pODBCManagement->isRunning() )
return false;
if (m_xODBCManagement.get())
m_xODBCManagement->disableCallback();
#endif
return ModalDialog::Close();
return nRet;
}
#ifdef HAVE_ODBC_ADMINISTRATION
IMPL_LINK_NOARG(ODatasourceSelectDialog, ManageClickHdl, Button*, void)
IMPL_LINK_NOARG(ODatasourceSelectDialog, ManageClickHdl, weld::Button&, void)
{
if ( !m_pODBCManagement.get() )
m_pODBCManagement.reset( new OOdbcManagement( LINK( this, ODatasourceSelectDialog, ManageProcessFinished ) ) );
if ( !m_xODBCManagement.get() )
m_xODBCManagement.reset( new OOdbcManagement( LINK( this, ODatasourceSelectDialog, ManageProcessFinished ) ) );
if ( !m_pODBCManagement->manageDataSources_async() )
if ( !m_xODBCManagement->manageDataSources_async() )
{
// TODO: error message
m_pDatasource->GrabFocus();
m_pManageDatasources->Disable();
m_xDatasource->grab_focus();
m_xManageDatasources->set_sensitive(false);
return;
}
m_pDatasource->Disable();
m_pOk->Disable();
m_pCancel->Disable();
m_pManageDatasources->Disable();
m_xDatasource->set_sensitive(false);
m_xOk->set_sensitive(false);
m_xCancel->set_sensitive(false);
m_xManageDatasources->set_sensitive(false);
SAL_WARN_IF( !m_pODBCManagement->isRunning(), "dbaccess.ui", "ODatasourceSelectDialog::ManageClickHdl: success, but not running - you were *fast*!" );
SAL_WARN_IF( !m_xODBCManagement->isRunning(), "dbaccess.ui", "ODatasourceSelectDialog::ManageClickHdl: success, but not running - you were *fast*!" );
}
IMPL_LINK_NOARG( ODatasourceSelectDialog, ManageProcessFinished, void*, void )
{
m_xODBCManagement->receivedCallback();
std::set<OUString> aOdbcDatasources;
OOdbcEnumeration aEnumeration;
aEnumeration.getDatasourceNames( aOdbcDatasources );
fillListBox( aOdbcDatasources );
m_pDatasource->Enable();
m_pOk->Enable();
m_pCancel->Enable();
m_pManageDatasources->Enable();
m_xDatasource->set_sensitive(true);
m_xOk->set_sensitive(true);
m_xCancel->set_sensitive(true);
m_xManageDatasources->set_sensitive(true);
}
#endif
void ODatasourceSelectDialog::fillListBox(const std::set<OUString>& _rDatasources)
{
OUString sSelected;
if (m_pDatasource->GetEntryCount())
sSelected = m_pDatasource->GetSelectedEntry();
m_pDatasource->Clear();
if (m_xDatasource->n_children())
sSelected = m_xDatasource->get_selected_text();
m_xDatasource->clear();
// fill the list
for (auto const& datasource : _rDatasources)
{
m_pDatasource->InsertEntry(datasource);
m_xDatasource->append_text(datasource);
}
if (m_pDatasource->GetEntryCount())
if (m_xDatasource->n_children())
{
if (!sSelected.isEmpty())
m_pDatasource->SelectEntry(sSelected);
m_xDatasource->select_text(sSelected);
else // select the first entry
m_pDatasource->SelectEntryPos(0);
m_xDatasource->select(0);
}
}
......
......@@ -24,11 +24,8 @@
#include "odbcconfig.hxx"
#include <commontypes.hxx>
#include <vcl/dialog.hxx>
#include <vcl/lstbox.hxx>
#include <vcl/button.hxx>
#include <vcl/fixed.hxx>
#include <rtl/ustring.hxx>
#include <vcl/weld.hxx>
#include <memory>
......@@ -37,35 +34,33 @@ namespace dbaui
{
// ODatasourceSelector
class ODatasourceSelectDialog final : public ModalDialog
class ODatasourceSelectDialog final : public weld::GenericDialogController
{
VclPtr<ListBox> m_pDatasource;
VclPtr<OKButton> m_pOk;
VclPtr<CancelButton> m_pCancel;
std::unique_ptr<weld::TreeView> m_xDatasource;
std::unique_ptr<weld::Button> m_xOk;
std::unique_ptr<weld::Button> m_xCancel;
std::unique_ptr<weld::Button> m_xManageDatasources;
#ifdef HAVE_ODBC_ADMINISTRATION
VclPtr<PushButton> m_pManageDatasources;
std::unique_ptr< OOdbcManagement >
m_pODBCManagement;
std::unique_ptr<OOdbcManagement> m_xODBCManagement;
#endif
public:
ODatasourceSelectDialog( vcl::Window* _pParent, const std::set<OUString>& _rDatasources );
ODatasourceSelectDialog(weld::Window* pParent, const std::set<OUString>& rDatasources);
virtual ~ODatasourceSelectDialog() override;
virtual void dispose() override;
OUString GetSelected() const {
return m_pDatasource->GetSelectedEntry();
return m_xDatasource->get_selected_text();
}
void Select( const OUString& _rEntry ) {
m_pDatasource->SelectEntry(_rEntry);
m_xDatasource->select_text(_rEntry);
}
virtual bool Close() override;
virtual short run() override;
private:
DECL_LINK( ListDblClickHdl, ListBox&, void );
DECL_LINK( ListDblClickHdl, weld::TreeView&, void );
#ifdef HAVE_ODBC_ADMINISTRATION
DECL_LINK(ManageClickHdl, Button*, void);
DECL_LINK( ManageProcessFinished, void*, void );
DECL_LINK(ManageClickHdl, weld::Button&, void);
DECL_LINK(ManageProcessFinished, void*, void);
#endif
void fillListBox(const std::set<OUString>& _rDatasources);
};
......
......@@ -233,14 +233,33 @@ class ProcessTerminationWait : public ::osl::Thread
{
oslProcess m_hProcessHandle;
Link<void*,void> m_aFinishHdl;
ImplSVEvent* m_nEventId;
public:
ProcessTerminationWait( oslProcess _hProcessHandle, const Link<void*,void>& _rFinishHdl )
:m_hProcessHandle( _hProcessHandle )
,m_aFinishHdl( _rFinishHdl )
: m_hProcessHandle( _hProcessHandle )
, m_aFinishHdl( _rFinishHdl )
, m_nEventId(nullptr)
{
}
void disableCallback()
{
// if finished event not posted yet, disable by turning it to a no-op Link
m_aFinishHdl = Link<void*, void>();
if (m_nEventId)
{
// already posted, remove it
Application::RemoveUserEvent(m_nEventId);
m_nEventId = nullptr;
}
}
void receivedCallback()
{
m_nEventId = nullptr;
}
protected:
virtual void SAL_CALL run() override
{
......@@ -248,7 +267,7 @@ protected:
osl_joinProcess( m_hProcessHandle );
osl_freeProcessHandle( m_hProcessHandle );
Application::PostUserEvent( m_aFinishHdl );
m_nEventId = Application::PostUserEvent( m_aFinishHdl );
}
};
......@@ -285,6 +304,18 @@ bool OOdbcManagement::manageDataSources_async()
return true;
}
void OOdbcManagement::disableCallback()
{
if (m_pProcessWait.get())
m_pProcessWait->disableCallback();
}
void OOdbcManagement::receivedCallback()
{
if (m_pProcessWait.get())
m_pProcessWait->receivedCallback();
}
bool OOdbcManagement::isRunning() const
{
return ( m_pProcessWait.get() && m_pProcessWait->isRunning() );
......
......@@ -90,7 +90,7 @@ class ProcessTerminationWait;
class OOdbcManagement
{
std::unique_ptr< ProcessTerminationWait > m_pProcessWait;
Link<void*,void> m_aAsyncFinishCallback;
Link<void*,void> m_aAsyncFinishCallback;
public:
explicit OOdbcManagement( const Link<void*,void>& _rAsyncFinishCallback );
......@@ -98,6 +98,8 @@ public:
bool manageDataSources_async();
bool isRunning() const;
void disableCallback();
void receivedCallback();
};
#endif
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<!-- Generated with glade 3.22.1 -->
<interface domain="dba">
<requires lib="gtk+" version="3.18"/>
<object class="GtkTreeStore" id="liststore2">
<columns>
<!-- column-name text -->
<column type="gchararray"/>
<!-- column-name id -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkDialog" id="ChooseDataSourceDialog">
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="title" translatable="yes" context="choosedatasourcedialog|ChooseDataSourceDialog">Data Source</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="default_width">0</property>
<property name="default_height">0</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>
......@@ -96,10 +110,10 @@
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes" context="choosedatasourcedialog|label1">Choose a data source:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">treeview:border</property>
<property name="mnemonic_widget">treeview</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
......@@ -107,14 +121,39 @@
</packing>
</child>
<child>
<object class="GtkTreeView" id="treeview:border">
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="show_expanders">False</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection1"/>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="treeview">
<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">liststore2</property>
<property name="headers_visible">False</property>
<property name="search_column">1</property>
<property name="show_expanders">False</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="Macro Library List-selection2"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn5">
<property name="resizable">True</property>
<property name="spacing">6</property>
<child>
<object class="GtkCellRendererText" id="cellrenderer4"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
......@@ -135,6 +174,7 @@
<action-widget response="-5">ok</action-widget>
<action-widget response="-6">cancel</action-widget>
<action-widget response="-11">help</action-widget>
<action-widget response="101">organize</action-widget>
</action-widgets>
</object>
</interface>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment