mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-20 17:41:13 +02:00
Do not require AudacityApp.h when using global file history
This commit is contained in:
@@ -722,10 +722,6 @@ void AudacityApp::MacNewFile()
|
|||||||
|
|
||||||
#endif //__WXMAC__
|
#endif //__WXMAC__
|
||||||
|
|
||||||
#define ID_RECENT_CLEAR 6100
|
|
||||||
#define ID_RECENT_FIRST 6101
|
|
||||||
#define ID_RECENT_LAST 6112
|
|
||||||
|
|
||||||
// IPC communication
|
// IPC communication
|
||||||
#define ID_IPC_SERVER 6200
|
#define ID_IPC_SERVER 6200
|
||||||
#define ID_IPC_SOCKET 6201
|
#define ID_IPC_SOCKET 6201
|
||||||
@@ -752,8 +748,9 @@ BEGIN_EVENT_TABLE(AudacityApp, wxApp)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Recent file event handlers.
|
// Recent file event handlers.
|
||||||
EVT_MENU(ID_RECENT_CLEAR, AudacityApp::OnMRUClear)
|
EVT_MENU(FileHistory::ID_RECENT_CLEAR, AudacityApp::OnMRUClear)
|
||||||
EVT_MENU_RANGE(ID_RECENT_FIRST, ID_RECENT_LAST, AudacityApp::OnMRUFile)
|
EVT_MENU_RANGE(FileHistory::ID_RECENT_FIRST, FileHistory::ID_RECENT_LAST,
|
||||||
|
AudacityApp::OnMRUFile)
|
||||||
|
|
||||||
// Handle AppCommandEvents (usually from a script)
|
// Handle AppCommandEvents (usually from a script)
|
||||||
EVT_APP_COMMAND(wxID_ANY, AudacityApp::OnReceiveCommand)
|
EVT_APP_COMMAND(wxID_ANY, AudacityApp::OnReceiveCommand)
|
||||||
@@ -820,15 +817,16 @@ bool AudacityApp::SafeMRUOpen(const wxString &fullPathStr)
|
|||||||
|
|
||||||
void AudacityApp::OnMRUClear(wxCommandEvent& WXUNUSED(event))
|
void AudacityApp::OnMRUClear(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
mRecentFiles->Clear();
|
FileHistory::Global().Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
//vvv Basically, anything from Recent Files is treated as a .aup, until proven otherwise,
|
//vvv Basically, anything from Recent Files is treated as a .aup, until proven otherwise,
|
||||||
// then it tries to Import(). Very questionable handling, imo.
|
// then it tries to Import(). Very questionable handling, imo.
|
||||||
// Better, for example, to check the file type early on.
|
// Better, for example, to check the file type early on.
|
||||||
void AudacityApp::OnMRUFile(wxCommandEvent& event) {
|
void AudacityApp::OnMRUFile(wxCommandEvent& event) {
|
||||||
int n = event.GetId() - ID_RECENT_FIRST;
|
int n = event.GetId() - FileHistory::ID_RECENT_FIRST;
|
||||||
const auto &fullPathStr = mRecentFiles->GetHistoryFile(n);
|
auto &history = FileHistory::Global();
|
||||||
|
const auto &fullPathStr = history.GetHistoryFile(n);
|
||||||
|
|
||||||
// Try to open only if not already open.
|
// Try to open only if not already open.
|
||||||
// Test IsAlreadyOpen() here even though AudacityProject::MRUOpen() also now checks,
|
// Test IsAlreadyOpen() here even though AudacityProject::MRUOpen() also now checks,
|
||||||
@@ -839,7 +837,7 @@ void AudacityApp::OnMRUFile(wxCommandEvent& event) {
|
|||||||
// -- if open fails for some exceptional reason of resource exhaustion that
|
// -- if open fails for some exceptional reason of resource exhaustion that
|
||||||
// the user can correct, leave the file in history.
|
// the user can correct, leave the file in history.
|
||||||
if (!AudacityProject::IsAlreadyOpen(fullPathStr) && !MRUOpen(fullPathStr))
|
if (!AudacityProject::IsAlreadyOpen(fullPathStr) && !MRUOpen(fullPathStr))
|
||||||
mRecentFiles->RemoveFileFromHistory(n);
|
history.RemoveFileFromHistory(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudacityApp::OnTimer(wxTimerEvent& WXUNUSED(event))
|
void AudacityApp::OnTimer(wxTimerEvent& WXUNUSED(event))
|
||||||
@@ -1445,10 +1443,6 @@ bool AudacityApp::OnInit()
|
|||||||
this->AssociateFileTypes();
|
this->AssociateFileTypes();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO - read the number of files to store in history from preferences
|
|
||||||
mRecentFiles = std::make_unique<FileHistory>(ID_RECENT_LAST - ID_RECENT_FIRST + 1, ID_RECENT_CLEAR);
|
|
||||||
mRecentFiles->Load(*gPrefs, wxT("RecentFiles"));
|
|
||||||
|
|
||||||
theTheme.EnsureInitialised();
|
theTheme.EnsureInitialised();
|
||||||
|
|
||||||
// AColor depends on theTheme.
|
// AColor depends on theTheme.
|
||||||
@@ -1592,8 +1586,9 @@ bool AudacityApp::OnInit()
|
|||||||
wxMenuBar::MacSetCommonMenuBar(menuBar.release());
|
wxMenuBar::MacSetCommonMenuBar(menuBar.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
mRecentFiles->UseMenu(recentMenu);
|
auto &recentFiles = FileHistory::Global();
|
||||||
mRecentFiles->AddFilesToMenu(recentMenu);
|
recentFiles.UseMenu(recentMenu);
|
||||||
|
recentFiles.AddFilesToMenu(recentMenu);
|
||||||
|
|
||||||
SetExitOnFrameDelete(false);
|
SetExitOnFrameDelete(false);
|
||||||
|
|
||||||
@@ -2185,11 +2180,6 @@ void AudacityApp::OnEndSession(wxCloseEvent & event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudacityApp::AddFileToHistory(const FilePath & name)
|
|
||||||
{
|
|
||||||
mRecentFiles->AddFileToHistory(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
int AudacityApp::OnExit()
|
int AudacityApp::OnExit()
|
||||||
{
|
{
|
||||||
gIsQuitting = true;
|
gIsQuitting = true;
|
||||||
@@ -2212,7 +2202,7 @@ int AudacityApp::OnExit()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mRecentFiles->Save(*gPrefs, wxT("RecentFiles"));
|
FileHistory::Global().Save(*gPrefs, wxT("RecentFiles"));
|
||||||
|
|
||||||
FinishPreferences();
|
FinishPreferences();
|
||||||
|
|
||||||
|
@@ -39,7 +39,6 @@ class CommandHandler;
|
|||||||
class AppCommandEvent;
|
class AppCommandEvent;
|
||||||
class AudacityLogger;
|
class AudacityLogger;
|
||||||
class AudacityProject;
|
class AudacityProject;
|
||||||
class FileHistory;
|
|
||||||
|
|
||||||
void SaveWindowSize();
|
void SaveWindowSize();
|
||||||
|
|
||||||
@@ -155,8 +154,6 @@ class AudacityApp final : public wxApp {
|
|||||||
int flags = wxDIR_FILES);
|
int flags = wxDIR_FILES);
|
||||||
static bool IsTempDirectoryNameOK( const wxString & Name );
|
static bool IsTempDirectoryNameOK( const wxString & Name );
|
||||||
|
|
||||||
FileHistory *GetRecentFiles() {return mRecentFiles.get();}
|
|
||||||
void AddFileToHistory(const FilePath & name);
|
|
||||||
bool GetWindowRectAlreadySaved()const {return mWindowRectAlreadySaved;}
|
bool GetWindowRectAlreadySaved()const {return mWindowRectAlreadySaved;}
|
||||||
void SetWindowRectAlreadySaved(bool alreadySaved) {mWindowRectAlreadySaved = alreadySaved;}
|
void SetWindowRectAlreadySaved(bool alreadySaved) {mWindowRectAlreadySaved = alreadySaved;}
|
||||||
|
|
||||||
@@ -181,7 +178,6 @@ class AudacityApp final : public wxApp {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<CommandHandler> mCmdHandler;
|
std::unique_ptr<CommandHandler> mCmdHandler;
|
||||||
std::unique_ptr<FileHistory> mRecentFiles;
|
|
||||||
|
|
||||||
std::unique_ptr<wxLocale> mLocale;
|
std::unique_ptr<wxLocale> mLocale;
|
||||||
|
|
||||||
|
@@ -31,7 +31,6 @@
|
|||||||
#include "Experimental.h"
|
#include "Experimental.h"
|
||||||
|
|
||||||
#include "AdornedRulerPanel.h"
|
#include "AdornedRulerPanel.h"
|
||||||
#include "AudacityApp.h"
|
|
||||||
#include "AudioIO.h"
|
#include "AudioIO.h"
|
||||||
#include "Clipboard.h"
|
#include "Clipboard.h"
|
||||||
#include "LabelTrack.h"
|
#include "LabelTrack.h"
|
||||||
@@ -538,7 +537,7 @@ CommandFlag MenuManager::GetUpdateFlags
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wxGetApp().GetRecentFiles()->GetCount() > 0)
|
if (FileHistory::Global().GetCount() > 0)
|
||||||
flags |= HaveRecentFiles;
|
flags |= HaveRecentFiles;
|
||||||
|
|
||||||
if (project.IsSyncLocked())
|
if (project.IsSyncLocked())
|
||||||
|
@@ -95,6 +95,7 @@ scroll information. It also has some status flags.
|
|||||||
|
|
||||||
#include "AdornedRulerPanel.h"
|
#include "AdornedRulerPanel.h"
|
||||||
#include "Clipboard.h"
|
#include "Clipboard.h"
|
||||||
|
#include "widgets/FileHistory.h"
|
||||||
#include "FreqWindow.h"
|
#include "FreqWindow.h"
|
||||||
#include "effects/Contrast.h"
|
#include "effects/Contrast.h"
|
||||||
#include "AutoRecovery.h"
|
#include "AutoRecovery.h"
|
||||||
@@ -3129,9 +3130,8 @@ void AudacityProject::OpenFile(const FilePath &fileNameArg, bool addtohistory)
|
|||||||
// else any asynch calls into the blockfile code will not have
|
// else any asynch calls into the blockfile code will not have
|
||||||
// finished logging errors (if any) before the call to ProjectFSCK()
|
// finished logging errors (if any) before the call to ProjectFSCK()
|
||||||
|
|
||||||
if (addtohistory) {
|
if (addtohistory)
|
||||||
wxGetApp().AddFileToHistory(fileName);
|
FileHistory::Global().AddFileToHistory(fileName);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use a finally block here, because there are calls to Save() below which
|
// Use a finally block here, because there are calls to Save() below which
|
||||||
@@ -4293,7 +4293,7 @@ bool AudacityProject::Import(const FilePath &fileName, WaveTrackArray* pTrackArr
|
|||||||
if (!success)
|
if (!success)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
wxGetApp().AddFileToHistory(fileName);
|
FileHistory::Global().AddFileToHistory(fileName);
|
||||||
|
|
||||||
// no more errors, commit
|
// no more errors, commit
|
||||||
cleanup.release();
|
cleanup.release();
|
||||||
@@ -4372,7 +4372,7 @@ bool AudacityProject::SaveAs(const wxString & newFileName, bool bWantSaveCopy /*
|
|||||||
success = DoSave(!bOwnsNewAupName || bWantSaveCopy, bWantSaveCopy);
|
success = DoSave(!bOwnsNewAupName || bWantSaveCopy, bWantSaveCopy);
|
||||||
|
|
||||||
if (success && addToHistory) {
|
if (success && addToHistory) {
|
||||||
wxGetApp().AddFileToHistory(mFileName);
|
FileHistory::Global().AddFileToHistory(mFileName);
|
||||||
}
|
}
|
||||||
if (!success || bWantSaveCopy) // bWantSaveCopy doesn't actually change current project.
|
if (!success || bWantSaveCopy) // bWantSaveCopy doesn't actually change current project.
|
||||||
{
|
{
|
||||||
@@ -4542,7 +4542,7 @@ will be irreversibly overwritten."), fName, fName);
|
|||||||
success = DoSave(!bOwnsNewAupName || bWantSaveCopy, bWantSaveCopy, bLossless);
|
success = DoSave(!bOwnsNewAupName || bWantSaveCopy, bWantSaveCopy, bLossless);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
wxGetApp().AddFileToHistory(mFileName);
|
FileHistory::Global().AddFileToHistory(mFileName);
|
||||||
if( !bHasPath )
|
if( !bHasPath )
|
||||||
{
|
{
|
||||||
gPrefs->Write( wxT("/SaveAs/Path"), filename.GetPath());
|
gPrefs->Write( wxT("/SaveAs/Path"), filename.GetPath());
|
||||||
@@ -5354,7 +5354,7 @@ bool AudacityProject::SaveFromTimerRecording(wxFileName fnFile) {
|
|||||||
bSuccess = DoSave(true, false);
|
bSuccess = DoSave(true, false);
|
||||||
|
|
||||||
if (bSuccess) {
|
if (bSuccess) {
|
||||||
wxGetApp().AddFileToHistory(mFileName);
|
FileHistory::Global().AddFileToHistory(mFileName);
|
||||||
mbLoadedFromAup = true;
|
mbLoadedFromAup = true;
|
||||||
SetProjectTitle();
|
SetProjectTitle();
|
||||||
}
|
}
|
||||||
|
@@ -81,7 +81,7 @@ void DoExport
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxGetApp().AddFileToHistory(filename);
|
FileHistory::Global().AddFileToHistory(filename);
|
||||||
// We're in batch mode, the file does not exist already.
|
// We're in batch mode, the file does not exist already.
|
||||||
// We really can proceed without prompting.
|
// We really can proceed without prompting.
|
||||||
int nChannels = MacroCommands::IsMono() ? 1 : 2;
|
int nChannels = MacroCommands::IsMono() ? 1 : 2;
|
||||||
@@ -131,7 +131,7 @@ AudacityProject *DoImportMIDI(
|
|||||||
pProject->ZoomAfterImport(pTrack);
|
pProject->ZoomAfterImport(pTrack);
|
||||||
pNewProject = nullptr;
|
pNewProject = nullptr;
|
||||||
|
|
||||||
wxGetApp().AddFileToHistory(fileName);
|
FileHistory::Global().AddFileToHistory(fileName);
|
||||||
|
|
||||||
return pProject;
|
return pProject;
|
||||||
}
|
}
|
||||||
@@ -597,8 +597,9 @@ MenuTable::BaseItemPtr FileMenu( AudacityProject& )
|
|||||||
,
|
,
|
||||||
Special( [](AudacityProject &, wxMenu &theMenu){
|
Special( [](AudacityProject &, wxMenu &theMenu){
|
||||||
// Recent Files and Recent Projects menus
|
// Recent Files and Recent Projects menus
|
||||||
wxGetApp().GetRecentFiles()->UseMenu( &theMenu );
|
auto &history = FileHistory::Global();
|
||||||
wxGetApp().GetRecentFiles()->AddFilesToMenu( &theMenu );
|
history.UseMenu( &theMenu );
|
||||||
|
history.AddFilesToMenu( &theMenu );
|
||||||
|
|
||||||
wxWeakRef<wxMenu> recentFilesMenu{ &theMenu };
|
wxWeakRef<wxMenu> recentFilesMenu{ &theMenu };
|
||||||
wxTheApp->CallAfter( [=] {
|
wxTheApp->CallAfter( [=] {
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
*******************************************************************//**
|
*******************************************************************//**
|
||||||
|
|
||||||
\class FileHistory
|
\class FileHistory
|
||||||
\brief Similar to FileHistory, but customized to our needs.
|
\brief Similar to wxFileHistory, but customized to our needs.
|
||||||
|
|
||||||
*//*******************************************************************/
|
*//*******************************************************************/
|
||||||
|
|
||||||
@@ -21,6 +21,9 @@
|
|||||||
#include <wx/menu.h>
|
#include <wx/menu.h>
|
||||||
|
|
||||||
#include "../Internat.h"
|
#include "../Internat.h"
|
||||||
|
#include "../Prefs.h"
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
FileHistory::FileHistory(size_t maxfiles, wxWindowID base)
|
FileHistory::FileHistory(size_t maxfiles, wxWindowID base)
|
||||||
{
|
{
|
||||||
@@ -32,6 +35,19 @@ FileHistory::~FileHistory()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileHistory &FileHistory::Global()
|
||||||
|
{
|
||||||
|
// TODO - read the number of files to store in history from preferences
|
||||||
|
static FileHistory history{
|
||||||
|
ID_RECENT_LAST - ID_RECENT_FIRST + 1, ID_RECENT_CLEAR };
|
||||||
|
static std::once_flag flag;
|
||||||
|
std::call_once( flag, [&]{
|
||||||
|
history.Load(*gPrefs, wxT("RecentFiles"));
|
||||||
|
});
|
||||||
|
|
||||||
|
return history;
|
||||||
|
}
|
||||||
|
|
||||||
// File history management
|
// File history management
|
||||||
void FileHistory::AddFileToHistory(const FilePath & file, bool update)
|
void FileHistory::AddFileToHistory(const FilePath & file, bool update)
|
||||||
{
|
{
|
||||||
|
@@ -28,6 +28,15 @@ class AUDACITY_DLL_API FileHistory
|
|||||||
FileHistory(size_t maxfiles = 12, wxWindowID idbase = wxID_FILE);
|
FileHistory(size_t maxfiles = 12, wxWindowID idbase = wxID_FILE);
|
||||||
virtual ~FileHistory();
|
virtual ~FileHistory();
|
||||||
|
|
||||||
|
// These constants define the range of IDs reserved by the global file history
|
||||||
|
enum {
|
||||||
|
ID_RECENT_CLEAR = 6100,
|
||||||
|
ID_RECENT_FIRST = 6101,
|
||||||
|
ID_RECENT_LAST = 6112
|
||||||
|
};
|
||||||
|
|
||||||
|
static FileHistory &Global();
|
||||||
|
|
||||||
void AddFileToHistory(const FilePath & file, bool update = true);
|
void AddFileToHistory(const FilePath & file, bool update = true);
|
||||||
void RemoveFileFromHistory(size_t i, bool update = true);
|
void RemoveFileFromHistory(size_t i, bool update = true);
|
||||||
void Clear();
|
void Clear();
|
||||||
|
Reference in New Issue
Block a user