aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/SPAppController.m8
-rw-r--r--Source/SPCopyTable.h2
-rw-r--r--Source/SPCopyTable.m209
-rw-r--r--Source/SPEditSheetTextView.m76
-rw-r--r--Source/SPTextViewAdditions.m78
5 files changed, 256 insertions, 117 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index d64b5183..eb013e48 100644
--- a/Source/SPAppController.m
+++ b/Source/SPAppController.m
@@ -969,11 +969,13 @@
// Add installed Bundles
[menu addItem:[NSMenuItem separatorItem]];
- NSArray *scopes = [NSArray arrayWithObjects:SPBundleScopeInputField, SPBundleScopeQueryEditor, nil];
+ NSArray *scopes = [NSArray arrayWithObjects:SPBundleScopeInputField, SPBundleScopeQueryEditor, SPBundleScopeDataTable, nil];
NSArray *scopeTitles = [NSArray arrayWithObjects:NSLocalizedString(@"Input Fields", @"input fields menu item label"),
- NSLocalizedString(@"Query Editor", @"query editor menu item label"), nil];
+ NSLocalizedString(@"Query Editor", @"query editor menu item label"),
+ NSLocalizedString(@"Data Table", @"data table menu item label"),nil];
NSArray *scopeSelector = [NSArray arrayWithObjects:@"executeBundleItemForInputField:",
- @"executeBundleItemForEditor:", nil];
+ @"executeBundleItemForEditor:",
+ @"executeBundleItemForDataTable:", nil];
NSInteger k = 0;
for(NSString* scope in scopes) {
diff --git a/Source/SPCopyTable.h b/Source/SPCopyTable.h
index 3ccff43c..22e6f15c 100644
--- a/Source/SPCopyTable.h
+++ b/Source/SPCopyTable.h
@@ -154,6 +154,8 @@
- (BOOL)isCellEditingMode;
- (BOOL)isCellComplex;
+- (IBAction)executeBundleItemForDataTable:(id)sender;
+
@end
extern NSInteger MENU_EDIT_COPY;
diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m
index dfb80cc4..84c43640 100644
--- a/Source/SPCopyTable.m
+++ b/Source/SPCopyTable.m
@@ -31,6 +31,8 @@
#import "SPCustomQuery.h"
#import "SPDataStorage.h"
#import "SPTextAndLinkCell.h"
+#import "SPTooltip.h"
+#import "SPAlertSheets.h"
NSInteger MENU_EDIT_COPY = 2001;
NSInteger MENU_EDIT_COPY_WITH_COLUMN = 2002;
@@ -619,6 +621,213 @@ NSInteger MENU_EDIT_COPY_AS_SQL = 2003;
#pragma mark -
+- (NSMenu *)menuForEvent:(NSEvent *)event
+{
+
+ NSMenu *menu = [self menu];
+
+ if(![[self delegate] isKindOfClass:[SPCustomQuery class]] && ![[self delegate] isKindOfClass:[SPTableContent class]]) return menu;
+
+ [[NSApp delegate] reloadBundles:self];
+
+ // Remove 'Bundles' sub menu and separator
+ NSMenuItem *bItem = [menu itemWithTag:10000000];
+ if(bItem) {
+ NSInteger sepIndex = [menu indexOfItem:bItem]-1;
+ [menu removeItemAtIndex:sepIndex];
+ [menu removeItem:bItem];
+ }
+
+ NSArray *bundleCategories = [[NSApp delegate] bundleCategoriesForScope:SPBundleScopeDataTable];
+ NSArray *bundleItems = [[NSApp delegate] bundleItemsForScope:SPBundleScopeDataTable];
+
+ // Add 'Bundles' sub menu
+ if(bundleItems && [bundleItems count]) {
+ [menu addItem:[NSMenuItem separatorItem]];
+
+ NSMenu *bundleMenu = [[[NSMenu alloc] init] autorelease];
+ NSMenuItem *bundleSubMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Bundles", @"bundles menu item label") 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:@selector(executeBundleItemForDataTable:) 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];
+
+ }
+
+ return menu;
+
+}
+
+- (IBAction)executeBundleItemForDataTable:(id)sender
+{
+ NSInteger idx = [sender tag] - 1000000;
+ NSString *infoPath = nil;
+ NSArray *bundleItems = [[NSApp delegate] bundleItemsForScope:SPBundleScopeDataTable];
+ if(idx >=0 && idx < [bundleItems count]) {
+ infoPath = [[bundleItems objectAtIndex:idx] objectForKey:SPBundleInternPathToFileKey];
+ } else {
+ if([sender tag] == 0 && [[sender toolTip] length]) {
+ infoPath = [sender toolTip];
+ }
+ }
+
+ if(!infoPath) {
+ NSBeep();
+ return;
+ }
+
+ NSError *readError = nil;
+ NSString *convError = nil;
+ NSPropertyListFormat format;
+ NSDictionary *cmdData = nil;
+ NSData *pData = [NSData dataWithContentsOfFile:infoPath options:NSUncachedRead error:&readError];
+
+ cmdData = [[NSPropertyListSerialization propertyListFromData:pData
+ mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
+
+ if(!cmdData || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
+ NSLog(@"“%@” file couldn't be read.", infoPath);
+ NSBeep();
+ if (cmdData) [cmdData release];
+ return;
+ } else {
+ if([cmdData objectForKey:SPBundleFileCommandKey] && [[cmdData objectForKey:SPBundleFileCommandKey] length]) {
+
+ NSString *cmd = [cmdData objectForKey:SPBundleFileCommandKey];
+ NSString *inputAction = @"";
+ NSString *inputFallBackAction = @"";
+ NSError *err = nil;
+
+ [[NSFileManager defaultManager] removeItemAtPath:SPBundleTaskInputFilePath error:nil];
+
+ if([cmdData objectForKey:SPBundleFileInputSourceKey])
+ inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString];
+ if([cmdData objectForKey:SPBundleFileInputSourceFallBackKey])
+ inputFallBackAction = [[cmdData objectForKey:SPBundleFileInputSourceFallBackKey] lowercaseString];
+
+ NSMutableDictionary *env = [NSMutableDictionary dictionary];
+ [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:@"SP_BUNDLE_PATH"];
+ [env setObject:SPBundleTaskInputFilePath forKey:@"SP_BUNDLE_INPUT_FILE"];
+
+ id tablesListInstance = [[self delegate] valueForKeyPath:@"tablesListInstance"];
+ id tableDocumentInstance = [[self delegate] valueForKeyPath:@"tableDocumentInstance"];
+
+ if (tablesListInstance) {
+ if([tablesListInstance selectedDatabase])
+ [env setObject:[tablesListInstance selectedDatabase] forKey:@"SP_SELECTED_DATABASE"];
+
+ if ([tablesListInstance allDatabaseNames])
+ [env setObject:[[tablesListInstance allDatabaseNames] componentsJoinedBySpacesAndQuoted] forKey:@"SP_ALL_DATABASES"];
+
+ if ([tablesListInstance allTableNames])
+ [env setObject:[[tablesListInstance allTableNames] componentsJoinedBySpacesAndQuoted] forKey:@"SP_ALL_TABLES"];
+
+ if ([tablesListInstance allViewNames])
+ [env setObject:[[tablesListInstance allViewNames] componentsJoinedBySpacesAndQuoted] forKey:@"SP_ALL_VIEWS"];
+
+ if ([tablesListInstance allFunctionNames])
+ [env setObject:[[tablesListInstance allFunctionNames] componentsJoinedBySpacesAndQuoted] forKey:@"SP_ALL_FUNCTIONS"];
+
+ if ([tablesListInstance allProcedureNames])
+ [env setObject:[[tablesListInstance allProcedureNames] componentsJoinedBySpacesAndQuoted] forKey:@"SP_ALL_PROCEDURES"];
+
+ if ([tablesListInstance tableName])
+ [env setObject:[tablesListInstance tableName] forKey:@"SP_SELECTED_TABLE"];
+
+ }
+
+ if(tableDocumentInstance && [tableDocumentInstance mySQLVersion])
+ [env setObject:[tableDocumentInstance mySQLVersion] forKey:@"SP_RDBMS_VERSION"];
+
+ if(1)
+ [env setObject:@"mysql" forKey:@"SP_RDBMS_TYPE"];
+
+
+ // NSError *inputFileError = nil;
+ // NSString *input = [NSString stringWithString:[[self string] substringWithRange:replaceRange]];
+ // [input writeToFile:SPBundleTaskInputFilePath
+ // atomically:YES
+ // encoding:NSUTF8StringEncoding
+ // error:&inputFileError];
+ //
+ // if(inputFileError != nil) {
+ // NSString *errorMessage = [inputFileError localizedDescription];
+ // SPBeginAlertSheet(NSLocalizedString(@"Bundle Error", @"bundle error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil,
+ // [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]);
+ // if (cmdData) [cmdData release];
+ // return;
+ // }
+
+ NSString *output = [cmd runBashCommandWithEnvironment:env atCurrentDirectoryPath:nil error:&err];
+
+ [[NSFileManager defaultManager] removeItemAtPath:SPBundleTaskInputFilePath error:nil];
+
+ if(err == nil && [cmdData objectForKey:SPBundleFileOutputActionKey]) {
+ if([[cmdData objectForKey:SPBundleFileOutputActionKey] length]
+ && ![[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionNone]) {
+ NSString *action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString];
+
+ if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) {
+ [SPTooltip showWithObject:output];
+ }
+
+ else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) {
+ [SPTooltip showWithObject:output ofType:@"html"];
+ }
+ }
+ } else {
+ NSString *errorMessage = [err localizedDescription];
+ SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil,
+ [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]);
+ }
+
+ }
+
+ if (cmdData) [cmdData release];
+
+ }
+
+ }
+
/**
* Only have the copy menu item enabled when row(s) are selected in
* supported tables.
diff --git a/Source/SPEditSheetTextView.m b/Source/SPEditSheetTextView.m
index babac98e..7ac5185f 100644
--- a/Source/SPEditSheetTextView.m
+++ b/Source/SPEditSheetTextView.m
@@ -145,82 +145,6 @@
}
-/**
- * Add Bundle menu items.
- */
-- (NSMenu *)menuForEvent:(NSEvent *)event
-{
-
- NSMenu *menu = [[self class] defaultMenu];
-
- // Remove 'Bundles' sub menu and separator
- NSMenuItem *bItem = [menu itemWithTag:10000000];
- if(bItem) {
- NSInteger sepIndex = [menu indexOfItem:bItem]-1;
- [menu removeItemAtIndex:sepIndex];
- [menu removeItem:bItem];
- }
-
- if([[[[[[NSApp delegate] frontDocumentWindow] delegate] selectedTableDocument] connectionID] isEqualToString:@"_"]) return menu;
-
- [[NSApp delegate] reloadBundles:self];
-
- NSArray *bundleCategories = [[NSApp delegate] bundleCategoriesForScope:SPBundleScopeInputField];
- NSArray *bundleItems = [[NSApp delegate] bundleItemsForScope:SPBundleScopeInputField];
-
- // Add 'Bundles' sub menu
- [menu addItem:[NSMenuItem separatorItem]];
-
- NSMenu *bundleMenu = [[[NSMenu alloc] init] autorelease];
- NSMenuItem *bundleSubMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Bundles", @"bundles menu item label") 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:@selector(executeBundleItemForInputField:) 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];
-
- return menu;
-
-}
-
/*
* Insert the content of a dragged file path or if ⌘ is pressed
* while dragging insert the file path
diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m
index 24a5236f..3084138d 100644
--- a/Source/SPTextViewAdditions.m
+++ b/Source/SPTextViewAdditions.m
@@ -692,55 +692,57 @@
NSArray *bundleItems = [[NSApp delegate] bundleItemsForScope:SPBundleScopeInputField];
// Add 'Bundles' sub menu
- [menu addItem:[NSMenuItem separatorItem]];
-
- NSMenu *bundleMenu = [[[NSMenu alloc] init] autorelease];
- NSMenuItem *bundleSubMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Bundles", @"bundles menu item label") 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]];
+ if(bundleItems && [bundleItems count]) {
+ [menu addItem:[NSMenuItem separatorItem]];
+
+ NSMenu *bundleMenu = [[[NSMenu alloc] init] autorelease];
+ NSMenuItem *bundleSubMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Bundles", @"bundles menu item label") 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) {
+ 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];
+ 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]];
+ if([keyEq length])
+ [mItem setKeyEquivalentModifierMask:[[[item objectForKey:SPBundleFileKeyEquivalentKey] objectAtIndex:1] intValue]];
- [mItem setTarget:[[NSApp mainWindow] firstResponder]];
+ [mItem setTarget:[[NSApp mainWindow] firstResponder]];
- if([item objectForKey:SPBundleFileTooltipKey])
- [mItem setToolTip:[item objectForKey:SPBundleFileTooltipKey]];
+ if([item objectForKey:SPBundleFileTooltipKey])
+ [mItem setToolTip:[item objectForKey:SPBundleFileTooltipKey]];
- [mItem setTag:1000000 + i++];
+ [mItem setTag:1000000 + i++];
- if([item objectForKey:SPBundleFileCategoryKey]) {
- [[categoryMenus objectAtIndex:[bundleCategories indexOfObject:[item objectForKey:SPBundleFileCategoryKey]]] addItem:mItem];
- } else {
- [bundleMenu addItem:mItem];
+ if([item objectForKey:SPBundleFileCategoryKey]) {
+ [[categoryMenus objectAtIndex:[bundleCategories indexOfObject:[item objectForKey:SPBundleFileCategoryKey]]] addItem:mItem];
+ } else {
+ [bundleMenu addItem:mItem];
+ }
}
- }
- [bundleSubMenuItem release];
+ [bundleSubMenuItem release];
+ }
return menu;