JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
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
30 : maxNumberOfItems (10)
31{
32}
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{
59 removeFile (file);
60 files.insert (0, file.getFullPathName());
61
62 setMaxNumberOfItems (maxNumberOfItems);
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,
110 : f.getFileName());
111 ++num;
112 }
113 }
114 }
115
116 return num;
117}
118
119//==============================================================================
121{
122 return files.joinIntoString ("\n");
123}
124
132
133
134//==============================================================================
144
146{
147 #if JUCE_MAC
149 {
150 // for some reason, OSX doesn't provide a method to just remove a single file
151 // from the recent list, so we clear them all and add them back excluding
152 // the specified file
153
156
158
159 auto* nsFile = createNSURLFromFile (file);
160
162
163 for (NSURL* url : reverseEnumerator)
164 if (! [url isEqual:nsFile])
166 }
167 #endif
168}
169
179
180} // namespace juce
Represents a local file or directory.
Definition juce_File.h:45
const String & getFullPathName() const noexcept
Returns the complete, absolute path of this file.
Definition juce_File.h:153
String getFileName() const
Returns the last section of the pathname.
bool exists() const
Checks whether the file actually exists.
Creates and displays a popup-menu.
static void forgetRecentFileNatively(const File &file)
Tells the OS to remove a file from the OS-managed list of recent documents for this app.
int getNumFiles() const
Returns the number of files in the list.
String toString() const
Returns a string that encapsulates all the files in the list.
void removeNonExistentFiles()
Checks each of the files in the list, removing any that don't exist.
int createPopupMenuItems(PopupMenu &menuToAddItemsTo, int baseItemId, bool showFullPaths, bool dontAddNonExistentFiles, const File **filesToAvoid=nullptr)
Adds entries to a menu, representing each of the files in the list.
void restoreFromString(const String &stringifiedVersion)
Restores the list from a previously stringified version of the list.
static void registerRecentFileNatively(const File &file)
Tells the OS to add a file to the OS-managed list of recent documents for this app.
File getFile(int index) const
Returns one of the files in the list.
void clear()
Clears all the files from the list.
static void clearRecentFilesNatively()
Tells the OS to clear the OS-managed list of recent documents for this app.
void addFile(const File &file)
Adds a file to the list.
void setMaxNumberOfItems(int newMaxNumber)
Sets a limit for the number of files that will be stored in the list.
void removeFile(const File &file)
Removes a file from the list.
String joinIntoString(StringRef separatorString, int startIndex=0, int numberOfElements=-1) const
Joins the strings in the array together into one string.
void insert(int index, String stringToAdd)
Inserts a string into the array.
void clear()
Removes all elements from the array.
void removeString(StringRef stringToRemove, bool ignoreCase=false)
Finds a string in the array and removes it.
int size() const noexcept
Returns the number of strings in the array.
int addLines(StringRef stringToBreakUp)
Breaks up a string into lines and adds them to this array.
void removeRange(int startIndex, int numberToRemove)
Removes a range of elements from the array.
void remove(int index)
Removes a string from the array.
The JUCE String class!
Definition juce_String.h:53
#define JUCE_AUTORELEASEPOOL
A macro that can be used to easily declare a local ScopedAutoReleasePool object for RAII-based obj-C ...
JUCE Namespace.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88