aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Interfaces/English.lproj/DBView.xib46
-rw-r--r--Resources/sequel-pro-mysql-help-template.html36
-rw-r--r--Source/CMTextView.m2
-rw-r--r--Source/CustomQuery.h8
-rw-r--r--Source/CustomQuery.m313
-rw-r--r--sequel-pro.xcodeproj/project.pbxproj4
6 files changed, 228 insertions, 181 deletions
diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib
index 067aac60..a6075f19 100644
--- a/Interfaces/English.lproj/DBView.xib
+++ b/Interfaces/English.lproj/DBView.xib
@@ -372,7 +372,7 @@
<reference key="NSControlView" ref="1029554648"/>
<int key="NSButtonFlags">-2042609409</int>
<int key="NSButtonFlags2">35</int>
- <object class="NSCustomResource" key="NSNormalImage">
+ <object class="NSCustomResource" key="NSNormalImage" id="818950635">
<string key="NSClassName">NSImage</string>
<string key="NSResourceName">button_action</string>
</object>
@@ -387,10 +387,7 @@
<string key="NSKeyEquiv"/>
<int key="NSKeyEquivModMask">1048576</int>
<int key="NSMnemonicLoc">2147483647</int>
- <object class="NSCustomResource" key="NSImage" id="247330881">
- <string key="NSClassName">NSImage</string>
- <string key="NSResourceName">button_action</string>
- </object>
+ <reference key="NSImage" ref="818950635"/>
<string key="NSAction">_popUpItemAction:</string>
<reference key="NSTarget" ref="753352469"/>
</object>
@@ -2267,8 +2264,8 @@
<bool key="NS.raise.underflow">YES</bool>
<bool key="NS.raise.dividebyzero">YES</bool>
</object>
- <string key="NS.decimal">.</string>
- <string key="NS.thousand">,</string>
+ <string key="NS.decimal">,</string>
+ <string key="NS.thousand">.</string>
<bool key="NS.hasthousands">NO</bool>
<bool key="NS.localized">YES</bool>
<bool key="NS.allowsfloats">NO</bool>
@@ -2954,7 +2951,7 @@
<reference key="NSControlView" ref="363916571"/>
<int key="NSButtonFlags">-2042609409</int>
<int key="NSButtonFlags2">35</int>
- <reference key="NSNormalImage" ref="247330881"/>
+ <reference key="NSNormalImage" ref="818950635"/>
<string key="NSAlternateContents"/>
<string key="NSKeyEquivalent"/>
<int key="NSPeriodicDelay">400</int>
@@ -2966,7 +2963,7 @@
<string key="NSKeyEquiv"/>
<int key="NSKeyEquivModMask">1048576</int>
<int key="NSMnemonicLoc">2147483647</int>
- <reference key="NSImage" ref="247330881"/>
+ <reference key="NSImage" ref="818950635"/>
<string key="NSAction">_popUpItemAction:</string>
<reference key="NSTarget" ref="984501775"/>
</object>
@@ -6365,7 +6362,7 @@
<object class="NSSearchField" id="375350404">
<reference key="NSNextResponder" ref="539508428"/>
<int key="NSvFlags">266</int>
- <string key="NSFrame">{{122, 280}, {220, 19}}</string>
+ <string key="NSFrame">{{122, 280}, {218, 19}}</string>
<reference key="NSSuperview" ref="539508428"/>
<bool key="NSEnabled">YES</bool>
<object class="NSSearchFieldCell" key="NSCell" id="980282163">
@@ -6599,7 +6596,7 @@
<object class="NSSegmentedControl" id="781717900">
<reference key="NSNextResponder" ref="539508428"/>
<int key="NSvFlags">265</int>
- <string key="NSFrame">{{349, 281}, {145, 18}}</string>
+ <string key="NSFrame">{{347, 281}, {145, 18}}</string>
<reference key="NSSuperview" ref="539508428"/>
<bool key="NSEnabled">YES</bool>
<object class="NSSegmentedCell" key="NSCell" id="814562035">
@@ -6611,27 +6608,26 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSSegmentItem">
<double key="NSSegmentItemWidth">4.600000e+01</double>
- <string key="NSSegmentItemLabel">Web</string>
- <string type="base64-UTF8" key="NSSegmentItemTooltip">U2VhcmNoIGluIHRoZSBvbmxpbmUgZG9jdW1lbnRhdGlvbiBb4oyl4oyYV10</string>
+ <string key="NSSegmentItemLabel">MySQL</string>
+ <string type="base64-UTF8" key="NSSegmentItemTooltip">U2VhcmNoIGluIE15U1FMIEhlbHAgIFvih6fijJhNXQ</string>
+ <bool key="NSSegmentItemSelected">YES</bool>
<int key="NSSegmentItemImageScaling">0</int>
</object>
<object class="NSSegmentItem">
<double key="NSSegmentItemWidth">4.600000e+01</double>
<string key="NSSegmentItemLabel">Page</string>
- <string type="base64-UTF8" key="NSSegmentItemTooltip">U2VhcmNoIGluIGN1cnJlbnQgcGFnZSBb4oyl4oyYUF0</string>
+ <string type="base64-UTF8" key="NSSegmentItemTooltip">U2VhcmNoIGluIGN1cnJlbnQgcGFnZSBb4oen4oyYUF0</string>
<int key="NSSegmentItemTag">1</int>
- <bool key="NSSegmentItemSelected">YES</bool>
<int key="NSSegmentItemImageScaling">0</int>
</object>
<object class="NSSegmentItem">
<double key="NSSegmentItemWidth">4.500000e+01</double>
- <string key="NSSegmentItemLabel">MySQL</string>
- <string type="base64-UTF8" key="NSSegmentItemTooltip">U2VhcmNoIGluIE15U1FMIEhlbHAgIFvijKXijJhNXQ</string>
+ <string key="NSSegmentItemLabel">Web</string>
+ <string type="base64-UTF8" key="NSSegmentItemTooltip">U2VhcmNoIGluIHRoZSBvbmxpbmUgZG9jdW1lbnRhdGlvbiBb4oen4oyYV10</string>
<int key="NSSegmentItemTag">2</int>
<int key="NSSegmentItemImageScaling">0</int>
</object>
</object>
- <int key="NSSelectedSegment">1</int>
<int key="NSSegmentStyle">3</int>
</object>
</object>
@@ -6648,9 +6644,9 @@
<reference key="NSSupport" ref="244931163"/>
<reference key="NSControlView" ref="898579432"/>
<int key="NSButtonFlags">-2038284033</int>
- <int key="NSButtonFlags2">402653313</int>
+ <int key="NSButtonFlags2">268435585</int>
<string key="NSAlternateContents"/>
- <string key="NSKeyEquivalent">w</string>
+ <string key="NSKeyEquivalent">W</string>
<int key="NSPeriodicDelay">200</int>
<int key="NSPeriodicInterval">25</int>
</object>
@@ -6668,9 +6664,9 @@
<reference key="NSSupport" ref="244931163"/>
<reference key="NSControlView" ref="296086739"/>
<int key="NSButtonFlags">-2038284033</int>
- <int key="NSButtonFlags2">402653313</int>
+ <int key="NSButtonFlags2">268435585</int>
<string key="NSAlternateContents"/>
- <string key="NSKeyEquivalent">p</string>
+ <string key="NSKeyEquivalent">P</string>
<int key="NSPeriodicDelay">200</int>
<int key="NSPeriodicInterval">25</int>
</object>
@@ -6688,9 +6684,9 @@
<reference key="NSSupport" ref="244931163"/>
<reference key="NSControlView" ref="111700280"/>
<int key="NSButtonFlags">-2038284033</int>
- <int key="NSButtonFlags2">402653313</int>
+ <int key="NSButtonFlags2">268435585</int>
<string key="NSAlternateContents"/>
- <string key="NSKeyEquivalent">m</string>
+ <string key="NSKeyEquivalent">M</string>
<int key="NSPeriodicDelay">200</int>
<int key="NSPeriodicInterval">25</int>
</object>
@@ -18602,11 +18598,11 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<reference ref="881970916"/>
<reference ref="771216088"/>
<reference ref="375350404"/>
- <reference ref="781717900"/>
<reference ref="898579432"/>
<reference ref="296086739"/>
<reference ref="111700280"/>
<reference ref="379816804"/>
+ <reference ref="781717900"/>
</object>
<reference key="parent" ref="78186995"/>
</object>
diff --git a/Resources/sequel-pro-mysql-help-template.html b/Resources/sequel-pro-mysql-help-template.html
new file mode 100644
index 00000000..13f14e3d
--- /dev/null
+++ b/Resources/sequel-pro-mysql-help-template.html
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html dir="ltr" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<style type="text/css" media="all">
+ body {
+ margin: 2px;
+ padding: 10px;
+ font-family:'Helvetica';
+ font-size:9pt;
+ }
+ h2 {
+ }
+ ul {
+ }
+ li {
+ }
+ .internallink {
+ color:#6A81DD;
+ text-decoration:none;
+ }
+ .description {
+ font-family:Monaco;
+ }
+ .example {
+ font-family:Courier;
+ }
+ .header {
+ padding-bottom:5px;
+ }
+</style>
+</head>
+<body>
+%@
+</body>
+</html>
diff --git a/Source/CMTextView.m b/Source/CMTextView.m
index 4ccbe16e..01037358 100644
--- a/Source/CMTextView.m
+++ b/Source/CMTextView.m
@@ -270,7 +270,7 @@ YY_BUFFER_STATE yy_scan_string (const char *);
if(curFlags==(NSControlKeyMask))
{
- [[[[self window] delegate] valueForKeyPath:@"customQueryInstance"] getHelpForCurrentWord:self];
+ [[[[self window] delegate] valueForKeyPath:@"customQueryInstance"] showHelpForCurrentWord:self];
return;
}
diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h
index 42b2ae66..fd305662 100644
--- a/Source/CustomQuery.h
+++ b/Source/CustomQuery.h
@@ -90,7 +90,7 @@
- (IBAction)chooseQueryHistory:(id)sender;
- (IBAction)closeSheet:(id)sender;
- (IBAction)gearMenuItemSelected:(id)sender;
-- (IBAction)getHelpForCurrentWord:(id)sender;
+- (IBAction)showHelpForCurrentWord:(id)sender;
- (IBAction)showHelpForSearchString:(id)sender;
- (IBAction)helpSegmentDispatcher:(id)sender;
- (IBAction)helpTargetDispatcher:(id)sender;
@@ -117,9 +117,11 @@
- (NSArray *)currentResult;
// MySQL Help
-- (void)showHelpFor:(NSString *)aString setHistory:(BOOL)setHistory;
-- (NSString *)getHTMLHelpFor:(NSString *)aString;
+- (NSString *)getHTMLformattedMySQLHelpFor:(NSString *)aString;
+- (void)showHelpFor:(NSString *)aString addToHistory:(BOOL)addToHistory;
- (void)helpTargetValidation;
+- (void)openMySQLonlineDocumentationWithString:(NSString *)searchString;
+
// Other
- (void)setConnection:(CMMCPConnection *)theConnection;
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index 3ae3c718..dd0711e0 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -29,7 +29,16 @@
#import "SPTextViewAdditions.h"
#import "TableDocument.h"
-#define MYSQL_DEV_SEARCH_URL @"http://search.mysql.com/search?q=%@&site=refman-%@"
+#define SP_MYSQL_DEV_SEARCH_URL @"http://search.mysql.com/search?q=%@&site=refman-%@"
+#define SP_HELP_SEARCH_IN_MYSQL 0
+#define SP_HELP_SEARCH_IN_PAGE 1
+#define SP_HELP_SEARCH_IN_WEB 2
+#define SP_HELP_GOBACK_BUTTON 0
+#define SP_HELP_SHOW_TOC_BUTTON 1
+#define SP_HELP_GOFORWARD_BUTTON 2
+#define SP_HELP_NOT_AVAILABLE @"__no_help_available"
+#define SP_HELP_TOC_SEARCH_STRING @"contents"
+
@implementation CustomQuery
@@ -1365,110 +1374,120 @@ traps enter key and
/*
- * Retrieve and show the data for "HELP 'aString'".
+ * Show the data for "HELP 'searchString'".
*/
-- (void)showHelpFor:(NSString *)aString setHistory:(BOOL)setHistory
+- (void)showHelpFor:(NSString *)searchString addToHistory:(BOOL)addToHistory
{
- NSString * helpString = [self getHTMLHelpFor:aString];
- // Order out the Help window if not visible
+ NSString * helpString = [self getHTMLformattedMySQLHelpFor:searchString];
+ // Order out resp. init the Help window if not visible
if(![helpWebViewWindow isVisible])
{
+ // get current MySQL version for title and online search
mySQLversion = [[[(TableDocument *)[[textView window] delegate] mySQLVersion] substringToIndex:3] retain];
+
[helpWebViewWindow setTitle:[NSString stringWithFormat:@"%@ (%@ %@)", NSLocalizedString(@"MySQL Help", @"mysql help"), NSLocalizedString(@"version", @"version"), mySQLversion]];
+
+ // init search history
[helpWebView setMaintainsBackForwardList:YES];
[[helpWebView backForwardList] setCapacity:20];
+
+ // init goback/forward buttons
if([[helpWebView backForwardList] backListCount] < 1)
{
- [helpNavigator setEnabled:NO forSegment:0];
- [helpNavigator setEnabled:NO forSegment:2];
+ [helpNavigator setEnabled:NO forSegment:SP_HELP_GOBACK_BUTTON];
+ [helpNavigator setEnabled:NO forSegment:SP_HELP_GOFORWARD_BUTTON];
} else {
- [helpNavigator setEnabled:[[helpWebView backForwardList] backListCount] forSegment:0];
- [helpNavigator setEnabled:[[helpWebView backForwardList] forwardListCount] forSegment:2];
+ [helpNavigator setEnabled:[[helpWebView backForwardList] backListCount] forSegment:SP_HELP_GOBACK_BUTTON];
+ [helpNavigator setEnabled:[[helpWebView backForwardList] forwardListCount] forSegment:SP_HELP_GOFORWARD_BUTTON];
}
- if(![helpString isEqualToString:@"__no_help_available"])
- [helpWebViewWindow orderFront:helpWebView];
- helpTarget = 2; // set default to search in MySQL help
- [helpTargetSelector setSelectedSegment:2];
+
+ // set default to search in MySQL help
+ helpTarget = SP_HELP_SEARCH_IN_MYSQL;
+ [helpTargetSelector setSelectedSegment:SP_HELP_SEARCH_IN_MYSQL];
[self helpTargetValidation];
+
+ // order out Help window if Help is available
+ if(![helpString isEqualToString:SP_HELP_NOT_AVAILABLE])
+ [helpWebViewWindow orderFront:helpWebView];
+
}
- if([helpString isEqualToString:@"__no_help_available"])
+
+ // close Help window if no Help avaiable
+ if([helpString isEqualToString:SP_HELP_NOT_AVAILABLE])
[helpWebViewWindow close];
if(![helpString length]) return;
- if(setHistory)
+ // add searchString to history list
+ if(addToHistory)
{
- WebHistoryItem *aWebHistoryItem = [[WebHistoryItem alloc] initWithURLString:[NSString stringWithFormat:@"applewebdata://%@", aString] title:aString lastVisitedTimeInterval:[[NSDate date] timeIntervalSinceDate:[NSDate distantFuture]]];
+ WebHistoryItem *aWebHistoryItem = [[WebHistoryItem alloc] initWithURLString:[NSString stringWithFormat:@"applewebdata://%@", searchString] title:searchString lastVisitedTimeInterval:[[NSDate date] timeIntervalSinceDate:[NSDate distantFuture]]];
[[helpWebView backForwardList] addItem:aWebHistoryItem];
}
- [helpNavigator setEnabled:[[helpWebView backForwardList] backListCount] forSegment:0];
- [helpNavigator setEnabled:[[helpWebView backForwardList] forwardListCount] forSegment:2];
+
+ // validate goback/forward buttons
+ [helpNavigator setEnabled:[[helpWebView backForwardList] backListCount] forSegment:SP_HELP_GOBACK_BUTTON];
+ [helpNavigator setEnabled:[[helpWebView backForwardList] forwardListCount] forSegment:SP_HELP_GOFORWARD_BUTTON];
+ // load HTML formatted help into the webview
[[helpWebView mainFrame] loadHTMLString:helpString baseURL:nil];
-
}
/*
- * Retrieve and show the data for "HELP 'search word'" according to helpTarget
+ * Show the data for "HELP 'search word'" according to helpTarget
*/
- (IBAction)showHelpForSearchString:(id)sender
{
- NSString *searchTerm = [[helpSearchField stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+ NSString *searchString = [[helpSearchField stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
switch(helpTarget)
{
- case 0: // page
- if(![helpWebView searchFor:searchTerm direction:YES caseSensitive:NO wrap:YES])
- if([searchTerm length]) NSBeep();
- break;
- case 1: // online
- // Open MySQL Documentation search in browser
- if(![searchTerm length])
+ case SP_HELP_SEARCH_IN_PAGE:
+ if(![helpWebView searchFor:searchString direction:YES caseSensitive:NO wrap:YES])
+ if([searchString length]) NSBeep();
+ break;
+ case SP_HELP_SEARCH_IN_WEB:
+ if(![searchString length])
+ break;
+ [self openMySQLonlineDocumentationWithString:searchString];
+ break;
+ case SP_HELP_SEARCH_IN_MYSQL:
+ [self showHelpFor:searchString addToHistory:YES];
break;
- [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:
- [[NSString stringWithFormat:
- MYSQL_DEV_SEARCH_URL,
- searchTerm,
- [mySQLversion stringByReplacingOccurrencesOfString:@"." withString:@""]]
- stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]];
- break;
- case 2: // MySQL
- [self showHelpFor:searchTerm setHistory:YES];
- break;
}
}
/*
- * Retrieve and show the Help for the selected text in the webview
+ * Show the Help for the selected text in the webview
*/
- (IBAction)showHelpForWebViewSelection:(id)sender
{
- [self showHelpFor:[[helpWebView selectedDOMRange] text] setHistory:YES];
+ [self showHelpFor:[[helpWebView selectedDOMRange] text] addToHistory:YES];
}
/*
- * Retrieve and show MySQL's online documentation for the selected text in the webview
+ * Show MySQL's online documentation for the selected text in the webview
*/
- (IBAction)searchInDocForWebViewSelection:(id)sender
{
- [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:
- [[NSString stringWithFormat:
- MYSQL_DEV_SEARCH_URL,
- [[helpWebView selectedDOMRange] text],
- [mySQLversion stringByReplacingOccurrencesOfString:@"." withString:@""]]
- stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]];
+ NSString *searchString = [[[helpWebView selectedDOMRange] text] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+ if(![searchString length])
+ {
+ NSBeep();
+ return;
+ }
+ [self openMySQLonlineDocumentationWithString:searchString];
}
/*
- * Retrieve and show the data for "HELP 'currentWord'"
+ * Show the data for "HELP 'currentWord'"
*/
-- (IBAction)getHelpForCurrentWord:(id)sender
+- (IBAction)showHelpForCurrentWord:(id)sender
{
- NSString *aString = [[textView string] substringWithRange:[textView getRangeForCurrentWord]];
- // if(![aString length]) return;
- [self showHelpFor:aString setHistory:YES];
+ NSString *searchString = [[textView string] substringWithRange:[textView getRangeForCurrentWord]];
+ [self showHelpFor:searchString addToHistory:YES];
}
/*
@@ -1476,13 +1495,13 @@ traps enter key and
*/
- (IBAction)helpSearchFindNextInPage:(id)sender
{
- if(!helpTarget)
+ if(helpTarget == SP_HELP_SEARCH_IN_PAGE)
if(![helpWebView searchFor:[[helpSearchField stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] direction:YES caseSensitive:NO wrap:YES])
NSBeep();
}
- (IBAction)helpSearchFindPreviousInPage:(id)sender
{
- if(!helpTarget)
+ if(helpTarget == SP_HELP_SEARCH_IN_PAGE)
if(![helpWebView searchFor:[[helpSearchField stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] direction:NO caseSensitive:NO wrap:YES])
NSBeep();
}
@@ -1494,138 +1513,111 @@ traps enter key and
{
switch([helpNavigator selectedSegment])
{
- case 0:
- if([[helpWebView backForwardList] backListCount]) {
- [self showHelpFor:[[[[helpWebView backForwardList] backItem] URLString] lastPathComponent] setHistory:NO];
- [[helpWebView backForwardList] goBack];
- }
- break;
- case 1: // TOC
- [self showHelpFor:@"contents" setHistory:YES];
- break;
- case 2:
- if([[helpWebView backForwardList] forwardListCount]) {
- [self showHelpFor:[[[[helpWebView backForwardList] forwardItem] URLString] lastPathComponent] setHistory:NO];
- [[helpWebView backForwardList] goForward];
- }
- break;
+ case SP_HELP_GOBACK_BUTTON:
+ if([[helpWebView backForwardList] backListCount]) {
+ [self showHelpFor:[[[[helpWebView backForwardList] backItem] URLString] lastPathComponent] addToHistory:NO];
+ [[helpWebView backForwardList] goBack];
+ }
+ break;
+ case SP_HELP_SHOW_TOC_BUTTON:
+ [self showHelpFor:SP_HELP_TOC_SEARCH_STRING addToHistory:YES];
+ break;
+ case SP_HELP_GOFORWARD_BUTTON:
+ if([[helpWebView backForwardList] forwardListCount]) {
+ [self showHelpFor:[[[[helpWebView backForwardList] forwardItem] URLString] lastPathComponent] addToHistory:NO];
+ [[helpWebView backForwardList] goForward];
+ }
+ break;
}
- [helpNavigator setEnabled:[[helpWebView backForwardList] backListCount] forSegment:0];
- [helpNavigator setEnabled:[[helpWebView backForwardList] forwardListCount] forSegment:2];
+ // validate goback and goforward buttons according history
+ [helpNavigator setEnabled:[[helpWebView backForwardList] backListCount] forSegment:SP_HELP_GOBACK_BUTTON];
+ [helpNavigator setEnabled:[[helpWebView backForwardList] forwardListCount] forSegment:SP_HELP_GOFORWARD_BUTTON];
}
/*
- * Set helpTarget
+ * Set helpTarget according user choice via mouse and keyboard short-cuts.
*/
- (IBAction)helpSelectHelpTargetMySQL:(id)sender
{
- helpTarget = 2;
- [helpTargetSelector setSelectedSegment:2];
+ helpTarget = SP_HELP_SEARCH_IN_MYSQL;
+ [helpTargetSelector setSelectedSegment:SP_HELP_SEARCH_IN_MYSQL];
[self helpTargetValidation];
}
- (IBAction)helpSelectHelpTargetPage:(id)sender
{
- helpTarget = 0;
- [helpTargetSelector setSelectedSegment:1];
+ helpTarget = SP_HELP_SEARCH_IN_PAGE;
+ [helpTargetSelector setSelectedSegment:SP_HELP_SEARCH_IN_PAGE];
[self helpTargetValidation];
}
- (IBAction)helpSelectHelpTargetWeb:(id)sender
{
- helpTarget = 1;
- [helpTargetSelector setSelectedSegment:0];
+ helpTarget = SP_HELP_SEARCH_IN_WEB;
+ [helpTargetSelector setSelectedSegment:SP_HELP_SEARCH_IN_WEB];
[self helpTargetValidation];
}
- (IBAction)helpTargetDispatcher:(id)sender
{
- switch([helpTargetSelector selectedSegment])
- {
- case 0:
- helpTarget = 1;
- break;
- case 1:
- helpTarget = 0;
- break;
- case 2:
- helpTarget = 2;
- break;
- }
+ helpTarget = [helpTargetSelector selectedSegment];
[self helpTargetValidation];
}
+
/*
- * Control search target buttons and help behaviour
+ * Control the help search field behaviour.
*/
- (void)helpTargetValidation
{
switch(helpTarget)
{
- case 0: // page
- case 1: // online
+ case SP_HELP_SEARCH_IN_PAGE:
+ case SP_HELP_SEARCH_IN_WEB:
[helpSearchFieldCell setSendsWholeSearchString:YES];
break;
- case 2: // MySQL
+ case SP_HELP_SEARCH_IN_MYSQL:
[helpSearchFieldCell setSendsWholeSearchString:NO];
break;
}
}
+- (void)openMySQLonlineDocumentationWithString:(NSString *)searchString
+{
+ [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:
+ [[NSString stringWithFormat:
+ SP_MYSQL_DEV_SEARCH_URL,
+ searchString,
+ [mySQLversion stringByReplacingOccurrencesOfString:@"." withString:@""]]
+ stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]];
+}
+
/*
- * Return the help string HTML formatted from executing "HELP 'aString'".
+ * Return the help string HTML formatted from executing "HELP 'searchString'".
* If more than one help topic was found return a link list.
*/
-- (NSString *)getHTMLHelpFor:(NSString *)aString
+- (NSString *)getHTMLformattedMySQLHelpFor:(NSString *)searchString
{
- if(![aString length]) return(@"");
+ if(![searchString length]) return @"";
- CMMCPResult *theResult = nil;
- NSDictionary *tableDetails;
- NSRange aRange;
+ NSRange aRange;
+ CMMCPResult *theResult = nil;
+ NSDictionary *tableDetails;
NSMutableString *theHelp = [NSMutableString string];
- [theHelp setString:
- @"<html>"
- @"<head>"
- @" <style type='text/css' media='screen'>"
- @" body {"
- @" margin: 2px;"
- @" padding: 10px;"
- @" font-family:'Helvetica';"
- @" font-size:9pt;"
- @" }"
- @" .internallink {"
- @" color:#6A81DD;"
- @" text-decoration:none;"
- @" }"
- @" .code {"
- @" font-family:Monaco;"
- @" }"
- @" .example {"
- @" font-family:Courier;"
- @" }"
- @" .searchstring {"
- @" }"
- @" .header {"
- @" padding-bottom:5px;"
- @" }"
- @" </style>"
- @"</head>"
- @"<body>"
-
- ];
-
- theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"HELP '%@'", aString]];
+
+ [theHelp setString:@""];
+
+ // search via: HELP 'searchString'
+ theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"HELP '%@'", searchString]];
if ( ![[mySQLConnection getLastErrorMessage] isEqualToString:@""])
{
- [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:
- [[NSString stringWithFormat:
- MYSQL_DEV_SEARCH_URL,
- aString,
- [mySQLversion stringByReplacingOccurrencesOfString:@"." withString:@""]]
- stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]];
- return @"__no_help_available";
+ // if an error or HELP is not supported fall back to online search
+ [self openMySQLonlineDocumentationWithString:searchString];
+ return SP_HELP_NOT_AVAILABLE;
}
+ // nothing found?
if(![theResult numOfRows]) {
- theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"HELP '%@%%'", aString]];
+ // try to search via: HELP 'searchString%'
+ theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"HELP '%@%%'", searchString]];
+ // really nothing found?
if(![theResult numOfRows])
return @"";
}
@@ -1645,7 +1637,7 @@ traps enter key and
[desc setString:[[[tableDetails objectForKey:@"description"] copy] autorelease]];
- //[desc replaceOccurrencesOfString:[aString uppercaseString] withString:[NSString stringWithFormat:@"<span class='searchstring'>%@</span>", [aString uppercaseString]] options:NSLiteralSearch range:NSMakeRange(0,[desc length])];
+ //[desc replaceOccurrencesOfString:[searchString uppercaseString] withString:[NSString stringWithFormat:@"<span class='searchstring'>%@</span>", [searchString uppercaseString]] options:NSLiteralSearch range:NSMakeRange(0,[desc length])];
// detect and generate http links
aRange = NSMakeRange(0,0);
@@ -1694,10 +1686,11 @@ traps enter key and
// break;
// }
- [theHelp appendString:@"<pre class='code'>"];
+ [theHelp appendString:@"<pre class='description'>"];
[theHelp appendString:desc];
[theHelp appendString:@"</pre>"];
}
+ // are examples available?
if([tableDetails objectForKey:@"example"]){
NSString *examples = [[[tableDetails objectForKey:@"example"] copy] autorelease];
if([examples length]){
@@ -1710,12 +1703,13 @@ traps enter key and
int i;
int r = [theResult numOfRows];
if (r) [theResult dataSeek:0];
-
- if(![aString isEqualToString:@"contents"])
- [theHelp appendString:[NSString stringWithFormat:@"<br><i>%@ “%@”</i><br>", NSLocalizedString(@"Help topics for", @"help topics for"), aString]];
+ // check if HELP 'contents' is called
+ if(![searchString isEqualToString:SP_HELP_TOC_SEARCH_STRING])
+ [theHelp appendString:[NSString stringWithFormat:@"<br><i>%@ “%@”</i><br>", NSLocalizedString(@"Help topics for", @"help topics for"), searchString]];
else
- [theHelp appendString:[NSString stringWithFormat:@"<br><b>%@:</b><br>", NSLocalizedString(@"MySQL Help – Categories", @"mysql help categories"), aString]];
+ [theHelp appendString:[NSString stringWithFormat:@"<br><b>%@:</b><br>", NSLocalizedString(@"MySQL Help – Categories", @"mysql help categories"), searchString]];
+ // iterate through all found rows and print them as HTML ul/li list
[theHelp appendString:@"<ul>"];
for ( i = 0 ; i < r ; i++ ) {
NSArray *anArray = [theResult fetchRowAsArray];
@@ -1725,13 +1719,27 @@ traps enter key and
}
[theHelp appendString:@"</ul>"];
}
- [theHelp appendString:@"</body></html>"];
[tableDetails release];
- return theHelp;
+
+ NSString *helpHTMLTemplatePath = [[NSBundle mainBundle] pathForResource:@"sequel-pro-mysql-help-template" ofType:@"html"];
+ NSError *error;
+ NSString *helpHTMLTemplate = [[NSString alloc]
+ initWithContentsOfFile:helpHTMLTemplatePath
+ encoding:NSUTF8StringEncoding
+ error:&error];
+ // an error occurred while reading
+ if (helpHTMLTemplate == nil)
+ return [NSString stringWithFormat:@"Error reading “sequel-pro-mysql-help-template.html”!<br>%@", [error localizedFailureReason]];
+
+ return [NSString stringWithFormat:helpHTMLTemplate, theHelp];
}
+//////////////////////////////
+// WebView delegate methods //
+//////////////////////////////
+
/*
* Link detector: If user clicked at an http link open it in the default browser,
* otherwise search for it in the MySQL help. Additionally handle back/forward events from
@@ -1740,9 +1748,9 @@ traps enter key and
- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener
{
int navigationType = [[actionInformation objectForKey:WebActionNavigationTypeKey] intValue];
+
if([[[request URL] scheme] isEqualToString:@"applewebdata"] && navigationType == WebNavigationTypeLinkClicked){
- // [self showHelpFor:[[[request URL] path] substringWithRange:NSMakeRange(1,[[[request URL] path] length]-1)] setHistory:YES];
- [self showHelpFor:[[[request URL] path] lastPathComponent] setHistory:YES];
+ [self showHelpFor:[[[request URL] path] lastPathComponent] addToHistory:YES];
[listener ignore];
} else {
if (navigationType == WebNavigationTypeOther) {
@@ -1757,7 +1765,7 @@ traps enter key and
[listener ignore];
} else if (navigationType == WebNavigationTypeBackForward) {
// catch back/forward events from contextual menu
- [self showHelpFor:[[[[actionInformation objectForKey:WebActionOriginalURLKey] absoluteString] lastPathComponent] stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding] setHistory:NO];
+ [self showHelpFor:[[[[actionInformation objectForKey:WebActionOriginalURLKey] absoluteString] lastPathComponent] stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding] addToHistory:NO];
[listener ignore];
} else if (navigationType == WebNavigationTypeReload) {
// just in case
@@ -1771,7 +1779,8 @@ traps enter key and
/*
- * Manage contextual menu in helpWebView
+ * Manage contextual menu in helpWebView
+ * Ignore "Reload", "Open Link", "Open Link in new Window", "Download link".
*/
- (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary *)element defaultMenuItems:(NSArray *)defaultMenuItems
{
diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj
index a4456729..6d69dddb 100644
--- a/sequel-pro.xcodeproj/project.pbxproj
+++ b/sequel-pro.xcodeproj/project.pbxproj
@@ -121,6 +121,7 @@
B5E92F400F75B32100012500 /* toolbar-export-xml.tiff in Resources */ = {isa = PBXBuildFile; fileRef = B5E92F3A0F75B32100012500 /* toolbar-export-xml.tiff */; };
B5EAC0FD0EC87FF900CC579C /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5EAC0FC0EC87FF900CC579C /* Security.framework */; };
B5F4F7810F7BCF990059AE84 /* toolbar-switch-to-procedures.tiff in Resources */ = {isa = PBXBuildFile; fileRef = B5F4F7800F7BCF990059AE84 /* toolbar-switch-to-procedures.tiff */; };
+ BC2C8E220FA8C2DB008468C7 /* sequel-pro-mysql-help-template.html in Resources */ = {isa = PBXBuildFile; fileRef = BC2C8E210FA8C2DB008468C7 /* sequel-pro-mysql-help-template.html */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@@ -322,6 +323,7 @@
B5E92F3A0F75B32100012500 /* toolbar-export-xml.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = "toolbar-export-xml.tiff"; sourceTree = "<group>"; };
B5EAC0FC0EC87FF900CC579C /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
B5F4F7800F7BCF990059AE84 /* toolbar-switch-to-procedures.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = "toolbar-switch-to-procedures.tiff"; sourceTree = "<group>"; };
+ BC2C8E210FA8C2DB008468C7 /* sequel-pro-mysql-help-template.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "sequel-pro-mysql-help-template.html"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -440,6 +442,7 @@
17E641F80EF02088001BC333 /* sequel-pro.scriptTerminology */,
17E641F50EF02088001BC333 /* Growl Registration Ticket.growlRegDict */,
5885940E0F7AEE6000ED0E67 /* sparkle-public-key.pem */,
+ BC2C8E210FA8C2DB008468C7 /* sequel-pro-mysql-help-template.html */,
);
path = Resources;
sourceTree = "<group>";
@@ -817,6 +820,7 @@
296DC8D20F90950C002A3258 /* sequel-pro-print-template.html in Resources */,
B508B5DA0F9837A200E03A69 /* button_edit.tiff in Resources */,
B53857340F9CC3B600EB2354 /* button_clear.tiff in Resources */,
+ BC2C8E220FA8C2DB008468C7 /* sequel-pro-mysql-help-template.html in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};