[Libreoffice-commits] core.git: 2 commits - sd/source
Katarina Behrens
Katarina.Behrens at cib.de
Wed Apr 15 05:54:29 PDT 2015
sd/source/ui/func/fuinsfil.cxx | 114 ++++++++++++++++++++++++++---------------
1 file changed, 75 insertions(+), 39 deletions(-)
New commits:
commit 24d6c704a6a5fb9d0bfbea4156a8d95c27693544
Author: Katarina Behrens <Katarina.Behrens at cib.de>
Date: Wed Apr 15 14:50:43 2015 +0200
tdf#62101: Show only file extensions we're able to insert
Change-Id: If8f53ac8af85f15958cd488fb0fd4c37997963c9
diff --git a/sd/source/ui/func/fuinsfil.cxx b/sd/source/ui/func/fuinsfil.cxx
index ce6d3e7..7b554d2 100644
--- a/sd/source/ui/func/fuinsfil.cxx
+++ b/sd/source/ui/func/fuinsfil.cxx
@@ -69,6 +69,42 @@ using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::com::sun::star;
+typedef ::std::pair< OUString, OUString > FilterDesc;
+
+namespace
+{
+
+OUString lcl_GetExtensionsList ( ::std::vector< FilterDesc > const& rFilterDescList )
+{
+ OUString aExtensions;
+ ::std::vector< FilterDesc >::const_iterator aIter( rFilterDescList.begin() );
+
+ while (aIter != rFilterDescList.end())
+ {
+ OUString sWildcard = (*aIter).second;
+
+ if ( aExtensions.indexOf( sWildcard ) == -1 )
+ {
+ if ( !aExtensions.isEmpty() )
+ aExtensions += ";";
+ aExtensions += sWildcard;
+ }
+
+ ++aIter;
+ }
+
+ return aExtensions;
+}
+
+void lcl_AddFilter ( ::std::vector< FilterDesc >& rFilterDescList,
+ const SfxFilter *pFilter )
+{
+ if (pFilter)
+ rFilterDescList.push_back( ::std::make_pair( pFilter->GetUIName(), pFilter->GetDefaultExtension() ) );
+}
+
+}
+
namespace sd {
TYPEINIT1( FuInsertFile, FuPoor );
@@ -93,10 +129,11 @@ rtl::Reference<FuPoor> FuInsertFile::Create( ViewShell* pViewSh, ::sd::Window* p
void FuInsertFile::DoExecute( SfxRequest& rReq )
{
SfxFilterMatcher& rMatcher = SfxGetpApp()->GetFilterMatcher();
- ::std::vector< OUString > aFilterVector;
+ ::std::vector< FilterDesc > aFilterVector;
+ ::std::vector< OUString > aOtherFilterVector;
const SfxItemSet* pArgs = rReq.GetArgs ();
- FuInsertFile::GetSupportedFilterVector( aFilterVector );
+ FuInsertFile::GetSupportedFilterVector( aOtherFilterVector );
if (!pArgs)
{
@@ -128,72 +165,73 @@ void FuInsertFile::DoExecute( SfxRequest& rReq )
// Get filter for current format
try
{
- OUString aAllSpec( SD_RESSTR( STR_ALL_FILES ) );
-
- xFilterManager->appendFilter( aAllSpec, OUString("*.*") );
- xFilterManager->setCurrentFilter( aAllSpec ); // set default-filter (<All>)
-
// Get main filter
const SfxFilter* pFilter = SfxFilter::GetDefaultFilterFromFactory( aOwnCont );
- if( pFilter )
- xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
+ lcl_AddFilter( aFilterVector, pFilter );
// get template filter
if( mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
pFilter = DrawDocShell::Factory().GetTemplateFilter();
else
pFilter = GraphicDocShell::Factory().GetTemplateFilter();
- if( pFilter )
- xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
+ lcl_AddFilter( aFilterVector, pFilter );
// get cross filter
pFilter = SfxFilter::GetDefaultFilterFromFactory( aOtherCont );
- if( pFilter )
- {
- xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
- }
+ lcl_AddFilter( aFilterVector, pFilter );
// get Powerpoint filter
OUString aExt = ".ppt";
pFilter = aMatch.GetFilter4Extension( aExt );
- if( pFilter )
- xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
+ lcl_AddFilter( aFilterVector, pFilter );
// Get other draw/impress filters
pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARIMPRESS_60, SfxFilterFlags::IMPORT, SfxFilterFlags::TEMPLATEPATH );
- if( pFilter )
- xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
+ lcl_AddFilter( aFilterVector, pFilter );
pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARIMPRESS_60, SfxFilterFlags::TEMPLATEPATH );
- if( pFilter )
- xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
+ lcl_AddFilter( aFilterVector, pFilter );
pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW_60, SfxFilterFlags::IMPORT, SfxFilterFlags::TEMPLATEPATH );
- if( pFilter )
- xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
+ lcl_AddFilter( aFilterVector, pFilter );
pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW_60, SfxFilterFlags::TEMPLATEPATH );
- if( pFilter )
- xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
+ lcl_AddFilter( aFilterVector, pFilter );
pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW, SfxFilterFlags::IMPORT, SfxFilterFlags::TEMPLATEPATH );
- if( pFilter )
- xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
+ lcl_AddFilter( aFilterVector, pFilter );
pFilter = aMatch.GetFilter4ClipBoardId( SotClipboardFormatId::STARDRAW, SfxFilterFlags::TEMPLATEPATH );
- if( pFilter )
- xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
+ lcl_AddFilter( aFilterVector, pFilter );
// add additional supported filters
- ::std::vector< OUString >::const_iterator aIter( aFilterVector.begin() );
+ ::std::vector< OUString >::const_iterator aOtherIter( aOtherFilterVector.begin() );
- while( aIter != aFilterVector.end() )
+ while( aOtherIter != aOtherFilterVector.end() )
{
- if( ( pFilter = rMatcher.GetFilter4Mime( *aIter ) ) != NULL )
- xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
+ if( ( pFilter = rMatcher.GetFilter4Mime( *aOtherIter ) ) != NULL )
+ lcl_AddFilter( aFilterVector, pFilter );
+ ++aOtherIter;
+ }
+
+ // set default-filter (<All>)
+ OUString aAllSpec( SD_RESSTR( STR_ALL_FILES ) );
+ OUString aExtensions = lcl_GetExtensionsList( aFilterVector );
+ OUString aGUIName = aAllSpec + " (" + aExtensions + ")";
+
+ xFilterManager->appendFilter( aGUIName, aExtensions );
+ xFilterManager->setCurrentFilter( aAllSpec );
+
+ // add filters to filter manager finally
+ ::std::vector< ::std::pair < OUString, OUString > >::const_iterator aIter( aFilterVector.begin() );
+
+ while( aIter != aFilterVector.end() )
+ {
+ xFilterManager->appendFilter( (*aIter).first, (*aIter).second );
++aIter;
}
+
}
catch (const IllegalArgumentException&)
{
@@ -252,7 +290,7 @@ void FuInsertFile::DoExecute( SfxRequest& rReq )
}
else
{
- bool bFound = ( ::std::find( aFilterVector.begin(), aFilterVector.end(), pFilter->GetMimeType() ) != aFilterVector.end() );
+ bool bFound = ( ::std::find( aOtherFilterVector.begin(), aOtherFilterVector.end(), pFilter->GetMimeType() ) != aOtherFilterVector.end() );
if( !bFound &&
( aFilterName.indexOf( "Text" ) != -1 ||
aFilterName.indexOf( "Rich" ) != -1 ||
commit fd9f706f2e8b048a83ea002ecb5f525ca3e21f61
Author: Katarina Behrens <Katarina.Behrens at cib.de>
Date: Tue Apr 14 17:33:36 2015 +0200
Use cross-app filter directly
and bypass SfxFilterMatcher, which will likely not find it. We're
able to insert .odp file into Draw and .odg file into Impress
anyway
Change-Id: I02332f0ebd6856d088261ce014bd04f87acfbac6
diff --git a/sd/source/ui/func/fuinsfil.cxx b/sd/source/ui/func/fuinsfil.cxx
index c47c8ec..ce6d3e7 100644
--- a/sd/source/ui/func/fuinsfil.cxx
+++ b/sd/source/ui/func/fuinsfil.cxx
@@ -138,15 +138,6 @@ void FuInsertFile::DoExecute( SfxRequest& rReq )
if( pFilter )
xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
- // get cross filter
- pFilter = SfxFilter::GetDefaultFilterFromFactory( aOtherCont );
- if( pFilter )
- {
- pFilter = aMatch.GetFilter4Extension( pFilter->GetDefaultExtension() );
- if ( pFilter )
- xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
- }
-
// get template filter
if( mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
pFilter = DrawDocShell::Factory().GetTemplateFilter();
@@ -155,6 +146,13 @@ void FuInsertFile::DoExecute( SfxRequest& rReq )
if( pFilter )
xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
+ // get cross filter
+ pFilter = SfxFilter::GetDefaultFilterFromFactory( aOtherCont );
+ if( pFilter )
+ {
+ xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
+ }
+
// get Powerpoint filter
OUString aExt = ".ppt";
pFilter = aMatch.GetFilter4Extension( aExt );
More information about the Libreoffice-commits
mailing list