diff options
-rw-r--r-- | sfx2/inc/guisaveas.hxx | 1 | ||||
-rw-r--r-- | sfx2/source/dialog/alienwarn.cxx | 10 | ||||
-rw-r--r-- | sfx2/source/doc/guisaveas.cxx | 49 | ||||
-rw-r--r-- | sfx2/source/inc/alienwarn.hxx | 3 | ||||
-rw-r--r-- | sfx2/uiconfig/ui/alienwarndialog.ui | 4 |
5 files changed, 51 insertions, 16 deletions
diff --git a/sfx2/inc/guisaveas.hxx b/sfx2/inc/guisaveas.hxx index 0c2aa9048746..19bfb51ff5e3 100644 --- a/sfx2/inc/guisaveas.hxx +++ b/sfx2/inc/guisaveas.hxx @@ -80,6 +80,7 @@ public: const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel, const OUString& aOldUIName, const OUString& aDefUIName, + const OUString& aDefExtension, bool bCanProceedFurther ); static vcl::Window* GetModelWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel ); diff --git a/sfx2/source/dialog/alienwarn.cxx b/sfx2/source/dialog/alienwarn.cxx index d1dc6ea1c136..e6c8234964b5 100644 --- a/sfx2/source/dialog/alienwarn.cxx +++ b/sfx2/source/dialog/alienwarn.cxx @@ -25,7 +25,7 @@ #include <vcl/msgbox.hxx> #include "alienwarn.hxx" -SfxAlienWarningDialog::SfxAlienWarningDialog(vcl::Window* pParent, const OUString& _rFormatName) +SfxAlienWarningDialog::SfxAlienWarningDialog(vcl::Window* pParent, const OUString& _rFormatName, const OUString& _rDefaultExtension) : MessageDialog(pParent, "AlienWarnDialog", "sfx/ui/alienwarndialog.ui") { get(m_pWarningOnBox, "ask"); @@ -34,6 +34,9 @@ SfxAlienWarningDialog::SfxAlienWarningDialog(vcl::Window* pParent, const OUStrin m_pWarningOnBox->set_margin_left(QueryBox::GetStandardImage().GetSizePixel().Width() + 12); get(m_pKeepCurrentBtn, "save"); + get(m_pUseDefaultFormatBtn, "cancel"); + + OUString aExtension = _rDefaultExtension.toAsciiUpperCase(); // replace formatname (text) OUString sInfoText = get_primary_text(); @@ -45,6 +48,11 @@ SfxAlienWarningDialog::SfxAlienWarningDialog(vcl::Window* pParent, const OUStrin sInfoText = sInfoText.replaceAll( "%FORMATNAME", _rFormatName ); m_pKeepCurrentBtn->SetText( sInfoText ); + // replace defaultextension (button) + sInfoText = m_pUseDefaultFormatBtn->GetText(); + sInfoText = sInfoText.replaceAll( "%DEFAULTEXTENSION", aExtension ); + m_pUseDefaultFormatBtn->SetText( sInfoText ); + // load value of "warning on" checkbox from save options m_pWarningOnBox->Check( SvtSaveOptions().IsWarnAlienFormat() ); } diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx index c75786910d38..12519424e271 100644 --- a/sfx2/source/doc/guisaveas.cxx +++ b/sfx2/source/doc/guisaveas.cxx @@ -317,6 +317,7 @@ public: bool ShowDocumentInfoDialog(); + OUString GetRecommendedExtension( const OUString& aTypeName ); OUString GetRecommendedDir( const OUString& aSuggestedDir ); OUString GetRecommendedName( const OUString& aSuggestedName, const OUString& aTypeName ); @@ -791,6 +792,10 @@ sal_Int8 ModelData_Impl::CheckFilter( const OUString& aFilterName ) OUString aPreusedFilterName = GetDocProps().getUnpackedValueOrDefault( OUString("PreusedFilterName"), OUString() ); + + OUString aDefType = aDefFiltPropsHM.getUnpackedValueOrDefault( "Type", OUString() ); + OUString aDefExtension = GetRecommendedExtension( aDefType ); + if ( !aPreusedFilterName.equals( aFilterName ) && !aUIName.equals( aDefUIName ) ) { // is it possible to get these names from somewhere and not just @@ -828,7 +833,7 @@ sal_Int8 ModelData_Impl::CheckFilter( const OUString& aFilterName ) return STATUS_SAVEAS; } } - if ( !SfxStoringHelper::WarnUnacceptableFormat( GetModel(), aUIName, aDefUIName, true ) ) + if ( !SfxStoringHelper::WarnUnacceptableFormat( GetModel(), aUIName, aDefUIName, aDefExtension, true ) ) return STATUS_SAVEAS_STANDARDNAME; } } @@ -1216,6 +1221,32 @@ bool ModelData_Impl::ShowDocumentInfoDialog() } +OUString ModelData_Impl::GetRecommendedExtension( const OUString& aTypeName ) +{ + if ( aTypeName.isEmpty() ) + return OUString(); + + uno::Reference< container::XNameAccess > xTypeDetection = uno::Reference< container::XNameAccess >( + comphelper::getProcessServiceFactory()->createInstance("com.sun.star.document.TypeDetection"), + uno::UNO_QUERY ); + if ( xTypeDetection.is() ) + { + uno::Sequence< beans::PropertyValue > aTypeNameProps; + if ( ( xTypeDetection->getByName( aTypeName ) >>= aTypeNameProps ) && aTypeNameProps.getLength() ) + { + ::comphelper::SequenceAsHashMap aTypeNamePropsHM( aTypeNameProps ); + uno::Sequence< OUString > aExtensions = aTypeNamePropsHM.getUnpackedValueOrDefault( + OUString("Extensions"), + ::uno::Sequence< OUString >() ); + if ( aExtensions.getLength() ) + return aExtensions[0]; + } + } + + return OUString(); +} + + OUString ModelData_Impl::GetRecommendedDir( const OUString& aSuggestedDir ) { OUString aRecommendedDir; @@ -1283,16 +1314,9 @@ OUString ModelData_Impl::GetRecommendedName( const OUString& aSuggestedName, con INetURLObject aObj( "c:/" + aRecommendedName, INetProtocol::File, INetURLObject::ENCODE_ALL, RTL_TEXTENCODING_UTF8, INetURLObject::FSYS_DOS ); - uno::Sequence< beans::PropertyValue > aTypeNameProps; - if ( ( xTypeDetection->getByName( aTypeName ) >>= aTypeNameProps ) && aTypeNameProps.getLength() ) - { - ::comphelper::SequenceAsHashMap aTypeNamePropsHM( aTypeNameProps ); - uno::Sequence< OUString > aExtensions = aTypeNamePropsHM.getUnpackedValueOrDefault( - OUString("Extensions"), - ::uno::Sequence< OUString >() ); - if ( aExtensions.getLength() ) - aObj.SetExtension( aExtensions[0] ); - } + OUString aExtension = GetRecommendedExtension( aTypeName ); + if ( !aExtension.isEmpty() ) + aObj.SetExtension( aExtension ); aRecommendedName = aObj.GetName( INetURLObject::DECODE_WITH_CHARSET, RTL_TEXTENCODING_UTF8 ); } @@ -1850,13 +1874,14 @@ void SfxStoringHelper::SetDocInfoState( bool SfxStoringHelper::WarnUnacceptableFormat( const uno::Reference< frame::XModel >& xModel, const OUString& aOldUIName, const OUString& /*aDefUIName*/, + const OUString& aDefExtension, bool /*bCanProceedFurther*/ ) { if ( !SvtSaveOptions().IsWarnAlienFormat() ) return true; vcl::Window* pWin = SfxStoringHelper::GetModelWindow( xModel ); - SfxAlienWarningDialog aDlg( pWin, aOldUIName ); + SfxAlienWarningDialog aDlg( pWin, aOldUIName, aDefExtension ); return aDlg.Execute() == RET_OK; } diff --git a/sfx2/source/inc/alienwarn.hxx b/sfx2/source/inc/alienwarn.hxx index 8609f68ce861..f2f455211432 100644 --- a/sfx2/source/inc/alienwarn.hxx +++ b/sfx2/source/inc/alienwarn.hxx @@ -26,10 +26,11 @@ class SfxAlienWarningDialog : public MessageDialog { private: PushButton* m_pKeepCurrentBtn; + PushButton* m_pUseDefaultFormatBtn; CheckBox* m_pWarningOnBox; public: - SfxAlienWarningDialog(vcl::Window* pParent, const OUString& _rFormatName); + SfxAlienWarningDialog(vcl::Window* pParent, const OUString& _rFormatName, const OUString& _rDefaultExtension); virtual ~SfxAlienWarningDialog(); }; diff --git a/sfx2/uiconfig/ui/alienwarndialog.ui b/sfx2/uiconfig/ui/alienwarndialog.ui index d83a47f45a97..d7b49b8d5cbd 100644 --- a/sfx2/uiconfig/ui/alienwarndialog.ui +++ b/sfx2/uiconfig/ui/alienwarndialog.ui @@ -24,7 +24,7 @@ <property name="layout_style">end</property> <child> <object class="GtkButton" id="cancel"> - <property name="label" translatable="yes">Use _ODF Format</property> + <property name="label" translatable="yes">Use %DEFAULTEXTENSION _Format</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> @@ -65,7 +65,7 @@ </child> <child> <object class="GtkCheckButton" id="ask"> - <property name="label" translatable="yes">_Ask when not saving in ODF format</property> + <property name="label" translatable="yes">_Ask when not saving in ODF or default format</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">False</property> |