include/sfx2/docfile.hxx             |    2 --
 include/sfx2/filedlghelper.hxx       |    3 ++-
 sc/inc/filtuno.hxx                   |    1 -
 sc/source/ui/unoobj/filtuno.cxx      |   11 ++++++-----
 sfx2/source/appl/appopen.cxx         |   21 ++++++++++-----------
 sfx2/source/dialog/filedlghelper.cxx |   10 ++++++++--
 sfx2/source/doc/docfile.cxx          |   10 ----------
 sfx2/source/doc/objstor.cxx          |    7 -------
 uui/source/iahndl-filter.cxx         |    8 --------
 9 files changed, 26 insertions(+), 47 deletions(-)

New commits:
commit 85bfc66f54934510b5c2f07ed0a1b8fe0db31823
Author:     Shardul Vikram Singh <[email protected]>
AuthorDate: Thu Apr 3 02:54:30 2025 +0530
Commit:     Mike Kaganski <[email protected]>
CommitDate: Thu Apr 3 22:57:01 2025 +0200

    tdf#74580 Simplify passing "Edit Filter Settings" to Filter Dialog
    
    Simplify passing the checkbox state of "Edit Filter Settings" to
    the Filter Dialog via ContextLayer.
    
    Change-Id: I6dd581a530de9e8634d515295d2dab978b1c8f8b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183646
    Reviewed-by: Mike Kaganski <[email protected]>
    Tested-by: Jenkins

diff --git a/include/sfx2/docfile.hxx b/include/sfx2/docfile.hxx
index 0db2d3264283..6ab8d2ce5571 100644
--- a/include/sfx2/docfile.hxx
+++ b/include/sfx2/docfile.hxx
@@ -204,8 +204,6 @@ public:
 
     [[nodiscard]] bool IsRepairPackage() const;
 
-    [[nodiscard]] bool ShowFilterDialog() const;
-
     css::uno::Reference< css::io::XInputStream > const &  GetInputStream();
 
     void                CreateTempFile( bool bReplace = true );
diff --git a/include/sfx2/filedlghelper.hxx b/include/sfx2/filedlghelper.hxx
index bc8055e4d45f..13749fa1b603 100644
--- a/include/sfx2/filedlghelper.hxx
+++ b/include/sfx2/filedlghelper.hxx
@@ -186,6 +186,7 @@ public:
     sal_Int16               GetDialogType() const;
     bool                    IsPasswordEnabled() const;
     OUString                GetRealFilter() const;
+    bool                    CheckCurrentFilterOptionsCapability() const;
 
     void                    SetTitle( const OUString&  rNewTitle );
     OUString                GetPath() const;
@@ -300,7 +301,7 @@ ErrCode FileOpenDialog_Impl( weld::Window* pParent,
                              sal_Int16 nDialog,
                              const OUString& rStandardDir,
                              const css::uno::Sequence< OUString >& rDenyList,
-                             bool& rShowFilterDialog );
+                             std::optional<bool>& rShowFilterDialog );
 
 css::uno::Reference<css::ui::dialogs::XFolderPicker2> SFX2_DLLPUBLIC 
createFolderPicker(const css::uno::Reference<css::uno::XComponentContext>& 
rContext, weld::Window* pPreferredParent);
 
diff --git a/sc/inc/filtuno.hxx b/sc/inc/filtuno.hxx
index 272a94fd6344..100fdeb001d4 100644
--- a/sc/inc/filtuno.hxx
+++ b/sc/inc/filtuno.hxx
@@ -45,7 +45,6 @@ private:
     css::uno::Reference< css::io::XInputStream > xInputStream;
     css::uno::Reference< css::awt::XWindow > xDialogParent;
     bool         bExport;
-    bool mbForceShow = false;
 
 public:
                             ScFilterOptionsObj();
diff --git a/sc/source/ui/unoobj/filtuno.cxx b/sc/source/ui/unoobj/filtuno.cxx
index c0048fcc6132..0bb3db3453f8 100644
--- a/sc/source/ui/unoobj/filtuno.cxx
+++ b/sc/source/ui/unoobj/filtuno.cxx
@@ -20,6 +20,7 @@
 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
 #include <tools/urlobj.hxx>
 #include <vcl/svapp.hxx>
+#include <uno/current_context.hxx>
 #include <unotools/filteroptions_settings.hxx>
 #include <unotools/ucbstreamhelper.hxx>
 #include <connectivity/dbtools.hxx>
@@ -190,15 +191,17 @@ sal_Int16 SAL_CALL ScFilterOptionsObj::execute()
         ScopedVclPtr<AbstractScImportAsciiDlg> 
pDlg(pFact->CreateScImportAsciiDlg(Application::GetFrameWeld(xDialogParent), 
aPrivDatName,
                                                                                
   pInStream.get(), SC_IMPORTFILE));
 
-        const bool bShow = mbForceShow || 
utl::isShowFilterOptionsDialog(aFilterString);
+        bool bShow;
+        // The "ShowFilterDialog" flag is passed from 
SfxApplication::OpenDocExec_Impl
+        if 
(!(css::uno::getCurrentContext()->getValueByName(u"ShowFilterDialog"_ustr) >>= 
bShow))
+            bShow = utl::isShowFilterOptionsDialog(aFilterString);
         const bool bOk = !bShow || pDlg->Execute() == RET_OK;
 
         if (bOk)
         {
             ScAsciiOptions aOptions;
             pDlg->GetOptions( aOptions );
-            if (bShow)
-                pDlg->SaveParameters();
+            pDlg->SaveParameters();
             aFilterOptions = aOptions.WriteToString();
             nRet = ui::dialogs::ExecutableDialogResults::OK;
         }
@@ -372,8 +375,6 @@ void SAL_CALL ScFilterOptionsObj::initialize(const 
uno::Sequence<uno::Any>& rArg
     ::comphelper::NamedValueCollection aProperties(rArguments);
     if (aProperties.has(u"ParentWindow"_ustr))
         aProperties.get(u"ParentWindow"_ustr) >>= xDialogParent;
-    if (aProperties.has(u"ShowFilterDialog"_ustr))
-        aProperties.get(u"ShowFilterDialog"_ustr) >>= mbForceShow;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/appl/appopen.cxx b/sfx2/source/appl/appopen.cxx
index 1bbf2ad7aa9c..1f91c3ea5be6 100644
--- a/sfx2/source/appl/appopen.cxx
+++ b/sfx2/source/appl/appopen.cxx
@@ -44,7 +44,6 @@
 #include <rtl/ustring.hxx>
 
 #include <comphelper/processfactory.hxx>
-#include <comphelper/propertyvalue.hxx>
 #include <comphelper/sequence.hxx>
 #include <comphelper/SetFlagContextHelper.hxx>
 #include <comphelper/storagehelper.hxx>
@@ -657,7 +656,7 @@ void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq )
         if ( pDenyListItem )
             pDenyListItem->GetStringList( aDenyList );
 
-        bool bShowFilterDialog = true;
+        std::optional<bool> bShowFilterDialog;
         weld::Window* pTopWindow = GetTopWindow();
         ErrCode nErr = sfx2::FileOpenDialog_Impl(pTopWindow,
                 nDialogType,
@@ -712,10 +711,16 @@ void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq )
                 rReq.AppendItem(SfxStringItem(SID_DOC_SERVICE, aDocService));
             }
 
-            // The actual use of bShowFilterDialog will be in the recursive 
call to OpenDocExec_Impl
+            // Passes the checkbox state of "Edit Filter Settings" to filter 
dialogs through multiple layers of code.
+            // Since some layers use a published API and cannot be modified 
directly, we use a context layer instead.
+            // This is a one-time flag and is not stored in any configuration.
+            // For an example of how it's used, see 
ScFilterOptionsObj::execute.
             std::optional<css::uno::ContextLayer> oLayer;
-            if (bShowFilterDialog)
-                
oLayer.emplace(comphelper::NewFlagContext(u"ShowFilterDialog"_ustr));
+            if (bShowFilterDialog.has_value())
+            {
+                
oLayer.emplace(comphelper::NewFlagContext(u"ShowFilterDialog"_ustr,
+                                                          
bShowFilterDialog.value()));
+            }
 
             for (auto const& url : aURLList)
             {
@@ -1083,12 +1088,6 @@ void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq )
         auto nIndex = static_cast<sal_Int32>(std::distance(std::cbegin(aArgs), 
pArg));
         comphelper::removeElementAt(aArgs, nIndex);
     }
-    if (comphelper::IsContextFlagActive(u"ShowFilterDialog"_ustr))
-    {
-        const auto i = aArgs.getLength();
-        aArgs.realloc(i + 1);
-        aArgs.getArray()[i] = 
comphelper::makePropertyValue(u"ShowFilterDialog"_ustr, true);
-    }
 
     // TODO/LATER: either remove LinkItem or create an asynchronous process 
for it
     if( bHidden || pLinkItem || rReq.IsSynchronCall() )
diff --git a/sfx2/source/dialog/filedlghelper.cxx 
b/sfx2/source/dialog/filedlghelper.cxx
index 8d28908ae94a..04c4cbe50459 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -2699,6 +2699,11 @@ OUString FileDialogHelper::GetRealFilter() const
     return sFilter;
 }
 
+bool FileDialogHelper::CheckCurrentFilterOptionsCapability() const
+{
+    return mpImpl->CheckFilterOptionsCapability(mpImpl->getCurrentSfxFilter());
+}
+
 void FileDialogHelper::SetTitle( const OUString& rNewTitle )
 {
     if ( mpImpl->mxFileDlg.is() )
@@ -2919,7 +2924,7 @@ ErrCode FileOpenDialog_Impl( weld::Window* pParent,
                              sal_Int16 nDialog,
                              const OUString& rStandardDir,
                              const css::uno::Sequence< OUString >& rDenyList,
-                             bool& rShowFilterDialog )
+                             std::optional<bool>& rShowFilterDialog )
 {
     ErrCode nRet;
     std::unique_ptr<FileDialogHelper> pDialog;
@@ -2943,7 +2948,8 @@ ErrCode FileOpenDialog_Impl( weld::Window* pParent,
 
     uno::Reference< ui::dialogs::XFilePickerControlAccess > xExtFileDlg( 
pDialog->GetFilePicker(), uno::UNO_QUERY );
     uno::Any aVal = xExtFileDlg->getValue( 
ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS, 0 );
-    aVal >>= rShowFilterDialog;
+    if (aVal.has<bool>() && pDialog->CheckCurrentFilterOptionsCapability())
+        rShowFilterDialog = aVal.get<bool>();
 
     return nRet;
 }
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index ba0c49377e2e..760d21bf48da 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -412,8 +412,6 @@ public:
     /// if true, xStorage is an inner package and not directly from xStream
     bool m_bODFWholesomeEncryption = false;
 
-    bool m_bShowFilterDialog = false;
-
     OUString m_aName;
     OUString m_aLogicName;
     OUString m_aLongName;
@@ -3687,17 +3685,9 @@ void SfxMedium::SetArgs(const 
uno::Sequence<beans::PropertyValue>& rArgs)
     aArgsMap.erase(u"Stream"_ustr);
     aArgsMap.erase(u"InputStream"_ustr);
 
-    if (auto it = aArgsMap.find(u"ShowFilterDialog"_ustr); it != 
aArgsMap.end())
-    {
-        it->second >>= pImpl->m_bShowFilterDialog;
-        aArgsMap.erase(it);
-    }
-
     pImpl->m_aArgs = aArgsMap.getAsConstPropertyValueList();
 }
 
-bool SfxMedium::ShowFilterDialog() const { return pImpl->m_bShowFilterDialog; }
-
 const uno::Sequence<beans::PropertyValue> & SfxMedium::GetArgs() const { 
return pImpl->m_aArgs; }
 
 SfxMedium::SfxMedium( const uno::Reference < embed::XStorage >& rStor, const 
OUString& rBaseURL, const std::shared_ptr<SfxItemSet>& p ) :
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index d3836221e89f..0a52c32eab6b 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -64,7 +64,6 @@
 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
 #include <comphelper/fileformat.h>
 #include <comphelper/processfactory.hxx>
-#include <comphelper/propertyvalue.hxx>
 #include <svtools/langtab.hxx>
 #include <svtools/sfxecode.hxx>
 #include <unotools/configmgr.hxx>
@@ -1238,12 +1237,6 @@ ErrCode SfxObjectShell::HandleFilter( SfxMedium* 
pMedium, SfxObjectShell const *
 
                                 Sequence< PropertyValue > rProperties;
                                 TransformItems( SID_OPENDOC, rSet, rProperties 
);
-                                if (pMedium->ShowFilterDialog())
-                                {
-                                    const auto i = rProperties.getLength();
-                                    rProperties.realloc(i + 1);
-                                    rProperties.getArray()[i] = 
comphelper::makePropertyValue(u"ShowFilterDialog"_ustr, true);
-                                }
                                 rtl::Reference<RequestFilterOptions> 
pFORequest = new RequestFilterOptions( pDoc->GetModel(), rProperties );
 
                                 rHandler->handle( pFORequest );
diff --git a/uui/source/iahndl-filter.cxx b/uui/source/iahndl-filter.cxx
index 3fb3aa26783f..95b3450b9881 100644
--- a/uui/source/iahndl-filter.cxx
+++ b/uui/source/iahndl-filter.cxx
@@ -210,13 +210,6 @@ handleFilterOptionsRequest_(
             {
                 pProperty->Value >>= aFilterName;
             }
-            bool bShowFilterDialog = false;
-            pProperty = std::find_if(rRequest.rProperties.begin(), 
rRequest.rProperties.end(),
-                [](const beans::PropertyValue& rProp) { return rProp.Name == 
"ShowFilterDialog"; });
-            if (pProperty != rRequest.rProperties.end())
-            {
-                pProperty->Value >>= bShowFilterDialog;
-            }
 
             uno::Sequence < beans::PropertyValue > aProps;
             if ( xFilterCFG->getByName( aFilterName ) >>= aProps )
@@ -232,7 +225,6 @@ handleFilterOptionsRequest_(
                         uno::Sequence<uno::Any> 
aDialogArgs(comphelper::InitAnyPropertySequence(
                         {
                             {"ParentWindow", uno::Any(rWindow)},
-                            {"ShowFilterDialog", uno::Any(bShowFilterDialog)},
                         }));
 
                         uno::Reference<

Reply via email to