LMMS
Loading...
Searching...
No Matches
juce_RecentlyOpenedFilesList.cpp
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
33
34//==============================================================================
36{
37 maxNumberOfItems = jmax (1, newMaxNumber);
38
39 files.removeRange (maxNumberOfItems, getNumFiles());
40}
41
43{
44 return files.size();
45}
46
48{
49 return File (files [index]);
50}
51
53{
54 files.clear();
55}
56
58{
60 files.insert (0, file.getFullPathName());
61
63}
64
66{
67 files.removeString (file.getFullPathName());
68}
69
71{
72 for (int i = getNumFiles(); --i >= 0;)
73 if (! getFile(i).exists())
74 files.remove (i);
75}
76
77//==============================================================================
79 const int baseItemId,
80 const bool showFullPaths,
81 const bool dontAddNonExistentFiles,
82 const File** filesToAvoid)
83{
84 int num = 0;
85
86 for (int i = 0; i < getNumFiles(); ++i)
87 {
88 const File f (getFile(i));
89
90 if ((! dontAddNonExistentFiles) || f.exists())
91 {
92 bool needsAvoiding = false;
93
94 if (filesToAvoid != nullptr)
95 {
96 for (const File** avoid = filesToAvoid; *avoid != nullptr; ++avoid)
97 {
98 if (f == **avoid)
99 {
100 needsAvoiding = true;
101 break;
102 }
103 }
104 }
105
106 if (! needsAvoiding)
107 {
108 menuToAddTo.addItem (baseItemId + i,
109 showFullPaths ? f.getFullPathName()
110 : f.getFileName());
111 ++num;
112 }
113 }
114 }
115
116 return num;
117}
118
119//==============================================================================
121{
122 return files.joinIntoString ("\n");
123}
124
126{
127 clear();
128 files.addLines (stringifiedVersion);
129
131}
132
133
134//==============================================================================
136{
137 #if JUCE_MAC
139 {
140 [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: createNSURLFromFile (file)];
141 }
142 #else
144 #endif
145}
146
148{
149 #if JUCE_MAC
151 {
152 // for some reason, OSX doesn't provide a method to just remove a single file
153 // from the recent list, so we clear them all and add them back excluding
154 // the specified file
155
156 auto sharedDocController = [NSDocumentController sharedDocumentController];
157 auto recentDocumentURLs = [sharedDocController recentDocumentURLs];
158
159 [sharedDocController clearRecentDocuments: nil];
160
161 auto* nsFile = createNSURLFromFile (file);
162
163 auto reverseEnumerator = [recentDocumentURLs reverseObjectEnumerator];
164
165 for (NSURL* url : reverseEnumerator)
166 if (! [url isEqual:nsFile])
167 [sharedDocController noteNewRecentDocumentURL:url];
168 }
169 #else
171 #endif
172}
173
175{
176 #if JUCE_MAC
178 {
179 [[NSDocumentController sharedDocumentController] clearRecentDocuments: nil];
180 }
181 #endif
182}
183
184} // namespace juce
Type jmax(const Type a, const Type b)
Definition MathsFunctions.h:48
Definition juce_File.h:45
Definition juce_PopupMenu.h:80
void addItem(Item newItem)
Definition juce_PopupMenu.cpp:1753
static void forgetRecentFileNatively(const File &file)
Definition juce_RecentlyOpenedFilesList.cpp:147
int getNumFiles() const
Definition juce_RecentlyOpenedFilesList.cpp:42
StringArray files
Definition juce_RecentlyOpenedFilesList.h:171
String toString() const
Definition juce_RecentlyOpenedFilesList.cpp:120
void removeNonExistentFiles()
Definition juce_RecentlyOpenedFilesList.cpp:70
RecentlyOpenedFilesList()
Definition juce_RecentlyOpenedFilesList.cpp:29
int createPopupMenuItems(PopupMenu &menuToAddItemsTo, int baseItemId, bool showFullPaths, bool dontAddNonExistentFiles, const File **filesToAvoid=nullptr)
Definition juce_RecentlyOpenedFilesList.cpp:78
void restoreFromString(const String &stringifiedVersion)
Definition juce_RecentlyOpenedFilesList.cpp:125
static void registerRecentFileNatively(const File &file)
Definition juce_RecentlyOpenedFilesList.cpp:135
File getFile(int index) const
Definition juce_RecentlyOpenedFilesList.cpp:47
void clear()
Definition juce_RecentlyOpenedFilesList.cpp:52
static void clearRecentFilesNatively()
Definition juce_RecentlyOpenedFilesList.cpp:174
void addFile(const File &file)
Definition juce_RecentlyOpenedFilesList.cpp:57
int maxNumberOfItems
Definition juce_RecentlyOpenedFilesList.h:172
void setMaxNumberOfItems(int newMaxNumber)
Definition juce_RecentlyOpenedFilesList.cpp:35
void removeFile(const File &file)
Definition juce_RecentlyOpenedFilesList.cpp:65
Definition juce_String.h:53
register unsigned i
Definition inflate.c:1575
unsigned f
Definition inflate.c:1572
#define JUCE_AUTORELEASEPOOL
Definition juce_Memory.h:158
Definition carla_juce.cpp:31
NSURL * createNSURLFromFile(const String &f)
Definition juce_mac_ObjCHelpers.h:62
void ignoreUnused(Types &&...) noexcept
Definition juce_MathsFunctions.h:333
struct zdirent * file
Definition win32.c:1500