aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPAppController.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-11-15 23:23:54 +0000
committerBibiko <bibiko@eva.mpg.de>2010-11-15 23:23:54 +0000
commit487df2675fdc65933010ccf08ae0f5aa4ad92842 (patch)
tree78a2d4478604ce7c72dc6e17f7470bc055f6ff8a /Source/SPAppController.m
parentcd4ae516d0db053c1bb818e617cf5b5bbebdaafc (diff)
downloadsequelpro-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/SPAppController.m')
-rw-r--r--Source/SPAppController.m101
1 files changed, 96 insertions, 5 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 -