Kaydet (Commit) e904e6ad authored tarafından Juan A. Suarez Romero's avatar Juan A. Suarez Romero Kaydeden (comit) Jacobo Aragunde Pérez

tdf#90478: Show the right default format when saving

When saving a file that is not in ODF format (the default format), there
is a dialog asking if should keep the original format or rather use ODF.

But the default format can be changed to a different one than ODF. And
the dialog will still assume the ODF is the default one.

This commit fixes the wording in the dialog to use the the default
format instead of hard-coded ODF.

In order to keep the text simple, instead of using the long name for the
default format, it uses the proper file extension.

So if for example changes from ODF to Microsoft Word 97 default format,
and saving a non-Word document, the dialog will ask user if document
should be saved in default DOC format.

Change-Id: I0b259af9eca61161ec8a3d7e72d4722b5afdf4b4
Reviewed-on: https://gerrit.libreoffice.org/15170Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarJacobo Aragunde Pérez <jaragunde@igalia.com>
üst 36189096
...@@ -80,6 +80,7 @@ public: ...@@ -80,6 +80,7 @@ public:
const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel,
const OUString& aOldUIName, const OUString& aOldUIName,
const OUString& aDefUIName, const OUString& aDefUIName,
const OUString& aDefExtension,
bool bCanProceedFurther ); bool bCanProceedFurther );
static vcl::Window* GetModelWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel ); static vcl::Window* GetModelWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel );
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include <vcl/msgbox.hxx> #include <vcl/msgbox.hxx>
#include "alienwarn.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") : MessageDialog(pParent, "AlienWarnDialog", "sfx/ui/alienwarndialog.ui")
{ {
get(m_pWarningOnBox, "ask"); get(m_pWarningOnBox, "ask");
...@@ -34,6 +34,9 @@ SfxAlienWarningDialog::SfxAlienWarningDialog(vcl::Window* pParent, const OUStrin ...@@ -34,6 +34,9 @@ SfxAlienWarningDialog::SfxAlienWarningDialog(vcl::Window* pParent, const OUStrin
m_pWarningOnBox->set_margin_left(QueryBox::GetStandardImage().GetSizePixel().Width() + 12); m_pWarningOnBox->set_margin_left(QueryBox::GetStandardImage().GetSizePixel().Width() + 12);
get(m_pKeepCurrentBtn, "save"); get(m_pKeepCurrentBtn, "save");
get(m_pUseDefaultFormatBtn, "cancel");
OUString aExtension = _rDefaultExtension.toAsciiUpperCase();
// replace formatname (text) // replace formatname (text)
OUString sInfoText = get_primary_text(); OUString sInfoText = get_primary_text();
...@@ -45,6 +48,11 @@ SfxAlienWarningDialog::SfxAlienWarningDialog(vcl::Window* pParent, const OUStrin ...@@ -45,6 +48,11 @@ SfxAlienWarningDialog::SfxAlienWarningDialog(vcl::Window* pParent, const OUStrin
sInfoText = sInfoText.replaceAll( "%FORMATNAME", _rFormatName ); sInfoText = sInfoText.replaceAll( "%FORMATNAME", _rFormatName );
m_pKeepCurrentBtn->SetText( sInfoText ); 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 // load value of "warning on" checkbox from save options
m_pWarningOnBox->Check( SvtSaveOptions().IsWarnAlienFormat() ); m_pWarningOnBox->Check( SvtSaveOptions().IsWarnAlienFormat() );
} }
......
...@@ -317,6 +317,7 @@ public: ...@@ -317,6 +317,7 @@ public:
bool ShowDocumentInfoDialog(); bool ShowDocumentInfoDialog();
OUString GetRecommendedExtension( const OUString& aTypeName );
OUString GetRecommendedDir( const OUString& aSuggestedDir ); OUString GetRecommendedDir( const OUString& aSuggestedDir );
OUString GetRecommendedName( const OUString& aSuggestedName, OUString GetRecommendedName( const OUString& aSuggestedName,
const OUString& aTypeName ); const OUString& aTypeName );
...@@ -791,6 +792,10 @@ sal_Int8 ModelData_Impl::CheckFilter( const OUString& aFilterName ) ...@@ -791,6 +792,10 @@ sal_Int8 ModelData_Impl::CheckFilter( const OUString& aFilterName )
OUString aPreusedFilterName = GetDocProps().getUnpackedValueOrDefault( OUString aPreusedFilterName = GetDocProps().getUnpackedValueOrDefault(
OUString("PreusedFilterName"), OUString("PreusedFilterName"),
OUString() ); OUString() );
OUString aDefType = aDefFiltPropsHM.getUnpackedValueOrDefault( "Type", OUString() );
OUString aDefExtension = GetRecommendedExtension( aDefType );
if ( !aPreusedFilterName.equals( aFilterName ) && !aUIName.equals( aDefUIName ) ) if ( !aPreusedFilterName.equals( aFilterName ) && !aUIName.equals( aDefUIName ) )
{ {
// is it possible to get these names from somewhere and not just // is it possible to get these names from somewhere and not just
...@@ -828,7 +833,7 @@ sal_Int8 ModelData_Impl::CheckFilter( const OUString& aFilterName ) ...@@ -828,7 +833,7 @@ sal_Int8 ModelData_Impl::CheckFilter( const OUString& aFilterName )
return STATUS_SAVEAS; return STATUS_SAVEAS;
} }
} }
if ( !SfxStoringHelper::WarnUnacceptableFormat( GetModel(), aUIName, aDefUIName, true ) ) if ( !SfxStoringHelper::WarnUnacceptableFormat( GetModel(), aUIName, aDefUIName, aDefExtension, true ) )
return STATUS_SAVEAS_STANDARDNAME; return STATUS_SAVEAS_STANDARDNAME;
} }
} }
...@@ -1216,6 +1221,32 @@ bool ModelData_Impl::ShowDocumentInfoDialog() ...@@ -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 ModelData_Impl::GetRecommendedDir( const OUString& aSuggestedDir )
{ {
OUString aRecommendedDir; OUString aRecommendedDir;
...@@ -1283,16 +1314,9 @@ OUString ModelData_Impl::GetRecommendedName( const OUString& aSuggestedName, con ...@@ -1283,16 +1314,9 @@ OUString ModelData_Impl::GetRecommendedName( const OUString& aSuggestedName, con
INetURLObject aObj( "c:/" + aRecommendedName, INetProtocol::File, INetURLObject aObj( "c:/" + aRecommendedName, INetProtocol::File,
INetURLObject::ENCODE_ALL, RTL_TEXTENCODING_UTF8, INetURLObject::FSYS_DOS ); INetURLObject::ENCODE_ALL, RTL_TEXTENCODING_UTF8, INetURLObject::FSYS_DOS );
uno::Sequence< beans::PropertyValue > aTypeNameProps; OUString aExtension = GetRecommendedExtension( aTypeName );
if ( ( xTypeDetection->getByName( aTypeName ) >>= aTypeNameProps ) && aTypeNameProps.getLength() ) if ( !aExtension.isEmpty() )
{ aObj.SetExtension( aExtension );
::comphelper::SequenceAsHashMap aTypeNamePropsHM( aTypeNameProps );
uno::Sequence< OUString > aExtensions = aTypeNamePropsHM.getUnpackedValueOrDefault(
OUString("Extensions"),
::uno::Sequence< OUString >() );
if ( aExtensions.getLength() )
aObj.SetExtension( aExtensions[0] );
}
aRecommendedName = aObj.GetName( INetURLObject::DECODE_WITH_CHARSET, RTL_TEXTENCODING_UTF8 ); aRecommendedName = aObj.GetName( INetURLObject::DECODE_WITH_CHARSET, RTL_TEXTENCODING_UTF8 );
} }
...@@ -1850,13 +1874,14 @@ void SfxStoringHelper::SetDocInfoState( ...@@ -1850,13 +1874,14 @@ void SfxStoringHelper::SetDocInfoState(
bool SfxStoringHelper::WarnUnacceptableFormat( const uno::Reference< frame::XModel >& xModel, bool SfxStoringHelper::WarnUnacceptableFormat( const uno::Reference< frame::XModel >& xModel,
const OUString& aOldUIName, const OUString& aOldUIName,
const OUString& /*aDefUIName*/, const OUString& /*aDefUIName*/,
const OUString& aDefExtension,
bool /*bCanProceedFurther*/ ) bool /*bCanProceedFurther*/ )
{ {
if ( !SvtSaveOptions().IsWarnAlienFormat() ) if ( !SvtSaveOptions().IsWarnAlienFormat() )
return true; return true;
vcl::Window* pWin = SfxStoringHelper::GetModelWindow( xModel ); vcl::Window* pWin = SfxStoringHelper::GetModelWindow( xModel );
SfxAlienWarningDialog aDlg( pWin, aOldUIName ); SfxAlienWarningDialog aDlg( pWin, aOldUIName, aDefExtension );
return aDlg.Execute() == RET_OK; return aDlg.Execute() == RET_OK;
} }
......
...@@ -26,10 +26,11 @@ class SfxAlienWarningDialog : public MessageDialog ...@@ -26,10 +26,11 @@ class SfxAlienWarningDialog : public MessageDialog
{ {
private: private:
PushButton* m_pKeepCurrentBtn; PushButton* m_pKeepCurrentBtn;
PushButton* m_pUseDefaultFormatBtn;
CheckBox* m_pWarningOnBox; CheckBox* m_pWarningOnBox;
public: public:
SfxAlienWarningDialog(vcl::Window* pParent, const OUString& _rFormatName); SfxAlienWarningDialog(vcl::Window* pParent, const OUString& _rFormatName, const OUString& _rDefaultExtension);
virtual ~SfxAlienWarningDialog(); virtual ~SfxAlienWarningDialog();
}; };
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<property name="layout_style">end</property> <property name="layout_style">end</property>
<child> <child>
<object class="GtkButton" id="cancel"> <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="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
</child> </child>
<child> <child>
<object class="GtkCheckButton" id="ask"> <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="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">False</property> <property name="receives_default">False</property>
......
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