From 08fb692301568e7143271ffad9bbcb3a5b247de5 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 13 Jan 2010 20:53:39 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20several=20sheetDidEnd=20selectors?= =?UTF-8?q?=20to=20close=20a=20NSAlert=20or=20NSWindow=20properly=20to=20a?= =?UTF-8?q?void=20overlapping=20sheets=20=E2=80=A2=20F5=20completion=20-?= =?UTF-8?q?=20if=20a=20table=20is=20selected=20and=20no=20further=20parsin?= =?UTF-8?q?g=20info=20is=20given=20show=20that=20table=20and=20its=20field?= =?UTF-8?q?s=20at=20the=20top=20of=20the=20suggestions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 13 ++++++++++--- Source/SPProcessListController.m | 7 +++++++ Source/TableDocument.m | 9 ++++++++- Source/TableSource.m | 9 ++++++--- Source/TablesList.m | 23 ++++++++++++++++++++--- 5 files changed, 51 insertions(+), 10 deletions(-) diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 1359b8d8..06ada98e 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -216,6 +216,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) NSString *currentDb = nil; NSString *currentTable = nil; + if ([[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"selectedDatabase"] != nil) currentDb = [[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKeyPath:@"selectedDatabase"]; if ([[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"tableName"] != nil) @@ -257,12 +258,18 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) for(id db in sortedDbs) { NSArray *allTables = [[dbs objectForKey:db] allKeys]; - NSArray *sortedTables; + NSMutableArray *sortedTables = [NSMutableArray array]; if(aTableNameExists) { - sortedTables = [NSArray arrayWithObject:aTableName]; + [sortedTables addObject:aTableName]; } else { [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:db, @"display", @"database-small", @"image", nil]]; - sortedTables= [allTables sortedArrayUsingDescriptors:[NSArray arrayWithObject:desc]]; + [sortedTables addObjectsFromArray:[allTables sortedArrayUsingDescriptors:[NSArray arrayWithObject:desc]]]; + // if(aDbName == nil && aTableName) { + if([sortedTables count] > 1 && [sortedTables containsObject:currentTable]) { + [sortedTables removeObject:currentTable]; + [sortedTables insertObject:currentTable atIndex:0]; + } + // } } for(id table in sortedTables) { NSDictionary * theTable = [[dbs objectForKey:db] objectForKey:table]; diff --git a/Source/SPProcessListController.m b/Source/SPProcessListController.m index fb3dec5d..98137fb4 100644 --- a/Source/SPProcessListController.m +++ b/Source/SPProcessListController.m @@ -274,6 +274,13 @@ */ - (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo { + + // Order out current sheet to suppress overlapping of sheets + if ([sheet respondsToSelector:@selector(orderOut:)]) + [sheet orderOut:nil]; + else if ([sheet respondsToSelector:@selector(window)]) + [[sheet window] orderOut:nil]; + if (returnCode == NSAlertDefaultReturn) { NSUInteger processId = [[[processes objectAtIndex:[processListTableView selectedRow]] valueForKey:@"Id"] integerValue]; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 88578b08..f61ead71 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -1130,8 +1130,15 @@ * if contextInfo == removeDatabase -> Remove the selected database * if contextInfo == addDatabase -> Add a new database */ -- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo +- (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo { + + // Order out current sheet to suppress overlapping of sheets + if ([sheet respondsToSelector:@selector(orderOut:)]) + [sheet orderOut:nil]; + else if ([sheet respondsToSelector:@selector(window)]) + [[sheet window] orderOut:nil]; + // Remove the current database if ([contextInfo isEqualToString:@"removeDatabase"]) { if (returnCode == NSAlertDefaultReturn) { diff --git a/Source/TableSource.m b/Source/TableSource.m index 4feadddb..7f943850 100644 --- a/Source/TableSource.m +++ b/Source/TableSource.m @@ -872,10 +872,13 @@ fetches the result as an array with a dictionary for each row in it * if contextInfo == addIndex: adds and index to the mysql-db if user hits ok * if contextInfo == cannotremovefield: do nothing */ -- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo -{ +- (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo +{ // Order out current sheet to suppress overlapping of sheets - if ([sheet respondsToSelector:@selector(orderOut:)]) [sheet orderOut:nil]; + if ([sheet respondsToSelector:@selector(orderOut:)]) + [sheet orderOut:nil]; + else if ([sheet respondsToSelector:@selector(window)]) + [[sheet window] orderOut:nil]; if ([contextInfo isEqualToString:@"addrow"]) { diff --git a/Source/TablesList.m b/Source/TablesList.m index 742ac458..baca3e8a 100644 --- a/Source/TablesList.m +++ b/Source/TablesList.m @@ -510,6 +510,8 @@ // Order out current sheet to suppress overlapping of sheets if ([sheet respondsToSelector:@selector(orderOut:)]) [sheet orderOut:nil]; + else if ([sheet respondsToSelector:@selector(window)]) + [[sheet window] orderOut:nil]; if ([contextInfo isEqualToString:@"addRow"]) { alertSheetOpened = NO; @@ -1886,9 +1888,24 @@ // Couldn't truncate table if (![[mySQLConnection getLastErrorMessage] isEqualTo:@""]) { - NSBeginAlertSheet(NSLocalizedString(@"Error truncating table", @"error truncating table message"), - NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to truncate the table '%@'.\n\nMySQL said: %@", @"error truncating table informative message"), [filteredTables objectAtIndex:currentIndex], [mySQLConnection getLastErrorMessage]]); + // NSBeginAlertSheet(NSLocalizedString(@"Error truncating table", @"error truncating table message"), + // NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, @selector(sheetDidEnd:returnCode:contextInfo:), nil, nil, + // [NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to truncate the table '%@'.\n\nMySQL said: %@", @"error truncating table informative message"), [filteredTables objectAtIndex:currentIndex], [mySQLConnection getLastErrorMessage]]); + + NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error truncating table", @"error truncating table message") + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to truncate the table '%@'.\n\nMySQL said: %@", @"error truncating table informative message"), + [filteredTables objectAtIndex:currentIndex], [mySQLConnection getLastErrorMessage]]]; + + [alert setAlertStyle:NSCriticalAlertStyle]; + // NSArray *buttons = [alert buttons]; + // // Change the alert's cancel button to have the key equivalent of return + // [[buttons objectAtIndex:0] setKeyEquivalent:@"t"]; + // [[buttons objectAtIndex:0] setKeyEquivalentModifierMask:NSCommandKeyMask]; + // [[buttons objectAtIndex:1] setKeyEquivalent:@"\r"]; + [alert beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"truncateTableError"]; } // Get next index (beginning from the end) -- cgit v1.2.3