aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPDatabaseDocument.m12
-rw-r--r--Source/SPExtendedTableInfo.m177
-rw-r--r--Source/SPNarrowDownCompletion.m14
-rw-r--r--Source/SPQueryFavoriteManager.m12
-rw-r--r--Source/SPTextView.m8
5 files changed, 131 insertions, 92 deletions
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index ac6d4dda..4e2d5954 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -305,18 +305,6 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax";
// Hide the activity list
[self setActivityPaneHidden:[NSNumber numberWithInteger:1]];
- // Bind the background color of the create syntax text view to the users preference
- [createTableSyntaxTextView setAllowsDocumentBackgroundColorChange:YES];
-
- NSMutableDictionary *bindingOptions = [NSMutableDictionary dictionary];
-
- [bindingOptions setObject:NSUnarchiveFromDataTransformerName forKey:@"NSValueTransformerName"];
-
- [createTableSyntaxTextView bind:@"backgroundColor"
- toObject:[NSUserDefaultsController sharedUserDefaultsController]
- withKeyPath:@"values.CustomQueryEditorBackgroundColor"
- options:bindingOptions];
-
// Load additional nibs, keeping track of the top-level objects to allow correct release
NSArray *connectionDialogTopLevelObjects = nil;
NSNib *nibLoader = [[NSNib alloc] initWithNibNamed:@"ConnectionErrorDialog" bundle:[NSBundle mainBundle]];
diff --git a/Source/SPExtendedTableInfo.m b/Source/SPExtendedTableInfo.m
index d2afe969..5cd867ce 100644
--- a/Source/SPExtendedTableInfo.m
+++ b/Source/SPExtendedTableInfo.m
@@ -35,8 +35,12 @@
#import "SPServerSupport.h"
#import "SPMySQL.h"
-@interface SPExtendedTableInfo (PrivateAPI)
+static NSString *SPUpdateTableTypeCurrentType = @"SPUpdateTableTypeCurrentType";
+static NSString *SPUpdateTableTypeNewType = @"SPUpdateTableTypeNewType";
+@interface SPExtendedTableInfo ()
+
+- (void)_changeCurrentTableTypeFrom:(NSString *)currentType to:(NSString *)newType;
- (NSString *)_formatValueWithKey:(NSString *)key inDictionary:(NSDictionary *)statusDict;
@end
@@ -50,17 +54,6 @@
*/
- (void)awakeFromNib
{
- [tableCreateSyntaxTextView setAllowsDocumentBackgroundColorChange:YES];
-
- NSMutableDictionary *bindingOptions = [NSMutableDictionary dictionary];
-
- [bindingOptions setObject:NSUnarchiveFromDataTransformerName forKey:@"NSValueTransformerName"];
-
- [tableCreateSyntaxTextView bind:@"backgroundColor"
- toObject:[NSUserDefaultsController sharedUserDefaultsController]
- withKeyPath:@"values.CustomQueryEditorBackgroundColor"
- options:bindingOptions];
-
// Add observers for document task activity
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(startDocumentTaskForTab:)
@@ -96,25 +89,32 @@
NSString *currentType = [tableDataInstance statusValueForKey:@"Engine"];
// Check if the user selected the same type
- if ([currentType isEqualToString:newType]) {
- return;
- }
-
- // Alter table's storage type
- [connection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ %@ = %@", [selectedTable backtickQuotedString], [[tableDocumentInstance serverSupport] engineTypeQueryName], newType]];
-
- if (![connection queryErrored]) {
-
- // Reload the table's data
- [tableDocumentInstance loadTable:selectedTable ofType:[tableDocumentInstance tableType]];
- }
- else {
- [sender selectItemWithTitle:currentType];
-
- SPBeginAlertSheet(NSLocalizedString(@"Error changing table type", @"error changing table type message"),
- NSLocalizedString(@"OK", @"OK button"), nil, nil, [NSApp mainWindow], self, nil, nil,
- [NSString stringWithFormat:NSLocalizedString(@"An error occurred when trying to change the table type to '%@'.\n\nMySQL said: %@", @"error changing table type informative message"), newType, [connection lastErrorMessage]]);
- }
+ if ([currentType isEqualToString:newType]) return;
+
+ NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Change table type", @"change table type message")
+ defaultButton:NSLocalizedString(@"Change", @"change button")
+ alternateButton:NSLocalizedString(@"Cancel", @"cancel button")
+ otherButton:nil
+ informativeTextWithFormat:NSLocalizedString(@"Are you sure you want to change this table's type to %@?\n\nPlease be aware that changing a table's type has the potential to cause the loss of some or all of it's data. This action cannot be undone.", @"change table type informative message"), newType];
+
+ [alert setAlertStyle:NSCriticalAlertStyle];
+
+ NSArray *buttons = [alert buttons];
+
+ // Change the alert's cancel button to have the key equivalent of return
+ [[buttons objectAtIndex:0] setKeyEquivalent:@"d"];
+ [[buttons objectAtIndex:0] setKeyEquivalentModifierMask:NSCommandKeyMask];
+ [[buttons objectAtIndex:1] setKeyEquivalent:@"\r"];
+
+ NSMutableDictionary *dataDict = [[NSMutableDictionary alloc] initWithCapacity:2];
+
+ [dataDict setObject:currentType forKey:SPUpdateTableTypeCurrentType];
+ [dataDict setObject:newType forKey:SPUpdateTableTypeNewType];
+
+ [alert beginSheetModalForWindow:[tableDocumentInstance parentWindow]
+ modalDelegate:self
+ didEndSelector:@selector(confirmChangeTableTypeDidEnd:returnCode:contextInfo:)
+ contextInfo:dataDict];
}
/**
@@ -247,7 +247,8 @@
[tableCreateSyntaxTextView didChangeText];
[tableCreateSyntaxTextView setEditable:NO];
}
- } else {
+ }
+ else {
[tableCreateSyntaxTextView setEditable:YES];
[tableCreateSyntaxTextView shouldChangeTextInRange:NSMakeRange(0, [[tableCreateSyntaxTextView string] length]) replacementString:@""];
[tableCreateSyntaxTextView setString:@""];
@@ -280,6 +281,7 @@
[tableEncodingPopUpButton addItemWithTitle:[statusFields objectForKey:@"CharacterSetClient"]];
[tableCollationPopUpButton addItemWithTitle:[statusFields objectForKey:@"Collation"]];
}
+
return;
}
@@ -355,7 +357,9 @@
// Set comments
NSString *commentText = [statusFields objectForKey:@"Comment"];
+
if (!commentText) commentText = @"";
+
[tableCommentsTextView setEditable:YES];
[tableCommentsTextView shouldChangeTextInRange:NSMakeRange(0, [[tableCommentsTextView string] length]) replacementString:commentText];
[tableCommentsTextView setString:commentText];
@@ -368,9 +372,11 @@
[tableCreateSyntaxTextView setString:@""];
[tableCreateSyntaxTextView didChangeText];
[tableCreateSyntaxTextView shouldChangeTextInRange:NSMakeRange(0, 0) replacementString:[tableDataInstance tableCreateSyntax]];
+
if ([tableDataInstance tableCreateSyntax]) {
[tableCreateSyntaxTextView insertText:[[tableDataInstance tableCreateSyntax] stringByAppendingString:@";"]];
}
+
[tableCreateSyntaxTextView didChangeText];
[tableCreateSyntaxTextView setEditable:NO];
@@ -391,35 +397,59 @@
NSMutableDictionary *tableInfo = [NSMutableDictionary dictionary];
NSDictionary *statusFields = [tableDataInstance statusValues];
- if([tableTypePopUpButton titleOfSelectedItem])
+ if ([tableTypePopUpButton titleOfSelectedItem]) {
[tableInfo setObject:[tableTypePopUpButton titleOfSelectedItem] forKey:@"type"];
- if([tableEncodingPopUpButton titleOfSelectedItem])
+ }
+
+ if ([tableEncodingPopUpButton titleOfSelectedItem]) {
[tableInfo setObject:[tableEncodingPopUpButton titleOfSelectedItem] forKey:@"encoding"];
- if([tableCollationPopUpButton titleOfSelectedItem])
+ }
+
+ if ([tableCollationPopUpButton titleOfSelectedItem]) {
[tableInfo setObject:[tableCollationPopUpButton titleOfSelectedItem] forKey:@"collation"];
+ }
- if([self _formatValueWithKey:@"Create_time" inDictionary:statusFields])
+ if ([self _formatValueWithKey:@"Create_time" inDictionary:statusFields]) {
[tableInfo setObject:[self _formatValueWithKey:@"Create_time" inDictionary:statusFields] forKey:@"createdAt"];
- if([self _formatValueWithKey:@"Update_time" inDictionary:statusFields])
+ }
+
+ if ([self _formatValueWithKey:@"Update_time" inDictionary:statusFields]) {
[tableInfo setObject:[self _formatValueWithKey:@"Update_time" inDictionary:statusFields] forKey:@"updatedAt"];
- if([self _formatValueWithKey:@"Rows" inDictionary:statusFields])
+ }
+
+ if ([self _formatValueWithKey:@"Rows" inDictionary:statusFields]) {
[tableInfo setObject:[self _formatValueWithKey:@"Rows" inDictionary:statusFields] forKey:@"rowNumber"];
- if([self _formatValueWithKey:@"Row_format" inDictionary:statusFields])
+ }
+
+ if ([self _formatValueWithKey:@"Row_format" inDictionary:statusFields]) {
[tableInfo setObject:[self _formatValueWithKey:@"Row_format" inDictionary:statusFields] forKey:@"rowFormat"];
- if([self _formatValueWithKey:@"Avg_row_length" inDictionary:statusFields])
+ }
+
+ if ([self _formatValueWithKey:@"Avg_row_length" inDictionary:statusFields]) {
[tableInfo setObject:[self _formatValueWithKey:@"Avg_row_length" inDictionary:statusFields] forKey:@"rowAvgLength"];
- if([self _formatValueWithKey:@"Auto_increment" inDictionary:statusFields])
+ }
+
+ if ([self _formatValueWithKey:@"Auto_increment" inDictionary:statusFields]) {
[tableInfo setObject:[self _formatValueWithKey:@"Auto_increment" inDictionary:statusFields] forKey:@"rowAutoIncrement"];
- if([self _formatValueWithKey:@"Data_length" inDictionary:statusFields])
+ }
+
+ if ([self _formatValueWithKey:@"Data_length" inDictionary:statusFields]) {
[tableInfo setObject:[self _formatValueWithKey:@"Data_length" inDictionary:statusFields] forKey:@"dataSize"];
- if([self _formatValueWithKey:@"Max_data_length" inDictionary:statusFields])
+ }
+
+ if ([self _formatValueWithKey:@"Max_data_length" inDictionary:statusFields]) {
[tableInfo setObject:[self _formatValueWithKey:@"Max_data_length" inDictionary:statusFields] forKey:@"maxDataSize"];
- if([self _formatValueWithKey:@"Index_length" inDictionary:statusFields])
+ }
+
+ if ([self _formatValueWithKey:@"Index_length" inDictionary:statusFields]) {
[tableInfo setObject:[self _formatValueWithKey:@"Index_length" inDictionary:statusFields] forKey:@"indexSize"];
+ }
+
[tableInfo setObject:[self _formatValueWithKey:@"Data_free" inDictionary:statusFields] forKey:@"sizeFree"];
- if([tableCommentsTextView string])
+ if ([tableCommentsTextView string]) {
[tableInfo setObject:[tableCommentsTextView string] forKey:@"comments"];
+ }
NSError *error = nil;
NSArray *HTMLExcludes = [NSArray arrayWithObjects:@"doctype", @"html", @"head", @"body", @"xml", nil];
@@ -430,12 +460,12 @@
// Set tableCreateSyntaxTextView's font size temporarily to 10pt for printing
NSFont *oldFont = [tableCreateSyntaxTextView font];
BOOL editableStatus = [tableCreateSyntaxTextView isEditable];
+
[tableCreateSyntaxTextView setEditable:YES];
[tableCreateSyntaxTextView setFont:[NSFont fontWithName:[oldFont fontName] size:10.0f]];
// Convert tableCreateSyntaxTextView to HTML
- NSData *HTMLData = [[tableCreateSyntaxTextView textStorage] dataFromRange:NSMakeRange(0, [[tableCreateSyntaxTextView string] length])
- documentAttributes:attributes error:&error];
+ NSData *HTMLData = [[tableCreateSyntaxTextView textStorage] dataFromRange:NSMakeRange(0, [[tableCreateSyntaxTextView string] length]) documentAttributes:attributes error:&error];
// Restore original font settings
[tableCreateSyntaxTextView setFont:oldFont];
@@ -485,6 +515,22 @@
}
}
+/**
+ * Called when the user dismisses the change table type confirmation dialog.
+ */
+- (void)confirmChangeTableTypeDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(NSDictionary *)contextInfo
+{
+ if (returnCode == NSAlertDefaultReturn) {
+ [self _changeCurrentTableTypeFrom:[contextInfo objectForKey:SPUpdateTableTypeCurrentType]
+ to:[contextInfo objectForKey:SPUpdateTableTypeNewType]];
+ }
+ else {
+ [tableTypePopUpButton selectItemWithTitle:[contextInfo objectForKey:SPUpdateTableTypeCurrentType]];
+ }
+
+ [contextInfo release];
+}
+
#pragma mark -
#pragma mark Task interaction
@@ -516,7 +562,7 @@
// If we are viewing tables in the information_schema database, then disable all controls that cause table
// changes as these tables are not modifiable by anyone.
- //also affects mysql and performance_schema
+ // also affects mysql and performance_schema
BOOL isSystemSchemaDb = ([[tableDocumentInstance database] isEqualToString:@"information_schema"] || [[tableDocumentInstance database] isEqualToString:@"performance_schema"] || [[tableDocumentInstance database] isEqualToString:@"mysql"]);
if ([[databaseDataInstance getDatabaseStorageEngines] count] && [statusFields objectForKey:@"Engine"]) {
@@ -527,8 +573,7 @@
[tableEncodingPopUpButton setEnabled:(!isSystemSchemaDb)];
}
- if ([[databaseDataInstance getDatabaseCollationsForEncoding:[tableDataInstance tableEncoding]] count]
- && [statusFields objectForKey:@"Collation"])
+ if ([[databaseDataInstance getDatabaseCollationsForEncoding:[tableDataInstance tableEncoding]] count] && [statusFields objectForKey:@"Collation"])
{
[tableCollationPopUpButton setEnabled:(!isSystemSchemaDb)];
}
@@ -550,9 +595,30 @@
[super dealloc];
}
-@end
+#pragma mark -
+#pragma mark Private API
-@implementation SPExtendedTableInfo (PrivateAPI)
+/**
+ * Changes the current table's storage engine to the supplied type.
+ */
+- (void)_changeCurrentTableTypeFrom:(NSString *)currentType to:(NSString *)newType
+{
+ // Alter table's storage type
+ [connection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ %@ = %@", [selectedTable backtickQuotedString], [[tableDocumentInstance serverSupport] engineTypeQueryName], newType]];
+
+ if ([connection queryErrored]) {
+
+ // Reload the table's data
+ [tableDocumentInstance loadTable:selectedTable ofType:[tableDocumentInstance tableType]];
+ }
+ else {
+ [tableTypePopUpButton selectItemWithTitle:currentType];
+
+ SPBeginAlertSheet(NSLocalizedString(@"Error changing table type", @"error changing table type message"),
+ NSLocalizedString(@"OK", @"OK button"), nil, nil, [NSApp mainWindow], self, nil, nil,
+ [NSString stringWithFormat:NSLocalizedString(@"An error occurred when trying to change the table type to '%@'.\n\nMySQL said: %@", @"error changing table type informative message"), newType, [connection lastErrorMessage]]);
+ }
+}
/**
* Format and returns the value within the info dictionary with the associated key.
@@ -605,12 +671,7 @@
}
}
- if ([key isEqualToString:@"Auto_increment"]) {
- return ([value length] > 0) ? value : NSLocalizedString(@"Not available", @"not available label");
- }
- else {
- return ([value length] > 0) ? value : NSLocalizedString(@"Not available", @"not available label");
- }
+ return ([value length] > 0) ? value : NSLocalizedString(@"Not available", @"not available label");
}
@end
diff --git a/Source/SPNarrowDownCompletion.m b/Source/SPNarrowDownCompletion.m
index 5fbeaf39..4dc2711d 100644
--- a/Source/SPNarrowDownCompletion.m
+++ b/Source/SPNarrowDownCompletion.m
@@ -178,12 +178,10 @@
if (stateTimer != nil) {
[stateTimer invalidate];
[stateTimer release];
- stateTimer = nil;
}
closeMe = YES;
[theView setCompletionIsOpen:NO];
-
[super close];
}
@@ -328,12 +326,12 @@
if(caretPos.y >= 0 && caretPos.y < [self frame].size.height)
{
- caretPos.y += [self frame].size.height + ([tableFont pointSize]*1.5f);
+ caretPos.y += [self frame].size.height + ([tableFont pointSize]*1.5);
isAbove = YES;
}
if(caretPos.y < 0 && (mainScreen.size.height-[self frame].size.height) < (caretPos.y*-1))
{
- caretPos.y += [self frame].size.height + ([tableFont pointSize]*1.5f);
+ caretPos.y += [self frame].size.height + ([tableFont pointSize]*1.5);
isAbove = YES;
}
@@ -346,7 +344,7 @@
[self setLevel:NSNormalWindowLevel];
[self setHidesOnDeactivate:YES];
[self setHasShadow:YES];
- [self setAlphaValue:0.9f];
+ [self setAlphaValue:0.9];
NSScrollView* scrollView = [[[NSScrollView alloc] initWithFrame:NSZeroRect] autorelease];
[scrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
@@ -732,10 +730,10 @@
if(caretPos.y >= 0 && (isAbove || caretPos.y < newHeight))
{
isAbove = YES;
- old.y = caretPos.y + newHeight + ([tableFont pointSize]*1.5f);
+ old.y = caretPos.y + newHeight + ([tableFont pointSize]*1.5);
}
if(caretPos.y < 0 && (isAbove || ([self rectOfMainScreen].size.height-newHeight) < (caretPos.y*-1)))
- old.y = caretPos.y + newHeight + ([tableFont pointSize]*1.5f);
+ old.y = caretPos.y + newHeight + ([tableFont pointSize]*1.5);
// newHeight is currently the new height for theTableView, but we need to resize the whole window
// so here we use the difference in height to find the new height for the window
@@ -984,7 +982,7 @@
// Restore the text selection location, and clearly mark the autosuggested text
[theView setSelectedRange:NSMakeRange(currentSelectionPosition, 0)];
- NSMutableAttributedStringAddAttributeValueRange([theView textStorage], NSForegroundColorAttributeName, [[theView otherTextColor] colorWithAlphaComponent:0.3f], NSMakeRange(currentSelectionPosition, [toInsert length]));
+ NSMutableAttributedStringAddAttributeValueRange([theView textStorage], NSForegroundColorAttributeName, [[theView otherTextColor] colorWithAlphaComponent:0.3], NSMakeRange(currentSelectionPosition, [toInsert length]));
NSMutableAttributedStringAddAttributeValueRange([theView textStorage], kSPAutoCompletePlaceholderName, kSPAutoCompletePlaceholderVal, NSMakeRange(currentSelectionPosition, [toInsert length]));
[self checkSpaceForAllowedCharacter];
diff --git a/Source/SPQueryFavoriteManager.m b/Source/SPQueryFavoriteManager.m
index 28f824fe..1b5ce3dc 100644
--- a/Source/SPQueryFavoriteManager.m
+++ b/Source/SPQueryFavoriteManager.m
@@ -82,18 +82,6 @@
*/
- (void)awakeFromNib
{
- [favoriteQueryTextView setAllowsDocumentBackgroundColorChange:YES];
-
- NSMutableDictionary *bindingOptions = [NSMutableDictionary dictionary];
-
- [bindingOptions setObject:NSUnarchiveFromDataTransformerName forKey:@"NSValueTransformerName"];
-
- [favoriteQueryTextView bind:@"backgroundColor"
- toObject:[NSUserDefaultsController sharedUserDefaultsController]
- withKeyPath:@"values.CustomQueryEditorBackgroundColor"
- options:bindingOptions];
-
-
[favorites addObject:[NSDictionary dictionaryWithObjectsAndKeys:
@"Global", @"name",
@"", @"headerOfFileURL",
diff --git a/Source/SPTextView.m b/Source/SPTextView.m
index 73e45c88..eb8b8064 100644
--- a/Source/SPTextView.m
+++ b/Source/SPTextView.m
@@ -182,7 +182,9 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
#ifndef SP_REFACTOR
[self setQueryHiliteColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorHighlightQueryColor]]];
- [self setQueryEditorBackgroundColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorBackgroundColor]]];
+ NSColor *backgroundColor = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorBackgroundColor]];
+ [self setQueryEditorBackgroundColor:backgroundColor];
+ [self setBackgroundColor:backgroundColor];
[self setCommentColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorCommentColor]]];
[self setQuoteColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorQuoteColor]]];
[self setKeywordColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorSQLKeywordColor]]];
@@ -242,7 +244,9 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
{
#ifndef SP_REFACTOR
if ([keyPath isEqualToString:SPCustomQueryEditorBackgroundColor]) {
- [self setQueryEditorBackgroundColor:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]];
+ NSColor *backgroundColor = [NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]];
+ [self setQueryEditorBackgroundColor:backgroundColor];
+ [self setBackgroundColor:backgroundColor];
[self setNeedsDisplayInRect:[self bounds]];
} else if ([keyPath isEqualToString:SPCustomQueryEditorFont]) {
[self setFont:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]];