diff options
author | Caolán McNamara <caolanm@redhat.com> | 2021-10-18 11:37:12 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2021-10-18 20:29:32 +0200 |
commit | c263a01a47a0a2521f50feb9544b51e78399a78c (patch) | |
tree | fb58d487f4e742db341cb5d8125f35c0db0eee9c /fpicker | |
parent | 3c168b1dc876e4fca97f73683572462a29227523 (diff) |
Related: tdf#145169 change to selected dir on remote "save"
if a dir is selected then try to change to that dir
when save is clicked instead of saving using that as
basename, which is consistent with standard fpicker.
don't change the contents of the Entry, leave it alone.
Change-Id: Id19fbf0f3ef2b8220059a1fa166b7783feb8d57d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123755
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'fpicker')
-rw-r--r-- | fpicker/source/office/RemoteFilesDialog.cxx | 43 | ||||
-rw-r--r-- | fpicker/source/office/RemoteFilesDialog.hxx | 2 |
2 files changed, 21 insertions, 24 deletions
diff --git a/fpicker/source/office/RemoteFilesDialog.cxx b/fpicker/source/office/RemoteFilesDialog.cxx index 544887795da4..9757f151541c 100644 --- a/fpicker/source/office/RemoteFilesDialog.cxx +++ b/fpicker/source/office/RemoteFilesDialog.cxx @@ -380,21 +380,18 @@ void RemoteFilesDialog::OpenURL( OUString const & sURL ) } } -void RemoteFilesDialog::AddFileExtension() +OUString RemoteFilesDialog::AddFileExtension(const OUString& rFileName) { if (m_nCurrentFilter == -1) - return; + return rFileName; OUString sExt = m_aFilters[m_nCurrentFilter].second; - OUString sFileName = m_xName_ed->get_text(); + sal_Int32 nDotPos = rFileName.lastIndexOf( '.' ); - sal_Int32 nDotPos = sFileName.lastIndexOf( '.' ); + if (nDotPos == -1) + return rFileName + sExt.subView( 1 ); // without '*' - if ( nDotPos == -1 ) - { - sFileName += sExt.subView( 1 ); // without '*' - m_xName_ed->set_text( sFileName ); - } + return rFileName; } void RemoteFilesDialog::EnableControls() @@ -826,18 +823,18 @@ IMPL_LINK_NOARG ( RemoteFilesDialog, NewFolderHdl, weld::Button&, void ) IMPL_LINK_NOARG ( RemoteFilesDialog, OkHdl, weld::Button&, void ) { - OUString sNameNoExt = m_xName_ed->get_text(); - OUString sPathNoExt; - - // auto extension - if( m_eMode == REMOTEDLG_MODE_SAVE ) - AddFileExtension(); + OUString sUserSelectedPath; // check if file/path exists - OUString sCurrentPath = m_xFileView->GetViewURL(); OUString sSelectedItem = m_xFileView->GetCurrentURL(); - OUString sName = m_xName_ed->get_text(); + OUString sUserTypedName = m_xName_ed->get_text(); + OUString sFileName; + // auto extension + if( m_eMode == REMOTEDLG_MODE_SAVE ) + sFileName = AddFileExtension(sUserTypedName); + else + sFileName = sUserTypedName; bool bFileDlg = ( m_eType == REMOTEDLG_TYPE_FILEDLG ); bool bSelected = ( m_xFileView->GetSelectionCount() > 0 ); @@ -847,8 +844,8 @@ IMPL_LINK_NOARG ( RemoteFilesDialog, OkHdl, weld::Button&, void ) if( !bSelected ) { - m_sPath = sCurrentPath + INetURLObject::encode( sName, INetURLObject::PART_FPATH, INetURLObject::EncodeMechanism::All ); - sPathNoExt = sCurrentPath + INetURLObject::encode( sNameNoExt, INetURLObject::PART_FPATH, INetURLObject::EncodeMechanism::All ); + m_sPath = sCurrentPath + INetURLObject::encode(sFileName, INetURLObject::PART_FPATH, INetURLObject::EncodeMechanism::All); + sUserSelectedPath = sCurrentPath + INetURLObject::encode(sUserTypedName, INetURLObject::PART_FPATH, INetURLObject::EncodeMechanism::All); } else { @@ -864,6 +861,7 @@ IMPL_LINK_NOARG ( RemoteFilesDialog, OkHdl, weld::Button&, void ) aURL.SetUser( aCurrentURL.GetUser() ); m_sPath = aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ); + sUserSelectedPath = m_sPath; } bool bExists = false; @@ -878,7 +876,7 @@ IMPL_LINK_NOARG ( RemoteFilesDialog, OkHdl, weld::Button&, void ) if( m_eMode == REMOTEDLG_MODE_SAVE ) { OUString sMsg = FpsResId( STR_SVT_ALREADYEXISTOVERWRITE ); - sMsg = sMsg.replaceFirst( "$filename$", sName ); + sMsg = sMsg.replaceFirst("$filename$", sFileName); std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Question, VclButtonsType::YesNo, sMsg)); if (xBox->run() != RET_YES) @@ -887,10 +885,9 @@ IMPL_LINK_NOARG ( RemoteFilesDialog, OkHdl, weld::Button&, void ) } else { - if( ContentIsFolder( sPathNoExt ) ) + if (ContentIsFolder(sUserSelectedPath)) { - OpenURL( sPathNoExt ); - m_xName_ed->set_text( "" ); + OpenURL(sUserSelectedPath); if (!bSelected) m_xName_ed->grab_focus(); diff --git a/fpicker/source/office/RemoteFilesDialog.hxx b/fpicker/source/office/RemoteFilesDialog.hxx index 6ff5ae747212..93a8e363f5b4 100644 --- a/fpicker/source/office/RemoteFilesDialog.hxx +++ b/fpicker/source/office/RemoteFilesDialog.hxx @@ -149,7 +149,7 @@ private: void OpenURL( OUString const & sURL ); - void AddFileExtension(); + OUString AddFileExtension(const OUString& rFileName); void EnableExtraMenuItems(bool bEnable); void EnableControls(); |