mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 16:10:06 +02:00
Do not require AudacityApp.h when using global file history
This commit is contained in:
parent
d4f71c2c64
commit
2d8c287384
@ -722,10 +722,6 @@ void AudacityApp::MacNewFile()
|
||||
|
||||
#endif //__WXMAC__
|
||||
|
||||
#define ID_RECENT_CLEAR 6100
|
||||
#define ID_RECENT_FIRST 6101
|
||||
#define ID_RECENT_LAST 6112
|
||||
|
||||
// IPC communication
|
||||
#define ID_IPC_SERVER 6200
|
||||
#define ID_IPC_SOCKET 6201
|
||||
@ -752,8 +748,9 @@ BEGIN_EVENT_TABLE(AudacityApp, wxApp)
|
||||
#endif
|
||||
|
||||
// Recent file event handlers.
|
||||
EVT_MENU(ID_RECENT_CLEAR, AudacityApp::OnMRUClear)
|
||||
EVT_MENU_RANGE(ID_RECENT_FIRST, ID_RECENT_LAST, AudacityApp::OnMRUFile)
|
||||
EVT_MENU(FileHistory::ID_RECENT_CLEAR, AudacityApp::OnMRUClear)
|
||||
EVT_MENU_RANGE(FileHistory::ID_RECENT_FIRST, FileHistory::ID_RECENT_LAST,
|
||||
AudacityApp::OnMRUFile)
|
||||
|
||||
// Handle AppCommandEvents (usually from a script)
|
||||
EVT_APP_COMMAND(wxID_ANY, AudacityApp::OnReceiveCommand)
|
||||
@ -820,15 +817,16 @@ bool AudacityApp::SafeMRUOpen(const wxString &fullPathStr)
|
||||
|
||||
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,
|
||||
// then it tries to Import(). Very questionable handling, imo.
|
||||
// Better, for example, to check the file type early on.
|
||||
void AudacityApp::OnMRUFile(wxCommandEvent& event) {
|
||||
int n = event.GetId() - ID_RECENT_FIRST;
|
||||
const auto &fullPathStr = mRecentFiles->GetHistoryFile(n);
|
||||
int n = event.GetId() - FileHistory::ID_RECENT_FIRST;
|
||||
auto &history = FileHistory::Global();
|
||||
const auto &fullPathStr = history.GetHistoryFile(n);
|
||||
|
||||
// Try to open only if not already open.
|
||||
// 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
|
||||
// the user can correct, leave the file in history.
|
||||
if (!AudacityProject::IsAlreadyOpen(fullPathStr) && !MRUOpen(fullPathStr))
|
||||
mRecentFiles->RemoveFileFromHistory(n);
|
||||
history.RemoveFileFromHistory(n);
|
||||
}
|
||||
|
||||
void AudacityApp::OnTimer(wxTimerEvent& WXUNUSED(event))
|
||||
@ -1445,10 +1443,6 @@ bool AudacityApp::OnInit()
|
||||
this->AssociateFileTypes();
|
||||
#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();
|
||||
|
||||
// AColor depends on theTheme.
|
||||
@ -1592,8 +1586,9 @@ bool AudacityApp::OnInit()
|
||||
wxMenuBar::MacSetCommonMenuBar(menuBar.release());
|
||||
}
|
||||
|
||||
mRecentFiles->UseMenu(recentMenu);
|
||||
mRecentFiles->AddFilesToMenu(recentMenu);
|
||||
auto &recentFiles = FileHistory::Global();
|
||||
recentFiles.UseMenu(recentMenu);
|
||||
recentFiles.AddFilesToMenu(recentMenu);
|
||||
|
||||
SetExitOnFrameDelete(false);
|
||||
|
||||
@ -2185,11 +2180,6 @@ void AudacityApp::OnEndSession(wxCloseEvent & event)
|
||||
}
|
||||
}
|
||||
|
||||
void AudacityApp::AddFileToHistory(const FilePath & name)
|
||||
{
|
||||
mRecentFiles->AddFileToHistory(name);
|
||||
}
|
||||
|
||||
int AudacityApp::OnExit()
|
||||
{
|
||||
gIsQuitting = true;
|
||||
@ -2212,7 +2202,7 @@ int AudacityApp::OnExit()
|
||||
}
|
||||
}
|
||||
|
||||
mRecentFiles->Save(*gPrefs, wxT("RecentFiles"));
|
||||
FileHistory::Global().Save(*gPrefs, wxT("RecentFiles"));
|
||||
|
||||
FinishPreferences();
|
||||
|
||||
|
@ -39,7 +39,6 @@ class CommandHandler;
|
||||
class AppCommandEvent;
|
||||
class AudacityLogger;
|
||||
class AudacityProject;
|
||||
class FileHistory;
|
||||
|
||||
void SaveWindowSize();
|
||||
|
||||
@ -155,8 +154,6 @@ class AudacityApp final : public wxApp {
|
||||
int flags = wxDIR_FILES);
|
||||
static bool IsTempDirectoryNameOK( const wxString & Name );
|
||||
|
||||
FileHistory *GetRecentFiles() {return mRecentFiles.get();}
|
||||
void AddFileToHistory(const FilePath & name);
|
||||
bool GetWindowRectAlreadySaved()const {return mWindowRectAlreadySaved;}
|
||||
void SetWindowRectAlreadySaved(bool alreadySaved) {mWindowRectAlreadySaved = alreadySaved;}
|
||||
|
||||
@ -181,7 +178,6 @@ class AudacityApp final : public wxApp {
|
||||
|
||||
private:
|
||||
std::unique_ptr<CommandHandler> mCmdHandler;
|
||||
std::unique_ptr<FileHistory> mRecentFiles;
|
||||
|
||||
std::unique_ptr<wxLocale> mLocale;
|
||||
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "Experimental.h"
|
||||
|
||||
#include "AdornedRulerPanel.h"
|
||||
#include "AudacityApp.h"
|
||||
#include "AudioIO.h"
|
||||
#include "Clipboard.h"
|
||||
#include "LabelTrack.h"
|
||||
@ -538,7 +537,7 @@ CommandFlag MenuManager::GetUpdateFlags
|
||||
}
|
||||
}
|
||||
|
||||
if (wxGetApp().GetRecentFiles()->GetCount() > 0)
|
||||
if (FileHistory::Global().GetCount() > 0)
|
||||
flags |= HaveRecentFiles;
|
||||
|
||||
if (project.IsSyncLocked())
|
||||
|
@ -95,6 +95,7 @@ scroll information. It also has some status flags.
|
||||
|
||||
#include "AdornedRulerPanel.h"
|
||||
#include "Clipboard.h"
|
||||
#include "widgets/FileHistory.h"
|
||||
#include "FreqWindow.h"
|
||||
#include "effects/Contrast.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
|
||||
// finished logging errors (if any) before the call to ProjectFSCK()
|
||||
|
||||
if (addtohistory) {
|
||||
wxGetApp().AddFileToHistory(fileName);
|
||||
}
|
||||
if (addtohistory)
|
||||
FileHistory::Global().AddFileToHistory(fileName);
|
||||
}
|
||||
|
||||
// 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)
|
||||
return false;
|
||||
|
||||
wxGetApp().AddFileToHistory(fileName);
|
||||
FileHistory::Global().AddFileToHistory(fileName);
|
||||
|
||||
// no more errors, commit
|
||||
cleanup.release();
|
||||
@ -4372,7 +4372,7 @@ bool AudacityProject::SaveAs(const wxString & newFileName, bool bWantSaveCopy /*
|
||||
success = DoSave(!bOwnsNewAupName || bWantSaveCopy, bWantSaveCopy);
|
||||
|
||||
if (success && addToHistory) {
|
||||
wxGetApp().AddFileToHistory(mFileName);
|
||||
FileHistory::Global().AddFileToHistory(mFileName);
|
||||
}
|
||||
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);
|
||||
|
||||
if (success) {
|
||||
wxGetApp().AddFileToHistory(mFileName);
|
||||
FileHistory::Global().AddFileToHistory(mFileName);
|
||||
if( !bHasPath )
|
||||
{
|
||||
gPrefs->Write( wxT("/SaveAs/Path"), filename.GetPath());
|
||||
@ -5354,7 +5354,7 @@ bool AudacityProject::SaveFromTimerRecording(wxFileName fnFile) {
|
||||
bSuccess = DoSave(true, false);
|
||||
|
||||
if (bSuccess) {
|
||||
wxGetApp().AddFileToHistory(mFileName);
|
||||
FileHistory::Global().AddFileToHistory(mFileName);
|
||||
mbLoadedFromAup = true;
|
||||
SetProjectTitle();
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ void DoExport
|
||||
}
|
||||
else
|
||||
{
|
||||
wxGetApp().AddFileToHistory(filename);
|
||||
FileHistory::Global().AddFileToHistory(filename);
|
||||
// We're in batch mode, the file does not exist already.
|
||||
// We really can proceed without prompting.
|
||||
int nChannels = MacroCommands::IsMono() ? 1 : 2;
|
||||
@ -131,7 +131,7 @@ AudacityProject *DoImportMIDI(
|
||||
pProject->ZoomAfterImport(pTrack);
|
||||
pNewProject = nullptr;
|
||||
|
||||
wxGetApp().AddFileToHistory(fileName);
|
||||
FileHistory::Global().AddFileToHistory(fileName);
|
||||
|
||||
return pProject;
|
||||
}
|
||||
@ -597,8 +597,9 @@ MenuTable::BaseItemPtr FileMenu( AudacityProject& )
|
||||
,
|
||||
Special( [](AudacityProject &, wxMenu &theMenu){
|
||||
// Recent Files and Recent Projects menus
|
||||
wxGetApp().GetRecentFiles()->UseMenu( &theMenu );
|
||||
wxGetApp().GetRecentFiles()->AddFilesToMenu( &theMenu );
|
||||
auto &history = FileHistory::Global();
|
||||
history.UseMenu( &theMenu );
|
||||
history.AddFilesToMenu( &theMenu );
|
||||
|
||||
wxWeakRef<wxMenu> recentFilesMenu{ &theMenu };
|
||||
wxTheApp->CallAfter( [=] {
|
||||
|
@ -9,7 +9,7 @@
|
||||
*******************************************************************//**
|
||||
|
||||
\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 "../Internat.h"
|
||||
#include "../Prefs.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
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
|
||||
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);
|
||||
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 RemoveFileFromHistory(size_t i, bool update = true);
|
||||
void Clear();
|
||||
|
Loading…
x
Reference in New Issue
Block a user