Remove files from recent-files list on failed open
authorCampbell Barton <ideasman42@gmail.com>
Wed, 5 Aug 2015 11:25:28 +0000 (21:25 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 5 Aug 2015 11:26:10 +0000 (21:26 +1000)
source/blender/windowmanager/intern/wm_files.c

index 74be3bc6f5da309aa852c1a4cd8a78afacf429ee..24c25fd0eb768f3c2d00b36106fd9101b3d12270 100644 (file)
@@ -398,6 +398,8 @@ void WM_file_autoexec_init(const char *filepath)
 
 bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
 {
+       /* assume automated tasks with background, don't write recent file list */
+       const bool do_history = (G.background == false) && (CTX_wm_manager(C)->op_undo_depth == 0);
        bool success = false;
        int retval;
 
@@ -420,9 +422,6 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
                int G_f = G.f;
                ListBase wmbase;
 
-               /* assume automated tasks with background, don't write recent file list */
-               const bool do_history = (G.background == false) && (CTX_wm_manager(C)->op_undo_depth == 0);
-
                /* put aside screens to match with persistent windows later */
                /* also exit screens and editors */
                wm_window_match_init(C, &wmbase); 
@@ -528,6 +527,19 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
                BLI_assert(!"invalid 'retval'");
        }
 
+
+       if (success == false) {
+               /* remove from recent files list */
+               if (do_history) {
+                       RecentFile *recent = BLI_findstring_ptr(&G.recent_files, filepath, offsetof(RecentFile, filepath));
+                       if (recent) {
+                               MEM_freeN(recent->filepath);
+                               BLI_freelinkN(&G.recent_files, recent);
+                               write_history();
+                       }
+               }
+       }
+
        WM_cursor_wait(0);
 
        return success;