Revision: 2710
http://skim-app.svn.sourceforge.net/skim-app/?rev=2710&view=rev
Author: hofman
Date: 2007-08-23 04:08:50 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
Move delete and copy support to custom base table classes.
Implement copying for note table and delete for donwload table.
Modified Paths:
--------------
trunk/SKMainWindowController.m
trunk/SKNoteOutlineView.h
trunk/SKNoteOutlineView.m
trunk/SKOutlineView.h
trunk/SKOutlineView.m
trunk/SKTableView.h
trunk/SKTableView.m
trunk/SKThumbnailTableView.h
trunk/SKThumbnailTableView.m
Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m 2007-08-23 08:51:51 UTC (rev 2709)
+++ trunk/SKMainWindowController.m 2007-08-23 11:08:50 UTC (rev 2710)
@@ -3230,13 +3230,74 @@
[item setRowHeight:newHeight];
}
-- (void)outlineViewDeleteSelectedRows:(NSOutlineView *)ov {
- if ([ov isEqual:noteOutlineView] && [ov selectedRow] != -1) {
- [pdfView removeAnnotation:[self selectedNote]];
+- (NSArray *)noteItems:(NSArray *)items {
+ NSEnumerator *itemEnum = [items objectEnumerator];
+ PDFAnnotation *item;
+ NSMutableArray *noteItems = [NSMutableArray array];
+
+ while (item = [itemEnum nextObject]) {
+ if ([item type] == nil) {
+ item = [(SKNoteText *)item annotation];
+ }
+ if ([noteItems containsObject:item] == NO)
+ [noteItems addObject:item];
+ }
+ return noteItems;
+}
+
+- (void)outlineView:(NSOutlineView *)ov deleteItems:(NSArray *)items {
+ if ([ov isEqual:noteOutlineView] && [items count]) {
+ NSEnumerator *itemEnum = [[self noteItems:items] objectEnumerator];
+ PDFAnnotation *item;
+ while (item = [itemEnum nextObject])
+ [pdfView removeAnnotation:item];
[[[self document] undoManager]
setActionName:NSLocalizedString(@"Remove Note", @"Undo action name")];
}
}
+- (BOOL)outlineView:(NSOutlineView *)ov canDeleteItems:(NSArray *)items {
+ if ([ov isEqual:noteOutlineView]) {
+ return [items count] > 0;
+ }
+ return NO;
+}
+
+- (void)outlineView:(NSOutlineView *)ov copyItems:(NSArray *)items {
+ if ([ov isEqual:noteOutlineView] && [items count]) {
+ NSEnumerator *itemEnum = [[self noteItems:items] objectEnumerator];
+ PDFAnnotation *item = nil;
+ id firstItem = [items objectAtIndex:0];
+ while (item = [itemEnum nextObject])
+ if ([item isMovable]) break;
+ NSPasteboard *pboard = [NSPasteboard generalPasteboard];
+ NSMutableArray *types = [NSMutableArray array];
+ NSData *noteData = item ? [NSKeyedArchiver
archivedDataWithRootObject:[item dictionaryValue]] : nil;
+ NSAttributedString *attrString = [firstItem type] ? nil : [(SKNoteText
*)firstItem contents];
+ NSString *string = [firstItem type] ? [firstItem contents] :
[attrString string];
+ if (noteData)
+ [types addObject:SKSkimNotePboardType];
+ if (string)
+ [types addObject:NSStringPboardType];
+ if (attrString)
+ [types addObject:NSRTFPboardType];
+ if ([types count])
+ [pboard declareTypes:types owner:nil];
+ if (noteData)
+ [pboard setData:noteData forType:SKSkimNotePboardType];
+ if (string)
+ [pboard setString:string forType:NSStringPboardType];
+ if (attrString)
+ [pboard setData:[attrString RTFFromRange:NSMakeRange(0, [string
length]) documentAttributes:nil] forType:NSRTFPboardType];
+ }
+}
+
+- (BOOL)outlineView:(NSOutlineView *)ov canCopyItems:(NSArray *)items {
+ if ([ov isEqual:noteOutlineView]) {
+ return [items count] > 0;
+ }
+ return NO;
+}
+
- (NSArray *)outlineViewHighlightedRows:(NSOutlineView *)ov {
if ([ov isEqual:outlineView]) {
NSMutableArray *array = [NSMutableArray array];
@@ -3270,10 +3331,14 @@
- (void)deleteNote:(id)sender {
PDFAnnotation *annotation = [sender representedObject];
- [pdfView removeAnnotation:annotation];
- [[[self document] undoManager] setActionName:NSLocalizedString(@"Remove
Note", @"Undo action name")];
+ [self outlineView:noteOutlineView deleteItems:[NSArray
arrayWithObjects:annotation, nil]];
}
+- (void)copyNote:(id)sender {
+ PDFAnnotation *annotation = [sender representedObject];
+ [self outlineView:noteOutlineView copyItems:[NSArray
arrayWithObjects:annotation, nil]];
+}
+
- (void)selectNote:(id)sender {
PDFAnnotation *annotation = [sender representedObject];
[pdfView setActiveAnnotation:annotation];
@@ -3285,25 +3350,33 @@
- (NSMenu *)outlineView:(NSOutlineView *)ov menuForTableColumn:(NSTableColumn
*)tableColumn item:(id)item {
NSMenu *menu = nil;
+ NSMenuItem *menuItem;
+
if ([ov isEqual:noteOutlineView]) {
- if ([item type] == nil)
- item = [(SKNoteText *)item annotation];
+ PDFAnnotation *annotation = [item type] ? item : [(SKNoteText *)item
annotation];
menu = [[[NSMenu allocWithZone:[NSMenu menuZone]] init] autorelease];
- NSMenuItem *menuItem = [menu
addItemWithTitle:NSLocalizedString(@"Delete", @"Menu item title")
action:@selector(deleteNote:) keyEquivalent:@""];
- [menuItem setTarget:self];
- [menuItem setRepresentedObject:item];
+ if ([self outlineView:ov canDeleteItems:[NSArray
arrayWithObjects:item, nil]]) {
+ menuItem = [menu addItemWithTitle:NSLocalizedString(@"Delete",
@"Menu item title") action:@selector(deleteNote:) keyEquivalent:@""];
+ [menuItem setTarget:self];
+ [menuItem setRepresentedObject:item];
+ }
+ if ([self outlineView:ov canCopyItems:[NSArray arrayWithObjects:item,
nil]]) {
+ menuItem = [menu addItemWithTitle:NSLocalizedString(@"Copy",
@"Menu item title") action:@selector(copyNote:) keyEquivalent:@""];
+ [menuItem setTarget:self];
+ [menuItem setRepresentedObject:item];
+ }
if ([pdfView hideNotes] == NO) {
- if ([item isEditable]) {
+ if ([annotation isEditable]) {
menuItem = [menu addItemWithTitle:NSLocalizedString(@"Edit",
@"Menu item title") action:@selector(editThisAnnotation:) keyEquivalent:@""];
[menuItem setTarget:pdfView];
- [menuItem setRepresentedObject:item];
+ [menuItem setRepresentedObject:annotation];
}
- if ([pdfView activeAnnotation] == item)
+ if ([pdfView activeAnnotation] == annotation)
menuItem = [menu
addItemWithTitle:NSLocalizedString(@"Deselect", @"Menu item title")
action:@selector(deselectNote:) keyEquivalent:@""];
else
menuItem = [menu addItemWithTitle:NSLocalizedString(@"Select",
@"Menu item title") action:@selector(selectNote:) keyEquivalent:@""];
[menuItem setTarget:self];
- [menuItem setRepresentedObject:item];
+ [menuItem setRepresentedObject:annotation];
}
}
return menu;
Modified: trunk/SKNoteOutlineView.h
===================================================================
--- trunk/SKNoteOutlineView.h 2007-08-23 08:51:51 UTC (rev 2709)
+++ trunk/SKNoteOutlineView.h 2007-08-23 11:08:50 UTC (rev 2710)
@@ -58,11 +58,9 @@
@interface NSObject (SKNoteOutlineViewDelegate)
-- (void)outlineViewDeleteSelectedRows:(NSOutlineView *)anOutlineView;
- (BOOL)outlineView:(NSOutlineView *)anOutlineView canResizeRowByItem:(id)item;
- (void)outlineView:(NSOutlineView *)anOutlineView
setHeightOfRow:(int)newHeight byItem:(id)item;
- (void)outlineViewNoteTypesDidChange:(NSOutlineView *)anOutlineView;
-- (NSMenu *)outlineView:(NSOutlineView *)anOutlineView
menuForTableColumn:(NSTableColumn *)tableColumn item:(id)item;
@end
Modified: trunk/SKNoteOutlineView.m
===================================================================
--- trunk/SKNoteOutlineView.m 2007-08-23 08:51:51 UTC (rev 2709)
+++ trunk/SKNoteOutlineView.m 2007-08-23 11:08:50 UTC (rev 2710)
@@ -53,50 +53,6 @@
[self noteTypeMenu]; // this sets the menu for the header view
}
-- (void)delete:(id)sender {
- if ([[self delegate]
respondsToSelector:@selector(outlineViewDeleteSelectedRows:)]) {
- if ([[self selectedRowIndexes] count] == 0)
- NSBeep();
- else
- [[self delegate] outlineViewDeleteSelectedRows:self];
- }
-}
-
-- (void)keyDown:(NSEvent *)theEvent {
- NSString *characters = [theEvent charactersIgnoringModifiers];
- unichar eventChar = [characters length] > 0 ? [characters
characterAtIndex:0] : 0;
- unsigned int modifiers = [theEvent modifierFlags] &
NSDeviceIndependentModifierFlagsMask;
-
- if ((eventChar == NSDeleteCharacter || eventChar ==
NSDeleteFunctionKey) && modifiers == 0)
- [self delete:self];
- else
- [super keyDown:theEvent];
-}
-
-- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
- if ([menuItem action] == @selector(delete:))
- return [[self selectedRowIndexes] count] > 0;
- else if ([NSOutlineView
instancesRespondToSelector:@selector(validateMenuItem:)])
- return [super validateMenuItem:menuItem];
- return YES;
-}
-
-- (NSMenu *)menuForEvent:(NSEvent *)theEvent {
- NSMenu *menu = nil;
-
- if ([[self delegate]
respondsToSelector:@selector(outlineView:menuForTableColumn:item:)]) {
- NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
- int row = [self rowAtPoint:mouseLoc];
- int column = [self columnAtPoint:mouseLoc];
- if (row != -1 && column != -1) {
- NSTableColumn *tableColumn = [[self tableColumns]
objectAtIndex:column];
- menu = [[self delegate] outlineView:self
menuForTableColumn:tableColumn item:[self itemAtRow:row]];
- }
- }
-
- return menu;
-}
-
- (BOOL)resizeRow:(int)row withEvent:(NSEvent *)theEvent {
id item = [self itemAtRow:row];
NSPoint startPoint = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
Modified: trunk/SKOutlineView.h
===================================================================
--- trunk/SKOutlineView.h 2007-08-23 08:51:51 UTC (rev 2709)
+++ trunk/SKOutlineView.h 2007-08-23 11:08:50 UTC (rev 2710)
@@ -44,10 +44,27 @@
SKTypeSelectHelper *typeSelectHelper;
}
+- (NSArray *)selectedItems;
+
- (SKTypeSelectHelper *)typeSelectHelper;
- (void)setTypeSelectHelper:(SKTypeSelectHelper *)newTypeSelectHelper;
+- (BOOL)canDelete;
+- (void)delete:(id)sender;
+
+- (BOOL)canCopy;
+- (void)copy:(id)sender;
+
- (void)scrollToBeginningOfDocument:(id)sender;
- (void)scrollToEndOfDocument:(id)sender;
@end
+
+
[EMAIL PROTECTED] NSObject (SKOutlineViewDelegate)
+- (void)outlineView:(NSOutlineView *)anOutlineView deleteItems:(NSArray
*)items;
+- (BOOL)outlineView:(NSOutlineView *)anOutlineView canDeleteItems:(NSArray
*)items;
+- (void)outlineView:(NSOutlineView *)anOutlineView copyItems:(NSArray *)items;
+- (BOOL)outlineView:(NSOutlineView *)anOutlineView canCopyItems:(NSArray
*)items;
+- (NSMenu *)outlineView:(NSOutlineView *)anOutlineView
menuForTableColumn:(NSTableColumn *)tableColumn item:(id)item;
[EMAIL PROTECTED]
Modified: trunk/SKOutlineView.m
===================================================================
--- trunk/SKOutlineView.m 2007-08-23 08:51:51 UTC (rev 2709)
+++ trunk/SKOutlineView.m 2007-08-23 11:08:50 UTC (rev 2710)
@@ -48,6 +48,18 @@
[super dealloc];
}
+- (NSArray *)selectedItems {
+ NSMutableArray *items = [NSMutableArray array];
+ NSIndexSet *indexes = [self selectedRowIndexes];
+ unsigned int index = [indexes firstIndex];
+
+ while (index != NSNotFound) {
+ [items addObject:[self itemAtRow:index]];
+ index = [indexes indexGreaterThanIndex:index];
+ }
+ return items;
+}
+
- (SKTypeSelectHelper *)typeSelectHelper {
return typeSelectHelper;
}
@@ -101,4 +113,66 @@
[self scrollRowToVisible:[self numberOfRows] - 1];
}
+- (BOOL)canDelete {
+ NSArray *items = [self selectedItems];
+ if ([items count] && [[self delegate]
respondsToSelector:@selector(outlineView:deleteItems:)]) {
+ if ([[self delegate]
respondsToSelector:@selector(outlineView:canDeleteItems:)])
+ return [[self delegate] outlineView:self canDeleteItems:items];
+ else
+ return YES;
+ }
+ return NO;
+}
+
+- (void)delete:(id)sender {
+ if ([self canDelete])
+ [[self delegate] outlineView:self deleteItems:[self selectedItems]];
+ else
+ NSBeep();
+}
+
+- (BOOL)canCopy {
+ NSArray *items = [self selectedItems];
+ if ([items count] && [[self delegate]
respondsToSelector:@selector(outlineView:copyItems:)]) {
+ if ([[self delegate]
respondsToSelector:@selector(outlineView:canCopyItems:)])
+ return [[self delegate] outlineView:self canCopyItems:items];
+ else
+ return YES;
+ }
+ return NO;
+}
+
+- (void)copy:(id)sender {
+ if ([self canCopy])
+ [[self delegate] outlineView:self copyItems:[self selectedItems]];
+ else
+ NSBeep();
+}
+
+- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
+ if ([menuItem action] == @selector(delete:))
+ return [self canDelete];
+ else if ([menuItem action] == @selector(copy:))
+ return [self canCopy];
+ else if ([[SKOutlineView superclass]
instancesRespondToSelector:@selector(validateMenuItem:)])
+ return [super validateMenuItem:menuItem];
+ return YES;
+}
+
+- (NSMenu *)menuForEvent:(NSEvent *)theEvent {
+ NSMenu *menu = nil;
+
+ if ([[self delegate]
respondsToSelector:@selector(outlineView:menuForTableColumn:item:)]) {
+ NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
+ int row = [self rowAtPoint:mouseLoc];
+ int column = [self columnAtPoint:mouseLoc];
+ if (row != -1 && column != -1) {
+ NSTableColumn *tableColumn = [[self tableColumns]
objectAtIndex:column];
+ menu = [[self delegate] outlineView:self
menuForTableColumn:tableColumn item:[self itemAtRow:row]];
+ }
+ }
+
+ return menu;
+}
+
@end
Modified: trunk/SKTableView.h
===================================================================
--- trunk/SKTableView.h 2007-08-23 08:51:51 UTC (rev 2709)
+++ trunk/SKTableView.h 2007-08-23 11:08:50 UTC (rev 2710)
@@ -50,6 +50,9 @@
- (BOOL)canDelete;
- (void)delete:(id)sender;
+- (BOOL)canCopy;
+- (void)copy:(id)sender;
+
- (void)scrollToBeginningOfDocument:(id)sender;
- (void)scrollToEndOfDocument:(id)sender;
@@ -59,4 +62,7 @@
@interface NSObject (SKTableViewDelegate)
- (void)tableView:(NSTableView *)aTableView deleteRowsWithIndexes:(NSIndexSet
*)rowIndexes;
- (BOOL)tableView:(NSTableView *)aTableView
canDeleteRowsWithIndexes:(NSIndexSet *)rowIndexes;
+- (void)tableView:(NSTableView *)aTableView copyRowsWithIndexes:(NSIndexSet
*)rowIndexes;
+- (BOOL)tableView:(NSTableView *)aTableView canCopyRowsWithIndexes:(NSIndexSet
*)rowIndexes;
+- (NSMenu *)tableView:(NSTableView *)aTableView
menuForTableColumn:(NSTableColumn *)tableColumn row:(int)rowIndex;
@end
Modified: trunk/SKTableView.m
===================================================================
--- trunk/SKTableView.m 2007-08-23 08:51:51 UTC (rev 2709)
+++ trunk/SKTableView.m 2007-08-23 11:08:50 UTC (rev 2710)
@@ -95,10 +95,13 @@
- (BOOL)canDelete {
NSIndexSet *indexes = [self selectedRowIndexes];
- return [indexes count] &&
- [[self delegate]
respondsToSelector:@selector(tableView:canDeleteRowsWithIndexes:)] &&
- [[self delegate]
respondsToSelector:@selector(tableView:deleteRowsWithIndexes:)] &&
- [[self delegate] tableView:self canDeleteRowsWithIndexes:indexes];
+ if ([indexes count] && [[self delegate]
respondsToSelector:@selector(tableView:deleteRowsWithIndexes:)]) {
+ if ([[self delegate]
respondsToSelector:@selector(tableView:canDeleteRowsWithIndexes:)])
+ return [[self delegate] tableView:self
canDeleteRowsWithIndexes:indexes];
+ else
+ return YES;
+ }
+ return NO;
}
- (void)delete:(id)sender {
@@ -108,10 +111,48 @@
NSBeep();
}
+- (BOOL)canCopy {
+ NSIndexSet *indexes = [self selectedRowIndexes];
+ if ([indexes count] && [[self delegate]
respondsToSelector:@selector(tableView:copyRowsWithIndexes:)]) {
+ if ([[self delegate]
respondsToSelector:@selector(tableView:canCopyRowsWithIndexes:)])
+ return [[self delegate] tableView:self
canCopyRowsWithIndexes:indexes];
+ else
+ return YES;
+ }
+ return NO;
+}
+
+- (void)copy:(id)sender {
+ if ([self canCopy])
+ [[self delegate] tableView:self copyRowsWithIndexes:[self
selectedRowIndexes]];
+ else
+ NSBeep();
+}
+
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
if ([menuItem action] == @selector(delete:))
return [self canDelete];
+ else if ([menuItem action] == @selector(copy:))
+ return [self canCopy];
+ else if ([[SKTableView superclass]
instancesRespondToSelector:@selector(validateMenuItem:)])
+ return [super validateMenuItem:menuItem];
return YES;
}
+- (NSMenu *)menuForEvent:(NSEvent *)theEvent {
+ NSMenu *menu = nil;
+
+ if ([[self delegate]
respondsToSelector:@selector(tableView:menuForTableColumn:row:)]) {
+ NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
+ int row = [self rowAtPoint:mouseLoc];
+ int column = [self columnAtPoint:mouseLoc];
+ if (row != -1 && column != -1) {
+ NSTableColumn *tableColumn = [[self tableColumns]
objectAtIndex:column];
+ menu = [[self delegate] tableView:self
menuForTableColumn:tableColumn row:row];
+ }
+ }
+
+ return menu;
+}
+
@end
Modified: trunk/SKThumbnailTableView.h
===================================================================
--- trunk/SKThumbnailTableView.h 2007-08-23 08:51:51 UTC (rev 2709)
+++ trunk/SKThumbnailTableView.h 2007-08-23 11:08:50 UTC (rev 2710)
@@ -48,7 +48,6 @@
}
- (BOOL)isScrolling;
-- (BOOL)canCopy;
@end
@@ -66,7 +65,4 @@
@interface NSObject (SKThumbnailTableViewDelegate)
- (NSArray *)tableViewHighlightedRows:(NSTableView *)tableView;
- (BOOL)tableView:(NSTableView *)tableView commandSelectRow:(int)rowIndex;
-- (void)tableView:(NSTableView *)aTableView copyRowsWithIndexes:(NSIndexSet
*)rowIndexes;
-- (BOOL)tableView:(NSTableView *)aTableView canCopyRowsWithIndexes:(NSIndexSet
*)rowIndexes;
-- (NSMenu *)tableView:(NSTableView *)aTableView
menuForTableColumn:(NSTableColumn *)tableColumn row:(int)rowIndex;
@end
Modified: trunk/SKThumbnailTableView.m
===================================================================
--- trunk/SKThumbnailTableView.m 2007-08-23 08:51:51 UTC (rev 2709)
+++ trunk/SKThumbnailTableView.m 2007-08-23 11:08:50 UTC (rev 2710)
@@ -132,45 +132,6 @@
[super mouseDown:theEvent];
}
-- (BOOL)canCopy {
- NSIndexSet *indexes = [self selectedRowIndexes];
- return [indexes count] &&
- [[self delegate]
respondsToSelector:@selector(tableView:canCopyRowsWithIndexes:)] &&
- [[self delegate]
respondsToSelector:@selector(tableView:copyRowsWithIndexes:)] &&
- [[self delegate] tableView:self canCopyRowsWithIndexes:indexes];
-}
-
-- (void)copy:(id)sender {
- if ([self canCopy])
- [[self delegate] tableView:self copyRowsWithIndexes:[self
selectedRowIndexes]];
- else
- NSBeep();
-}
-
-- (NSMenu *)menuForEvent:(NSEvent *)theEvent {
- NSMenu *menu = nil;
-
- if ([[self delegate]
respondsToSelector:@selector(tableView:menuForTableColumn:row:)]) {
- NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
- int row = [self rowAtPoint:mouseLoc];
- int column = [self columnAtPoint:mouseLoc];
- if (row != -1 && column != -1) {
- NSTableColumn *tableColumn = [[self tableColumns]
objectAtIndex:column];
- menu = [[self delegate] tableView:self
menuForTableColumn:tableColumn row:row];
- }
- }
-
- return menu;
-}
-
-- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
- if ([menuItem action] == @selector(copy:))
- return [self canCopy];
- else if ([NSTableView
instancesRespondToSelector:@selector(validateMenuItem:)])
- return [super validateMenuItem:menuItem];
- return YES;
-}
-
@end
#pragma mark -
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit