Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First add the proper extensions to CFBundleDocumentTypes inside the .plist file.<br></p> <p>Next implement the following delegates:<br> - application:openFile: (one file dropped)<br> - application:openFiles: (multiple files dropped)<br></p> <p>Reference:<br> <a href="http://developer.apple.com/library/mac/#documentation/cocoa/reference/NSApplicationDelegate_Protocol/">NSApplicationDelegate Protocol Reference</a></p> <p><strong>Response to comment:</strong></p> <p>Step by step example, hopefully it makes everything clear :)</p> <p>Add to the .plist file:</p> <pre><code> &lt;key&gt;CFBundleDocumentTypes&lt;/key&gt; &lt;array&gt; &lt;dict&gt; &lt;key&gt;CFBundleTypeExtensions&lt;/key&gt; &lt;array&gt; &lt;string&gt;xml&lt;/string&gt; &lt;/array&gt; &lt;key&gt;CFBundleTypeIconFile&lt;/key&gt; &lt;string&gt;application.icns&lt;/string&gt; &lt;key&gt;CFBundleTypeMIMETypes&lt;/key&gt; &lt;array&gt; &lt;string&gt;text/xml&lt;/string&gt; &lt;/array&gt; &lt;key&gt;CFBundleTypeName&lt;/key&gt; &lt;string&gt;XML File&lt;/string&gt; &lt;key&gt;CFBundleTypeRole&lt;/key&gt; &lt;string&gt;Viewer&lt;/string&gt; &lt;key&gt;LSIsAppleDefaultForType&lt;/key&gt; &lt;true/&gt; &lt;/dict&gt; &lt;/array&gt; </code></pre> <p>Add to ...AppDelegate.h</p> <pre><code>- (BOOL)processFile:(NSString *)file; - (IBAction)openFileManually:(id)sender; </code></pre> <p>Add to ...AppDelegate.m</p> <pre><code>- (IBAction)openFileManually:(id)sender; { NSOpenPanel *openPanel = [NSOpenPanel openPanel]; NSArray *fileTypes = [NSArray arrayWithObjects:@"xml",nil]; NSInteger result = [openPanel runModalForDirectory:NSHomeDirectory() file:nil types:fileTypes ]; if(result == NSOKButton){ [self processFile:[openPanel filename]]; } } - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename { return [self processFile:filename]; } - (BOOL)processFile:(NSString *)file { NSLog(@"The following file has been dropped or selected: %@",file); // Process file here return YES; // Return YES when file processed succesfull, else return NO. } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload