Kaydet (Commit) 3963bab7 authored tarafından Caolán McNamara's avatar Caolán McNamara

weld SwCreateAddressListDialog

Change-Id: I3ae15af8a2c7475394dfc5f6e54b89950d2238c0
Reviewed-on: https://gerrit.libreoffice.org/68511
Tested-by: Jenkins
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst b164e74e
...@@ -71,9 +71,6 @@ using namespace ::com::sun::star::task; ...@@ -71,9 +71,6 @@ using namespace ::com::sun::star::task;
using namespace ::com::sun::star::beans; using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::ui::dialogs; using namespace ::com::sun::star::ui::dialogs;
#define ITEMID_NAME 1
#define ITEMID_TABLE 2
struct AddressUserData_Impl struct AddressUserData_Impl
{ {
uno::Reference<XDataSource> xSource; uno::Reference<XDataSource> xSource;
...@@ -125,90 +122,52 @@ static OUString lcl_getFlatURL( uno::Reference<beans::XPropertySet> const & xSou ...@@ -125,90 +122,52 @@ static OUString lcl_getFlatURL( uno::Reference<beans::XPropertySet> const & xSou
return OUString(); return OUString();
} }
class SwAddrSourceLB : public SvSimpleTable SwAddressListDialog::SwAddressListDialog(SwMailMergeAddressBlockPage* pParent)
{ : SfxDialogController(pParent->GetFrameWeld(), "modules/swriter/ui/selectaddressdialog.ui", "SelectAddressDialog")
public: , m_bInSelectHdl(false)
explicit SwAddrSourceLB(SvSimpleTableContainer& rParent) , m_xAddressPage(pParent)
: SvSimpleTable(rParent, 0) , m_xDescriptionFI(m_xBuilder->weld_label("desc"))
{ , m_xConnecting(m_xBuilder->weld_label("connecting"))
} , m_xListLB(m_xBuilder->weld_tree_view("sources"))
virtual void Resize() override; , m_xLoadListPB(m_xBuilder->weld_button("add"))
void setColSizes(); , m_xCreateListPB(m_xBuilder->weld_button("create"))
}; , m_xFilterPB(m_xBuilder->weld_button("filter"))
, m_xEditPB(m_xBuilder->weld_button("edit"))
void SwAddrSourceLB::Resize() , m_xTablePB(m_xBuilder->weld_button("changetable"))
{ , m_xOK(m_xBuilder->weld_button("ok"))
SvSimpleTable::Resize(); , m_xIter(m_xListLB->make_iterator())
setColSizes();
}
void SwAddrSourceLB::setColSizes()
{ {
HeaderBar &rHB = GetTheHeaderBar(); m_sConnecting = m_xConnecting->get_label();
if (rHB.GetItemCount() < 2)
return;
long nWidth = rHB.GetSizePixel().Width(); const OUString sTemp(m_xDescriptionFI->get_label()
.replaceFirst("%1", m_xLoadListPB->get_label())
.replaceFirst("%2", m_xCreateListPB->get_label()));
m_xDescriptionFI->set_label(sTemp);
m_xFilterPB->connect_clicked( LINK( this, SwAddressListDialog, FilterHdl_Impl ));
m_xLoadListPB->connect_clicked( LINK( this, SwAddressListDialog, LoadHdl_Impl ));
m_xCreateListPB->connect_clicked( LINK( this, SwAddressListDialog,CreateHdl_Impl ));
m_xEditPB->connect_clicked(LINK( this, SwAddressListDialog, EditHdl_Impl));
m_xTablePB->connect_clicked(LINK( this, SwAddressListDialog, TableSelectHdl_Impl));
long nTabs[] = { 0, nWidth/2 }; m_xListLB->set_size_request(m_xListLB->get_approximate_digit_width() * 52,
m_xListLB->get_height_rows(9));
SvSimpleTable::SetTabs(SAL_N_ELEMENTS(nTabs), nTabs, MapUnit::MapPixel); std::vector<int> aWidths;
} aWidths.push_back(m_xListLB->get_approximate_digit_width() * 26);
m_xListLB->set_column_fixed_widths(aWidths);
SwAddressListDialog::SwAddressListDialog(SwMailMergeAddressBlockPage* pParent)
: SfxModalDialog(pParent, "SelectAddressDialog",
"modules/swriter/ui/selectaddressdialog.ui")
, m_xListLB->make_sorted();
m_xOK->connect_clicked(LINK(this, SwAddressListDialog, OKHdl_Impl));
m_pCreatedDataSource(nullptr),
m_bInSelectHdl(false),
m_pAddressPage(pParent)
{
get(m_pDescriptionFI, "desc");
get(m_pLoadListPB, "add");
get(m_pCreateListPB, "create");
get(m_pFilterPB, "filter");
get(m_pEditPB, "edit");
get(m_pTablePB, "changetable");
get(m_pOK, "ok");
OUString sName = get<FixedText>("name")->GetText();
OUString sTable = get<FixedText>("table")->GetText();
m_sConnecting = get<FixedText>("connecting")->GetText();
const OUString sTemp(m_pDescriptionFI->GetText()
.replaceFirst("%1", m_pLoadListPB->GetText())
.replaceFirst("%2", m_pCreateListPB->GetText()));
m_pDescriptionFI->SetText(sTemp);
m_pFilterPB->SetClickHdl( LINK( this, SwAddressListDialog, FilterHdl_Impl ));
m_pLoadListPB->SetClickHdl( LINK( this, SwAddressListDialog, LoadHdl_Impl ));
m_pCreateListPB->SetClickHdl( LINK( this, SwAddressListDialog,CreateHdl_Impl ));
m_pEditPB->SetClickHdl(LINK( this, SwAddressListDialog, EditHdl_Impl));
m_pTablePB->SetClickHdl(LINK( this, SwAddressListDialog, TableSelectHdl_Impl));
SvSimpleTableContainer *pHeaderTreeContainer = get<SvSimpleTableContainer>("sources");
Size aSize = pHeaderTreeContainer->LogicToPixel(Size(182 , 102), MapMode(MapUnit::MapAppFont));
pHeaderTreeContainer->set_width_request(aSize.Width());
pHeaderTreeContainer->set_height_request(aSize.Height());
m_pListLB = VclPtr<SwAddrSourceLB>::Create(*pHeaderTreeContainer);
m_pListLB->InsertHeaderEntry(sName + "\t" + sTable);
m_pListLB->setColSizes();
m_pListLB->SetStyle( m_pListLB->GetStyle() | WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP );
m_pListLB->SetSelectionMode( SelectionMode::Single );
m_pOK->SetClickHdl( LINK( this, SwAddressListDialog, OKHdl_Impl));
uno::Reference<XComponentContext> xContext( ::comphelper::getProcessComponentContext() ); uno::Reference<XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
m_xDBContext = DatabaseContext::create(xContext); m_xDBContext = DatabaseContext::create(xContext);
SwMailMergeConfigItem& rConfigItem = m_pAddressPage->GetWizard()->GetConfigItem(); SwMailMergeConfigItem& rConfigItem = m_xAddressPage->GetWizard()->GetConfigItem();
const SwDBData& rCurrentData = rConfigItem.GetCurrentDBData(); const SwDBData& rCurrentData = rConfigItem.GetCurrentDBData();
bool bEnableEdit = false; bool bEnableEdit = false;
bool bEnableOK = true; bool bEnableOK = true;
m_pListLB->SelectAll( false ); m_xListLB->unselect_all();
SwDBConfig aDb; SwDBConfig aDb;
const OUString sBibliography = aDb.GetBibliographySource().sDataSource; const OUString sBibliography = aDb.GetBibliographySource().sDataSource;
...@@ -218,13 +177,15 @@ SwAddressListDialog::SwAddressListDialog(SwMailMergeAddressBlockPage* pParent) ...@@ -218,13 +177,15 @@ SwAddressListDialog::SwAddressListDialog(SwMailMergeAddressBlockPage* pParent)
{ {
if ( pNames[nName] == sBibliography ) if ( pNames[nName] == sBibliography )
continue; continue;
SvTreeListEntry* pEntry = m_pListLB->InsertEntry(pNames[nName]); m_xListLB->append(m_xIter.get());
AddressUserData_Impl* pUserData = new AddressUserData_Impl(); m_xListLB->set_text(*m_xIter, pNames[nName], 0);
pEntry->SetUserData(pUserData); m_aUserData.emplace_back(new AddressUserData_Impl);
if(pNames[nName] == rCurrentData.sDataSource) AddressUserData_Impl* pUserData = m_aUserData.back().get();
m_xListLB->set_id(*m_xIter, OUString::number(reinterpret_cast<sal_Int64>(pUserData)));
if (pNames[nName] == rCurrentData.sDataSource)
{ {
m_pListLB->Select(pEntry); m_xListLB->select(*m_xIter);
m_pListLB->SetEntryText(rCurrentData.sCommand, pEntry, ITEMID_TABLE - 1); m_xListLB->set_text(*m_xIter, rCurrentData.sCommand, 1);
pUserData->nCommandType = rCurrentData.nCommandType; pUserData->nCommandType = rCurrentData.nCommandType;
pUserData->xSource = rConfigItem.GetSource(); pUserData->xSource = rConfigItem.GetSource();
pUserData->xConnection = rConfigItem.GetConnection(); pUserData->xConnection = rConfigItem.GetConnection();
...@@ -249,50 +210,28 @@ SwAddressListDialog::SwAddressListDialog(SwMailMergeAddressBlockPage* pParent) ...@@ -249,50 +210,28 @@ SwAddressListDialog::SwAddressListDialog(SwMailMergeAddressBlockPage* pParent)
} }
} }
m_pOK->Enable(m_pListLB->GetEntryCount()>0 && bEnableOK); m_xOK->set_sensitive(m_xListLB->n_children() > 0 && bEnableOK);
m_pEditPB->Enable(bEnableEdit); m_xEditPB->set_sensitive(bEnableEdit);
m_pListLB->SetSelectHdl(LINK(this, SwAddressListDialog, ListBoxSelectHdl_Impl)); m_xListLB->connect_changed(LINK(this, SwAddressListDialog, ListBoxSelectHdl_Impl));
TableSelectHdl_Impl(nullptr); TableSelectHdl(nullptr);
} }
SwAddressListDialog::~SwAddressListDialog() SwAddressListDialog::~SwAddressListDialog()
{ {
disposeOnce();
}
void SwAddressListDialog::dispose()
{
SvTreeListEntry* pEntry = m_pListLB->First();
while(pEntry)
{
AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pEntry->GetUserData());
delete pUserData;
pEntry = m_pListLB->Next( pEntry );
}
m_pListLB.disposeAndClear();
m_pAddressPage.clear();
m_pDescriptionFI.clear();
m_pLoadListPB.clear();
m_pCreateListPB.clear();
m_pFilterPB.clear();
m_pEditPB.clear();
m_pTablePB.clear();
m_pOK.clear();
SfxModalDialog::dispose();
} }
IMPL_LINK_NOARG(SwAddressListDialog, FilterHdl_Impl, Button*, void) IMPL_LINK_NOARG(SwAddressListDialog, FilterHdl_Impl, weld::Button&, void)
{ {
SvTreeListEntry* pSelect = m_pListLB->FirstSelected(); int nSelect = m_xListLB->get_selected_index();
uno::Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() ); uno::Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
if(pSelect) if (nSelect != -1)
{ {
const OUString sCommand = SvTabListBox::GetEntryText(pSelect, ITEMID_TABLE - 1); const OUString sCommand = m_xListLB->get_text(nSelect, 1);
if (sCommand.isEmpty()) if (sCommand.isEmpty())
return; return;
AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData()); AddressUserData_Impl* pUserData = reinterpret_cast<AddressUserData_Impl*>(m_xListLB->get_id(nSelect).toInt64());
if(pUserData->xConnection.is() ) if (pUserData->xConnection.is() )
{ {
try try
{ {
...@@ -304,7 +243,7 @@ IMPL_LINK_NOARG(SwAddressListDialog, FilterHdl_Impl, Button*, void) ...@@ -304,7 +243,7 @@ IMPL_LINK_NOARG(SwAddressListDialog, FilterHdl_Impl, Button*, void)
xMgr->createInstance("com.sun.star.sdb.RowSet"), UNO_QUERY); xMgr->createInstance("com.sun.star.sdb.RowSet"), UNO_QUERY);
uno::Reference<XPropertySet> xRowProperties(xRowSet, UNO_QUERY); uno::Reference<XPropertySet> xRowProperties(xRowSet, UNO_QUERY);
xRowProperties->setPropertyValue("DataSourceName", xRowProperties->setPropertyValue("DataSourceName",
makeAny(SvTabListBox::GetEntryText(pSelect, ITEMID_NAME - 1))); makeAny(m_xListLB->get_text(nSelect, 0)));
xRowProperties->setPropertyValue("Command", makeAny(sCommand)); xRowProperties->setPropertyValue("Command", makeAny(sCommand));
xRowProperties->setPropertyValue("CommandType", makeAny(pUserData->nCommandType)); xRowProperties->setPropertyValue("CommandType", makeAny(pUserData->nCommandType));
xRowProperties->setPropertyValue("ActiveConnection", makeAny(pUserData->xConnection.getTyped())); xRowProperties->setPropertyValue("ActiveConnection", makeAny(pUserData->xConnection.getTyped()));
...@@ -321,7 +260,7 @@ IMPL_LINK_NOARG(SwAddressListDialog, FilterHdl_Impl, Button*, void) ...@@ -321,7 +260,7 @@ IMPL_LINK_NOARG(SwAddressListDialog, FilterHdl_Impl, Button*, void)
if ( RET_OK == xDialog->execute() ) if ( RET_OK == xDialog->execute() )
{ {
WaitObject aWO( nullptr ); weld::WaitObject aWait(m_xDialog.get());
pUserData->sFilter = xComposer->getFilter(); pUserData->sFilter = xComposer->getFilter();
} }
::comphelper::disposeComponent(xRowSet); ::comphelper::disposeComponent(xRowSet);
...@@ -334,23 +273,27 @@ IMPL_LINK_NOARG(SwAddressListDialog, FilterHdl_Impl, Button*, void) ...@@ -334,23 +273,27 @@ IMPL_LINK_NOARG(SwAddressListDialog, FilterHdl_Impl, Button*, void)
} }
} }
IMPL_LINK_NOARG(SwAddressListDialog, LoadHdl_Impl, Button*, void) IMPL_LINK_NOARG(SwAddressListDialog, LoadHdl_Impl, weld::Button&, void)
{ {
SwView* pView = m_pAddressPage->GetWizard()->GetSwView(); SwView* pView = m_xAddressPage->GetWizard()->GetSwView();
const OUString sNewSource = SwDBManager::LoadAndRegisterDataSource(GetFrameWeld(), pView ? pView->GetDocShell() : nullptr); const OUString sNewSource = SwDBManager::LoadAndRegisterDataSource(m_xDialog.get(), pView ? pView->GetDocShell() : nullptr);
if(!sNewSource.isEmpty()) if(!sNewSource.isEmpty())
{ {
SvTreeListEntry* pNewSource = m_pListLB->InsertEntry(sNewSource); m_xListLB->append(m_xIter.get());
pNewSource->SetUserData(new AddressUserData_Impl()); m_xListLB->set_text(*m_xIter, sNewSource, 0);
m_pListLB->Select(pNewSource); m_aUserData.emplace_back(new AddressUserData_Impl);
AddressUserData_Impl* pUserData = m_aUserData.back().get();
m_xListLB->set_id(*m_xIter, OUString::number(reinterpret_cast<sal_Int64>(pUserData)));
m_xListLB->select(*m_xIter);
ListBoxSelectHdl_Impl(*m_xListLB);
} }
} }
IMPL_LINK_NOARG(SwAddressListDialog, CreateHdl_Impl, Button*, void) IMPL_LINK_NOARG(SwAddressListDialog, CreateHdl_Impl, weld::Button&, void)
{ {
OUString sInputURL; OUString sInputURL;
SwCreateAddressListDialog aDlg(GetFrameWeld(), sInputURL, m_pAddressPage->GetWizard()->GetConfigItem()); SwCreateAddressListDialog aDlg(m_xDialog.get(), sInputURL, m_xAddressPage->GetWizard()->GetConfigItem());
if (RET_OK == aDlg.run()) if (RET_OK == aDlg.run())
{ {
//register the URL a new datasource //register the URL a new datasource
...@@ -407,13 +350,15 @@ IMPL_LINK_NOARG(SwAddressListDialog, CreateHdl_Impl, Button*, void) ...@@ -407,13 +350,15 @@ IMPL_LINK_NOARG(SwAddressListDialog, CreateHdl_Impl, Button*, void)
uno::Reference<XNamingService> xNaming(m_xDBContext, UNO_QUERY); uno::Reference<XNamingService> xNaming(m_xDBContext, UNO_QUERY);
xNaming->registerObject( sFind, xNewInstance ); xNaming->registerObject( sFind, xNewInstance );
//now insert the new source into the ListBox //now insert the new source into the ListBox
m_pCreatedDataSource = m_pListLB->InsertEntry(sFind + "\t" + aFilters[0]); m_xListLB->append(m_xIter.get());
AddressUserData_Impl* pUserData = new AddressUserData_Impl(); m_xListLB->set_text(*m_xIter, sFind, 0);
pUserData->sURL = sURL; m_xListLB->set_text(*m_xIter, aFilters[0], 1);
m_pCreatedDataSource->SetUserData(pUserData); m_aUserData.emplace_back(new AddressUserData_Impl);
m_pListLB->Select(m_pCreatedDataSource); AddressUserData_Impl* pUserData = m_aUserData.back().get();
m_pCreateListPB->Enable(false); m_xListLB->set_id(*m_xIter, OUString::number(reinterpret_cast<sal_Int64>(pUserData)));
m_xListLB->select(*m_xIter);
ListBoxSelectHdl_Impl(*m_xListLB);
m_xCreateListPB->set_sensitive(false);
} }
catch (const Exception&) catch (const Exception&)
{ {
...@@ -421,15 +366,15 @@ IMPL_LINK_NOARG(SwAddressListDialog, CreateHdl_Impl, Button*, void) ...@@ -421,15 +366,15 @@ IMPL_LINK_NOARG(SwAddressListDialog, CreateHdl_Impl, Button*, void)
} }
} }
IMPL_LINK_NOARG(SwAddressListDialog, EditHdl_Impl, Button*, void) IMPL_LINK_NOARG(SwAddressListDialog, EditHdl_Impl, weld::Button&, void)
{ {
SvTreeListEntry* pEntry = m_pListLB->FirstSelected(); int nEntry = m_xListLB->get_selected_index();
AddressUserData_Impl* pUserData = pEntry ? static_cast<AddressUserData_Impl*>(pEntry->GetUserData()) : nullptr; AddressUserData_Impl* pUserData = nEntry != -1 ? reinterpret_cast<AddressUserData_Impl*>(m_xListLB->get_id(nEntry).toInt64()) : nullptr;
if(pUserData && !pUserData->sURL.isEmpty()) if (pUserData && !pUserData->sURL.isEmpty())
{ {
if(pUserData->xResultSet.is()) if(pUserData->xResultSet.is())
{ {
SwMailMergeConfigItem& rConfigItem = m_pAddressPage->GetWizard()->GetConfigItem(); SwMailMergeConfigItem& rConfigItem = m_xAddressPage->GetWizard()->GetConfigItem();
if(rConfigItem.GetResultSet() != pUserData->xResultSet) if(rConfigItem.GetResultSet() != pUserData->xResultSet)
::comphelper::disposeComponent( pUserData->xResultSet ); ::comphelper::disposeComponent( pUserData->xResultSet );
pUserData->xResultSet = nullptr; pUserData->xResultSet = nullptr;
...@@ -440,87 +385,71 @@ IMPL_LINK_NOARG(SwAddressListDialog, EditHdl_Impl, Button*, void) ...@@ -440,87 +385,71 @@ IMPL_LINK_NOARG(SwAddressListDialog, EditHdl_Impl, Button*, void)
pUserData->xColumnsSupplier.clear(); pUserData->xColumnsSupplier.clear();
pUserData->xConnection.clear(); pUserData->xConnection.clear();
// will automatically close if it was the las reference // will automatically close if it was the las reference
SwCreateAddressListDialog aDlg(GetFrameWeld(), pUserData->sURL, SwCreateAddressListDialog aDlg(m_xDialog.get(), pUserData->sURL,
m_pAddressPage->GetWizard()->GetConfigItem()); m_xAddressPage->GetWizard()->GetConfigItem());
aDlg.run(); aDlg.run();
} }
}; };
IMPL_LINK_NOARG(SwAddressListDialog, ListBoxSelectHdl_Impl, SvTreeListBox*, void) IMPL_LINK_NOARG(SwAddressListDialog, ListBoxSelectHdl_Impl, weld::TreeView&, void)
{ {
SvTreeListEntry* pSelect = m_pListLB->FirstSelected(); int nSelect = m_xListLB->get_selected_index();
Application::PostUserEvent( LINK( this, SwAddressListDialog, Application::PostUserEvent( LINK( this, SwAddressListDialog,
StaticListBoxSelectHdl_Impl ), pSelect, true ); StaticListBoxSelectHdl_Impl ), reinterpret_cast<void*>(nSelect) );
} }
IMPL_LINK(SwAddressListDialog, StaticListBoxSelectHdl_Impl, void*, p, void) IMPL_LINK(SwAddressListDialog, StaticListBoxSelectHdl_Impl, void*, p, void)
{ {
SvTreeListEntry* pSelect = static_cast<SvTreeListEntry*>(p); int nSelect = reinterpret_cast<sal_IntPtr>(p);
//prevent nested calls of the select handler //prevent nested calls of the select handler
if(m_bInSelectHdl) if (m_bInSelectHdl)
return; return;
EnterWait(); weld::WaitObject aWait(m_xDialog.get());
m_bInSelectHdl = true; m_bInSelectHdl = true;
AddressUserData_Impl* pUserData = nullptr; AddressUserData_Impl* pUserData = nullptr;
if(pSelect) if (nSelect != -1)
{ {
const OUString sTable(SvTabListBox::GetEntryText(pSelect, ITEMID_TABLE - 1)); const OUString sTable(m_xListLB->get_text(nSelect, 1));
if(sTable.isEmpty()) if (sTable.isEmpty())
{ {
m_pListLB->SetEntryText(m_sConnecting, pSelect, ITEMID_TABLE - 1); m_xListLB->set_text(nSelect, m_sConnecting, 1);
// allow painting of the new entry
m_pListLB->Window::Invalidate(InvalidateFlags::Update);
Application::Reschedule( true );
} }
pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData()); pUserData = reinterpret_cast<AddressUserData_Impl*>(m_xListLB->get_id(nSelect).toInt64());
if(pUserData->nTableAndQueryCount > 1 || pUserData->nTableAndQueryCount == -1) if(pUserData->nTableAndQueryCount > 1 || pUserData->nTableAndQueryCount == -1)
{ {
/* DetectTablesAndQueries(nSelect, sTable.isEmpty());
* We're a callback from a selection from a list box, which takes
* place on mouse down before mouse up. The next dialog also has a
* list box. Spawning it means this list box doesn't get the mouse
* down event. So it sticks on "making selection" mode. So if you
* cancel the next dialog and just move the mouse out of this entry
* and back then the dialog pops up again, without requiring a click
*
* Most expedient thing to do is to manually end the parent selection
* here.
*/
m_pListLB->EndSelection();
DetectTablesAndQueries(pSelect, sTable.isEmpty());
} }
else else
{ {
//otherwise set the selected db-data //otherwise set the selected db-data
m_aDBData.sDataSource = SvTabListBox::GetEntryText(pSelect, ITEMID_NAME - 1); m_aDBData.sDataSource = m_xListLB->get_text(nSelect, 0);
m_aDBData.sCommand = SvTabListBox::GetEntryText(pSelect, ITEMID_TABLE - 1); m_aDBData.sCommand = m_xListLB->get_text(nSelect, 1);
m_aDBData.nCommandType = pUserData->nCommandType; m_aDBData.nCommandType = pUserData->nCommandType;
m_pOK->Enable(); m_xOK->set_sensitive(true);
} }
if(SvTabListBox::GetEntryText(pSelect, ITEMID_TABLE - 1) == m_sConnecting) if (m_xListLB->get_text(nSelect, 1) == m_sConnecting)
m_pListLB->SetEntryText(OUString(), pSelect, ITEMID_TABLE - 1); m_xListLB->set_text(nSelect, OUString(), 1);
} }
m_pEditPB->Enable(pUserData && !pUserData->sURL.isEmpty() && m_xEditPB->set_sensitive(pUserData && !pUserData->sURL.isEmpty() &&
SWUnoHelper::UCB_IsFile( pUserData->sURL ) && //#i97577# SWUnoHelper::UCB_IsFile( pUserData->sURL ) && //#i97577#
!SWUnoHelper::UCB_IsReadOnlyFileName( pUserData->sURL ) ); !SWUnoHelper::UCB_IsReadOnlyFileName( pUserData->sURL ) );
m_bInSelectHdl = false; m_bInSelectHdl = false;
LeaveWait();
} }
// detect the number of tables for a data source // detect the number of tables for a data source
// if only one is available then set it at the entry // if only one is available then set it at the entry
void SwAddressListDialog::DetectTablesAndQueries( void SwAddressListDialog::DetectTablesAndQueries(
SvTreeListEntry* pSelect, int nSelect,
bool bWidthDialog) bool bWidthDialog)
{ {
try try
{ {
AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData()); AddressUserData_Impl* pUserData = reinterpret_cast<AddressUserData_Impl*>(m_xListLB->get_id(nSelect).toInt64());
uno::Reference<XCompletedConnection> xComplConnection; uno::Reference<XCompletedConnection> xComplConnection;
if(!pUserData->xConnection.is()) if(!pUserData->xConnection.is())
{ {
m_aDBData.sDataSource = SvTabListBox::GetEntryText(pSelect, ITEMID_NAME - 1); m_aDBData.sDataSource = m_xListLB->get_text(nSelect, 0);
m_xDBContext->getByName(m_aDBData.sDataSource) >>= xComplConnection; m_xDBContext->getByName(m_aDBData.sDataSource) >>= xComplConnection;
pUserData->xSource.set(xComplConnection, UNO_QUERY); pUserData->xSource.set(xComplConnection, UNO_QUERY);
...@@ -551,8 +480,8 @@ void SwAddressListDialog::DetectTablesAndQueries( ...@@ -551,8 +480,8 @@ void SwAddressListDialog::DetectTablesAndQueries(
if(nTables > 1 && bWidthDialog) if(nTables > 1 && bWidthDialog)
{ {
//now call the table select dialog - if more than one table exists //now call the table select dialog - if more than one table exists
SwSelectDBTableDialog aDlg(GetFrameWeld(), pUserData->xConnection); SwSelectDBTableDialog aDlg(m_xDialog.get(), pUserData->xConnection);
const OUString sTable = SvTabListBox::GetEntryText(pSelect, ITEMID_TABLE - 1); const OUString sTable = m_xListLB->get_text(nSelect, 1);
if(!sTable.isEmpty()) if(!sTable.isEmpty())
aDlg.SetSelectedTable(sTable, pUserData->nCommandType == CommandType::TABLE); aDlg.SetSelectedTable(sTable, pUserData->nCommandType == CommandType::TABLE);
if(RET_OK == aDlg.run()) if(RET_OK == aDlg.run())
...@@ -589,53 +518,57 @@ void SwAddressListDialog::DetectTablesAndQueries( ...@@ -589,53 +518,57 @@ void SwAddressListDialog::DetectTablesAndQueries(
SwDBSelect::TABLE : SwDBSelect::QUERY ); SwDBSelect::TABLE : SwDBSelect::QUERY );
//#i97577# //#i97577#
if( pUserData->xColumnsSupplier.is() ) if( pUserData->xColumnsSupplier.is() )
m_pListLB->SetEntryText(m_aDBData.sCommand, pSelect, ITEMID_TABLE - 1); m_xListLB->set_text(nSelect, m_aDBData.sCommand, 1);
else else
m_pListLB->SetEntryText(OUString(), pSelect, ITEMID_TABLE - 1); m_xListLB->set_text(nSelect, OUString(), 1);
} }
const OUString sCommand = SvTabListBox::GetEntryText(pSelect, ITEMID_TABLE - 1); const OUString sCommand = m_xListLB->get_text(nSelect, 1);
m_pOK->Enable(pSelect && !sCommand.isEmpty()); m_xOK->set_sensitive(!sCommand.isEmpty());
m_pFilterPB->Enable( pUserData->xConnection.is() && !sCommand.isEmpty() ); m_xFilterPB->set_sensitive( pUserData->xConnection.is() && !sCommand.isEmpty() );
m_pTablePB->Enable( pUserData->nTableAndQueryCount > 1 ); m_xTablePB->set_sensitive( pUserData->nTableAndQueryCount > 1 );
} }
catch (const Exception&) catch (const Exception&)
{ {
OSL_FAIL("exception caught in SwAddressListDialog::DetectTablesAndQueries"); OSL_FAIL("exception caught in SwAddressListDialog::DetectTablesAndQueries");
m_pOK->Enable( false ); m_xOK->set_sensitive(false);
} }
} }
IMPL_LINK(SwAddressListDialog, TableSelectHdl_Impl, Button*, pButton, void) IMPL_LINK(SwAddressListDialog, TableSelectHdl_Impl, weld::Button&, rButton, void)
{
TableSelectHdl(&rButton);
}
void SwAddressListDialog::TableSelectHdl(weld::Button* pButton)
{ {
EnterWait(); weld::WaitObject aWait(m_xDialog.get());
SvTreeListEntry* pSelect = m_pListLB->FirstSelected();
if(pSelect) int nSelect = m_xListLB->get_selected_index();
if (nSelect != -1)
{ {
AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData()); AddressUserData_Impl* pUserData = reinterpret_cast<AddressUserData_Impl*>(m_xListLB->get_id(nSelect).toInt64());
//only call the table select dialog if tables have not been searched for or there //only call the table select dialog if tables have not been searched for or there
//are more than 1 //are more than 1
const OUString sTable = SvTabListBox::GetEntryText(pSelect, ITEMID_TABLE - 1); const OUString sTable = m_xListLB->get_text(nSelect, 1);
if( pUserData->nTableAndQueryCount > 1 || pUserData->nTableAndQueryCount == -1) if( pUserData->nTableAndQueryCount > 1 || pUserData->nTableAndQueryCount == -1)
{ {
DetectTablesAndQueries(pSelect, (pButton != nullptr) || sTable.isEmpty()); DetectTablesAndQueries(nSelect, (pButton != nullptr) || sTable.isEmpty());
} }
} }
LeaveWait();
} }
IMPL_LINK_NOARG(SwAddressListDialog, OKHdl_Impl, Button*, void) IMPL_LINK_NOARG(SwAddressListDialog, OKHdl_Impl, weld::Button&, void)
{ {
EndDialog(RET_OK); m_xDialog->response(RET_OK);
} }
uno::Reference< XDataSource> SwAddressListDialog::GetSource() uno::Reference< XDataSource> SwAddressListDialog::GetSource()
{ {
uno::Reference< XDataSource> xRet; uno::Reference< XDataSource> xRet;
SvTreeListEntry* pSelect = m_pListLB->FirstSelected(); int nSelect = m_xListLB->get_selected_index();
if(pSelect) if (nSelect != -1)
{ {
AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData()); AddressUserData_Impl* pUserData = reinterpret_cast<AddressUserData_Impl*>(m_xListLB->get_id(nSelect).toInt64());
xRet = pUserData->xSource; xRet = pUserData->xSource;
} }
return xRet; return xRet;
...@@ -645,10 +578,10 @@ uno::Reference< XDataSource> SwAddressListDialog::GetSource() ...@@ -645,10 +578,10 @@ uno::Reference< XDataSource> SwAddressListDialog::GetSource()
SharedConnection SwAddressListDialog::GetConnection() SharedConnection SwAddressListDialog::GetConnection()
{ {
SharedConnection xRet; SharedConnection xRet;
SvTreeListEntry* pSelect = m_pListLB->FirstSelected(); int nSelect = m_xListLB->get_selected_index();
if(pSelect) if (nSelect != -1)
{ {
AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData()); AddressUserData_Impl* pUserData = reinterpret_cast<AddressUserData_Impl*>(m_xListLB->get_id(nSelect).toInt64());
xRet = pUserData->xConnection; xRet = pUserData->xConnection;
} }
return xRet; return xRet;
...@@ -657,21 +590,21 @@ SharedConnection SwAddressListDialog::GetConnection() ...@@ -657,21 +590,21 @@ SharedConnection SwAddressListDialog::GetConnection()
uno::Reference< XColumnsSupplier> SwAddressListDialog::GetColumnsSupplier() uno::Reference< XColumnsSupplier> SwAddressListDialog::GetColumnsSupplier()
{ {
uno::Reference< XColumnsSupplier> xRet; uno::Reference< XColumnsSupplier> xRet;
SvTreeListEntry* pSelect = m_pListLB->FirstSelected(); int nSelect = m_xListLB->get_selected_index();
if(pSelect) if (nSelect != -1)
{ {
AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData()); AddressUserData_Impl* pUserData = reinterpret_cast<AddressUserData_Impl*>(m_xListLB->get_id(nSelect).toInt64());
xRet = pUserData->xColumnsSupplier; xRet = pUserData->xColumnsSupplier;
} }
return xRet; return xRet;
} }
OUString SwAddressListDialog::GetFilter() OUString SwAddressListDialog::GetFilter()
{ {
SvTreeListEntry* pSelect = m_pListLB->FirstSelected(); int nSelect = m_xListLB->get_selected_index();
if(pSelect) if (nSelect != -1)
{ {
AddressUserData_Impl* pUserData = static_cast<AddressUserData_Impl*>(pSelect->GetUserData()); AddressUserData_Impl* pUserData = reinterpret_cast<AddressUserData_Impl*>(m_xListLB->get_id(nSelect).toInt64());
return pUserData->sFilter; return pUserData->sFilter;
} }
return OUString(); return OUString();
......
...@@ -41,50 +41,50 @@ namespace com{namespace sun{namespace star{ ...@@ -41,50 +41,50 @@ namespace com{namespace sun{namespace star{
} }
}}} }}}
class SwMailMergeAddressBlockPage; class SwMailMergeAddressBlockPage;
class SwAddrSourceLB;
class SwAddressListDialog : public SfxModalDialog struct AddressUserData_Impl;
{
VclPtr<FixedText> m_pDescriptionFI;
VclPtr<SwAddrSourceLB> m_pListLB;
VclPtr<PushButton> m_pLoadListPB;
VclPtr<PushButton> m_pCreateListPB;
VclPtr<PushButton> m_pFilterPB;
VclPtr<PushButton> m_pEditPB;
VclPtr<PushButton> m_pTablePB;
VclPtr<OKButton> m_pOK;
class SwAddressListDialog : public SfxDialogController
{
OUString m_sConnecting; OUString m_sConnecting;
SvTreeListEntry* m_pCreatedDataSource;
bool m_bInSelectHdl; bool m_bInSelectHdl;
VclPtr<SwMailMergeAddressBlockPage> m_pAddressPage; VclPtr<SwMailMergeAddressBlockPage> m_xAddressPage;
css::uno::Reference< css::sdb::XDatabaseContext> m_xDBContext; css::uno::Reference< css::sdb::XDatabaseContext> m_xDBContext;
SwDBData m_aDBData; SwDBData m_aDBData;
void DetectTablesAndQueries(SvTreeListEntry* pSelect, bool bWidthDialog); std::vector<std::unique_ptr<AddressUserData_Impl>> m_aUserData;
DECL_LINK(FilterHdl_Impl, Button*, void); std::unique_ptr<weld::Label> m_xDescriptionFI;
DECL_LINK(LoadHdl_Impl, Button*, void); std::unique_ptr<weld::Label> m_xConnecting;
DECL_LINK(CreateHdl_Impl, Button*, void); std::unique_ptr<weld::TreeView> m_xListLB;
DECL_LINK(ListBoxSelectHdl_Impl, SvTreeListBox*, void); std::unique_ptr<weld::Button> m_xLoadListPB;
DECL_LINK(EditHdl_Impl, Button*, void); std::unique_ptr<weld::Button> m_xCreateListPB;
DECL_LINK(TableSelectHdl_Impl, Button*, void); std::unique_ptr<weld::Button> m_xFilterPB;
DECL_LINK(OKHdl_Impl, Button*, void); std::unique_ptr<weld::Button> m_xEditPB;
std::unique_ptr<weld::Button> m_xTablePB;
std::unique_ptr<weld::Button> m_xOK;
std::unique_ptr<weld::TreeIter> m_xIter;
void DetectTablesAndQueries(int Select, bool bWidthDialog);
DECL_LINK(FilterHdl_Impl, weld::Button&, void);
DECL_LINK(LoadHdl_Impl, weld::Button&, void);
DECL_LINK(CreateHdl_Impl, weld::Button&, void);
DECL_LINK(ListBoxSelectHdl_Impl, weld::TreeView&, void);
DECL_LINK(EditHdl_Impl, weld::Button&, void);
DECL_LINK(TableSelectHdl_Impl, weld::Button&, void);
void TableSelectHdl(weld::Button* pButton);
DECL_LINK(OKHdl_Impl, weld::Button&, void);
DECL_LINK(StaticListBoxSelectHdl_Impl, void*, void); DECL_LINK(StaticListBoxSelectHdl_Impl, void*, void);
public: public:
SwAddressListDialog(SwMailMergeAddressBlockPage* pParent); SwAddressListDialog(SwMailMergeAddressBlockPage* pParent);
virtual ~SwAddressListDialog() override; virtual ~SwAddressListDialog() override;
virtual void dispose() override;
css::uno::Reference< css::sdbc::XDataSource> css::uno::Reference< css::sdbc::XDataSource>
GetSource(); GetSource();
......
...@@ -168,16 +168,16 @@ IMPL_LINK_NOARG(SwMailMergeAddressBlockPage, AddressListHdl_Impl, Button*, void) ...@@ -168,16 +168,16 @@ IMPL_LINK_NOARG(SwMailMergeAddressBlockPage, AddressListHdl_Impl, Button*, void)
{ {
try try
{ {
ScopedVclPtrInstance< SwAddressListDialog > xAddrDialog(this); SwAddressListDialog aAddrDialog(this);
if(RET_OK == xAddrDialog->Execute()) if (RET_OK == aAddrDialog.run())
{ {
SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem(); SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
rConfigItem.SetCurrentConnection( rConfigItem.SetCurrentConnection(
xAddrDialog->GetSource(), aAddrDialog.GetSource(),
xAddrDialog->GetConnection(), aAddrDialog.GetConnection(),
xAddrDialog->GetColumnsSupplier(), aAddrDialog.GetColumnsSupplier(),
xAddrDialog->GetDBData()); aAddrDialog.GetDBData());
OUString sFilter = xAddrDialog->GetFilter(); OUString sFilter = aAddrDialog.GetFilter();
rConfigItem.SetFilter( sFilter ); rConfigItem.SetFilter( sFilter );
InsertDataHdl_Impl(nullptr); InsertDataHdl_Impl(nullptr);
GetWizard()->UpdateRoadmap(); GetWizard()->UpdateRoadmap();
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 --> <!-- Generated with glade 3.22.1 -->
<interface domain="sw"> <interface domain="sw">
<requires lib="gtk+" version="3.18"/> <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="SelectAddressDialog"> <object class="GtkDialog" id="SelectAddressDialog">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="border_width">6</property> <property name="border_width">6</property>
<property name="title" translatable="yes" context="selectaddressdialog|SelectAddressDialog">Select Address List</property> <property name="title" translatable="yes" context="selectaddressdialog|SelectAddressDialog">Select Address List</property>
<property name="resizable">False</property> <property name="resizable">False</property>
<property name="type_hint">dialog</property> <property name="type_hint">dialog</property>
<child>
<placeholder/>
</child>
<child internal-child="vbox"> <child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1"> <object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property> <property name="can_focus">False</property>
...@@ -82,10 +94,11 @@ ...@@ -82,10 +94,11 @@
<object class="GtkLabel" id="desc"> <object class="GtkLabel" id="desc">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes" context="selectaddressdialog|desc">Select an address list. Click '%1' to select recipients from a different list. If you do not have an address list you can create one by clicking '%2'.</property> <property name="label" translatable="yes" context="selectaddressdialog|desc">Select an address list. Click '%1' to select recipients from a different list. If you do not have an address list you can create one by clicking '%2'.</property>
<property name="wrap">True</property> <property name="wrap">True</property>
<property name="width_chars">52</property>
<property name="max_width_chars">52</property> <property name="max_width_chars">52</property>
<property name="xalign">0</property>
</object> </object>
<packing> <packing>
<property name="left_attach">0</property> <property name="left_attach">0</property>
...@@ -104,8 +117,8 @@ ...@@ -104,8 +117,8 @@
<object class="GtkLabel" id="label2"> <object class="GtkLabel" id="label2">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes" context="selectaddressdialog|label2">Your recipients are currently selected from:</property> <property name="label" translatable="yes" context="selectaddressdialog|label2">Your recipients are currently selected from:</property>
<property name="xalign">0</property>
</object> </object>
<packing> <packing>
<property name="left_attach">0</property> <property name="left_attach">0</property>
...@@ -197,48 +210,63 @@ ...@@ -197,48 +210,63 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkGrid" id="grid3"> <object class="GtkLabel" id="connecting">
<property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="label" translatable="yes" context="selectaddressdialog|connecting">Connecting to data source...</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<property name="shadow_type">in</property>
<child> <child>
<object class="svtlo-SvSimpleTableContainer" id="sources:border"> <object class="GtkTreeView" id="sources">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<property name="model">liststore1</property>
<property name="search_column">0</property>
<property name="show_expanders">False</property>
<child internal-child="selection"> <child internal-child="selection">
<object class="GtkTreeSelection" id="Simple Table Container-selection4"/> <object class="GtkTreeSelection" id="Macro Library List-selection1"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
<property name="resizable">True</property>
<property name="spacing">6</property>
<property name="title" translatable="yes" context="selectaddressdialog|name">Name</property>
<child>
<object class="GtkCellRendererText" id="cellrenderer1"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn2">
<property name="resizable">True</property>
<property name="spacing">6</property>
<property name="title" translatable="yes" context="selectaddressdialog|table">Table</property>
<child>
<object class="GtkCellRendererText" id="cellrenderer2"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child> </child>
</object> </object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="name">
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="label" translatable="yes" context="selectaddressdialog|name">Name</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="table">
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="label" translatable="yes" context="selectaddressdialog|table">Table</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child> </child>
</object> </object>
<packing> <packing>
...@@ -246,17 +274,6 @@ ...@@ -246,17 +274,6 @@
<property name="top_attach">1</property> <property name="top_attach">1</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkLabel" id="connecting">
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="label" translatable="yes" context="selectaddressdialog|connecting">Connecting to data source...</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="left_attach">0</property> <property name="left_attach">0</property>
......
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