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/+/123773
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
diff --git a/fpicker/source/office/RemoteFilesDialog.cxx b/fpicker/source/office/RemoteFilesDialog.cxx
index ff4e0b7..a48620f 100644
--- a/fpicker/source/office/RemoteFilesDialog.cxx
+++ b/fpicker/source/office/RemoteFilesDialog.cxx
@@ -379,21 +379,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()
@@ -825,18 +822,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 );
@@ -846,8 +843,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
    {
@@ -863,6 +860,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;
@@ -877,7 +875,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)
@@ -886,10 +884,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 55cfa28..3d95ff9 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();