aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-06-15 16:05:54 +0000
committerBibiko <bibiko@eva.mpg.de>2009-06-15 16:05:54 +0000
commit70d15ff4ecdfd3c6996b3b8b2259674f9e9c9345 (patch)
tree83480a09ef5d35003e1971ac9c341f578940f55e /Source
parent39c34617b01f72c7466eee98675447e277e326cb (diff)
downloadsequelpro-70d15ff4ecdfd3c6996b3b8b2259674f9e9c9345.tar.gz
sequelpro-70d15ff4ecdfd3c6996b3b8b2259674f9e9c9345.tar.bz2
sequelpro-70d15ff4ecdfd3c6996b3b8b2259674f9e9c9345.zip
• deleted the drag&drop feature of file path or content from SPTextViewAdditions
- that feature should be added by subclassing NSTextView • fixed focus setting of editSheet • fixed general issue if SP tries to execute a query which is longer than max_allowed_packet - now it reconnects after changing max_allowed_packet (if it's editable) - the user will be informed via a log entry about that change - the new max_allowed_packet size will be valid during the current session; after reconnection to that db the default size will be used
Diffstat (limited to 'Source')
-rw-r--r--Source/CMMCPConnection.m4
-rw-r--r--Source/CMTextView.h3
-rw-r--r--Source/CMTextView.m172
-rw-r--r--Source/SPTextViewAdditions.h3
-rw-r--r--Source/SPTextViewAdditions.m172
-rw-r--r--Source/TableContent.m13
6 files changed, 187 insertions, 180 deletions
diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m
index 4e897056..ca86fbd7 100644
--- a/Source/CMMCPConnection.m
+++ b/Source/CMMCPConnection.m
@@ -697,6 +697,7 @@ static void forcePingTimeout(int signalNumber);
if(isMaxAllowedPacketEditable && queryResultCode == 1 && queryErrorID == 2006) {
currentMaxAllowedPacket = [self getMaxAllowedPacket];
[self setMaxAllowedPacketTo:strlen(theCQuery)+1024];
+ [self reconnect];
}
// The connection has been restored - re-run the query
@@ -1074,7 +1075,8 @@ static void forcePingTimeout(int signalNumber)
if(![self isMaxAllowedPacketEditable] || newSize < 1024) return [self getMaxAllowedPacket];
mysql_query(mConnection, [[NSString stringWithFormat:@"SET GLOBAL max_allowed_packet = %d", newSize] UTF8String]);
-
+ // Inform the user via a log entry about that change
+ [delegate queryGaveError:[NSString stringWithFormat:@"Query too large; max_allowed_packet temporarily set to %d for the current session to allow query to succeed", newSize]];
return [self getMaxAllowedPacket];
}
diff --git a/Source/CMTextView.h b/Source/CMTextView.h
index 9b0d7659..374704af 100644
--- a/Source/CMTextView.h
+++ b/Source/CMTextView.h
@@ -82,4 +82,7 @@
- (NSArray *)suggestionsForSQLCompletionWith:(NSString *)currentWord dictMode:(BOOL)isDictMode;
- (void) selectCurrentQuery;
+- (unsigned int)characterIndexOfPoint:(NSPoint)aPoint;
+- (void)insertFileContentOfFile:(NSString *)aPath;
+
@end
diff --git a/Source/CMTextView.m b/Source/CMTextView.m
index 39c83977..142663bd 100644
--- a/Source/CMTextView.m
+++ b/Source/CMTextView.m
@@ -2456,6 +2456,178 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
// Dragging methods
///////////////////////////
+/*
+ * Insert the content of a dragged file path or if ⌘ is pressed
+ * while dragging insert the file path
+ */
+- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
+{
+ NSPasteboard *pboard = [sender draggingPasteboard];
+
+ if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
+ NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
+
+ // Only one file path is allowed
+ if([files count] > 1) {
+ NSLog(@"%@", NSLocalizedString(@"Only one dragged item allowed.",@"Only one dragged item allowed."));
+ return YES;
+ }
+
+ NSString *filepath = [[pboard propertyListForType:NSFilenamesPboardType] objectAtIndex:0];
+
+ // Set the new insertion point
+ NSPoint draggingLocation = [sender draggingLocation];
+ draggingLocation = [self convertPoint:draggingLocation fromView:nil];
+ unsigned int characterIndex = [self characterIndexOfPoint:draggingLocation];
+ [self setSelectedRange:NSMakeRange(characterIndex,0)];
+
+ // Check if user pressed ⌘ while dragging for inserting only the file path
+ if([sender draggingSourceOperationMask] == 4)
+ {
+ [self insertText:filepath];
+ return YES;
+ }
+
+ // Check size and NSFileType
+ NSDictionary *attr = [[NSFileManager defaultManager] fileAttributesAtPath:filepath traverseLink:YES];
+ if(attr)
+ {
+ NSNumber *filesize = [attr objectForKey:NSFileSize];
+ NSString *filetype = [attr objectForKey:NSFileType];
+ if(filetype == NSFileTypeRegular && filesize)
+ {
+ // Ask for confirmation if file content is larger than 1MB
+ if([filesize unsignedLongValue] > 1000000)
+ {
+ NSAlert *alert = [[NSAlert alloc] init];
+ [alert addButtonWithTitle:NSLocalizedString(@"OK", @"OK button")];
+ [alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"cancel button")];
+ [alert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"Do you really want to proceed with %.1f MB of data?", @"message of panel asking for confirmation for inserting large text from dragging action"),
+ [filesize unsignedLongValue]/1048576.0]];
+ [alert setHelpAnchor:filepath];
+ [alert setMessageText:NSLocalizedString(@"Warning",@"Warning")];
+ [alert setAlertStyle:NSWarningAlertStyle];
+ [alert beginSheetModalForWindow:[self window]
+ modalDelegate:self
+ didEndSelector:@selector(dragAlertSheetDidEnd:returnCode:contextInfo:)
+ contextInfo:nil];
+ [alert release];
+
+ } else
+ [self insertFileContentOfFile:filepath];
+ }
+ }
+ return YES;
+ }
+
+ return [super performDragOperation:sender];
+}
+
+/*
+ * Confirmation sheetDidEnd method
+ */
+- (void)dragAlertSheetDidEnd:(NSAlert *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
+{
+
+ [[sheet window] orderOut:nil];
+ if ( returnCode == NSAlertFirstButtonReturn )
+ [self insertFileContentOfFile:[sheet helpAnchor]];
+
+}
+/*
+ * Convert a NSPoint, usually the mouse location, to
+ * a character index of the text view.
+ */
+- (unsigned int)characterIndexOfPoint:(NSPoint)aPoint
+{
+ unsigned int glyphIndex;
+ NSLayoutManager *layoutManager = [self layoutManager];
+ float fraction;
+ NSRange range;
+
+ range = [layoutManager glyphRangeForTextContainer:[self textContainer]];
+ glyphIndex = [layoutManager glyphIndexForPoint:aPoint
+ inTextContainer:[self textContainer]
+ fractionOfDistanceThroughGlyph:&fraction];
+ if( fraction > 0.5 ) glyphIndex++;
+
+ if( glyphIndex == NSMaxRange(range) )
+ return [[self textStorage] length];
+ else
+ return [layoutManager characterIndexForGlyphAtIndex:glyphIndex];
+
+}
+
+/*
+ * Insert content of a plain text file for a given path.
+ * In addition it tries to figure out the file's text encoding heuristically.
+ */
+- (void)insertFileContentOfFile:(NSString *)aPath
+{
+
+ NSError *err = nil;
+ NSStringEncoding enc;
+ NSString *content = nil;
+
+ // Make usage of the UNIX command "file" to get an info
+ // about file type and encoding.
+ NSTask *task=[[NSTask alloc] init];
+ NSPipe *pipe=[[NSPipe alloc] init];
+ NSFileHandle *handle;
+ NSString *result;
+ [task setLaunchPath:@"/usr/bin/file"];
+ [task setArguments:[NSArray arrayWithObjects:aPath, @"-Ib", nil]];
+ [task setStandardOutput:pipe];
+ handle=[pipe fileHandleForReading];
+ [task launch];
+ result=[[NSString alloc] initWithData:[handle readDataToEndOfFile]
+ encoding:NSASCIIStringEncoding];
+
+ [pipe release];
+ [task release];
+
+ // UTF16/32 files are detected as application/octet-stream resp. audio/mpeg
+ if([result hasPrefix:@"application/octet-stream"] || [result hasPrefix:@"audio/mpeg"] || [result hasPrefix:@"text/plain"] || [[[aPath pathExtension] lowercaseString] isEqualToString:@"sql"])
+ {
+ // if UTF16/32 cocoa will try to find the correct encoding
+ if([result hasPrefix:@"application/octet-stream"] || [result hasPrefix:@"audio/mpeg"] || [result rangeOfString:@"utf-16"].length)
+ enc = 0;
+ else if([result rangeOfString:@"utf-8"].length)
+ enc = NSUTF8StringEncoding;
+ else if([result rangeOfString:@"iso-8859-1"].length)
+ enc = NSISOLatin1StringEncoding;
+ else if([result rangeOfString:@"us-ascii"].length)
+ enc = NSASCIIStringEncoding;
+ else
+ enc = 0;
+
+ if(enc == 0) // cocoa tries to detect the encoding
+ content = [NSString stringWithContentsOfFile:aPath usedEncoding:&enc error:&err];
+ else
+ content = [NSString stringWithContentsOfFile:aPath encoding:enc error:&err];
+
+ if(content)
+ {
+ [self insertText:content];
+ [result release];
+ [self insertText:@""]; // Invoke keyword uppercasing
+ return;
+ }
+ // If UNIX "file" failed try cocoa's encoding detection
+ content = [NSString stringWithContentsOfFile:aPath encoding:enc error:&err];
+ if(content)
+ {
+ [self insertText:content];
+ [result release];
+ [self insertText:@""]; // Invoke keyword uppercasing
+ return;
+ }
+ }
+
+ [result release];
+
+ NSLog(@"%@ ‘%@’.", NSLocalizedString(@"Couldn't read the file content of", @"Couldn't read the file content of"), aPath);
+}
- (void) dealloc
{
diff --git a/Source/SPTextViewAdditions.h b/Source/SPTextViewAdditions.h
index ccf865fb..22b809c8 100644
--- a/Source/SPTextViewAdditions.h
+++ b/Source/SPTextViewAdditions.h
@@ -44,8 +44,5 @@
- (void)makeTextSizeLarger;
- (void)makeTextSizeSmaller;
-- (unsigned int)characterIndexOfPoint:(NSPoint)aPoint;
-
-- (void)insertFileContentOfFile:(NSString *)aPath;
@end \ No newline at end of file
diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m
index 7e882dca..f9c9a1de 100644
--- a/Source/SPTextViewAdditions.m
+++ b/Source/SPTextViewAdditions.m
@@ -385,178 +385,6 @@
}
}
-/*
- * Insert the content of a dragged file path or if ⌘ is pressed
- * while dragging insert the file path
- */
-- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
-{
- NSPasteboard *pboard = [sender draggingPasteboard];
-
- if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
- NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
-
- // Only one file path is allowed
- if([files count] > 1) {
- NSLog(@"%@", NSLocalizedString(@"Only one dragged item allowed.",@"Only one dragged item allowed."));
- return YES;
- }
-
- NSString *filepath = [[pboard propertyListForType:NSFilenamesPboardType] objectAtIndex:0];
-
- // Set the new insertion point
- NSPoint draggingLocation = [sender draggingLocation];
- draggingLocation = [self convertPoint:draggingLocation fromView:nil];
- unsigned int characterIndex = [self characterIndexOfPoint:draggingLocation];
- [self setSelectedRange:NSMakeRange(characterIndex,0)];
-
- // Check if user pressed ⌘ while dragging for inserting only the file path
- if([sender draggingSourceOperationMask] == 4)
- {
- [self insertText:filepath];
- return YES;
- }
-
- // Check size and NSFileType
- NSDictionary *attr = [[NSFileManager defaultManager] fileAttributesAtPath:filepath traverseLink:YES];
- if(attr)
- {
- NSNumber *filesize = [attr objectForKey:NSFileSize];
- NSString *filetype = [attr objectForKey:NSFileType];
- if(filetype == NSFileTypeRegular && filesize)
- {
- // Ask for confirmation if file content is larger than 1MB
- if([filesize unsignedLongValue] > 1000000)
- {
- NSAlert *alert = [[NSAlert alloc] init];
- [alert addButtonWithTitle:NSLocalizedString(@"OK", @"OK button")];
- [alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"cancel button")];
- [alert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"Do you really want to proceed with %.1f MB of data?", @"message of panel asking for confirmation for inserting large text from dragging action"),
- [filesize unsignedLongValue]/1048576.0]];
- [alert setHelpAnchor:filepath];
- [alert setMessageText:NSLocalizedString(@"Warning",@"Warning")];
- [alert setAlertStyle:NSWarningAlertStyle];
- [alert beginSheetModalForWindow:[self window]
- modalDelegate:self
- didEndSelector:@selector(dragAlertSheetDidEnd:returnCode:contextInfo:)
- contextInfo:nil];
- [alert release];
-
- } else
- [self insertFileContentOfFile:filepath];
- }
- }
- return YES;
- }
-
- return [super performDragOperation:sender];
-}
-
-/*
- * Confirmation sheetDidEnd method
- */
-- (void)dragAlertSheetDidEnd:(NSAlert *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
-{
-
- [[sheet window] orderOut:nil];
- if ( returnCode == NSAlertFirstButtonReturn )
- [self insertFileContentOfFile:[sheet helpAnchor]];
-
-}
-/*
- * Convert a NSPoint, usually the mouse location, to
- * a character index of the text view.
- */
-- (unsigned int)characterIndexOfPoint:(NSPoint)aPoint
-{
- unsigned int glyphIndex;
- NSLayoutManager *layoutManager = [self layoutManager];
- float fraction;
- NSRange range;
-
- range = [layoutManager glyphRangeForTextContainer:[self textContainer]];
- glyphIndex = [layoutManager glyphIndexForPoint:aPoint
- inTextContainer:[self textContainer]
- fractionOfDistanceThroughGlyph:&fraction];
- if( fraction > 0.5 ) glyphIndex++;
-
- if( glyphIndex == NSMaxRange(range) )
- return [[self textStorage] length];
- else
- return [layoutManager characterIndexForGlyphAtIndex:glyphIndex];
-
-}
-
-/*
- * Insert content of a plain text file for a given path.
- * In addition it tries to figure out the file's text encoding heuristically.
- */
-- (void)insertFileContentOfFile:(NSString *)aPath
-{
-
- NSError *err = nil;
- NSStringEncoding enc;
- NSString *content = nil;
-
- // Make usage of the UNIX command "file" to get an info
- // about file type and encoding.
- NSTask *task=[[NSTask alloc] init];
- NSPipe *pipe=[[NSPipe alloc] init];
- NSFileHandle *handle;
- NSString *result;
- [task setLaunchPath:@"/usr/bin/file"];
- [task setArguments:[NSArray arrayWithObjects:aPath, @"-Ib", nil]];
- [task setStandardOutput:pipe];
- handle=[pipe fileHandleForReading];
- [task launch];
- result=[[NSString alloc] initWithData:[handle readDataToEndOfFile]
- encoding:NSASCIIStringEncoding];
-
- [pipe release];
- [task release];
-
- // UTF16/32 files are detected as application/octet-stream resp. audio/mpeg
- if([result hasPrefix:@"application/octet-stream"] || [result hasPrefix:@"audio/mpeg"] || [result hasPrefix:@"text/plain"] || [[[aPath pathExtension] lowercaseString] isEqualToString:@"sql"])
- {
- // if UTF16/32 cocoa will try to find the correct encoding
- if([result hasPrefix:@"application/octet-stream"] || [result hasPrefix:@"audio/mpeg"] || [result rangeOfString:@"utf-16"].length)
- enc = 0;
- else if([result rangeOfString:@"utf-8"].length)
- enc = NSUTF8StringEncoding;
- else if([result rangeOfString:@"iso-8859-1"].length)
- enc = NSISOLatin1StringEncoding;
- else if([result rangeOfString:@"us-ascii"].length)
- enc = NSASCIIStringEncoding;
- else
- enc = 0;
-
- if(enc == 0) // cocoa tries to detect the encoding
- content = [NSString stringWithContentsOfFile:aPath usedEncoding:&enc error:&err];
- else
- content = [NSString stringWithContentsOfFile:aPath encoding:enc error:&err];
-
- if(content)
- {
- [self insertText:content];
- [result release];
- [self insertText:@""]; // Invoke keyword uppercasing
- return;
- }
- // If UNIX "file" failed try cocoa's encoding detection
- content = [NSString stringWithContentsOfFile:aPath encoding:enc error:&err];
- if(content)
- {
- [self insertText:content];
- [result release];
- [self insertText:@""]; // Invoke keyword uppercasing
- return;
- }
- }
-
- [result release];
-
- NSLog(@"%@ ‘%@’.", NSLocalizedString(@"Couldn't read the file content of", @"Couldn't read the file content of"), aPath);
-}
/*
* Increase the textView's font size by 1
diff --git a/Source/TableContent.m b/Source/TableContent.m
index 551ddd59..bb37b444 100644
--- a/Source/TableContent.m
+++ b/Source/TableContent.m
@@ -2320,15 +2320,20 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn
// Locate the caret in editTextView
// (to select all takes a bit time for large data)
[editTextView setSelectedRange:NSMakeRange(0,0)];
- // Set focus to editTextView
- [editSheet makeFirstResponder:editTextView];
+
+ // Set focus
+ if(image == nil)
+ [editSheet makeFirstResponder:editTextView];
+ else
+ [editSheet makeFirstResponder:editImage];
+
[stringValue release];
}
- [editSheetProgressBar stopAnimation:self];
-
editSheetWillBeInitialized = NO;
+ [editSheetProgressBar stopAnimation:self];
+
// wait for editSheet
code = [NSApp runModalForWindow:editSheet];