mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 16:10:06 +02:00
Added Steve Parry's patch that adds the Open and SaveAs commands to scripting.
This commit is contained in:
parent
30e6a3dec4
commit
6fc830c0b6
@ -3551,6 +3551,41 @@ bool AudacityProject::Import(wxString fileName, WaveTrackArray* pTrackArray /*=
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AudacityProject::SaveAs(const wxString newFileName, bool bWantSaveCompressed /*= false*/, bool addToHistory /*= true*/)
|
||||||
|
{
|
||||||
|
wxString oldFileName = mFileName;
|
||||||
|
|
||||||
|
//check to see if the new project file already exists.
|
||||||
|
//We should only overwrite it if this project already has the same name, where the user
|
||||||
|
//simply chose to use the save as command although the save command would have the effect.
|
||||||
|
if(mFileName!=newFileName && wxFileExists(newFileName)) {
|
||||||
|
wxMessageDialog m(
|
||||||
|
NULL,
|
||||||
|
_("The project was not saved because the file name provided would overwrite another project.\nPlease try again and select an original name."),
|
||||||
|
_("Error Saving Project"),
|
||||||
|
wxOK|wxICON_ERROR);
|
||||||
|
m.ShowModal();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mFileName = newFileName;
|
||||||
|
SetProjectTitle();
|
||||||
|
|
||||||
|
bool success = Save(false, true, bWantSaveCompressed);
|
||||||
|
|
||||||
|
if (success && addToHistory) {
|
||||||
|
wxGetApp().AddFileToHistory(mFileName);
|
||||||
|
}
|
||||||
|
if (!success || bWantSaveCompressed) // bWantSaveCompressed doesn't actually change current project.
|
||||||
|
{
|
||||||
|
// Reset file name on error
|
||||||
|
mFileName = oldFileName;
|
||||||
|
SetProjectTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
return(success);
|
||||||
|
}
|
||||||
|
|
||||||
bool AudacityProject::SaveAs(bool bWantSaveCompressed /*= false*/)
|
bool AudacityProject::SaveAs(bool bWantSaveCompressed /*= false*/)
|
||||||
{
|
{
|
||||||
wxString path = wxPathOnly(mFileName);
|
wxString path = wxPathOnly(mFileName);
|
||||||
|
@ -203,6 +203,7 @@ class AUDACITY_DLL_API AudacityProject: public wxFrame,
|
|||||||
void UnlockAllBlocks();
|
void UnlockAllBlocks();
|
||||||
bool Save(bool overwrite = true, bool fromSaveAs = false, bool bWantSaveCompressed = false);
|
bool Save(bool overwrite = true, bool fromSaveAs = false, bool bWantSaveCompressed = false);
|
||||||
bool SaveAs(bool bWantSaveCompressed = false);
|
bool SaveAs(bool bWantSaveCompressed = false);
|
||||||
|
bool SaveAs(const wxString newFileName, bool bWantSaveCompressed = false, bool addToHistory = true);
|
||||||
#ifdef USE_LIBVORBIS
|
#ifdef USE_LIBVORBIS
|
||||||
bool SaveCompressedWaveTracks(const wxString strProjectPathName); // full path for aup except extension
|
bool SaveCompressedWaveTracks(const wxString strProjectPathName); // full path for aup except extension
|
||||||
#endif
|
#endif
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "SetProjectInfoCommand.h"
|
#include "SetProjectInfoCommand.h"
|
||||||
#include "PreferenceCommands.h"
|
#include "PreferenceCommands.h"
|
||||||
#include "ImportExportCommands.h"
|
#include "ImportExportCommands.h"
|
||||||
|
#include "OpenSaveCommands.h"
|
||||||
|
|
||||||
CommandDirectory *CommandDirectory::mInstance = NULL;
|
CommandDirectory *CommandDirectory::mInstance = NULL;
|
||||||
|
|
||||||
@ -58,6 +59,8 @@ CommandDirectory::CommandDirectory()
|
|||||||
AddCommand(new GetPreferenceCommandType());
|
AddCommand(new GetPreferenceCommandType());
|
||||||
AddCommand(new ImportCommandType());
|
AddCommand(new ImportCommandType());
|
||||||
AddCommand(new ExportCommandType());
|
AddCommand(new ExportCommandType());
|
||||||
|
AddCommand(new OpenProjectCommandType());
|
||||||
|
AddCommand(new SaveProjectCommandType());
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandDirectory::~CommandDirectory()
|
CommandDirectory::~CommandDirectory()
|
||||||
|
100
src/commands/OpenSaveCommands.cpp
Normal file
100
src/commands/OpenSaveCommands.cpp
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
/**********************************************************************
|
||||||
|
|
||||||
|
Audacity - A Digital Audio Editor
|
||||||
|
Copyright 1999-2009 Audacity Team
|
||||||
|
File License: wxWidgets
|
||||||
|
|
||||||
|
Stephen Parry
|
||||||
|
|
||||||
|
******************************************************************//**
|
||||||
|
|
||||||
|
\file OpenSaveCommands.cpp
|
||||||
|
\brief Contains definitions for the OpenProjectCommand and SaveProjectCommand classes
|
||||||
|
|
||||||
|
*//*******************************************************************/
|
||||||
|
|
||||||
|
#include "OpenSaveCommands.h"
|
||||||
|
#include "../Project.h"
|
||||||
|
#include "../export/Export.h"
|
||||||
|
|
||||||
|
// OpenProject
|
||||||
|
|
||||||
|
wxString OpenProjectCommandType::BuildName()
|
||||||
|
{
|
||||||
|
return wxT("OpenProject");
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenProjectCommandType::BuildSignature(CommandSignature &signature)
|
||||||
|
{
|
||||||
|
BoolValidator *addToHistoryValidator(new BoolValidator());
|
||||||
|
signature.AddParameter(wxT("AddToHistory"), true, addToHistoryValidator);
|
||||||
|
Validator *filenameValidator(new Validator());
|
||||||
|
signature.AddParameter(wxT("Filename"), wxT(""), filenameValidator);
|
||||||
|
}
|
||||||
|
|
||||||
|
Command *OpenProjectCommandType::Create(CommandOutputTarget *target)
|
||||||
|
{
|
||||||
|
return new OpenProjectCommand(*this, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OpenProjectCommand::Apply(CommandExecutionContext context)
|
||||||
|
{
|
||||||
|
wxString fileName = GetString(wxT("Filename"));
|
||||||
|
bool addToHistory = GetBool(wxT("AddToHistory"));
|
||||||
|
wxString oldFileName = context.proj->GetFileName();
|
||||||
|
if(fileName == wxEmptyString)
|
||||||
|
{
|
||||||
|
context.proj->OnOpen();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.proj->OpenFile(fileName,addToHistory);
|
||||||
|
}
|
||||||
|
wxString newFileName = context.proj->GetFileName();
|
||||||
|
|
||||||
|
// Because Open does not return a success or failure, we have to guess
|
||||||
|
// at this point, based on whether the project file name has
|
||||||
|
// changed and what to...
|
||||||
|
return newFileName != wxEmptyString && newFileName != oldFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
OpenProjectCommand::~OpenProjectCommand()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
// SaveProject
|
||||||
|
|
||||||
|
wxString SaveProjectCommandType::BuildName()
|
||||||
|
{
|
||||||
|
return wxT("SaveProject");
|
||||||
|
}
|
||||||
|
|
||||||
|
void SaveProjectCommandType::BuildSignature(CommandSignature &signature)
|
||||||
|
{
|
||||||
|
BoolValidator *saveCompressedValidator(new BoolValidator());
|
||||||
|
BoolValidator *addToHistoryValidator(new BoolValidator());
|
||||||
|
|
||||||
|
signature.AddParameter(wxT("Compress"), false, saveCompressedValidator);
|
||||||
|
signature.AddParameter(wxT("AddToHistory"), true, addToHistoryValidator);
|
||||||
|
|
||||||
|
Validator *filenameValidator(new Validator());
|
||||||
|
signature.AddParameter(wxT("Filename"), wxT(""), filenameValidator);
|
||||||
|
}
|
||||||
|
|
||||||
|
Command *SaveProjectCommandType::Create(CommandOutputTarget *target)
|
||||||
|
{
|
||||||
|
return new SaveProjectCommand(*this, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SaveProjectCommand::Apply(CommandExecutionContext context)
|
||||||
|
{
|
||||||
|
wxString fileName = GetString(wxT("Filename"));
|
||||||
|
bool saveCompressed = GetBool(wxT("Compress"));
|
||||||
|
bool addToHistory = GetBool(wxT("AddToHistory"));
|
||||||
|
if(fileName == wxEmptyString)
|
||||||
|
return context.proj->SaveAs(saveCompressed);
|
||||||
|
else
|
||||||
|
return context.proj->SaveAs(fileName,saveCompressed,addToHistory);
|
||||||
|
}
|
||||||
|
|
||||||
|
SaveProjectCommand::~SaveProjectCommand()
|
||||||
|
{ }
|
65
src/commands/OpenSaveCommands.h
Normal file
65
src/commands/OpenSaveCommands.h
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/**********************************************************************
|
||||||
|
|
||||||
|
Audacity: A Digital Audio Editor
|
||||||
|
Audacity(R) is copyright (c) 1999-2009 Audacity Team.
|
||||||
|
File License: wxwidgets
|
||||||
|
|
||||||
|
OpenSaveCommands.h
|
||||||
|
Stephen Parry
|
||||||
|
|
||||||
|
******************************************************************//**
|
||||||
|
|
||||||
|
\class OpenProjectCommand
|
||||||
|
\brief Command for opening an Audacity project
|
||||||
|
|
||||||
|
\class SaveProjectCommand
|
||||||
|
\brief Command for saving an Audacity project
|
||||||
|
|
||||||
|
*//*******************************************************************/
|
||||||
|
|
||||||
|
#include "Command.h"
|
||||||
|
#include "CommandType.h"
|
||||||
|
|
||||||
|
// Open
|
||||||
|
|
||||||
|
class OpenProjectCommandType : public CommandType
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual wxString BuildName();
|
||||||
|
virtual void BuildSignature(CommandSignature &signature);
|
||||||
|
virtual Command *Create(CommandOutputTarget *target);
|
||||||
|
};
|
||||||
|
|
||||||
|
class OpenProjectCommand : public CommandImplementation
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
OpenProjectCommand(CommandType &type,
|
||||||
|
CommandOutputTarget *target)
|
||||||
|
: CommandImplementation(type, target)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
virtual ~OpenProjectCommand();
|
||||||
|
virtual bool Apply(CommandExecutionContext context);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Save
|
||||||
|
|
||||||
|
class SaveProjectCommandType : public CommandType
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual wxString BuildName();
|
||||||
|
virtual void BuildSignature(CommandSignature &signature);
|
||||||
|
virtual Command *Create(CommandOutputTarget *target);
|
||||||
|
};
|
||||||
|
|
||||||
|
class SaveProjectCommand : public CommandImplementation
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SaveProjectCommand(CommandType &type,
|
||||||
|
CommandOutputTarget *target)
|
||||||
|
: CommandImplementation(type, target)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
virtual ~SaveProjectCommand();
|
||||||
|
virtual bool Apply(CommandExecutionContext context);
|
||||||
|
};
|
@ -1960,6 +1960,14 @@
|
|||||||
RelativePath="..\..\..\src\commands\MessageCommand.h"
|
RelativePath="..\..\..\src\commands\MessageCommand.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\src\commands\OpenSaveCommands.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\src\commands\OpenSaveCommands.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\..\src\commands\PreferenceCommands.cpp"
|
RelativePath="..\..\..\src\commands\PreferenceCommands.cpp"
|
||||||
>
|
>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user