Revision: 15695
          http://sourceforge.net/p/skim-app/code/15695
Author:   hofman
Date:     2025-10-09 16:27:06 +0000 (Thu, 09 Oct 2025)
Log Message:
-----------
make attachment emailer a subclass of NSSharingService, rathr than faking one

Modified Paths:
--------------
    trunk/SKAttachmentEmailer.h
    trunk/SKAttachmentEmailer.m
    trunk/SKShareMenuController.m

Modified: trunk/SKAttachmentEmailer.h
===================================================================
--- trunk/SKAttachmentEmailer.h 2025-10-09 15:34:18 UTC (rev 15694)
+++ trunk/SKAttachmentEmailer.h 2025-10-09 16:27:06 UTC (rev 15695)
@@ -40,36 +40,16 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
-@protocol SKAttachmentEmailerDelegate;
 
-@interface SKAttachmentEmailer : NSObject {
+@interface SKAttachmentEmailer : NSSharingService {
     NSString *mailAppID;
-    __weak id<SKAttachmentEmailerDelegate> delegate;
     NSString *subject;
 }
 
+- (instancetype)init NS_DESIGNATED_INITIALIZER;
+
 @property (nonatomic, readonly) BOOL permissionToComposeMessage;
 
-@property (nonatomic, readonly) NSString *title;
-@property (nonatomic, readonly) NSImage *image;
-@property (nonatomic, nullable, weak) id<SKAttachmentEmailerDelegate> delegate;
-
-@property (nonatomic, nullable, strong) NSString *subject;
-
-- (BOOL)canPerformWithItems:(NSArray *)items;
-- (void)performWithItems:(NSArray *)items;
-
 @end
 
-#pragma mark -
-
-@protocol SKAttachmentEmailerDelegate <NSObject>
-
-@optional
-
-- (void)sharingService:(id)sharingService didShareItems:(NSArray *)items;
-- (void)sharingService:(id)sharingService didFailToShareItems:(NSArray *)items 
error:(NSError *)error;
-
-@end
-
 NS_ASSUME_NONNULL_END

Modified: trunk/SKAttachmentEmailer.m
===================================================================
--- trunk/SKAttachmentEmailer.m 2025-10-09 15:34:18 UTC (rev 15694)
+++ trunk/SKAttachmentEmailer.m 2025-10-09 16:27:06 UTC (rev 15695)
@@ -46,30 +46,39 @@
 
 @implementation SKAttachmentEmailer
 
-@synthesize delegate, subject;
-@dynamic title, image;
-
 - (instancetype)init {
-    self = [super init];
+    NSURL *appURL = [[NSWorkspace sharedWorkspace] 
URLForApplicationToOpenURL:[NSURL URLWithString:@"mailto://";]];
+    NSString *appID = nil;
+    if (appURL)
+        appID = [[NSBundle bundleWithURL:appURL] bundleIdentifier];
+    else
+        appID = @"com.apple.Mail";
+    if ([@"com.microsoft.entourage" isCaseInsensitiveEqual:appID] == NO &&
+        [@"com.microsoft.outlook" isCaseInsensitiveEqual:appID] == NO &&
+        [@"com.barebones.mailsmith" isCaseInsensitiveEqual:appID] == NO &&
+        [@"com.mailplaneapp.Mailplane" isCaseInsensitiveEqual:appID] == NO &&
+        [@"com.postbox-inc.postboxexpress" isCaseInsensitiveEqual:appID] == NO 
&&
+        [@"com.postbox-inc.postbox" isCaseInsensitiveEqual:appID] == NO &&
+        [@"com.apple.Mail" isCaseInsensitiveEqual:appID] == NO)
+        appID = @"com.apple.Mail";
+    NSString *appPath = [[[NSWorkspace sharedWorkspace] 
URLForApplicationWithBundleIdentifier:appID] path];
+    NSString *title = [[[NSFileManager defaultManager] 
displayNameAtPath:appPath] stringByDeletingPathExtension];
+    NSImage *image = [NSImage imageWithSize:NSMakeSize(16.0, 16.0) 
drawingHandler:^(NSRect dstRect){
+        NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:appPath];
+        [icon drawInRect:dstRect];
+        return YES;
+    }];
+    self = [super initWithTitle:title image:image alternateImage:nil 
handler:^{}];
     if (self) {
-        NSURL *appURL = [[NSWorkspace sharedWorkspace] 
URLForApplicationToOpenURL:[NSURL URLWithString:@"mailto://";]];
-        if (appURL)
-            mailAppID = [[NSBundle bundleWithURL:appURL] bundleIdentifier];
-        else
-            mailAppID = @"com.apple.Mail";
-        if ([@"com.microsoft.entourage" isCaseInsensitiveEqual:mailAppID] == 
NO &&
-            [@"com.microsoft.outlook" isCaseInsensitiveEqual:mailAppID] == NO 
&&
-            [@"com.barebones.mailsmith" isCaseInsensitiveEqual:mailAppID] == 
NO &&
-            [@"com.mailplaneapp.Mailplane" isCaseInsensitiveEqual:mailAppID] 
== NO &&
-            [@"com.postbox-inc.postboxexpress" 
isCaseInsensitiveEqual:mailAppID] == NO &&
-            [@"com.postbox-inc.postbox" isCaseInsensitiveEqual:mailAppID] == 
NO &&
-            [@"com.apple.Mail" isCaseInsensitiveEqual:mailAppID] == NO) {
-            mailAppID = @"com.apple.Mail";
-        }
+        mailAppID = appID;
     }
     return self;
 }
 
+- (instancetype)initWithTitle:(NSString *)title image:(NSImage *)image 
alternateImage:(NSImage *)alternateImage handler:(void (^)(void))block {
+    return [self init];
+}
+
 - (BOOL)permissionToComposeMessage {
 #if !SDK_BEFORE_10_14
     if (@available(macOS 10.14, *)) {
@@ -80,21 +89,6 @@
     return YES;
 }
 
-- (NSString *)title {
-    NSString *appPath = [[[NSWorkspace sharedWorkspace] 
URLForApplicationWithBundleIdentifier:mailAppID] path];
-    return [[[NSFileManager defaultManager] displayNameAtPath:appPath] 
stringByDeletingPathExtension];
-}
-
-- (NSImage *)image {
-    NSString *appPath = [[[NSWorkspace sharedWorkspace] 
URLForApplicationWithBundleIdentifier:mailAppID] path];
-    NSImage *image = [NSImage imageWithSize:NSMakeSize(16.0, 16.0) 
drawingHandler:^(NSRect dstRect){
-        NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:appPath];
-        [icon drawInRect:dstRect];
-        return YES;
-    }];
-    return image;
-}
-
 - (BOOL)canPerformWithItems:(NSArray *)items {
     return [items count] == 1 && [[items firstObject] isKindOfClass:[NSURL 
class]] && [[items firstObject] isFileURL];
 }
@@ -159,6 +153,8 @@
     static dispatch_queue_t queue = NULL;
     if (queue == NULL)
         queue = 
dispatch_queue_create("net.sourceforge.skim-app.queue.NSAppleScript", 
DISPATCH_QUEUE_SERIAL);
+    if ([[self delegate] 
respondsToSelector:@selector(sharingService:willShareItems:)])
+        [[self delegate] sharingService:(id)self willShareItems:items];
     dispatch_async(queue, ^{
         NSDictionary *errorDict = nil;
         BOOL success = [script compileAndReturnError:&errorDict];

Modified: trunk/SKShareMenuController.m
===================================================================
--- trunk/SKShareMenuController.m       2025-10-09 15:34:18 UTC (rev 15694)
+++ trunk/SKShareMenuController.m       2025-10-09 16:27:06 UTC (rev 15695)
@@ -81,7 +81,7 @@
         [menu addItemWithTitle:NSLocalizedString(@"No Document", @"Menu item 
title") action:NULL keyEquivalent:@""];
     } else {
         for (NSSharingService *service in services) {
-            NSMenuItem *item = [menu addItemWithTitle:[service title] 
action:@selector(share:) target:doc];
+            NSMenuItem *item = [menu addItemWithTitle:[service menuItemTitle] 
action:@selector(share:) target:doc];
             [item setRepresentedObject:service];
             [item setImage:[service image]];
         }

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



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to