sfx2/inc/recentdocsview.hxx            |    2 ++
 sfx2/source/control/recentdocsview.cxx |   13 +++++++++++++
 sfx2/source/dialog/backingwindow.cxx   |    3 +++
 sfx2/uiconfig/ui/startcenter.ui        |    7 +++++++
 4 files changed, 25 insertions(+)

New commits:
commit 2839b604af94dbd1ee59dc6d47dc2f4c6ebd8dc6
Author:     oguzbalkaya <[email protected]>
AuthorDate: Tue Aug 30 23:29:53 2022 +0200
Commit:     Hossein <[email protected]>
CommitDate: Wed Aug 31 13:23:53 2022 +0200

    tdf#101302: Add option to clear unavailable files in menu/start center
    
    This patch adresses tdf#101302. It essentially adds a menu item to clear
    unavailable files from the menu and start center. Previously, they were
    visible as recent documents in the menu and start center, and caused
    error when selected.
    
    Change-Id: I55ee9f663b24c343a90817c438aff11d9230061c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120480
    Tested-by: Jenkins
    Reviewed-by: Hossein <[email protected]>

diff --git a/sfx2/inc/recentdocsview.hxx b/sfx2/inc/recentdocsview.hxx
index 3ee34eabc41a..44165afbe38a 100644
--- a/sfx2/inc/recentdocsview.hxx
+++ b/sfx2/inc/recentdocsview.hxx
@@ -80,6 +80,8 @@ public:
     // received on load of recently used file
     void DispatchedLoadRecentUsedFile();
 
+    void clearUnavailableFiles();
+
 private:
     virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override;
 
diff --git a/sfx2/source/control/recentdocsview.cxx 
b/sfx2/source/control/recentdocsview.cxx
index 9eea0e1c2488..61b9b55a64a6 100644
--- a/sfx2/source/control/recentdocsview.cxx
+++ b/sfx2/source/control/recentdocsview.cxx
@@ -18,6 +18,7 @@
  */
 
 #include <sal/log.hxx>
+#include <comphelper/DirectoryHelper.hxx>
 #include <recentdocsview.hxx>
 #include <sfx2/sfxresid.hxx>
 #include <unotools/historyoptions.hxx>
@@ -173,6 +174,18 @@ void RecentDocsView::Reload()
     Invalidate();
 }
 
+void RecentDocsView::clearUnavailableFiles(){
+    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);
+        }
+    }
+    Reload();
+}
+
 bool RecentDocsView::MouseButtonDown( const MouseEvent& rMEvt )
 {
     if (rMEvt.IsLeft())
diff --git a/sfx2/source/dialog/backingwindow.cxx 
b/sfx2/source/dialog/backingwindow.cxx
index 163c5c298e4f..6b68370b0bae 100644
--- a/sfx2/source/dialog/backingwindow.cxx
+++ b/sfx2/source/dialog/backingwindow.cxx
@@ -603,6 +603,9 @@ IMPL_LINK (BackingWindow, MenuSelectHdl, const OString&, 
rId, void)
         mxAllRecentThumbnails->Reload();
         return;
     }
+    else if(rId == "clear_unavailable"){
+        mxAllRecentThumbnails->clearUnavailableFiles();
+    }
     else if (!rId.isEmpty())
     {
         initializeLocalView();
diff --git a/sfx2/uiconfig/ui/startcenter.ui b/sfx2/uiconfig/ui/startcenter.ui
index e65eba9e9aba..89b4653dffa7 100644
--- a/sfx2/uiconfig/ui/startcenter.ui
+++ b/sfx2/uiconfig/ui/startcenter.ui
@@ -17,6 +17,13 @@
         <property name="label" translatable="yes" 
context="startcenter|clear_all">Clear Recent Documents</property>
       </object>
     </child>
+    <child>
+      <object class="GtkMenuItem" id="clear_unavailable">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <property name="label" translatable="yes" 
context="startcenter|clear_unavailable">Clear Unavailable Files</property>
+      </object>
+    </child>
   </object>
   <object class="GtkImage" id="database_all_image">
     <property name="visible">True</property>

Reply via email to