aboutsummaryrefslogtreecommitdiffstats
path: root/Source/TableDocument.m
diff options
context:
space:
mode:
authordrx777 <david.rekowski@gmx.de>2010-04-28 17:11:41 +0000
committerdrx777 <david.rekowski@gmx.de>2010-04-28 17:11:41 +0000
commitf36685ae1bee7b9274de27414ab8b64dbc57770f (patch)
tree269b242812332fab9bfdbe37955fbfbe72a87def /Source/TableDocument.m
parent29b42d1c3b751781fb70684f5bb779001d19b1f3 (diff)
downloadsequelpro-f36685ae1bee7b9274de27414ab8b64dbc57770f.tar.gz
sequelpro-f36685ae1bee7b9274de27414ab8b64dbc57770f.tar.bz2
sequelpro-f36685ae1bee7b9274de27414ab8b64dbc57770f.zip
This changeset implements renaming and duplicating databases on a server. Details as follows:
* altered MCPConnection listTablesFromDB:like: to return NSArray * altered MCPConnection listFieldsFromTable:like: to use backtick quoted strings for table and fieldnames * added MCPConnection listTablesFromDB for a complete table list * added SPStringAdditions.h to various files to prevent warnings * added sheets for duplicate/rename DB in DBView.xib * added duplicate/rename menu items to MainMenu.xib * added outlets in TableDocument: databaseNewSheet databaseRenameSheet databaseCopyNameField databaseRenameNameField copyOnlyStructureButton copyDatabaseButton renameDatabaseButton * added methods in TableDocument: getConnection, copyDatabase, renameDatabase, _copyDatabase, _renameDatabase * added OCMock Framework for object mocking in tests * added group Others/DatabaseActions
Diffstat (limited to 'Source/TableDocument.m')
-rw-r--r--Source/TableDocument.m90
1 files changed, 88 insertions, 2 deletions
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index 3cda7ad1..6e0cac4c 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -57,10 +57,15 @@
#import "SPConstants.h"
#import "SPMainThreadTrampoline.h"
#import "SPLogger.h"
+#import "SPDatabaseCopy.h"
+#import "SPTableCopy.h"
+#import "SPDatabaseRename.h"
@interface TableDocument (PrivateAPI)
- (void)_addDatabase;
+- (void)_copyDatabase;
+- (void)_renameDatabase;
- (void)_removeDatabase;
- (void)_selectDatabaseAndItem:(NSDictionary *)selectionDetails;
@@ -755,6 +760,11 @@
}
}
+- (MCPConnection *) getConnection {
+ return mySQLConnection;
+}
+
+
/**
* Set whether the connection controller should automatically start
* connecting; called by maincontroller, but only for first window.
@@ -911,9 +921,9 @@
- (IBAction)addDatabase:(id)sender
{
if (![tablesListInstance selectionShouldChangeInTableView:nil]) return;
-
+
[databaseNameField setStringValue:@""];
-
+
[NSApp beginSheet:databaseSheet
modalForWindow:tableWindow
modalDelegate:self
@@ -921,6 +931,39 @@
contextInfo:@"addDatabase"];
}
+
+/**
+ * opens the copy database sheet and copies the databsae
+ */
+- (IBAction)copyDatabase:(id)sender
+{
+ if (![tablesListInstance selectionShouldChangeInTableView:nil]) return;
+
+ [databaseCopyNameField setStringValue:@""];
+
+ [NSApp beginSheet:databaseNewSheet
+ modalForWindow:tableWindow
+ modalDelegate:self
+ didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
+ contextInfo:@"copyDatabase"];
+}
+
+/**
+ * opens the rename database sheet and renames the databsae
+ */
+- (IBAction)renameDatabase:(id)sender
+{
+ if (![tablesListInstance selectionShouldChangeInTableView:nil]) return;
+
+ [databaseRenameNameField setStringValue:@""];
+
+ [NSApp beginSheet:databaseRenameSheet
+ modalForWindow:tableWindow
+ modalDelegate:self
+ didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
+ contextInfo:@"renameDatabase"];
+}
+
/**
* opens sheet to ask user if he really wants to delete the db
*/
@@ -1035,6 +1078,12 @@
else
[chooseDatabaseButton selectItemAtIndex:0];
}
+ }
+ else if ([contextInfo isEqualToString:@"copyDatabase"]) {
+ [self _copyDatabase];
+ }
+ else if ([contextInfo isEqualToString:@"renameDatabase"]) {
+ [self _renameDatabase];
}
// Close error status sheet for OPTIMIZE, CHECK, REPAIR etc.
else if ([contextInfo isEqualToString:@"statusError"]) {
@@ -4086,6 +4135,43 @@
@implementation TableDocument (PrivateAPI)
+- (void)_copyDatabase {
+ if ([[databaseCopyNameField stringValue] isEqualToString:@""]) {
+ SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, NSLocalizedString(@"Database must have a name.", @"message of panel when no db name is given"));
+ return;
+ }
+ SPDatabaseCopy *dbActionCopy = [[SPDatabaseCopy alloc] init];
+ [dbActionCopy setConnection: [self getConnection]];
+ [dbActionCopy setParent: self];
+
+ BOOL copyWithContent = [copyOnlyStructureButton state] == NSOffState;
+
+ [dbActionCopy copyDatabaseFrom: [self database]
+ to: [databaseCopyNameField stringValue]
+ withContent: copyWithContent];
+ [dbActionCopy release];
+ [selectedDatabase release];
+ selectedDatabase = [[NSString alloc] initWithString:[databaseCopyNameField stringValue]];
+ [self setDatabases: self];
+}
+
+- (void)_renameDatabase {
+ if ([[databaseRenameNameField stringValue] isEqualToString:@""]) {
+ SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, NSLocalizedString(@"Database must have a name.", @"message of panel when no db name is given"));
+ return;
+ }
+ SPDatabaseRename *dbActionRename = [[SPDatabaseRename alloc] init];
+ [dbActionRename setConnection: [self getConnection]];
+ [dbActionRename setParent: self];
+
+ [dbActionRename renameDatabaseFrom: [self database]
+ to: [databaseRenameNameField stringValue]];
+ [dbActionRename release];
+ [selectedDatabase release];
+ selectedDatabase = [[NSString alloc] initWithString:[databaseRenameNameField stringValue]];
+ [self setDatabases: self];
+}
+
/**
* Adds a new database.
*/