aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2011-05-05 19:10:04 +0000
committerstuconnolly <stuart02@gmail.com>2011-05-05 19:10:04 +0000
commit47a1c49e95403e6da6c9e0ae979144fd5c1dff08 (patch)
tree9a2d09926682834c5cffefc85a1d7235849e88b7 /Source
parentde27c6e8f75c00cf5f28fdd5d6f8f1acc740320d (diff)
downloadsequelpro-47a1c49e95403e6da6c9e0ae979144fd5c1dff08.tar.gz
sequelpro-47a1c49e95403e6da6c9e0ae979144fd5c1dff08.tar.bz2
sequelpro-47a1c49e95403e6da6c9e0ae979144fd5c1dff08.zip
Small tidy up, mainly the addition of constants.
Diffstat (limited to 'Source')
-rw-r--r--Source/SPConstants.h2
-rw-r--r--Source/SPConstants.m2
-rw-r--r--Source/SPNavigatorController.m13
-rw-r--r--Source/SPTableContent.m4
-rw-r--r--Source/SPTablesList.m140
-rw-r--r--Source/SPTextView.m4
6 files changed, 57 insertions, 108 deletions
diff --git a/Source/SPConstants.h b/Source/SPConstants.h
index ffe37d66..e35adb75 100644
--- a/Source/SPConstants.h
+++ b/Source/SPConstants.h
@@ -241,6 +241,8 @@ extern NSString *SPDefaultMonospacedFontName;
extern NSString *SPDefaultPasteboardDragType;
extern NSString *SPFavoritesPasteboardDragType;
extern NSString *SPContentFilterPasteboardDragType;
+extern NSString *SPNavigatorPasteboardDragType;
+extern NSString *SPNavigatorTableDataPasteboardDragType;
// File extensions
extern NSString *SPFileExtensionDefault;
diff --git a/Source/SPConstants.m b/Source/SPConstants.m
index 1f391d47..30ae2bfd 100644
--- a/Source/SPConstants.m
+++ b/Source/SPConstants.m
@@ -42,6 +42,8 @@ NSString *SPDefaultMonospacedFontName = @"Monaco";
NSString *SPDefaultPasteboardDragType = @"SequelProPasteboard";
NSString *SPFavoritesPasteboardDragType = @"SPFavoritesPasteboard";
NSString *SPContentFilterPasteboardDragType = @"SPContentFilterPasteboard";
+NSString *SPNavigatorPasteboardDragType = @"SPNavigatorPasteboardDragType";
+NSString *SPNavigatorTableDataPasteboardDragType = @"SPNavigatorTableDataPasteboardDragType";
// File extensions
NSString *SPFileExtensionDefault = @"spf";
diff --git a/Source/SPNavigatorController.m b/Source/SPNavigatorController.m
index be24948b..1c17dd25 100644
--- a/Source/SPNavigatorController.m
+++ b/Source/SPNavigatorController.m
@@ -39,11 +39,6 @@
static SPNavigatorController *sharedNavigatorController = nil;
-#ifndef SP_REFACTOR /* pasteboard types */
-#define DragFromNavigatorPboardType @"SPDragFromNavigatorPboardType"
-#define DragTableDataFromNavigatorPboardType @"SPDragTableDataFromNavigatorPboardType"
-#endif
-
@implementation SPNavigatorController
#ifndef SP_REFACTOR /* unused sort func */
@@ -146,7 +141,7 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte
prefs = [NSUserDefaults standardUserDefaults];
[self setWindowFrameAutosaveName:@"SPNavigator"];
- [outlineSchema2 registerForDraggedTypes:[NSArray arrayWithObjects:DragTableDataFromNavigatorPboardType, DragFromNavigatorPboardType, NSStringPboardType, nil]];
+ [outlineSchema2 registerForDraggedTypes:[NSArray arrayWithObjects:SPNavigatorTableDataPasteboardDragType, SPNavigatorPasteboardDragType, NSStringPboardType, nil]];
[outlineSchema2 setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES];
[outlineSchema2 setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO];
@@ -1108,7 +1103,7 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte
- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
{
// Provide data for our custom type, and simple NSStrings.
- [pboard declareTypes:[NSArray arrayWithObjects:DragTableDataFromNavigatorPboardType, DragFromNavigatorPboardType, NSStringPboardType, nil] owner:self];
+ [pboard declareTypes:[NSArray arrayWithObjects:SPNavigatorTableDataPasteboardDragType, SPNavigatorPasteboardDragType, NSStringPboardType, nil] owner:self];
// Collect the actual schema paths without leading connection ID
NSMutableArray *draggedItems = [NSMutableArray array];
@@ -1125,7 +1120,7 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte
NSKeyedArchiver *archiver = [[[NSKeyedArchiver alloc] initForWritingWithMutableData:arraydata] autorelease];
[archiver encodeObject:draggedItems forKey:@"itemdata"];
[archiver finishEncoding];
- [pboard setData:arraydata forType:DragFromNavigatorPboardType];
+ [pboard setData:arraydata forType:SPNavigatorPasteboardDragType];
if([draggedItems count] == 1) {
NSArray *pathComponents = [[draggedItems objectAtIndex:0] componentsSeparatedByString:SPUniqueSchemaDelimiter];
@@ -1134,7 +1129,7 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte
[pboard setString:[NSString stringWithFormat:@"CREATE TABLE IF NOT EXISTS %@ SELECT * FROM %@",
[[pathComponents lastObject] backtickQuotedString],
[pathComponents componentsJoinedByPeriodAndBacktickQuoted]
- ] forType:DragTableDataFromNavigatorPboardType];
+ ] forType:SPNavigatorTableDataPasteboardDragType];
}
}
// For external destinations provide a comma separated string
diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m
index dcc56525..e3c990d3 100644
--- a/Source/SPTableContent.m
+++ b/Source/SPTableContent.m
@@ -51,8 +51,10 @@
#import "SPBundleHTMLOutputController.h"
#import "SPCustomQuery.h"
-@interface SPTableContent (Private)
+@interface SPTableContent ()
+
- (BOOL)cancelRowEditing;
+
@end
@implementation SPTableContent
diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m
index 5ccb9bae..6c37ee87 100644
--- a/Source/SPTablesList.m
+++ b/Source/SPTablesList.m
@@ -49,13 +49,20 @@
#import "SPWindowController.h"
#import "SPAppController.h"
-@interface SPTablesList (PrivateAPI)
+// Constants
+static NSString *SPAddRow = @"SPAddRow";
+static NSString *SPAddNewTable = @"SPAddNewTable";
+static NSString *SPRemoveTable = @"SPRemoveTable";
+static NSString *SPTruncateTable = @"SPTruncateTable";
+static NSString *SPDuplicateTable = @"SPDuplicateTable";
-- (void)removeTable;
-- (void)truncateTable;
-- (void)addTable;
-- (void)copyTable;
-- (void)renameTableOfType:(SPTableType)tableType from:(NSString *)oldTableName to:(NSString *)newTableName;
+@interface SPTablesList ()
+
+- (void)_removeTable;
+- (void)_truncateTable;
+- (void)_addTable;
+- (void)_copyTable;
+- (void)_renameTableOfType:(SPTableType)tableType from:(NSString *)oldTableName to:(NSString *)newTableName;
@end
#endif
@@ -383,7 +390,7 @@
modalForWindow:[tableDocumentInstance parentWindow]
modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
- contextInfo:@"addTable"];
+ contextInfo:SPAddNewTable];
}
/**
@@ -471,7 +478,7 @@
[alert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"Are you sure you want to delete the selected %@? This operation cannot be undone.", @"delete tables/views informative message"), tblTypes]];
}
- [alert beginSheetModalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"removeRow"];
+ [alert beginSheetModalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:SPRemoveTable];
}
/**
@@ -518,7 +525,7 @@
modalForWindow:[tableDocumentInstance parentWindow]
modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
- contextInfo:@"copyTable"];
+ contextInfo:SPDuplicateTable];
}
/**
@@ -604,7 +611,7 @@
[alert setInformativeText:NSLocalizedString(@"Are you sure you want to delete ALL records in the selected tables? This operation cannot be undone.", @"truncate tables informative message")];
}
- [alert beginSheetModalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"truncateTable"];
+ [alert beginSheetModalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:SPTruncateTable];
}
/**
@@ -658,27 +665,27 @@
else if ([sheet respondsToSelector:@selector(window)])
[[sheet window] orderOut:nil];
- if ([contextInfo isEqualToString:@"addRow"]) {
+ if ([contextInfo isEqualToString:SPAddRow]) {
alertSheetOpened = NO;
}
- else if ([contextInfo isEqualToString:@"removeRow"]) {
+ else if ([contextInfo isEqualToString:SPRemoveTable]) {
if (returnCode == NSAlertDefaultReturn) {
- [self performSelector:@selector(removeTable) withObject:nil afterDelay:0.0];
+ [self performSelector:@selector(_removeTable) withObject:nil afterDelay:0.0];
}
}
- else if ([contextInfo isEqualToString:@"truncateTable"]) {
+ else if ([contextInfo isEqualToString:SPTruncateTable]) {
if (returnCode == NSAlertDefaultReturn) {
- [self truncateTable];
+ [self _truncateTable];
}
}
- else if ([contextInfo isEqualToString:@"addTable"]) {
+ else if ([contextInfo isEqualToString:SPAddNewTable]) {
if (returnCode == NSOKButton) {
- [self addTable];
+ [self _addTable];
}
}
- else if ([contextInfo isEqualToString:@"copyTable"]) {
+ else if ([contextInfo isEqualToString:SPDuplicateTable]) {
if (returnCode == NSOKButton) {
- [self copyTable];
+ [self _copyTable];
}
}
}
@@ -1449,7 +1456,7 @@
@try {
// first: update the database
- [self renameTableOfType:selectedTableType from:selectedTableName to:newTableName];
+ [self _renameTableOfType:selectedTableType from:selectedTableName to:newTableName];
// second: update the table list
if (isTableListFiltered) {
@@ -1672,8 +1679,8 @@
NSPasteboard *pboard = [info draggingPasteboard];
// tables were dropped coming from the Navigator
- if ( [[pboard types] containsObject:@"SPDragTableDataFromNavigatorPboardType"] ) {
- NSString *query = [pboard stringForType:@"SPDragTableDataFromNavigatorPboardType"];
+ if ( [[pboard types] containsObject:SPNavigatorTableDataPasteboardDragType] ) {
+ NSString *query = [pboard stringForType:SPNavigatorTableDataPasteboardDragType];
if(!query) return NO;
[mySQLConnection queryString:query];
@@ -1984,7 +1991,7 @@
object:tableDocumentInstance];
- [tablesListView registerForDraggedTypes:[NSArray arrayWithObjects:@"SPDragTableDataFromNavigatorPboardType", nil]];
+ [tablesListView registerForDraggedTypes:[NSArray arrayWithObjects:SPNavigatorTableDataPasteboardDragType, nil]];
}
#endif
@@ -2016,14 +2023,11 @@
#endif
#ifndef SP_REFACTOR /* operations performed on whole tables */
-@end
-
-@implementation SPTablesList (PrivateAPI)
/**
* Removes the selected object (table, view, procedure, function, etc.) from the database and tableView.
*/
-- (void)removeTable
+- (void)_removeTable
{
NSIndexSet *indexes = [tablesListView selectedRowIndexes];
[tablesListView selectRowIndexes:[NSIndexSet indexSet] byExtendingSelection:NO];
@@ -2117,7 +2121,7 @@
/**
* Trucates the selected table(s).
*/
-- (void)truncateTable
+- (void)_truncateTable
{
NSIndexSet *indexes = [tablesListView selectedRowIndexes];
@@ -2159,7 +2163,7 @@
/**
* Adds a new table table to the database using the selected character set encoding and storage engine.
*/
-- (void)addTable
+- (void)_addTable
{
NSString *charSetStatement = @"";
NSString *engineStatement = @"";
@@ -2244,7 +2248,7 @@
SPBeginAlertSheet(NSLocalizedString(@"Error adding new table", @"error adding new table message"),
NSLocalizedString(@"OK", @"OK button"), nil, nil, [tableDocumentInstance parentWindow], self,
- @selector(sheetDidEnd:returnCode:contextInfo:), @"addRow",
+ @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 getLastErrorMessage]]);
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
@@ -2258,7 +2262,7 @@
/**
* Copies the currently selected object (table, view, procedure, function, etc.).
*/
-- (void)copyTable
+- (void)_copyTable
{
NSString *tableType = @"";
@@ -2444,7 +2448,7 @@
* This function ONLY changes the database. It does NOT refresh the views etc.
* CAREFUL: This function raises an exception if renaming fails, and does not show an error message.
*/
-- (void)renameTableOfType:(SPTableType)tableType from:(NSString *)oldTableName to:(NSString *)newTableName
+- (void)_renameTableOfType:(SPTableType)tableType from:(NSString *)oldTableName to:(NSString *)newTableName
{
// check if the name really changed
if ([oldTableName isEqualToString:newTableName]) return;
@@ -2456,17 +2460,21 @@
// this code should be improved in case we find out that something uses table names like mytable-1, mytable-2, etc.
NSString* tempTableName;
int tempNumber;
- for(tempNumber=2; tempNumber<100; tempNumber++) {
+
+ for (tempNumber=2; tempNumber<100; tempNumber++)
+ {
tempTableName = [NSString stringWithFormat:@"%@-%d",selectedTableName,tempNumber];
if ([self isTableNameValid:tempTableName forType:tableType]) break;
}
+
if (tempNumber==100) {
// we couldn't find a temporary name
[NSException raise:@"No Tempname found" format:NSLocalizedString(@"An error occured while renaming '%@'. No temporary name could be found. Please try renaming to something else first.", @"rename table error - no temporary name found"), oldTableName];
}
- [self renameTableOfType:tableType from:oldTableName to:tempTableName];
- [self renameTableOfType:tableType from:tempTableName to:newTableName];
+ [self _renameTableOfType:tableType from:oldTableName to:tempTableName];
+ [self _renameTableOfType:tableType from:tempTableName to:newTableName];
+
return;
}
@@ -2478,6 +2486,7 @@
if ([mySQLConnection queryErrored]) {
[NSException raise:@"MySQL Error" format:NSLocalizedString(@"An error occured while renaming '%@'.\n\nMySQL said: %@", @"rename table error informative message"), oldTableName, [mySQLConnection getLastErrorMessage]];
}
+
return;
}
@@ -2524,65 +2533,4 @@
}
#endif
-/**
- * Check tableName for length and if the tableName doesn't match
- * against current database table/view names (case-insensitive).
- */
-- (BOOL)isTableNameValid:(NSString *)tableName forType:(SPTableType)tableType
-{
- return [self isTableNameValid:tableName forType:tableType ignoringSelectedTable:NO];
-}
-
-/**
- * Check tableName for length and if the tableName doesn't match
- * against current database table/view names (case-insensitive).
- */
-- (BOOL)isTableNameValid:(NSString *)tableName forType:(SPTableType)tableType ignoringSelectedTable:(BOOL)ignoreSelectedTable
-{
- BOOL isValid = YES;
-
- // delete trailing whitespaces since 'foo ' or ' ' are not valid table names
- NSString *fieldStr = [tableName stringByMatching:@"(.*?)\\s*$" capture:1];
- NSString *lowercaseFieldStr = [fieldStr lowercaseString];
-
- // If table name has trailing whitespaces return 'no valid'
- if([fieldStr length] != [tableName length]) return NO;
-
- // empty table names are invalid
- if([fieldStr length] == 0) return NO;
-
-
- NSArray *similarTables;
- switch (tableType) {
- case SPTableTypeView:
- case SPTableTypeTable:
- similarTables = [self allTableAndViewNames];
- break;
- case SPTableTypeProc:
- similarTables = [self allProcedureNames];
- break;
- case SPTableTypeFunc:
- similarTables = [self allFunctionNames];
- break;
- default:
- // if some other table type is given, just return yes
- // better a mysql error than not being able to change something at all
- return YES;
- }
-
- for(id table in similarTables) {
- //compare case insensitive here
- if([lowercaseFieldStr isEqualToString:[table lowercaseString]]) {
- if (ignoreSelectedTable) {
- // if table is the selectedTable, ignore it
- // we must compare CASE SENSITIVE here!
- if ([table isEqualToString:selectedTableName]) continue;
- }
- isValid = NO;
- break;
- }
- }
- return isValid;
-}
-
@end
diff --git a/Source/SPTextView.m b/Source/SPTextView.m
index fa01709e..cb0e4d9e 100644
--- a/Source/SPTextView.m
+++ b/Source/SPTextView.m
@@ -3444,13 +3444,13 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
}
// Insert selected items coming from the Navigator
- if ( [[pboard types] containsObject:@"SPDragFromNavigatorPboardType"] ) {
+ if ( [[pboard types] containsObject:SPNavigatorPasteboardDragType] ) {
NSPoint draggingLocation = [sender draggingLocation];
draggingLocation = [self convertPoint:draggingLocation fromView:nil];
NSUInteger characterIndex = [self characterIndexOfPoint:draggingLocation];
[self setSelectedRange:NSMakeRange(characterIndex,0)];
- NSKeyedUnarchiver *unarchiver = [[[NSKeyedUnarchiver alloc] initForReadingWithData:[pboard dataForType:@"SPDragFromNavigatorPboardType"]] autorelease];
+ NSKeyedUnarchiver *unarchiver = [[[NSKeyedUnarchiver alloc] initForReadingWithData:[pboard dataForType:SPNavigatorPasteboardDragType]] autorelease];
NSArray *draggedItems = [[NSArray alloc] initWithArray:(NSArray *)[unarchiver decodeObjectForKey:@"itemdata"]];
[unarchiver finishDecoding];