From f04a7a07e35bb23332629fa264fdbe6c59785ea9 Mon Sep 17 00:00:00 2001 From: Ankit Meel Date: Thu, 20 Apr 2023 23:53:08 +0530 Subject: [PATCH] macOS: Add open files to system recent files Completes the TODO in GHOST_SystemPathsCocoa::addToSystemRecentFiles Also renames the filename parameter to the more appropriate filepath. The recently opened/saved file will now also show up in: - Blender Dock icon > Right click. - Three finger swipe down in Open Blender i.e., App Expose Based on a earlier contribution by @jenkm. Pull Request: https://projects.blender.org/blender/blender/pulls/107174 --- intern/ghost/GHOST_ISystemPaths.hh | 2 +- intern/ghost/intern/GHOST_SystemPaths.hh | 2 +- intern/ghost/intern/GHOST_SystemPathsCocoa.hh | 2 +- intern/ghost/intern/GHOST_SystemPathsCocoa.mm | 8 ++++++-- intern/ghost/intern/GHOST_SystemPathsUnix.hh | 2 +- intern/ghost/intern/GHOST_SystemPathsWin32.cc | 8 ++++---- intern/ghost/intern/GHOST_SystemPathsWin32.hh | 2 +- source/blender/windowmanager/intern/wm_files.cc | 2 +- 8 files changed, 16 insertions(+), 12 deletions(-) diff --git a/intern/ghost/GHOST_ISystemPaths.hh b/intern/ghost/GHOST_ISystemPaths.hh index 934967529ee..2e7a68a9f7c 100644 --- a/intern/ghost/GHOST_ISystemPaths.hh +++ b/intern/ghost/GHOST_ISystemPaths.hh @@ -72,7 +72,7 @@ class GHOST_ISystemPaths { /** * Add the file to the operating system most recently used files */ - virtual void addToSystemRecentFiles(const char *filename) const = 0; + virtual void addToSystemRecentFiles(const char *filepath) const = 0; private: /** The one and only system paths. */ diff --git a/intern/ghost/intern/GHOST_SystemPaths.hh b/intern/ghost/intern/GHOST_SystemPaths.hh index 01089e86203..9ce4bf648c8 100644 --- a/intern/ghost/intern/GHOST_SystemPaths.hh +++ b/intern/ghost/intern/GHOST_SystemPaths.hh @@ -47,5 +47,5 @@ class GHOST_SystemPaths : public GHOST_ISystemPaths { /** * Add the file to the operating system most recently used files */ - virtual void addToSystemRecentFiles(const char *filename) const = 0; + virtual void addToSystemRecentFiles(const char *filepath) const = 0; }; diff --git a/intern/ghost/intern/GHOST_SystemPathsCocoa.hh b/intern/ghost/intern/GHOST_SystemPathsCocoa.hh index 95b4790ea85..185ca524af0 100644 --- a/intern/ghost/intern/GHOST_SystemPathsCocoa.hh +++ b/intern/ghost/intern/GHOST_SystemPathsCocoa.hh @@ -54,5 +54,5 @@ class GHOST_SystemPathsCocoa : public GHOST_SystemPaths { /** * Add the file to the operating system most recently used files */ - void addToSystemRecentFiles(const char *filename) const; + void addToSystemRecentFiles(const char *filepath) const; }; diff --git a/intern/ghost/intern/GHOST_SystemPathsCocoa.mm b/intern/ghost/intern/GHOST_SystemPathsCocoa.mm index e4f003d2cee..2f1d09f76ee 100644 --- a/intern/ghost/intern/GHOST_SystemPathsCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemPathsCocoa.mm @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-or-later * Copyright 2010 Blender Foundation */ +#import #import #include "GHOST_Debug.hh" @@ -112,7 +113,10 @@ const char *GHOST_SystemPathsCocoa::getBinaryDir() const return tempPath; } -void GHOST_SystemPathsCocoa::addToSystemRecentFiles(const char *filename) const +void GHOST_SystemPathsCocoa::addToSystemRecentFiles(const char *filepath) const { - /* TODO: implement for macOS */ + @autoreleasepool { + NSURL *const file_url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:filepath]]; + [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:file_url]; + } } diff --git a/intern/ghost/intern/GHOST_SystemPathsUnix.hh b/intern/ghost/intern/GHOST_SystemPathsUnix.hh index d9b9b5a9e05..f24ce32792b 100644 --- a/intern/ghost/intern/GHOST_SystemPathsUnix.hh +++ b/intern/ghost/intern/GHOST_SystemPathsUnix.hh @@ -52,5 +52,5 @@ class GHOST_SystemPathsUnix : public GHOST_SystemPaths { /** * Add the file to the operating system most recently used files */ - void addToSystemRecentFiles(const char *filename) const; + void addToSystemRecentFiles(const char *filepath) const; }; diff --git a/intern/ghost/intern/GHOST_SystemPathsWin32.cc b/intern/ghost/intern/GHOST_SystemPathsWin32.cc index c9740483803..5ce121aa7a7 100644 --- a/intern/ghost/intern/GHOST_SystemPathsWin32.cc +++ b/intern/ghost/intern/GHOST_SystemPathsWin32.cc @@ -117,10 +117,10 @@ const char *GHOST_SystemPathsWin32::getBinaryDir() const return NULL; } -void GHOST_SystemPathsWin32::addToSystemRecentFiles(const char *filename) const +void GHOST_SystemPathsWin32::addToSystemRecentFiles(const char *filepath) const { /* SHARD_PATH resolves to SHARD_PATHA for non-UNICODE build */ - UTF16_ENCODE(filename); - SHAddToRecentDocs(SHARD_PATHW, filename_16); - UTF16_UN_ENCODE(filename); + UTF16_ENCODE(filepath); + SHAddToRecentDocs(SHARD_PATHW, filepath_16); + UTF16_UN_ENCODE(filepath); } diff --git a/intern/ghost/intern/GHOST_SystemPathsWin32.hh b/intern/ghost/intern/GHOST_SystemPathsWin32.hh index e15f1958319..2ecc406415b 100644 --- a/intern/ghost/intern/GHOST_SystemPathsWin32.hh +++ b/intern/ghost/intern/GHOST_SystemPathsWin32.hh @@ -61,5 +61,5 @@ class GHOST_SystemPathsWin32 : public GHOST_SystemPaths { /** * Add the file to the operating system most recently used files */ - void addToSystemRecentFiles(const char *filename) const; + void addToSystemRecentFiles(const char *filepath) const; }; diff --git a/source/blender/windowmanager/intern/wm_files.cc b/source/blender/windowmanager/intern/wm_files.cc index 3a8670ce377..3d4d14c8334 100644 --- a/source/blender/windowmanager/intern/wm_files.cc +++ b/source/blender/windowmanager/intern/wm_files.cc @@ -1584,7 +1584,7 @@ static void wm_history_file_update(void) /* Write current file to #BLENDER_HISTORY_FILE. */ wm_history_file_write(); - /* also update most recent files on System */ + /* Also update most recent files on system. */ GHOST_addToSystemRecentFiles(blendfile_path); } }