sfx2/inc/guisaveas.hxx              |    1 +
 sfx2/source/dialog/alienwarn.cxx    |   11 ++++++++++-
 sfx2/source/doc/guisaveas.cxx       |    9 ++++++---
 sfx2/source/inc/alienwarn.hxx       |    3 ++-
 sfx2/uiconfig/ui/alienwarndialog.ui |    4 ++--
 5 files changed, 21 insertions(+), 7 deletions(-)

New commits:
commit cc42d34ce938352135fb405a47d5bc7e5d929e1b
Author:     bruh <randomfores...@gmail.com>
AuthorDate: Thu Jan 23 00:58:41 2025 +0530
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Fri Jan 24 12:58:19 2025 +0100

    tdf#158624 -  Improve warning dialogue for non-recommended formats during 
save
    
    Implemented changes to display the recommended file extension in the
    warning dialogue when a non-recommended extension is selected during
    document save. This improves user guidance and ensures better file
    format compatibility.
    
    Change-Id: I08208a8968f37a4dfeb34623402004b41a0a2c34
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180605
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins

diff --git a/sfx2/inc/guisaveas.hxx b/sfx2/inc/guisaveas.hxx
index a1f85bbc2248..d6a037f4ed26 100644
--- a/sfx2/inc/guisaveas.hxx
+++ b/sfx2/inc/guisaveas.hxx
@@ -101,6 +101,7 @@ public:
     static bool WarnUnacceptableFormat(
                                     const css::uno::Reference< 
css::frame::XModel >& xModel,
                                     std::u16string_view aOldUIName,
+                                    std::u16string_view aExtension,
                                     const OUString& aDefExtension,
                                     bool rDefaultIsAlien );
 
diff --git a/sfx2/source/dialog/alienwarn.cxx b/sfx2/source/dialog/alienwarn.cxx
index 9d96dfa77268..3e9be6970de8 100644
--- a/sfx2/source/dialog/alienwarn.cxx
+++ b/sfx2/source/dialog/alienwarn.cxx
@@ -22,6 +22,7 @@
 
 SfxAlienWarningDialog::SfxAlienWarningDialog(weld::Window* pParent,
                                              std::u16string_view _rFormatName,
+                                             std::u16string_view _rExtension,
                                              const OUString& 
_rDefaultExtension,
                                              bool rDefaultIsAlien)
     : MessageDialogController(pParent, u"sfx/ui/alienwarndialog.ui"_ustr, 
u"AlienWarnDialog"_ustr,
@@ -32,9 +33,10 @@ SfxAlienWarningDialog::SfxAlienWarningDialog(weld::Window* 
pParent,
 {
     OUString aExtension = u"ODF"_ustr;
 
-    // replace formatname (text)
+    // replace formatname and extension (text)
     OUString sInfoText = m_xDialog->get_primary_text();
     sInfoText = sInfoText.replaceAll("%FORMATNAME", _rFormatName);
+    sInfoText = sInfoText.replaceAll("%EXTENSION", _rExtension);
     m_xDialog->set_primary_text(sInfoText);
 
     // replace formatname (button)
@@ -49,6 +51,13 @@ SfxAlienWarningDialog::SfxAlienWarningDialog(weld::Window* 
pParent,
         m_xDialog->set_secondary_text(OUString());
         aExtension = _rDefaultExtension.toAsciiUpperCase();
     }
+    else
+    {
+        // replace extension (secondary-text)
+        sInfoText = m_xDialog->get_secondary_text();
+        sInfoText = sInfoText.replaceAll("%EXTENSION", _rDefaultExtension);
+        m_xDialog->set_secondary_text(sInfoText);
+    }
 
     // replace defaultextension (button)
     sInfoText = m_xUseDefaultFormatBtn->get_label();
diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx
index adfc6c8345fa..7e6be3b5ebab 100644
--- a/sfx2/source/doc/guisaveas.cxx
+++ b/sfx2/source/doc/guisaveas.cxx
@@ -845,14 +845,16 @@ sal_Int8 ModelData_Impl::CheckFilter( const OUString& 
aFilterName )
         // the default filter is acceptable and the old filter is alien one
         // so ask to make a saveAs operation
         const OUString aUIName = 
aFiltPropsHM.getUnpackedValueOrDefault(u"UIName"_ustr, OUString() );
-        const OUString aDefUIName = 
aDefFiltPropsHM.getUnpackedValueOrDefault(u"UIName"_ustr, OUString() );
+        const OUString aType = aFiltPropsHM.getUnpackedValueOrDefault( 
u"Type"_ustr, OUString() );
+        const OUString aExtension = GetRecommendedExtension(aType);
         const OUString aPreusedFilterName = 
GetDocProps().getUnpackedValueOrDefault(u"PreusedFilterName"_ustr, OUString() );
+        const OUString aDefUIName = 
aDefFiltPropsHM.getUnpackedValueOrDefault(u"UIName"_ustr, OUString() );
         const OUString aDefType = aDefFiltPropsHM.getUnpackedValueOrDefault( 
u"Type"_ustr, OUString() );
         const OUString aDefExtension = GetRecommendedExtension( aDefType );
 
         if ( aPreusedFilterName != aFilterName && aUIName != aDefUIName )
         {
-            if ( !SfxStoringHelper::WarnUnacceptableFormat( GetModel(), 
aUIName, aDefExtension,
+            if ( !SfxStoringHelper::WarnUnacceptableFormat( GetModel(), 
aUIName,aExtension, aDefExtension,
                                                             static_cast<bool>( 
nDefFiltFlags & SfxFilterFlags::ALIEN ) ) )
                 return STATUS_SAVEAS_STANDARDNAME;
         }
@@ -2090,6 +2092,7 @@ void SfxStoringHelper::SetDocInfoState(
 // static
 bool SfxStoringHelper::WarnUnacceptableFormat( const uno::Reference< 
frame::XModel >& xModel,
                                                     std::u16string_view 
aOldUIName,
+                                                    std::u16string_view 
aExtension,
                                                     const OUString& 
aDefExtension,
                                                     bool bDefIsAlien )
 {
@@ -2097,7 +2100,7 @@ bool SfxStoringHelper::WarnUnacceptableFormat( const 
uno::Reference< frame::XMod
         return true;
 
     weld::Window* pWin = SfxStoringHelper::GetModelWindow(xModel);
-    SfxAlienWarningDialog aDlg(pWin, aOldUIName, aDefExtension, bDefIsAlien);
+    SfxAlienWarningDialog aDlg(pWin, aOldUIName,aExtension, aDefExtension, 
bDefIsAlien);
 
     return aDlg.run() == RET_OK;
 }
diff --git a/sfx2/source/inc/alienwarn.hxx b/sfx2/source/inc/alienwarn.hxx
index 7c4f8cb364ee..29fab4f53892 100644
--- a/sfx2/source/inc/alienwarn.hxx
+++ b/sfx2/source/inc/alienwarn.hxx
@@ -30,7 +30,8 @@ private:
 
 public:
     SfxAlienWarningDialog(weld::Window* pParent, std::u16string_view 
_rFormatName,
-                          const OUString& _rDefaultExtension, bool 
rDefaultIsAlien);
+                          std::u16string_view _rExtension, const OUString& 
_rDefaultExtension,
+                          bool rDefaultIsAlien);
     virtual ~SfxAlienWarningDialog() override;
 };
 
diff --git a/sfx2/uiconfig/ui/alienwarndialog.ui 
b/sfx2/uiconfig/ui/alienwarndialog.ui
index 02570dfd1ed4..c0c913977b00 100644
--- a/sfx2/uiconfig/ui/alienwarndialog.ui
+++ b/sfx2/uiconfig/ui/alienwarndialog.ui
@@ -10,8 +10,8 @@
     <property name="type-hint">dialog</property>
     <property name="skip-taskbar-hint">True</property>
     <property name="message-type">question</property>
-    <property name="text" translatable="yes" 
context="alienwarndialog|AlienWarnDialog">This document may contain formatting 
or content that cannot be saved in the currently selected file format 
“%FORMATNAME”.</property>
-    <property name="secondary-text" translatable="yes" 
context="alienwarndialog|AlienWarnDialog">Use the default ODF file format to be 
sure that the document is saved correctly.</property>
+    <property name="text" translatable="yes" 
context="alienwarndialog|AlienWarnDialog">This document may contain formatting 
or content that cannot be saved in the currently selected file format 
“%FORMATNAME (*.%EXTENSION)”.</property>
+    <property name="secondary-text" translatable="yes" 
context="alienwarndialog|AlienWarnDialog">Use the default ODF file format 
(*.%EXTENSION) to be sure that the document is saved correctly.</property>
     <child internal-child="vbox">
       <object class="GtkBox" id="messagedialog-vbox">
         <property name="can-focus">False</property>

Reply via email to