From a343ff6aa7e5789cd0d35a28caace8e39959e777 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Sat, 13 Jun 2009 13:25:59 +0000 Subject: =?UTF-8?q?=E2=80=A2=20moved=20code=20for=20de/increasing=20font?= =?UTF-8?q?=20and=20drag&drop=20feature=20(content=20or=20while=20holding?= =?UTF-8?q?=20=E2=8C=98=20path)=20to=20SPTextViewAddition=20-=20two=20fing?= =?UTF-8?q?er=20zooming=20gesture=20is=20disabled=20for=20NSTableView=20ce?= =?UTF-8?q?lls=20-=20i.e.=20all=20NSTextViews=20including=20NSTableView=20?= =?UTF-8?q?cells=20inherit=20these=20feature=20=E2=80=A2=20simplified=20Qu?= =?UTF-8?q?ickLookFormat=20IBActions=20-=20added=20bin/text=20storing=20ty?= =?UTF-8?q?pe=20to=20each=20action=20=E2=80=A2=20QuickLook=20animation=20s?= =?UTF-8?q?et=20to=20SP's=20window=20middle=20point=20=E2=80=A2=20fixed=20?= =?UTF-8?q?issue=20that=20while=20having=20an=20image=20in=20editSheet=20a?= =?UTF-8?q?n=20attribute=20change=20(font/size)=20in=20the=20editTextView?= =?UTF-8?q?=20destroyed=20the=20image=20data=20=E2=80=A2=20fix=20to=20allo?= =?UTF-8?q?w=20again=20drag&drop=20an=20image=20to=20editSheet=20=E2=80=A2?= =?UTF-8?q?=20hide=20text/image/hex=20segment=20controll=20and=20QuickLook?= =?UTF-8?q?=20pull=20down=20button=20if=20user=20chose=20multipleLineEditi?= =?UTF-8?q?ngButton=20for=20non-blob=20fields=20=20=E2=80=A2=20disabled=20?= =?UTF-8?q?NSLog=20of=20print=20result=20in=20TableDocument?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 214 ---------------------------------------------------- 1 file changed, 214 deletions(-) (limited to 'Source/CMTextView.m') diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 9c66b068..39c83977 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -1003,30 +1003,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) return [compl autorelease]; } -/* - * Increase the textView's font size by 1 - */ -- (void)makeTextSizeLarger -{ - NSFont *aFont = [self font]; - BOOL editableStatus = [self isEditable]; - [self setEditable:YES]; - [self setFont:[[NSFontManager sharedFontManager] convertFont:aFont toSize:[aFont pointSize]+1]]; - [self setEditable:editableStatus]; -} - -/* - * Decrease the textView's font size by 1 but not smaller than 4pt - */ -- (void)makeTextSizeSmaller -{ - NSFont *aFont = [self font]; - int newSize = ([aFont pointSize]-1 < 4) ? [aFont pointSize] : [aFont pointSize]-1; - BOOL editableStatus = [self isEditable]; - [self setEditable:YES]; - [self setFont:[[NSFontManager sharedFontManager] convertFont:aFont toSize:newSize]]; - [self setEditable:editableStatus]; -} /* * Hook to invoke the auto-uppercasing of SQL keywords after pasting @@ -2480,196 +2456,6 @@ 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 )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.")); - NSBeep(); - 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); - NSBeep(); -} - -#pragma mark - -#pragma mark multi-touch trackpad support - -/* - * Trackpad two-finger zooming gesture in/decreases the font size - */ -- (void) magnifyWithEvent:(NSEvent *)anEvent -{ - if([anEvent deltaZ]>5.0) - [self makeTextSizeLarger]; - else if([anEvent deltaZ]<-5.0) - [self makeTextSizeSmaller]; - - [self insertText:@""]; -} - (void) dealloc { -- cgit v1.2.3