diff --git a/src/Project.cpp b/src/Project.cpp
index 47ee3d310..df093f7eb 100644
--- a/src/Project.cpp
+++ b/src/Project.cpp
@@ -3551,6 +3551,41 @@ bool AudacityProject::Import(wxString fileName, WaveTrackArray* pTrackArray /*=
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*/)
{
wxString path = wxPathOnly(mFileName);
diff --git a/src/Project.h b/src/Project.h
index 5878b8f44..1b36b78a9 100644
--- a/src/Project.h
+++ b/src/Project.h
@@ -203,6 +203,7 @@ class AUDACITY_DLL_API AudacityProject: public wxFrame,
void UnlockAllBlocks();
bool Save(bool overwrite = true, bool fromSaveAs = false, bool bWantSaveCompressed = false);
bool SaveAs(bool bWantSaveCompressed = false);
+ bool SaveAs(const wxString newFileName, bool bWantSaveCompressed = false, bool addToHistory = true);
#ifdef USE_LIBVORBIS
bool SaveCompressedWaveTracks(const wxString strProjectPathName); // full path for aup except extension
#endif
diff --git a/src/commands/CommandDirectory.cpp b/src/commands/CommandDirectory.cpp
index f418f3e08..f853eb99b 100644
--- a/src/commands/CommandDirectory.cpp
+++ b/src/commands/CommandDirectory.cpp
@@ -30,6 +30,7 @@
#include "SetProjectInfoCommand.h"
#include "PreferenceCommands.h"
#include "ImportExportCommands.h"
+#include "OpenSaveCommands.h"
CommandDirectory *CommandDirectory::mInstance = NULL;
@@ -58,6 +59,8 @@ CommandDirectory::CommandDirectory()
AddCommand(new GetPreferenceCommandType());
AddCommand(new ImportCommandType());
AddCommand(new ExportCommandType());
+ AddCommand(new OpenProjectCommandType());
+ AddCommand(new SaveProjectCommandType());
}
CommandDirectory::~CommandDirectory()
diff --git a/src/commands/OpenSaveCommands.cpp b/src/commands/OpenSaveCommands.cpp
new file mode 100644
index 000000000..2942f4209
--- /dev/null
+++ b/src/commands/OpenSaveCommands.cpp
@@ -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()
+{ }
diff --git a/src/commands/OpenSaveCommands.h b/src/commands/OpenSaveCommands.h
new file mode 100644
index 000000000..0136b22b8
--- /dev/null
+++ b/src/commands/OpenSaveCommands.h
@@ -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);
+};
diff --git a/win/Projects/Audacity/Audacity.vcproj b/win/Projects/Audacity/Audacity.vcproj
index b36e84d13..1889da939 100644
--- a/win/Projects/Audacity/Audacity.vcproj
+++ b/win/Projects/Audacity/Audacity.vcproj
@@ -1960,6 +1960,14 @@
RelativePath="..\..\..\src\commands\MessageCommand.h"
>
+
+
+
+