]> git.saurik.com Git - wxWidgets.git/commitdiff
filter out bundles/packages when showing the open file dialog (patch 1675784)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 7 Apr 2007 22:25:23 +0000 (22:25 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 7 Apr 2007 22:25:23 +0000 (22:25 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45316 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/mac/carbon/filedlg.cpp

index c845e7ac0a73f11851c2b9562dcdbe4fa0130681..ec922ff21aa337c01f74577d3ff77d55132ae26f 100644 (file)
@@ -273,27 +273,45 @@ pascal Boolean CrossPlatformFilterCallback(
     void *callBackUD,
     NavFilterModes filterMode )
 {
-    bool display = true;
     OpenUserDataRecPtr data = (OpenUserDataRecPtr) callBackUD ;
 
     if (filterMode == kNavFilteringBrowserList)
     {
+        // We allow navigation to all folders. For files, we check against the current
+        // filter string.
+        // However, packages should be dealt with like files and not like folders. So
+        // check if a folder is a package before deciding what to do.
+        FSRef fsref;
         NavFileOrFolderInfo* theInfo = (NavFileOrFolderInfo*) info ;
-        if ( !theInfo->isFolder )
-        {
-            AECoerceDesc (theItem, typeFSRef, theItem);
+        AECoerceDesc (theItem, typeFSRef, theItem);
+        if ( AEGetDescData (theItem, &fsref, sizeof (FSRef)) != noErr)
+            return true;
 
-            FSRef fsref ;
-            if ( AEGetDescData (theItem, &fsref, sizeof (FSRef)) == noErr )
-            {
-                memcpy( &fsref , *theItem->dataHandle , sizeof(FSRef) ) ;
-                wxString file = wxMacFSRefToPath( &fsref ) ;
-                display = CheckFile( file , theInfo->fileAndFolder.fileInfo.finderInfo.fdType , data ) ;
-            }
+        if ( theInfo->isFolder )
+        {
+            // check bundle bit (using Finder Services - used by OS9 on some bundles)
+            FSCatalogInfo catalogInfo;
+            if (FSGetCatalogInfo (&fsref, kFSCatInfoFinderInfo, &catalogInfo, NULL, NULL, NULL) != noErr)
+                return true;
+
+            // Check bundle item (using Launch Services - used by OS-X through info.plist or APP)
+            LSItemInfoRecord lsInfo;
+            if (LSCopyItemInfoForRef(&fsref, kLSRequestBasicFlagsOnly, &lsInfo ) != noErr)
+                return true;
+
+            // If it's not a bundle, then it's a normal folder and it passes our filter
+            FileInfo *fileInfo = (FileInfo *) catalogInfo.finderInfo;
+            if ( !(fileInfo->finderFlags & kHasBundle) &&
+                 !(lsInfo.flags & (kLSItemInfoIsApplication | kLSItemInfoIsPackage)) )
+                return true;
         }
+
+        wxString file = wxMacFSRefToPath( &fsref ) ;
+        return CheckFile( file , theInfo->fileAndFolder.fileInfo.finderInfo.fdType , data ) ;
+
     }
 
-    return display;
+    return true;
 }
 
 int wxFileDialog::ShowModal()