From 487df2675fdc65933010ccf08ae0f5aa4ad92842 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 15 Nov 2010 23:23:54 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Bundle=20support=20-=20started=20to=20popul?= =?UTF-8?q?ate=20the=20main=20menu=20item=20Bundles=20[still=20hidden]=20-?= =?UTF-8?q?=20enabled=20key=20equivalents=20for=20NSTextViews=20-=20distin?= =?UTF-8?q?guishes=20between=20Query=20Editor=20scope=20and=20text=20input?= =?UTF-8?q?=20scope=20via=20menu=20item=20validation=20inside=20main=20men?= =?UTF-8?q?u=20Bundles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/MainMenu.xib | 78 ++------------------------ Source/SPAppController.m | 101 ++++++++++++++++++++++++++++++++-- Source/SPConstants.h | 5 +- Source/SPTextView.m | 12 +++- Source/SPTextViewAdditions.m | 27 +++++++-- 5 files changed, 138 insertions(+), 85 deletions(-) diff --git a/Interfaces/English.lproj/MainMenu.xib b/Interfaces/English.lproj/MainMenu.xib index 6204e5d7..681cba8f 100644 --- a/Interfaces/English.lproj/MainMenu.xib +++ b/Interfaces/English.lproj/MainMenu.xib @@ -12,7 +12,7 @@ YES - + YES @@ -1746,37 +1746,11 @@ submenuAction: + 6 Bundles YES - - - Open Bundle Editor - b - 1835008 - 2147483647 - - - - - - Reload Bundles - - 2147483647 - - - - - - YES - YES - - - 2147483647 - - - @@ -1789,7 +1763,7 @@ submenuAction: - 6 + 7 Window @@ -1881,7 +1855,7 @@ submenuAction: - 7 + 8 Help @@ -3092,22 +3066,6 @@ 1175 - - - reloadBundles: - - - - 1184 - - - - openBundleEditor: - - - - 1185 - @@ -4526,27 +4484,9 @@ YES - - - - - 1180 - - - - - 1181 - - - - - 1183 - - - @@ -4620,9 +4560,6 @@ 1178.IBPluginDependency 1179.IBEditorWindowLastContentRect 1179.IBPluginDependency - 1180.IBPluginDependency - 1181.IBPluginDependency - 1183.IBPluginDependency 129.IBPluginDependency 129.ImportedFromIB2 130.IBEditorWindowLastContentRect @@ -4938,7 +4875,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{781, 372}, {271, 173}} + {{578, 550}, {271, 173}} com.apple.InterfaceBuilder.CocoaPlugin {{561, 605}, {181, 43}} @@ -5010,10 +4947,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{435, 670}, {234, 53}} - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin + {{435, 717}, {64, 6}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin 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 -- cgit v1.2.3