diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-11-15 23:23:54 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-11-15 23:23:54 +0000 |
commit | 487df2675fdc65933010ccf08ae0f5aa4ad92842 (patch) | |
tree | 78a2d4478604ce7c72dc6e17f7470bc055f6ff8a /Source | |
parent | cd4ae516d0db053c1bb818e617cf5b5bbebdaafc (diff) | |
download | sequelpro-487df2675fdc65933010ccf08ae0f5aa4ad92842.tar.gz sequelpro-487df2675fdc65933010ccf08ae0f5aa4ad92842.tar.bz2 sequelpro-487df2675fdc65933010ccf08ae0f5aa4ad92842.zip |
• Bundle support
- started to populate the main menu item Bundles [still hidden]
- enabled key equivalents for NSTextViews
- distinguishes between Query Editor scope and text input scope via menu item validation inside main menu Bundles
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPAppController.m | 101 | ||||
-rw-r--r-- | Source/SPConstants.h | 5 | ||||
-rw-r--r-- | Source/SPTextView.m | 12 | ||||
-rw-r--r-- | Source/SPTextViewAdditions.m | 27 |
4 files changed, 132 insertions, 13 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m index ba0257e1..d64b5183 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -117,6 +117,7 @@ */ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem { + if ([menuItem action] == @selector(openCurrentConnectionInNewWindow:)) { [menuItem setTitle:NSLocalizedString(@"Open in New Window", @"menu item open in new window")]; @@ -852,19 +853,31 @@ - (IBAction)reloadBundles:(id)sender { + + BOOL foundInstalledBundles = NO; + + [bundleItems removeAllObjects]; + [bundleUsedScopes removeAllObjects]; + [bundleCategories removeAllObjects]; + [bundleKeyEquivalents removeAllObjects]; + + // Get main menu "Bundles"'s submenu + NSMenu *menu = [[[NSApp mainMenu] itemWithTag:SPMainMenuBundles] submenu]; + + // Clean menu + [menu removeAllItems]; + NSString *bundlePath = [[NSFileManager defaultManager] applicationSupportDirectoryForSubDirectory:SPBundleSupportFolder createIfNotExists:NO error:nil]; if(bundlePath) { NSError *error = nil; NSArray *foundBundles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundlePath error:&error]; if (foundBundles && [foundBundles count]) { - [bundleItems removeAllObjects]; - [bundleUsedScopes removeAllObjects]; - [bundleCategories removeAllObjects]; - [bundleKeyEquivalents removeAllObjects]; for(NSString* bundle in foundBundles) { if(![[[bundle pathExtension] lowercaseString] isEqualToString:[SPUserBundleFileExtension lowercaseString]]) continue; + foundInstalledBundles = YES; + NSError *readError = nil; NSString *convError = nil; NSPropertyListFormat format; @@ -892,7 +905,7 @@ [bundleKeyEquivalents setObject:[NSMutableDictionary dictionary] forKey:scope]; } - if([cmdData objectForKey:SPBundleFileCategoryKey] && ![bundleCategories containsObject:[cmdData objectForKey:SPBundleFileCategoryKey]]) + if([cmdData objectForKey:SPBundleFileCategoryKey] && ![[bundleCategories objectForKey:scope] containsObject:[cmdData objectForKey:SPBundleFileCategoryKey]]) [[bundleCategories objectForKey:scope] addObject:[cmdData objectForKey:SPBundleFileCategoryKey]]; } @@ -937,9 +950,87 @@ [[bundleItems objectForKey:scope] sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]; [[bundleCategories objectForKey:scope] sortUsingSelector:@selector(compare:)]; } + } + } + + // Rebuild Bundles main menu item + + NSMenuItem *anItem; + anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Bundle Editor", @"bundle editor menu item label") action:@selector(openBundleEditor:) keyEquivalent:@"b"]; + [anItem setKeyEquivalentModifierMask:(NSCommandKeyMask|NSAlternateKeyMask|NSControlKeyMask)]; + [menu addItem:anItem]; + [anItem release]; + anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Reload Bundles", @"reload bundles menu item label") action:@selector(reloadBundles:) keyEquivalent:@""]; + [menu addItem:anItem]; + [anItem release]; + + if(!foundInstalledBundles) return; + + // Add installed Bundles + [menu addItem:[NSMenuItem separatorItem]]; + + NSArray *scopes = [NSArray arrayWithObjects:SPBundleScopeInputField, SPBundleScopeQueryEditor, nil]; + NSArray *scopeTitles = [NSArray arrayWithObjects:NSLocalizedString(@"Input Fields", @"input fields menu item label"), + NSLocalizedString(@"Query Editor", @"query editor menu item label"), nil]; + NSArray *scopeSelector = [NSArray arrayWithObjects:@"executeBundleItemForInputField:", + @"executeBundleItemForEditor:", nil]; + + NSInteger k = 0; + for(NSString* scope in scopes) { + + NSArray *bundleCategories = [[NSApp delegate] bundleCategoriesForScope:scope]; + NSArray *bundleItems = [[NSApp delegate] bundleItemsForScope:scope]; + + if(![bundleItems count]) continue; + + NSMenu *bundleMenu = [[[NSMenu alloc] init] autorelease]; + NSMenuItem *bundleSubMenuItem = [[NSMenuItem alloc] initWithTitle:[scopeTitles objectAtIndex:k] action:nil keyEquivalent:@""]; + [bundleSubMenuItem setTag:10000000]; + + [menu addItem:bundleSubMenuItem]; + [menu setSubmenu:bundleMenu forItem:bundleSubMenuItem]; + + NSMutableArray *categorySubMenus = [NSMutableArray array]; + NSMutableArray *categoryMenus = [NSMutableArray array]; + if([bundleCategories count]) { + for(NSString* title in bundleCategories) { + [categorySubMenus addObject:[[[NSMenuItem alloc] initWithTitle:title action:nil keyEquivalent:@""] autorelease]]; + [categoryMenus addObject:[[[NSMenu alloc] init] autorelease]]; + [bundleMenu addItem:[categorySubMenus lastObject]]; + [bundleMenu setSubmenu:[categoryMenus lastObject] forItem:[categorySubMenus lastObject]]; + } + } + + NSInteger i = 0; + for(NSDictionary *item in bundleItems) { + + NSString *keyEq; + if([item objectForKey:SPBundleFileKeyEquivalentKey]) + keyEq = [[item objectForKey:SPBundleFileKeyEquivalentKey] objectAtIndex:0]; + else + keyEq = @""; + NSMenuItem *mItem = [[[NSMenuItem alloc] initWithTitle:[item objectForKey:SPBundleInternLabelKey] action:NSSelectorFromString([scopeSelector objectAtIndex:k]) keyEquivalent:keyEq] autorelease]; + + if([keyEq length]) + [mItem setKeyEquivalentModifierMask:[[[item objectForKey:SPBundleFileKeyEquivalentKey] objectAtIndex:1] intValue]]; + + if([item objectForKey:SPBundleFileTooltipKey]) + [mItem setToolTip:[item objectForKey:SPBundleFileTooltipKey]]; + + [mItem setTag:1000000 + i++]; + + if([item objectForKey:SPBundleFileCategoryKey]) { + [[categoryMenus objectAtIndex:[bundleCategories indexOfObject:[item objectForKey:SPBundleFileCategoryKey]]] addItem:mItem]; + } else { + [bundleMenu addItem:mItem]; + } } + + [bundleSubMenuItem release]; + k++; } + } #pragma mark - diff --git a/Source/SPConstants.h b/Source/SPConstants.h index 897c0c26..64003bad 100644 --- a/Source/SPConstants.h +++ b/Source/SPConstants.h @@ -151,8 +151,9 @@ typedef enum SPMainMenuView = 3, SPMainMenuDatabase = 4, SPMainMenuTable = 5, - SPMainMenuWindow = 6, - SPMainMenuHelp = 7 + SPMainMenuBundles = 6, + SPMainMenuWindow = 7, + SPMainMenuHelp = 8 } SPMainMenuTags; // Encoding constants diff --git a/Source/SPTextView.m b/Source/SPTextView.m index 21ab5260..f83b2549 100644 --- a/Source/SPTextView.m +++ b/Source/SPTextView.m @@ -2991,7 +2991,17 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) * Disable the search in the MySQL help function when getRangeForCurrentWord returns zero length. */ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem -{ +{ + + if([menuItem action] == @selector(executeBundleItemForEditor:)) + { + return YES; + } + if([menuItem action] == @selector(executeBundleItemForInputField:)) + { + return NO; + } + // Enable or disable the search in the MySQL help menu item depending on whether there is a // selection and whether it is a reasonable length. if ([menuItem action] == @selector(showMySQLHelpForCurrentWord:)) { diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index 381f8f0a..24a5236f 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -715,17 +715,19 @@ NSInteger i = 0; for(NSDictionary *item in bundleItems) { - NSString *keyEq = @""; - // if([item objectForKey:SPBundleFileKeyEquivalentKey]) - // keyEq = [[item objectForKey:SPBundleFileKeyEquivalentKey] objectAtIndex:0]; - // else - // keyEq = @""; + NSString *keyEq; + if([item objectForKey:SPBundleFileKeyEquivalentKey]) + keyEq = [[item objectForKey:SPBundleFileKeyEquivalentKey] objectAtIndex:0]; + else + keyEq = @""; NSMenuItem *mItem = [[[NSMenuItem alloc] initWithTitle:[item objectForKey:SPBundleInternLabelKey] action:@selector(executeBundleItemForInputField:) keyEquivalent:keyEq] autorelease]; if([keyEq length]) [mItem setKeyEquivalentModifierMask:[[[item objectForKey:SPBundleFileKeyEquivalentKey] objectAtIndex:1] intValue]]; + [mItem setTarget:[[NSApp mainWindow] firstResponder]]; + if([item objectForKey:SPBundleFileTooltipKey]) [mItem setToolTip:[item objectForKey:SPBundleFileTooltipKey]]; @@ -744,6 +746,21 @@ } +- (BOOL)validateMenuItem:(NSMenuItem *)menuItem +{ + + if([menuItem action] == @selector(executeBundleItemForEditor:)) + { + return NO; + } + if([menuItem action] == @selector(executeBundleItemForInputField:)) + { + return YES; + } + + return YES; + +} #pragma mark - #pragma mark multi-touch trackpad support |