Renaissance—A Cross-Platform Development Tool for Linux and Mac OS X
Under Mac OS X, we are sharing the main gsmarkup file with the GNUstep version of our application, so we now have to create the gsmarkup file used for our sample application menu, for Mac OS X. Doing so allows us to have a different menu for Mac OS X, which is required because the layout of menus under GNUstep (vertical) is different from the one on Mac OS X (horizontal). Create the file Cocoa-Menu.gsmarkup with the content shown in Listing 6.
Listing 6. Cocoa-Menu.gsmarkup
<gsmarkup> <objects> <menu type="main"> <menu title="TiffViewer" type="apple"> <menuItem title="Hide TiffViewer" key="h" action="hide:"/> <menuItem title="Quit TiffViewer" key="q" action="terminate:"/> </menu> <menu title="File"> <menuItem title="Load Image" action="loadImage:"/> </menu> </menu> </objects> </gsmarkup>
In Listing 6, we also define three menu items: Hide TiffViewer, Quit TiffViewer and Load Image. Contrary to GNUstep, we create the first two under the TiffViewer menu, to be displayed in bold (notice the type="apple") and the latter under the File menu. We do this because the menu disposition on Mac OS X is different from GNUstep, and we want to follow the HIG at least with regard to the menus.
Once the file has been created, we need to create the Mac OS X project file and build the application. To do so, start the Project Builder application and proceed with the following steps:
From the File menu, choose the New Project... menu item and select Cocoa Application. Click on the Next button.
Specify the project name (TiffViewer) and the project directory, then click on the Finish button.
Select the Classes node in the Groups & Files panel and then click on the Add Files... menu item from the Project menu. Add the AppController.m and ImageModel.m files. Those are the same files used under GNUstep.
Expand the Other Sources node and delete the main.m file. We don't need this file.
Expand the Resources node and double-click on MainMenu.nib. This launches Interface Builder. From Interface Builder's MainMenu.nib window, delete MainMenu and Window by clicking on the corresponding icons and choosing Delete from the Edit menu. Save everything and then quit Interface Builder. We need to do so because Renaissance can provide the application menu using our gsmarkup file.
Select the Resources node and add the Cocoa-Menu.gsmarkup and TiffViewer.gsmarkup files, as you did in Step 3.
Expand the Frameworks and Linked Frameworks nodes and click on the Add Frameworks... menu item from the Project menu. Add the Renaissance.framework located in the /Library/Frameworks directory.
Finally, from the Build menu in Project Builder, choose Build and Run. This compiles and launches the application.
As you have seen in this section, porting the application from GNUstep to Mac OS X is rather trivial. No code changes were required. As under GNUstep, you can load a TIFF file in the application and try to resize the window. You should see the image view automatically resizing both horizontally and vertically, as specified in the main gsmarkup file. You also should notice the Apple-style horizontal disposition of the application menu, as shown in Figure 2.
As said before, Renaissance eases localization. In order to show how, let's translate our simple TIFF viewer to the French language. Renaissance automatically knows what to translate and what to maintain. In our menu gsmarkup files, each of the menu items had a title. Renaissance automatically uses the title of UI elements as a key in the Localizable.strings files to get the right translated string. In order to translate our sample application, create a French.lproj directory inside the project's root directory. In that newly created directory, create the Localizable.strings file with the content shown in Listing 7.
- Readers' Choice Awards 2013
- Linux Kernel News - November 2013
- Mars Needs Women
- Sublime Text: One Editor to Rule Them All?
- RSS Feeds
- Raspberry Pi: the Perfect Home Server
- December 2013 Issue of Linux Journal: Readers' Choice
- Tech Tip: Really Simple HTTP Server with Python
- Advanced Hard Drive Caching Techniques
- Linux Systems Administrator
- The kernel doesn't really
7 hours 19 min ago
7 hours 50 min ago
7 hours 51 min ago
9 hours 55 min ago
- This should be very helpful
11 hours 9 min ago
- As much as I share your point
13 hours 29 min ago
- So girls had it better ?
17 hours 1 min ago
- Reply to comment | Linux Journal
17 hours 21 min ago
- why is GNOME 3 in the fifth position at 14.1 %?
22 hours 53 min ago
- Sublime Is Brilliant!
1 day 3 hours ago