Revision: 15190
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=15190&view=rev
Author: hofman
Date: 2009-04-25 22:05:41 +0000 (Sat, 25 Apr 2009)
Log Message:
-----------
Tableview delete does not necessarily delete the selected rows, so use the rows
or items as passed in the delegate methods.
Modified Paths:
--------------
trunk/bibdesk/BDSKFileContentSearchController.h
trunk/bibdesk/BDSKFileContentSearchController.m
trunk/bibdesk/BibDocument_Actions.h
trunk/bibdesk/BibDocument_Actions.m
trunk/bibdesk/BibDocument_DataSource.m
trunk/bibdesk/BibDocument_Groups.h
trunk/bibdesk/BibDocument_Groups.m
trunk/bibdesk/BibPref_Export.m
Modified: trunk/bibdesk/BDSKFileContentSearchController.h
===================================================================
--- trunk/bibdesk/BDSKFileContentSearchController.h 2009-04-25 21:21:26 UTC
(rev 15189)
+++ trunk/bibdesk/BDSKFileContentSearchController.h 2009-04-25 22:05:41 UTC
(rev 15190)
@@ -77,6 +77,10 @@
- (NSArray *)selectedURLs;
- (NSArray *)selectedResults;
+- (NSArray *)identifierURLsAtIndexes:(NSIndexSet *)indexes;
+- (NSArray *)URLsAtIndexes:(NSIndexSet *)indexes;
+- (NSArray *)resultsAtIndexes:(NSIndexSet *)indexes;
+
- (NSArray *)results;
- (void)setResults:(NSArray *)newResults;
- (NSArray *)filteredResults;
Modified: trunk/bibdesk/BDSKFileContentSearchController.m
===================================================================
--- trunk/bibdesk/BDSKFileContentSearchController.m 2009-04-25 21:21:26 UTC
(rev 15189)
+++ trunk/bibdesk/BDSKFileContentSearchController.m 2009-04-25 22:05:41 UTC
(rev 15190)
@@ -360,6 +360,19 @@
return [resultsArrayController selectedObjects];
}
+- (NSArray *)identifierURLsAtIndexes:(NSIndexSet *)indexes
+{
+ return [[[resultsArrayController arrangedObjects]
objectsAtIndexes:indexes]
valueForKeyPath:@"@distinctUnionOfObjects.identifierURL"];
+}
+
+- (NSArray *)URLsAtIndexes:(NSIndexSet *)indexes {
+ return [[[resultsArrayController arrangedObjects]
objectsAtIndexes:indexes] valueForKeyPath:@"@distinctUnionOfObjects.URL"];
+}
+
+- (NSArray *)resultsAtIndexes:(NSIndexSet *)indexes {
+ return [[resultsArrayController arrangedObjects] objectsAtIndexes:indexes];
+}
+
#pragma mark -
#pragma mark SearchKit methods
Modified: trunk/bibdesk/BibDocument_Actions.h
===================================================================
--- trunk/bibdesk/BibDocument_Actions.h 2009-04-25 21:21:26 UTC (rev 15189)
+++ trunk/bibdesk/BibDocument_Actions.h 2009-04-25 22:05:41 UTC (rev 15190)
@@ -57,21 +57,12 @@
*/
- (IBAction)newPub:(id)sender; // new pub button pressed.
-/*!
- @method deleteSelectedPubs:
- @abstract Deletes the selected publications from the document
- @discussion Action of the Delete button. It removes the selected items of
the tableview from the publications array. It assumes that there is at least
one selected item -- the worst that could happen should be that the change
count is wrong if it's called otherwise.
- @param sender The sending object - not used.
-
-*/
+- (void)deletePubs:(NSArray *)pubs;
+
- (IBAction)deleteSelectedPubs:(id)sender;
-/*!
- @method removeSelectedPubs:
- @abstract Removes the selected publications from the selected groups
- @discussion It removes the selected items of the tableview from the groups
selected in the group tableview, or deletes them if the first group is
selected. It assumes that there is at least one selected item -- the worst that
could happen should be that the change count is wrong if it's called otherwise.
- @param sender The sending object - not used.
-
-*/
+
+- (void)removePubs:(NSArray *)pubs;
+
- (IBAction)removeSelectedPubs:(id)sender;
/*!
Modified: trunk/bibdesk/BibDocument_Actions.m
===================================================================
--- trunk/bibdesk/BibDocument_Actions.m 2009-04-25 21:21:26 UTC (rev 15189)
+++ trunk/bibdesk/BibDocument_Actions.m 2009-04-25 22:05:41 UTC (rev 15190)
@@ -185,30 +185,30 @@
}
- (void)removePubsAlertDidEnd:(NSAlert *)alert
returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
- if ([alert suppressionButtonState] == NSOnState)
+ NSArray *pubs = [(NSArray *)contextInfo autorelease];
+ if ([alert suppressionButtonState] == NSOnState)
[[NSUserDefaults standardUserDefaults] setBool:NO
forKey:BDSKWarnOnRemovalFromGroupKey];
if (returnCode == NSAlertDefaultReturn)
- [self removePublications:[self selectedPublications] fromGroups:[self
selectedGroups]];
+ [self removePublications:pubs fromGroups:[self selectedGroups]];
}
// this method is called for the main table; it's a wrapper for delete or
remove from group
-- (IBAction)removeSelectedPubs:(id)sender{
+- (void)removePubs:(NSArray *)pubs{
NSArray *selectedGroups = [self selectedGroups];
- if([self hasLibraryGroupSelected]){
- [self deleteSelectedPubs:sender];
- }else{
+ if ([self hasLibraryGroupSelected]) {
+ [self deletePubs:pubs];
+ } else {
BOOL canRemove = NO;
if ([self hasStaticGroupsSelected])
canRemove = YES;
else if ([[self currentGroupField] isSingleValuedGroupField] == NO)
canRemove = [self hasCategoryGroupsSelected];
- if(canRemove == NO){
+ if (canRemove == NO) {
NSBeep();
- return;
}
// the items may not belong to the groups that you're trying to remove
them from, but we'll warn as if they were
- if ([[NSUserDefaults standardUserDefaults]
boolForKey:BDSKWarnOnRemovalFromGroupKey]) {
+ else if ([[NSUserDefaults standardUserDefaults]
boolForKey:BDSKWarnOnRemovalFromGroupKey]) {
NSString *groupName = ([selectedGroups count] > 1 ?
NSLocalizedString(@"multiple groups", @"multiple groups") : [NSString
stringWithFormat:NSLocalizedString(@"group \"%...@\"", @"group \"Name\""),
[[selectedGroups firstObject] stringValue]]);
NSAlert *alert = [NSAlert
alertWithMessageText:NSLocalizedString(@"Warning", @"Message in alert dialog")
defaultButton:NSLocalizedString(@"Yes", @"Button title")
@@ -220,15 +220,19 @@
[alert beginSheetModalForWindow:documentWindow
modalDelegate:self
didEndSelector:@selector(removePubsAlertDidEnd:returnCode:contextInfo:)
- contextInfo:NULL];
- return;
+ contextInfo:[pubs retain]];
} else {
- [self removePublications:[self selectedPublications]
fromGroups:selectedGroups];
+ [self removePublications:pubs fromGroups:selectedGroups];
}
}
}
+- (IBAction)removeSelectedPubs:(id)sender{
+ [self removePubs:[self selectedGroups]];
+}
+
- (void)deletePubsAlertDidEnd:(NSAlert *)alert
returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
+ NSArray *pubs = [(NSArray *)contextInfo autorelease];
if (alert != nil && [alert suppressionButtonState] == NSOnState)
[[NSUserDefaults standardUserDefaults] setBool:NO
forKey:BDSKWarnOnDeleteKey];
if (returnCode == NSAlertOtherReturn)
@@ -236,12 +240,12 @@
// deletion changes the scroll position
NSTableView *tv = [self isDisplayingFileContentSearch] ?
[fileSearchController tableView] : tableView;
- NSInteger numSelectedPubs = [self numberOfSelectedPubs];
+ NSInteger numPubs = [pubs count];
// This is preserved as an ivar; since removePublications: triggers an
async search as a UI update, restoring the selection/scroll position here will
no longer work if a search is active. Storing a row is safe since sort order
should be stable.
rowToSelectAfterDelete = [[tv selectedRowIndexes] lastIndex];
scrollLocationAfterDelete = [[tv enclosingScrollView]
scrollPositionAsPercentage];
- [self removePublications:[self selectedPublications]];
+ [self removePublications:pubs];
if([NSString isEmptyString:[self searchString]]) {
if(rowToSelectAfterDelete >= [tv numberOfRows])
@@ -254,7 +258,7 @@
}
NSString * pubSingularPlural;
- if (numSelectedPubs == 1) {
+ if (numPubs == 1) {
pubSingularPlural = NSLocalizedString(@"publication",
@"publication, in status message");
} else {
pubSingularPlural = NSLocalizedString(@"publications",
@"publications, in status message");
@@ -263,17 +267,16 @@
[[self undoManager] setActionName:[NSString
stringWithFormat:NSLocalizedString(@"Delete %@", @"Undo action name: Delete
Publication(s)"),pubSingularPlural]];
}
-- (IBAction)deleteSelectedPubs:(id)sender{
- NSInteger numSelectedPubs = [self numberOfSelectedPubs];
- if (numSelectedPubs == 0 ||
- [self hasExternalGroupsSelected] == YES) {
+- (void)deletePubs:(NSArray *)pubs {
+ NSInteger numPubs = [pubs count];
+ if (numPubs == 0 || [self hasExternalGroupsSelected] == YES) {
return;
}
if ([[NSUserDefaults standardUserDefaults]
boolForKey:BDSKWarnOnDeleteKey]) {
NSString *info;
- if (numSelectedPubs > 1)
- info = [NSString stringWithFormat:NSLocalizedString(@"You are
about to delete %ld publications. Do you want to proceed?", @"Informative text
in alert dialog"), (long)numSelectedPubs];
+ if (numPubs > 1)
+ info = [NSString stringWithFormat:NSLocalizedString(@"You are
about to delete %ld publications. Do you want to proceed?", @"Informative text
in alert dialog"), (long)numPubs];
else
info = NSLocalizedString(@"You are about to delete a publication.
Do you want to proceed?", @"Informative text in alert dialog");
NSAlert *alert = [NSAlert
alertWithMessageText:NSLocalizedString(@"Warning", @"Message in alert dialog")
@@ -286,12 +289,16 @@
[alert beginSheetModalForWindow:documentWindow
modalDelegate:self
didEndSelector:@selector(deletePubsAlertDidEnd:returnCode:contextInfo:)
- contextInfo:NULL];
+ contextInfo:[pubs retain]];
} else {
- [self deletePubsAlertDidEnd:nil returnCode:NSAlertDefaultReturn
contextInfo:NULL];
+ [self deletePubsAlertDidEnd:nil returnCode:NSAlertDefaultReturn
contextInfo:[pubs retain]];
}
}
+- (IBAction)deleteSelectedPubs:(id)sender{
+ [self deletePubs:[self selectedPublications]];
+}
+
// -delete:, -alternateDelete:, -copy:, -cut:, -alternateCut:, -paste:, and
-duplicate are defined in BDSKTableView and BDSKMainTableView using dataSource
methods
- (IBAction)copyAsAction:(id)sender{
Modified: trunk/bibdesk/BibDocument_DataSource.m
===================================================================
--- trunk/bibdesk/BibDocument_DataSource.m 2009-04-25 21:21:26 UTC (rev
15189)
+++ trunk/bibdesk/BibDocument_DataSource.m 2009-04-25 22:05:41 UTC (rev
15190)
@@ -81,6 +81,7 @@
#import <FileView/FileView.h>
#import "BDSKApplication.h"
#import "BDSKAppController.h"
+#import "BDSKFileContentSearchController.h"
#define MAX_DRAG_IMAGE_WIDTH 700.0
@@ -1067,9 +1068,18 @@
}
- (void)tableView:(NSTableView *)tv deleteRowsWithIndexes:(NSIndexSet
*)rowIndexes {
- // the rows are always the selected rows
- if (tv == tableView || tv == [fileSearchController tableView]) {
- [self removeSelectedPubs:nil];
+ if (tv == tableView) {
+ [self removePubs:[shownPublications
objectsAtIndexes:rowIndexes]];
+ } else if (tv == [fileSearchController tableView]) {
+ NSMutableArray *pubs = [NSMutableArray array];
+ NSEnumerator *itemEnum = [[fileSearchController
identifierURLsAtIndexes:rowIndexes] objectEnumerator];
+ NSURL *idURL;
+ BibItem *pub;
+ while (idURL = [itemEnum nextObject]) {
+ if (pub = [publications itemForIdentifierURL:idURL])
+ [pubs addObject:pub];
+ }
+ [self removePubs:pubs];
}
}
@@ -1081,9 +1091,18 @@
}
- (void)tableView:(NSTableView *)tv alternateDeleteRowsWithIndexes:(NSIndexSet
*)rowIndexes {
- // the rows are always the selected rows
- if (tv == tableView || tv == [fileSearchController tableView]) {
- [self deleteSelectedPubs:nil];
+ if (tv == tableView) {
+ [self deletePubs:[shownPublications
objectsAtIndexes:rowIndexes]];
+ } else if (tv == [fileSearchController tableView]) {
+ NSMutableArray *pubs = [NSMutableArray array];
+ NSEnumerator *itemEnum = [[fileSearchController
identifierURLsAtIndexes:rowIndexes] objectEnumerator];
+ NSURL *idURL;
+ BibItem *pub;
+ while (idURL = [itemEnum nextObject]) {
+ if (pub = [publications itemForIdentifierURL:idURL])
+ [pubs addObject:pub];
+ }
+ [self deletePubs:pubs];
}
}
@@ -1704,8 +1723,6 @@
#pragma mark OutlineView actions
-// the next 3 are called from tableview actions defined in
NSTableView_OAExtensions
-
- (void)outlineViewInsertNewline:(NSOutlineView *)ov {
if (ov == groupOutlineView) {
[self renameGroupAction:nil];
@@ -1713,15 +1730,14 @@
}
- (void)outlineView:(NSOutlineView *)ov deleteItems:(NSArray *)items {
- // the rows are always the selected rows
if (ov == groupOutlineView) {
- [self removeSelectedGroups:nil];
+ [self removeGroups:items];
}
}
- (BOOL)outlineView:(NSOutlineView *)ov canDeleteItems:(NSArray *)items {
if (ov == groupOutlineView) {
- return [self hasStaticGroupsSelected] || [self
hasSmartGroupsSelected] || [self hasSearchGroupsSelected] || [self
hasURLGroupsSelected] || [self hasScriptGroupsSelected];
+ return [[items filteredArrayUsingPredicate:[NSPredicate
predicateWithFormat:@"isStatic == YES OR isSmart == YES OR isSearch == YES OR
isURL == YES OR isScript == YES"]] count] > 0;
}
return NO;
}
Modified: trunk/bibdesk/BibDocument_Groups.h
===================================================================
--- trunk/bibdesk/BibDocument_Groups.h 2009-04-25 21:21:26 UTC (rev 15189)
+++ trunk/bibdesk/BibDocument_Groups.h 2009-04-25 22:05:41 UTC (rev 15190)
@@ -107,6 +107,7 @@
- (IBAction)addSearchBookmark:(id)sender;
- (IBAction)dismissSearchBookmarkSheet:(id)sender;
- (IBAction)addGroupButtonAction:(id)sender;
+- (void)removeGroups:(NSArray *)theGroups;
- (IBAction)removeSelectedGroups:(id)sender;
- (void)editGroup:(BDSKGroup *)group;
- (IBAction)editGroupAction:(id)sender;
Modified: trunk/bibdesk/BibDocument_Groups.m
===================================================================
--- trunk/bibdesk/BibDocument_Groups.m 2009-04-25 21:21:26 UTC (rev 15189)
+++ trunk/bibdesk/BibDocument_Groups.m 2009-04-25 22:05:41 UTC (rev 15190)
@@ -1026,8 +1026,8 @@
[self addStaticGroupAction:sender];
}
-- (IBAction)removeSelectedGroups:(id)sender {
- NSEnumerator *groupEnum = [[self selectedGroups] objectEnumerator];
+- (void)removeGroups:(NSArray *)theGroups {
+ NSEnumerator *groupEnum = [theGroups objectEnumerator];
BDSKGroup *group;
BOOL didRemove = NO;
@@ -1054,6 +1054,10 @@
}
}
+- (IBAction)removeSelectedGroups:(id)sender {
+ [self removeGroups:[self selectedGroups]];
+}
+
- (void)editGroup:(BDSKGroup *)group {
if ([group isEditable] == NO) {
Modified: trunk/bibdesk/BibPref_Export.m
===================================================================
--- trunk/bibdesk/BibPref_Export.m 2009-04-25 21:21:26 UTC (rev 15189)
+++ trunk/bibdesk/BibPref_Export.m 2009-04-25 22:05:41 UTC (rev 15190)
@@ -344,14 +344,18 @@
}
}
+- (BOOL)canDeleteItem:(BDSKTreeNode *)item
+{
+ return ((templatePrefList == BDSKExportTemplateList && [item isLeaf] ==
NO) ||
+ ([item isLeaf] && [[item valueForKey:BDSKTemplateRoleString]
isEqualToString:BDSKTemplateMainPageString] == NO));
+}
+
- (BOOL)canDeleteSelectedItem
{
NSInteger row = [outlineView selectedRow];
- BDSKTreeNode *selItem = row == -1 ? nil : [outlineView itemAtRow:row];
- if (selItem == nil)
+ if (row == -1)
return NO;
- return ((templatePrefList == BDSKExportTemplateList && [selItem isLeaf] ==
NO) ||
- ([selItem isLeaf] && [[selItem
valueForKey:BDSKTemplateRoleString] isEqualToString:BDSKTemplateMainPageString]
== NO));
+ return [self canDeleteItem:[outlineView itemAtRow:row]];
}
// we can't add items to the services outline view
@@ -368,16 +372,22 @@
- (void)outlineView:(NSOutlineView *)ov deleteItems:(NSArray *)items;
{
- // currently we don't allow multiple selection, so we'll ignore the rows
argument
- if([self canDeleteSelectedItem])
+ // currently we don't allow multiple selection
+ BDSKTreeNode *item = [items lastObject];
+ if(item && [self canDeleteItem:item]) {
[self removeNode:nil];
- else
+ if ([item isLeaf])
+ [[item parent] removeChild:item];
+ else
+ [itemNodes removeObjectIdenticalTo:item];
+ [self updateUI];
+ } else
NSBeep();
}
- (BOOL)outlineView:(NSOutlineView *)ov canDeleteItems:(NSArray *)items {
- // currently we don't allow multiple selection, so we'll ignore the rows
argument
- return [self canDeleteSelectedItem];
+ // currently we don't allow multiple selection
+ return [self canDeleteItem:[items lastObject]];
}
- (BOOL)outlineView:(NSOutlineView *)ov isGroupItem:(id)item {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit