cui/source/customize/cfg.cxx | 86 +++++++----------------- include/sfx2/filedlghelper.hxx | 7 - sfx2/source/dialog/filedlghelper.cxx | 124 +++-------------------------------- sfx2/source/dialog/filedlgimpl.hxx | 5 - 4 files changed, 38 insertions(+), 184 deletions(-)
New commits: commit 2bbd12d870e935ff3c361b21a599ea86aff061d3 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Mon May 12 20:45:00 2025 +0200 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Tue May 13 06:35:07 2025 +0200 Don't use XFilePicker::getFiles in FileDialogHelper Since commit ef8341f05ec79fcdac3b05b45659f5c98ff05edf, XFilePicker3 is used there; XFilePicker2::getSelectedFiles is guaranteed to be available. Fallback to deprecated API is not needed, and this allows to drop some ugly code. Change-Id: Id11a5238f3db5930c30f80df6ee6a77a377f6475 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185232 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx index c2a2fc1f1a48..c40112f0daea 100644 --- a/cui/source/customize/cfg.cxx +++ b/cui/source/customize/cfg.cxx @@ -2927,7 +2927,7 @@ IMPL_LINK_NOARG(SvxIconSelectorDialog, ImportHdl, weld::Button&, void) if ( ERRCODE_NONE == aImportDialog.Execute() ) { - uno::Sequence< OUString > paths = aImportDialog.GetMPath(); + uno::Sequence< OUString > paths = aImportDialog.GetSelectedFiles(); ImportGraphics ( paths ); } } @@ -3063,83 +3063,51 @@ void SvxIconSelectorDialog::ImportGraphics( { std::vector<OUString> rejected; - if ( rPaths.getLength() == 1 ) + bool replaceAll = false; + for (const auto& aPath : rPaths) { - if ( m_xImportedImageManager->hasImage( SvxConfigPageHelper::GetImageType(), rPaths[0] ) ) + bool result = true; + if ( m_xImportedImageManager->hasImage( SvxConfigPageHelper::GetImageType(), aPath ) ) { - sal_Int32 aIndex = rPaths[0].lastIndexOf('/'); - OUString aIconName = rPaths[0].copy(aIndex + 1); - SvxIconReplacementDialog aDlg(m_xDialog.get(), aIconName, false); - sal_uInt16 ret = aDlg.run(); - if ( ret == 2 ) + bool replace = replaceAll; + if (!replace) { - ReplaceGraphicItem( rPaths[0] ); - } - } - else - { - if ( !ImportGraphic( rPaths[0] ) ) - { - rejected.push_back(rPaths[0]); - } - } - } - else - { - OUString aSourcePath( rPaths[0] ); - if (!aSourcePath.endsWith("/")) - aSourcePath += "/"; - bool replaceAll = false; - - for ( sal_Int32 i = 1; i < rPaths.getLength(); ++i ) - { - OUString aPath = aSourcePath + rPaths[i]; - bool result = true; - if ( m_xImportedImageManager->hasImage( SvxConfigPageHelper::GetImageType(), aPath ) ) - { - bool replace = replaceAll; - if (!replace) + sal_Int32 aIndex = aPath.lastIndexOf('/'); + OUString aIconName = aPath.copy(aIndex + 1); + SvxIconReplacementDialog aDlg(m_xDialog.get(), aIconName, rPaths.getLength() > 1); + sal_uInt16 ret = aDlg.run(); + if (ret == 2) { - sal_Int32 aIndex = rPaths[i].lastIndexOf('/'); - OUString aIconName = rPaths[i].copy(aIndex + 1); - SvxIconReplacementDialog aDlg(m_xDialog.get(), aIconName, true); - sal_uInt16 ret = aDlg.run(); - if (ret == 2) - { - replace = true; - } - else if (ret == 5) - { - replace = true; - replaceAll = true; - } + replace = true; } - if (replace) + else if (ret == 5) { - ReplaceGraphicItem(aPath); + replace = true; + replaceAll = true; } } - else - { - result = ImportGraphic(aPath); - } - if (!result) + if (replace) { - rejected.push_back(rPaths[i]); + ReplaceGraphicItem(aPath); } } + else + { + result = ImportGraphic(aPath); + } + if (!result) + { + rejected.push_back(aPath); + } } if (rejected.empty()) return; OUStringBuffer message; - OUString fPath; - if (rPaths.getLength() > 1) - fPath = OUString::Concat(rPaths[0].subView(8)) + "/"; for (const auto& rejected_item : rejected) { - message.append(fPath + rejected_item + " "); + message.append(rejected_item + " "); } SvxIconChangeDialog aDialog(m_xDialog.get(), message.makeStringAndClear()); diff --git a/include/sfx2/filedlghelper.hxx b/include/sfx2/filedlghelper.hxx index 602e9a7d9068..b98e128b191b 100644 --- a/include/sfx2/filedlghelper.hxx +++ b/include/sfx2/filedlghelper.hxx @@ -192,13 +192,6 @@ public: void SetTitle( const OUString& rNewTitle ); OUString GetPath() const; - /** @deprecated: Don't use this method to retrieve the selected files - There are file picker which can provide multiple selected file which belong - to different folders. As this method always provides the root folder for all selected - files this cannot work. - */ - css::uno::Sequence< OUString > GetMPath() const; - /** Provides the selected files with full path information */ css::uno::Sequence< OUString > GetSelectedFiles() const; diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx index 406d913c5f12..5ed936a33a64 100644 --- a/sfx2/source/dialog/filedlghelper.cxx +++ b/sfx2/source/dialog/filedlghelper.cxx @@ -646,7 +646,7 @@ void FileDialogHelper_Impl::updatePreviewState( bool _bUpdatePreviewWindow ) void FileDialogHelper_Impl::updateVersions() { Sequence < OUString > aEntries; - Sequence < OUString > aPathSeq = mxFileDlg->getFiles(); + Sequence < OUString > aPathSeq = mxFileDlg->getSelectedFiles(); if ( aPathSeq.getLength() == 1 ) { @@ -719,7 +719,7 @@ IMPL_LINK_NOARG(FileDialogHelper_Impl, TimeOutHdl_Impl, Timer *, void) if ( ! xFilePicker.is() ) return; - Sequence < OUString > aPathSeq = mxFileDlg->getFiles(); + Sequence < OUString > aPathSeq = mxFileDlg->getSelectedFiles(); if ( mbShowPreview && ( aPathSeq.getLength() == 1 ) ) { @@ -832,7 +832,7 @@ ErrCode FileDialogHelper_Impl::getGraphic( Graphic& rGraphic ) const // rhbz#1079672 do not return maGraphic, it needs not to be the selected file OUString aPath; - Sequence<OUString> aPathSeq = mxFileDlg->getFiles(); + Sequence<OUString> aPathSeq = mxFileDlg->getSelectedFiles(); if (aPathSeq.getLength() == 1) { @@ -993,14 +993,12 @@ FileDialogHelper_Impl::FileDialogHelper_Impl( mbSystemPicker = lcl_isSystemFilePicker( mxFileDlg ); mbAsyncPicker = lcl_isAsyncFilePicker(mxFileDlg); - uno::Reference< XInitialization > xInit( mxFileDlg, UNO_QUERY ); - if ( ! mxFileDlg.is() ) { return; } - + uno::Reference< XInitialization > xInit( mxFileDlg, UNO_QUERY ); if ( xInit.is() ) { sal_Int16 nTemplateDescription = TemplateDescription::FILEOPEN_SIMPLE; @@ -1405,48 +1403,6 @@ void FileDialogHelper_Impl::implStartExecute() } } -void FileDialogHelper_Impl::implGetAndCacheFiles(const uno::Reference< XInterface >& xPicker, std::vector<OUString>& rpURLList) -{ - rpURLList.clear(); - - // a) the new way (optional!) - uno::Reference< XFilePicker3 > xPickNew(xPicker, UNO_QUERY); - if (xPickNew.is()) - { - Sequence< OUString > lFiles = xPickNew->getSelectedFiles(); - comphelper::sequenceToContainer(rpURLList, lFiles); - } - - // b) the olde way ... non optional. - else - { - uno::Reference< XFilePicker3 > xPickOld(xPicker, UNO_QUERY_THROW); - Sequence< OUString > lFiles = xPickOld->getFiles(); - ::sal_Int32 nFiles = lFiles.getLength(); - if ( nFiles == 1 ) - { - rpURLList.push_back(lFiles[0]); - } - else if ( nFiles > 1 ) - { - INetURLObject aPath( lFiles[0] ); - aPath.setFinalSlash(); - - for (::sal_Int32 i = 1; i < nFiles; i++) - { - if (i == 1) - aPath.Append( lFiles[i] ); - else - aPath.setName( lFiles[i] ); - - rpURLList.push_back(aPath.GetMainURL(INetURLObject::DecodeMechanism::NONE)); - } - } - } - - mlLastURLs = rpURLList; -} - ErrCode FileDialogHelper_Impl::execute( std::vector<OUString>& rpURLList, std::optional<SfxAllItemSet>& rpSet, OUString& rFilter, @@ -1571,7 +1527,7 @@ ErrCode FileDialogHelper_Impl::execute( std::vector<OUString>& rpURLList, std::shared_ptr<const SfxFilter> pCurrentFilter = getCurrentSfxFilter(); // fill the rpURLList - implGetAndCacheFiles( mxFileDlg, rpURLList ); + comphelper::sequenceToContainer(rpURLList, mxFileDlg->getSelectedFiles()); if ( rpURLList.empty() ) return ERRCODE_ABORT; @@ -2732,75 +2688,17 @@ void FileDialogHelper::SetTitle( const OUString& rNewTitle ) OUString FileDialogHelper::GetPath() const { - OUString aPath; - - if ( !mpImpl->mlLastURLs.empty()) - return mpImpl->mlLastURLs[0]; - - if ( mpImpl->mxFileDlg.is() ) - { - Sequence < OUString > aPathSeq = mpImpl->mxFileDlg->getFiles(); + if (mpImpl->mxFileDlg) + if (auto aPathSeq = mpImpl->mxFileDlg->getSelectedFiles(); aPathSeq.hasElements()) + return aPathSeq[0]; - if ( aPathSeq.getLength() == 1 ) - { - aPath = aPathSeq[0]; - } - } - - return aPath; -} - -Sequence < OUString > FileDialogHelper::GetMPath() const -{ - if ( !mpImpl->mlLastURLs.empty()) - return comphelper::containerToSequence(mpImpl->mlLastURLs); - - if ( mpImpl->mxFileDlg.is() ) - return mpImpl->mxFileDlg->getFiles(); - else - { - Sequence < OUString > aEmpty; - return aEmpty; - } + return {}; } Sequence< OUString > FileDialogHelper::GetSelectedFiles() const { - // a) the new way (optional!) - uno::Sequence< OUString > aResultSeq; - if (mpImpl->mxFileDlg.is()) - { - aResultSeq = mpImpl->mxFileDlg->getSelectedFiles(); - } - // b) the olde way ... non optional. - else - { - uno::Reference< XFilePicker > xPickOld(mpImpl->mxFileDlg, UNO_QUERY_THROW); - Sequence< OUString > lFiles = xPickOld->getFiles(); - ::sal_Int32 nFiles = lFiles.getLength(); - if ( nFiles > 1 ) - { - aResultSeq = Sequence< OUString >( nFiles-1 ); - auto pResultSeq = aResultSeq.getArray(); - - INetURLObject aPath( lFiles[0] ); - aPath.setFinalSlash(); - - for (::sal_Int32 i = 1; i < nFiles; i++) - { - if (i == 1) - aPath.Append( lFiles[i] ); - else - aPath.setName( lFiles[i] ); - - pResultSeq[i-1] = aPath.GetMainURL( INetURLObject::DecodeMechanism::NONE ); - } - } - else - aResultSeq = std::move(lFiles); - } - - return aResultSeq; + uno::Reference<XFilePicker3> xFileDlg(mpImpl->mxFileDlg, uno::UNO_SET_THROW); + return xFileDlg->getSelectedFiles(); } OUString FileDialogHelper::GetDisplayDirectory() const diff --git a/sfx2/source/dialog/filedlgimpl.hxx b/sfx2/source/dialog/filedlgimpl.hxx index 6595119a63fd..4867d9423e17 100644 --- a/sfx2/source/dialog/filedlgimpl.hxx +++ b/sfx2/source/dialog/filedlgimpl.hxx @@ -53,8 +53,6 @@ namespace sfx2 FileDialogHelper* mpAntiImpl; weld::Window* mpFrameWeld; - ::std::vector< OUString > mlLastURLs; - OUString maPath; OUString maFileName; OUString maCurFilter; @@ -140,9 +138,6 @@ namespace sfx2 void verifyPath( ); - void implGetAndCacheFiles( const css::uno::Reference< XInterface >& xPicker , - std::vector<OUString>& rpURLList ); - DECL_LINK( TimeOutHdl_Impl, Timer *, void); public: