Revision: 27626
          http://sourceforge.net/p/bibdesk/svn/27626
Author:   hofman
Date:     2022-06-13 15:53:31 +0000 (Mon, 13 Jun 2022)
Log Message:
-----------
Don't add alternate Show menu items to script menu items with a user defined 
shortcut

Modified Paths:
--------------
    trunk/bibdesk/BDSKScriptMenu.m

Modified: trunk/bibdesk/BDSKScriptMenu.m
===================================================================
--- trunk/bibdesk/BDSKScriptMenu.m      2022-06-13 14:56:36 UTC (rev 27625)
+++ trunk/bibdesk/BDSKScriptMenu.m      2022-06-13 15:53:31 UTC (rev 27626)
@@ -51,6 +51,8 @@
 
 #define BDSKScriptMenuDisabledKey @"BDSKScriptMenuDisabled"
 
+static char BDSKScriptMenuDefaultsObservationContext;
+
 @interface BDSKScriptMenuController : NSObject <NSMenuDelegate> {
     NSMenu *scriptMenu;
     FSEventStreamRef streamRef;
@@ -61,10 +63,9 @@
 
 + (id)sharedController;
 
-- (NSMenu *)scriptMenu;
+@property (nonatomic, readonly) NSMenu *scriptMenu;
 
-- (BOOL)menuNeedsUpdate;
-- (void)setMenuNeedsUpdate:(BOOL)flag;
+@property (nonatomic) BOOL menuNeedsUpdate;
 
 - (void)executeScript:(id)sender;
 - (void)openScript:(id)sender;
@@ -74,6 +75,8 @@
 
 @implementation BDSKScriptMenuController
 
+@synthesize scriptMenu, menuNeedsUpdate;
+
 + (id)sharedController {
     static BDSKScriptMenuController *sharedController = nil;
     if (sharedController == nil)
@@ -152,17 +155,20 @@
             menuNeedsUpdate = YES;
             
             [scriptMenu setDelegate:self];
+            
+            [[NSUserDefaultsController sharedUserDefaultsController] 
addObserver:self forKeyPath:@"values.NSUserKeyEquivalents" options:0 
context:&BDSKScriptMenuDefaultsObservationContext];
         }
     }
     return self;
 }    
 
-- (NSMenu *)scriptMenu { return scriptMenu; }
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object 
change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
+    if (context == &BDSKScriptMenuDefaultsObservationContext)
+        [self setMenuNeedsUpdate:YES];
+    else
+        [super observeValueForKeyPath:keyPath ofObject:object change:change 
context:context];
+}
 
-- (BOOL)menuNeedsUpdate { return menuNeedsUpdate; }
-
-- (void)setMenuNeedsUpdate:(BOOL)flag { menuNeedsUpdate = flag; }
-
 - (NSArray *)directoryContentsAtPath:(NSString *)path 
recursionDepth:(NSInteger)recursionDepth
 {
        NSMutableArray *fileArray = [NSMutableArray array];
@@ -217,6 +223,8 @@
     // we call this method recursively; if the menu is nil, the stuff we add 
won't be retained
     NSParameterAssert(menu != nil);
     
+    NSDictionary *shortcuts = [[NSUserDefaults standardUserDefaults] 
dictionaryForKey:@"NSUserKeyEquivalents"];
+    
     [menu setAutoenablesItems:NO];
     [menu removeAllItems];
     
@@ -247,6 +255,8 @@
                        [item setRepresentedObject:scriptFilename];
                        [menu addItem:item];
                        [item release];
+            if (shortcuts && ([shortcuts objectForKey:scriptName] || 
[shortcuts objectForKey:[NSString stringWithFormat:@"%CScripts%C%@", 0x1B,0x1B, 
scriptName]]))
+                continue;
                        item = [[NSMenuItem allocWithZone:[NSMenu menuZone]] 
initWithTitle:showScriptName action:@selector(openScript:) keyEquivalent:@""];
                        [item setKeyEquivalentModifierMask:NSAlternateKeyMask];
                        [item setTarget:self];

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



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to