Bug 422511 - "Open with 'TextEditor.app'" Should be "Open with 'TextEditor'"
authorHåkan Waara <hwaara@gmail.com>, Shawn Wilsher <sdwilsh@shawnwilsher.com>
Wed, 03 Sep 2008 12:22:16 -0400
changeset 18739 f96f0b755e14c943c8ec8be0f3125ae663c2e70c
parent 18738 eecb83d9acdcb4a4748b6640cc85f634a2e81912
child 18740 b3201f4a8641fcf49845907af9aa83bf628f31f9
push idunknown
push userunknown
push dateunknown
bugs422511
milestone1.9.1b1pre
Bug 422511 - "Open with 'TextEditor.app'" Should be "Open with 'TextEditor'" This changeset gets an application bundle's name instead of the bundle's file name on OS X. Original patch by HÃ¥kan Waara, updated by Shawn Wilsher. Original patch r=sdwilsh, sr=biesi Updated patch r=hwaara, sr=biesi
toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in
uriloader/exthandler/mac/nsLocalHandlerAppMac.h
uriloader/exthandler/mac/nsLocalHandlerAppMac.mm
uriloader/exthandler/mac/nsMIMEInfoMac.h
uriloader/exthandler/mac/nsMIMEInfoMac.mm
--- a/toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in
+++ b/toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in
@@ -699,17 +699,23 @@ nsUnknownContentTypeDialog.prototype = {
 
       var otherHandler = this.dialogElement("otherHandler");
               
       // Fill application name textbox.
       if (this.chosenApp && this.chosenApp.executable && 
           this.chosenApp.executable.path) {
         otherHandler.setAttribute("path",
                                   this.getPath(this.chosenApp.executable));
+
+#if XP_MACOSX
+        this.chosenApp.executable.QueryInterface(Components.interfaces.nsILocalFileMac);
+        otherHandler.label = this.chosenApp.executable.bundleDisplayName;
+#else
         otherHandler.label = this.chosenApp.executable.leafName;
+#endif
         otherHandler.hidden = false;
       }
 
       var useDefault = this.dialogElement("useSystemDefault");
       var openHandler = this.dialogElement("openHandler");
       openHandler.selectedIndex = 0;
 
       if (this.mLauncher.MIMEInfo.preferredAction == this.nsIMIMEInfo.useSystemDefault) {
@@ -1059,17 +1065,23 @@ nsUnknownContentTypeDialog.prototype = {
           createInstance(Components.interfaces.nsILocalHandlerApp);
         localHandlerApp.executable = fp.file;
         this.chosenApp = localHandlerApp;
         
         // Update dialog.
         var otherHandler = this.dialogElement("otherHandler");
         otherHandler.removeAttribute("hidden");
         otherHandler.setAttribute("path", this.getPath(this.chosenApp.executable));
+#ifdef XP_MACOSX
+        this.chosenApp.executable
+            .QueryInterface(Components.interfaces.nsILocalFileMac);
+        otherHandler.label = this.chosenApp.executable.bundleDisplayName;
+#else
         otherHandler.label = this.chosenApp.executable.leafName;
+#endif
         this.dialogElement("openHandler").selectedIndex = 1;
         this.dialogElement("openHandler").setAttribute("lastSelectedItemID", "otherHandler");
         
         this.dialogElement("mode").selectedItem = this.dialogElement("open");
       }
       else {
         var openHandler = this.dialogElement("openHandler");
         var lastSelectedID = openHandler.getAttribute("lastSelectedItemID");
--- a/uriloader/exthandler/mac/nsLocalHandlerAppMac.h
+++ b/uriloader/exthandler/mac/nsLocalHandlerAppMac.h
@@ -47,13 +47,13 @@ class nsLocalHandlerAppMac : public nsLo
 
     nsLocalHandlerAppMac(const PRUnichar *aName, nsIFile *aExecutable)
       : nsLocalHandlerApp(aName, aExecutable) {} 
 
     nsLocalHandlerAppMac(const nsAString & aName, nsIFile *aExecutable) 
       : nsLocalHandlerApp(aName, aExecutable) {}
     virtual ~nsLocalHandlerAppMac() { }
 
-    NS_IMETHOD LaunchWithURI(nsIURI* aURI,
-                             nsIInterfaceRequestor* aWindowContext);
+    NS_IMETHOD LaunchWithURI(nsIURI* aURI, nsIInterfaceRequestor* aWindowContext);
+    NS_IMETHOD GetName(nsAString& aName);
 };
 
 #endif /*NSLOCALHANDLERAPPMAC_H_*/
--- a/uriloader/exthandler/mac/nsLocalHandlerAppMac.mm
+++ b/uriloader/exthandler/mac/nsLocalHandlerAppMac.mm
@@ -37,16 +37,32 @@
 
 #import <Carbon/Carbon.h>
 
 #include "nsObjCExceptions.h"
 #include "nsLocalHandlerAppMac.h"
 #include "nsILocalFileMac.h"
 #include "nsIURI.h"
 
+// We override this to make sure app bundles display their pretty name (without .app suffix)
+NS_IMETHODIMP nsLocalHandlerAppMac::GetName(nsAString& aName)
+{
+  if (mExecutable) {
+    nsCOMPtr<nsILocalFileMac> macFile = do_QueryInterface(mExecutable);
+    if (macFile) {
+      PRBool isPackage;
+      (void)macFile->IsPackage(&isPackage);
+      if (isPackage)
+        return macFile->GetBundleDisplayName(aName);
+    }
+  }
+
+  return nsLocalHandlerApp::GetName(aName);
+}
+
 /** 
  * mostly copy/pasted from nsMacShellService.cpp (which is in browser/,
  * so we can't depend on it here).  This code probably really wants to live
  * somewhere more central (see bug 389922).
  */
 NS_IMETHODIMP
 nsLocalHandlerAppMac::LaunchWithURI(nsIURI *aURI,
                                     nsIInterfaceRequestor *aWindowContext)
--- a/uriloader/exthandler/mac/nsMIMEInfoMac.h
+++ b/uriloader/exthandler/mac/nsMIMEInfoMac.h
@@ -53,13 +53,15 @@ class nsMIMEInfoMac : public nsMIMEInfoI
 #ifdef DEBUG
     virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile) {
       NS_NOTREACHED("do not call this method, use LaunchWithFile");
       return NS_ERROR_UNEXPECTED;
     }
 #endif
     static NS_HIDDEN_(nsresult) OpenApplicationWithURI(nsIFile *aApplication, 
                                                        const nsCString& aURI);
+                                                       
+    NS_IMETHOD GetDefaultDescription(nsAString& aDefaultDescription);
     
 };
 
 
 #endif
--- a/uriloader/exthandler/mac/nsMIMEInfoMac.mm
+++ b/uriloader/exthandler/mac/nsMIMEInfoMac.mm
@@ -43,16 +43,32 @@
 #import <Carbon/Carbon.h>
 
 #include "nsObjCExceptions.h"
 #include "nsMIMEInfoMac.h"
 #include "nsILocalFileMac.h"
 #include "nsIFileURL.h"
 #include "nsIInternetConfigService.h"
 
+// We override this to make sure app bundles display their pretty name (without .app suffix)
+NS_IMETHODIMP nsMIMEInfoMac::GetDefaultDescription(nsAString& aDefaultDescription)
+{
+  if (mDefaultApplication) {
+    nsCOMPtr<nsILocalFileMac> macFile = do_QueryInterface(mDefaultApplication);
+    if (macFile) {
+      PRBool isPackage;
+      (void)macFile->IsPackage(&isPackage);
+      if (isPackage)
+        return macFile->GetBundleDisplayName(aDefaultDescription);
+    }
+  }
+
+  return nsMIMEInfoImpl::GetDefaultDescription(aDefaultDescription);
+}
+
 NS_IMETHODIMP
 nsMIMEInfoMac::LaunchWithFile(nsIFile *aFile)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   nsCOMPtr<nsIFile> application;
   nsresult rv;