1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-15 15:49:36 +02:00

Round 7 of wx3 changes

I believe the FileDialog is now complete and consistent across
all 3 platforms.
This commit is contained in:
Leland Lucius 2015-07-16 01:12:09 -05:00
parent 553308fc29
commit 805f0e29d1
9 changed files with 150 additions and 79 deletions

View File

@ -41,20 +41,23 @@ void FileDialogBase::CreateUserPane(wxWindow *parent)
}
}
//----------------------------------------------------------------------------
// FileDialog convenience functions
//----------------------------------------------------------------------------
//
// Copied from wx 3.0.2 and modified to support additional features
//
/////////////////////////////////////////////////////////////////////////////
// Name: src/common/fldlgcmn.cpp
// Purpose: wxFileDialog common functions
// Author: John Labenski
// Modified by: Leland Lucius for use with Audacity
// Modified by: Leland Lucius
// Created: 14.06.03 (extracted from src/*/filedlg.cpp)
// Copyright: (c) Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
// FileDialog convenience functions
//----------------------------------------------------------------------------
wxString FileSelector(const wxString& title,
const wxString& defaultDir,
const wxString& defaultFileName,

View File

@ -21,8 +21,6 @@ custom controls.
#include <wx/filectrl.h>
#include <wx/filedlg.h>
#define FD_NO_ADD_EXTENSION 0x0400
class FileDialogBase : public wxFileDialogBase
{
public:
@ -53,11 +51,14 @@ protected:
#error Unknown implementation
#endif
//
// Copied from wx 3.0.2 and modified to support additional features
//
/////////////////////////////////////////////////////////////////////////////
// Name: wx/filedlg.h
// Purpose: wxFileDialog base header
// Author: Robert Roebling
// Modified by: Leland Lucius for use by Audacity
// Modified by: Leland Lucius
// Created: 8/17/99
// Copyright: (c) Robert Roebling
// Licence: wxWindows licence

View File

@ -1,19 +1,18 @@
//
// Copied from wx 3.0.2 and modified to support additional features
//
/////////////////////////////////////////////////////////////////////////////
// Name: wx/osx/filedlg.h
// Purpose: wxFileDialog class
// Author: Stefan Csomor
// Modified by:
// Modified by: Leland Lucius
// Created: 1998-01-01
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _FILEDIALOG_H_
#define _FILEDIALOG_H_
#ifndef _MAC_FILEDIALOG_H_
#define _MAC_FILEDIALOG_H_
#include <wx/choice.h>
@ -71,8 +70,10 @@ public:
// implementation only
#if wxOSX_USE_COCOA
void DoViewResized(void* object);
void DoSendFolderChangedEvent(void* panel, const wxString& path);
void DoSendSelectionChangedEvent(void* panel);
wxString DoCaptureFilename(void* panel, const wxString& name);
#endif
protected:
@ -96,6 +97,7 @@ protected:
wxArrayString m_currentExtensions;
WX_NSObject m_delegate;
WX_NSObject m_sheetDelegate;
wxString m_noOverwritePromptFilename;
#endif
private:
@ -103,4 +105,4 @@ private:
void Init();
};
#endif // _FILEDIALOG_H_
#endif

View File

@ -1,12 +1,11 @@
//
// Copied from wxWidgets 3.0.2 and modified to support additional features
//
/////////////////////////////////////////////////////////////////////////////
// Name: src/cocoa/filedlg.mm
// Purpose: wxFileDialog for wxCocoa
// Author: Ryan Norton
// Modified by:
// Modified by: Leland Lucius
// Created: 2004-10-02
// Copyright: (c) Ryan Norton
// Licence: wxWindows licence
@ -55,13 +54,19 @@
- (FileDialog*) fileDialog;
- (void) setFileDialog:(FileDialog*) dialog;
- (BOOL)panel:(id)sender validateURL:(NSURL *)url error:(NSError **)outError AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
- (void)panel:(id)sender didChangeToDirectoryURL:(NSURL *)url AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
- (void)panelSelectionDidChange:(id)sender AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER;
- (NSString *)panel:(id)sender userEnteredFilename:(NSString *)filename confirmed:(BOOL)okFlag;
- (void)viewResized:(NSNotification *)notification;
@end
@implementation OSPanelDelegate
- (void)viewResized:(NSNotification *)notification
{
_dialog->DoViewResized([notification object]);
}
- (id) init
{
@ -84,12 +89,26 @@
{
wxString path = wxCFStringRef::AsStringWithNormalizationFormC( [url path] );
_dialog->DoSendFolderChangedEvent(sender, path);
_dialog->DoSendFolderChangedEvent(sender, path);
}
- (void)panelSelectionDidChange:(id)sender AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
{
_dialog->DoSendSelectionChangedEvent(sender);
_dialog->DoSendSelectionChangedEvent(sender);
}
- (NSString *)panel:(id)sender userEnteredFilename:(NSString *)filename confirmed:(BOOL)okFlag;
{
if (okFlag == YES)
{
wxString name = wxCFStringRef::AsStringWithNormalizationFormC( filename );
wxCFStringRef cfname( _dialog->DoCaptureFilename( sender, name ) );
return [[NSString alloc] initWithString:cfname.AsNSString()];
}
return filename;
}
@end
@ -257,6 +276,11 @@ void FileDialog::ShowWindowModal()
wxCFStringRef dir( m_dir );
wxCFStringRef file( m_fileName );
m_noOverwritePromptFilename = wxEmptyString;
m_path = wxEmptyString;
m_fileNames.Clear();
m_paths.Clear();
wxNonOwnedWindow* parentWindow = NULL;
m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
@ -330,6 +354,11 @@ void FileDialog::OnFilterSelected( wxCommandEvent &WXUNUSED(event) )
DoOnFilterSelected( m_filterChoice->GetSelection() );
}
void FileDialog::DoViewResized(void* object)
{
m_filterPanel->Layout();
}
void FileDialog::DoSendFolderChangedEvent(void* panel, const wxString & path)
{
m_dir = wxPathOnly( path );
@ -382,7 +411,33 @@ void FileDialog::DoSendSelectionChangedEvent(void* panel)
GetEventHandler()->ProcessEvent( event );
}
wxString FileDialog::DoCaptureFilename(void* panel, const wxString & name)
{
if ( HasFlag( wxFD_SAVE ) )
{
if ( !HasFlag(wxFD_OVERWRITE_PROMPT) )
{
NSSavePanel* sPanel = (NSSavePanel*) panel;
NSString* dir = [[sPanel directoryURL] path];
wxFileName fn;
fn.SetPath(wxCFStringRef::AsStringWithNormalizationFormC( dir ));
fn.SetFullName(name);
m_currentlySelectedFilename = fn.GetFullPath();
fn.SetName(wxT("NoOverwritePrompt"));
fn.AssignTempFileName(fn.GetFullPath());
m_noOverwritePromptFilename = fn.GetFullPath();
return fn.GetFullName();
}
}
return name;
}
void FileDialog::SetupExtraControls(WXWindow nativeWindow)
{
NSSavePanel* panel = (NSSavePanel*) nativeWindow;
@ -401,13 +456,21 @@ void FileDialog::SetupExtraControls(WXWindow nativeWindow)
m_filterPanel = NULL;
m_filterChoice = NULL;
NSView* accView = nil;
if ( m_useFileTypeFilter || HasUserPaneCreator() )
{
wxBoxSizer *verticalSizer = new wxBoxSizer( wxVERTICAL );
m_filterPanel = new wxPanel( this, wxID_ANY );
accView = m_filterPanel->GetHandle();
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:del
selector:@selector(viewResized:)
name:NSViewFrameDidChangeNotification
object:accView];
if ( m_useFileTypeFilter )
{
wxBoxSizer *horizontalSizer = new wxBoxSizer( wxHORIZONTAL );
@ -424,31 +487,37 @@ void FileDialog::SetupExtraControls(WXWindow nativeWindow)
}
m_filterChoice->Connect( wxEVT_CHOICE, wxCommandEventHandler( FileDialog::OnFilterSelected ), NULL, this );
horizontalSizer->Add( m_filterChoice, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
horizontalSizer->Add( m_filterChoice, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
verticalSizer->Add( horizontalSizer, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5 );
}
if ( HasUserPaneCreator() )
{
wxPanel *extrapanel = new wxPanel( m_filterPanel, wxID_ANY );
CreateUserPane( extrapanel );
wxPanel *userpane = new wxPanel( m_filterPanel, wxID_ANY );
CreateUserPane( userpane );
wxBoxSizer *horizontalSizer = new wxBoxSizer( wxHORIZONTAL );
horizontalSizer->Add( extrapanel, 1, wxEXPAND, 5 );
verticalSizer->Add( horizontalSizer, 1, wxEXPAND|wxALL, 5 );
horizontalSizer->Add( userpane, 1, wxEXPAND, 0 );
verticalSizer->Add( horizontalSizer, 1, wxEXPAND, 0 );
}
m_filterPanel->SetSizer( verticalSizer );
m_filterPanel->Layout();
verticalSizer->SetSizeHints( m_filterPanel );
accView = m_filterPanel->GetHandle();
NSSize ss = [[accView superview] frame].size;
wxSize ws = m_filterPanel->GetBestSize();
ws.SetWidth( wxMax( (wxCoord) ss.width, ws.GetWidth() ) );
m_filterPanel->SetSize(ws);
}
if ( accView != nil )
{
[accView removeFromSuperview];
[panel setAccessoryView:accView];
[accView setAutoresizingMask:NSViewWidthSizable];
}
}
@ -465,6 +534,7 @@ int FileDialog::ShowModal()
wxCFStringRef dir( m_dir );
wxCFStringRef file( m_fileName );
m_noOverwritePromptFilename = wxEmptyString;
m_path = wxEmptyString;
m_fileNames.Clear();
m_paths.Clear();
@ -600,6 +670,15 @@ void FileDialog::ModalFinishedCallback(void* panel, int returnCode)
result = wxID_OK;
m_path = wxCFStringRef::AsStringWithNormalizationFormC([sPanel filename]);
if (!HasFlag(wxFD_OVERWRITE_PROMPT))
{
wxASSERT(!m_noOverwritePromptFilename.IsEmpty());
if (!m_noOverwritePromptFilename.IsEmpty())
{
wxRemoveFile(m_noOverwritePromptFilename);
m_path = m_currentlySelectedFilename;
}
}
m_fileName = wxFileNameFromPath(m_path);
m_dir = wxPathOnly( m_path );
if (m_filterChoice)

View File

@ -1068,22 +1068,20 @@ int FileDialog::ShowModal()
//=== Adding the correct extension >>=================================
m_filterIndex = (int)of.nFilterIndex - 1;
if (HasFdFlag(FD_NO_ADD_EXTENSION))
if ( !of.nFileExtension ||
(of.nFileExtension && fileNameBuffer[of.nFileExtension] == wxT('\0')) )
{
if ( !of.nFileExtension ||
(of.nFileExtension && fileNameBuffer[of.nFileExtension] == wxT('\0')) )
{
// User has typed a filename without an extension:
const wxChar* extension = filterBuffer;
int maxFilter = (int)(of.nFilterIndex*2L) - 1;
for( int i = 0; i < maxFilter; i++ ) // get extension
extension = extension + wxStrlen( extension ) + 1;
m_fileName = AppendExtension(fileNameBuffer, extension);
wxStrlcpy(fileNameBuffer, m_fileName.c_str(), WXSIZEOF(fileNameBuffer));
}
// User has typed a filename without an extension:
const wxChar* extension = filterBuffer;
int maxFilter = (int)(of.nFilterIndex*2L) - 1;
for( int i = 0; i < maxFilter; i++ ) // get extension
extension = extension + wxStrlen( extension ) + 1;
m_fileName = AppendExtension(fileNameBuffer, extension);
wxStrlcpy(fileNameBuffer, m_fileName.c_str(), WXSIZEOF(fileNameBuffer));
}
m_path = fileNameBuffer;
m_fileName = wxFileNameFromPath(fileNameBuffer);
m_fileNames.Add(m_fileName);

View File

@ -1280,7 +1280,6 @@
EDFCEBA618894B2A00C98E51 /* RealFFTf48x.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EDFCEBA218894B2A00C98E51 /* RealFFTf48x.cpp */; };
EDFCEBA718894B2A00C98E51 /* SseMathFuncs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EDFCEBA418894B2A00C98E51 /* SseMathFuncs.cpp */; };
EDFCEBB518894B9E00C98E51 /* Equalization48x.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EDFCEBB318894B9E00C98E51 /* Equalization48x.cpp */; };
EEFF576E109AB4E20032EDFE /* CaptureEvents.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EEFF576C109AB4E10032EDFE /* CaptureEvents.cpp */; };
/* End PBXBuildFile section */
/* Begin PBXBuildRule section */
@ -1772,7 +1771,6 @@
1790AFE809883BFD008A330A /* BlockFile.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 3; lastKnownFileType = sourcecode.cpp.cpp; path = BlockFile.cpp; sourceTree = "<group>"; tabWidth = 3; };
1790AFE909883BFD008A330A /* BlockFile.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 3; lastKnownFileType = sourcecode.c.h; path = BlockFile.h; sourceTree = "<group>"; tabWidth = 3; };
1790AFF009883BFD008A330A /* configtemplate.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 3; lastKnownFileType = sourcecode.c.h; path = configtemplate.h; sourceTree = "<group>"; tabWidth = 3; };
1790AFF109883BFD008A330A /* configunix.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 3; lastKnownFileType = sourcecode.c.h; path = configunix.h; sourceTree = "<group>"; tabWidth = 3; };
1790AFF409883BFD008A330A /* CrossFade.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 3; lastKnownFileType = sourcecode.cpp.cpp; path = CrossFade.cpp; sourceTree = "<group>"; tabWidth = 3; };
1790AFF509883BFD008A330A /* CrossFade.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 3; lastKnownFileType = sourcecode.c.h; path = CrossFade.h; sourceTree = "<group>"; tabWidth = 3; };
1790AFF709883BFD008A330A /* DirManager.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 3; lastKnownFileType = sourcecode.cpp.cpp; path = DirManager.cpp; sourceTree = "<group>"; tabWidth = 3; usesTabs = 0; };
@ -3090,8 +3088,6 @@
EDFCEBA518894B2A00C98E51 /* SseMathFuncs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SseMathFuncs.h; sourceTree = "<group>"; };
EDFCEBB318894B9E00C98E51 /* Equalization48x.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Equalization48x.cpp; sourceTree = "<group>"; };
EDFCEBB418894B9E00C98E51 /* Equalization48x.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Equalization48x.h; sourceTree = "<group>"; };
EEFF576C109AB4E10032EDFE /* CaptureEvents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 3; lastKnownFileType = sourcecode.cpp.cpp; name = CaptureEvents.cpp; path = ../src/CaptureEvents.cpp; sourceTree = SOURCE_ROOT; tabWidth = 3; };
EEFF576D109AB4E20032EDFE /* CaptureEvents.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 3; lastKnownFileType = sourcecode.c.h; name = CaptureEvents.h; path = ../src/CaptureEvents.h; sourceTree = SOURCE_ROOT; tabWidth = 3; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -3846,7 +3842,6 @@
1790AFE809883BFD008A330A /* BlockFile.cpp */,
1790AFE909883BFD008A330A /* BlockFile.h */,
1790AFF009883BFD008A330A /* configtemplate.h */,
1790AFF109883BFD008A330A /* configunix.h */,
1790AFF409883BFD008A330A /* CrossFade.cpp */,
1790AFF509883BFD008A330A /* CrossFade.h */,
2849B4600A7444BE00ECF12D /* Dependencies.cpp */,
@ -4223,8 +4218,6 @@
children = (
1790B0B809883BFD008A330A /* BatchPrefs.cpp */,
1790B0B909883BFD008A330A /* BatchPrefs.h */,
EEFF576C109AB4E10032EDFE /* CaptureEvents.cpp */,
EEFF576D109AB4E20032EDFE /* CaptureEvents.h */,
284B278E0FC66863005EAC96 /* DevicePrefs.cpp */,
284B278F0FC66863005EAC96 /* DevicePrefs.h */,
1790B0BB09883BFD008A330A /* DirectoriesPrefs.cpp */,
@ -7534,7 +7527,6 @@
28DE72AF10388583007E18EC /* SetTrackInfoCommand.cpp in Sources */,
28DE72B2103885AA007E18EC /* TimeWarper.cpp in Sources */,
EDD94EDB103CB520000873F1 /* ImportExportCommands.cpp in Sources */,
EEFF576E109AB4E20032EDFE /* CaptureEvents.cpp in Sources */,
284249EE10D337CE004330A6 /* GetProjectInfoCommand.cpp in Sources */,
284249EF10D337CE004330A6 /* SetProjectInfoCommand.cpp in Sources */,
18CE3C951145511200282C50 /* ODDecodeFFmpegTask.cpp in Sources */,

View File

@ -3793,16 +3793,12 @@ bool AudacityProject::SaveAs(const wxString & newFileName, bool bWantSaveCompres
bool AudacityProject::SaveAs(bool bWantSaveCompressed /*= false*/)
{
wxString path = wxPathOnly(mFileName);
wxString fName;
wxString ext = wxT(".aup");
fName = GetName().Len()? GetName() + ext : wxString(wxT(""));
wxFileName filename(mFileName);
wxString sProjName = this->GetName();
if (sProjName.IsEmpty())
sProjName = _("<untitled>");
wxString sDialogTitle;
if (bWantSaveCompressed)
{
@ -3831,29 +3827,29 @@ For an audio file that will open in other apps, use 'Export'.\n"),
sDialogTitle.Printf(_("Save Project \"%s\" As..."), sProjName.c_str());
}
fName = FileSelector(
sDialogTitle,
path, fName, wxT(""),
_("Audacity projects") + static_cast<wxString>(wxT(" (*.aup)|*.aup")),
// JKC: I removed 'wxFD_OVERWRITE_PROMPT' because we are checking
// for overwrite ourselves later, and we disallow it.
// We disallow overwrite because we would have to delete the many
// smaller files too, or prompt to move them.
wxFD_SAVE | wxRESIZE_BORDER | FD_NO_ADD_EXTENSION, this);
// JKC: I removed 'wxFD_OVERWRITE_PROMPT' because we are checking
// for overwrite ourselves later, and we disallow it.
// We disallow overwrite because we would have to delete the many
// smaller files too, or prompt to move them.
wxString fName = FileSelector(sDialogTitle,
filename.GetPath(),
filename.GetFullName(),
wxT("aup"),
_("Audacity projects") + wxT(" (*.aup)|*.aup"),
wxFD_SAVE | wxRESIZE_BORDER,
this);
if (fName == wxT(""))
return false;
size_t len = fName.Len();
if (len > 4 && fName.Mid(len - 4) == wxT(".aup"))
fName = fName.Mid(0, len - 4);
wxString oldFileName = mFileName;
filename = fName;
filename.SetExt(wxT("aup"));
fName = filename.GetFullPath();
//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!=fName+ext && wxFileExists(fName+ext)) {
if (mFileName != fName && filename.FileExists()) {
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."),
@ -3863,7 +3859,8 @@ For an audio file that will open in other apps, use 'Export'.\n"),
return false;
}
mFileName = fName + ext;
wxString oldFileName = mFileName;
mFileName = fName;
SetProjectTitle();
bool success = Save(false, true, bWantSaveCompressed);

View File

@ -564,7 +564,7 @@ bool Exporter::GetFilename()
mFilename.GetPath(),
mFilename.GetFullName(),
maskString,
wxFD_SAVE | wxRESIZE_BORDER | FD_NO_ADD_EXTENSION);
wxFD_SAVE | wxRESIZE_BORDER);
mDialog = &fd;
mDialog->PushEventHandler(this);
@ -580,6 +580,10 @@ bool Exporter::GetFilename()
}
mFilename = fd.GetPath();
if (mFilename == wxT("")) {
return false;
}
mFormat = fd.GetFilterIndex();
mFilterIndex = fd.GetFilterIndex();
@ -597,10 +601,6 @@ bool Exporter::GetFilename()
}
}
if (mFilename == wxT("")) {
return false;
}
wxString ext = mFilename.GetExt();
wxString defext = mPlugins[mFormat]->GetExtension(mSubFormat).Lower();

View File

@ -27,7 +27,6 @@ class DirManager;
class WaveTrack;
class TrackList;
class MixerSpec;
class FileDialog;
class TimeTrack;
class Mixer;