sfx2/source/dialog/filedlghelper.cxx | 1 sfx2/source/doc/guisaveas.cxx | 73 ++++------------------------------- 2 files changed, 10 insertions(+), 64 deletions(-)
New commits: commit 67ea1fc544a0651e8da78531cfa3525f72c434ef Author: Samuel Mehrbrodt <samuel.mehrbr...@collabora.com> AuthorDate: Mon Sep 8 10:04:49 2025 +0200 Commit: Samuel Mehrbrodt <samuel.mehrbr...@collabora.com> CommitDate: Mon Sep 8 13:15:53 2025 +0200 tdf#167897 Fix save/export directory preselection with empty user profile In the case of an empty user profile, the logic to display the correct directory was twisted. This also reverts the fix for tdf#165228 since the root cause now has been fixed. Change-Id: I0e33c53b7e1d8a7366caad0e1375a2f95a3ae313 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190655 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@collabora.com> diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx index c65d8d1fefa5..232425881010 100644 --- a/sfx2/source/dialog/filedlghelper.cxx +++ b/sfx2/source/dialog/filedlghelper.cxx @@ -1458,7 +1458,6 @@ ErrCode FileDialogHelper_Impl::execute( css::uno::Sequence<OUString>& rpURLList, } rpURLList = {}; - maPath.clear(); // tdf#165228 This should not survive between calls to execute if ( ! mxFileDlg.is() ) return ERRCODE_ABORT; diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx index f99fb12aad16..1d7241f42756 100644 --- a/sfx2/source/doc/guisaveas.cxx +++ b/sfx2/source/doc/guisaveas.cxx @@ -347,7 +347,6 @@ public: bool ShowDocumentInfoDialog(); static OUString GetRecommendedExtension( const OUString& aTypeName ); - OUString GetRecommendedDir( const OUString& aSuggestedDir ); OUString GetRecommendedName( const OUString& aSuggestedName, const OUString& aTypeName ); }; @@ -963,9 +962,15 @@ bool ModelData_Impl::OutputFileDialog( sal_Int16 nStoreMode, if (SfxViewShell* pViewShell = SfxViewShell::Current()) { SfxObjectShell* pDocShell = pViewShell->GetObjectShell(); - if (sPreselectedDir.isEmpty() && pDocShell && !pDocShell->IsBasedOnTemplate()) - sPreselectedDir = GetDocProps().getUnpackedValueOrDefault("DocumentBaseURL", OUString()); + if (pDocShell && !pDocShell->IsBasedOnTemplate()) + { + if (sPreselectedDir.isEmpty()) + sPreselectedDir = GetDocProps().getUnpackedValueOrDefault("DocumentBaseURL", OUString()); + if (sPreselectedDir.isEmpty() && GetStorable()->hasLocation()) + sPreselectedDir = GetStorable()->getLocation(); + } } + INetURLObject aObj(sPreselectedDir); aObj.removeSegment(); // remove file name from URL sPreselectedDir = aObj.GetMainURL(INetURLObject::DecodeMechanism::NONE); @@ -1072,9 +1077,8 @@ bool ModelData_Impl::OutputFileDialog( sal_Int16 nStoreMode, } } - const OUString aRecommendedDir {GetRecommendedDir( aSuggestedDir )}; - if ( !aRecommendedDir.isEmpty() ) - pFileDlg->SetDisplayFolder( aRecommendedDir ); + if ( !aSuggestedDir.isEmpty() ) + pFileDlg->SetDisplayFolder( aSuggestedDir ); const OUString aRecommendedName {GetRecommendedName( aSuggestedName, aAdjustToType )}; if ( !aRecommendedName.isEmpty() ) pFileDlg->SetFileName( aRecommendedName ); @@ -1346,63 +1350,6 @@ OUString ModelData_Impl::GetRecommendedExtension( const OUString& aTypeName ) return OUString(); } - -OUString ModelData_Impl::GetRecommendedDir( const OUString& aSuggestedDir ) -{ - if ( ( !aSuggestedDir.isEmpty() || GetStorable()->hasLocation() ) - && !GetMediaDescr().getUnpackedValueOrDefault(u"RepairPackage"_ustr, false ) ) - { - INetURLObject aLocation; - if ( !aSuggestedDir.isEmpty() ) - aLocation = INetURLObject( aSuggestedDir ); - else - { - const OUString aOldURL = GetStorable()->getLocation(); - if ( !aOldURL.isEmpty() ) - { - INetURLObject aTmp( aOldURL ); - if ( aTmp.removeSegment() ) - aLocation = std::move(aTmp); - } - - if ( aLocation.HasError() ) - aLocation = INetURLObject(); - } - - OUString sLocationURL( aLocation.GetMainURL( INetURLObject::DecodeMechanism::NONE ) ); - bool bIsInTempPath( false ); - OUString sSysTempPath; - if( osl::FileBase::getTempDirURL( sSysTempPath ) == osl::FileBase::E_None ) - bIsInTempPath = !sSysTempPath.isEmpty() && sLocationURL.startsWith( sSysTempPath ); -#ifdef _WIN32 - if( !bIsInTempPath ) - { - PWSTR sPath; - HRESULT hRes = SHGetKnownFolderPath(FOLDERID_InternetCache, 0, nullptr, &sPath); - if( SUCCEEDED(hRes) ) - { - OUString sTempINetFiles; - if( osl::FileBase::getFileURLFromSystemPath(OUString(o3tl::toU(sPath)), sTempINetFiles) == osl::FileBase::E_None ) - bIsInTempPath = !sTempINetFiles.isEmpty() && sLocationURL.startsWith( sTempINetFiles ); - } - CoTaskMemFree(sPath); - } -#endif - // Suggest somewhere other than the system's temp directory - if( bIsInTempPath ) - aLocation = INetURLObject(); - - aLocation.setFinalSlash(); - if ( !aLocation.HasError() ) - return aLocation.GetMainURL( INetURLObject::DecodeMechanism::NONE ); - - return OUString(); - } - - return OUString(); -} - - OUString ModelData_Impl::GetRecommendedName( const OUString& aSuggestedName, const OUString& aTypeName ) { // the last used name might be provided by aSuggestedName from the old selection, or from the MediaDescriptor