From 220114d04bfd815513287c743e4bdb4eb6a88137 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 22 May 2012 16:24:06 +0100 Subject: [PATCH] Added a method RecentlyOpenedFilesList::registerRecentFileNatively() and updated the introjucer to register its recent documents with the OS. --- .../Introjucer/Source/Project/jucer_Project.cpp | 17 ++++++++++++----- .../Introjucer/Source/Project/jucer_Project.h | 2 +- modules/juce_gui_extra/juce_gui_extra.cpp | 3 +-- .../misc/juce_RecentlyOpenedFilesList.cpp | 14 ++++++++++++++ .../misc/juce_RecentlyOpenedFilesList.h | 6 ++++++ 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/extras/Introjucer/Source/Project/jucer_Project.cpp b/extras/Introjucer/Source/Project/jucer_Project.cpp index 3c6517a41d..6a0a7f6a32 100644 --- a/extras/Introjucer/Source/Project/jucer_Project.cpp +++ b/extras/Introjucer/Source/Project/jucer_Project.cpp @@ -202,6 +202,13 @@ void Project::addDefaultModules (bool shouldCopyFilesLocally) } //============================================================================== +static void registerRecentFile (const File& file) +{ + RecentlyOpenedFilesList::registerRecentFileNatively (file); + StoredSettings::getInstance()->recentFiles.addFile (file); + StoredSettings::getInstance()->flush(); +} + const String Project::loadDocument (const File& file) { ScopedPointer xml (XmlDocument::parse (file)); @@ -214,8 +221,7 @@ const String Project::loadDocument (const File& file) if (! newTree.hasType (Tags::projectRoot)) return "The document contains errors and couldn't be parsed!"; - StoredSettings::getInstance()->recentFiles.addFile (file); - StoredSettings::getInstance()->flush(); + registerRecentFile (file); projectRoot = newTree; removeDefunctExporters(); @@ -229,15 +235,16 @@ const String Project::saveDocument (const File& file) return saveProject (file, true); } -String Project::saveProject (const File& file, bool showProgressBox) +String Project::saveProject (const File& file, bool isCommandLineApp) { updateProjectSettings(); sanitiseConfigFlags(); - StoredSettings::getInstance()->recentFiles.addFile (file); + if (isCommandLineApp) + registerRecentFile (file); ProjectSaver saver (*this, file); - return saver.save (showProgressBox); + return saver.save (isCommandLineApp); } String Project::saveResourcesOnly (const File& file) diff --git a/extras/Introjucer/Source/Project/jucer_Project.h b/extras/Introjucer/Source/Project/jucer_Project.h index 16b70a9436..40850cad2a 100644 --- a/extras/Introjucer/Source/Project/jucer_Project.h +++ b/extras/Introjucer/Source/Project/jucer_Project.h @@ -46,7 +46,7 @@ public: const String getDocumentTitle(); const String loadDocument (const File& file); const String saveDocument (const File& file); - String saveProject (const File& file, bool showProgressBox); + String saveProject (const File& file, bool isCommandLineApp); String saveResourcesOnly (const File& file); const File getLastDocumentOpened(); void setLastDocumentOpened (const File& file); diff --git a/modules/juce_gui_extra/juce_gui_extra.cpp b/modules/juce_gui_extra/juce_gui_extra.cpp index 009914ab64..b86445502d 100644 --- a/modules/juce_gui_extra/juce_gui_extra.cpp +++ b/modules/juce_gui_extra/juce_gui_extra.cpp @@ -79,7 +79,7 @@ namespace juce { -// START_AUTOINCLUDE documents/*.cpp, code_editor/*.cpp, embedding/*.cpp, lookandfeel/*.cpp, misc/*.cpp +#include "../juce_core/native/juce_osx_ObjCHelpers.h" #include "documents/juce_FileBasedDocument.cpp" #include "code_editor/juce_CodeDocument.cpp" #include "code_editor/juce_CodeEditorComponent.cpp" @@ -92,7 +92,6 @@ namespace juce #include "misc/juce_RecentlyOpenedFilesList.cpp" #include "misc/juce_SplashScreen.cpp" #include "misc/juce_SystemTrayIconComponent.cpp" -// END_AUTOINCLUDE } diff --git a/modules/juce_gui_extra/misc/juce_RecentlyOpenedFilesList.cpp b/modules/juce_gui_extra/misc/juce_RecentlyOpenedFilesList.cpp index 09d8f019b1..5bb0b0df2a 100644 --- a/modules/juce_gui_extra/misc/juce_RecentlyOpenedFilesList.cpp +++ b/modules/juce_gui_extra/misc/juce_RecentlyOpenedFilesList.cpp @@ -130,3 +130,17 @@ void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersio setMaxNumberOfItems (maxNumberOfItems); } + + +//============================================================================== +void RecentlyOpenedFilesList::registerRecentFileNatively (const File& file) +{ + #if JUCE_MAC + JUCE_AUTORELEASEPOOL + + [[NSDocumentController sharedDocumentController] + noteNewRecentDocumentURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]]; + #else + (void) file; + #endif +} diff --git a/modules/juce_gui_extra/misc/juce_RecentlyOpenedFilesList.h b/modules/juce_gui_extra/misc/juce_RecentlyOpenedFilesList.h index 98e115ed45..08924842b6 100644 --- a/modules/juce_gui_extra/misc/juce_RecentlyOpenedFilesList.h +++ b/modules/juce_gui_extra/misc/juce_RecentlyOpenedFilesList.h @@ -102,6 +102,12 @@ public: */ void removeNonExistentFiles(); + /** Tells the OS to add a file to the OS-managed list of recent documents for this app. + Not all OSes maintain a list of recent files for an application, so this + function will have no effect on some OSes. Currently it's just implemented for OSX. + */ + static void registerRecentFileNatively (const File& file); + //============================================================================== /** Adds entries to a menu, representing each of the files in the list.