[Libreoffice-commits] core.git: fpicker/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Tue Apr 14 12:25:58 UTC 2020


 fpicker/source/office/OfficeControlAccess.cxx |   84 +++++++-------
 fpicker/source/office/RemoteFilesDialog.cxx   |  144 ++++++++++++------------
 fpicker/source/office/iodlg.cxx               |  151 +++++++++++++-------------
 3 files changed, 190 insertions(+), 189 deletions(-)

New commits:
commit 89b2fd604420d53b6d6ccc6e7656c3bcf282703d
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Apr 14 12:05:09 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Apr 14 14:25:24 2020 +0200

    loplugin:flatten in fpicker
    
    Change-Id: Icfad1871686c894379b0e703194307a5bd72b2f7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92160
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/fpicker/source/office/OfficeControlAccess.cxx b/fpicker/source/office/OfficeControlAccess.cxx
index 296e9368779a..e8f4e3929d79 100644
--- a/fpicker/source/office/OfficeControlAccess.cxx
+++ b/fpicker/source/office/OfficeControlAccess.cxx
@@ -340,52 +340,52 @@ namespace svt
     {
         weld::Widget* pControl = m_pFilePickerController->getControl( nControlId );
         DBG_ASSERT( pControl, "OControlAccess::SetValue: don't have this control in the current mode!" );
-        if ( pControl )
+        if ( !pControl )
+            return;
+
+        PropFlags nPropertyId = PropFlags::Unknown;
+        if ( ControlActions::SET_HELP_URL == nControlAction )
         {
-            PropFlags nPropertyId = PropFlags::Unknown;
-            if ( ControlActions::SET_HELP_URL == nControlAction )
-            {
-                nPropertyId = PropFlags::HelpUrl;
-            }
-            else
+            nPropertyId = PropFlags::HelpUrl;
+        }
+        else
+        {
+            switch ( nControlId )
             {
-                switch ( nControlId )
-                {
-                    case CHECKBOX_AUTOEXTENSION:
-                    case CHECKBOX_PASSWORD:
-                    case CHECKBOX_FILTEROPTIONS:
-                    case CHECKBOX_READONLY:
-                    case CHECKBOX_LINK:
-                    case CHECKBOX_PREVIEW:
-                    case CHECKBOX_SELECTION:
-                        nPropertyId = PropFlags::Checked;
-                        break;
-
-                    case LISTBOX_FILTER:
-                        SAL_WARN( "fpicker.office", "Use the XFilterManager to access the filter listbox" );
-                        break;
-
-                    case LISTBOX_VERSION:
-                    case LISTBOX_TEMPLATE:
-                    case LISTBOX_IMAGE_TEMPLATE:
-                    case LISTBOX_IMAGE_ANCHOR:
-                        if ( ControlActions::SET_SELECT_ITEM == nControlAction )
-                        {
-                            nPropertyId = PropFlags::SelectedItemIndex;
-                        }
-                        else
-                        {
-                            weld::ComboBox* pComboBox = dynamic_cast<weld::ComboBox*>(pControl);
-                            assert(pComboBox && "OControlAccess::SetValue: implGetControl returned nonsense!");
-                            implDoListboxAction(pComboBox, nControlAction, rValue);
-                        }
-                        break;
-                }
+                case CHECKBOX_AUTOEXTENSION:
+                case CHECKBOX_PASSWORD:
+                case CHECKBOX_FILTEROPTIONS:
+                case CHECKBOX_READONLY:
+                case CHECKBOX_LINK:
+                case CHECKBOX_PREVIEW:
+                case CHECKBOX_SELECTION:
+                    nPropertyId = PropFlags::Checked;
+                    break;
+
+                case LISTBOX_FILTER:
+                    SAL_WARN( "fpicker.office", "Use the XFilterManager to access the filter listbox" );
+                    break;
+
+                case LISTBOX_VERSION:
+                case LISTBOX_TEMPLATE:
+                case LISTBOX_IMAGE_TEMPLATE:
+                case LISTBOX_IMAGE_ANCHOR:
+                    if ( ControlActions::SET_SELECT_ITEM == nControlAction )
+                    {
+                        nPropertyId = PropFlags::SelectedItemIndex;
+                    }
+                    else
+                    {
+                        weld::ComboBox* pComboBox = dynamic_cast<weld::ComboBox*>(pControl);
+                        assert(pComboBox && "OControlAccess::SetValue: implGetControl returned nonsense!");
+                        implDoListboxAction(pComboBox, nControlAction, rValue);
+                    }
+                    break;
             }
-
-            if ( PropFlags::Unknown != nPropertyId )
-                implSetControlProperty( nControlId, pControl, nPropertyId, rValue );
         }
+
+        if ( PropFlags::Unknown != nPropertyId )
+            implSetControlProperty( nControlId, pControl, nPropertyId, rValue );
     }
 
     Any OControlAccess::getValue( sal_Int16 nControlId, sal_Int16 nControlAction ) const
diff --git a/fpicker/source/office/RemoteFilesDialog.cxx b/fpicker/source/office/RemoteFilesDialog.cxx
index f8791df0b27c..fcbd203b536b 100644
--- a/fpicker/source/office/RemoteFilesDialog.cxx
+++ b/fpicker/source/office/RemoteFilesDialog.cxx
@@ -233,22 +233,22 @@ void RemoteFilesDialog::InitSize()
     // initialize from config
     SvtViewOptions aDlgOpt( EViewType::Dialog, m_sIniKey );
 
-    if( aDlgOpt.Exists() )
-    {
-        m_xDialog->set_window_state(OUStringToOString(aDlgOpt.GetWindowState(), RTL_TEXTENCODING_UTF8));
+    if( !aDlgOpt.Exists() )
+        return;
 
-        Any aUserData = aDlgOpt.GetUserItem( "UserData" );
-        OUString sCfgStr;
-        if( aUserData >>= sCfgStr )
-        {
-            sal_Int32 nPos1{ sCfgStr.indexOf('|') };
-            if (nPos1<0)
-                return;
-            sal_Int32 nPos2{ sCfgStr.indexOf('|', nPos1+1 ) };
-            if (nPos2<0)
-                return;
-            m_xFileView->SetConfigString( sCfgStr.copy(nPos2+1) );
-        }
+    m_xDialog->set_window_state(OUStringToOString(aDlgOpt.GetWindowState(), RTL_TEXTENCODING_UTF8));
+
+    Any aUserData = aDlgOpt.GetUserItem( "UserData" );
+    OUString sCfgStr;
+    if( aUserData >>= sCfgStr )
+    {
+        sal_Int32 nPos1{ sCfgStr.indexOf('|') };
+        if (nPos1<0)
+            return;
+        sal_Int32 nPos2{ sCfgStr.indexOf('|', nPos1+1 ) };
+        if (nPos2<0)
+            return;
+        m_xFileView->SetConfigString( sCfgStr.copy(nPos2+1) );
     }
 }
 
@@ -339,61 +339,61 @@ void RemoteFilesDialog::AddFilter( const OUString& rFilter, const OUString& rTyp
 
 void RemoteFilesDialog::OpenURL( OUString const & sURL )
 {
-    if( m_xFileView )
-    {
-        DisableControls();
+    if( !m_xFileView )
+        return;
 
-        auto xWait = std::make_unique<weld::WaitObject>(m_xDialog.get());
+    DisableControls();
 
-        if( !sURL.isEmpty() )
-        {
-            OUString sFilter = FILEDIALOG_FILTER_ALL;
+    auto xWait = std::make_unique<weld::WaitObject>(m_xDialog.get());
 
-            if( m_nCurrentFilter != -1)
-            {
-                sFilter = m_aFilters[m_nCurrentFilter].second;
-            }
+    if( !sURL.isEmpty() )
+    {
+        OUString sFilter = FILEDIALOG_FILTER_ALL;
 
-            m_xFileView->EndInplaceEditing();
+        if( m_nCurrentFilter != -1)
+        {
+            sFilter = m_aFilters[m_nCurrentFilter].second;
+        }
 
-            DBG_ASSERT( !m_pCurrentAsyncAction.is(), "SvtFileDialog::executeAsync: previous async action not yet finished!" );
+        m_xFileView->EndInplaceEditing();
 
-            m_pCurrentAsyncAction = new AsyncPickerAction( this, m_xFileView.get(), AsyncPickerAction::Action::eOpenURL );
+        DBG_ASSERT( !m_pCurrentAsyncAction.is(), "SvtFileDialog::executeAsync: previous async action not yet finished!" );
 
-            // -1 timeout - sync
-            m_pCurrentAsyncAction->execute( sURL, sFilter, -1, -1, GetBlackList() );
+        m_pCurrentAsyncAction = new AsyncPickerAction( this, m_xFileView.get(), AsyncPickerAction::Action::eOpenURL );
 
-            if( m_eMode != REMOTEDLG_MODE_SAVE )
-                m_xName_ed->set_text( "" );
+        // -1 timeout - sync
+        m_pCurrentAsyncAction->execute( sURL, sFilter, -1, -1, GetBlackList() );
 
-            m_xFileView->grab_focus();
-        }
-        else
-        {
-            xWait.reset();
+        if( m_eMode != REMOTEDLG_MODE_SAVE )
+            m_xName_ed->set_text( "" );
 
-            // content doesn't exist
-            ErrorHandler::HandleError( ERRCODE_IO_NOTEXISTS );
+        m_xFileView->grab_focus();
+    }
+    else
+    {
+        xWait.reset();
 
-            EnableControls();
-        }
+        // content doesn't exist
+        ErrorHandler::HandleError( ERRCODE_IO_NOTEXISTS );
+
+        EnableControls();
     }
 }
 
 void RemoteFilesDialog::AddFileExtension()
 {
-    if (m_nCurrentFilter != -1)
-    {
-        OUString sExt = m_aFilters[m_nCurrentFilter].second;
-        OUString sFileName = m_xName_ed->get_text();
+    if (m_nCurrentFilter == -1)
+        return;
 
-        sal_Int32 nDotPos = sFileName.lastIndexOf( '.' );
+    OUString sExt = m_aFilters[m_nCurrentFilter].second;
+    OUString sFileName = m_xName_ed->get_text();
 
-        if ( nDotPos == -1 )
-        {
-            sFileName += sExt.copy( 1 ); // without '*'
-            m_xName_ed->set_text( sFileName );
-        }
+    sal_Int32 nDotPos = sFileName.lastIndexOf( '.' );
+
+    if ( nDotPos == -1 )
+    {
+        sFileName += sExt.copy( 1 ); // without '*'
+        m_xName_ed->set_text( sFileName );
     }
 }
 
@@ -725,32 +725,32 @@ IMPL_LINK_NOARG( RemoteFilesDialog, DoubleClickHdl, SvtFileView*, bool )
 IMPL_LINK_NOARG( RemoteFilesDialog, SelectHdl, SvtFileView*, void )
 {
     SvtContentEntry* pData = m_xFileView->FirstSelected();
-    if (pData)
+    if (!pData)
+        return;
+
+    if( ( pData->mbIsFolder && ( m_eType == REMOTEDLG_TYPE_PATHDLG ) )
+        || ( !pData->mbIsFolder && ( m_eType == REMOTEDLG_TYPE_FILEDLG ) ) )
     {
-        if( ( pData->mbIsFolder && ( m_eType == REMOTEDLG_TYPE_PATHDLG ) )
-            || ( !pData->mbIsFolder && ( m_eType == REMOTEDLG_TYPE_FILEDLG ) ) )
-        {
-            // url must contain user info, because we need this info in recent files entry
-            // (to fill user field in login box by default)
-            INetURLObject aURL( pData->maURL );
-            INetURLObject aCurrentURL( m_sLastServiceUrl );
-            aURL.SetUser( aCurrentURL.GetUser() );
+        // url must contain user info, because we need this info in recent files entry
+        // (to fill user field in login box by default)
+        INetURLObject aURL( pData->maURL );
+        INetURLObject aCurrentURL( m_sLastServiceUrl );
+        aURL.SetUser( aCurrentURL.GetUser() );
 
-            m_sPath = aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE );
+        m_sPath = aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE );
 
-            m_xName_ed->set_text( aURL.GetLastName(INetURLObject::DecodeMechanism::WithCharset) );
-        }
-        else
+        m_xName_ed->set_text( aURL.GetLastName(INetURLObject::DecodeMechanism::WithCharset) );
+    }
+    else
+    {
+        if( m_eMode == REMOTEDLG_MODE_OPEN )
         {
-            if( m_eMode == REMOTEDLG_MODE_OPEN )
-            {
-                m_sPath.clear();
-                m_xName_ed->set_text( "" );
-            }
+            m_sPath.clear();
+            m_xName_ed->set_text( "" );
         }
-
-        EnableControls();
     }
+
+    EnableControls();
 }
 
 IMPL_LINK_NOARG(RemoteFilesDialog, FileNameGetFocusHdl, weld::Widget&, void)
diff --git a/fpicker/source/office/iodlg.cxx b/fpicker/source/office/iodlg.cxx
index e8f50f6d15d4..c4c12a6f0a8f 100644
--- a/fpicker/source/office/iodlg.cxx
+++ b/fpicker/source/office/iodlg.cxx
@@ -163,56 +163,56 @@ namespace
     void lcl_autoUpdateFileExtension( SvtFileDialog* _pDialog, const OUString& _rLastFilterExt )
     {
         // if auto extension is enabled...
-        if ( _pDialog->isAutoExtensionEnabled() )
-        {
-            // automatically switch to the extension of the (maybe just newly selected) extension
-            OUString aNewFile = _pDialog->getCurrentFileText( );
-            OUString aExt = GetFsysExtension_Impl( aNewFile, _rLastFilterExt );
+        if ( !_pDialog->isAutoExtensionEnabled() )
+            return;
+
+        // automatically switch to the extension of the (maybe just newly selected) extension
+        OUString aNewFile = _pDialog->getCurrentFileText( );
+        OUString aExt = GetFsysExtension_Impl( aNewFile, _rLastFilterExt );
+
+        // but only if there already is an extension
+        if ( aExt.isEmpty() )
+            return;
 
-            // but only if there already is an extension
-            if ( !aExt.isEmpty() )
+        // check if it is a real file extension, and not only the "post-dot" part in
+        // a directory name
+        bool bRealExtensions = true;
+        if ( -1 != aExt.indexOf( '/' ) )
+            bRealExtensions = false;
+        else if ( -1 != aExt.indexOf( '\\' ) )
+            bRealExtensions = false;
+        else
+        {
+            // no easy way to tell, because the part containing the dot already is the last
+            // segment of the complete file name
+            // So we have to check if the file name denotes a folder or a file.
+            // For performance reasons, we do this for file urls only
+            INetURLObject aURL( aNewFile );
+            if ( INetProtocol::NotValid == aURL.GetProtocol() )
+            {
+                OUString sURL;
+                if ( osl::FileBase::getFileURLFromSystemPath( aNewFile, sURL )
+                     == osl::FileBase::E_None )
+                    aURL = INetURLObject( sURL );
+            }
+            if ( INetProtocol::File == aURL.GetProtocol() )
             {
-                // check if it is a real file extension, and not only the "post-dot" part in
-                // a directory name
-                bool bRealExtensions = true;
-                if ( -1 != aExt.indexOf( '/' ) )
-                    bRealExtensions = false;
-                else if ( -1 != aExt.indexOf( '\\' ) )
-                    bRealExtensions = false;
-                else
+                try
                 {
-                    // no easy way to tell, because the part containing the dot already is the last
-                    // segment of the complete file name
-                    // So we have to check if the file name denotes a folder or a file.
-                    // For performance reasons, we do this for file urls only
-                    INetURLObject aURL( aNewFile );
-                    if ( INetProtocol::NotValid == aURL.GetProtocol() )
-                    {
-                        OUString sURL;
-                        if ( osl::FileBase::getFileURLFromSystemPath( aNewFile, sURL )
-                             == osl::FileBase::E_None )
-                            aURL = INetURLObject( sURL );
-                    }
-                    if ( INetProtocol::File == aURL.GetProtocol() )
-                    {
-                        try
-                        {
-                            bRealExtensions = !_pDialog->ContentIsFolder( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
-                        }
-                        catch( const css::uno::Exception& )
-                        {
-                            SAL_INFO( "fpicker.office", "Exception in lcl_autoUpdateFileExtension" );
-                        }
-                    }
+                    bRealExtensions = !_pDialog->ContentIsFolder( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
                 }
-
-                if ( bRealExtensions )
+                catch( const css::uno::Exception& )
                 {
-                    SetFsysExtension_Impl( aNewFile, _pDialog->GetDefaultExt() );
-                    _pDialog->setCurrentFileText( aNewFile );
+                    SAL_INFO( "fpicker.office", "Exception in lcl_autoUpdateFileExtension" );
                 }
             }
         }
+
+        if ( bRealExtensions )
+        {
+            SetFsysExtension_Impl( aNewFile, _pDialog->GetDefaultExt() );
+            _pDialog->setCurrentFileText( aNewFile );
+        }
     }
 
 #if defined( UNX )
@@ -484,25 +484,26 @@ SvtFileDialog::~SvtFileDialog()
     m_xFileView->SetSelectHdl(Link<SvtFileView*,void>());
 
     // Save bookmarked places
-    if (m_xImpl->m_xPlaces->IsUpdated()) {
-        const std::vector<PlacePtr> aPlaces = m_xImpl->m_xPlaces->GetPlaces();
-        Sequence< OUString > placesUrlsList(m_xImpl->m_xPlaces->GetNbEditablePlaces());
-        Sequence< OUString > placesNamesList(m_xImpl->m_xPlaces->GetNbEditablePlaces());
-        int i(0);
-        for (auto const& place : aPlaces)
-        {
-            if(place->IsEditable()) {
-                placesUrlsList[i] = place->GetUrl();
-                placesNamesList[i] = place->GetName();
-                ++i;
-            }
-        }
+    if (!m_xImpl->m_xPlaces->IsUpdated())
+        return;
 
-        std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_xContext));
-        officecfg::Office::Common::Misc::FilePickerPlacesUrls::set(placesUrlsList, batch);
-        officecfg::Office::Common::Misc::FilePickerPlacesNames::set(placesNamesList, batch);
-        batch->commit();
+    const std::vector<PlacePtr> aPlaces = m_xImpl->m_xPlaces->GetPlaces();
+    Sequence< OUString > placesUrlsList(m_xImpl->m_xPlaces->GetNbEditablePlaces());
+    Sequence< OUString > placesNamesList(m_xImpl->m_xPlaces->GetNbEditablePlaces());
+    int i(0);
+    for (auto const& place : aPlaces)
+    {
+        if(place->IsEditable()) {
+            placesUrlsList[i] = place->GetUrl();
+            placesNamesList[i] = place->GetName();
+            ++i;
+        }
     }
+
+    std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(m_xContext));
+    officecfg::Office::Common::Misc::FilePickerPlacesUrls::set(placesUrlsList, batch);
+    officecfg::Office::Common::Misc::FilePickerPlacesNames::set(placesNamesList, batch);
+    batch->commit();
 }
 
 IMPL_LINK_NOARG(SvtFileDialog, NewFolderHdl_Impl, weld::Button&, void)
@@ -2266,25 +2267,25 @@ void SvtFileDialog::appendDefaultExtension(OUString& rFileName,
 {
     const OUString aType(rFilterExtensions.toAsciiLowerCase());
 
-    if ( aType != FILEDIALOG_FILTER_ALL )
-    {
-        const OUString aTemp(rFileName.toAsciiLowerCase());
-        sal_Int32 nPos = 0;
+    if ( aType == FILEDIALOG_FILTER_ALL )
+        return;
 
-        do
-        {
-            if (nPos+1<aType.getLength() && aType[nPos]=='*') // take care of a leading *
-                ++nPos;
-            const OUString aExt(aType.getToken( 0, FILEDIALOG_DEF_EXTSEP, nPos ));
-            if (aExt.isEmpty())
-                continue;
-            if (aTemp.endsWith(aExt))
-                return;
-        }
-        while (nPos>=0);
+    const OUString aTemp(rFileName.toAsciiLowerCase());
+    sal_Int32 nPos = 0;
 
-        rFileName += "." + rFilterDefaultExtension;
+    do
+    {
+        if (nPos+1<aType.getLength() && aType[nPos]=='*') // take care of a leading *
+            ++nPos;
+        const OUString aExt(aType.getToken( 0, FILEDIALOG_DEF_EXTSEP, nPos ));
+        if (aExt.isEmpty())
+            continue;
+        if (aTemp.endsWith(aExt))
+            return;
     }
+    while (nPos>=0);
+
+    rFileName += "." + rFilterDefaultExtension;
 }
 
 void SvtFileDialog::initDefaultPlaces( )


More information about the Libreoffice-commits mailing list