From cc2e00c656a34d4c472a25f929282c8fc63d0174 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Tue, 30 Nov 2010 00:16:06 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Bundle=20commands=20-=20before=20closing=20?= =?UTF-8?q?a=20db=20doc=20window=20kill=20all=20commands=20associated=20to?= =?UTF-8?q?=20this=20doc=20-=20suppress=20an=20error=20message=20if=20a=20?= =?UTF-8?q?bash=20command=20was=20killed=20via=20code=209=20-=20added=20a?= =?UTF-8?q?=20temporary=20and=20preliminary=20table=20view=20to=20display?= =?UTF-8?q?=20command=20activities=20(double-click=20at=20TABLE=20INFO=20h?= =?UTF-8?q?eader=20to=20toggle=20and=20refresh=20it=20-=20only=20for=20tes?= =?UTF-8?q?ting=20purposes=20-=20it=20shows=20all=20commands=20started=20f?= =?UTF-8?q?rom=20that=20db=20doc=20and=20a=20General=20command=20names)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 2 +- Source/SPCopyTable.m | 2 +- Source/SPDatabaseDocument.m | 17 ++++++++++ Source/SPTableInfo.h | 10 +++++- Source/SPTableInfo.m | 76 ++++++++++++++++++++++++++++++++++++-------- Source/SPTextView.m | 2 +- Source/SPTextViewAdditions.m | 2 +- 7 files changed, 93 insertions(+), 18 deletions(-) (limited to 'Source') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 12b9e9a4..ad456b89 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -818,7 +818,7 @@ } } } - } else { + } else if([err code] != 9) { // Suppress an error message if command was killed NSString *errorMessage = [err localizedDescription]; SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [NSApp mainWindow], self, nil, nil, [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]); diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m index f06c4700..94e0eb45 100644 --- a/Source/SPCopyTable.m +++ b/Source/SPCopyTable.m @@ -960,7 +960,7 @@ NSInteger MENU_EDIT_COPY_AS_SQL = 2003; } } } - } else { + } else if([err code] != 9) { // Suppress an error message if command was killed NSString *errorMessage = [err localizedDescription]; SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]); diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 23805b12..8ec6ad61 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -3655,6 +3655,7 @@ */ - (BOOL)parentTabShouldClose { + // If no connection is available, always return YES. Covers initial setup and disconnections. if(!_isConnected) return YES; @@ -3673,8 +3674,23 @@ return isSaved; } + // Terminate all running BASH commands + for(NSDictionary* cmd in [self runningBASHProcesses]) { + NSInteger pid = [[cmd objectForKey:@"pid"] intValue]; + NSTask *killTask = [[NSTask alloc] init]; + [killTask setLaunchPath:@"/bin/sh"]; + [killTask setArguments:[NSArray arrayWithObjects:@"-c", [NSString stringWithFormat:@"kill -9 -%ld", pid], nil]]; + [killTask launch]; + [killTask waitUntilExit]; + [killTask release]; + } + [[SPNavigatorController sharedNavigatorController] performSelectorOnMainThread:@selector(removeConnection:) withObject:[self connectionID] waitUntilDone:YES]; + // Note that this call does not need to be removed in release builds as leaks analysis output is only + // dumped if [[SPLogger logger] setDumpLeaksOnTermination]; has been called first. + [[SPLogger logger] dumpLeaks]; + // Return YES by default return YES; } @@ -3703,6 +3719,7 @@ [createTableSyntaxWindow orderOut:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self]; [self setParentWindow:nil]; + } /** diff --git a/Source/SPTableInfo.h b/Source/SPTableInfo.h index 041f9173..bae3da4e 100644 --- a/Source/SPTableInfo.h +++ b/Source/SPTableInfo.h @@ -29,10 +29,18 @@ IBOutlet id tableListInstance; IBOutlet id tableDataInstance; IBOutlet id tableDocumentInstance; - + + IBOutlet NSTableView *activitiesTable; + + IBOutlet NSScrollView *tableInfoScrollView; + IBOutlet NSScrollView *activitiesScrollView; + IBOutlet NSView *containerView; + NSMutableArray *info; + NSMutableArray *activities; } - (void)tableChanged:(NSNotification *)notification; +- (void)updateActivities; @end diff --git a/Source/SPTableInfo.m b/Source/SPTableInfo.m index 0270c097..ba24040a 100644 --- a/Source/SPTableInfo.m +++ b/Source/SPTableInfo.m @@ -39,7 +39,8 @@ - (id)init { if ((self = [super init])) { - info = [[NSMutableArray alloc] init]; + info = [[NSMutableArray alloc] init]; + activities = [[NSMutableArray alloc] init]; } return self; @@ -52,6 +53,14 @@ name:SPTableChangedNotification object:tableDocumentInstance]; + [tableInfoScrollView setAlphaValue:1.0f]; + [activitiesScrollView setAlphaValue:0.0f]; + + // [self performSelector:@selector(updateActivities) withObject:nil afterDelay:1.0f]; + + [activities addObject:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"ACTIVITIES", @"header for activities pane"), @"name", nil]]; + [activitiesTable reloadData]; + [info addObject:NSLocalizedString(@"TABLE INFORMATION", @"header for table info pane")]; [infoTable reloadData]; } @@ -61,10 +70,23 @@ [[NSNotificationCenter defaultCenter] removeObserver:self]; [info release]; + [activities release]; [super dealloc]; } +- (void)updateActivities +{ + NSMutableArray *acts = [NSMutableArray array]; + [acts removeAllObjects]; + [acts addObject:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"ACTIVITIES", @"header for activities pane"), @"name", nil]]; + [acts addObjectsFromArray:[tableDocumentInstance runningBASHProcesses]]; + [acts addObjectsFromArray:[[NSApp delegate] runningBASHProcesses]]; + [activities setArray:acts]; + [activitiesTable reloadData]; + // [self performSelector:@selector(updateActivities) withObject:nil afterDelay:1.0f]; +} + /** * Notification to indicate the table has changed and that the table info requires * reloading for display. This is called on table changes, and also (with a nil argument) @@ -251,12 +273,23 @@ - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView { - return [info count]; + if(aTableView == infoTable) { + return [info count]; + } else { + return [activities count]; + } } - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { - return [info objectAtIndex:rowIndex]; + if(aTableView == infoTable) { + return [info objectAtIndex:rowIndex]; + } else { + if(rowIndex > -1 && rowIndex < [activities count]) + return [NSArrayObjectAtIndex(activities,rowIndex) objectForKey:@"name"]; + else + return @"..."; + } } - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row @@ -264,11 +297,26 @@ return (row == 0 ? 25 : [tableView rowHeight]); } - - (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex { - // row 1 and 6 should be editable - ie be able to rename the table and change the auto_increment value. - return NO;//(rowIndex == 1 || rowIndex == 6 ); + if(rowIndex == 0) return YES; + return NO; +} + +- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex +{ + if(rowIndex > 0) return NO; + if([tableInfoScrollView alphaValue] == 1.0f) { + [tableInfoScrollView setAlphaValue:0.0f]; + [activitiesScrollView setAlphaValue:1.0f]; + } else { + [tableInfoScrollView setAlphaValue:1.0f]; + [activitiesScrollView setAlphaValue:0.0f]; + } + [infoTable deselectAll:nil]; + [activitiesTable deselectAll:nil]; + [self updateActivities]; + return NO; } - (BOOL)tableView:(NSTableView *)aTableView isGroupRow:(NSInteger)row @@ -279,13 +327,15 @@ - (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { - if ((rowIndex > 0) && [[aTableColumn identifier] isEqualToString:@"info"]) { - [(ImageAndTextCell*)aCell setImage:[NSImage imageNamed:@"table-property"]]; - [(ImageAndTextCell*)aCell setIndentationLevel:1]; - [(ImageAndTextCell*)aCell setDrawsBackground:NO]; - } else { - [(ImageAndTextCell*)aCell setImage:nil]; - [(ImageAndTextCell*)aCell setIndentationLevel:0]; + if(aTableView == infoTable) { + if ((rowIndex > 0) && [[aTableColumn identifier] isEqualToString:@"info"]) { + [(ImageAndTextCell*)aCell setImage:[NSImage imageNamed:@"table-property"]]; + [(ImageAndTextCell*)aCell setIndentationLevel:1]; + [(ImageAndTextCell*)aCell setDrawsBackground:NO]; + } else { + [(ImageAndTextCell*)aCell setImage:nil]; + [(ImageAndTextCell*)aCell setIndentationLevel:0]; + } } } diff --git a/Source/SPTextView.m b/Source/SPTextView.m index c458e7b1..85d2623a 100644 --- a/Source/SPTextView.m +++ b/Source/SPTextView.m @@ -1718,7 +1718,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) NSString *cmdResult = [[theHintString substringWithRange:cmdRange] runBashCommandWithEnvironment:nil atCurrentDirectoryPath:nil error:&err]; if(err == nil) { [theHintString replaceCharactersInRange:tagRange withString:cmdResult]; - } else { + } else if([err code] != 9) { // Suppress an error message if command was killed NSString *errorMessage = [err localizedDescription]; SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [theHintString substringWithRange:cmdRange], errorMessage]); diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index f75505df..e613dac1 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -667,7 +667,7 @@ } } - } else { + } else if([err code] != 9) { // Suppress an error message if command was killed NSString *errorMessage = [err localizedDescription]; SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]); -- cgit v1.2.3