From 3022dc22ceae5da4e8c8d6b287c03619e03fc123 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Fri, 4 Oct 2019 12:11:21 +0100 Subject: weld OCollectionView MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I3aac2b42442ec3f61c2d18369eae061ae44880a5 Reviewed-on: https://gerrit.libreoffice.org/80205 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- dbaccess/inc/bitmaps.hlst | 2 - dbaccess/source/ui/dlg/CollectionView.cxx | 146 ++++++++++++++++----------- dbaccess/source/ui/inc/CollectionView.hxx | 42 ++++---- dbaccess/source/ui/uno/dbinteraction.cxx | 6 +- dbaccess/uiconfig/ui/collectionviewdialog.ui | 60 ++++++++++- 5 files changed, 165 insertions(+), 91 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/inc/bitmaps.hlst b/dbaccess/inc/bitmaps.hlst index b12d7c681a9f..fb9c4567bb87 100644 --- a/dbaccess/inc/bitmaps.hlst +++ b/dbaccess/inc/bitmaps.hlst @@ -24,8 +24,6 @@ #define FORMFOLDER_TREE_ICON "dbaccess/res/forms_16.png" #define REPORT_TREE_ICON "dbaccess/res/report_16.png" #define REPORTFOLDER_TREE_ICON "dbaccess/res/reports_16.png" -#define BMP_NAVIGATION_BTN_UP_SC "res/fp010.png" -#define BMP_NAVIGATION_CREATEFOLDER_SC "res/fp015.png" #define BMP_PRIMARY_KEY "dbaccess/res/jo01.png" #define BMP_PKEYICON "dbaccess/res/pkey.png" #define BMP_UP "dbaccess/res/sortup.png" diff --git a/dbaccess/source/ui/dlg/CollectionView.cxx b/dbaccess/source/ui/dlg/CollectionView.cxx index 8838514e130d..14f942902e9d 100644 --- a/dbaccess/source/ui/dlg/CollectionView.cxx +++ b/dbaccess/source/ui/dlg/CollectionView.cxx @@ -39,10 +39,16 @@ #include #include #include +#include +#include +#include #include #include #include #include +#include +#include +#include #include #include #include @@ -58,61 +64,49 @@ using namespace ::com::sun::star::container; using namespace ::com::sun::star::task; using namespace ::com::sun::star::sdbc; using namespace comphelper; -OCollectionView::OCollectionView( vcl::Window * pParent - ,const Reference< XContent>& _xContent - ,const OUString& _sDefaultName - ,const css::uno::Reference< css::uno::XComponentContext >& _rxContext) - : ModalDialog( pParent, "CollectionView", "dbaccess/ui/collectionviewdialog.ui") + +OCollectionView::OCollectionView(weld::Window* pParent, + const Reference< XContent>& _xContent, + const OUString& _sDefaultName, + const css::uno::Reference< css::uno::XComponentContext >& _rxContext) + : GenericDialogController(pParent, "dbaccess/ui/collectionviewdialog.ui", "CollectionView") , m_xContent(_xContent) , m_xContext(_rxContext) , m_bCreateForm(true) + , m_xFTCurrentPath(m_xBuilder->weld_label("currentPathLabel")) + , m_xNewFolder(m_xBuilder->weld_button("newFolderButton")) + , m_xUp(m_xBuilder->weld_button("upButton")) + , m_xView(m_xBuilder->weld_tree_view("viewTreeview")) + , m_xName(m_xBuilder->weld_entry("fileNameEntry")) + , m_xPB_OK(m_xBuilder->weld_button("ok")) { - get(m_pFTCurrentPath, "currentPathLabel"); - get(m_pNewFolder, "newFolderButton"); - get(m_pUp, "upButton"); - get(m_pView, "viewTreeview"); - get(m_pName, "fileNameEntry"); - get(m_pPB_OK, "ok"); + Reference xHandler( + InteractionHandler::createWithParent(m_xContext, m_xDialog->GetXWindow())); + m_xCmdEnv = new ::ucbhelper::CommandEnvironment(xHandler, nullptr); OSL_ENSURE(m_xContent.is(),"No valid content!"); - m_pView->Initialize(m_xContent); - m_pFTCurrentPath->SetStyle( m_pFTCurrentPath->GetStyle() | WB_PATHELLIPSIS ); + m_xView->set_size_request(m_xView->get_approximate_digit_width() * 60, m_xView->get_height_rows(8)); + m_xView->make_sorted(); + Initialize(); initCurrentPath(); - m_pName->SetText(_sDefaultName); - m_pName->GrabFocus(); - - m_pUp->SetModeImage(Image(StockImage::Yes, BMP_NAVIGATION_BTN_UP_SC)); - m_pNewFolder->SetModeImage(Image(StockImage::Yes, BMP_NAVIGATION_CREATEFOLDER_SC)); + m_xName->set_text(_sDefaultName); + m_xName->grab_focus(); - m_pView->SetDoubleClickHdl( LINK( this, OCollectionView, Dbl_Click_FileView ) ); - m_pView->EnableAutoResize(); - m_pView->EnableDelete(true); - m_pUp->SetClickHdl( LINK( this, OCollectionView, Up_Click ) ); - m_pNewFolder->SetClickHdl( LINK( this, OCollectionView, NewFolder_Click ) ); - m_pPB_OK->SetClickHdl( LINK( this, OCollectionView, Save_Click ) ); + m_xView->connect_row_activated( LINK( this, OCollectionView, Dbl_Click_FileView ) ); + m_xUp->connect_clicked( LINK( this, OCollectionView, Up_Click ) ); + m_xNewFolder->connect_clicked( LINK( this, OCollectionView, NewFolder_Click ) ); + m_xPB_OK->connect_clicked( LINK( this, OCollectionView, Save_Click ) ); } OCollectionView::~OCollectionView() { - disposeOnce(); -} - -void OCollectionView::dispose() -{ - m_pFTCurrentPath.clear(); - m_pNewFolder.clear(); - m_pUp.clear(); - m_pView.clear(); - m_pName.clear(); - m_pPB_OK.clear(); - ModalDialog::dispose(); } -IMPL_LINK_NOARG(OCollectionView, Save_Click, Button*, void) +IMPL_LINK_NOARG(OCollectionView, Save_Click, weld::Button&, void) { - OUString sName = m_pName->GetText(); - if ( sName.isEmpty() ) + OUString sName = m_xName->get_text(); + if (sName.isEmpty()) return; try { @@ -132,7 +126,7 @@ IMPL_LINK_NOARG(OCollectionView, Save_Click, Button*, void) xChild.set(m_xContent,UNO_QUERY); } } - m_pView->Initialize(m_xContent); + Initialize(); initCurrentPath(); } OUString sSubFolder = sName.copy(0,nIndex-1); @@ -157,7 +151,7 @@ IMPL_LINK_NOARG(OCollectionView, Save_Click, Button*, void) IOErrorCode_NOT_EXISTING_PATH,aValues); Reference xHandler( - InteractionHandler::createWithParent(m_xContext, VCLUnoHelper::GetInterface( this ))); + InteractionHandler::createWithParent(m_xContext, m_xDialog->GetXWindow())); OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aException)); Reference< XInteractionRequest > xRequest(pRequest); @@ -174,14 +168,14 @@ IMPL_LINK_NOARG(OCollectionView, Save_Click, Button*, void) { if ( xNameContainer->hasByName(sName) ) { - std::unique_ptr xQueryBox(Application::CreateMessageDialog(GetFrameWeld(), + std::unique_ptr xQueryBox(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Question, VclButtonsType::YesNo, DBA_RES(STR_ALREADYEXISTOVERWRITE))); if (xQueryBox->run() != RET_YES) return; } - m_pName->SetText(sName); - EndDialog( RET_OK ); + m_xName->set_text(sName); + m_xDialog->response(RET_OK); } } catch( const Exception& ) @@ -190,17 +184,17 @@ IMPL_LINK_NOARG(OCollectionView, Save_Click, Button*, void) } } -IMPL_LINK_NOARG(OCollectionView, NewFolder_Click, Button*, void) +IMPL_LINK_NOARG(OCollectionView, NewFolder_Click, weld::Button&, void) { try { Reference xNameContainer(m_xContent,UNO_QUERY); - if ( dbaui::insertHierachyElement(GetFrameWeld(),m_xContext,xNameContainer,OUString(),m_bCreateForm) ) - m_pView->Initialize(m_xContent); + if ( dbaui::insertHierachyElement(m_xDialog.get(),m_xContext,xNameContainer,OUString(),m_bCreateForm) ) + Initialize(); } catch( const SQLException& ) { - showError( ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() ), VCLUnoHelper::GetInterface(this), m_xContext ); + showError(::dbtools::SQLExceptionInfo(::cppu::getCaughtException()), m_xDialog->GetXWindow(), m_xContext); } catch( const Exception& ) { @@ -208,7 +202,7 @@ IMPL_LINK_NOARG(OCollectionView, NewFolder_Click, Button*, void) } } -IMPL_LINK_NOARG(OCollectionView, Up_Click, Button*, void) +IMPL_LINK_NOARG(OCollectionView, Up_Click, weld::Button&, void) { try { @@ -219,11 +213,11 @@ IMPL_LINK_NOARG(OCollectionView, Up_Click, Button*, void) if ( xNameAccess.is() ) { m_xContent.set(xNameAccess,UNO_QUERY); - m_pView->Initialize(m_xContent); + Initialize(); initCurrentPath(); } else - m_pUp->Disable(); + m_xUp->set_sensitive(false); } } catch( const Exception& ) @@ -232,16 +226,15 @@ IMPL_LINK_NOARG(OCollectionView, Up_Click, Button*, void) } } -IMPL_LINK_NOARG(OCollectionView, Dbl_Click_FileView, SvTreeListBox*, bool) +IMPL_LINK_NOARG(OCollectionView, Dbl_Click_FileView, weld::TreeView&, void) { try { Reference xNameAccess(m_xContent,UNO_QUERY); if ( xNameAccess.is() ) { - OUString sSubFolder = m_pView->GetCurrentURL(); - sSubFolder = sSubFolder.copy(sSubFolder.lastIndexOf('/') + 1); - if ( !sSubFolder.isEmpty() ) + OUString sSubFolder = m_xView->get_selected_text(); + if (!sSubFolder.isEmpty()) { Reference< XContent> xContent; if ( xNameAccess->hasByName(sSubFolder) ) @@ -249,7 +242,7 @@ IMPL_LINK_NOARG(OCollectionView, Dbl_Click_FileView, SvTreeListBox*, bool) if ( xContent.is() ) { m_xContent = xContent; - m_pView->Initialize(m_xContent); + Initialize(); initCurrentPath(); } } @@ -259,7 +252,6 @@ IMPL_LINK_NOARG(OCollectionView, Dbl_Click_FileView, SvTreeListBox*, bool) { DBG_UNHANDLED_EXCEPTION("dbaccess"); } - return false; } void OCollectionView::initCurrentPath() @@ -279,7 +271,7 @@ void OCollectionView::initCurrentPath() else if ( !m_bCreateForm && sCID.getLength() != static_cast(strlen(s_sReportsCID)) ) sPath = sCID.copy(strlen(s_sReportsCID) - 2); - m_pFTCurrentPath->SetText(sPath); + m_xFTCurrentPath->set_label(sPath); Reference xChild(m_xContent,UNO_QUERY); bEnable = xChild.is() && Reference(xChild->getParent(),UNO_QUERY).is(); } @@ -288,12 +280,46 @@ void OCollectionView::initCurrentPath() { DBG_UNHANDLED_EXCEPTION("dbaccess"); } - m_pUp->Enable(bEnable); + m_xUp->set_sensitive(bEnable); } OUString OCollectionView::getName() const { - return m_pName->GetText(); + return m_xName->get_text(); +} + +#define ROW_TITLE 1 +#define ROW_IS_FOLDER 2 + +void OCollectionView::Initialize() +{ + weld::WaitObject aWaitCursor(m_xDialog.get()); + + m_xView->clear(); + + try + { + ::ucbhelper::Content aContent(m_xContent, m_xCmdEnv, comphelper::getProcessComponentContext()); + Sequence aProps(2); + aProps[0] = "Title"; + aProps[1] = "IsFolder"; + auto xDynResultSet = aContent.createDynamicCursor(aProps, ucbhelper::INCLUDE_FOLDERS_ONLY); + if (!xDynResultSet.is()) + return; + + Reference xResultSet = xDynResultSet->getStaticResultSet(); + Reference xRow(xResultSet, UNO_QUERY); + while (xResultSet->next()) + { + if (!xRow->getBoolean(ROW_IS_FOLDER)) + continue; + m_xView->append_text(xRow->getString(ROW_TITLE)); + } + } + catch (const Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } } } // namespace dbaui diff --git a/dbaccess/source/ui/inc/CollectionView.hxx b/dbaccess/source/ui/inc/CollectionView.hxx index 2036032cd7be..949e60b749ec 100644 --- a/dbaccess/source/ui/inc/CollectionView.hxx +++ b/dbaccess/source/ui/inc/CollectionView.hxx @@ -20,12 +20,9 @@ #ifndef INCLUDED_DBACCESS_SOURCE_UI_INC_COLLECTIONVIEW_HXX #define INCLUDED_DBACCESS_SOURCE_UI_INC_COLLECTIONVIEW_HXX -#include -#include -#include -#include -#include +#include #include +#include #include #include @@ -33,32 +30,35 @@ namespace dbaui { /* this class allows to browse through the collection of forms and reports */ - class OCollectionView : public ModalDialog + class OCollectionView : public weld::GenericDialogController { - VclPtr m_pFTCurrentPath; - VclPtr m_pNewFolder; - VclPtr m_pUp; - VclPtr m_pView; - VclPtr m_pName; - VclPtr m_pPB_OK; css::uno::Reference< css::ucb::XContent> m_xContent; css::uno::Reference< css::uno::XComponentContext > m_xContext; + css::uno::Reference< css::ucb::XCommandEnvironment > m_xCmdEnv; bool m_bCreateForm; - DECL_LINK(Up_Click, Button*, void); - DECL_LINK(NewFolder_Click, Button*, void); - DECL_LINK(Save_Click, Button*, void); - DECL_LINK(Dbl_Click_FileView, SvTreeListBox*, bool); + std::unique_ptr m_xFTCurrentPath; + std::unique_ptr m_xNewFolder; + std::unique_ptr m_xUp; + std::unique_ptr m_xView; + std::unique_ptr m_xName; + std::unique_ptr m_xPB_OK; + + DECL_LINK(Up_Click, weld::Button&, void); + DECL_LINK(NewFolder_Click, weld::Button&, void); + DECL_LINK(Save_Click, weld::Button&, void); + DECL_LINK(Dbl_Click_FileView, weld::TreeView&, void); /// sets the fixedtext to the right content void initCurrentPath(); + + void Initialize(); public: - OCollectionView( vcl::Window * pParent - ,const css::uno::Reference< css::ucb::XContent>& _xContent - ,const OUString& _sDefaultName - ,const css::uno::Reference< css::uno::XComponentContext >& _rxContext); + OCollectionView(weld::Window * pParent, + const css::uno::Reference< css::ucb::XContent>& _xContent, + const OUString& _sDefaultName, + const css::uno::Reference< css::uno::XComponentContext >& _rxContext); virtual ~OCollectionView() override; - virtual void dispose() override; const css::uno::Reference< css::ucb::XContent>& getSelectedFolder() const { return m_xContent;} OUString getName() const; }; diff --git a/dbaccess/source/ui/uno/dbinteraction.cxx b/dbaccess/source/ui/uno/dbinteraction.cxx index 1bd4f34e28e6..7824298889fa 100644 --- a/dbaccess/source/ui/uno/dbinteraction.cxx +++ b/dbaccess/source/ui/uno/dbinteraction.cxx @@ -261,8 +261,8 @@ namespace dbaui Reference< XInteractionDocumentSave > xCallback(_rContinuations[nDocuPos], UNO_QUERY); OSL_ENSURE(xCallback.is(), "BasicInteractionHandler::implHandle(DocumentSaveRequest): can't save document without an appropriate interaction handler!s"); - ScopedVclPtrInstance< OCollectionView > aDlg(nullptr, _rDocuRequest.Content, _rDocuRequest.Name, m_xContext); - sal_Int16 nResult = aDlg->Execute(); + OCollectionView aDlg(Application::GetFrameWeld(m_xParentWindow), _rDocuRequest.Content, _rDocuRequest.Name, m_xContext); + sal_Int16 nResult = aDlg.run(); try { switch (nResult) @@ -270,7 +270,7 @@ namespace dbaui case RET_OK: if (xCallback.is()) { - xCallback->setName(aDlg->getName(), aDlg->getSelectedFolder()); + xCallback->setName(aDlg.getName(), aDlg.getSelectedFolder()); xCallback->select(); } break; diff --git a/dbaccess/uiconfig/ui/collectionviewdialog.ui b/dbaccess/uiconfig/ui/collectionviewdialog.ui index a89de8eb8648..0ffb48584773 100644 --- a/dbaccess/uiconfig/ui/collectionviewdialog.ui +++ b/dbaccess/uiconfig/ui/collectionviewdialog.ui @@ -2,13 +2,33 @@ - + + True + False + res/fp015.png + + + True + False + res/fp010.png + + + + + + + + + False True True 6 Save + True + 0 + 0 dialog @@ -93,6 +113,7 @@ True False True + 3 True @@ -100,6 +121,7 @@ start start True + middle False @@ -116,6 +138,8 @@ True True Create New Directory + image1 + True False @@ -131,6 +155,8 @@ True True Up One Level + image2 + True False @@ -146,13 +172,37 @@ - + True True - True True - - + in + + + True + True + True + True + liststore1 + False + 1 + False + + + + + + True + Folder Name + + + + 0 + + + + + -- cgit