diff options
Diffstat (limited to 'Source')
40 files changed, 237 insertions, 218 deletions
diff --git a/Source/GeneratePreviewForURL.m b/Source/GeneratePreviewForURL.m index 9b66d3e7..5261b76a 100644 --- a/Source/GeneratePreviewForURL.m +++ b/Source/GeneratePreviewForURL.m @@ -37,6 +37,7 @@ #import "SPDataAdditions.h" #import "SPEditorTokens.h" +#import "SPSyntaxParser.h" OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize); OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options); @@ -48,17 +49,6 @@ void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview); This function's job is to create preview for designated file ----------------------------------------------------------------------------- */ -#pragma mark lex init - -/* -* Include all the extern variables and prototypes required for flex (used for syntax highlighting) -*/ -extern NSUInteger yylex(); -extern NSUInteger yyuoffset, yyuleng; -typedef struct yy_buffer_state *YY_BUFFER_STATE; -void yy_switch_to_buffer(YY_BUFFER_STATE); -YY_BUFFER_STATE yy_scan_string (const char *); - OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options) { @@ -528,6 +518,5 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview) { - // implement only if supported + // Implement only if supported } - diff --git a/Source/GenerateThumbnailForURL.m b/Source/GenerateThumbnailForURL.m index 3b7d3151..84a0ceea 100644 --- a/Source/GenerateThumbnailForURL.m +++ b/Source/GenerateThumbnailForURL.m @@ -37,19 +37,17 @@ void CancelThumbnailGeneration(void* thisInterface, QLThumbnailRequestRef thumbnail); OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maximumSize); -/* ----------------------------------------------------------------------------- -Generate a thumbnail for file - -This function's job is to create thumbnail for designated file as fast as possible ------------------------------------------------------------------------------ */ - +/** + * Generate a thumbnail for file. + * + * This function's job is to create thumbnail for designated file as fast as possible. + */ void CancelThumbnailGeneration(void* thisInterface, QLThumbnailRequestRef thumbnail) { - // implement only if supported + // Implement only if supported } OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maximumSize) - { return noErr; diff --git a/Source/SPAppController.h b/Source/SPAppController.h index ccaf58dd..85850b50 100644 --- a/Source/SPAppController.h +++ b/Source/SPAppController.h @@ -40,7 +40,7 @@ @class SPDatabaseDocument; @class SPBundleEditorController; -@interface SPAppController : NSObject <FRFeedbackReporterDelegate> +@interface SPAppController : NSObject <FRFeedbackReporterDelegate, NSApplicationDelegate, NSOpenSavePanelDelegate> { IBOutlet NSWindow* bundleEditorWindow; diff --git a/Source/SPAppController.m b/Source/SPAppController.m index da70ceb9..d89abe19 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -51,21 +51,11 @@ #import "SPBundleCommandRunner.h" #import "SPWindowManagement.h" #import "SPCopyTable.h" +#import "SPSyntaxParser.h" #import <PSMTabBar/PSMTabBarControl.h> #import <Sparkle/Sparkle.h> -#pragma mark Lex init - -/* -* Include all the extern variables and prototypes required for flex (used for syntax highlighting) -*/ -extern NSUInteger yylex(); -extern NSUInteger yyuoffset, yyuleng; -typedef struct yy_buffer_state *YY_BUFFER_STATE; -void yy_switch_to_buffer(YY_BUFFER_STATE); -YY_BUFFER_STATE yy_scan_string (const char *); - @interface SPAppController () - (void)_copyDefaultThemes; @@ -222,6 +212,7 @@ YY_BUFFER_STATE yy_scan_string (const char *); } NSOpenPanel *panel = [NSOpenPanel openPanel]; + [panel setDelegate:self]; [panel setCanSelectHiddenExtension:YES]; [panel setCanChooseDirectories:NO]; @@ -266,6 +257,7 @@ YY_BUFFER_STATE yy_scan_string (const char *); { if (returnCode) { [panel orderOut:self]; + [self application:nil openFiles:[panel filenames]]; } @@ -278,15 +270,15 @@ YY_BUFFER_STATE yy_scan_string (const char *); */ - (void)application:(NSApplication *)app openFiles:(NSArray *)filenames { - for (NSString *filename in filenames) { // Opens a sql file and insert its content into the Custom Query editor - if([[[filename pathExtension] lowercaseString] isEqualToString:[SPFileExtensionSQL lowercaseString]]) { + if ([[[filename pathExtension] lowercaseString] isEqualToString:[SPFileExtensionSQL lowercaseString]]) { // Check size and NSFileType - NSDictionary *attr = [[NSFileManager defaultManager] fileAttributesAtPath:filename traverseLink:YES]; - if(attr) + NSDictionary *attr = [[NSFileManager defaultManager] attributesOfItemAtPath:filename error:nil]; + + if (attr) { NSNumber *filesize = [attr objectForKey:NSFileSize]; NSString *filetype = [attr objectForKey:NSFileType]; @@ -772,7 +764,7 @@ YY_BUFFER_STATE yy_scan_string (const char *); return; } - NSString *activeProcessID = [[[[self frontDocumentWindow] delegate] selectedTableDocument] processID]; + NSString *activeProcessID = [[(SPWindowController *)[[self frontDocumentWindow] delegate] selectedTableDocument] processID]; SPDatabaseDocument *processDocument = nil; @@ -780,7 +772,7 @@ YY_BUFFER_STATE yy_scan_string (const char *); // For speed check the front most first otherwise iterate through all if(passedProcessID && [passedProcessID length]) { if([activeProcessID isEqualToString:passedProcessID]) { - processDocument = [[[self frontDocumentWindow] delegate] selectedTableDocument]; + processDocument = [(SPWindowController *)[[self frontDocumentWindow] delegate] selectedTableDocument]; } else { for (NSWindow *aWindow in [NSApp orderedWindows]) { if([[aWindow windowController] isMemberOfClass:[SPWindowController class]]) { @@ -799,7 +791,7 @@ YY_BUFFER_STATE yy_scan_string (const char *); // if no processDoc found and no passedProcessID was passed execute // command at front most doc if(!processDocument && !passedProcessID) - processDocument = [[[self frontDocumentWindow] delegate] selectedTableDocument]; + processDocument = [(SPWindowController *)[[self frontDocumentWindow] delegate] selectedTableDocument]; if(processDocument && command) { if([command isEqualToString:@"passToDoc"]) { diff --git a/Source/SPBundleCommandRunner.m b/Source/SPBundleCommandRunner.m index 5dd0878a..84ef4dc8 100644 --- a/Source/SPBundleCommandRunner.m +++ b/Source/SPBundleCommandRunner.m @@ -160,7 +160,7 @@ // Furthermore this id is used to communicate with the called command as file name. id doc = nil; if([[[NSApp mainWindow] delegate] respondsToSelector:@selector(selectedTableDocument)]) - doc = [[[NSApp mainWindow] delegate] selectedTableDocument]; + doc = [(SPWindowController *)[[NSApp mainWindow] delegate] selectedTableDocument]; // Check if connected if([doc getConnection] == nil) doc = nil; diff --git a/Source/SPBundleCommandTextView.m b/Source/SPBundleCommandTextView.m index d889c8d8..dc674baa 100644 --- a/Source/SPBundleCommandTextView.m +++ b/Source/SPBundleCommandTextView.m @@ -621,14 +621,14 @@ [self setSelectedRange:NSMakeRange(characterIndex,0)]; // Check if user pressed ⌘ while dragging for inserting only the file path - if([sender draggingSourceOperationMask] == 4) - { + if ([sender draggingSourceOperationMask] == 4) { [self insertText:filepath]; return YES; } // Check size and NSFileType - NSDictionary *attr = [[NSFileManager defaultManager] fileAttributesAtPath:filepath traverseLink:YES]; + NSDictionary *attr = [[NSFileManager defaultManager] attributesOfItemAtPath:filepath error:nil]; + if(attr) { NSNumber *filesize = [attr objectForKey:NSFileSize]; diff --git a/Source/SPChooseMenuItemDialog.h b/Source/SPChooseMenuItemDialog.h index 558bbc4c..ff56ac2d 100644 --- a/Source/SPChooseMenuItemDialog.h +++ b/Source/SPChooseMenuItemDialog.h @@ -32,7 +32,7 @@ @class SPChooseMenuItemDialogTextView; -@interface SPChooseMenuItemDialog : NSWindow +@interface SPChooseMenuItemDialog : NSWindow <NSTextViewDelegate> { NSMenu *contextMenu; NSInteger selectedItemIndex; diff --git a/Source/SPChooseMenuItemDialog.m b/Source/SPChooseMenuItemDialog.m index a164e858..4bfdcbcb 100644 --- a/Source/SPChooseMenuItemDialog.m +++ b/Source/SPChooseMenuItemDialog.m @@ -39,27 +39,21 @@ @end @implementation SPChooseMenuItemDialogTextView -{ -} - (id)init; { - if ((self = [super initWithFrame:NSMakeRect(1, 1, 2, 2)])) - { - } - - return self; + return [super initWithFrame:NSMakeRect(1, 1, 2, 2)]; } - (IBAction)menuItemHandler:(id)sender { - [[self delegate] setSelectedItemIndex:[sender tag]]; - [[self delegate] setWaitForChoice:NO]; + [(SPChooseMenuItemDialog *)[self delegate] setSelectedItemIndex:[sender tag]]; + [(SPChooseMenuItemDialog *)[self delegate] setWaitForChoice:NO]; } - (NSMenu *)menuForEvent:(NSEvent *)event { - return [[self delegate] contextMenu]; + return [(SPChooseMenuItemDialog *)[self delegate] contextMenu]; } @end @@ -72,21 +66,18 @@ - (id)init; { - if((self = [super initWithContentRect:NSMakeRect(1,1,2,2) - styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO])) + if ((self = [super initWithContentRect:NSMakeRect(1, 1, 2, 2) + styleMask:NSBorderlessWindowMask + backing:NSBackingStoreBuffered + defer:NO])) { waitForChoice = YES; selectedItemIndex = -1; } + return self; } -- (void)dealloc -{ - [dummyTextView release]; - [super dealloc]; -} - - (void)initDialog { [self setReleasedWhenClosed:YES]; @@ -96,39 +87,49 @@ [self setAlphaValue:0.0f]; dummyTextView = [[SPChooseMenuItemDialogTextView alloc] init]; + [dummyTextView setDelegate:self]; [self setContentView:dummyTextView]; - } + (NSInteger)withItems:(NSArray*)theList atPosition:(NSPoint)location { - - if(!theList || ![theList count]) return -1; + if (!theList || ![theList count]) return -1; SPChooseMenuItemDialog *dialog = [SPChooseMenuItemDialog new]; [dialog initDialog]; - NSMenu *theMenu = [[[NSMenu alloc] init] autorelease]; NSInteger cnt = 0; - for(id item in theList) { + NSMenu *theMenu = [[[NSMenu alloc] init] autorelease]; + + for (id item in theList) + { NSMenuItem *aMenuItem; - if([item isKindOfClass:[NSString class]]) + + if ([item isKindOfClass:[NSString class]]) { aMenuItem = [[NSMenuItem alloc] initWithTitle:item action:@selector(menuItemHandler:) keyEquivalent:@""]; + } else if([item isKindOfClass:[NSDictionary class]]) { NSString *title = ([item objectForKey:@"title"]) ?: @""; + SEL action = ([item objectForKey:@"action"]) ? NSSelectorFromString([item objectForKey:@"action"]) : @selector(menuItemHandler:); + NSString *keyEquivalent = ([item objectForKey:@"key"]) ?: @""; + aMenuItem = [[NSMenuItem alloc] initWithTitle:title action:action keyEquivalent:keyEquivalent]; - if([item objectForKey:@"tooltip"]) + + if ([item objectForKey:@"tooltip"]) { [aMenuItem setToolTip:[item objectForKey:@"tooltip"]]; + } } + [aMenuItem setTag:cnt++]; [theMenu addItem:aMenuItem]; [aMenuItem release]; } + [dialog setContextMenu:theMenu]; [dialog setFrameTopLeftPoint:location]; @@ -149,8 +150,8 @@ [[NSApplication sharedApplication] sendEvent:theEvent]; - while([dialog waitForChoice] && [[[NSApp keyWindow] firstResponder] isKindOfClass:[SPChooseMenuItemDialogTextView class]]) { - + while ([dialog waitForChoice] && [[[NSApp keyWindow] firstResponder] isKindOfClass:[SPChooseMenuItemDialogTextView class]]) + { NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode @@ -169,4 +170,13 @@ return [dialog selectedItemIndex]; } +#pragma mark - + +- (void)dealloc +{ + [dummyTextView release]; + + [super dealloc]; +} + @end diff --git a/Source/SPContentFilterManager.h b/Source/SPContentFilterManager.h index 17ed782f..2268ba2a 100644 --- a/Source/SPContentFilterManager.h +++ b/Source/SPContentFilterManager.h @@ -39,10 +39,7 @@ @end -@interface SPContentFilterManager : NSWindowController -#ifdef SP_REFACTOR /* ivars */ -<NSOpenSavePanelDelegate> -#endif +@interface SPContentFilterManager : NSWindowController <NSOpenSavePanelDelegate> { #ifndef SP_REFACTOR /* ivars */ NSUserDefaults *prefs; diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m index c36ac380..a8a7e9fd 100644 --- a/Source/SPCopyTable.m +++ b/Source/SPCopyTable.m @@ -954,17 +954,19 @@ static const NSInteger kBlobAsImageFile = 4; if (!rowIndices || ![rowIndices count]) return; NSMutableIndexSet *selection = [NSMutableIndexSet indexSet]; -#ifndef SP_REFACTOR - NSInteger rows = [[self delegate] numberOfRowsInTableView:self]; -#else + NSInteger rows = [(id<NSTableViewDataSource>)[self delegate] numberOfRowsInTableView:self]; -#endif + NSInteger i; + if(rows > 0) { - for(NSString* idx in rowIndices) { + for (NSString* idx in rowIndices) + { i = [idx integerValue]; - if(i >= 0 && i < rows) + + if (i >= 0 && i < rows) { [selection addIndex:i]; + } } [self selectRowIndexes:selection byExtendingSelection:NO]; @@ -1075,14 +1077,13 @@ static const NSInteger kBlobAsImageFile = 4; [[control window] makeFirstResponder:control]; if([[self delegate] isKindOfClass:[SPTableContent class]] && ![self isCellEditingMode] && [[self delegate] respondsToSelector:@selector(saveRowToTable)]) [(SPTableContent*)[self delegate] saveRowToTable]; + return YES; - } // Trap down arrow key else if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(moveDown:)] ) { - // If enum field is edited ARROW key navigates through the popup list if([self isCellComplex]) return NO; @@ -1092,58 +1093,58 @@ static const NSInteger kBlobAsImageFile = 4; if (NSMaxRange([[textView string] lineRangeForRange:[textView selectedRange]]) < [[textView string] length]) return NO; - NSInteger newRow = row+1; -#ifndef SP_REFACTOR - if (newRow>=[[self delegate] numberOfRowsInTableView:self]) return YES; //check if we're already at the end of the list -#else - if (newRow>=[(id<NSTableViewDataSource>)[self delegate] numberOfRowsInTableView:self]) return YES; //check if we're already at the end of the list -#endif + NSInteger newRow = row + 1; + + // Check if we're already at the end of the list + if (newRow >= [(id<NSTableViewDataSource>)[self delegate] numberOfRowsInTableView:self]) return YES; [[control window] makeFirstResponder:control]; - if([[self delegate] isKindOfClass:[SPTableContent class]] && ![self isCellEditingMode] && [[self delegate] respondsToSelector:@selector(saveRowToTable)]) + + if ([[self delegate] isKindOfClass:[SPTableContent class]] && ![self isCellEditingMode] && [[self delegate] respondsToSelector:@selector(saveRowToTable)]) { [(SPTableContent*)([self delegate]) saveRowToTable]; + } -#ifndef SP_REFACTOR - if (newRow>=[[self delegate] numberOfRowsInTableView:self]) return YES; //check again. saveRowToTable could reload the table and change the number of rows -#else - if (newRow>=[(id<NSTableViewDataSource>)[self delegate] numberOfRowsInTableView:self]) return YES; //check again. saveRowToTable could reload the table and change the number of rows -#endif - if (tableStorage && (NSUInteger)column>=[tableStorage columnCount]) return YES; //the column count could change too + // Check again. saveRowToTable could reload the table and change the number of rows + if (newRow>=[(id<NSTableViewDataSource>)[self delegate] numberOfRowsInTableView:self]) return YES; + + // The column count could change too + if (tableStorage && (NSUInteger)column >= [tableStorage columnCount]) return YES; [self selectRowIndexes:[NSIndexSet indexSetWithIndex:newRow] byExtendingSelection:NO]; [self editColumn:column row:newRow withEvent:nil select:YES]; + return YES; } - // Trap up arrow key else if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(moveUp:)] ) { - // If enum field is edited ARROW key navigates through the popup list - if ([self isCellComplex]) - return NO; + if ([self isCellComplex]) return NO; // Check whether the editor is multiline - if so, allow the arrow up to change selection if it's not // on the first line - if ([[textView string] lineRangeForRange:[textView selectedRange]].location > 0) - return NO; + if ([[textView string] lineRangeForRange:[textView selectedRange]].location > 0) return NO; - if (row==0) return YES; //already at the beginning of the list - NSInteger newRow = row-1; + // Already at the beginning of the list + if (row == 0) return YES; + + NSInteger newRow = row - 1; [[control window] makeFirstResponder:control]; - if([[self delegate] isKindOfClass:[SPTableContent class]] && ![self isCellEditingMode] && [[self delegate] respondsToSelector:@selector(saveRowToTable)]) - [(SPTableContent*)([self delegate]) saveRowToTable]; + + if ([[self delegate] isKindOfClass:[SPTableContent class]] && ![self isCellEditingMode] && [[self delegate] respondsToSelector:@selector(saveRowToTable)]) { + [(SPTableContent *)[self delegate] saveRowToTable]; + } -#ifndef SP_REFACTOR - if (newRow>=[[self delegate] numberOfRowsInTableView:self]) return YES; // saveRowToTable could reload the table and change the number of rows -#else - if (newRow>=[(id<NSTableViewDataSource>)[self delegate] numberOfRowsInTableView:self]) return YES; // saveRowToTable could reload the table and change the number of rows -#endif - if (tableStorage && (NSUInteger)column>=[tableStorage columnCount]) return YES; //the column count could change too + // saveRowToTable could reload the table and change the number of rows + if (newRow >= [(id<NSTableViewDataSource>)[self delegate] numberOfRowsInTableView:self]) return YES; + + // The column count could change too + if (tableStorage && (NSUInteger)column>=[tableStorage columnCount]) return YES; [self selectRowIndexes:[NSIndexSet indexSetWithIndex:newRow] byExtendingSelection:NO]; [self editColumn:column row:newRow withEvent:nil select:YES]; + return YES; } diff --git a/Source/SPCustomQuery.h b/Source/SPCustomQuery.h index 982b2059..ffbe4549 100644 --- a/Source/SPCustomQuery.h +++ b/Source/SPCustomQuery.h @@ -58,10 +58,7 @@ @class SPMySQLFastStreamingResult; @class SPTextView; -@interface SPCustomQuery : NSObject -#ifdef SP_REFACTOR -<NSTableViewDataSource, NSWindowDelegate, NSTableViewDelegate> -#endif +@interface SPCustomQuery : NSObject <NSTableViewDataSource, NSWindowDelegate, NSTableViewDelegate> { IBOutlet id tableDocumentInstance; IBOutlet id tablesListInstance; diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m index 39d2d1e7..5abd0ef3 100644 --- a/Source/SPCustomQuery.m +++ b/Source/SPCustomQuery.m @@ -2594,7 +2594,7 @@ if (aTextView == textView) { if ([aTextView methodForSelector:aSelector] == [aTextView methodForSelector:@selector(insertNewline:)] && [[[NSApp currentEvent] characters] isEqualToString:@"\003"]) { - [self runAllQueries:self]; + [self runSelectedQueries:self]; return YES; } diff --git a/Source/SPDataImport.h b/Source/SPDataImport.h index 5c66b07f..0d23b104 100644 --- a/Source/SPDataImport.h +++ b/Source/SPDataImport.h @@ -41,7 +41,7 @@ typedef enum { @class SPFieldMapperController, SPFileHandle; -@interface SPDataImport : NSObject +@interface SPDataImport : NSObject <NSOpenSavePanelDelegate> { IBOutlet id tableDocumentInstance; IBOutlet id tablesListInstance; diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h index b5ea2373..ac9f45bc 100644 --- a/Source/SPDatabaseDocument.h +++ b/Source/SPDatabaseDocument.h @@ -57,18 +57,12 @@ #import "SPConnectionControllerDelegateProtocol.h" -#ifdef SP_REFACTOR /* patch */ #import <SPMySQL/SPMySQLConnectionDelegate.h> -#endif /** * The SPDatabaseDocument class controls the primary database view window. */ -@interface SPDatabaseDocument : NSObject <SPConnectionControllerDelegateProtocol -#ifdef SP_REFACTOR /* patch */ - , SPMySQLConnectionDelegate, NSTextFieldDelegate -#endif -> +@interface SPDatabaseDocument : NSObject <SPConnectionControllerDelegateProtocol, SPMySQLConnectionDelegate, NSTextFieldDelegate, NSToolbarDelegate> { #ifdef SP_REFACTOR /* patch */ id delegate; diff --git a/Source/SPEditSheetTextView.m b/Source/SPEditSheetTextView.m index 8ddbb665..8548271f 100644 --- a/Source/SPEditSheetTextView.m +++ b/Source/SPEditSheetTextView.m @@ -197,12 +197,14 @@ } // Check size and NSFileType - NSDictionary *attr = [[NSFileManager defaultManager] fileAttributesAtPath:filepath traverseLink:YES]; - if(attr) + NSDictionary *attr = [[NSFileManager defaultManager] attributesOfItemAtPath:filepath error:nil]; + + if (attr) { NSNumber *filesize = [attr objectForKey:NSFileSize]; NSString *filetype = [attr objectForKey:NSFileType]; - if(filetype == NSFileTypeRegular && filesize) + + if (filetype == NSFileTypeRegular && filesize) { // Ask for confirmation if file content is larger than 1MB if([filesize unsignedLongValue] > 1000000) diff --git a/Source/SPEditorPreferencePane.h b/Source/SPEditorPreferencePane.h index 4db496bc..29610a08 100644 --- a/Source/SPEditorPreferencePane.h +++ b/Source/SPEditorPreferencePane.h @@ -39,7 +39,7 @@ * * Editor preference pane controller. */ -@interface SPEditorPreferencePane : SPPreferencePane <SPPreferencePaneProtocol> +@interface SPEditorPreferencePane : SPPreferencePane <SPPreferencePaneProtocol, NSOpenSavePanelDelegate> { IBOutlet NSWindow *enterNameWindow; IBOutlet NSWindow *editThemeListWindow; diff --git a/Source/SPExportFile.m b/Source/SPExportFile.m index af3e738a..125adf15 100644 --- a/Source/SPExportFile.m +++ b/Source/SPExportFile.m @@ -216,7 +216,7 @@ exportFileHandle = [[SPFileHandle fileHandleForWritingAtPath:[self exportFilePath]] retain]; if (!exportFileHandle) { - [[NSFileManager defaultManager] removeFileAtPath:[self exportFilePath] handler:nil]; + [[NSFileManager defaultManager] removeItemAtPath:[self exportFilePath] error:nil]; return SPExportFileHandleFailed; } diff --git a/Source/SPFavoritesImportProtocol.h b/Source/SPFavoritesImportProtocol.h index 23a6db72..37e9fe08 100644 --- a/Source/SPFavoritesImportProtocol.h +++ b/Source/SPFavoritesImportProtocol.h @@ -31,7 +31,7 @@ // More info at <http://code.google.com/p/sequel-pro/> /** - * @protocol SPFavoritesExportProtocol SPFavoritesExportProtocol.h + * @protocol SPFavoritesImportProtocol SPFavoritesImportProtocol.h * * @author Stuart Connolly http://stuconnolly.com/ * diff --git a/Source/SPFavoritesImporter.h b/Source/SPFavoritesImporter.h index 100b7221..51bf82c9 100644 --- a/Source/SPFavoritesImporter.h +++ b/Source/SPFavoritesImporter.h @@ -42,7 +42,7 @@ @property (readwrite, assign) NSObject <SPFavoritesImportProtocol> *delegate; /** - * @property exportPath The file path to import from + * @property importPath The file path to import from */ @property (readwrite, retain) NSString *importPath; diff --git a/Source/SPFavoritesImporter.m b/Source/SPFavoritesImporter.m index 3a0c2099..f33e1705 100644 --- a/Source/SPFavoritesImporter.m +++ b/Source/SPFavoritesImporter.m @@ -100,8 +100,8 @@ */ - (void)_informDelegateOfImportCompletion:(NSError *)error { - if ([self delegate] && [[self delegate] respondsToSelector:@selector(favoritesExportCompletedWithError:)]) { - [[self delegate] performSelectorOnMainThread:@selector(favoritesExportCompletedWithError:) withObject:error waitUntilDone:NO]; + if ([self delegate] && [[self delegate] respondsToSelector:@selector(favoritesImportCompletedWithError:)]) { + [[self delegate] performSelectorOnMainThread:@selector(favoritesImportCompletedWithError:) withObject:error waitUntilDone:NO]; } } diff --git a/Source/SPFavoritesOutlineView.m b/Source/SPFavoritesOutlineView.m index 3688f769..f4fc3a7a 100644 --- a/Source/SPFavoritesOutlineView.m +++ b/Source/SPFavoritesOutlineView.m @@ -33,7 +33,7 @@ #import "SPFavoritesOutlineView.h" #import "SPConnectionControllerDelegate.h" -static NSUInteger SPFavoritesOutlineViewUnindent = 14; +static NSUInteger SPFavoritesOutlineViewUnindent = 6; @implementation SPFavoritesOutlineView @@ -98,8 +98,9 @@ static NSUInteger SPFavoritesOutlineViewUnindent = 14; } /** - * Don't reserve a gap for the disclosure triangles for top-level items. This involves reducing the - * padding - and increasing the width - of all rows to compensate. + * Disclosure triangles for the top-level items hae been removed, and similarly other + * paddings need altering. This involves increasing the padding - and reducing the width - + * of all rows to compensate. */ - (NSRect)frameOfCellAtColumn:(NSInteger)columnIndex row:(NSInteger)rowIndex { @@ -110,11 +111,18 @@ static NSUInteger SPFavoritesOutlineViewUnindent = 14; return superFrame; } - return NSMakeRect(superFrame.origin.x - SPFavoritesOutlineViewUnindent, superFrame.origin.y, superFrame.size.width + SPFavoritesOutlineViewUnindent, superFrame.size.height); + // Don't alter padding for the top-level items + if ([[self delegate] respondsToSelector:@selector(outlineView:isGroupItem:)]) { + if ([[self delegate] outlineView:self isGroupItem:[self itemAtRow:rowIndex]]) { + return superFrame; + } + } + + return NSMakeRect(superFrame.origin.x + SPFavoritesOutlineViewUnindent, superFrame.origin.y, superFrame.size.width - SPFavoritesOutlineViewUnindent, superFrame.size.height); } /** - * As no gap is reserved for the disclosure triangles at the top level, the frames for other + * Disclosure triangles for the top-level items have been removed, the frames for other * disclosure items need to be similarly moved. */ - (NSRect)frameOfOutlineCellAtRow:(NSInteger)rowIndex @@ -129,8 +137,8 @@ static NSUInteger SPFavoritesOutlineViewUnindent = 14; } // On versions of Lion or above, amend the padding appropriately - if (systemVersion >= 0x1070 && superFrame.origin.x > SPFavoritesOutlineViewUnindent) { - return NSMakeRect(superFrame.origin.x - SPFavoritesOutlineViewUnindent, superFrame.origin.y, superFrame.size.width, superFrame.size.height); + if (systemVersion >= 0x1070) { + return NSMakeRect(superFrame.origin.x + SPFavoritesOutlineViewUnindent, superFrame.origin.y, superFrame.size.width, superFrame.size.height); } return superFrame; diff --git a/Source/SPFieldEditorController.h b/Source/SPFieldEditorController.h index fb3b6b80..a920c9b0 100644 --- a/Source/SPFieldEditorController.h +++ b/Source/SPFieldEditorController.h @@ -40,10 +40,7 @@ * This class offers a sheet for editing different kind of data such as text, blobs (including images) as * editSheet and bit fields as bitSheet. */ -@interface SPFieldEditorController : NSWindowController -#ifdef SP_REFACTOR -<NSComboBoxDataSource> -#endif +@interface SPFieldEditorController : NSWindowController <NSComboBoxDataSource> { IBOutlet id editSheetProgressBar; IBOutlet id editSheetSegmentControl; diff --git a/Source/SPFieldMapperController.h b/Source/SPFieldMapperController.h index 2f2a5920..79b73bcc 100644 --- a/Source/SPFieldMapperController.h +++ b/Source/SPFieldMapperController.h @@ -35,10 +35,7 @@ @class SPTablesList; @class SPMySQLConnection; -@interface SPFieldMapperController : NSWindowController -#ifdef SP_REFACTOR -<NSTokenFieldCellDelegate> -#endif +@interface SPFieldMapperController : NSWindowController <NSTokenFieldCellDelegate> { IBOutlet SPTableView *fieldMapperTableView; IBOutlet id fieldMapperTableScrollView; diff --git a/Source/SPNarrowDownCompletion.h b/Source/SPNarrowDownCompletion.h index 02a4ddc0..073844a1 100644 --- a/Source/SPNarrowDownCompletion.h +++ b/Source/SPNarrowDownCompletion.h @@ -34,11 +34,7 @@ @class SPDatabaseStructure; -#ifndef SP_REFACTOR -@interface SPNarrowDownCompletion : NSWindow -#else @interface SPNarrowDownCompletion : NSWindow <NSTableViewDelegate, NSTableViewDataSource, NSTokenFieldCellDelegate> -#endif { NSArray* suggestions; NSMutableString* mutablePrefix; diff --git a/Source/SPNavigatorOutlineView.m b/Source/SPNavigatorOutlineView.m index 17252750..c0772ebd 100644 --- a/Source/SPNavigatorOutlineView.m +++ b/Source/SPNavigatorOutlineView.m @@ -44,7 +44,7 @@ { // Enter or Return selects in active document the chosen item if ([self numberOfSelectedRows] == 1 && ([theEvent keyCode] == 36 || [theEvent keyCode] == 76)) { - [[self delegate] selectInActiveDocumentItem:[self itemAtRow:[self selectedRow]] fromView:self]; + [(SPNavigatorController *)[self delegate] selectInActiveDocumentItem:[self itemAtRow:[self selectedRow]] fromView:self]; return; } diff --git a/Source/SPPreferenceController.h b/Source/SPPreferenceController.h index 23c2fdb8..3e7bdf23 100644 --- a/Source/SPPreferenceController.h +++ b/Source/SPPreferenceController.h @@ -46,7 +46,7 @@ * * Main preferences window controller. */ -@interface SPPreferenceController : NSWindowController +@interface SPPreferenceController : NSWindowController <NSToolbarDelegate> { // Preference pane controllers IBOutlet SPGeneralPreferencePane <SPPreferencePaneProtocol> *generalPreferencePane; diff --git a/Source/SPQueryFavoriteManager.h b/Source/SPQueryFavoriteManager.h index a0a62bdd..017e3cc1 100644 --- a/Source/SPQueryFavoriteManager.h +++ b/Source/SPQueryFavoriteManager.h @@ -40,10 +40,7 @@ @end -@interface SPQueryFavoriteManager : NSWindowController -#ifdef SP_REFACTOR -<NSOpenSavePanelDelegate> -#endif +@interface SPQueryFavoriteManager : NSWindowController <NSOpenSavePanelDelegate> { #ifndef SP_REFACTOR /* ivars */ NSUserDefaults *prefs; diff --git a/Source/SPSplitView.h b/Source/SPSplitView.h index 1b699671..b181d1ce 100644 --- a/Source/SPSplitView.h +++ b/Source/SPSplitView.h @@ -32,9 +32,9 @@ @class SPSplitViewAnimationRetainCycleBypass; -@interface SPSplitView : NSSplitView +@interface SPSplitView : NSSplitView <NSSplitViewDelegate> { - NSObject *delegate; + id<NSSplitViewDelegate> delegate; IBOutlet NSButton *collapseToggleButton; IBOutlet NSView *additionalDragHandleView; diff --git a/Source/SPSplitView.m b/Source/SPSplitView.m index 2793fd87..4930e171 100644 --- a/Source/SPSplitView.m +++ b/Source/SPSplitView.m @@ -120,7 +120,7 @@ #pragma mark - #pragma mark Delegate management -- (void)setDelegate:(NSObject *)aDelegate +- (void)setDelegate:(id<NSSplitViewDelegate>)aDelegate { delegate = aDelegate; } @@ -699,6 +699,7 @@ [self _ensureDefaultSubviewSizesToIndex:l-1]; delegate = [super delegate]; + [super setDelegate:self]; } @@ -1089,7 +1090,8 @@ } // Check for a first responder to restore, using the "true" first responder for field editors - NSResponder *firstResponderToRestore = [[self window] firstResponder]; + NSResponder<NSTextDelegate> *firstResponderToRestore = [[self window] firstResponder]; + if ([firstResponderToRestore respondsToSelector:@selector(isFieldEditor)] && [(NSText *)firstResponderToRestore isFieldEditor]) { firstResponderToRestore = [(NSText *)firstResponderToRestore delegate]; } diff --git a/Source/SPSyntaxParser.h b/Source/SPSyntaxParser.h new file mode 100644 index 00000000..74fbb9bc --- /dev/null +++ b/Source/SPSyntaxParser.h @@ -0,0 +1,38 @@ +// +// $Id$ +// +// SPSyntaxParser.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on January 25, 2013. +// Copyright (c) 2013 Stuart Connolly. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + +/** + * Variable and prototype definitions required for flex syntax hightlighting parsing. + */ +extern NSUInteger yylex(); +extern NSUInteger yyuoffset, yyuleng; +typedef struct yy_buffer_state *YY_BUFFER_STATE; +void yy_switch_to_buffer(YY_BUFFER_STATE); +YY_BUFFER_STATE yy_scan_string(const char *); diff --git a/Source/SPTableContent.h b/Source/SPTableContent.h index 3d191da4..fcc106b2 100644 --- a/Source/SPTableContent.h +++ b/Source/SPTableContent.h @@ -51,10 +51,7 @@ @class SPSplitView; #endif -@interface SPTableContent : NSObject -#ifdef SP_REFACTOR -<NSTableViewDelegate, NSTableViewDataSource, NSComboBoxDataSource, NSComboBoxDelegate> -#endif +@interface SPTableContent : NSObject <NSTableViewDelegate, NSTableViewDataSource, NSComboBoxDataSource, NSComboBoxDelegate> { IBOutlet SPDatabaseDocument *tableDocumentInstance; IBOutlet id tablesListInstance; diff --git a/Source/SPTableContentDelegate.m b/Source/SPTableContentDelegate.m index e0064337..e1976762 100644 --- a/Source/SPTableContentDelegate.m +++ b/Source/SPTableContentDelegate.m @@ -756,13 +756,13 @@ * Trap the enter, escape, tab and arrow keys, overriding default behaviour and continuing/ending editing, * only within the current row. */ -- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command +- (BOOL)control:(NSControl<NSControlTextEditingDelegate> *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command { #ifndef SP_REFACTOR // Check firstly if SPCopyTable can handle command if ([control control:control textView:textView doCommandBySelector:(SEL)command]) #else - if ([(id<NSControlTextEditingDelegate>)control control:control textView:textView doCommandBySelector:(SEL)command]) + if ([control control:control textView:textView doCommandBySelector:(SEL)command]) #endif return YES; diff --git a/Source/SPTableView.m b/Source/SPTableView.m index 8ec61f0a..61c63c75 100644 --- a/Source/SPTableView.m +++ b/Source/SPTableView.m @@ -42,7 +42,7 @@ @end -@interface SPTableView (PrivateAPI) +@interface SPTableView () - (void)_doubleClickAction; - (void)_disableDoubleClickAction:(NSNotification *)notification; @@ -50,32 +50,37 @@ @end - @implementation SPTableView @synthesize tabEditingDisabled; -- (id) init +- (id)init { if ((self = [super init])) { emptyDoubleClickAction = NULL; } + return self; } -- (void) awakeFromNib +- (void)awakeFromNib { [super setDoubleAction:@selector(_doubleClickAction)]; - if ([NSTableView instancesRespondToSelector:@selector(awakeFromNib)]) + + if ([NSTableView instancesRespondToSelector:@selector(awakeFromNib)]) { [super awakeFromNib]; + } } +#pragma mark - + /** * Track window changes, in order to add listeners for when sheets are shown * or hidden; this allows the double-click action to be disabled while sheets * are open, preventing beeps when using the field editor on double-click. */ -- (void) viewWillMoveToWindow:(NSWindow *)aWindow { +- (void)viewWillMoveToWindow:(NSWindow *)aWindow +{ NSNotificationCenter *notifier = [NSNotificationCenter defaultCenter]; [notifier removeObserver:self name:NSWindowWillBeginSheetNotification object:nil]; @@ -87,8 +92,6 @@ } } -#pragma mark - - /** * Right-click at row will select that row before ordering out the contextual menu * if not more than one row is selected. @@ -100,7 +103,7 @@ SPDatabaseDocument *parentTableDocument = nil; if ([[[[[self window] delegate] class] description] isEqualToString:@"SPWindowController"]) { - parentTableDocument = [[[self window] delegate] selectedTableDocument]; + parentTableDocument = [(SPWindowController *)[[self window] delegate] selectedTableDocument]; } // If SPDatabaseDocument is performing a task suppress any context menu @@ -150,11 +153,14 @@ * display instead; this prevents the selected cell from automatically editing * if the table is backtabbed to. */ -- (BOOL)becomeFirstResponder { +- (BOOL)becomeFirstResponder +{ if (tabEditingDisabled) { [self display]; + return YES; } + return [super becomeFirstResponder]; } @@ -208,9 +214,11 @@ else if (tabEditingDisabled && [[theEvent characters] length] && [[theEvent characters] characterAtIndex:0] == NSTabCharacter) { if (([theEvent modifierFlags] & NSShiftKeyMask) != NSShiftKeyMask) { [[self window] selectKeyViewFollowingView:self]; - } else { + } + else { [[self window] selectKeyViewPrecedingView:self]; } + return; } @@ -277,11 +285,6 @@ #endif -@end - - -@implementation SPTableView (PrivateAPI) - /** * On a double click, determine whether the action was in the empty area * of the current table; if so, perform the assigned emptyDoubleClick action. diff --git a/Source/SPTablesList.h b/Source/SPTablesList.h index 8d267c71..1d4fd6ca 100644 --- a/Source/SPTablesList.h +++ b/Source/SPTablesList.h @@ -44,10 +44,7 @@ @class SQLSidebarViewController; #endif -@interface SPTablesList : NSObject -#ifdef SP_REFACTOR -<NSTextFieldDelegate> -#endif +@interface SPTablesList : NSObject <NSTextFieldDelegate, NSTableViewDelegate> { IBOutlet SPDatabaseDocument *tableDocumentInstance; IBOutlet SPTableStructure *tableSourceInstance; diff --git a/Source/SPTextView.h b/Source/SPTextView.h index b6348407..d596395d 100644 --- a/Source/SPTextView.h +++ b/Source/SPTextView.h @@ -40,10 +40,7 @@ @class SPCopyTable; @class NoodleLineNumberView; -@interface SPTextView : NSTextView -#ifdef SP_REFACTOR -<NSTextStorageDelegate> -#endif +@interface SPTextView : NSTextView <NSTextStorageDelegate> { IBOutlet SPDatabaseDocument *tableDocumentInstance; IBOutlet SPTablesList *tablesListInstance; diff --git a/Source/SPTextView.m b/Source/SPTextView.m index e7f15e5e..9a29460e 100644 --- a/Source/SPTextView.m +++ b/Source/SPTextView.m @@ -52,23 +52,12 @@ #import "SPBundleCommandRunner.h" #import "NoodleLineNumberView.h" #import "SPCopyTable.h" +#import "SPEditorTokens.h" +#import "SPSyntaxParser.h" #import <SPMySQL/SPMySQL.h> #pragma mark - -#pragma mark lex init - -/** - * Include all the extern variables and prototypes required for flex (used for syntax highlighting) - */ -#import "SPEditorTokens.h" -extern NSUInteger yylex(); -extern NSUInteger yyuoffset, yyuleng; -typedef struct yy_buffer_state *YY_BUFFER_STATE; -void yy_switch_to_buffer(YY_BUFFER_STATE); -YY_BUFFER_STATE yy_scan_string (const char *); - -#pragma mark - #pragma mark attribute definition #define kAPlinked @"Linked" // attribute for a via auto-pair inserted char @@ -83,7 +72,7 @@ YY_BUFFER_STATE yy_scan_string (const char *); #define kBTQuoteValue @"isBTQuoted" #pragma mark - -#pragma mark constant definitions +#pragma mark Constant definitions #define SP_CQ_SEARCH_IN_MYSQL_HELP_MENU_ITEM_TAG 1000 #define SP_CQ_COPY_AS_RTF_MENU_ITEM_TAG 1001 @@ -102,7 +91,6 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse); @end - // some helper functions for handling rectangles and points // needed in roundedBezierPathAroundRange: static inline CGFloat SPRectTop(NSRect rectangle) { return rectangle.origin.y; } @@ -3460,11 +3448,8 @@ static inline NSPoint SPPointOnLine(NSPoint a, NSPoint b, CGFloat t) { return NS } // Check size and NSFileType -#ifndef SP_REFACTOR - NSDictionary *attr = [[NSFileManager defaultManager] fileAttributesAtPath:filepath traverseLink:YES]; -#else NSDictionary *attr = [[NSFileManager defaultManager] attributesOfItemAtPath:filepath error:nil]; -#endif + if(attr) { NSNumber *filesize = [attr objectForKey:NSFileSize]; diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index 0857bbb9..de3b955b 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -802,7 +802,7 @@ [menu removeItem:bItem]; } - if([[[[[[NSApp delegate] frontDocumentWindow] delegate] selectedTableDocument] connectionID] isEqualToString:@"_"]) return menu; + if ([[[(SPWindowController *)[[[NSApp delegate] frontDocumentWindow] delegate] selectedTableDocument] connectionID] isEqualToString:@"_"]) return menu; [[NSApp delegate] reloadBundles:self]; diff --git a/Source/SPWindowAdditions.m b/Source/SPWindowAdditions.m index 9cec1a7c..6966b311 100644 --- a/Source/SPWindowAdditions.m +++ b/Source/SPWindowAdditions.m @@ -82,9 +82,9 @@ */ - (void)swipeWithEvent:(NSEvent *)event { - if (![[self delegate] isKindOfClass:[SPWindowController class]] || ![[[self delegate] documents] count]) return; + if (![[self delegate] isKindOfClass:[SPWindowController class]] || ![[(SPWindowController *)[self delegate] documents] count]) return; - id frontDoc = [[self delegate] selectedTableDocument]; + id frontDoc = [(SPWindowController *)[self delegate] selectedTableDocument]; if (frontDoc && [frontDoc isKindOfClass:[SPDatabaseDocument class]] && [frontDoc valueForKeyPath:@"spHistoryControllerInstance"] && ![frontDoc isWorking]) { diff --git a/Source/SPWindowController.h b/Source/SPWindowController.h index 964cedd5..39b70dcf 100644 --- a/Source/SPWindowController.h +++ b/Source/SPWindowController.h @@ -33,7 +33,7 @@ @class PSMTabBarControl; @class SPDatabaseDocument; -@interface SPWindowController : NSWindowController +@interface SPWindowController : NSWindowController <NSWindowDelegate> { IBOutlet PSMTabBarControl *tabBar; IBOutlet NSTabView *tabView; diff --git a/Source/SequelProTunnelAssistant.m b/Source/SequelProTunnelAssistant.m index 55ee2ee7..73e9c71c 100644 --- a/Source/SequelProTunnelAssistant.m +++ b/Source/SequelProTunnelAssistant.m @@ -40,6 +40,7 @@ int main(int argc, const char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSDictionary *environment = [[NSProcessInfo processInfo] environment]; NSString *argument = nil; SPSSHTunnel *sequelProTunnel; @@ -57,19 +58,27 @@ int main(int argc, const char *argv[]) // Check if we're being asked a question and respond if so if (argument && [argument rangeOfString:@" (yes/no)?"].location != NSNotFound) { + sequelProTunnel = (SPSSHTunnel *)[NSConnection rootProxyForConnectionWithRegisteredName:connectionName host:nil]; + if (!sequelProTunnel) { NSLog(@"SSH Tunnel: unable to connect to Sequel Pro to show SSH question"); [pool release]; return 1; + } + BOOL response = [sequelProTunnel getResponseForQuestion:argument]; + if (response) { printf("yes\n"); - } else { + } + else { printf("no\n"); } + [pool release]; + return 0; } @@ -90,15 +99,19 @@ int main(int argc, const char *argv[]) } keychain = [[SPKeychain alloc] init]; + if ([keychain passwordExistsForName:keychainName account:keychainAccount]) { printf("%s\n", [[keychain getPasswordForName:keychainName account:keychainAccount] UTF8String]); [keychain release]; [pool release]; return 0; } + + [keychain release]; // If retrieving the password failed, log an error and fall back to requesting from the GUI NSLog(@"SSH Tunnel: specified keychain password not found"); + argument = [NSString stringWithFormat:NSLocalizedString(@"The SSH password could not be loaded from the keychain; please enter the SSH password for %@:", @"Prompt for SSH password when keychain fetch failed"), connectionName]; } @@ -113,6 +126,7 @@ int main(int argc, const char *argv[]) } sequelProTunnel = (SPSSHTunnel *)[NSConnection rootProxyForConnectionWithRegisteredName:connectionName host:nil]; + if (!sequelProTunnel) { NSLog(@"SSH Tunnel: unable to connect to Sequel Pro for internal authentication"); [pool release]; @@ -120,6 +134,7 @@ int main(int argc, const char *argv[]) } password = [sequelProTunnel getPasswordWithVerificationHash:verificationHash]; + if (password) { printf("%s\n", [password UTF8String]); [pool release]; @@ -128,6 +143,7 @@ int main(int argc, const char *argv[]) // If retrieving the password failed, log an error and fall back to requesting from the GUI NSLog(@"SSH Tunnel: unable to successfully request password from Sequel Pro for internal authentication"); + argument = [NSString stringWithFormat:NSLocalizedString(@"The SSH password could not be loaded; please enter the SSH password for %@:", @"Prompt for SSH password when direct fetch failed"), connectionName]; } } @@ -141,12 +157,14 @@ int main(int argc, const char *argv[]) // Check whether the passphrase is in the keychain, using standard OS X sshagent name and account SPKeychain *keychain = [[SPKeychain alloc] init]; + if ([keychain passwordExistsForName:@"SSH" account:keyName]) { printf("%s\n", [[keychain getPasswordForName:@"SSH" account:keyName] UTF8String]); [keychain release]; [pool release]; return 0; } + [keychain release]; } @@ -159,19 +177,23 @@ int main(int argc, const char *argv[]) } sequelProTunnel = (SPSSHTunnel *)[NSConnection rootProxyForConnectionWithRegisteredName:connectionName host:nil]; + if (!sequelProTunnel) { NSLog(@"SSH Tunnel: unable to connect to Sequel Pro to show SSH question"); [pool release]; return 1; } passphrase = [sequelProTunnel getPasswordForQuery:argument verificationHash:verificationHash]; + if (!passphrase) { [pool release]; return 1; } printf("%s\n", [passphrase UTF8String]); + [pool release]; + return 0; } @@ -186,6 +208,7 @@ int main(int argc, const char *argv[]) } sequelProTunnel = (SPSSHTunnel *)[NSConnection rootProxyForConnectionWithRegisteredName:connectionName host:nil]; + if (!sequelProTunnel) { NSLog(@"SSH Tunnel: unable to connect to Sequel Pro to show SSH question"); [pool release]; @@ -193,6 +216,7 @@ int main(int argc, const char *argv[]) } passphrase = [sequelProTunnel getPasswordForQuery:argument verificationHash:verificationHash]; + if (!passphrase) { [pool release]; return 1; @@ -205,5 +229,6 @@ int main(int argc, const char *argv[]) [pool release]; + return 1; } |