Skip to content

Commit

Permalink
Disable Reference integration
Browse files Browse the repository at this point in the history
There's no way to get the search term from the new style of links
Apple's using, especially for Swift terms like IntegerLiteralConvertible
  • Loading branch information
Kapeli committed Sep 23, 2015
1 parent 3687da9 commit f1e71df
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions Classes/OMQuickHelpPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
typedef NS_ENUM(NSInteger, OMQuickHelpPluginIntegrationStyle) {
OMQuickHelpPluginIntegrationStyleDisabled = 0, // Disable this plugin altogether
OMQuickHelpPluginIntegrationStyleQuickHelp, // Search Dash instead of showing the "Quick Help" popup
OMQuickHelpPluginIntegrationStyleReference, // Show the "Quick Help" popup, but search Dash instead
OMQuickHelpPluginIntegrationStyleReference, // Show the "Quick Help" popup, but search Dash instead
// of showing Xcode's documentation viewer (when the "Reference" link
// in the popup is clicked)
// DISABLED: There's no way to get the search term from the new style
// of links Apple's using, especially for Swift terms like
// IntegerLiteralConvertible
};

typedef NS_ENUM(NSInteger, OMSearchDocumentationPluginIntegrationStyle) {
Expand Down Expand Up @@ -83,11 +86,24 @@ - (void)om_showQuickHelp:(id)sender
if(symbolString.length)
{
if (dashStyle == OMQuickHelpPluginIntegrationStyleQuickHelp) {
// BOOL success = NO;
// @try {
// Class quickHelpCommandHandler = NSClassFromString(@"IDEQuickHelpCommandHandler");
// if(quickHelpCommandHandler)
// {
// id commandHandler = [quickHelpCommandHandler handlerForAction:@selector(showDocumentationForSymbol:) withSelectionSource:self];
// [commandHandler performSelector:@selector(showDocumentationForSymbol:) withObject:self];
// success = YES;
// }
// }
// @catch(NSException *exception) { }
// if(!success)
// {
BOOL dashOpened = [self om_showQuickHelpForSearchString:symbolString];
if (!dashOpened) {
[self om_dashNotInstalledFallback];
}
}
// }
} else {
// Show regular quick help--wait to search Dash until the user clicks on a link
//No, this is not an infinite loop because the method is swizzled
Expand Down Expand Up @@ -150,6 +166,10 @@ - (void)om_handleLinkClickWithActionInformation:(id)info {
return;
}

if(kOMDebugMode)
{
NSLog(@"om_handleLinkClickWithActionInformation with info: %@", info);
}
// Dismiss the quick help popup
[[self valueForKey:@"quickHelpController"] performSelector:@selector(closeQuickHelp)];

Expand Down Expand Up @@ -316,6 +336,7 @@ - (NSURL *)om_dashURLFromQuickHelpLinkActionInformation:(id)info {
}

- (NSURL *)om_dashURLFromAppleDocURL:(NSURL *)url {
return nil;
if(![url fragment] || [[url fragment] rangeOfString:@"apple_ref"].location == NSNotFound)
{
return nil;
Expand Down Expand Up @@ -730,6 +751,11 @@ - (void)swizzle

Class docCommandHandlerClass = NSClassFromString(@"IDEDocCommandHandler");
if (docCommandHandlerClass) {
// if(![docCommandHandlerClass jr_swizzleClassMethod:@selector(loadURL:)
// withClassMethod:@selector(om_loadDocURL:) error:NULL])
// {
// NSLog(@"OMQuickHelp: Couldn't swizzle loadURL:");
// }
if(![docCommandHandlerClass jr_swizzleMethod:@selector(searchDocumentationForSelectedText:)
withMethod:@selector(om_searchDocumentationForSelectedText:) error:NULL])
{
Expand Down Expand Up @@ -786,6 +812,10 @@ -(id)init
[quickHelpStyleItem setTarget:self];
[quickHelpIntegrationStyleMenuItems addObject:quickHelpStyleItem];

// NSMenuItem *quickHelpReferenceLinkStyleItem = [dashMenu addItemWithTitle:@"Replace Quick Help Reference Link" action:@selector(toggleIntegrationStyle:) keyEquivalent:@""];
// quickHelpReferenceLinkStyleItem.tag = OMQuickHelpPluginIntegrationStyleReference;
// [quickHelpReferenceLinkStyleItem setTarget:self];
// [quickHelpIntegrationStyleMenuItems addObject:quickHelpReferenceLinkStyleItem];

_quickHelpIntegrationStyleMenuItems = [quickHelpIntegrationStyleMenuItems copy];

Expand All @@ -794,6 +824,10 @@ -(id)init
[[NSUserDefaults standardUserDefaults] setInteger:OMQuickHelpPluginIntegrationStyleQuickHelp forKey:kOMQuickHelpOpenInDashStyle];
}

if ([[NSUserDefaults standardUserDefaults] integerForKey:kOMQuickHelpOpenInDashStyle] == OMQuickHelpPluginIntegrationStyleReference) {
[[NSUserDefaults standardUserDefaults] setInteger:OMQuickHelpPluginIntegrationStyleQuickHelp forKey:kOMQuickHelpOpenInDashStyle];
}

// the default menu option should be to replace search documentation
if (![[NSUserDefaults standardUserDefaults] objectForKey:kOMSearchDocumentationOpenInDashStyle]) {
[[NSUserDefaults standardUserDefaults] setInteger:OMSearchDocumentationPluginIntegrationStyleEnabled forKey:kOMSearchDocumentationOpenInDashStyle];
Expand Down

0 comments on commit f1e71df

Please sign in to comment.