From: <ho...@us...> - 2011-04-29 09:19:03
|
Revision: 17858 http://bibdesk.svn.sourceforge.net/bibdesk/?rev=17858&view=rev Author: hofman Date: 2011-04-29 09:18:54 +0000 (Fri, 29 Apr 2011) Log Message: ----------- move text import view classes to separate files Modified Paths: -------------- trunk/bibdesk/BDSKTextImportController.h trunk/bibdesk/BDSKTextImportController.m trunk/bibdesk/Bibdesk.xcodeproj/project.pbxproj Added Paths: ----------- trunk/bibdesk/BDSKImportTextView.h trunk/bibdesk/BDSKImportTextView.m trunk/bibdesk/BDSKTextImportItemTableView.h trunk/bibdesk/BDSKTextImportItemTableView.m Added: trunk/bibdesk/BDSKImportTextView.h =================================================================== --- trunk/bibdesk/BDSKImportTextView.h (rev 0) +++ trunk/bibdesk/BDSKImportTextView.h 2011-04-29 09:18:54 UTC (rev 17858) @@ -0,0 +1,44 @@ +// +// BDSKImportTextView.h +// Bibdesk +// +// Created by Christiaan Hofman on 4/29/11. +/* + This software is Copyright (c) 2011 + Christiaan Hofman. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of Christiaan Hofman nor the names of any + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import <Cocoa/Cocoa.h> + + +@interface BDSKImportTextView : NSTextView +- (IBAction)makePlainText:(id)sender; +@end Added: trunk/bibdesk/BDSKImportTextView.m =================================================================== --- trunk/bibdesk/BDSKImportTextView.m (rev 0) +++ trunk/bibdesk/BDSKImportTextView.m 2011-04-29 09:18:54 UTC (rev 17858) @@ -0,0 +1,66 @@ +// +// BDSKImportTextView.m +// Bibdesk +// +// Created by Christiaan Hofman on 4/29/11. +/* + This software is Copyright (c) 2011 + Christiaan Hofman. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of Christiaan Hofman nor the names of any + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import "BDSKImportTextView.h" + + +@implementation BDSKImportTextView + +- (IBAction)makePlainText:(id)sender{ + NSTextStorage *textStorage = [self textStorage]; + [textStorage setAttributes:nil range:NSMakeRange(0,[textStorage length])]; +} + +- (NSMenu *)menuForEvent:(NSEvent *)event{ + NSMenu *menu = [super menuForEvent:event]; + NSInteger i, count = [menu numberOfItems]; + + for (i = 0; i < count; i++) { + if ([[menu itemAtIndex:i] action] == @selector(paste:)) { + [menu insertItemWithTitle:NSLocalizedString(@"Paste as Plain Text", @"Menu item title") action:@selector(pasteAsPlainText:) keyEquivalent:@"" atIndex:i+1]; + break; + } + } + + [menu addItem:[NSMenuItem separatorItem]]; + [menu addItemWithTitle:NSLocalizedString(@"Make Plain Text", @"Menu item title") action:@selector(makePlainText:) keyEquivalent:@""]; + + return menu; +} + +@end Modified: trunk/bibdesk/BDSKTextImportController.h =================================================================== --- trunk/bibdesk/BDSKTextImportController.h 2011-04-29 06:35:53 UTC (rev 17857) +++ trunk/bibdesk/BDSKTextImportController.h 2011-04-29 09:18:54 UTC (rev 17858) @@ -38,18 +38,11 @@ #import <Cocoa/Cocoa.h> #import "BDSKOwnerProtocol.h" -#import "BDSKTableView.h" +#import "BDSKTextImportItemTableView.h" #import "BDSKComplexStringFormatter.h" #import "BDSKCitationFormatter.h" #import "BDSKWebView.h" -@protocol BDSKTextImportItemTableViewDelegate <BDSKTableViewDelegate> -- (void)tableViewDidChangeTemporaryTypeSelectMode:(NSTableView *)tView; -- (BOOL)tableView:(NSTableView *)tView performActionForRow:(NSInteger)row; -@end - -#pragma mark - - @class BibDocument, BibItem, BDSKEdgeView, WebDownload, BDSKComplexStringEditor; @class BDSKCiteKeyFormatter, BDSKCrossrefFormatter; @@ -135,26 +128,3 @@ - (void)downloadLinkedFileAsLocalUrl:(id)sender; @end - -#pragma mark - - -@interface BDSKTextImportItemTableView : BDSKTableView { - BOOL temporaryTypeSelectMode; - NSResponder *savedFirstResponder; - BOOL didSetValue; -} -- (BOOL)isInTemporaryTypeSelectMode; -- (void)startTemporaryTypeSelectMode; -- (void)endTemporaryTypeSelectMode; -- (BOOL)performActionForRow:(NSInteger)row; -#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 -- (id <BDSKTextImportItemTableViewDelegate>)delegate; -- (void)setDelegate:(id <BDSKTextImportItemTableViewDelegate>)newDelegate; -#endif -@end - -#pragma mark - - -@interface BDSKImportTextView : NSTextView {} -- (IBAction)makePlainText:(id)sender; -@end Modified: trunk/bibdesk/BDSKTextImportController.m =================================================================== --- trunk/bibdesk/BDSKTextImportController.m 2011-04-29 06:35:53 UTC (rev 17857) +++ trunk/bibdesk/BDSKTextImportController.m 2011-04-29 09:18:54 UTC (rev 17858) @@ -1699,202 +1699,3 @@ } @end - -#pragma mark - - -@interface NSTableView (BDSKApplePrivate2) -- (void)_dataSourceSetValue:(id)value forColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; -@end - -@implementation BDSKTextImportItemTableView - -- (BOOL)performKeyEquivalent:(NSEvent *)theEvent{ - - unichar c = [theEvent firstCharacter]; - NSUInteger flags = [theEvent modifierFlags]; - - if (flags & NSCommandKeyMask) { - - if (c >= '0' && c <= '9') { - - NSUInteger idx = c == '0' ? 9 : (NSUInteger)(c - '1'); - if (flags & NSAlternateKeyMask) - idx += 10; - BOOL rv = [self performActionForRow:idx]; - if (temporaryTypeSelectMode) - [self endTemporaryTypeSelectMode]; - return rv; - - } else if (temporaryTypeSelectMode) { - - if (c == NSTabCharacter || c == 0x001b) { - [self endTemporaryTypeSelectMode]; - } else if (c == NSCarriageReturnCharacter || c == NSEnterCharacter || c == NSNewlineCharacter) { - [self endTemporaryTypeSelectMode]; - [self performActionForRow:[self selectedRow]]; - } - if (temporaryTypeSelectMode == NO) { - NSInteger row = [self selectedRow]; - if (row != -1) - [self editColumn:2 row:row withEvent:nil select:YES]; - return YES; - } - - } else if (c == '=') { - - [self startTemporaryTypeSelectMode]; - return YES; - } - } - - return [super performKeyEquivalent:theEvent]; -} - -- (void)keyDown:(NSEvent *)event{ - unichar c = [event firstCharacter]; - NSUInteger flags = ([event deviceIndependentModifierFlags] & ~NSAlphaShiftKeyMask); - - static NSCharacterSet *fieldNameCharSet = nil; - if (fieldNameCharSet == nil) - fieldNameCharSet = [[[[BDSKTypeManager sharedManager] strictInvalidCharactersForField:BDSKCiteKeyString] invertedSet] copy]; - - if (temporaryTypeSelectMode) { - if ((c == NSTabCharacter || c == 0x001b) && flags == 0) { - [self endTemporaryTypeSelectMode]; - return; - } else if ((c == NSCarriageReturnCharacter || c == NSEnterCharacter || c == NSNewlineCharacter) && flags == 0) { - [self endTemporaryTypeSelectMode]; - [self performActionForRow:[self selectedRow]]; - return; - } else if ([[self typeSelectHelper] isTypeSelectEvent:event] == NO && - (c != NSDownArrowFunctionKey && c != NSUpArrowFunctionKey && c != NSHomeFunctionKey && c != NSEndFunctionKey)) { - // we allow navigation in the table using arrow keys - NSBeep(); - return; - } - } - - [super keyDown:event]; -} - -- (BOOL)isInTemporaryTypeSelectMode { - return temporaryTypeSelectMode; -} - -- (void)startTemporaryTypeSelectMode { - if (temporaryTypeSelectMode) - return; - temporaryTypeSelectMode = YES; - savedFirstResponder = [[self window] firstResponder]; - if ([savedFirstResponder isKindOfClass:[NSTextView class]] && [(NSTextView *)savedFirstResponder isFieldEditor]) - savedFirstResponder = (NSResponder *)[(NSTextView *)savedFirstResponder delegate]; - [[self window] makeFirstResponder:self]; - if ([self selectedRow] == -1 && [self numberOfRows] > 0) - [self selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO]; - [[self delegate] tableViewDidChangeTemporaryTypeSelectMode:self]; -} - -- (void)endTemporaryTypeSelectMode { - if (temporaryTypeSelectMode == NO) - return; - temporaryTypeSelectMode = NO; - [[self window] makeFirstResponder:savedFirstResponder]; - savedFirstResponder = nil; - [[self delegate] tableViewDidChangeTemporaryTypeSelectMode:self]; -} - -- (BOOL)performActionForRow:(NSInteger)row { - if ([[self delegate] tableView:self performActionForRow:row]) { - return YES; - } else { - NSBeep(); - return NO; - } -} - -- (BOOL)resignFirstResponder { - [self endTemporaryTypeSelectMode]; - return [super resignFirstResponder]; -} - -- (void)awakeFromNib{ - BDSKTypeSelectHelper *aTypeSelectHelper = [[BDSKTypeSelectHelper alloc] init]; - [aTypeSelectHelper setCyclesSimilarResults:YES]; - [self setTypeSelectHelper:aTypeSelectHelper]; - [aTypeSelectHelper release]; -} - -- (void)textDidEndEditing:(NSNotification *)aNotification { - /* - NSTableView has an optimization of sorts where the value will not be set if the string in the cell - is equal to the old string. When you want to change e.g. year={2009} to year=2009, this becomes - a problem. I got fed up with deleting the old string, then setting the new raw string. - - Note that the current cell's objectValue is still the old value, so we have to work with the formatter - directly in order to get the (possibly complex) edited string. - */ - NSInteger editedRow = [self editedRow]; - NSInteger editedColumn = [self editedColumn]; - BOOL shouldCheckValue = NO; - id newValue = nil; - if (editedColumn >= 0 && editedRow >= 0 && [self respondsToSelector:@selector(_dataSourceSetValue:forColumn:row:)]) { - NSCell *editedCell = [self preparedCellAtColumn:editedColumn row:editedRow]; - NSFormatter *formatter = [editedCell formatter]; - id oldValue = [editedCell objectValue]; - newValue = [[aNotification object] string]; - if (formatter == nil || [formatter getObjectValue:&newValue forString:newValue errorDescription:NULL]) { - shouldCheckValue = [oldValue respondsToSelector:@selector(isEqualAsComplexString:)] && - [newValue respondsToSelector:@selector(isEqualAsComplexString:)] && - [oldValue isEqualAsComplexString:newValue] == NO; - } - newValue = [newValue copy]; - } - didSetValue = NO; - - [super textDidEndEditing:aNotification]; - - // only try setting if NSTableView did not, and if these are not equal as complex strings - if (didSetValue == NO && shouldCheckValue) - [self _dataSourceSetValue:newValue forColumn:[[self tableColumns] objectAtIndex:editedColumn] row:editedRow]; - [newValue release]; - - // on Leopard, we have to manually handle tab/return movements to avoid losing focus - // http://www.cocoabuilder.com/archive/message/cocoa/2007/10/31/191866 -} - -#pragma mark Delegate and DataSource - -#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 -- (id <BDSKTextImportItemTableViewDelegate>)delegate { return (id <BDSKTextImportItemTableViewDelegate>)[super delegate]; } -- (void)setDelegate:(id <BDSKTextImportItemTableViewDelegate>)newDelegate { [super setDelegate:newDelegate]; } -#endif - -@end - -#pragma mark - - -@implementation BDSKImportTextView - -- (IBAction)makePlainText:(id)sender{ - NSTextStorage *textStorage = [self textStorage]; - [textStorage setAttributes:nil range:NSMakeRange(0,[textStorage length])]; -} - -- (NSMenu *)menuForEvent:(NSEvent *)event{ - NSMenu *menu = [super menuForEvent:event]; - NSInteger i, count = [menu numberOfItems]; - - for (i = 0; i < count; i++) { - if ([[menu itemAtIndex:i] action] == @selector(paste:)) { - [menu insertItemWithTitle:NSLocalizedString(@"Paste as Plain Text", @"Menu item title") action:@selector(pasteAsPlainText:) keyEquivalent:@"" atIndex:i+1]; - break; - } - } - - [menu addItem:[NSMenuItem separatorItem]]; - [menu addItemWithTitle:NSLocalizedString(@"Make Plain Text", @"Menu item title") action:@selector(makePlainText:) keyEquivalent:@""]; - - return menu; -} - -@end Added: trunk/bibdesk/BDSKTextImportItemTableView.h =================================================================== --- trunk/bibdesk/BDSKTextImportItemTableView.h (rev 0) +++ trunk/bibdesk/BDSKTextImportItemTableView.h 2011-04-29 09:18:54 UTC (rev 17858) @@ -0,0 +1,66 @@ +// +// BDSKTextImportItemTableView.h +// Bibdesk +// +// Created by Christiaan Hofman on 4/29/11. +/* + This software is Copyright (c) 2011 + Christiaan Hofman. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of Christiaan Hofman nor the names of any + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import <Cocoa/Cocoa.h> +#import "BDSKTableView.h" + + +@protocol BDSKTextImportItemTableViewDelegate <BDSKTableViewDelegate> +- (void)tableViewDidChangeTemporaryTypeSelectMode:(NSTableView *)tView; +- (BOOL)tableView:(NSTableView *)tView performActionForRow:(NSInteger)row; +@end + + +@interface BDSKTextImportItemTableView : BDSKTableView { + BOOL temporaryTypeSelectMode; + NSResponder *savedFirstResponder; + BOOL didSetValue; +} + +- (BOOL)isInTemporaryTypeSelectMode; +- (void)startTemporaryTypeSelectMode; +- (void)endTemporaryTypeSelectMode; + +- (BOOL)performActionForRow:(NSInteger)row; + +#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 +- (id <BDSKTextImportItemTableViewDelegate>)delegate; +- (void)setDelegate:(id <BDSKTextImportItemTableViewDelegate>)newDelegate; +#endif + +@end Added: trunk/bibdesk/BDSKTextImportItemTableView.m =================================================================== --- trunk/bibdesk/BDSKTextImportItemTableView.m (rev 0) +++ trunk/bibdesk/BDSKTextImportItemTableView.m 2011-04-29 09:18:54 UTC (rev 17858) @@ -0,0 +1,212 @@ +// +// BDSKTextImportItemTableView.m +// Bibdesk +// +// Created by Christiaan Hofman on 4/29/11. +/* + This software is Copyright (c) 2011 + Christiaan Hofman. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of Christiaan Hofman nor the names of any + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import "BDSKTextImportItemTableView.h" +#import "BDSKTypeManager.h" +#import "NSEvent_BDSKExtensions.h" + + +@interface NSTableView (BDSKApplePrivate2) +- (void)_dataSourceSetValue:(id)value forColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; +@end + + +@implementation BDSKTextImportItemTableView + +- (BOOL)performKeyEquivalent:(NSEvent *)theEvent{ + + unichar c = [theEvent firstCharacter]; + NSUInteger flags = [theEvent modifierFlags]; + + if (flags & NSCommandKeyMask) { + + if (c >= '0' && c <= '9') { + + NSUInteger idx = c == '0' ? 9 : (NSUInteger)(c - '1'); + if (flags & NSAlternateKeyMask) + idx += 10; + BOOL rv = [self performActionForRow:idx]; + if (temporaryTypeSelectMode) + [self endTemporaryTypeSelectMode]; + return rv; + + } else if (temporaryTypeSelectMode) { + + if (c == NSTabCharacter || c == 0x001b) { + [self endTemporaryTypeSelectMode]; + } else if (c == NSCarriageReturnCharacter || c == NSEnterCharacter || c == NSNewlineCharacter) { + [self endTemporaryTypeSelectMode]; + [self performActionForRow:[self selectedRow]]; + } + if (temporaryTypeSelectMode == NO) { + NSInteger row = [self selectedRow]; + if (row != -1) + [self editColumn:2 row:row withEvent:nil select:YES]; + return YES; + } + + } else if (c == '=') { + + [self startTemporaryTypeSelectMode]; + return YES; + } + } + + return [super performKeyEquivalent:theEvent]; +} + +- (void)keyDown:(NSEvent *)event{ + unichar c = [event firstCharacter]; + NSUInteger flags = ([event deviceIndependentModifierFlags] & ~NSAlphaShiftKeyMask); + + static NSCharacterSet *fieldNameCharSet = nil; + if (fieldNameCharSet == nil) + fieldNameCharSet = [[[[BDSKTypeManager sharedManager] strictInvalidCharactersForField:BDSKCiteKeyString] invertedSet] copy]; + + if (temporaryTypeSelectMode) { + if ((c == NSTabCharacter || c == 0x001b) && flags == 0) { + [self endTemporaryTypeSelectMode]; + return; + } else if ((c == NSCarriageReturnCharacter || c == NSEnterCharacter || c == NSNewlineCharacter) && flags == 0) { + [self endTemporaryTypeSelectMode]; + [self performActionForRow:[self selectedRow]]; + return; + } else if ([[self typeSelectHelper] isTypeSelectEvent:event] == NO && + (c != NSDownArrowFunctionKey && c != NSUpArrowFunctionKey && c != NSHomeFunctionKey && c != NSEndFunctionKey)) { + // we allow navigation in the table using arrow keys + NSBeep(); + return; + } + } + + [super keyDown:event]; +} + +- (BOOL)isInTemporaryTypeSelectMode { + return temporaryTypeSelectMode; +} + +- (void)startTemporaryTypeSelectMode { + if (temporaryTypeSelectMode) + return; + temporaryTypeSelectMode = YES; + savedFirstResponder = [[self window] firstResponder]; + if ([savedFirstResponder isKindOfClass:[NSTextView class]] && [(NSTextView *)savedFirstResponder isFieldEditor]) + savedFirstResponder = (NSResponder *)[(NSTextView *)savedFirstResponder delegate]; + [[self window] makeFirstResponder:self]; + if ([self selectedRow] == -1 && [self numberOfRows] > 0) + [self selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO]; + [[self delegate] tableViewDidChangeTemporaryTypeSelectMode:self]; +} + +- (void)endTemporaryTypeSelectMode { + if (temporaryTypeSelectMode == NO) + return; + temporaryTypeSelectMode = NO; + [[self window] makeFirstResponder:savedFirstResponder]; + savedFirstResponder = nil; + [[self delegate] tableViewDidChangeTemporaryTypeSelectMode:self]; +} + +- (BOOL)performActionForRow:(NSInteger)row { + if ([[self delegate] tableView:self performActionForRow:row]) { + return YES; + } else { + NSBeep(); + return NO; + } +} + +- (BOOL)resignFirstResponder { + [self endTemporaryTypeSelectMode]; + return [super resignFirstResponder]; +} + +- (void)awakeFromNib{ + BDSKTypeSelectHelper *aTypeSelectHelper = [[BDSKTypeSelectHelper alloc] init]; + [aTypeSelectHelper setCyclesSimilarResults:YES]; + [self setTypeSelectHelper:aTypeSelectHelper]; + [aTypeSelectHelper release]; +} + +- (void)textDidEndEditing:(NSNotification *)aNotification { + /* + NSTableView has an optimization of sorts where the value will not be set if the string in the cell + is equal to the old string. When you want to change e.g. year={2009} to year=2009, this becomes + a problem. I got fed up with deleting the old string, then setting the new raw string. + + Note that the current cell's objectValue is still the old value, so we have to work with the formatter + directly in order to get the (possibly complex) edited string. + */ + NSInteger editedRow = [self editedRow]; + NSInteger editedColumn = [self editedColumn]; + BOOL shouldCheckValue = NO; + id newValue = nil; + if (editedColumn >= 0 && editedRow >= 0 && [self respondsToSelector:@selector(_dataSourceSetValue:forColumn:row:)]) { + NSCell *editedCell = [self preparedCellAtColumn:editedColumn row:editedRow]; + NSFormatter *formatter = [editedCell formatter]; + id oldValue = [editedCell objectValue]; + newValue = [[aNotification object] string]; + if (formatter == nil || [formatter getObjectValue:&newValue forString:newValue errorDescription:NULL]) { + shouldCheckValue = [oldValue respondsToSelector:@selector(isEqualAsComplexString:)] && + [newValue respondsToSelector:@selector(isEqualAsComplexString:)] && + [oldValue isEqualAsComplexString:newValue] == NO; + } + newValue = [newValue copy]; + } + didSetValue = NO; + + [super textDidEndEditing:aNotification]; + + // only try setting if NSTableView did not, and if these are not equal as complex strings + if (didSetValue == NO && shouldCheckValue) + [self _dataSourceSetValue:newValue forColumn:[[self tableColumns] objectAtIndex:editedColumn] row:editedRow]; + [newValue release]; + + // on Leopard, we have to manually handle tab/return movements to avoid losing focus + // http://www.cocoabuilder.com/archive/message/cocoa/2007/10/31/191866 +} + +#pragma mark Delegate and DataSource + +#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 +- (id <BDSKTextImportItemTableViewDelegate>)delegate { return (id <BDSKTextImportItemTableViewDelegate>)[super delegate]; } +- (void)setDelegate:(id <BDSKTextImportItemTableViewDelegate>)newDelegate { [super setDelegate:newDelegate]; } +#endif + +@end Modified: trunk/bibdesk/Bibdesk.xcodeproj/project.pbxproj =================================================================== --- trunk/bibdesk/Bibdesk.xcodeproj/project.pbxproj 2011-04-29 06:35:53 UTC (rev 17857) +++ trunk/bibdesk/Bibdesk.xcodeproj/project.pbxproj 2011-04-29 09:18:54 UTC (rev 17858) @@ -120,6 +120,10 @@ CE3256000A1748D0002D6E4C /* NSGeometry_BDSKExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = CE3255FE0A1748D0002D6E4C /* NSGeometry_BDSKExtensions.m */; }; CE325FCE0A1A74E9002D6E4C /* BDSKTemplateParser.m in Sources */ = {isa = PBXBuildFile; fileRef = CE325FCC0A1A74E9002D6E4C /* BDSKTemplateParser.m */; }; CE3263C5128806C3000040EC /* BDSKFieldCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = CE3263C3128806C3000040EC /* BDSKFieldCollection.m */; }; + CE33D606136AB73600ACE924 /* BDSKTextImportItemTableView.h in Headers */ = {isa = PBXBuildFile; fileRef = CE33D604136AB73600ACE924 /* BDSKTextImportItemTableView.h */; }; + CE33D607136AB73600ACE924 /* BDSKTextImportItemTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = CE33D605136AB73600ACE924 /* BDSKTextImportItemTableView.m */; }; + CE33D61B136AB8A700ACE924 /* BDSKImportTextView.h in Headers */ = {isa = PBXBuildFile; fileRef = CE33D619136AB8A700ACE924 /* BDSKImportTextView.h */; }; + CE33D61C136AB8A700ACE924 /* BDSKImportTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = CE33D61A136AB8A700ACE924 /* BDSKImportTextView.m */; }; CE3402750E014B3800A7FFE6 /* NSNumber_BDSKExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = CE3402730E014B3800A7FFE6 /* NSNumber_BDSKExtensions.m */; }; CE3448020A11302F0026A92A /* BDSKPreviewItem.m in Sources */ = {isa = PBXBuildFile; fileRef = CE3448000A11302F0026A92A /* BDSKPreviewItem.m */; }; CE34A5740B249E0B00755730 /* BDSKMARCParser.m in Sources */ = {isa = PBXBuildFile; fileRef = CE34A5720B249E0B00755730 /* BDSKMARCParser.m */; }; @@ -939,6 +943,10 @@ CE325FCC0A1A74E9002D6E4C /* BDSKTemplateParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BDSKTemplateParser.m; sourceTree = "<group>"; }; CE3263C2128806C3000040EC /* BDSKFieldCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BDSKFieldCollection.h; sourceTree = "<group>"; }; CE3263C3128806C3000040EC /* BDSKFieldCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BDSKFieldCollection.m; sourceTree = "<group>"; }; + CE33D604136AB73600ACE924 /* BDSKTextImportItemTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BDSKTextImportItemTableView.h; sourceTree = "<group>"; }; + CE33D605136AB73600ACE924 /* BDSKTextImportItemTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BDSKTextImportItemTableView.m; sourceTree = "<group>"; }; + CE33D619136AB8A700ACE924 /* BDSKImportTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BDSKImportTextView.h; sourceTree = "<group>"; }; + CE33D61A136AB8A700ACE924 /* BDSKImportTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BDSKImportTextView.m; sourceTree = "<group>"; }; CE3402720E014B3800A7FFE6 /* NSNumber_BDSKExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSNumber_BDSKExtensions.h; sourceTree = "<group>"; }; CE3402730E014B3800A7FFE6 /* NSNumber_BDSKExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSNumber_BDSKExtensions.m; sourceTree = "<group>"; }; CE3448000A11302F0026A92A /* BDSKPreviewItem.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = BDSKPreviewItem.m; sourceTree = "<group>"; }; @@ -2032,8 +2040,8 @@ isa = PBXGroup; children = ( 3D824AA707D099C300FB2F67 /* BDSKBackgroundView.m */, - CEF63D0810888A5A000A31E2 /* BDSKSeparatorCell.m */, 2730077707CF20B500F2E485 /* BDSKBorderlessKeyWindow.m */, + CE96DB7010C7288800F085F3 /* BDSKButtonBar.m */, CEEC6C53093A411E00A64F54 /* BDSKCollapsibleView.m */, CE6003270AF3E465000B5680 /* BDSKColoredView.m */, CE34E9780A03C16B00222942 /* BDSKConditionsView.m */, @@ -2058,6 +2066,7 @@ CEC7D0240F680C970051794E /* BDSKIconTextFieldCell.m */, CE3B682709D1B0190017D339 /* BDSKImagePopUpButton.m */, CE3B682909D1B0190017D339 /* BDSKImagePopUpButtonCell.m */, + CE33D61A136AB8A700ACE924 /* BDSKImportTextView.m */, F92405010BC5856900672839 /* BDSKLevelIndicatorCell.m */, CEF536691192EFE400027C3C /* BDSKNotesOutlineView.m */, CE62E0BE0F4C4A5500BDF01E /* BDSKOutlineView.m */, @@ -2070,11 +2079,12 @@ CEF7A6670915115B00BE9E02 /* BDSKScriptMenu.m */, F9EF21B308B1572500AAC9A9 /* BDSKScrollableTextField.m */, F9EF21B508B1572500AAC9A9 /* BDSKScrollableTextFieldCell.m */, - CE96DB7010C7288800F085F3 /* BDSKButtonBar.m */, + CEF63D0810888A5A000A31E2 /* BDSKSeparatorCell.m */, CE62E0920F4C46D600BDF01E /* BDSKSplitView.m */, F9A411F00A0B1FEF008493C0 /* BDSKSpotlightView.m */, CE30FAD60919713100CB1A19 /* BDSKStatusBar.m */, CE62E0B80F4C4A2100BDF01E /* BDSKTableView.m */, + CE33D605136AB73600ACE924 /* BDSKTextImportItemTableView.m */, F9DCEA4E094B7D1100AEE662 /* BDSKTextWithIconCell.m */, CE6DACC30A503ECF00123185 /* BDSKToolbarItem.m */, CEF7F42512743BCC00B20881 /* BDSKWebView.m */, @@ -2646,6 +2656,7 @@ CE3B682609D1B0190017D339 /* BDSKImagePopUpButton.h */, CE3B682809D1B0190017D339 /* BDSKImagePopUpButtonCell.h */, CE40EC520EE9AAEF00BCF379 /* BDSKImportCommand.h */, + CE33D619136AB8A700ACE924 /* BDSKImportTextView.h */, F97C9DB00C4481670002EE01 /* BDSKISIGroupServer.h */, F97C9DBC0C44866F0002EE01 /* BDSKISIWebServices.h */, CE7A313F0B08EA1F00D1B333 /* BDSKItemPasteboardHelper.h */, @@ -2751,6 +2762,7 @@ CE325FCB0A1A74E9002D6E4C /* BDSKTemplateParser.h */, F9DB895A08A54BBA00CB3D53 /* BDSKTeXTask.h */, 27AFAF9A080D1E1B0096F5D2 /* BDSKTextImportController.h */, + CE33D604136AB73600ACE924 /* BDSKTextImportItemTableView.h */, F98AA67F0971E3F400184BD8 /* BDSKTextViewCompletionController.h */, F9DCEA4D094B7D1100AEE662 /* BDSKTextWithIconCell.h */, F963E42A0A1D7ADD00695DDC /* BDSKTreeNode.h */, @@ -2938,6 +2950,8 @@ files = ( CE424A450D0F123500F824E7 /* BDSKCompletionServerProtocol.h in Headers */, CE095D51135C52B5000E4396 /* BDSKSelectCommand.h in Headers */, + CE33D606136AB73600ACE924 /* BDSKTextImportItemTableView.h in Headers */, + CE33D61B136AB8A700ACE924 /* BDSKImportTextView.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -3777,6 +3791,8 @@ CE3263C5128806C3000040EC /* BDSKFieldCollection.m in Sources */, CE0B3B3C1292E1A500BA05EB /* BDSKErrorObject.m in Sources */, CE095D52135C52B5000E4396 /* BDSKSelectCommand.m in Sources */, + CE33D607136AB73600ACE924 /* BDSKTextImportItemTableView.m in Sources */, + CE33D61C136AB8A700ACE924 /* BDSKImportTextView.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |