Revision: 15260
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=15260&view=rev
Author: hofman
Date: 2009-05-04 09:51:40 +0000 (Mon, 04 May 2009)
Log Message:
-----------
check groups one by one for single selection, simplifies the delegate method
and only enumerates the groups to select. Fix selectAll in group table. Remove
now unused delegate methods.
Modified Paths:
--------------
trunk/bibdesk/BDSKGroupOutlineView.h
trunk/bibdesk/BDSKGroupOutlineView.m
trunk/bibdesk/BibDocument_DataSource.m
Modified: trunk/bibdesk/BDSKGroupOutlineView.h
===================================================================
--- trunk/bibdesk/BDSKGroupOutlineView.h 2009-05-04 09:07:14 UTC (rev
15259)
+++ trunk/bibdesk/BDSKGroupOutlineView.h 2009-05-04 09:51:40 UTC (rev
15260)
@@ -53,7 +53,7 @@
@interface NSObject (BDSKGroupTableViewDelegate)
- (NSIndexSet *)outlineView:(BDSKGroupOutlineView *)anOutlineView
indexesOfRowsToHighlightInRange:(NSRange)indexRange;
-- (NSIndexSet *)outlineViewSingleSelectionIndexes:(BDSKGroupOutlineView
*)anOutlineView;
-- (void)outlineView:(BDSKGroupOutlineView *)aTableView
doubleClickedOnIconOfItem:(id)item;
-- (BOOL)outlineViewShouldEditNextItemWhenEditingEnds:(BDSKGroupOutlineView
*)aTableView;
+- (BOOL)outlineView:(BDSKGroupOutlineView *)anOutlineView
isSingleSelectionItem:(id)item;
+- (void)outlineView:(BDSKGroupOutlineView *)anOutlineView
doubleClickedOnIconOfItem:(id)item;
+- (BOOL)outlineViewShouldEditNextItemWhenEditingEnds:(BDSKGroupOutlineView
*)anOutlineView;
@end
Modified: trunk/bibdesk/BDSKGroupOutlineView.m
===================================================================
--- trunk/bibdesk/BDSKGroupOutlineView.m 2009-05-04 09:07:14 UTC (rev
15259)
+++ trunk/bibdesk/BDSKGroupOutlineView.m 2009-05-04 09:51:40 UTC (rev
15260)
@@ -222,18 +222,21 @@
// make sure that certain rows are only selected as a single selection
- (void)selectRowIndexes:(NSIndexSet *)indexes
byExtendingSelection:(BOOL)shouldExtend{
- NSIndexSet *singleIndexes = nil;
- if ([[self delegate]
respondsToSelector:@selector(outlineViewSingleSelectionIndexes:)])
- singleIndexes = [[self delegate]
outlineViewSingleSelectionIndexes:self];
-
- // don't extend rows that should be in single selection
- if (shouldExtend == YES && singleIndexes && [[self selectedRowIndexes]
intersectsIndexSet:singleIndexes])
- return;
- // remove single selection rows from multiple selections
- if ((shouldExtend == YES || [indexes count] > 1) && singleIndexes &&
[indexes intersectsIndexSet:singleIndexes]) {
- NSMutableIndexSet *mutableIndexes = [[indexes mutableCopy]
autorelease];
- [mutableIndexes removeIndexes:singleIndexes];
- indexes = mutableIndexes;
+ if ([[self delegate]
respondsToSelector:@selector(outlineView:isSingleSelectionItem:)]) {
+ // don't extend rows that should be in single selection
+ if (shouldExtend && [[self selectedRowIndexes] count] == 1 &&
+ [[self delegate] outlineView:self isSingleSelectionItem:[self
itemAtRow:[[self selectedRowIndexes] firstIndex]]])
+ return;
+ // remove single selection rows from multiple selections
+ if (shouldExtend || [indexes count] > 1) {
+ NSMutableIndexSet *mutableIndexes = [NSMutableIndexSet indexSet];
+ NSUInteger row = [indexes firstIndex];
+ while (row != NSNotFound) {
+ if ([[self delegate] outlineView:self
isSingleSelectionItem:[self itemAtRow:row]] == NO)
+ [mutableIndexes addIndex:row];
+ }
+ indexes = mutableIndexes;
+ }
}
if ([indexes count] == 0)
return;
@@ -265,21 +268,19 @@
// the default implementation is broken with the above modifications, and
would be invalid anyway
- (IBAction)selectAll:(id)sender {
- NSIndexSet *singleIndexes = nil;
- if ([[self delegate]
respondsToSelector:@selector(outlineViewSingleSelectionIndexes:)])
- singleIndexes = [[self delegate]
outlineViewSingleSelectionIndexes:self];
+ BOOL hasSingle = [[self delegate]
respondsToSelector:@selector(outlineView:isSingleSelectionItem:)];
+ BOOL hasUnselectable = [[self delegate]
respondsToSelector:@selector(outlineView:shouldSelectItem:)];
NSMutableIndexSet *indexes = [NSMutableIndexSet
indexSetWithIndexesInRange:NSMakeRange(0, [self numberOfRows])];
- [indexes removeIndexes:singleIndexes];
- if ([[self delegate]
respondsToSelector:@selector(outlineView:shouldSelectItem:)]) {
- NSMutableIndexSet *selectableIndexes = [NSMutableIndexSet indexSet];
+ if (hasSingle || hasUnselectable) {
NSUInteger row = [indexes firstIndex];
while (NSNotFound != row) {
- if ([[self delegate] outlineView:self shouldSelectItem:[self
itemAtRow:row]]) {
- [selectableIndexes addIndex:row];
- }
+ id item = [self itemAtRow:row];
+ if ((hasSingle && [[self delegate] outlineView:self
isSingleSelectionItem:item]) ||
+ (hasUnselectable && [[self delegate] outlineView:self
shouldSelectItem:item] == NO))
+ [indexes removeIndex:row];
+ row = [indexes indexGreaterThanIndex:row];
}
- indexes = selectableIndexes;
}
if ([indexes count] == 0) {
Modified: trunk/bibdesk/BibDocument_DataSource.m
===================================================================
--- trunk/bibdesk/BibDocument_DataSource.m 2009-05-04 09:07:14 UTC (rev
15259)
+++ trunk/bibdesk/BibDocument_DataSource.m 2009-05-04 09:51:40 UTC (rev
15260)
@@ -1179,6 +1179,31 @@
return [item cellValue];
}
+- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object
forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
+ // should never receive this for parent groups
+ if ([item isParent])
+ return;
+
+ BDSKGroup *group = item;
+ // object is always a group, see BDSKGroupCellFormatter
+ BDSKASSERT([object isKindOfClass:[NSDictionary class]]);
+ NSString *newName = [object valueForKey:BDSKGroupCellStringKey];
+ if([[group editingStringValue] isEqualToString:newName])
+ return;
+ if ([group isCategory]) {
+ NSArray *pubs = [groupedPublications copy];
+ // change the name of the group first, so we can preserve the
selection; we need to old group info to move though
+ id name = [[self currentGroupField] isPersonField] ? (id)[BibAuthor
authorWithName:newName andPub:[[group name] publication]] : (id)newName;
+ BDSKCategoryGroup *oldGroup = [[[BDSKCategoryGroup alloc]
initWithName:[group name] key:[(BDSKCategoryGroup *)group key] count:[group
count]] autorelease];
+ [(BDSKCategoryGroup *)group setName:name];
+ [self movePublications:pubs fromGroup:oldGroup toGroupNamed:newName];
+ [pubs release];
+ } else if([group hasEditableName]) {
+ [(BDSKMutableGroup *)group setName:newName];
+ [[self undoManager] setActionName:NSLocalizedString(@"Rename Group",
@"Undo action name")];
+ }
+}
+
#pragma mark OutlineView delegate
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldCollapseItem:(id)item {
@@ -1205,31 +1230,6 @@
return [item isParent];
}
-- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object
forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
- // should never receive this for parent groups
- if ([item isParent])
- return;
-
- BDSKGroup *group = item;
- // object is always a group, see BDSKGroupCellFormatter
- BDSKASSERT([object isKindOfClass:[NSDictionary class]]);
- NSString *newName = [object valueForKey:BDSKGroupCellStringKey];
- if([[group editingStringValue] isEqualToString:newName])
- return;
- if ([group isCategory]) {
- NSArray *pubs = [groupedPublications copy];
- // change the name of the group first, so we can preserve the
selection; we need to old group info to move though
- id name = [[self currentGroupField] isPersonField] ? (id)[BibAuthor
authorWithName:newName andPub:[[group name] publication]] : (id)newName;
- BDSKCategoryGroup *oldGroup = [[[BDSKCategoryGroup alloc]
initWithName:[group name] key:[(BDSKCategoryGroup *)group key] count:[group
count]] autorelease];
- [(BDSKCategoryGroup *)group setName:name];
- [self movePublications:pubs fromGroup:oldGroup toGroupNamed:newName];
- [pubs release];
- } else if([group hasEditableName]) {
- [(BDSKMutableGroup *)group setName:newName];
- [[self undoManager] setActionName:NSLocalizedString(@"Rename Group",
@"Undo action name")];
- }
-}
-
- (BOOL)outlineView:(NSOutlineView *)outlineView
shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item {
if ([item isParent] || [item hasEditableName] == NO) {
return NO;
@@ -1255,12 +1255,6 @@
[self updateSmartGroupsCountAndContent:YES];
}
-- (void)outlineView:(NSOutlineView *)outlineView
didClickTableColumn:(NSTableColumn *)tableColumn {
- // check whether this is the right kind of table view and don't re-sort
when we have a contextual menu click
- if ([[NSApp currentEvent] type] != NSRightMouseDown)
- [self sortGroupsByKey:sortGroupsKey];
-}
-
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell
forTableColumn:(NSTableColumn *)tableColumn item:(id)item {
BDSKGroup *group = item;
NSProgressIndicator *spinner = nil;
@@ -1346,28 +1340,14 @@
return indexSet;
}
-- (NSIndexSet *)outlineViewSingleSelectionIndexes:(BDSKGroupOutlineView *)ov {
- NSMutableIndexSet *indexes = [NSMutableIndexSet indexSetWithIndex:0];
- NSInteger i;
- for (i = 0; i < [ov numberOfRows]; i++) {
- BDSKGroup *group = [ov itemAtRow:i];
- if ([group isExternal])
- [indexes addIndex:i];
- }
- return indexes;
+- (BOOL)outlineView:(BDSKGroupOutlineView *)ov isSingleSelectionItem:(id)item {
+ return [item isEqual:[groups libraryGroup]] || [item isExternal];
}
- (void)outlineView:(BDSKGroupOutlineView *)aTableView
doubleClickedOnIconOfItem:(id)item {
[self editGroup:item];
}
-- (NSMenu *)outlineView:(BDSKGroupOutlineView *)anOutlineView
menuForTableHeaderColumn:(NSTableColumn *)tableColumn onPopUp:(BOOL)flag {
- if (flag == NO) {
- return [[NSApp delegate] groupSortMenu];
- }
- return nil;
-}
-
- (BOOL)outlineViewShouldEditNextItemWhenEditingEnds:(BDSKGroupOutlineView
*)ov{
if (ov == groupOutlineView && [[NSUserDefaults standardUserDefaults]
boolForKey:BDSKWarnOnRenameGroupKey])
return NO;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations
Conference from O'Reilly Media. Velocity features a full day of
expert-led, hands-on workshops and two days of sessions from industry
leaders in dedicated Performance & Operations tracks. Use code vel09scf
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit