aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPBundleHTMLOutputController.m2
-rw-r--r--Source/SPConnectionControllerDelegate.m119
-rw-r--r--Source/SPDatabaseDocument.h1
-rw-r--r--Source/SPDatabaseDocument.m1
-rw-r--r--Source/SPDatabaseViewController.h5
-rw-r--r--Source/SPDatabaseViewController.m53
-rw-r--r--Source/SPFavoritesController.m6
-rw-r--r--Source/SPTableRelations.h32
-rw-r--r--Source/SPTableStructure.h16
-rw-r--r--Source/SPTableStructure.m42
10 files changed, 181 insertions, 96 deletions
diff --git a/Source/SPBundleHTMLOutputController.m b/Source/SPBundleHTMLOutputController.m
index 32afd22c..444d59e0 100644
--- a/Source/SPBundleHTMLOutputController.m
+++ b/Source/SPBundleHTMLOutputController.m
@@ -42,7 +42,7 @@
@interface WebView (WebViewPrivate)
-- (void) setScriptDebugDelegate:(id) delegate;
+- (void)setScriptDebugDelegate:(id) delegate;
@end
diff --git a/Source/SPConnectionControllerDelegate.m b/Source/SPConnectionControllerDelegate.m
index ce6ab131..1865a6a2 100644
--- a/Source/SPConnectionControllerDelegate.m
+++ b/Source/SPConnectionControllerDelegate.m
@@ -84,8 +84,8 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
- (void)splitViewDidResizeSubviews:(NSNotification *)notification
{
if (initComplete) {
- [databaseConnectionView setPosition:[[[connectionSplitView subviews] objectAtIndex:0] frame].size.width ofDividerAtIndex:0];
-}
+ [databaseConnectionView setPosition:[[[connectionSplitView subviews] objectAtIndex:0] frame].size.width ofDividerAtIndex:0];
+ }
}
- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex
@@ -109,6 +109,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
{
if (isEditingConnection) {
[self _stopEditingConnection];
+
[[notification object] setNeedsDisplay:YES];
}
}
@@ -157,16 +158,20 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
if (node == quickConnectItem) {
if ([outlineView rowForItem:item] == [outlineView selectedRow]) {
[(SPTableTextFieldCell *)cell setImage:[NSImage imageNamed:SPQuickConnectImageWhite]];
- } else {
+ }
+ else {
[(SPTableTextFieldCell *)cell setImage:[NSImage imageNamed:SPQuickConnectImage]];
}
- } else {
+ }
+ else {
[(SPTableTextFieldCell *)cell setImage:nil];
}
- } else {
+ }
+ else {
if ([node isGroup]) {
[(SPTableTextFieldCell *)cell setImage:folderImage];
- } else {
+ }
+ else {
[(SPTableTextFieldCell *)cell setImage:[NSImage imageNamed:SPDatabaseImage]];
}
}
@@ -205,20 +210,26 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
// Only display a tooltip for group nodes that are a descendant of the root node
else if ([[node parentNode] parentNode]) {
+
NSUInteger favCount = 0;
NSUInteger groupCount = 0;
- for (SPTreeNode *eachNode in [node childNodes]) {
+
+ for (SPTreeNode *eachNode in [node childNodes])
+ {
if ([eachNode isGroup]) {
groupCount++;
- } else {
+ }
+ else {
favCount++;
}
}
NSMutableArray *tooltipParts = [NSMutableArray arrayWithCapacity:2];
+
if (favCount || !groupCount) {
[tooltipParts addObject:[NSString stringWithFormat:((favCount == 1) ? NSLocalizedString(@"%d favorite", @"favorite singular label (%d == 1)") : NSLocalizedString(@"%d favorites", @"favorites plural label (%d != 1)")), favCount]];
}
+
if (groupCount) {
[tooltipParts addObject:[NSString stringWithFormat:((groupCount == 1) ? NSLocalizedString(@"%d group", @"favorite group singular label (%d == 1)") : NSLocalizedString(@"%d groups", @"favorite groups plural label (%d != 1)")), groupCount]];
}
@@ -231,13 +242,9 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
{
-
// If this is a top level item, only allow the "Quick Connect" item to be selectable
if (![[item parentNode] parentNode]) {
- if (item == quickConnectItem) {
- return YES;
- }
- return NO;
+ return item == quickConnectItem;
}
// Otherwise allow all items to be selectable
@@ -268,7 +275,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
return NO;
}
- return (item != quickConnectItem);
+ return item != quickConnectItem;
}
- (void)outlineViewItemDidCollapse:(NSNotification *)notification
@@ -290,9 +297,9 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
{
-
// Prevent a drag which includes the outline title group from taking place
- for (id item in items) {
+ for (id item in items)
+ {
if (![[item parentNode] parentNode]) return NO;
}
@@ -341,14 +348,14 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
[outlineView setDropItem:item dropChildIndex:childIndex];
result = NSDragOperationMove;
- }
+ }
return result;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)childIndex
- {
- BOOL acceptedDrop = NO;
+{
+ BOOL acceptedDrop = NO;
if ((!item) || ([info draggingSource] != outlineView)) return acceptedDrop;
@@ -357,18 +364,18 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
// Cache the selected nodes for selection restoration afterwards
NSArray *preDragSelection = [self selectedFavoriteNodes];
- // Disable all automatic sorting
- currentSortItem = -1;
- reverseFavoritesSort = NO;
-
- [prefs setInteger:currentSortItem forKey:SPFavoritesSortedBy];
- [prefs setBool:NO forKey:SPFavoritesSortedInReverse];
-
- // Uncheck sort by menu items
- for (NSMenuItem *menuItem in [[favoritesSortByMenuItem submenu] itemArray])
- {
- [menuItem setState:NSOffState];
- }
+ // Disable all automatic sorting
+ currentSortItem = -1;
+ reverseFavoritesSort = NO;
+
+ [prefs setInteger:currentSortItem forKey:SPFavoritesSortedBy];
+ [prefs setBool:NO forKey:SPFavoritesSortedInReverse];
+
+ // Uncheck sort by menu items
+ for (NSMenuItem *menuItem in [[favoritesSortByMenuItem submenu] itemArray])
+ {
+ [menuItem setState:NSOffState];
+ }
if (![draggedNodes count]) return acceptedDrop;
@@ -391,7 +398,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
NSMutableArray *childNodeArray = [node mutableChildNodes];
for (SPTreeNode *treeNode in draggedNodes)
- {
+ {
// Remove the node from its old location
NSInteger oldIndex = [childNodeArray indexOfObject:treeNode];
NSInteger newIndex = childIndex;
@@ -402,8 +409,8 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
if (childIndex > oldIndex) {
newIndex--;
- }
- }
+ }
+ }
else {
[[[treeNode parentNode] mutableChildNodes] removeObject:treeNode];
}
@@ -419,18 +426,21 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
[[NSNotificationCenter defaultCenter] postNotificationName:SPConnectionFavoritesChangedNotification object:self];
- [[[[NSApp delegate] preferenceController] generalPreferencePane] updateDefaultFavoritePopup];
+ [[[[NSApp delegate] preferenceController] generalPreferencePane] updateDefaultFavoritePopup];
// Update the selection to account for rearranged faourites
NSMutableIndexSet *restoredSelection = [NSMutableIndexSet indexSet];
- for (SPTreeNode *eachNode in preDragSelection) {
+
+ for (SPTreeNode *eachNode in preDragSelection)
+ {
[restoredSelection addIndex:[favoritesOutlineView rowForItem:eachNode]];
}
+
[favoritesOutlineView selectRowIndexes:restoredSelection byExtendingSelection:NO];
- acceptedDrop = YES;
+ acceptedDrop = YES;
- return acceptedDrop;
+ return acceptedDrop;
}
#endif
@@ -464,8 +474,8 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
if (favoriteNameFieldWasAutogenerated && (field != standardNameField && field != socketNameField && field != sshNameField)) {
[self setName:[self _generateNameForConnection]];
- }
- }
+ }
+}
/**
* React to the end of control text changes in the connection interface.
@@ -483,17 +493,19 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
if (![favoriteName length]) {
favoriteName = [self _generateNameForConnection];
+
if (favoriteName) {
[self setName:favoriteName];
- }
+ }
// Enable user@host update in reaction to other UI changes
favoriteNameFieldWasAutogenerated = YES;
- } else if (![[field stringValue] isEqualToString:[self _generateNameForConnection]]) {
+ }
+ else if (![[field stringValue] isEqualToString:[self _generateNameForConnection]]) {
favoriteNameFieldWasAutogenerated = NO;
[self setName:favoriteName];
+ }
}
-}
// When a host field finishes editing, ensure that it hasn't been set to "localhost" to
// ensure that socket connections don't inadvertently occur.
@@ -577,7 +589,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
[connectionResizeContainer setFrame:connectionDetailsFrame];
scrollDocumentFrame.size.height = scrollViewFrame.size.height;
[[connectionDetailsScrollView documentView] setFrame:scrollDocumentFrame];
-}
+ }
}
#endif
@@ -597,9 +609,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
SPTreeNode *node = [self selectedFavoriteNode];
NSInteger selectedRows = [favoritesOutlineView numberOfSelectedRows];
- if (node == quickConnectItem) {
- return NO;
- }
+ if (node == quickConnectItem) return NO;
if ((action == @selector(sortFavorites:)) || (action == @selector(reverseSortFavorites:))) {
@@ -615,7 +625,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
if (action == @selector(reverseSortFavorites:)) {
[menuItem setState:reverseFavoritesSort];
}
-}
+ }
// Remove/rename the selected node
if (action == @selector(removeNode:) || action == @selector(renameNode:)) {
@@ -625,14 +635,14 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
// Duplicate and make the selected favorite the default
if (action == @selector(duplicateFavorite:)) {
return ((selectedRows == 1) && (![node isGroup]));
-}
+ }
// Make selected favorite the default
if (action == @selector(makeSelectedFavoriteDefault:)) {
NSInteger favoriteID = [[[self selectedFavorite] objectForKey:SPFavoriteIDKey] integerValue];
return ((selectedRows == 1) && (![node isGroup]) && (favoriteID != [prefs integerForKey:SPDefaultFavorite]));
-}
+ }
// Favorites export
if (action == @selector(exportFavorites:)) {
@@ -645,7 +655,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
}
else if (selectedRows > 1) {
[menuItem setTitle:NSLocalizedString(@"Export Selected...", @"export selected favorites menu item")];
- }
+ }
}
return YES;
@@ -675,7 +685,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
didEndSelector:NULL
contextInfo:NULL];
}
- }
+}
/**
* Called by the favorites importer when the imported data is available.
@@ -700,10 +710,13 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
[self _reloadFavoritesViewData];
// Select the new nodes and scroll into view
- for (SPTreeNode *eachNode in importedNodes) {
+ for (SPTreeNode *eachNode in importedNodes)
+ {
[importedIndexSet addIndex:[favoritesOutlineView rowForItem:eachNode]];
}
+
[favoritesOutlineView selectRowIndexes:importedIndexSet byExtendingSelection:NO];
+
[self _scrollToSelectedNode];
}
diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h
index c2a9124f..f0b66f33 100644
--- a/Source/SPDatabaseDocument.h
+++ b/Source/SPDatabaseDocument.h
@@ -202,6 +202,7 @@
BOOL contentLoaded;
BOOL statusLoaded;
BOOL triggersLoaded;
+ BOOL relationsLoaded;
NSString *selectedDatabase;
NSString *mySQLVersion;
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index 0993458b..2fce7598 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -195,6 +195,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
contentLoaded = NO;
statusLoaded = NO;
triggersLoaded = NO;
+ relationsLoaded = NO;
selectedDatabase = nil;
selectedDatabaseEncoding = [[NSString alloc] initWithString:@"latin1"];
diff --git a/Source/SPDatabaseViewController.h b/Source/SPDatabaseViewController.h
index 00017a39..c3774613 100644
--- a/Source/SPDatabaseViewController.h
+++ b/Source/SPDatabaseViewController.h
@@ -34,9 +34,10 @@
@interface SPDatabaseDocument (SPDatabaseViewController)
-// Getters
+// Accessors
- (NSString *)table;
- (SPTableType)tableType;
+
- (BOOL)structureLoaded;
- (BOOL)contentLoaded;
- (BOOL)statusLoaded;
@@ -50,9 +51,11 @@
- (IBAction)viewRelations:(id)sender;
- (IBAction)viewTriggers:(id)sender;
#endif
+
- (void)setStructureRequiresReload:(BOOL)reload;
- (void)setContentRequiresReload:(BOOL)reload;
- (void)setStatusRequiresReload:(BOOL)reload;
+- (void)setRelationsRequiresReload:(BOOL)reload;
// Table control
- (void)loadTable:(NSString *)aTable ofType:(SPTableType)aTableType;
diff --git a/Source/SPDatabaseViewController.m b/Source/SPDatabaseViewController.m
index fff47726..9949ac31 100644
--- a/Source/SPDatabaseViewController.m
+++ b/Source/SPDatabaseViewController.m
@@ -42,6 +42,7 @@
#import "SPTablesList.h"
#import "SPTableTriggers.h"
#import "SPThreadAdditions.h"
+#import "SPTableRelations.h"
#ifdef SP_CODA /* headers */
#import "SPTableStructure.h"
#import "SPTableStructureLoading.h"
@@ -275,6 +276,24 @@
}
}
+/**
+ * Mark the relations tab for refresh when it's next switched to,
+ * or reload the view if it's currently active
+ */
+- (void)setRelationsRequiresReload:(BOOL)reload
+{
+ if (reload && selectedTableName
+#ifndef SP_CODA /* check which tab is selected */
+ && [tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == SPTableViewRelations
+#endif
+ ) {
+ [[tableRelationsInstance onMainThread] refreshRelations:self];
+ }
+ else {
+ relationsLoaded = !reload;
+ }
+}
+
#ifndef SP_CODA /* !!! respond to tab change */
/**
* Triggers a task to update the newly selected tab view, ensuring
@@ -285,7 +304,10 @@
[self startTaskWithDescription:[NSString stringWithFormat:NSLocalizedString(@"Loading %@...", @"Loading table task string"), [self table]]];
if ([NSThread isMainThread]) {
- [NSThread detachNewThreadWithName:@"SPDatabaseViewController view load task" target:self selector:@selector(_loadTabTask:) object:tabViewItem];
+ [NSThread detachNewThreadWithName:@"SPDatabaseViewController view load task"
+ target:self
+ selector:@selector(_loadTabTask:)
+ object:tabViewItem];
}
else {
[self _loadTabTask:tabViewItem];
@@ -313,6 +335,7 @@
// Update the selected table name and type
if (selectedTableName) [selectedTableName release], selectedTableName = nil;
+
selectedTableType = SPTableTypeNone;
// Clear the views
@@ -322,11 +345,13 @@
#ifndef SP_CODA /* [extendedTableInfoInstance loadTable:] */
[[extendedTableInfoInstance onMainThread] loadTable:nil];
[[tableTriggersInstance onMainThread] resetInterface];
+ [[tableRelationsInstance onMainThread] refreshRelations:self];
#endif
structureLoaded = NO;
contentLoaded = NO;
statusLoaded = NO;
triggersLoaded = NO;
+ relationsLoaded = NO;
#ifndef SP_CODA
// Update the window title
@@ -346,6 +371,7 @@
// Store the new name
if (selectedTableName) [selectedTableName release];
+
selectedTableName = [[NSString alloc] initWithString:aTable];
selectedTableType = aTableType;
@@ -363,7 +389,10 @@
// If on the main thread, fire up a thread to deal with view changes and data loading;
// if already on a background thread, make the changes on the existing thread.
if ([NSThread isMainThread]) {
- [NSThread detachNewThreadWithName:@"SPDatabaseViewController table load task" target:self selector:@selector(_loadTableTask) object:nil];
+ [NSThread detachNewThreadWithName:@"SPDatabaseViewController table load task"
+ target:self
+ selector:@selector(_loadTableTask)
+ object:nil];
}
else {
[self _loadTableTask];
@@ -385,8 +414,7 @@
NSAutoreleasePool *tabLoadPool = [[NSAutoreleasePool alloc] init];
// If anything other than a single table or view is selected, don't proceed.
- if (![self table]
- || ([tablesListInstance tableType] != SPTableTypeTable && [tablesListInstance tableType] != SPTableTypeView))
+ if (![self table] || ([tablesListInstance tableType] != SPTableTypeTable && [tablesListInstance tableType] != SPTableTypeView))
{
[self endTask];
[tabLoadPool drain];
@@ -422,10 +450,17 @@
triggersLoaded = YES;
}
break;
+ case SPTableViewRelations:
+ if (!relationsLoaded) {
+ [[tableRelationsInstance onMainThread] refreshRelations:self];
+ relationsLoaded = YES;
+ }
+ break;
#endif
}
[self endTask];
+
[tabLoadPool drain];
}
@@ -445,14 +480,17 @@
// Reset table information caches and mark that all loaded views require their data reloading
[tableDataInstance resetAllData];
+
structureLoaded = NO;
contentLoaded = NO;
statusLoaded = NO;
triggersLoaded = NO;
-
+ relationsLoaded = NO;
+
// Ensure status and details are fetched using UTF8
NSString *previousEncoding = [mySQLConnection encoding];
BOOL changeEncoding = ![previousEncoding isEqualToString:@"utf8"];
+
if (changeEncoding) {
[mySQLConnection storeEncodingForRestoration];
[mySQLConnection setEncoding:@"utf8"];
@@ -517,6 +555,10 @@
[[tableTriggersInstance onMainThread] loadTriggers];
triggersLoaded = YES;
break;
+ case SPTableViewRelations:
+ [[tableRelationsInstance onMainThread] refreshRelations:self];
+ relationsLoaded = YES;
+ break;
}
#endif
}
@@ -528,6 +570,7 @@
if (!contentLoaded) [tableContentInstance loadTable:nil];
if (!statusLoaded) [[extendedTableInfoInstance onMainThread] loadTable:nil];
if (!triggersLoaded) [[tableTriggersInstance onMainThread] resetInterface];
+ if (!relationsLoaded) [[tableRelationsInstance onMainThread] refreshRelations:self];
// If the table row counts an inaccurate and require updating, trigger an update - no
// action will be performed if not necessary
diff --git a/Source/SPFavoritesController.m b/Source/SPFavoritesController.m
index e883d876..9ecee454 100644
--- a/Source/SPFavoritesController.m
+++ b/Source/SPFavoritesController.m
@@ -380,15 +380,16 @@ static SPFavoritesController *sharedFavoritesController = nil;
// to create the plist data. This is done before file changes as it can sometimes
// be terminated during shutdown.
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:data forKey:SPFavoritesRootKey];
+
NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:dictionary
format:NSPropertyListXMLFormat_v1_0
errorDescription:&errorString];
if (errorString) {
NSLog(@"Error converting favorites data to plist format: %@", errorString);
+
[errorString release];
}
-
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *dataPath = [fileManager applicationSupportDirectoryForSubDirectory:SPDataSupportFolder error:&error];
@@ -430,13 +431,14 @@ static SPFavoritesController *sharedFavoritesController = nil;
// Restore the original data file
error = nil;
+
[fileManager moveItemAtPath:favoritesBackupFile toPath:favoritesFile error:&error];
+
if (error) {
NSLog(@"Could not restore backup; favorites.plist left renamed as %@ due to error (%@)", favoritesBackupFile, [error localizedDescription]);
}
}
else {
-
// Remove the original backup
[fileManager removeItemAtPath:favoritesBackupFile error:NULL];
}
diff --git a/Source/SPTableRelations.h b/Source/SPTableRelations.h
index 52a2535b..9734b678 100644
--- a/Source/SPTableRelations.h
+++ b/Source/SPTableRelations.h
@@ -32,15 +32,16 @@
@class SPTableView;
@class SPMySQLConnection;
+@class SPDatabaseDocument;
+@class SPTablesList;
+@class SPTableData;
@interface SPTableRelations : NSObject
{
- IBOutlet id tableDocumentInstance;
- IBOutlet id tablesListInstance;
- IBOutlet id tableDataInstance;
-
- IBOutlet id tableList;
-
+ IBOutlet SPDatabaseDocument *tableDocumentInstance;
+ IBOutlet SPTablesList *tablesListInstance;
+ IBOutlet SPTableData *tableDataInstance;
+
IBOutlet NSButton *addRelationButton;
IBOutlet NSButton *removeRelationButton;
IBOutlet NSButton *refreshRelationsButton;
@@ -48,16 +49,16 @@
IBOutlet SPTableView *relationsTableView;
IBOutlet NSPanel *addRelationPanel;
- IBOutlet NSTextField *constraintName;
- IBOutlet NSBox *addRelationTableBox;
- IBOutlet NSPopUpButton *columnPopUpButton;
- IBOutlet NSPopUpButton *refTablePopUpButton;
- IBOutlet NSPopUpButton *refColumnPopUpButton;
- IBOutlet NSPopUpButton *onUpdatePopUpButton;
- IBOutlet NSPopUpButton *onDeletePopUpButton;
- IBOutlet NSButton *confirmAddRelationButton;
+ IBOutlet NSTextField *constraintName;
+ IBOutlet NSBox *addRelationTableBox;
+ IBOutlet NSPopUpButton *columnPopUpButton;
+ IBOutlet NSPopUpButton *refTablePopUpButton;
+ IBOutlet NSPopUpButton *refColumnPopUpButton;
+ IBOutlet NSPopUpButton *onUpdatePopUpButton;
+ IBOutlet NSPopUpButton *onDeletePopUpButton;
+ IBOutlet NSButton *confirmAddRelationButton;
IBOutlet NSProgressIndicator *dataProgressIndicator;
- IBOutlet NSTextField *progressStatusTextField;
+ IBOutlet NSTextField *progressStatusTextField;
SPMySQLConnection *connection;
@@ -87,6 +88,5 @@
// Other
- (NSArray *)relationDataForPrinting;
-- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo;
@end
diff --git a/Source/SPTableStructure.h b/Source/SPTableStructure.h
index c749c822..84de3310 100644
--- a/Source/SPTableStructure.h
+++ b/Source/SPTableStructure.h
@@ -40,21 +40,23 @@
@class SPTableView;
@class SPMySQLConnection;
@class SPMySQLResult;
+@class SPExtendedTableInfo;
+@class SPTableInfo;
@interface SPTableStructure : NSObject
#ifdef SP_CODA
<NSTableViewDelegate, NSTableViewDataSource, NSComboBoxCellDataSource>
#endif
{
- IBOutlet SPTablesList* tablesListInstance;
- IBOutlet SPTableData* tableDataInstance;
- IBOutlet SPDatabaseDocument* tableDocumentInstance;
+ IBOutlet SPTablesList *tablesListInstance;
+ IBOutlet SPTableData *tableDataInstance;
+ IBOutlet SPDatabaseDocument *tableDocumentInstance;
#ifndef SP_CODA /* ivars */
- IBOutlet id tableInfoInstance;
- IBOutlet id extendedTableInfoInstance;
+ IBOutlet SPTableInfo *tableInfoInstance;
+ IBOutlet SPExtendedTableInfo *extendedTableInfoInstance;
#endif
- IBOutlet SPIndexesController* indexesController;
- IBOutlet SPDatabaseData* databaseDataInstance;
+ IBOutlet SPIndexesController *indexesController;
+ IBOutlet SPDatabaseData *databaseDataInstance;
#ifndef SP_CODA /* ivars */
IBOutlet id keySheet;
diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m
index cd034a6d..883e21c8 100644
--- a/Source/SPTableStructure.m
+++ b/Source/SPTableStructure.m
@@ -51,6 +51,9 @@
#import <SPMySQL/SPMySQL.h>
+static NSString *SPRemoveField = @"SPRemoveField";
+static NSString *SPRemoveFieldAndForeignKey = @"SPRemoveFieldAndForeignKey";
+
@interface SPTableStructure (PrivateAPI)
- (void)_removeFieldAndForeignKey:(NSNumber *)removeForeignKey;
@@ -436,7 +439,7 @@
defaultButton:NSLocalizedString(@"Delete", @"delete button")
alternateButton:NSLocalizedString(@"Cancel", @"cancel button")
otherButton:nil
- informativeTextWithFormat:(hasForeignKey) ? [NSString stringWithFormat:NSLocalizedString(@"This field is part of a foreign key relationship with the table '%@'. This relationship must be removed before the field can be deleted.\n\nAre you sure you want to continue to delete the relationship and the field? This action cannot be undone.", @"delete field and foreign key informative message"), referencedTable] : [NSString stringWithFormat:NSLocalizedString(@"Are you sure you want to delete the field '%@'? This action cannot be undone.", @"delete field informative message"), field]];
+ informativeTextWithFormat:hasForeignKey ? [NSString stringWithFormat:NSLocalizedString(@"This field is part of a foreign key relationship with the table '%@'. This relationship must be removed before the field can be deleted.\n\nAre you sure you want to continue to delete the relationship and the field? This action cannot be undone.", @"delete field and foreign key informative message"), referencedTable] : [NSString stringWithFormat:NSLocalizedString(@"Are you sure you want to delete the field '%@'? This action cannot be undone.", @"delete field informative message"), field]];
[alert setAlertStyle:NSCriticalAlertStyle];
@@ -452,7 +455,10 @@
[[buttons objectAtIndex:1] setKeyEquivalent:@"\e"];
#endif
- [alert beginSheetModalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self didEndSelector:@selector(removeFieldSheetDidEnd:returnCode:contextInfo:) contextInfo:(hasForeignKey) ? @"removeFieldAndForeignKey" : @"removeField"];
+ [alert beginSheetModalForWindow:[tableDocumentInstance parentWindow]
+ modalDelegate:self
+ didEndSelector:@selector(removeFieldSheetDidEnd:returnCode:contextInfo:)
+ contextInfo:hasForeignKey ? SPRemoveFieldAndForeignKey : SPRemoveField];
}
/**
@@ -510,12 +516,17 @@
if (returnCode == NSAlertDefaultReturn) {
[tableDocumentInstance startTaskWithDescription:NSLocalizedString(@"Removing field...", @"removing field task status message")];
- NSNumber *removeKey = [NSNumber numberWithBool:[(NSString *)contextInfo hasSuffix:@"AndForeignKey"]];
+ NSNumber *removeKey = [NSNumber numberWithBool:[(NSString *)contextInfo isEqualToString:SPRemoveFieldAndForeignKey]];
if ([NSThread isMainThread]) {
- [NSThread detachNewThreadWithName:@"SPTableStructure field and key removal task" target:self selector:@selector(_removeFieldAndForeignKey:) object:removeKey];
-
- [tableDocumentInstance enableTaskCancellationWithTitle:NSLocalizedString(@"Cancel", @"cancel button") callbackObject:self callbackFunction:NULL];
+ [NSThread detachNewThreadWithName:@"SPTableStructure field and key removal task"
+ target:self
+ selector:@selector(_removeFieldAndForeignKey:)
+ object:removeKey];
+
+ [tableDocumentInstance enableTaskCancellationWithTitle:NSLocalizedString(@"Cancel", @"cancel button")
+ callbackObject:self
+ callbackFunction:NULL];
}
else {
[self _removeFieldAndForeignKey:removeKey];
@@ -531,18 +542,25 @@
- (BOOL)cancelRowEditing
{
if (!isEditingRow) return NO;
+
if (isEditingNewRow) {
isEditingNewRow = NO;
[tableFields removeObjectAtIndex:currentlyEditingRow];
- } else {
+ }
+ else {
[tableFields replaceObjectAtIndex:currentlyEditingRow withObject:[NSMutableDictionary dictionaryWithDictionary:oldRow]];
}
+
isEditingRow = NO;
isCurrentExtraAutoIncrement = [tableDataInstance tableHasAutoIncrementField];
autoIncrementIndex = nil;
+
[tableSourceView reloadData];
+
currentlyEditingRow = -1;
+
[[tableDocumentInstance parentWindow] makeFirstResponder:tableSourceView];
+
return YES;
}
@@ -556,7 +574,6 @@
#endif
}
-
#pragma mark -
#pragma mark Index sheet methods
@@ -1418,15 +1435,18 @@
[errorDictionary setObject:[NSString stringWithFormat:NSLocalizedString(@"Couldn't delete field %@.\nMySQL said: %@", @"message of panel when field cannot be deleted"),
[[tableFields objectAtIndex:[tableSourceView selectedRow]] objectForKey:@"name"],
[mySQLConnection lastErrorMessage]] forKey:@"message"];
+
[[self onMainThread] showErrorSheetWith:errorDictionary];
}
else {
[tableDataInstance resetAllData];
+
+ // Refresh relevant views
[tableDocumentInstance setStatusRequiresReload:YES];
- [self loadTable:selectedTable];
-
- // Mark the content table cache for refresh
[tableDocumentInstance setContentRequiresReload:YES];
+ [tableDocumentInstance setRelationsRequiresReload:YES];
+
+ [self loadTable:selectedTable];
}
[tableDocumentInstance endTask];