24#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
25#include <com/sun/star/ui/dialogs/FilePicker.hpp>
26#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
27#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
28#include <com/sun/star/ui/dialogs/XFilterManager.hpp>
29#include <com/sun/star/beans/PropertyValue.hpp>
30#include <com/sun/star/container/XEnumeration.hpp>
31#include <com/sun/star/container/XNameAccess.hpp>
32#include <com/sun/star/view/XControlAccess.hpp>
43 mxFilePicker = FilePicker::createWithMode( rxContext, TemplateDescription::FILESAVE_AUTOEXTENSION);
46 Reference< XFilePickerControlAccess > xAccess(
mxFilePicker, UNO_QUERY );
51 xAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0,
Any(
true ) );
53 catch( css::uno::Exception& )
58 Reference< XNameAccess > xFilters( rxContext->getServiceManager()->createInstanceWithContext(
59 "com.sun.star.document.FilterFactory", rxContext ), UNO_QUERY_THROW );
60 const Sequence< OUString > aFilterList( xFilters->getElementNames() );
61 for (
const auto& rFilter : aFilterList )
65 Sequence< PropertyValue > aFilterProperties;
66 if ( xFilters->getByName( rFilter ) >>= aFilterProperties )
69 bool bImpressFilter =
false;
70 for (
const PropertyValue& rProperty : std::as_const(aFilterProperties) )
73 switch(
TKGet( rProperty.Name ) )
80 bImpressFilter =
true;
87 case TK_Type : rProperty.Value >>= aFilterEntry.
maType;
break;
95 if ( bImpressFilter && ( ( aFilterEntry.
maFlags & 3 ) == 3 ) )
106 Reference< XNameAccess > xTypes( rxContext->getServiceManager()->createInstanceWithContext(
107 "com.sun.star.document.TypeDetection", rxContext ), UNO_QUERY_THROW );
111 Sequence< PropertyValue > aTypeProperties;
114 if ( xTypes->getByName( rFilterEntry.maType ) >>= aTypeProperties )
116 Sequence< OUString > aExtensions;
117 auto pProp = std::find_if(std::cbegin(aTypeProperties), std::cend(aTypeProperties),
118 [](
const PropertyValue& rProp) {
return rProp.Name ==
"Extensions"; });
119 if (pProp != std::cend(aTypeProperties))
120 pProp->Value >>= aExtensions;
121 if ( aExtensions.hasElements() )
127 rFilterEntry.maUIName +
" (." + aExtensions[0] +
")");
128 rFilterEntry.maUIName = aTitle;
129 OUString aFilter(
"*." + aExtensions[0]);
131 if ( rFilterEntry.maFlags & 0x100 )
154 Sequence< OUString > aFileSeq(
mxFilePicker->getSelectedFiles() );
155 return aFileSeq.hasElements() ? aFileSeq[ 0 ] : OUString();
159 OUString aFilterName;
160 Reference< XFilterManager > xFilterManager(
mxFilePicker, UNO_QUERY_THROW );
161 OUString
aUIName( xFilterManager->getCurrentFilter() );
163 [&
aUIName](
const FilterEntry& rFilterEntry) { return rFilterEntry.maUIName == aUIName; });
165 aFilterName = aIter->maFilterEntryName;
constexpr OUStringLiteral sDocumentService
FileOpenDialog(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
void setDefaultName(const OUString &)
OUString getFilterName() const
css::uno::Reference< css::ui::dialogs::XFilePicker3 > mxFilePicker
std::vector< FilterEntry > aFilterEntryList
PPPOptimizerTokenEnum TKGet(std::u16string_view rToken)
OUString maFilterEntryName