Kaydet (Commit) ff8c4923 authored tarafından Mike Kaganski's avatar Mike Kaganski

Optimize getting filter mask by index from CFilterContainer

Change-Id: Id4ea2c3dd7420954b1852021f136bc98f20a9846
Reviewed-on: https://gerrit.libreoffice.org/64663
Tested-by: Jenkins
Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 2edc86a5
......@@ -99,33 +99,36 @@ void CFilterContainer::empty()
// Precondition: the container is not empty
// there is a filter identified by the name
bool CFilterContainer::getFilter( const OUString& aName, OUString& theFilter ) const
bool CFilterContainer::getFilterByName(const OUString& aName, OUString& theFilter) const
{
OSL_PRECOND( !m_vFilters.empty() , "Empty filter container" );
return getFilterByIndex(getFilterTagPos(aName), theFilter);
}
sal_Int32 pos = getFilterTagPos( aName );
bool CFilterContainer::getFilterByIndex(sal_Int32 aIndex, OUString& theFilter) const
{
bool bRet = true;
try
{
if ( pos > -1 )
theFilter = m_vFilters.at( pos ).second;
theFilter = m_vFilters.at(aIndex).second;
}
catch( std::out_of_range& )
catch (std::out_of_range&)
{
OSL_FAIL( "Filter not in filter container" );
pos = -1;
OSL_FAIL("Filter index out of range");
bRet = false;
}
return pos > -1;
return bRet;
}
bool CFilterContainer::getFilter( sal_Int32 aIndex, OUString& theFilter ) const
bool CFilterContainer::getFilterNameByIndex(sal_Int32 aIndex, OUString& theName) const
{
bool bRet = true;
try
{
theFilter = m_vFilters.at( aIndex ).first;
theName = m_vFilters.at(aIndex).first;
}
catch( std::out_of_range& )
{
......
......@@ -58,11 +58,12 @@ public:
// clear all entries
void empty( );
// retrieve a filter from the container both methods
// retrieve a filter from the container. These methods
// return true on success and false if the specified
// filter was not found
bool getFilter( const OUString& aName, OUString& theFilter ) const;
bool getFilter( sal_Int32 aIndex, OUString& theFilter ) const;
bool getFilterByName(const OUString& aName, OUString& theFilter) const;
bool getFilterByIndex(sal_Int32 aIndex, OUString& theFilter) const;
bool getFilterNameByIndex(sal_Int32 aIndex, OUString& theName) const;
// returns the position of the specified filter or -1
// if the filter was not found
......
......@@ -428,7 +428,7 @@ void VistaFilePickerImpl::impl_sta_getCurrentFilter(const RequestRef& rRequest)
::sal_Int32 nRealIndex = (nIndex-1); // COM dialog base on 1 ... filter container on 0 .-)
if (
(nRealIndex >= 0 ) &&
(m_lFilters.getFilter(nRealIndex, sTitle))
(m_lFilters.getFilterNameByIndex(nRealIndex, sTitle))
)
rRequest->setArgument(PROP_FILTER_TITLE, sTitle);
else if ( nRealIndex == -1 ) // Dialog not visible yet
......@@ -1003,16 +1003,12 @@ void VistaFilePickerImpl::impl_sta_ShowDialogModal(const RequestRef& rRequest)
{
// COM dialog base on 1 ... filter container on 0 .-)
::size_t nRealIndex = (nFileType-1);
std::vector<OUString> vStrings;
::std::vector<COMDLG_FILTERSPEC> lFilters
= lcl_buildFilterList(m_lFilters, vStrings);
if ( nRealIndex < lFilters.size() )
OUString sFilter;
if (m_lFilters.getFilterByIndex(nRealIndex, sFilter))
{
PCWSTR lpFilterExt = lFilters[nRealIndex].pszSpec;
lpFilterExt = wcsrchr( lpFilterExt, '.' );
if ( lpFilterExt )
aFileURL += o3tl::toU(lpFilterExt);
const sal_Int32 idx = sFilter.indexOf('.');
if (idx >= 0)
aFileURL += sFilter.copy(idx);
}
}
}
......@@ -1285,7 +1281,7 @@ void VistaFilePickerImpl::impl_SetDefaultExtension( const OUString& currentFilte
if (currentFilter.getLength())
{
OUString FilterExt;
m_lFilters.getFilter(currentFilter, FilterExt);
m_lFilters.getFilterByName(currentFilter, FilterExt);
sal_Int32 posOfPoint = FilterExt.indexOf(L'.');
const sal_Unicode* pFirstExtStart = FilterExt.getStr() + posOfPoint + 1;
......@@ -1306,7 +1302,7 @@ void VistaFilePickerImpl::onAutoExtensionChanged (bool bChecked)
const OUString sFilter = m_lFilters.getCurrentFilter ();
OUString sExt ;
if ( !m_lFilters.getFilter (sFilter, sExt))
if (!m_lFilters.getFilterByName(sFilter, sExt))
return;
TFileDialog iDialog = impl_getBaseDialogInterface();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment