shell/macos: Use a submenu to include private link actions
authorJocelyn Turcotte <jturcotte@woboq.com>
Tue, 4 Jul 2017 15:34:51 +0000 (11:34 -0400)
committerChristian Kamm <mail@ckamm.de>
Fri, 7 Jul 2017 08:49:51 +0000 (10:49 +0200)
shell_integration/MacOSX/OwnCloudFinderSync/FinderSyncExt/FinderSync.h
shell_integration/MacOSX/OwnCloudFinderSync/FinderSyncExt/FinderSync.m
shell_integration/MacOSX/common/SyncClientProxy.h
shell_integration/MacOSX/common/SyncClientProxy.m

index a1356045b7d317446b067c28de22503398a70d3b..67a4360945f2e9c12a3fb61dfcb5d7bf7d9ba940 100644 (file)
@@ -22,6 +22,7 @@
        SyncClientProxy *_syncClientProxy;
        NSMutableSet *_registeredDirectories;
        NSString *_shareMenuTitle;
+       NSMutableDictionary *_strings;
 }
 
 @end
index 065be2e2f5e707dc9f0d05f47476e9160133e56a..0591824bb332f46b4f1c51aeb76f8af05c1a58be 100644 (file)
@@ -59,7 +59,7 @@
 
        _syncClientProxy = [[SyncClientProxy alloc] initWithDelegate:self serverName:serverName];
        _registeredDirectories = [[NSMutableSet alloc] init];
-       _shareMenuTitle = nil;
+       _strings = [[NSMutableDictionary alloc] init];
        
        [_syncClientProxy start];
        return self;
                }
        }];
 
-       if (_shareMenuTitle && !onlyRootsSelected) {
-               NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
-               NSMenuItem *item = [menu addItemWithTitle:_shareMenuTitle action:@selector(shareMenuAction:) keyEquivalent:@"title"];
-               item.image = [[NSBundle mainBundle] imageForResource:@"app.icns"];
-               
+       id contextMenuTitle = [_strings objectForKey:@"CONTEXT_MENU_TITLE"];
+       id shareTitle = [_strings objectForKey:@"SHARE_MENU_TITLE"];
+       id copyLinkTitle = [_strings objectForKey:@"COPY_PRIVATE_LINK_TITLE"];
+       id emailLinkTitle = [_strings objectForKey:@"EMAIL_PRIVATE_LINK_TITLE"];
+       if (contextMenuTitle && !onlyRootsSelected) {
+        NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
+        NSMenu *subMenu = [[NSMenu alloc] initWithTitle:@""];
+        NSMenuItem *subMenuItem = [menu addItemWithTitle:contextMenuTitle action:nil keyEquivalent:@""];
+        subMenuItem.submenu = subMenu;
+        subMenuItem.image = [[NSBundle mainBundle] imageForResource:@"app.icns"];
+
+               [subMenu addItemWithTitle:shareTitle action:@selector(shareMenuAction:) keyEquivalent:@""];
+               [subMenu addItemWithTitle:copyLinkTitle action:@selector(copyLinkMenuAction:) keyEquivalent:@""];
+               [subMenu addItemWithTitle:emailLinkTitle action:@selector(emailLinkMenuAction:) keyEquivalent:@""];
+
                return menu;
        }
        return nil;
 - (IBAction)shareMenuAction:(id)sender
 {
        NSArray* items = [[FIFinderSyncController defaultController] selectedItemURLs];
-       
+
        [items enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) {
                NSString* normalizedPath = [[obj path] decomposedStringWithCanonicalMapping];
                [_syncClientProxy askOnSocket:normalizedPath query:@"SHARE"];
        }];
 }
 
+- (IBAction)copyLinkMenuAction:(id)sender
+{
+       NSArray* items = [[FIFinderSyncController defaultController] selectedItemURLs];
+
+       [items enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) {
+               NSString* normalizedPath = [[obj path] decomposedStringWithCanonicalMapping];
+               [_syncClientProxy askOnSocket:normalizedPath query:@"COPY_PRIVATE_LINK"];
+       }];
+}
+
+- (IBAction)emailLinkMenuAction:(id)sender
+{
+       NSArray* items = [[FIFinderSyncController defaultController] selectedItemURLs];
+
+       [items enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) {
+               NSString* normalizedPath = [[obj path] decomposedStringWithCanonicalMapping];
+               [_syncClientProxy askOnSocket:normalizedPath query:@"EMAIL_PRIVATE_LINK"];
+       }];
+}
+
 #pragma mark - SyncClientProxyDelegate implementation
 
 - (void)setResultForPath:(NSString*)path result:(NSString*)result
        [FIFinderSyncController defaultController].directoryURLs = _registeredDirectories;
 }
 
-- (void)setShareMenuTitle:(NSString*)title
+- (void)setString:(NSString*)key value:(NSString*)value
 {
-       _shareMenuTitle = title;
+       [_strings setObject:value forKey:key];
 }
 
 - (void)connectionDidDie
 {
-       _shareMenuTitle = nil;
-       
+       [_strings removeAllObjects];
        [_registeredDirectories removeAllObjects];
        // For some reason the FIFinderSync cache doesn't seem to be cleared for the root item when
        // we reset the directoryURLs (seen on macOS 10.12 at least).
index aaaa294b62233c4a0620732d0551bd20127fa67b..8f96334164cc29133514a7117bcf37d77319984c 100644 (file)
@@ -20,7 +20,7 @@
 - (void)reFetchFileNameCacheForPath:(NSString*)path;
 - (void)registerPath:(NSString*)path;
 - (void)unregisterPath:(NSString*)path;
-- (void)setShareMenuTitle:(NSString*)title;
+- (void)setString:(NSString*)key value:(NSString*)value;
 - (void)connectionDidDie;
 @end
 
index 1e89ea67649d216d32fed3d40dccc261cba1e918..b7b64571f747d2f005f551d76acd3f64506d97fb 100644 (file)
@@ -73,7 +73,7 @@
        [_remoteEnd setProtocolForProxy:@protocol(ChannelProtocol)];
 
        // Everything is set up, start querying
-       [self askOnSocket:@"" query:@"SHARE_MENU_TITLE"];
+       [self askOnSocket:@"" query:@"GET_STRINGS"];
 }
 
 - (void)scheduleRetry
        } else if( [[chunks objectAtIndex:0 ] isEqualToString:@"UNREGISTER_PATH"] ) {
                NSString *path = [chunks objectAtIndex:1];
                [_delegate unregisterPath:path];
-       } else if( [[chunks objectAtIndex:0 ] isEqualToString:@"SHARE_MENU_TITLE"] ) {
-               [_delegate setShareMenuTitle:[chunks objectAtIndex:1]];
+       } else if( [[chunks objectAtIndex:0 ] isEqualToString:@"GET_STRINGS"] ) {
+               // BEGIN and END messages, do nothing.
+       } else if( [[chunks objectAtIndex:0 ] isEqualToString:@"STRING"] ) {
+               [_delegate setString:[chunks objectAtIndex:1] value:[chunks objectAtIndex:2]];
        } else {
                NSLog(@"SyncState: Unknown command %@", [chunks objectAtIndex:0]);
        }