Update of /cvsroot/audacity/audacity-src/src
In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv20458/src

Modified Files:
        Project.cpp Project.h 
Log Message:
A very involved solution to a missing | character which exposed a number of 
design weaknesses and a documentation issue:
* Revise the ShowOpenDialog() method too have two arguments not one formatted 
string argument
* Document ditto
* Change all call sites to new interface
* Change other uses of the same translation string to avoid both the same bug 
in future and creating a new translation string (this does involve a string 
change however).
Original idea by Ed Musgrove, implementation by RA.


Index: Project.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/Project.h,v
retrieving revision 1.175
retrieving revision 1.176
diff -u -d -r1.175 -r1.176
--- Project.h   26 Dec 2009 23:32:55 -0000      1.175
+++ Project.h   30 Dec 2009 15:56:03 -0000      1.176
@@ -161,7 +161,35 @@
 
    // File I/O
 
-   static wxArrayString ShowOpenDialog(wxString extra = wxEmptyString);
+   /** @brief Show an open dialogue for opening audio files, and possibly other
+    * sorts of files.
+    *
+    * The file type filter will automatically contain:
+    * - "All files" with any extension or none,
+    * - "All supported files" based on the file formats supported in this
+    *   build of Audacity,
+    * - All of the individual formats specified by the importer plug-ins which
+    *   are built into this build of Audacity, each with the relevant file
+    *   extensions for that format.
+    * The dialogue will start in the DefaultOpenPath directory read from the
+    * preferences, failing that the working directory. The file format filter
+    * will be set to the DefaultOpenType from the preferences, failing that
+    * the first format specified in the dialogue. These two parameters will
+    * be saved to the preferences once the user has chosen a file to open.
+    * @param extraformat Specify the name of an additional format to allow
+    * opening in this dialogue. This string is free-form, but should be short
+    * enough to fit in the file dialogue filter drop-down. It should be
+    * translated.
+    * @param extrafilter Specify the file extension(s) for the additional 
format
+    * specified by extraformat. The patterns must include the wildcard (e.g. 
+    * "*.aup" not "aup" or ".aup"), separate multiple patters with a semicolon,
+    * e.g. "*.aup;*.AUP" because patterns are case-sensitive. Do not add a
+    * trailing semicolon to the string. This string should not be translated
+    * @return Array of file paths which the user selected to open (multiple
+    * selections allowed).
+    */
+   static wxArrayString ShowOpenDialog(wxString extraformat = wxEmptyString,
+         wxString extrafilter = wxEmptyString);
    static void OpenFiles(AudacityProject *proj);
    void OpenFile(wxString fileName, bool addtohistory = true);
    bool WarnOfLegacyFile( );

Index: Project.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/Project.cpp,v
retrieving revision 1.479
retrieving revision 1.480
diff -u -d -r1.479 -r1.480
--- Project.cpp 26 Dec 2009 23:32:54 -0000      1.479
+++ Project.cpp 30 Dec 2009 15:56:03 -0000      1.480
@@ -2038,15 +2038,19 @@
 }
 
 // static method, can be called outside of a project
-wxArrayString AudacityProject::ShowOpenDialog(wxString extra)
+wxArrayString AudacityProject::ShowOpenDialog(wxString extraformat, wxString 
extrafilter)
 {
    FormatList l;
-   wxString filter;
-   wxString all;
+   wxString filter;  ///< List of file format names and extensions, separated
+   /// by | characters between _formats_ and extensions for each _format_, i.e.
+   /// format1name | *.ext | format2name | *.ex1;*.ex2
+   wxString all;  ///< One long list of all supported file extensions,
+   /// semicolon separated
 
-   if (extra != wxEmptyString)
-   {
-      all = extra.AfterFirst(wxT('|')).BeforeFirst(wxT('|')) + wxT(';');
+   if (extraformat != wxEmptyString)
+   {  // additional format specified
+      all = extrafilter + wxT(';');
+      // add it to the "all supported files" filter string
    }
 
    // Construct the filter
@@ -2054,10 +2058,14 @@
    wxGetApp().mImporter->GetSupportedImportFormats(&l);
 
    for (FormatList::compatibility_iterator n = l.GetFirst(); n; n = 
n->GetNext()) {
+      /* this loop runs once per supported _format_ */
       Format *f = n->GetData();
 
       wxString newfilter = f->formatName + wxT("|");
+      // bung format name into string plus | separator
       for (size_t i = 0; i < f->formatExtensions.GetCount(); i++) {
+         /* this loop runs once per valid _file extension_ for file containing
+          * the current _format_ */
          if (!newfilter.Contains(wxT("*.") + f->formatExtensions[i] + 
wxT(";")))
             newfilter += wxT("*.") + f->formatExtensions[i] + wxT(";");
          if (!all.Contains(wxT("*.") + f->formatExtensions[i] + wxT(";")))
@@ -2080,9 +2088,13 @@
 #endif
 
    wxString mask = _("All files|*|All supported files|") +
-                   all + wxT("|") +
-                   extra + 
-                   filter;
+                   all + wxT("|"); // "all" and "all supported" entries
+   if (extraformat != wxEmptyString)
+   {  // append caller-defined format if supplied  
+      mask +=  extraformat + wxT("|") + extrafilter + wxT("|");
+   }
+   mask += filter;   // put the names and extensions of all the importer 
formats
+   // we built up earlier into the mask
 
    // Retrieve saved path and type
    wxString path = gPrefs->Read(wxT("/DefaultOpenPath"),::wxGetCwd());
@@ -2137,7 +2149,10 @@
 // static method, can be called outside of a project
 void AudacityProject::OpenFiles(AudacityProject *proj)
 {
-   wxArrayString selectedFiles = ShowOpenDialog(_("Audacity projects|*.aup|"));
+   /* i18n-hint: This string is a label in the file type filter in the open 
+    * / save dialogues, for the option that only shows project files created
+    * with Audacity. */
+   wxArrayString selectedFiles = ShowOpenDialog(_("Audacity projects"), 
wxT("*.aup"));
    if (selectedFiles.GetCount() == 0) {
       return;
    }
@@ -3375,8 +3390,8 @@
                            _("You are saving an Audacity project file 
(.aup).\n\nSaving a project creates a file that only Audacity can open.\n\nTo 
save an audio file for other programs, use one of the \"File > Export\" 
commands.\n"));
 
       fName = FileSelector(_("Save Project As..."),
-                    path, fName, wxT(""),
-                    _("Audacity projects (*.aup)|*.aup"),
+         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


------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Audacity-cvs mailing list
Audacity-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to