aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTablesList.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/SPTablesList.m')
-rw-r--r--Source/SPTablesList.m298
1 files changed, 116 insertions, 182 deletions
diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m
index f09e27fb..690b30d9 100644
--- a/Source/SPTablesList.m
+++ b/Source/SPTablesList.m
@@ -98,6 +98,83 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
#endif
#pragma mark -
+#pragma mark Initialisation
+
+/**
+ * Standard init method. Performs various ivar initialisations.
+ */
+- (id)init
+{
+ if ((self = [super init])) {
+ tables = [[NSMutableArray alloc] init];
+ filteredTables = tables;
+ tableTypes = [[NSMutableArray alloc] init];
+ filteredTableTypes = tableTypes;
+ isTableListFiltered = NO;
+ tableListIsSelectable = YES;
+ tableListContainsViews = NO;
+ selectedTableType = SPTableTypeNone;
+ selectedTableName = nil;
+#ifndef SP_REFACTOR
+ [tables addObject:NSLocalizedString(@"TABLES", @"header for table list")];
+
+ smallSystemFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
+#endif
+ }
+
+ return self;
+}
+
+/**
+ * Standard awakeFromNib method for interface loading.
+ */
+- (void)awakeFromNib
+{
+#ifndef SP_REFACTOR
+ // Collapse the table information pane if preference to do so is set
+ if ([[[NSUserDefaults standardUserDefaults] objectForKey:SPTableInformationPanelCollapsed] boolValue]
+ && [tableListSplitView collapsibleSubview]) {
+ [tableInfoCollapseButton setNextState];
+ [tableInfoCollapseButton setToolTip:NSLocalizedString(@"Show Table Information",@"Show Table Information")];
+ [tableListSplitView setValue:[NSNumber numberWithFloat:[tableListSplitView collapsibleSubview].frame.size.height] forKey:@"uncollapsedSize"];
+ [[tableListSplitView collapsibleSubview] setAutoresizesSubviews:NO];
+ [[tableListSplitView collapsibleSubview] setFrameSize:NSMakeSize([tableListSplitView collapsibleSubview].frame.size.width, 0)];
+ [tableListSplitView setCollapsibleSubviewCollapsed:YES];
+ [[tableListSplitView collapsibleSubview] setAutoresizesSubviews:YES];
+ }
+ else {
+ [tableInfoCollapseButton setToolTip:NSLocalizedString(@"Hide Table Information",@"Hide Table Information")];
+ }
+
+ // Start the table filter list collapsed
+ if ([tableListFilterSplitView collapsibleSubview]) {
+ [tableListFilterSplitView setValue:[NSNumber numberWithFloat:[tableListFilterSplitView collapsibleSubview].frame.size.height] forKey:@"uncollapsedSize"];
+ // Set search bar view to the height of 1 instead of 0 to ensure that the view will be visible
+ // after opening a next connection window which has more than 20 tables
+ [[tableListFilterSplitView collapsibleSubview] setFrameSize:NSMakeSize([tableListFilterSplitView collapsibleSubview].frame.size.width, 1)];
+ [tableListFilterSplitView setCollapsibleSubviewCollapsed:YES];
+ }
+
+ // Disable tab edit behaviour in the tables list
+ [tablesListView setTabEditingDisabled:YES];
+#endif
+
+ // Add observers for document task activity
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(startDocumentTaskForTab:)
+ name:SPDocumentTaskStartNotification
+ object:tableDocumentInstance];
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(endDocumentTaskForTab:)
+ name:SPDocumentTaskEndNotification
+ object:tableDocumentInstance];
+
+#ifndef SP_REFACTOR
+ [tablesListView registerForDraggedTypes:[NSArray arrayWithObjects:SPNavigatorTableDataPasteboardDragType, nil]];
+#endif
+}
+
+#pragma mark -
#pragma mark IBAction methods
/**
@@ -215,58 +292,8 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
}
}
}
-#endif /*
- BOOL addedPFHeader = FALSE;
- NSString *pQuery = [NSString stringWithFormat:@"SHOW PROCEDURE STATUS WHERE db = '%@'",[tableDocumentInstance database]];
- theResult = [mySQLConnection queryString:pQuery];
-
- if( [theResult numOfRows] ) {
- // add the header row
- [tables addObject:NSLocalizedString(@"PROCS & FUNCS",@"header for procs & funcs list")];
- [tableTypes addObject:[NSNumber numberWithInt:SPTableTypeNone]];
- addedPFHeader = TRUE;
- [theResult dataSeek:0];
-
- if( [theResult numOfFields] == 1 ) {
- for( i = 0; i < [theResult numOfRows]; i++ ) {
- [tables addObject:[[theResult fetchRowAsArray] objectAtIndex:1]];
- [tableTypes addObject:[NSNumber numberWithInt:SPTableTypeProc]];
- }
- } else {
- for( i = 0; i < [theResult numOfRows]; i++ ) {
- resultRow = [theResult fetchRowAsArray];
- [tables addObject:[resultRow objectAtIndex:1]];
- [tableTypes addObject:[NSNumber numberWithInt:SPTableTypeProc]];
- }
- }
- }
-
- pQuery = [NSString stringWithFormat:@"SHOW FUNCTION STATUS WHERE db = '%@'",[tableDocumentInstance database]];
- theResult = [mySQLConnection queryString:pQuery];
-
- if( [theResult numOfRows] ) {
- if( !addedPFHeader ) {
- // add the header row
- [tables addObject:NSLocalizedString(@"PROCS & FUNCS",@"header for procs & funcs list")];
- [tableTypes addObject:[NSNumber numberWithInt:SPTableTypeNone]];
- }
- [theResult dataSeek:0];
-
- if( [theResult numOfFields] == 1 ) {
- for( i = 0; i < [theResult numOfRows]; i++ ) {
- [tables addObject:[[theResult fetchRowAsArray] objectAtIndex:1]];
- [tableTypes addObject:[NSNumber numberWithInt:SPTableTypeFunc]];
- }
- } else {
- for( i = 0; i < [theResult numOfRows]; i++ ) {
- resultRow = [theResult fetchRowAsArray];
- [tables addObject:[resultRow objectAtIndex:1]];
- [tableTypes addObject:[NSNumber numberWithInt:SPTableTypeFunc]];
- }
- }
- }
- */
-
+#endif
+
// Restore encoding if appropriate
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
@@ -570,38 +597,6 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
if (![[self tableName] length]) return;
[tablesListView editColumn:0 row:[tablesListView selectedRow] withEvent:nil select:YES];
-
- /*
-
- [tableRenameField setStringValue:[self tableName]];
- [renameTableButton setEnabled:NO];
-
- NSString *tableType;
-
- switch([self tableType]){
- case SPTableTypeTable:
- tableType = NSLocalizedString(@"table",@"table");
- break;
- case SPTableTypeView:
- tableType = NSLocalizedString(@"view",@"view");
- break;
- case SPTableTypeProc:
- tableType = NSLocalizedString(@"procedure",@"procedure");
- break;
- case SPTableTypeFunc:
- tableType = NSLocalizedString(@"function",@"function");
- break;
- }
-
- [tableRenameText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Rename %@ '%@' to:",@"rename item name to:"), tableType, [self tableName]]];
-
-
- [NSApp beginSheet:tableRenameSheet
- modalForWindow:[tableDocumentInstance parentWindow]
- modalDelegate:self
- didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
- contextInfo:@"renameTable"];
- */
}
/**
@@ -689,10 +684,12 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
- (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo
{
// Order out current sheet to suppress overlapping of sheets
- if ([sheet respondsToSelector:@selector(orderOut:)])
+ if ([sheet respondsToSelector:@selector(orderOut:)]) {
[sheet orderOut:nil];
- else if ([sheet respondsToSelector:@selector(window)])
+ }
+ else if ([sheet respondsToSelector:@selector(window)]) {
[[sheet window] orderOut:nil];
+ }
if ([contextInfo isEqualToString:SPAddRow]) {
alertSheetOpened = NO;
@@ -733,6 +730,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
- (void)setConnection:(SPMySQLConnection *)theConnection
{
mySQLConnection = theConnection;
+
[self updateTables:self];
}
@@ -1113,11 +1111,9 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
#endif
}
-
#pragma mark -
#pragma mark Getter methods
-
- (NSArray *)selectedTableNames
{
NSIndexSet *indexes = [tablesListView selectedRowIndexes];
@@ -1201,6 +1197,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
}
return returnArray;
}
+
- (NSArray *)allTableNames
{
NSMutableArray *returnArray = [NSMutableArray array];
@@ -1212,6 +1209,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
}
return returnArray;
}
+
- (NSArray *)allViewNames
{
NSMutableArray *returnArray = [NSMutableArray array];
@@ -1224,6 +1222,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
[returnArray sortUsingSelector:@selector(compare:)];
return returnArray;
}
+
- (NSArray *)allProcedureNames
{
NSMutableArray *returnArray = [NSMutableArray array];
@@ -1276,11 +1275,9 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
return tableTypes;
}
-
#pragma mark -
#pragma mark Setter methods
-
/**
* Select an item using the provided name; returns YES if the
* supplied name could be selected, or NO if not.
@@ -1459,7 +1456,6 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
*/
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
-
// During imports the table view sometimes appears to request items beyond the end of the array.
// Using a hinted noteNumberOfRowsChanged after dropping tables fixes this but then seems to stick
// even after override, so check here for the time being and display empty rows during import.
@@ -1721,7 +1717,8 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
[aCell setFont:smallSystemFont];
}
- } else {
+ }
+ else {
[aCell setImage:nil];
[aCell setIndentationLevel:0];
}
@@ -1849,7 +1846,6 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
*/
- (IBAction) updateFilter:(id)sender
{
-
// Don't try and maintain selections of multiple rows through filtering
if ([tablesListView numberOfSelectedRows] > 1) {
[tablesListView deselectAll:self];
@@ -1918,7 +1914,8 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
}
isTableListFiltered = YES;
- } else if (isTableListFiltered) {
+ }
+ else if (isTableListFiltered) {
isTableListFiltered = NO;
[filteredTables release];
#endif
@@ -1961,7 +1958,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
/**
* Disable all table list interactive elements during an ongoing task.
*/
-- (void) startDocumentTaskForTab:(NSNotification *)aNotification
+- (void)startDocumentTaskForTab:(NSNotification *)aNotification
{
tableListIsSelectable = NO;
[toolbarAddButton setEnabled:NO];
@@ -1974,7 +1971,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
/**
* Enable all table list interactive elements after an ongoing task.
*/
-- (void) endDocumentTaskForTab:(NSNotification *)aNotification
+- (void)endDocumentTaskForTab:(NSNotification *)aNotification
{
tableListIsSelectable = YES;
[toolbarAddButton setEnabled:YES];
@@ -1987,7 +1984,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
/**
* Set the table list to selectable or not during the task process.
*/
-- (void) setTableListSelectability:(BOOL)isSelectable
+- (void)setTableListSelectability:(BOOL)isSelectable
{
tableListIsSelectable = isSelectable;
}
@@ -2006,77 +2003,14 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
#pragma mark -
#pragma mark Other
-/**
- * Standard init method. Performs various ivar initialisations.
- */
-- (id)init
+#ifdef SP_REFACTOR /* glue */
+- (void)setDatabaseDocument:(SPDatabaseDocument*)val
{
- if ((self = [super init])) {
- tables = [[NSMutableArray alloc] init];
- filteredTables = tables;
- tableTypes = [[NSMutableArray alloc] init];
- filteredTableTypes = tableTypes;
- isTableListFiltered = NO;
- tableListIsSelectable = YES;
- tableListContainsViews = NO;
- selectedTableType = SPTableTypeNone;
- selectedTableName = nil;
-#ifndef SP_REFACTOR
- [tables addObject:NSLocalizedString(@"TABLES",@"header for table list")];
- smallSystemFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
-#endif
- }
-
- return self;
+ tableDocumentInstance = val;
}
-
-/**
- * Standard awakeFromNib method for interface loading.
- */
-- (void)awakeFromNib
-{
-#ifndef SP_REFACTOR
- // Collapse the table information pane if preference to do so is set
- if ([[[NSUserDefaults standardUserDefaults] objectForKey:SPTableInformationPanelCollapsed] boolValue]
- && [tableListSplitView collapsibleSubview]) {
- [tableInfoCollapseButton setNextState];
- [tableInfoCollapseButton setToolTip:NSLocalizedString(@"Show Table Information",@"Show Table Information")];
- [tableListSplitView setValue:[NSNumber numberWithFloat:[tableListSplitView collapsibleSubview].frame.size.height] forKey:@"uncollapsedSize"];
- [[tableListSplitView collapsibleSubview] setAutoresizesSubviews:NO];
- [[tableListSplitView collapsibleSubview] setFrameSize:NSMakeSize([tableListSplitView collapsibleSubview].frame.size.width, 0)];
- [tableListSplitView setCollapsibleSubviewCollapsed:YES];
- [[tableListSplitView collapsibleSubview] setAutoresizesSubviews:YES];
- } else {
- [tableInfoCollapseButton setToolTip:NSLocalizedString(@"Hide Table Information",@"Hide Table Information")];
- }
-
- // Start the table filter list collapsed
- if ([tableListFilterSplitView collapsibleSubview]) {
- [tableListFilterSplitView setValue:[NSNumber numberWithFloat:[tableListFilterSplitView collapsibleSubview].frame.size.height] forKey:@"uncollapsedSize"];
- // Set search bar view to the height of 1 instead of 0 to ensure that the view will be visible
- // after opening a next connection window which has more than 20 tables
- [[tableListFilterSplitView collapsibleSubview] setFrameSize:NSMakeSize([tableListFilterSplitView collapsibleSubview].frame.size.width, 1)];
- [tableListFilterSplitView setCollapsibleSubviewCollapsed:YES];
- }
-
- // Disable tab edit behaviour in the tables list
- [tablesListView setTabEditingDisabled:YES];
#endif
- // Add observers for document task activity
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(startDocumentTaskForTab:)
- name:SPDocumentTaskStartNotification
- object:tableDocumentInstance];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(endDocumentTaskForTab:)
- name:SPDocumentTaskEndNotification
- object:tableDocumentInstance];
-
-#ifndef SP_REFACTOR
- [tablesListView registerForDraggedTypes:[NSArray arrayWithObjects:SPNavigatorTableDataPasteboardDragType, nil]];
-#endif
-}
+#pragma mark -
/**
* Standard dealloc method.
@@ -2096,14 +2030,8 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
[super dealloc];
}
-
-#ifdef SP_REFACTOR /* glue */
-- (void)setDatabaseDocument:(SPDatabaseDocument*)val
-{
- tableDocumentInstance = val;
-}
-#endif
-
+#pragma mark -
+#pragma mark Private API
/**
* Removes the selected object (table, view, procedure, function, etc.) from the database and tableView.
@@ -2229,12 +2157,11 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
[filteredTables objectAtIndex:currentIndex], [mySQLConnection lastErrorMessage]]];
[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:[tableDocumentInstance parentWindow] modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"truncateTableError"];
+
+ [alert beginSheetModalForWindow:[tableDocumentInstance parentWindow]
+ modalDelegate:self
+ didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
+ contextInfo:@"truncateTableError"];
}
// Get next index (beginning from the end)
@@ -2258,7 +2185,9 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
[NSThread detachNewThreadSelector:@selector(_addTable) toTarget:self withObject:nil];
return;
}
+
NSAutoreleasePool *tableAdditionPool = [[NSAutoreleasePool alloc] init];
+
[tableDocumentInstance startTaskWithDescription:[NSString stringWithFormat:NSLocalizedString(@"Creating %@...", @"Creating table task string"), [tableNameField stringValue]]];
NSString *charSetStatement = @"";
@@ -2269,6 +2198,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
// Ensure the use of UTF8 when creating new tables
BOOL changeEncoding = ![[mySQLConnection encoding] isEqualToString:@"utf8"];
+
if (changeEncoding) {
[mySQLConnection storeEncodingForRestoration];
[mySQLConnection setEncoding:@"utf8"];
@@ -2277,7 +2207,9 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
// If there is an encoding selected other than the default we must specify it in CREATE TABLE statement
if ([tableEncodingButton indexOfSelectedItem] > 0) {
NSString *encodingName = [[tableEncodingButton title] stringByMatching:@"\\((.*)\\)" capture:1L];
+
if (!encodingName) encodingName = @"utf8";
+
charSetStatement = [NSString stringWithFormat:@"DEFAULT CHARACTER SET %@", [encodingName backtickQuotedString]];
}
@@ -2341,8 +2273,9 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
#endif
// Query the structure of all databases in the background (mainly for completion)
- [NSThread detachNewThreadSelector:@selector(queryDbStructureWithUserInfo:) toTarget:[tableDocumentInstance databaseStructureRetrieval] withObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"forceUpdate", nil]];
-
+ [NSThread detachNewThreadSelector:@selector(queryDbStructureWithUserInfo:)
+ toTarget:[tableDocumentInstance databaseStructureRetrieval]
+ withObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"forceUpdate", nil]];
}
else {
// Error while creating new table
@@ -2352,14 +2285,15 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
NSLocalizedString(@"OK", @"OK button"), nil, nil, [tableDocumentInstance parentWindow], self,
@selector(sheetDidEnd:returnCode:contextInfo:), SPAddRow,
[NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to add the new table '%@'.\n\nMySQL said: %@", @"error adding new table informative message"), tableName, [mySQLConnection lastErrorMessage]]);
-
+
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
+
[[tablesListView onMainThread] reloadData];
}
// Clear table name
[[tableNameField onMainThread] setStringValue:@""];
-
+
[tableDocumentInstance endTask];
[tableAdditionPool release];
}