Update of /cvsroot/audacity/audacity-src/src
In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv31903

Modified Files:
        Menus.cpp AudacityApp.cpp Project.h Project.cpp 
Log Message:
This one definitely got away from me...all of this just to generate a filter 
list!

Index: Project.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/Project.h,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -d -r1.118 -r1.119
--- Project.h   27 May 2007 21:11:30 -0000      1.118
+++ Project.h   27 May 2007 23:10:50 -0000      1.119
@@ -138,7 +138,8 @@
 
    // File I/O
 
-   static void ShowOpenDialog(AudacityProject *proj);
+   static wxArrayString ShowOpenDialog(wxString extra = wxEmptyString);
+   static void OpenFiles(AudacityProject *proj);
    void OpenFile(wxString fileName);
    void Import(wxString fileName);
    void AddImportedTracks(wxString fileName,
@@ -312,8 +313,6 @@
    static bool IsAutoSaveEnabled();
    void DeleteCurrentAutoSaveFile();
    
-   wxString GetImportFilesFilter();
-
    static bool GetCacheBlockFiles();
 
    // Callbacks for backend operations

Index: Project.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/Project.cpp,v
retrieving revision 1.309
retrieving revision 1.310
diff -u -d -r1.309 -r1.310
--- Project.cpp 27 May 2007 21:11:30 -0000      1.309
+++ Project.cpp 27 May 2007 23:10:50 -0000      1.310
@@ -1609,34 +1609,88 @@
 }
 
 // static method, can be called outside of a project
-void AudacityProject::ShowOpenDialog(AudacityProject *proj)
+wxArrayString AudacityProject::ShowOpenDialog(wxString extra)
 {
-   wxString path = gPrefs->Read(wxT("/DefaultOpenPath"),
-                                ::wxGetCwd());
-   // Beware, some compilers let you access mCleanSpeechMode
-   // here, even though it is not valid for a static method call,
-   // so we must go via prefs.
-   bool bCleanSpeechMode;
-   gPrefs->Read(wxT("/Batch/CleanSpeechMode"), &bCleanSpeechMode, false );
-   FileDialog dlog(NULL, _("Select one or more audio files..."),
-                   path, wxT(""),
-                       bCleanSpeechMode ? 
-                      _("Music files (*.wav;*.mp3)|*.wav;*.mp3|WAV files 
(*.wav)|*.wav|MP3 files (*.mp3)|*.mp3")
-                   :
-                   proj->GetImportFilesFilter().c_str(),
+   FormatList l;
+   wxString filter;
+   wxString all = extra.AfterFirst(wxT('|')).BeforeFirst(wxT('|'));
+
+   // Construct the filter
+   wxGetApp().mImporter->GetSupportedImportFormats(&l);
+
+   for (FormatList::Node *n = l.GetFirst(); n; n = n->GetNext()) {
+      Format *f = n->GetData();
+
+      filter += f->formatName + wxT("|");
+      for (size_t i = 0; i < f->formatExtensions.GetCount(); i++) {
+         filter += wxT("*.") + f->formatExtensions[i] + wxT(";");
+         all += wxT("*.") + f->formatExtensions[i] + wxT(";");
+      }
+      filter.RemoveLast(1);
+
+      filter += wxT("|");
+   }
+   all.RemoveLast(1);
+   filter.RemoveLast(1);
+
+   wxString mask = _("All files|*.*|All supported files|") +
+                   all + wxT("|") +
+                   extra + 
+                   filter;
+
+   // Retrieve saved path and type
+   wxString path = gPrefs->Read(wxT("/DefaultOpenPath"),::wxGetCwd());
+   wxString type = 
gPrefs->Read(wxT("/DefaultOpenType"),mask.BeforeFirst(wxT('|')));
+
+   // Convert the type to the filter index
+   int index = mask.First(type + wxT("|"));
+   if (index == wxNOT_FOUND) {
+      index = 0;
+   }
+   else {
+      index = mask.Left(index).Freq(wxT('|')) / 2;
+      if (index < 0) {
+         index = 0;
+      }
+   }
+
+   // Construct and display the file dialog
+   wxArrayString selected;
+
+   FileDialog dlog(NULL,
+                   _("Select one or more audio files..."),
+                   path,
+                   wxT(""),
+                   mask,
                    wxOPEN | wxMULTIPLE);
 
-   int result = dlog.ShowModal();
+   dlog.SetFilterIndex(index);
 
-   if (result != wxID_OK)
-      return;
+   if (dlog.ShowModal() != wxID_OK) {
+      return selected;
+   }
 
-   wxArrayString selectedFiles;
-   unsigned int ff;
+   // Convert the filter index to type and save
+   index = dlog.GetFilterIndex();
+   for (int i = 0; i < index; i++) {
+      mask = mask.AfterFirst(wxT('|')).AfterFirst(wxT('|'));
+   }
+   gPrefs->Write(wxT("/DefaultOpenType"), mask.BeforeFirst(wxT('|')));
 
-   dlog.GetPaths(selectedFiles);
+   // Return the selected files
+   dlog.GetPaths(selected);
+   return selected;
+}
 
-   for(ff=0; ff<selectedFiles.GetCount(); ff++) {
+// static method, can be called outside of a project
+void AudacityProject::OpenFiles(AudacityProject *proj)
+{
+   wxArrayString selectedFiles = ShowOpenDialog(_("Audacity projects|*.aup|"));
+   if (selectedFiles.GetCount() == 0) {
+      return;
+   }
+
+   for (size_t ff = 0; ff < selectedFiles.GetCount(); ff++) {
       wxString fileName = selectedFiles[ff];
       wxFileName newFileName(fileName);
 
@@ -3352,35 +3406,6 @@
           mProgressDialog[mProgressCurrent]->IsShown();
 }
 
-wxString AudacityProject::GetImportFilesFilter()
-{
-   FormatList l;
-   wxString filter;
-   wxString all;
-
-   wxGetApp().mImporter->GetSupportedImportFormats(&l);
-
-   FormatList::Node *n = l.GetFirst();
-   while (n) {
-      Format *f = n->GetData();
-
-      filter += f->formatName + wxT("|");
-      for (size_t i = 0; i < f->formatExtensions.GetCount(); i++) {
-         filter += wxT("*.") + f->formatExtensions[i] + wxT(";");
-         all += wxT("*.") + f->formatExtensions[i] + wxT(";");
-      }
-      filter.RemoveLast(1);
-
-      filter += wxT("|");
-
-      n = n->GetNext();
-   }
-   all.RemoveLast(1);
-   filter.RemoveLast(1);
-
-   return _("All files|*.*|All supported files|") + all + wxT("|") + filter;
-}
-
 bool AudacityProject::GetCacheBlockFiles()
 {  
    bool cacheBlockFiles = false;

Index: Menus.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/Menus.cpp,v
retrieving revision 1.316
retrieving revision 1.317
diff -u -d -r1.316 -r1.317
--- Menus.cpp   27 May 2007 09:31:50 -0000      1.316
+++ Menus.cpp   27 May 2007 23:10:50 -0000      1.317
@@ -2075,7 +2075,7 @@
 
 void AudacityProject::OnOpen()
 {
-   ShowOpenDialog(this);
+   OpenFiles(this);
 }
 
 void AudacityProject::OnClose()
@@ -3507,35 +3507,20 @@
 
 void AudacityProject::OnImport()
 {
-   wxString path = gPrefs->Read(wxT("/DefaultOpenPath"),::wxGetCwd());
-
-   // TODO: Build the list of file types dynamically
-
-   FileDialog dlog(this, _("Select one or more audio files..."),
-                   path, wxT(""),
-                   GetImportFilesFilter(),
-                   wxOPEN | wxMULTIPLE);
-
-   int result = dlog.ShowModal();
-
-   if (result != wxID_OK)
+   wxArrayString selectedFiles = ShowOpenDialog(wxT(""));
+   if (selectedFiles.GetCount() == 0) {
       return;
+   }
 
-   wxArrayString selectedFiles;
-   unsigned int ff;
-
-   dlog.GetPaths(selectedFiles);
-
-   selectedFiles.Sort();
-
-   for(ff=0; ff<selectedFiles.GetCount(); ff++) {
+   for (size_t ff = 0; ff < selectedFiles.GetCount(); ff++) {
       wxString fileName = selectedFiles[ff];
 
-      path =::wxPathOnly(fileName);
+      wxString path = ::wxPathOnly(fileName);
       gPrefs->Write(wxT("/DefaultOpenPath"), path);
       
       Import(fileName);
    }
+
    HandleResize(); // Adjust scrollers for new track sizes.
 }
 

Index: AudacityApp.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/AudacityApp.cpp,v
retrieving revision 1.173
retrieving revision 1.174
diff -u -d -r1.173 -r1.174
--- AudacityApp.cpp     27 May 2007 21:11:30 -0000      1.173
+++ AudacityApp.cpp     27 May 2007 23:10:50 -0000      1.174
@@ -1290,7 +1290,7 @@
 
 
    if(gAudacityProjects.GetCount() == 0)
-      AudacityProject::ShowOpenDialog(NULL);
+      AudacityProject::OpenFiles(NULL);
    else
       event.Skip();
 


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Audacity-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to