Revision: 5522
          http://skim-app.svn.sourceforge.net/skim-app/?rev=5522&view=rev
Author:   hofman
Date:     2009-08-08 11:34:31 +0000 (Sat, 08 Aug 2009)

Log Message:
-----------
implement paste: action to our general tableview subclass using delegate 
methods and use it in the download controller

Modified Paths:
--------------
    trunk/SKDownloadController.m
    trunk/SKTableView.h
    trunk/SKTableView.m

Modified: trunk/SKDownloadController.m
===================================================================
--- trunk/SKDownloadController.m        2009-08-08 11:18:18 UTC (rev 5521)
+++ trunk/SKDownloadController.m        2009-08-08 11:34:31 UTC (rev 5522)
@@ -200,16 +200,6 @@
         [[self mutableArrayValueForKey:DOWNLOADS_KEY] removeObject:download];
 }
 
-- (IBAction)paste:(id)sender {
-    NSPasteboard *pboard = [NSPasteboard generalPasteboard];
-    NSURL *theURL = [NSURL URLFromPasteboardAnyType:pboard];
-    
-    if ([theURL isFileURL])
-        [[NSDocumentController sharedDocumentController] 
openDocumentWithContentsOfURL:theURL display:YES error:NULL];
-    else if (theURL)
-        [self addDownloadForURL:theURL];
-}
-
 - (IBAction)showDownloadPreferences:(id)sender {
     [NSApp beginSheet:preferencesSheet modalForWindow:[self window] 
modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
 }
@@ -370,6 +360,20 @@
     return YES;
 }
 
+- (void)tableViewPaste:(NSTableView *)tv {
+    NSPasteboard *pboard = [NSPasteboard generalPasteboard];
+    NSURL *theURL = [NSURL URLFromPasteboardAnyType:pboard];
+    
+    if ([theURL isFileURL])
+        [[NSDocumentController sharedDocumentController] 
openDocumentWithContentsOfURL:theURL display:YES error:NULL];
+    else if (theURL)
+        [self addDownloadForURL:theURL];
+}
+
+- (BOOL)tableViewCanPaste:(NSTableView *)tv {
+    return (nil != [[NSPasteboard generalPasteboard] 
availableTypeFromArray:[NSArray arrayWithObjects:NSURLPboardType, 
SKWeblocFilePboardType, NSStringPboardType, nil]]);
+}
+
 - (NSMenu *)tableView:(NSTableView *)aTableView 
menuForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
     NSMenu *menu = [[[NSMenu allocWithZone:[NSMenu menuZone]] init] 
autorelease];
     NSMenuItem *menuItem;

Modified: trunk/SKTableView.h
===================================================================
--- trunk/SKTableView.h 2009-08-08 11:18:18 UTC (rev 5521)
+++ trunk/SKTableView.h 2009-08-08 11:34:31 UTC (rev 5522)
@@ -55,6 +55,9 @@
 - (BOOL)canCopy;
 - (void)copy:(id)sender;
 
+- (BOOL)canPaste;
+- (void)paste:(id)sender;
+
 - (void)scrollToBeginningOfDocument:(id)sender;
 - (void)scrollToEndOfDocument:(id)sender;
 
@@ -69,6 +72,9 @@
 - (void)tableView:(NSTableView *)aTableView copyRowsWithIndexes:(NSIndexSet 
*)rowIndexes;
 - (BOOL)tableView:(NSTableView *)aTableView canCopyRowsWithIndexes:(NSIndexSet 
*)rowIndexes;
 
+- (void)tableViewPaste:(NSTableView *)aTableView;
+- (BOOL)tableViewCanPaste:(NSTableView *)aTableView;
+
 - (NSMenu *)tableView:(NSTableView *)aTableView 
menuForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex;
 
 - (NSArray *)tableView:(NSTableView *)aTableView 
typeSelectHelperSelectionItems:(SKTypeSelectHelper *)aTypeSelectHelper;

Modified: trunk/SKTableView.m
===================================================================
--- trunk/SKTableView.m 2009-08-08 11:18:18 UTC (rev 5521)
+++ trunk/SKTableView.m 2009-08-08 11:34:31 UTC (rev 5522)
@@ -160,11 +160,30 @@
         NSBeep();
 }
 
+- (BOOL)canPaste {
+    if ([[self delegate] respondsToSelector:@selector(tableViewPaste:)]) {
+        if ([[self delegate] respondsToSelector:@selector(tableViewCanPaste:)])
+            return [[self delegate] tableViewCanPaste:self];
+        else
+            return YES;
+    }
+    return NO;
+}
+
+- (void)paste:(id)sender {
+    if ([self canPaste])
+        [[self delegate] tableViewPaste:self];
+    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 ([menuItem action] == @selector(paste:))
+        return [self canPaste];
     else if ([menuItem action] == @selector(selectAll:))
         return [self allowsMultipleSelection];
     else if ([menuItem action] == @selector(deselectAll:))


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to