Permalink
Browse files

Add support for Services

 - Now you can open from selection text using Service Menu or drag-and-drop
  • Loading branch information...
kanekoa committed Aug 12, 2013
1 parent 8f6ea58 commit b900e15f18608dec5c5232eac2c6dc54f2738644
Showing with 42 additions and 0 deletions.
  1. +20 −0 Opener/Opener-Info.plist
  2. +22 −0 Opener/PDAppDelegate.m
@@ -32,5 +32,25 @@
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSServices</key>
<array>
<dict>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>Opener.app/Open Selection</string>
</dict>
<key>NSMessage</key>
<string>requestService</string>
<key>NSPortName</key>
<string>Opener</string>
<key>NSSendTypes</key>
<array>
<string>NSStringPboardType</string>
</array>
<key>NSUserData</key>
<string>open-selection</string>
</dict>
</array>
</dict>
</plist>
@@ -26,6 +26,10 @@ - (void)dealloc {
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[NSApp setServicesProvider:self];
NSUpdateDynamicServices();
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(editingDidEnd:)
name:NSControlTextDidChangeNotification
@@ -223,4 +227,22 @@ - (BOOL)editingDidEnd:(NSNotification *)notification {
return YES;
}
#pragma mark - Service Handler
- (void)requestService:(NSPasteboard *)pboard
userData:(NSString *)userData
error:(NSString **)error
{
NSArray *types = [pboard types];
if (![types containsObject:NSPasteboardTypeString]) {
*error = @"Error: could not get string";
return;
}
NSString *filePath = [pboard stringForType:NSPasteboardTypeString];
self.urlField.stringValue = filePath;
[self openButtonPushed:self];
}
@end

0 comments on commit b900e15

Please sign in to comment.