Localizing Application (main) Menu? - cocoa

I'm porting a UNIX application which uses the Qt framework (Qt, not QuickTime) to Mac/Cocoa. Life is good, generally. Qt has a Cocoa implementation, so with some Objective-C++, I've gotten lots of Mac-specific bits working.
I can't get the main menu (i.e., the Application menu) to translate. It's set using:
[NSApp setMainMenu:menu];
I've got my en.lproj, ja.lproj, fr.lproj, etc. folders set up, and they have InfoPlist.strings files. Qt handles the internal localization of application-specific menus. But if I switch languages, I still have "Quit Avogadro".
I've read through as much documentation in the Mac Dev Center as possible, but can't find an answer.
I know that strings in the mainMenu are handled by Cocoa -- they're not localized in any Apple application. Any ideas on the magic trigger? Any ideas for where to look?
Thanks in advance!

I wanted to add some information to this, in case someone else is looking to do this. I was also trying to modify the application main menu and I was attempting to set it in the awakeFromNib method. This never worked because according to this thread we need to modify the application main menu AFTER the menu has been set. Otherwise, the application will always use the title found in its Info.plist. So, this means that if you ever change your application's name, you never have to update your application's MainMenu.nib.

It turns out that this was a Qt bug: https://bugreports.qt-project.org//browse/QTBUG-4463
It's fixed in Qt 4.7 and later

Related

Parenting a Qt application to another application

This is a follow up to an outstanding question, the solution to which appears to be that I have to make my Qt application the child of another application, specifically the active window that has input focus. I need to do this so that my Qt application automatically has input focus, without the user having to first click on it. (This is necessary because the Qt application is launched by a background process.)
I am aware of QWinWidget -- "a Qt widget that can be child of a native Win32 widget". Unfortunately, my application is based on QMainWindow and there is no obvious way to make it derive from QWinWidget.
The solution to which appears to be that I have to make my Qt application the child of another application, specifically the active window that has input focus...
Similar Win32 solutions where the other process app captures some window inside own canvas are usually driven by SetParent API call. Here is one. It works for me with the other process rendering within Qt widget but you need to make it the other way around. How do you get that Qt window handle? Well, for me QWidget::winId() is working even in Qt 5.3 but I lately stumbled upon discussion and a bit confused whether it always works or not. Anyway, you need to get an active window in your Qt app as well before you get its winId() which supposed to be window handle.
P.S. Olumide, please dismiss my initial comment. I thought, the other way around, what app parents what window and it turns out non-Qt takes Qt.

Add custom menu items to the Finder context menu

How do I add custom menu items to the context menu for files in Finder?
Unfortunately, most of the information out on the Internet and on Stack Overflow doesn't work in 10.6 or are too limited. Automator, for example, doesn't allow you to create items dynamically or create submenus.
I know it's still possible to do this sort of thing because Dropbox and FolderGlance both do similar things. Does anyone know how they implemented this?
Thanks.
For what it's worth, Dropbox now uses mach_star for code injection. Obviously this is a fragile solution. If you look through their version history, many of their updates are to fix finder integration.
In macOS 10.10+, Finder Sync Extensions can be used to add items to the Finder context menu. This is how modern versions of Dropbox and similar apps customize the right-click menu.
For those just seeking to use the functionality, not develop their own app extension, I've released a Mac app that allows for arbitrary customization of a Finder Sync Extension:
Service Station - Mac App Store
I downloaded FolderGlance and it appears to use an osax (Scripting Addition) bundle to inject code into the Finder process. This is definitely fragile and unsupported.
As far as I am aware the only legit way to add items to the Finder contextual menu is to create a Service, but that doesn't solve your problem.
Up to to the OS X 10.9.x only injecting code to Finder process via mach_inject was a solution (and even Dropbox did that).
However since 10.10 there are Finder plugins, which can customize context menus, add buttons to Toolbar and put overlays over file icons.
They used CFPlugIn to add their menu items.
More on it here:
http://developer.apple.com/library/ios/#documentation/CoreFoundation/Reference/CFPlugInRef/Reference/reference.html

Eclipse RCP OS-X: Either remove Preferences and About in Menubar or get notification

I'm developing an Eclipse RCP based application, which runs fine under OS-X and Windows.
Under OS-X I've run into the following Problem:
In the Menubar the first Menu "ApplicationName" has the default entries "About ApplicationName" and "Preferences".
I want to either grey these two out, remove them completely, or if this is not possible add a handle to get notified if they are clicked.
Thanks for help
See this SWT snippet (assuming you're using Cocoa). For Carbon, use this one.
In the new Cocoa API, it looks like you can do anything you like to the system menu items. I've only used the Carbon API, which is more of an unsupported hack.

How to hide an application based on the NetBeans Platform?

I'm not referring to a GUI-less application. I'm trying to have an application based on the NetBeans platform as a System Tray application. I was able to do the System Tray part quite easy but I'm having issues trying to figure out how to Hide/Show the GUI. I'll keep looking in the API meanwhile.
Any ideas?
WindowManager.getDefault().getMainWindow().setVisible(true/false) should work to hide and show the entire GUI, unless it has multiple windows (pure Swing Frame.getFrames() should give you all JFrame based windows, if that helps).
Not sure if that will solve the problem if you want the main window hidden on startup (but if it is a very simple UI, as is true of many tray apps, you might be able to just work with a dead-simple implementation of WindowManager such as WindowManager.Trivial and leave out the standard NetBeans windowing system entirely).

Cocoa osx: Add a menu item on dock elements for all running applications

I'm working to an application for OSX and I would to add a new menu item on the menu shown when you click on a dock icon.
The menu isn't for my application but it must appear for all running apps.
I've found only this doc http://cocoadevcentral.com/articles/000036.php but it adds to its own app.
My app will run on OSX 10.6 or superior
You can't do that with the public API. You need to inject code into the Dock. In 10.6, the standard way to inject the code is to use the OSAX loading trick, described in this blog post for that. Then you need to do Objective-C runtime hackery to replace the method, using method_exchangeImplementations.
Anyway it's a tricky process. But if you have the will, you can. SIMBL might (or might not) help you.

Resources