Audacity 3.2.0
ActiveProjects.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 ActiveProjects.cpp
6
7********************************************************************//********************************************************************/
13
14#include "ActiveProjects.h"
15#include "Prefs.h"
16
17#include <wx/filename.h>
18
20{
21 FilePaths files;
22
23 const auto activeProjectsGroup = gPrefs->BeginGroup("/ActiveProjects");
24 for(const auto& key : gPrefs->GetChildKeys())
25 {
26 wxFileName path = gPrefs->Read(key, wxT(""));
27 files.Add(path.GetFullPath());
28 }
29
30 return files;
31}
32
33void ActiveProjects::Add(const FilePath &path)
34{
35 wxString key = Find(path);
36
37 if (key.empty())
38 {
39 int i = 0;
40 do
41 {
42 key.Printf(wxT("/ActiveProjects/%d"), ++i);
43 } while (gPrefs->HasEntry(key));
44
45 gPrefs->Write(key, path);
46 gPrefs->Flush();
47 }
48}
49
50void ActiveProjects::Remove(const FilePath &path)
51{
52 wxString key = Find(path);
53
54 if (!key.empty())
55 {
56 gPrefs->DeleteEntry(wxT("/ActiveProjects/" + key));
57 gPrefs->Flush();
58 }
59}
60
61wxString ActiveProjects::Find(const FilePath &path)
62{
63 const auto activeProjectsGroup = gPrefs->BeginGroup("/ActiveProjects");
64 for(const auto& key : gPrefs->GetChildKeys())
65 {
66 if(gPrefs->Read(key, wxT("")).IsSameAs(path))
67 return key;
68 }
69 return {};
70}
71
wxT("CloseDown"))
static const AudacityProject::AttachedObjects::RegisteredFactory key
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
wxString FilePath
Definition: Project.h:21
virtual bool Flush() noexcept=0
GroupScope BeginGroup(const wxString &prefix)
Appends a prefix to the current group or sets a new absolute path. Group that was set as current befo...
virtual bool HasEntry(const wxString &key) const =0
Checks whether specified key exists within the current group.
virtual wxArrayString GetChildKeys() const =0
Returns all child keys within the current group.
virtual bool Write(const wxString &key, bool value)=0
bool DeleteEntry(const wxString &key)
Deletes specified entry if exists.
virtual bool Read(const wxString &key, bool *value) const =0
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
PROJECT_FILE_IO_API void Remove(const FilePath &path)
PROJECT_FILE_IO_API void Add(const FilePath &path)
PROJECT_FILE_IO_API wxString Find(const FilePath &path)
PROJECT_FILE_IO_API FilePaths GetAll()