Revision: 18030
          http://bibdesk.svn.sourceforge.net/bibdesk/?rev=18030&view=rev
Author:   dstebila
Date:     2011-07-31 03:58:32 +0000 (Sun, 31 Jul 2011)

Log Message:
-----------
Add "Open URL in BibDesk web group" to the Services menu.

Modified Paths:
--------------
    trunk/bibdesk/BDSKServiceProvider.h
    trunk/bibdesk/BDSKServiceProvider.m
    trunk/bibdesk/Info.plist
    trunk/bibdesk/NSURL_BDSKExtensions.h
    trunk/bibdesk/NSURL_BDSKExtensions.m

Modified: trunk/bibdesk/BDSKServiceProvider.h
===================================================================
--- trunk/bibdesk/BDSKServiceProvider.h 2011-07-30 06:34:58 UTC (rev 18029)
+++ trunk/bibdesk/BDSKServiceProvider.h 2011-07-31 03:58:32 UTC (rev 18030)
@@ -50,5 +50,6 @@
 - (void)showPubWithKey:(NSPasteboard *)pboard userData:(NSString *)userData 
error:(NSString **)error;
 - (void)openDocumentFromSelection:(NSPasteboard *)pboard userData:(NSString 
*)userData error:(NSString **)error;
 - (void)addPublicationsFromSelection:(NSPasteboard *)pboard userData:(NSString 
*)userData error:(NSString **)error;
+- (void)openURLInWebGroup:(NSPasteboard *)pboard userData:(NSString *)userData 
error:(NSString **)error;
 
 @end

Modified: trunk/bibdesk/BDSKServiceProvider.m
===================================================================
--- trunk/bibdesk/BDSKServiceProvider.m 2011-07-30 06:34:58 UTC (rev 18029)
+++ trunk/bibdesk/BDSKServiceProvider.m 2011-07-31 03:58:32 UTC (rev 18030)
@@ -41,10 +41,12 @@
 #import "BibDocument.h"
 #import "BibDocument_Search.h"
 #import "BibDocument_Actions.h"
+#import "BibDocument_Groups.h"
 #import "BDSKTemplate.h"
 #import "BDSKTemplateObjectProxy.h"
 #import "BDSKDocumentController.h"
 #import "NSSet_BDSKExtensions.h"
+#import "NSURL_BDSKExtensions.h"
 
 
 @implementation BDSKServiceProvider
@@ -353,4 +355,23 @@
     }
 }
 
+- (void)openURLInWebGroup:(NSPasteboard *)pboard 
+                 userData:(NSString *)userData 
+                    error:(NSString **)error {
+       // open in the frontmost bibliography
+       BibDocument * doc = [[NSDocumentController sharedDocumentController] 
mainDocument];
+    if ([doc isKindOfClass:[BibDocument class]] == NO) {
+        for (doc in [NSApp orderedDocuments])
+            if ([doc isKindOfClass:[BibDocument class]]) break;
+    }
+    if (doc == nil) {
+        // create a new document if we don't have one, or else this method 
appears to fail mysteriosly (since the error isn't displayed)
+        doc = [[NSDocumentController sharedDocumentController] 
openUntitledDocumentAndDisplay:YES error:NULL];
+    }
+    NSURL *theURL = [NSURL URLFromPasteboardAnyType:pboard];
+    if (theURL) {
+        [doc openURL:theURL];
+    }
+}
+
 @end

Modified: trunk/bibdesk/Info.plist
===================================================================
--- trunk/bibdesk/Info.plist    2011-07-30 06:34:58 UTC (rev 18029)
+++ trunk/bibdesk/Info.plist    2011-07-31 03:58:32 UTC (rev 18030)
@@ -437,6 +437,27 @@
                                <string>NSStringPboardType</string>
                        </array>
                </dict>
+               <dict>
+                       <key>NSMenuItem</key>
+                       <dict>
+                               <key>default</key>
+                               <string>BibDesk/Open URL in BibDesk web 
group</string>
+                       </dict>
+                       <key>NSMessage</key>
+                       <string>openURLInWebGroup</string>
+                       <key>NSRequiredContext</key>
+                       <dict>
+                               <key>NSTextContent</key>
+                               <string>URL</string>
+                       </dict>
+                       <key>NSPortName</key>
+                       <string>BibDesk</string>
+                       <key>NSSendTypes</key>
+                       <array>
+                               <string>NSURLPboardType</string>
+                               <string>NSStringPboardType</string>
+                       </array>
+               </dict>
        </array>
        <key>OSAScriptingDefinition</key>
        <string>BibDesk.sdef</string>

Modified: trunk/bibdesk/NSURL_BDSKExtensions.h
===================================================================
--- trunk/bibdesk/NSURL_BDSKExtensions.h        2011-07-30 06:34:58 UTC (rev 
18029)
+++ trunk/bibdesk/NSURL_BDSKExtensions.h        2011-07-31 03:58:32 UTC (rev 
18030)
@@ -53,6 +53,8 @@
 
 - (NSComparisonResult)UTICompare:(NSURL *)other;
 
++ (NSURL *)URLFromPasteboardAnyType:(NSPasteboard *)pasteboard;
+
 - (NSArray *)SkimNotes;
 - (NSString *)textSkimNotes;
 - (NSAttributedString *)richTextSkimNotes;

Modified: trunk/bibdesk/NSURL_BDSKExtensions.m
===================================================================
--- trunk/bibdesk/NSURL_BDSKExtensions.m        2011-07-30 06:34:58 UTC (rev 
18029)
+++ trunk/bibdesk/NSURL_BDSKExtensions.m        2011-07-31 03:58:32 UTC (rev 
18030)
@@ -245,6 +245,31 @@
     return [selfUTI caseInsensitiveCompare:otherUTI];
 }
 
+// This routine copied from Skim.app NSURL_SKExtensions.h, originally written 
by Christiaan Hofman
++ (NSURL *)URLFromPasteboardAnyType:(NSPasteboard *)pasteboard {
+    NSString *pboardType = [pasteboard availableTypeFromArray:[NSArray 
arrayWithObjects:NSURLPboardType, NSStringPboardType, nil]];
+    NSURL *theURL = nil;
+    if ([pboardType isEqualToString:NSURLPboardType]) {
+        theURL = [NSURL URLFromPasteboard:pasteboard];
+    } else if ([pboardType isEqualToString:NSStringPboardType]) {
+        NSString *string = [[pasteboard stringForType:NSStringPboardType] 
stringByTrimmingCharactersInSet:[NSCharacterSet 
whitespaceAndNewlineCharacterSet]];
+        if ([string rangeOfString:@"://"].length) {
+            if ([string hasPrefix:@"<"] && [string hasSuffix:@">"])
+                string = [string substringWithRange:NSMakeRange(1, [string 
length] - 2)];
+            theURL = [NSURL URLWithString:string];
+            if (theURL == nil)
+                theURL = [NSURL URLWithString:[string 
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
+        }
+        if (theURL == nil) {
+            if ([string hasPrefix:@"~"])
+                string = [string stringByExpandingTildeInPath];
+            if ([[NSFileManager defaultManager] fileExistsAtPath:string])
+                theURL = [NSURL fileURLWithPath:string];
+        }
+    }
+    return theURL;
+}
+
 #pragma mark Skim Notes
 
 - (NSArray *)SkimNotes {


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

------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to