framework/inc/strings.hrc                                  |    4 +
 framework/source/uielement/recentfilesmenucontroller.cxx   |   33 +++++++++-
 include/sfx2/strings.hrc                                   |    3 
 officecfg/registry/schema/org/openoffice/Office/Common.xcs |   12 +++
 sfx2/source/control/recentdocsview.cxx                     |   40 ++++++++++---
 5 files changed, 82 insertions(+), 10 deletions(-)

New commits:
commit 494538cfffbdd12ee13787e7991dca941879db0e
Author:     Sampath-1984 <[email protected]>
AuthorDate: Sun Nov 16 12:01:35 2025 +0530
Commit:     Heiko Tietze <[email protected]>
CommitDate: Wed Dec 3 14:05:43 2025 +0100

    tdf#166386 Confirmation Dialogs for clearing recent or unavailable documents
    
    Clearing recent or unavailable documents from the start center or the main 
menu will now ask for confirmation from the user before executing.
    
    Change-Id: Ic36924e6f16772eb6ee3bffc7116bdd405653c80
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194065
    Tested-by: Jenkins
    Reviewed-by: Heiko Tietze <[email protected]>

diff --git a/framework/inc/strings.hrc b/framework/inc/strings.hrc
index 7a4ccf6730ac..3fcfa7286002 100644
--- a/framework/inc/strings.hrc
+++ b/framework/inc/strings.hrc
@@ -79,4 +79,8 @@
 #define RID_STR_PROPTITLE_SPINBUTTON                
NC_("RID_STR_PROPTITLE_SPINBUTTON", "Spin Button")
 #define RID_STR_PROPTITLE_NAVBAR                    
NC_("RID_STR_PROPTITLE_NAVBAR", "Navigation Bar")
 
+#define STR_QUERY_CLR_RECENTS_DOCS_TITLE            
NC_("STR_QUERY_CLR_RECENTS_DOCS_TITLE", "Clear Recent Documents")
+#define STR_QUERY_CLR_RECENTS_DOCS_TEXT             
NC_("STR_QUERY_CLR_RECENTS_DOCS_TEXT", "This is an irreversible operation.")
+#define STR_QUERY_CLR_RECENTS_DOCS_QUESTION         
NC_("STR_QUERY_CLR_RECENTS_DOCS_QUESTION", "Do you want to clear all recent 
Documents?")
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/framework/source/uielement/recentfilesmenucontroller.cxx 
b/framework/source/uielement/recentfilesmenucontroller.cxx
index dac6d0b1be43..50e94cbb0156 100644
--- a/framework/source/uielement/recentfilesmenucontroller.cxx
+++ b/framework/source/uielement/recentfilesmenucontroller.cxx
@@ -30,6 +30,7 @@
 #include <tools/urlobj.hxx>
 #include <toolkit/awt/vclxmenu.hxx>
 #include <unotools/historyoptions.hxx>
+#include <vcl/abstdlg.hxx>
 #include <vcl/commandinfoprovider.hxx>
 #include <vcl/graph.hxx>
 #include <vcl/settings.hxx>
@@ -400,14 +401,40 @@ void SAL_CALL RecentFilesMenuController::itemSelected( 
const css::awt::MenuEvent
         return;
 
     const OUString aCommand( xPopupMenu->getCommand( rEvent.MenuId ) );
-
     if ( aCommand == CMD_CLEAR_LIST )
     {
-        SvtHistoryOptions::Clear( EHistoryType::PickList, false );
-        dispatchCommand(
+        const bool bDoAsk = 
officecfg::Office::Common::Misc::QueryClearRecentDocuments::get();
+        short nresult = RET_YES;
+        if (bDoAsk)
+        {
+            VclAbstractDialogFactory* pFact = 
VclAbstractDialogFactory::Create();
+            auto pDlg = pFact->CreateQueryDialog(
+                Application::GetDefDialogParent(),
+                FwkResId(STR_QUERY_CLR_RECENTS_DOCS_TITLE),
+                FwkResId(STR_QUERY_CLR_RECENTS_DOCS_TEXT),
+                FwkResId(STR_QUERY_CLR_RECENTS_DOCS_QUESTION),
+                true);
+            nresult = pDlg->Execute();
+
+            if (pDlg->ShowAgain() == false)
+            {
+                std::shared_ptr<comphelper::ConfigurationChanges> xChanges(
+                    comphelper::ConfigurationChanges::create());
+                
officecfg::Office::Common::Misc::QueryClearRecentDocuments::set(false, 
xChanges);
+                xChanges->commit();
+            }
+            pDlg->disposeOnce();
+        }
+
+        if ( ! bDoAsk || nresult == RET_YES )
+        {
+            SvtHistoryOptions::Clear( EHistoryType::PickList, false );
+            dispatchCommand(
             u"vnd.org.libreoffice.recentdocs:ClearRecentFileList"_ustr,
             css::uno::Sequence< css::beans::PropertyValue >() );
+        }
     }
+
     if ( aCommand == CMD_TOGGLE_CURRENTMODULE )
     {
         bool bIsExclusive = 
officecfg::Office::Common::History::ShowCurrentModuleOnly::get();
diff --git a/include/sfx2/strings.hrc b/include/sfx2/strings.hrc
index d6ef55d4b10b..e39c7fb8efec 100644
--- a/include/sfx2/strings.hrc
+++ b/include/sfx2/strings.hrc
@@ -380,6 +380,9 @@
 #define STR_WINDOW_TITLE_RENAME_NEW_CATEGORY    
NC_("STR_WINDOW_TITLE_RENAME_NEW_CATEGORY","New Category")
 
 #define STR_OBJECT_INSPECTOR                    NC_("STR_OBJECT_INSPECTOR", 
"UNO Object Inspector")
+#define STR_QUERY_CLR_UNAVAILABLE_DOCS_TITLE    
NC_("STR_QUERY_CLR_UNAVAILABLE_DOCS_TITLE", "Clear Unavailable Documents")
+#define STR_QUERY_CLR_UNAVAILABLE_DOCS_TEXT     
NC_("STR_QUERY_CLR_UNAVAILABLE_DOCS_TEXT", "This action is irreversible.")
+#define STR_QUERY_CLR_UNAVAILABLE_DOCS_QUESTION 
NC_("STR_QUERY_CLR_UNAVAILABLE_DOCS_QUESTION", "Do you want to clear all 
unavailable Documents?")
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs 
b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
index 773d38f930d9..766de1514ddb 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
@@ -5457,6 +5457,18 @@
         </info>
         <value>true</value>
       </prop>
+      <prop oor:name="QueryClearRecentDocuments" oor:type="xs:boolean" 
oor:nillable="false">
+        <info>
+          <desc>Determines whether to show the confirmation dialog when 
clearing recent documents.</desc>
+        </info>
+        <value>true</value>
+      </prop>
+      <prop oor:name="QueryClearUnavailableDocuments" oor:type="xs:boolean" 
oor:nillable="false">
+        <info>
+          <desc>Determines whether to show the confirmation dialog when 
clearing unavailable documents.</desc>
+        </info>
+        <value>true</value>
+      </prop>
       <prop oor:name="QueryDeleteAllComments" oor:type="xs:boolean" 
oor:nillable="false">
         <info>
           <desc>Determines whether to confirm delete all comments or all by 
user.</desc>
diff --git a/sfx2/source/control/recentdocsview.cxx 
b/sfx2/source/control/recentdocsview.cxx
index 8b9a4b1e5572..67117f62c320 100644
--- a/sfx2/source/control/recentdocsview.cxx
+++ b/sfx2/source/control/recentdocsview.cxx
@@ -22,6 +22,7 @@
 #include <recentdocsview.hxx>
 #include <sfx2/sfxresid.hxx>
 #include <unotools/historyoptions.hxx>
+#include <vcl/abstdlg.hxx>
 #include <vcl/event.hxx>
 #include <vcl/ptrstyle.hxx>
 #include <vcl/svapp.hxx>
@@ -187,16 +188,41 @@ void RecentDocsView::setFilter(ApplicationType aFilter)
     Reload();
 }
 
-void RecentDocsView::clearUnavailableFiles(){
-    std::vector< SvtHistoryOptions::HistoryItem > aHistoryList = 
SvtHistoryOptions::GetList( EHistoryType::PickList );
-    for ( size_t i = 0; i < aHistoryList.size(); i++ )
+void RecentDocsView::clearUnavailableFiles()
+{
+    const bool bDoAsk = 
officecfg::Office::Common::Misc::QueryClearUnavailableDocuments::get();
+    short nresult = RET_YES;
+    if (bDoAsk)
     {
-        const SvtHistoryOptions::HistoryItem& rPickListEntry = aHistoryList[i];
-        if ( !comphelper::DirectoryHelper::fileExists(rPickListEntry.sURL) ){
-            
SvtHistoryOptions::DeleteItem(EHistoryType::PickList,rPickListEntry.sURL, 
false);
+        VclAbstractDialogFactory* pFact = VclAbstractDialogFactory::Create();
+        auto pDlg = pFact->CreateQueryDialog(
+            Application::GetDefDialogParent(),
+            SfxResId(STR_QUERY_CLR_UNAVAILABLE_DOCS_TITLE),
+            SfxResId(STR_QUERY_CLR_UNAVAILABLE_DOCS_TEXT),
+            SfxResId(STR_QUERY_CLR_UNAVAILABLE_DOCS_QUESTION),
+            true);
+        nresult = pDlg->Execute();
+        if (pDlg->ShowAgain() == false)
+        {
+            std::shared_ptr<comphelper::ConfigurationChanges> xChanges(
+                comphelper::ConfigurationChanges::create());
+            
officecfg::Office::Common::Misc::QueryClearUnavailableDocuments::set(false, 
xChanges);
+            xChanges->commit();
         }
+        pDlg->disposeOnce();
+    }
+    if ( ! bDoAsk || nresult == RET_YES )
+    {
+        std::vector< SvtHistoryOptions::HistoryItem > aHistoryList = 
SvtHistoryOptions::GetList( EHistoryType::PickList );
+        for ( size_t i = 0; i < aHistoryList.size(); i++ )
+        {
+            const SvtHistoryOptions::HistoryItem& rPickListEntry = 
aHistoryList[i];
+            if ( !comphelper::DirectoryHelper::fileExists(rPickListEntry.sURL) 
){
+                
SvtHistoryOptions::DeleteItem(EHistoryType::PickList,rPickListEntry.sURL, 
false);
+            }
+        }
+        Reload();
     }
-    Reload();
 }
 
 bool RecentDocsView::MouseButtonDown( const MouseEvent& rMEvt )

Reply via email to