aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-11-23 12:45:07 +0000
committerBibiko <bibiko@eva.mpg.de>2010-11-23 12:45:07 +0000
commit9f5c7db05e8a999df38b200d93031b1475adf5dc (patch)
treef7da8d5ba93108838486d42d4e9fa5ee6d9c2a2c /Source
parentfe9a592ca3be829570f5bd88efd5b427120556e5 (diff)
downloadsequelpro-9f5c7db05e8a999df38b200d93031b1475adf5dc.tar.gz
sequelpro-9f5c7db05e8a999df38b200d93031b1475adf5dc.tar.bz2
sequelpro-9f5c7db05e8a999df38b200d93031b1475adf5dc.zip
• Bundle Editor
- bailed out from approach to assign more than one scope to Bundle commands; now there're three scopes available: Input Field (incl. Query Editor since it only differs in current_query and insert_as_snippet which falls back to current_line and tooltip message), Data Table, and General (which means that these commands are available app-wide) - moved "Disable Command" to scope popup menu since it's related - Input Field and Data Table commands will be shown as submenus in the Bundles main menu; all General commands will be added without creating a special submenu (only Category submenus will be generated) - fixed and simplified several issues
Diffstat (limited to 'Source')
-rw-r--r--Source/SPAppController.h2
-rw-r--r--Source/SPAppController.m166
-rw-r--r--Source/SPBundleCommandTextView.m21
-rw-r--r--Source/SPBundleEditorController.h15
-rw-r--r--Source/SPBundleEditorController.m233
-rw-r--r--Source/SPCopyTable.m202
-rw-r--r--Source/SPEditSheetTextView.m21
-rw-r--r--Source/SPStringAdditions.m2
-rw-r--r--Source/SPTextView.h2
-rw-r--r--Source/SPTextView.m195
-rw-r--r--Source/SPTextViewAdditions.m83
11 files changed, 410 insertions, 532 deletions
diff --git a/Source/SPAppController.h b/Source/SPAppController.h
index 35c9ee63..9a17dcb6 100644
--- a/Source/SPAppController.h
+++ b/Source/SPAppController.h
@@ -97,4 +97,6 @@
- (void)handleEventWithURL:(NSURL*)url;
+- (IBAction)executeBundleItemForApp:(id)sender;
+
@end
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index c5704f80..9a4e23e6 100644
--- a/Source/SPAppController.m
+++ b/Source/SPAppController.m
@@ -33,6 +33,9 @@
#import "SPWindowController.h"
#import "SPPreferencesUpgrade.h"
#import "SPBundleEditorController.h"
+#import "SPTooltip.h"
+#import "SPBundleHTMLOutputController.h"
+#import "SPAlertSheets.h"
#import <PSMTabBar/PSMTabBarControl.h>
#import <Sparkle/Sparkle.h>
@@ -598,6 +601,132 @@
NSLog(@"command id: %@", passedProcessID);
}
+- (IBAction)executeBundleItemForApp:(id)sender
+{
+
+ NSInteger idx = [sender tag] - 1000000;
+ NSString *infoPath = nil;
+ NSArray *bundleItems = [[NSApp delegate] bundleItemsForScope:SPBundleScopeGeneral];
+ 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;
+ NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, [NSString stringWithNewUUID]];
+
+ [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath 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:bundleInputFilePath forKey:@"SP_BUNDLE_INPUT_FILE"];
+
+ NSError *inputFileError = nil;
+ NSString *input = @"";
+ if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsTab]) {
+ input = [self rowsAsTabStringWithHeaders:YES onlySelectedRows:YES];
+ }
+ else if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsCsv]) {
+ input = [self rowsAsCsvStringWithHeaders:YES onlySelectedRows:YES];
+ }
+ else if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsSqlInsert]) {
+ input = [self rowsAsSqlInsertsOnlySelectedRows:YES];
+ }
+ else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsTab]) {
+ input = [self rowsAsTabStringWithHeaders:YES onlySelectedRows:NO];
+ }
+ else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsCsv]) {
+ input = [self rowsAsCsvStringWithHeaders:YES onlySelectedRows:NO];
+ }
+ else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsSqlInsert]) {
+ input = [self rowsAsSqlInsertsOnlySelectedRows:NO];
+ }
+
+ if(input == nil) input = @"";
+ [input writeToFile:bundleInputFilePath
+ 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, [NSApp mainWindow], 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:bundleInputFilePath error:nil];
+
+ if(err == nil && output && [cmdData objectForKey:SPBundleFileOutputActionKey]) {
+ if([[cmdData objectForKey:SPBundleFileOutputActionKey] length]
+ && ![[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionNone]) {
+ NSString *action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString];
+ NSPoint pos = [NSEvent mouseLocation];
+ pos.y -= 16;
+
+ if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) {
+ [SPTooltip showWithObject:output atLocation:pos];
+ }
+
+ else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) {
+ [SPTooltip showWithObject:output atLocation:pos ofType:@"html"];
+ }
+
+ else if([action isEqualToString:SPBundleOutputActionShowAsHTML]) {
+ SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init];
+ [c displayHTMLContent:output withOptions:nil];
+ }
+ }
+ } else {
+ NSString *errorMessage = [err localizedDescription];
+ SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [NSApp mainWindow], self, nil, nil,
+ [NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]);
+ }
+
+ }
+
+ if (cmdData) [cmdData release];
+
+ }
+
+}
+
#pragma mark -
#pragma mark Window management
@@ -1001,6 +1130,7 @@
// Rebuild Bundles main menu item
+ // Add default menu items
NSMenuItem *anItem;
anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Bundle Editor", @"bundle editor menu item label") action:@selector(openBundleEditor:) keyEquivalent:@"b"];
[anItem setKeyEquivalentModifierMask:(NSCommandKeyMask|NSAlternateKeyMask|NSControlKeyMask)];
@@ -1010,18 +1140,20 @@
[menu addItem:anItem];
[anItem release];
+ // Bail out if no Bundle was installed
if(!foundInstalledBundles) return;
// Add installed Bundles
+ // For each scope add a submenu but not for the last one (should be General always)
[menu addItem:[NSMenuItem separatorItem]];
- NSArray *scopes = [NSArray arrayWithObjects:SPBundleScopeInputField, SPBundleScopeQueryEditor, SPBundleScopeDataTable, nil];
+ NSArray *scopes = [NSArray arrayWithObjects:SPBundleScopeInputField, SPBundleScopeDataTable, SPBundleScopeGeneral, nil];
NSArray *scopeTitles = [NSArray arrayWithObjects:NSLocalizedString(@"Input Fields", @"input fields menu item label"),
- NSLocalizedString(@"Query Editor", @"query editor menu item label"),
- NSLocalizedString(@"Data Table", @"data table menu item label"),nil];
+ NSLocalizedString(@"Data Table", @"data table menu item label"),
+ NSLocalizedString(@"General", @"general menu item label"),nil];
NSArray *scopeSelector = [NSArray arrayWithObjects:@"executeBundleItemForInputField:",
- @"executeBundleItemForEditor:",
- @"executeBundleItemForDataTable:", nil];
+ @"executeBundleItemForDataTable:",
+ @"executeBundleItemForApp:", nil];
NSInteger k = 0;
for(NSString* scope in scopes) {
@@ -1034,13 +1166,25 @@
continue;
}
- NSMenu *bundleMenu = [[[NSMenu alloc] init] autorelease];
- NSMenuItem *bundleSubMenuItem = [[NSMenuItem alloc] initWithTitle:[scopeTitles objectAtIndex:k] action:nil keyEquivalent:@""];
- [bundleSubMenuItem setTag:10000000];
+ NSMenu *bundleMenu = nil;
+ NSMenuItem *bundleSubMenuItem = nil;
+
+ // Add last scope (General) not as submenu
+ if(k < [scopes count]-1) {
+ bundleMenu = [[[NSMenu alloc] init] autorelease];
+
+ bundleSubMenuItem = [[NSMenuItem alloc] initWithTitle:[scopeTitles objectAtIndex:k] action:nil keyEquivalent:@""];
+ [bundleSubMenuItem setTag:10000000];
- [menu addItem:bundleSubMenuItem];
- [menu setSubmenu:bundleMenu forItem:bundleSubMenuItem];
+ [menu addItem:bundleSubMenuItem];
+ [menu setSubmenu:bundleMenu forItem:bundleSubMenuItem];
+
+ } else {
+ bundleMenu = menu;
+ [menu addItem:[NSMenuItem separatorItem]];
+ }
+ // Add found Category submenus
NSMutableArray *categorySubMenus = [NSMutableArray array];
NSMutableArray *categoryMenus = [NSMutableArray array];
if([bundleCategories count]) {
@@ -1078,7 +1222,7 @@
}
}
- [bundleSubMenuItem release];
+ if(bundleSubMenuItem)[bundleSubMenuItem release];
k++;
}
diff --git a/Source/SPBundleCommandTextView.m b/Source/SPBundleCommandTextView.m
index 3213eda7..b90cea43 100644
--- a/Source/SPBundleCommandTextView.m
+++ b/Source/SPBundleCommandTextView.m
@@ -443,27 +443,6 @@
[[self delegate] setDoGroupDueToChars];
}
-
- if([[[[self delegate] class] description] isEqualToString:@"SPBundleEditorController"]) {
- [super keyDown: theEvent];
- return;
- }
-
- // Check for assign key equivalents inside user-defined bundle commands
- NSDictionary *keyEquivalents = [[NSApp delegate] bundleKeyEquivalentsForScope:SPBundleScopeInputField];
- if([keyEquivalents count]) {
- for(NSString* key in [keyEquivalents allKeys]) {
- NSArray *keyData = [keyEquivalents objectForKey:key];
- if([[keyData objectAtIndex:0] isEqualToString:charactersIgnMod] && [[[keyEquivalents objectForKey:key] objectAtIndex:1] intValue] == curFlags) {
- NSMenuItem *item = [[[NSMenuItem alloc] init] autorelease];
- [item setToolTip:[[keyEquivalents objectForKey:key] objectAtIndex:2]];
- [item setTag:0];
- [self executeBundleItemForInputField:item];
- return;
- }
- }
- }
-
[super keyDown: theEvent];
}
diff --git a/Source/SPBundleEditorController.h b/Source/SPBundleEditorController.h
index eca5659f..e07589e1 100644
--- a/Source/SPBundleEditorController.h
+++ b/Source/SPBundleEditorController.h
@@ -39,10 +39,7 @@
IBOutlet NSPopUpButton* inputPopupButton;
IBOutlet NSPopUpButton* inputFallbackPopupButton;
IBOutlet NSPopUpButton* outputPopupButton;
- IBOutlet NSButton *editorScopeButton;
- IBOutlet NSButton *inputFieldScopeButton;
- IBOutlet NSButton *dataTableScopeButton;
- IBOutlet NSButton *disableCheckBox;
+ IBOutlet NSPopUpButton* scopePopupButton;
IBOutlet NSButton *removeButton;
IBOutlet NSMenuItem *duplicateMenuItem;
IBOutlet NSMenuItem *revealInFinderMenuItem;
@@ -56,23 +53,21 @@
NSString *oldBundleName;
BOOL isTableCellEditing;
- NSMenu *inputEditorScopePopUpMenu;
+ NSMenu *inputGeneralScopePopUpMenu;
NSMenu *inputInputFieldScopePopUpMenu;
NSMenu *inputDataTableScopePopUpMenu;
NSMenu *inputNonePopUpMenu;
- NSMenu *outputEditorScopePopUpMenu;
+ NSMenu *outputGeneralScopePopUpMenu;
NSMenu *outputInputFieldScopePopUpMenu;
NSMenu *outputDataTableScopePopUpMenu;
- NSMenu *inputFallbackEditorScopePopUpMenu;
NSMenu *inputFallbackInputFieldScopePopUpMenu;
- NSArray *inputEditorScopeArray;
+ NSArray *inputGeneralScopeArray;
NSArray *inputInputFieldScopeArray;
NSArray *inputDataTableScopeArray;
- NSArray *outputEditorScopeArray;
+ NSArray *outputGeneralScopeArray;
NSArray *outputInputFieldScopeArray;
NSArray *outputDataTableScopeArray;
- NSArray *inputFallbackEditorScopeArray;
NSArray *inputFallbackInputFieldScopeArray;
BOOL doGroupDueToChars;
diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m
index 1f9a9732..bb628c55 100644
--- a/Source/SPBundleEditorController.m
+++ b/Source/SPBundleEditorController.m
@@ -56,23 +56,21 @@
- (void)dealloc
{
- [inputEditorScopePopUpMenu release];
+ [inputGeneralScopePopUpMenu release];
[inputInputFieldScopePopUpMenu release];
[inputDataTableScopePopUpMenu release];
- [outputEditorScopePopUpMenu release];
+ [outputGeneralScopePopUpMenu release];
[outputInputFieldScopePopUpMenu release];
[outputDataTableScopePopUpMenu release];
- [inputFallbackEditorScopePopUpMenu release];
[inputFallbackInputFieldScopePopUpMenu release];
[inputNonePopUpMenu release];
- [inputEditorScopeArray release];
+ [inputGeneralScopeArray release];
[inputInputFieldScopeArray release];
[inputDataTableScopeArray release];
- [outputEditorScopeArray release];
+ [outputGeneralScopeArray release];
[outputInputFieldScopeArray release];
[outputDataTableScopeArray release];
- [inputFallbackEditorScopeArray release];
[inputFallbackInputFieldScopeArray release];
if(commandBundleArray) [commandBundleArray release], commandBundleArray = nil;
@@ -86,43 +84,40 @@
{
// Init all needed menus
- inputEditorScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""];
+ inputGeneralScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""];
inputInputFieldScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""];
inputDataTableScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""];
inputNonePopUpMenu = [[NSMenu alloc] initWithTitle:@""];
- outputEditorScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""];
+ outputGeneralScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""];
outputInputFieldScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""];
outputDataTableScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""];
- inputFallbackEditorScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""];
inputFallbackInputFieldScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""];
- inputEditorScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, SPBundleInputSourceSelectedText, SPBundleInputSourceEntireContent, nil] retain];
+ inputGeneralScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, nil] retain];
inputInputFieldScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, SPBundleInputSourceSelectedText, SPBundleInputSourceEntireContent, nil] retain];
inputDataTableScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, SPBundleInputSourceSelectedTableRowsAsTab, SPBundleInputSourceSelectedTableRowsAsCsv, SPBundleInputSourceSelectedTableRowsAsSqlInsert, SPBundleInputSourceTableRowsAsTab, SPBundleInputSourceTableRowsAsCsv, SPBundleInputSourceTableRowsAsSqlInsert, nil] retain];
- outputEditorScopeArray = [[NSArray arrayWithObjects:SPBundleOutputActionNone, SPBundleOutputActionInsertAsText, SPBundleOutputActionInsertAsSnippet, SPBundleOutputActionReplaceSelection, SPBundleOutputActionReplaceContent, SPBundleOutputActionShowAsTextTooltip, SPBundleOutputActionShowAsHTMLTooltip, SPBundleOutputActionShowAsHTML, nil] retain];
- outputInputFieldScopeArray = [[NSArray arrayWithObjects:SPBundleOutputActionNone, SPBundleOutputActionInsertAsText, SPBundleOutputActionReplaceSelection, SPBundleOutputActionReplaceContent, SPBundleOutputActionShowAsTextTooltip, SPBundleOutputActionShowAsHTMLTooltip, SPBundleOutputActionShowAsHTML, nil] retain];
+ outputInputFieldScopeArray = [[NSArray arrayWithObjects:SPBundleOutputActionNone, SPBundleOutputActionInsertAsText, SPBundleOutputActionInsertAsSnippet, SPBundleOutputActionReplaceSelection, SPBundleOutputActionReplaceContent, SPBundleOutputActionShowAsTextTooltip, SPBundleOutputActionShowAsHTMLTooltip, SPBundleOutputActionShowAsHTML, nil] retain];
+ outputGeneralScopeArray = [[NSArray arrayWithObjects:SPBundleOutputActionNone, SPBundleOutputActionShowAsTextTooltip, SPBundleOutputActionShowAsHTMLTooltip, SPBundleOutputActionShowAsHTML, nil] retain];
outputDataTableScopeArray = [[NSArray arrayWithObjects:SPBundleOutputActionNone, SPBundleOutputActionShowAsTextTooltip, SPBundleOutputActionShowAsHTMLTooltip, SPBundleOutputActionShowAsHTML, nil] retain];
- inputFallbackEditorScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, SPBundleInputSourceCurrentWord, SPBundleInputSourceCurrentLine, SPBundleInputSourceCurrentQuery, SPBundleInputSourceEntireContent, nil] retain];
- inputFallbackInputFieldScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, SPBundleInputSourceCurrentWord, SPBundleInputSourceCurrentLine, SPBundleInputSourceEntireContent, nil] retain];
+ inputFallbackInputFieldScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, SPBundleInputSourceCurrentWord, SPBundleInputSourceCurrentLine, SPBundleInputSourceCurrentQuery, SPBundleInputSourceEntireContent, nil] retain];
NSMutableArray *allPopupScopeItems = [NSMutableArray array];
- [allPopupScopeItems addObjectsFromArray:inputEditorScopeArray];
+ [allPopupScopeItems addObjectsFromArray:inputGeneralScopeArray];
[allPopupScopeItems addObjectsFromArray:inputInputFieldScopeArray];
[allPopupScopeItems addObjectsFromArray:inputDataTableScopeArray];
- [allPopupScopeItems addObjectsFromArray:outputEditorScopeArray];
[allPopupScopeItems addObjectsFromArray:outputInputFieldScopeArray];
+ [allPopupScopeItems addObjectsFromArray:outputGeneralScopeArray];
[allPopupScopeItems addObjectsFromArray:outputDataTableScopeArray];
- [allPopupScopeItems addObjectsFromArray:inputFallbackEditorScopeArray];
[allPopupScopeItems addObjectsFromArray:inputFallbackInputFieldScopeArray];
NSDictionary *menuItemTitles = [NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:
NSLocalizedString(@"None", @"none menu item label"),
- NSLocalizedString(@"Selected Text", @"selected text menu item label"),
- NSLocalizedString(@"Entire Content", @"entire content menu item label"),
+
NSLocalizedString(@"None", @"none menu item label"),
NSLocalizedString(@"Selected Text", @"selected text menu item label"),
NSLocalizedString(@"Entire Content", @"entire content menu item label"),
+
NSLocalizedString(@"None", @"none menu item label"),
NSLocalizedString(@"Selected Rows (TSV)", @"selected rows (TSV) menu item label"),
NSLocalizedString(@"Selected Rows (CSV)", @"selected rows (CSV) menu item label"),
@@ -130,6 +125,7 @@
NSLocalizedString(@"Table Content (TSV)", @"table content (TSV) menu item label"),
NSLocalizedString(@"Table Content (CSV)", @"table content (CSV) menu item label"),
NSLocalizedString(@"Table Content (SQL)", @"table content (SQL) menu item label"),
+
NSLocalizedString(@"None", @"none menu item label"),
NSLocalizedString(@"Insert as Text", @"insert as text item label"),
NSLocalizedString(@"Insert as Snippet", @"insert as snippet item label"),
@@ -138,33 +134,29 @@
NSLocalizedString(@"Show as Text Tooltip", @"show as text tooltip item label"),
NSLocalizedString(@"Show as HTML Tooltip", @"show as html tooltip item label"),
NSLocalizedString(@"Show as HTML", @"show as html item label"),
+
NSLocalizedString(@"None", @"none menu item label"),
- NSLocalizedString(@"Insert as Text", @"insert as text item label"),
- NSLocalizedString(@"Replace Selection", @"replace selection item label"),
- NSLocalizedString(@"Replace Entire Content", @"replace entire content item label"),
NSLocalizedString(@"Show as Text Tooltip", @"show as text tooltip item label"),
NSLocalizedString(@"Show as HTML Tooltip", @"show as html tooltip item label"),
NSLocalizedString(@"Show as HTML", @"show as html item label"),
+
NSLocalizedString(@"None", @"none menu item label"),
NSLocalizedString(@"Show as Text Tooltip", @"show as text tooltip item label"),
NSLocalizedString(@"Show as HTML Tooltip", @"show as html tooltip item label"),
NSLocalizedString(@"Show as HTML", @"show as html item label"),
+
NSLocalizedString(@"None", @"none menu item label"),
NSLocalizedString(@"Current Word", @"current word item label"),
NSLocalizedString(@"Current Line", @"current line item label"),
NSLocalizedString(@"Current Query", @"current query item label"),
NSLocalizedString(@"Entire Content", @"entire content item label"),
- NSLocalizedString(@"None", @"none menu item label"),
- NSLocalizedString(@"Current Word", @"current word item label"),
- NSLocalizedString(@"Current Line", @"current line item label"),
- NSLocalizedString(@"Entire Content", @"entire content item label"),
nil]
forKeys:allPopupScopeItems];
NSMenuItem *anItem;
- for(NSString* title in inputEditorScopeArray) {
+ for(NSString* title in inputGeneralScopeArray) {
anItem = [[NSMenuItem alloc] initWithTitle:[menuItemTitles objectForKey:title] action:@selector(inputPopupButtonChanged:) keyEquivalent:@""];
- [inputEditorScopePopUpMenu addItem:anItem];
+ [inputGeneralScopePopUpMenu addItem:anItem];
[anItem release];
}
for(NSString* title in inputInputFieldScopeArray) {
@@ -177,9 +169,9 @@
[inputDataTableScopePopUpMenu addItem:anItem];
[anItem release];
}
- for(NSString* title in outputEditorScopeArray) {
+ for(NSString* title in outputGeneralScopeArray) {
anItem = [[NSMenuItem alloc] initWithTitle:[menuItemTitles objectForKey:title] action:@selector(outputPopupButtonChanged:) keyEquivalent:@""];
- [outputEditorScopePopUpMenu addItem:anItem];
+ [outputGeneralScopePopUpMenu addItem:anItem];
[anItem release];
}
for(NSString* title in outputInputFieldScopeArray) {
@@ -192,11 +184,6 @@
[outputDataTableScopePopUpMenu addItem:anItem];
[anItem release];
}
- for(NSString* title in inputFallbackEditorScopeArray) {
- anItem = [[NSMenuItem alloc] initWithTitle:[menuItemTitles objectForKey:title] action:@selector(inputFallbackPopupButtonChanged:) keyEquivalent:@""];
- [inputFallbackEditorScopePopUpMenu addItem:anItem];
- [anItem release];
- }
for(NSString* title in inputFallbackInputFieldScopeArray) {
anItem = [[NSMenuItem alloc] initWithTitle:[menuItemTitles objectForKey:title] action:@selector(inputFallbackPopupButtonChanged:) keyEquivalent:@""];
[inputFallbackInputFieldScopePopUpMenu addItem:anItem];
@@ -206,6 +193,26 @@
[inputNonePopUpMenu addItem:anItem];
[anItem release];
+ [inputGeneralScopePopUpMenu removeAllItems];
+ anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"General", @"general scope menu label") action:@selector(scopeButtonChanged:) keyEquivalent:@""];
+ [anItem setTag:0];
+ [inputGeneralScopePopUpMenu addItem:anItem];
+ [anItem release];
+ anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Input Field", @"input field scope menu label") action:@selector(scopeButtonChanged:) keyEquivalent:@""];
+ [anItem setTag:1];
+ [inputGeneralScopePopUpMenu addItem:anItem];
+ [anItem release];
+ anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Data Table", @"data table scope menu label") action:@selector(scopeButtonChanged:) keyEquivalent:@""];
+ [anItem setTag:2];
+ [inputGeneralScopePopUpMenu addItem:anItem];
+ [anItem release];
+ [inputGeneralScopePopUpMenu addItem:[NSMenuItem separatorItem]];
+ anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Disable Command", @"disable command menu label") action:@selector(scopeButtonChanged:) keyEquivalent:@""];
+ [anItem setTag:10];
+ [inputGeneralScopePopUpMenu addItem:anItem];
+ [anItem release];
+ [scopePopupButton setMenu:inputGeneralScopePopUpMenu];
+
[keyEquivalentField setCanCaptureGlobalHotKeys:YES];
}
@@ -221,8 +228,8 @@
NSInteger selectedIndex = [senderMenu indexOfItem:sender];
NSString *input = SPBundleInputSourceNone;
- if(senderMenu == inputEditorScopePopUpMenu)
- input = [inputEditorScopeArray objectAtIndex:selectedIndex];
+ if(senderMenu == inputGeneralScopePopUpMenu)
+ input = [inputGeneralScopeArray objectAtIndex:selectedIndex];
else if(senderMenu == inputInputFieldScopePopUpMenu)
input = [inputInputFieldScopeArray objectAtIndex:selectedIndex];
else if(senderMenu == inputDataTableScopePopUpMenu)
@@ -245,9 +252,7 @@
NSInteger selectedIndex = [senderMenu indexOfItem:sender];
NSString *input = SPBundleInputSourceNone;
- if(senderMenu == inputFallbackEditorScopePopUpMenu)
- input = [inputFallbackEditorScopeArray objectAtIndex:selectedIndex];
- else if(senderMenu == inputFallbackInputFieldScopePopUpMenu)
+ if(senderMenu == inputFallbackInputFieldScopePopUpMenu)
input = [inputFallbackInputFieldScopeArray objectAtIndex:selectedIndex];
[currentDict setObject:input forKey:SPBundleFileInputSourceFallBackKey];
@@ -263,8 +268,8 @@
NSInteger selectedIndex = [senderMenu indexOfItem:sender];
NSString *output = SPBundleOutputActionNone;
- if(senderMenu == outputEditorScopePopUpMenu)
- output = [outputEditorScopeArray objectAtIndex:selectedIndex];
+ if(senderMenu == outputGeneralScopePopUpMenu)
+ output = [outputGeneralScopeArray objectAtIndex:selectedIndex];
else if(senderMenu == outputInputFieldScopePopUpMenu)
output = [outputInputFieldScopeArray objectAtIndex:selectedIndex];
else if(senderMenu == outputDataTableScopePopUpMenu)
@@ -278,35 +283,22 @@
{
id currentDict = [commandBundleArray objectAtIndex:[commandsTableView selectedRow]];
- NSInteger inputMask = [[currentDict objectForKey:SPBundleScopeQueryEditor] intValue] * 1 +
- [[currentDict objectForKey:SPBundleScopeInputField] intValue] * 2 +
- [[currentDict objectForKey:SPBundleScopeDataTable] intValue] * 4;
-
- if(inputMask < 1 || inputMask > 7) {
- inputMask = 7;
- NSNumber *on = [NSNumber numberWithInt:1];
- [currentDict setObject:on forKey:SPBundleScopeQueryEditor];
- [currentDict setObject:on forKey:SPBundleScopeInputField];
- [currentDict setObject:on forKey:SPBundleScopeDataTable];
- }
-
- [currentDict setObject:[NSNumber numberWithInt:inputMask] forKey:@"inputMask"];
- if(inputMask > 4) {
- [currentDict setObject:SPBundleInputSourceNone forKey:SPBundleFileInputSourceKey];
- [currentDict setObject:SPBundleInputSourceNone forKey:SPBundleFileInputSourceFallBackKey];
- if(![[currentDict objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionShowAsTextTooltip]
- && ![[currentDict objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) {
- [currentDict setObject:SPBundleOutputActionNone forKey:SPBundleFileOutputActionKey];
- }
+ NSInteger selectedTag = [sender tag];
+ switch(selectedTag) {
+ case 0:
+ [currentDict setObject:SPBundleScopeGeneral forKey:SPBundleFileScopeKey];
+ break;
+ case 1:
+ [currentDict setObject:SPBundleScopeInputField forKey:SPBundleFileScopeKey];
+ break;
+ case 2:
+ [currentDict setObject:SPBundleScopeDataTable forKey:SPBundleFileScopeKey];
+ break;
+ default:
+ [currentDict setObject:@"" forKey:SPBundleFileScopeKey];
}
- if([[currentDict objectForKey:SPBundleFileInputSourceKey] isEqualToString:SPBundleInputSourceSelectedText]) {
- if(inputMask > 1 && [[currentDict objectForKey:SPBundleFileInputSourceFallBackKey] isEqualToString:SPBundleInputSourceCurrentQuery])
- [currentDict setObject:SPBundleInputSourceNone forKey:SPBundleFileInputSourceFallBackKey];
- }
- if((inputMask == 2 || inputMask == 3) && [[currentDict objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionInsertAsSnippet])
- [currentDict setObject:SPBundleOutputActionInsertAsText forKey:SPBundleFileOutputActionKey];
[self _updateInputPopupButton];
@@ -376,8 +368,8 @@
}
// Add a new Bundle
else {
- bundle = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"New Bundle", @"New Name", @"", SPBundleScopeInputField, [NSNumber numberWithInt:1], nil]
- forKeys:[NSArray arrayWithObjects:@"bundleName", SPBundleFileNameKey, SPBundleFileCommandKey, SPBundleFileScopeKey, SPBundleScopeInputField, nil]];
+ bundle = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"New Bundle", @"New Name", @"", SPBundleScopeGeneral, nil]
+ forKeys:[NSArray arrayWithObjects:@"bundleName", SPBundleFileNameKey, SPBundleFileCommandKey, SPBundleFileScopeKey, nil]];
}
if ([commandsTableView numberOfSelectedRows] > 0) {
insertIndex = [[commandsTableView selectedRowIndexes] lastIndex]+1;
@@ -499,18 +491,6 @@
[bundleCommand addEntriesFromDictionary:cmdData];
[bundleCommand setObject:[bundle stringByDeletingPathExtension] forKey:@"bundleName"];
- NSInteger inputMask = 0;
-
- // Handle stored scopes
- NSArray *scopes = [[cmdData objectForKey:SPBundleFileScopeKey] componentsSeparatedByString:@" "];
- for(NSString *scope in scopes) {
- [bundleCommand setObject:[NSNumber numberWithInt:1] forKey:scope];
- if([scope isEqualToString:SPBundleScopeQueryEditor]) inputMask += 1;
- if([scope isEqualToString:SPBundleScopeInputField]) inputMask += 2;
- if([scope isEqualToString:SPBundleScopeDataTable]) inputMask += 4;
- [bundleCommand setObject:[NSNumber numberWithInt:inputMask] forKey:@"inputMask"];
- }
-
[commandBundleArray addObject:bundleCommand];
}
@@ -599,35 +579,9 @@
NSMutableDictionary *saveDict = [NSMutableDictionary dictionary];
[saveDict addEntriesFromDictionary:bundle];
- // Build scope key
- NSMutableString *scopes = [NSMutableString string];
- if([bundle objectForKey:SPBundleScopeQueryEditor] && [[bundle objectForKey:SPBundleScopeQueryEditor] intValue]) {
- if([scopes length]) [scopes appendString:@" "];
- [scopes appendString:SPBundleScopeQueryEditor];
- }
- if([bundle objectForKey:SPBundleScopeInputField] && [[bundle objectForKey:SPBundleScopeInputField] intValue]) {
- if([scopes length]) [scopes appendString:@" "];
- [scopes appendString:SPBundleScopeInputField];
- }
- if([bundle objectForKey:SPBundleScopeDataTable] && [[bundle objectForKey:SPBundleScopeDataTable] intValue]) {
- if([scopes length]) [scopes appendString:@" "];
- [scopes appendString:SPBundleScopeDataTable];
- }
- if(![scopes length]) {
- // For safety reasons
- [scopes setString:[NSString stringWithFormat:@"%@ %@ %@", SPBundleScopeQueryEditor, SPBundleScopeInputField, SPBundleScopeDataTable]];
- [saveDict setObject:SPBundleInputSourceNone forKey:SPBundleFileInputSourceKey];
- [saveDict setObject:SPBundleOutputActionNone forKey:SPBundleFileOutputActionKey];
- }
- [saveDict setObject:scopes forKey:SPBundleFileScopeKey];
-
// Remove unnecessary keys
[saveDict removeObjectsForKeys:[NSArray arrayWithObjects:
@"bundleName",
- @"inputMask",
- SPBundleScopeQueryEditor,
- SPBundleScopeInputField,
- SPBundleScopeDataTable,
nil]];
// Remove a given old command.plist file
@@ -668,8 +622,8 @@
// Use a AppleScript script since NSWorkspace performFileOperation or NSFileManager moveItemAtPath
// have problems probably due access rights.
- NSString *moveToTrahCommand = [NSString stringWithFormat:@"osascript -e 'tell application \"Finder\" to move (POSIX file \"%@\") to the trash'", thePath];
- [moveToTrahCommand runBashCommandWithEnvironment:nil atCurrentDirectoryPath:nil error:&error];
+ NSString *moveToTrashCommand = [NSString stringWithFormat:@"osascript -e 'tell application \"Finder\" to move (POSIX file \"%@\") to the trash'", thePath];
+ [moveToTrashCommand runBashCommandWithEnvironment:nil atCurrentDirectoryPath:nil error:&error];
if(error != nil) {
NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while moving “%@” to Trash.", @"error while moving “%@” to trash"), thePath]
defaultButton:NSLocalizedString(@"OK", @"OK button")
@@ -1086,24 +1040,33 @@
NSString *output = [currentDict objectForKey:SPBundleFileOutputActionKey];
if(!output || ![output length]) output = SPBundleOutputActionNone;
- NSInteger inputMask = [[currentDict objectForKey:@"inputMask"] intValue];
- switch(inputMask) {
- case 1:
- [inputPopupButton setMenu:inputEditorScopePopUpMenu];
- anIndex = [inputEditorScopeArray indexOfObject:input];
- if(anIndex == NSNotFound) anIndex = 0;
- [inputPopupButton selectItemAtIndex:anIndex];
- [inputFallbackPopupButton setMenu:inputFallbackEditorScopePopUpMenu];
- anIndex = [inputFallbackEditorScopeArray indexOfObject:inputfallback];
- if(anIndex == NSNotFound) anIndex = 0;
- [inputFallbackPopupButton selectItemAtIndex:anIndex];
- [outputPopupButton setMenu:outputEditorScopePopUpMenu];
- anIndex = [outputEditorScopeArray indexOfObject:output];
+ NSString *scope = [currentDict objectForKey:SPBundleFileScopeKey];
+ if(!scope) scope = SPBundleScopeGeneral;
+
+ if([scope isEqualToString:SPBundleScopeGeneral])
+ [scopePopupButton selectItemWithTag:0];
+ else if([scope isEqualToString:SPBundleScopeInputField])
+ [scopePopupButton selectItemWithTag:1];
+ else if([scope isEqualToString:SPBundleScopeDataTable])
+ [scopePopupButton selectItemWithTag:2];
+ else
+ [scopePopupButton selectItemWithTag:10];
+
+ [currentDict setObject:[NSNumber numberWithBool:NO] forKey:SPBundleFileDisabledKey];
+
+ switch([[scopePopupButton selectedItem] tag]) {
+ case 0: // General
+ [inputPopupButton setMenu:inputNonePopUpMenu];
+ [inputPopupButton selectItemAtIndex:0];
+ [outputPopupButton setMenu:outputGeneralScopePopUpMenu];
+ anIndex = [outputGeneralScopeArray indexOfObject:output];
if(anIndex == NSNotFound) anIndex = 0;
[outputPopupButton selectItemAtIndex:anIndex];
+ input = SPBundleInputSourceNone;
+ [inputFallbackPopupButton setHidden:YES];
+ [fallbackLabelField setHidden:YES];
break;
- case 2:
- case 3:
+ case 1: // Input Field
[inputPopupButton setMenu:inputInputFieldScopePopUpMenu];
anIndex = [inputInputFieldScopeArray indexOfObject:input];
if(anIndex == NSNotFound) anIndex = 0;
@@ -1117,7 +1080,7 @@
if(anIndex == NSNotFound) anIndex = 0;
[outputPopupButton selectItemAtIndex:anIndex];
break;
- case 4:
+ case 2: // Data Table
[inputPopupButton setMenu:inputDataTableScopePopUpMenu];
anIndex = [inputDataTableScopeArray indexOfObject:input];
if(anIndex == NSNotFound) anIndex = 0;
@@ -1126,22 +1089,18 @@
anIndex = [outputDataTableScopeArray indexOfObject:output];
if(anIndex == NSNotFound) anIndex = 0;
[outputPopupButton selectItemAtIndex:anIndex];
+ input = SPBundleInputSourceNone;
+ [inputFallbackPopupButton setHidden:YES];
+ [fallbackLabelField setHidden:YES];
break;
- case 5:
- case 6:
- case 7:
- [inputPopupButton setMenu:inputNonePopUpMenu];
- [inputPopupButton selectItemAtIndex:0];
- [outputPopupButton setMenu:outputDataTableScopePopUpMenu];
- anIndex = [outputDataTableScopeArray indexOfObject:output];
- if(anIndex == NSNotFound) anIndex = 0;
- [outputPopupButton selectItemAtIndex:anIndex];
+ case 10: // Disable command
+ [currentDict setObject:[NSNumber numberWithBool:YES] forKey:SPBundleFileDisabledKey];
break;
default:
[inputPopupButton setMenu:inputNonePopUpMenu];
[inputPopupButton selectItemAtIndex:0];
- [outputPopupButton setMenu:outputDataTableScopePopUpMenu];
- anIndex = [outputDataTableScopeArray indexOfObject:output];
+ [outputPopupButton setMenu:outputGeneralScopePopUpMenu];
+ anIndex = [outputGeneralScopeArray indexOfObject:output];
if(anIndex == NSNotFound) anIndex = 0;
[outputPopupButton selectItemAtIndex:anIndex];
}
diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m
index 77dd14f6..28fcb476 100644
--- a/Source/SPCopyTable.m
+++ b/Source/SPCopyTable.m
@@ -804,132 +804,132 @@ NSInteger MENU_EDIT_COPY_AS_SQL = 2003;
- (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];
- }
+ 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;
- }
+ if(!infoPath) {
+ NSBeep();
+ return;
+ }
- NSError *readError = nil;
- NSString *convError = nil;
- NSPropertyListFormat format;
- NSDictionary *cmdData = nil;
- NSData *pData = [NSData dataWithContentsOfFile:infoPath options:NSUncachedRead error:&readError];
+ 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];
+ 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]) {
+ 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;
- NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, [NSString stringWithNewUUID]];
+ NSString *cmd = [cmdData objectForKey:SPBundleFileCommandKey];
+ NSString *inputAction = @"";
+ NSString *inputFallBackAction = @"";
+ NSError *err = nil;
+ NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, [NSString stringWithNewUUID]];
- [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil];
+ [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil];
- if([cmdData objectForKey:SPBundleFileInputSourceKey])
- inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString];
- if([cmdData objectForKey:SPBundleFileInputSourceFallBackKey])
- inputFallBackAction = [[cmdData objectForKey:SPBundleFileInputSourceFallBackKey] lowercaseString];
+ 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:bundleInputFilePath forKey:@"SP_BUNDLE_INPUT_FILE"];
+ NSMutableDictionary *env = [NSMutableDictionary dictionary];
+ [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:@"SP_BUNDLE_PATH"];
+ [env setObject:bundleInputFilePath forKey:@"SP_BUNDLE_INPUT_FILE"];
- if([[self delegate] respondsToSelector:@selector(usedQuery)] && [[self delegate] usedQuery])
- [env setObject:[[self delegate] usedQuery] forKey:@"SP_USED_QUERY_FOR_TABLE"];
+ if([[self delegate] respondsToSelector:@selector(usedQuery)] && [[self delegate] usedQuery])
+ [env setObject:[[self delegate] usedQuery] forKey:@"SP_USED_QUERY_FOR_TABLE"];
- NSError *inputFileError = nil;
- NSString *input = @"";
- if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsTab]) {
- input = [self rowsAsTabStringWithHeaders:YES onlySelectedRows:YES];
- }
- else if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsCsv]) {
- input = [self rowsAsCsvStringWithHeaders:YES onlySelectedRows:YES];
- }
- else if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsSqlInsert]) {
- input = [self rowsAsSqlInsertsOnlySelectedRows:YES];
- }
- else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsTab]) {
- input = [self rowsAsTabStringWithHeaders:YES onlySelectedRows:NO];
- }
- else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsCsv]) {
- input = [self rowsAsCsvStringWithHeaders:YES onlySelectedRows:NO];
- }
- else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsSqlInsert]) {
- input = [self rowsAsSqlInsertsOnlySelectedRows:NO];
- }
-
- if(input == nil) input = @"";
- [input writeToFile:bundleInputFilePath
- 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;
- }
+ NSError *inputFileError = nil;
+ NSString *input = @"";
+ if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsTab]) {
+ input = [self rowsAsTabStringWithHeaders:YES onlySelectedRows:YES];
+ }
+ else if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsCsv]) {
+ input = [self rowsAsCsvStringWithHeaders:YES onlySelectedRows:YES];
+ }
+ else if([inputAction isEqualToString:SPBundleInputSourceSelectedTableRowsAsSqlInsert]) {
+ input = [self rowsAsSqlInsertsOnlySelectedRows:YES];
+ }
+ else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsTab]) {
+ input = [self rowsAsTabStringWithHeaders:YES onlySelectedRows:NO];
+ }
+ else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsCsv]) {
+ input = [self rowsAsCsvStringWithHeaders:YES onlySelectedRows:NO];
+ }
+ else if([inputAction isEqualToString:SPBundleInputSourceTableRowsAsSqlInsert]) {
+ input = [self rowsAsSqlInsertsOnlySelectedRows:NO];
+ }
+
+ if(input == nil) input = @"";
+ [input writeToFile:bundleInputFilePath
+ 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];
+ NSString *output = [cmd runBashCommandWithEnvironment:env atCurrentDirectoryPath:nil error:&err];
- [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil];
+ [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil];
- if(err == nil && output && [cmdData objectForKey:SPBundleFileOutputActionKey]) {
- if([[cmdData objectForKey:SPBundleFileOutputActionKey] length]
- && ![[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionNone]) {
- NSString *action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString];
- NSPoint pos = [NSEvent mouseLocation];
- pos.y -= 16;
+ if(err == nil && output && [cmdData objectForKey:SPBundleFileOutputActionKey]) {
+ if([[cmdData objectForKey:SPBundleFileOutputActionKey] length]
+ && ![[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionNone]) {
+ NSString *action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString];
+ NSPoint pos = [NSEvent mouseLocation];
+ pos.y -= 16;
- if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) {
- [SPTooltip showWithObject:output atLocation:pos];
- }
+ if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) {
+ [SPTooltip showWithObject:output atLocation:pos];
+ }
- else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) {
- [SPTooltip showWithObject:output atLocation:pos ofType:@"html"];
- }
+ else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) {
+ [SPTooltip showWithObject:output atLocation:pos ofType:@"html"];
+ }
- else if([action isEqualToString:SPBundleOutputActionShowAsHTML]) {
- SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init];
- [c displayHTMLContent:output withOptions:nil];
- }
+ else if([action isEqualToString:SPBundleOutputActionShowAsHTML]) {
+ SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init];
+ [c displayHTMLContent:output withOptions:nil];
}
- } 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]);
}
-
+ } 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];
-
}
+ 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 a333a850..95fcd51d 100644
--- a/Source/SPEditSheetTextView.m
+++ b/Source/SPEditSheetTextView.m
@@ -137,27 +137,6 @@
[[self delegate] setDoGroupDueToChars];
}
-
- if([[[[self delegate] class] description] isEqualToString:@"SPBundleEditorController"]) {
- [super keyDown: theEvent];
- return;
- }
-
- // Check for assign key equivalents inside user-defined bundle commands
- NSDictionary *keyEquivalents = [[NSApp delegate] bundleKeyEquivalentsForScope:SPBundleScopeInputField];
- if([keyEquivalents count]) {
- for(NSString* key in [keyEquivalents allKeys]) {
- NSArray *keyData = [keyEquivalents objectForKey:key];
- if([[keyData objectAtIndex:0] isEqualToString:charactersIgnMod] && [[[keyEquivalents objectForKey:key] objectAtIndex:1] intValue] == curFlags) {
- NSMenuItem *item = [[[NSMenuItem alloc] init] autorelease];
- [item setToolTip:[[keyEquivalents objectForKey:key] objectAtIndex:2]];
- [item setTag:0];
- [self executeBundleItemForInputField:item];
- return;
- }
- }
- }
-
[super keyDown: theEvent];
}
diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m
index ea3f6385..1f9f2738 100644
--- a/Source/SPStringAdditions.m
+++ b/Source/SPStringAdditions.m
@@ -535,7 +535,7 @@
if(userTerminated) {
if(bashTask) [bashTask release];
NSBeep();
- NSLog(@"“%@” was terminated by user.", self);
+ NSLog(@"“%@” was terminated by user.", ([self length] > 50) ? [self substringToIndex:50] : self);
return @"";
}
diff --git a/Source/SPTextView.h b/Source/SPTextView.h
index 02482611..797fff34 100644
--- a/Source/SPTextView.h
+++ b/Source/SPTextView.h
@@ -144,6 +144,4 @@
- (BOOL)isSnippetMode;
-- (IBAction)executeBundleItemForEditor:(id)sender;
-
@end
diff --git a/Source/SPTextView.m b/Source/SPTextView.m
index ef581a8f..c458e7b1 100644
--- a/Source/SPTextView.m
+++ b/Source/SPTextView.m
@@ -2121,21 +2121,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
}
}
- // Check for assign key equivalents inside user-defined bundle commands
- NSDictionary *keyEquivalents = [[NSApp delegate] bundleKeyEquivalentsForScope:SPBundleScopeQueryEditor];
- if([keyEquivalents count]) {
- for(NSString* key in [keyEquivalents allKeys]) {
- NSArray *keyData = [keyEquivalents objectForKey:key];
- if([[keyData objectAtIndex:0] isEqualToString:charactersIgnMod] && [[[keyEquivalents objectForKey:key] objectAtIndex:1] intValue] == curFlags) {
- NSMenuItem *item = [[[NSMenuItem alloc] init] autorelease];
- [item setToolTip:[[keyEquivalents objectForKey:key] objectAtIndex:2]];
- [item setTag:0];
- [self executeBundleItemForEditor:item];
- return;
- }
- }
- }
-
// Only process for character autopairing if autopairing is enabled and a single character is being added.
if ([prefs boolForKey:SPCustomQueryAutoPairCharacters] && characters && [characters length] == 1) {
@@ -2928,8 +2913,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
[menu removeItem:bItem];
}
- NSArray *bundleCategories = [[NSApp delegate] bundleCategoriesForScope:SPBundleScopeQueryEditor];
- NSArray *bundleItems = [[NSApp delegate] bundleItemsForScope:SPBundleScopeQueryEditor];
+ NSArray *bundleCategories = [[NSApp delegate] bundleCategoriesForScope:SPBundleScopeInputField];
+ NSArray *bundleItems = [[NSApp delegate] bundleItemsForScope:SPBundleScopeInputField];
// Add 'Bundles' sub menu for custom query editor only so far if bundles with scope 'editor' were found
if(customQueryInstance && bundleItems && [bundleItems count]) {
@@ -2962,7 +2947,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
else
keyEq = @"";
- NSMenuItem *mItem = [[[NSMenuItem alloc] initWithTitle:[item objectForKey:SPBundleInternLabelKey] action:@selector(executeBundleItemForEditor:) 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]];
@@ -2994,15 +2979,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
- (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:)) {
@@ -3414,171 +3390,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
#pragma mark -
-- (IBAction)executeBundleItemForEditor:(id)sender
-{
-
- NSInteger idx = [sender tag] - 1000000;
- NSString *infoPath = nil;
- NSArray *bundleItems = [[NSApp delegate] bundleItemsForScope:SPBundleScopeQueryEditor];
- 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;
- NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, [NSString stringWithNewUUID]];
-
- NSRange currentWordRange, currentQueryRange, currentSelectionRange, currentLineRange;
-
- [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil];
-
- if([cmdData objectForKey:SPBundleFileInputSourceKey])
- inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString];
- if([cmdData objectForKey:SPBundleFileInputSourceFallBackKey])
- inputFallBackAction = [[cmdData objectForKey:SPBundleFileInputSourceFallBackKey] lowercaseString];
-
- currentSelectionRange = [self selectedRange];
- currentWordRange = [self getRangeForCurrentWord];
- if(customQueryInstance && [customQueryInstance currentQueryRange].length) {
- currentQueryRange = [customQueryInstance currentQueryRange];
- } else {
- currentQueryRange = currentSelectionRange;
- }
- currentLineRange = [[self string] lineRangeForRange:NSMakeRange([self selectedRange].location, 0)];
-
- NSRange replaceRange = NSMakeRange(currentSelectionRange.location, 0);
- if([inputAction isEqualToString:SPBundleInputSourceSelectedText]) {
- if(!currentSelectionRange.length) {
- if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentWord])
- replaceRange = currentWordRange;
- else if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentLine])
- replaceRange = currentLineRange;
- else if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentQuery])
- replaceRange = currentQueryRange;
- else if([inputAction isEqualToString:SPBundleInputSourceEntireContent])
- replaceRange = NSMakeRange(0,[[self string] length]);
- } else {
- replaceRange = currentSelectionRange;
- }
-
- }
- else if([inputAction isEqualToString:SPBundleInputSourceEntireContent]) {
- replaceRange = NSMakeRange(0, [[self string] length]);
- }
-
- NSMutableDictionary *env = [NSMutableDictionary dictionary];
- [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:@"SP_BUNDLE_PATH"];
- [env setObject:bundleInputFilePath forKey:@"SP_BUNDLE_INPUT_FILE"];
-
- if(currentSelectionRange.length)
- [env setObject:[[self string] substringWithRange:currentSelectionRange] forKey:@"SP_SELECTED_TEXT"];
-
- if(customQueryInstance && [customQueryInstance currentQueryRange].length)
- [env setObject:[[self string] substringWithRange:[customQueryInstance currentQueryRange]] forKey:@"SP_CURRENT_QUERY"];
-
- if(currentWordRange.length)
- [env setObject:[[self string] substringWithRange:currentWordRange] forKey:@"SP_CURRENT_WORD"];
-
- if(currentLineRange.length)
- [env setObject:[[self string] substringWithRange:currentLineRange] forKey:@"SP_CURRENT_LINE"];
-
- NSError *inputFileError = nil;
- NSString *input = [NSString stringWithString:[[self string] substringWithRange:replaceRange]];
- [input writeToFile:bundleInputFilePath
- 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:bundleInputFilePath error:nil];
-
- if(err == nil && output && [cmdData objectForKey:SPBundleFileOutputActionKey]) {
- if([[cmdData objectForKey:SPBundleFileOutputActionKey] length]
- && ![[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionNone]) {
- NSString *action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString];
-
- if([action isEqualToString:SPBundleOutputActionInsertAsText]) {
- [self insertText:output];
- }
-
- else if([action isEqualToString:SPBundleOutputActionInsertAsSnippet]) {
- [self insertAsSnippet:output atRange:replaceRange];
- }
-
- else if([action isEqualToString:SPBundleOutputActionReplaceContent]) {
- if([[self string] length])
- [self setSelectedRange:NSMakeRange(0, [[self string] length])];
- [self insertText:output];
- }
-
- else if([action isEqualToString:SPBundleOutputActionReplaceSelection]) {
- [self shouldChangeTextInRange:replaceRange replacementString:output];
- [self replaceCharactersInRange:replaceRange withString:output];
- }
-
- else if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) {
- [SPTooltip showWithObject:output];
- }
-
- else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) {
- [SPTooltip showWithObject:output ofType:@"html"];
- }
-
- else if([action isEqualToString:SPBundleOutputActionShowAsHTML]) {
- SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init];
- [c displayHTMLContent:output withOptions:nil];
- }
- }
- } 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];
-
- }
-
-}
#pragma mark -
diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m
index a33d80e4..1bc45aad 100644
--- a/Source/SPTextViewAdditions.m
+++ b/Source/SPTextViewAdditions.m
@@ -25,6 +25,7 @@
#import "SPAlertSheets.h"
#import "SPTooltip.h"
#import "SPBundleHTMLOutputController.h"
+#import "SPCustomQuery.h"
@implementation NSTextView (SPTextViewAdditions)
@@ -528,10 +529,12 @@
NSError *err = nil;
NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, [NSString stringWithNewUUID]];
- NSRange currentWordRange, currentSelectionRange, currentLineRange;
+ NSRange currentWordRange, currentSelectionRange, currentLineRange, currentQueryRange;
[[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil];
+ BOOL selfIsQueryEditor = ([[[self class] description] isEqualToString:@"SPTextView"]) ;
+
if([cmdData objectForKey:SPBundleFileInputSourceKey])
inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString];
if([cmdData objectForKey:SPBundleFileInputSourceFallBackKey])
@@ -541,6 +544,14 @@
currentWordRange = [self getRangeForCurrentWord];
currentLineRange = [[self string] lineRangeForRange:NSMakeRange([self selectedRange].location, 0)];
+ if(selfIsQueryEditor) {
+ currentQueryRange = [[self delegate] currentQueryRange];
+ } else {
+ currentQueryRange = currentLineRange;
+ }
+ if(!currentQueryRange.length)
+ currentQueryRange = currentSelectionRange;
+
NSRange replaceRange = NSMakeRange(currentSelectionRange.location, 0);
if([inputAction isEqualToString:SPBundleInputSourceSelectedText]) {
if(!currentSelectionRange.length) {
@@ -548,6 +559,8 @@
replaceRange = currentWordRange;
else if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentLine])
replaceRange = currentLineRange;
+ else if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentQuery])
+ replaceRange = currentQueryRange;
else if([inputAction isEqualToString:SPBundleInputSourceEntireContent])
replaceRange = NSMakeRange(0,[[self string] length]);
} else {
@@ -563,6 +576,9 @@
[env setObject:[infoPath stringByDeletingLastPathComponent] forKey:@"SP_BUNDLE_PATH"];
[env setObject:bundleInputFilePath forKey:@"SP_BUNDLE_INPUT_FILE"];
+ if(selfIsQueryEditor && [[self delegate] currentQueryRange].length)
+ [env setObject:[[self string] substringWithRange:[[self delegate] currentQueryRange]] forKey:@"SP_CURRENT_QUERY"];
+
if(currentSelectionRange.length)
[env setObject:[[self string] substringWithRange:currentSelectionRange] forKey:@"SP_SELECTED_TEXT"];
@@ -596,26 +612,7 @@
&& ![[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionNone]) {
NSString *action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString];
- if([action isEqualToString:SPBundleOutputActionInsertAsText]) {
- [self insertText:output];
- }
-
- else if([action isEqualToString:SPBundleOutputActionInsertAsSnippet]) {
- [self insertAsSnippet:output atRange:replaceRange];
- }
-
- else if([action isEqualToString:SPBundleOutputActionReplaceContent]) {
- if([[self string] length])
- [self setSelectedRange:NSMakeRange(0, [[self string] length])];
- [self insertText:output];
- }
-
- else if([action isEqualToString:SPBundleOutputActionReplaceSelection]) {
- [self shouldChangeTextInRange:replaceRange replacementString:output];
- [self replaceCharactersInRange:replaceRange withString:output];
- }
-
- else if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) {
+ if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) {
[SPTooltip showWithObject:output];
}
@@ -627,6 +624,35 @@
SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init];
[c displayHTMLContent:output withOptions:nil];
}
+
+ if([self isEditable]) {
+
+ if([action isEqualToString:SPBundleOutputActionInsertAsText]) {
+ [self insertText:output];
+ }
+
+ else if([action isEqualToString:SPBundleOutputActionInsertAsSnippet]) {
+ if([self respondsToSelector:@selector(insertAsSnippet:atRange:)])
+ [self insertAsSnippet:output atRange:replaceRange];
+ else
+ [SPTooltip showWithObject:NSLocalizedString(@"Input Field doesn't support insertion of snippets.", @"input field doesn't support insertion of snippets.")];
+ }
+
+ else if([action isEqualToString:SPBundleOutputActionReplaceContent]) {
+ if([[self string] length])
+ [self setSelectedRange:NSMakeRange(0, [[self string] length])];
+ [self insertText:output];
+ }
+
+ else if([action isEqualToString:SPBundleOutputActionReplaceSelection]) {
+ [self shouldChangeTextInRange:replaceRange replacementString:output];
+ [self replaceCharactersInRange:replaceRange withString:output];
+ }
+
+ } else {
+ [SPTooltip showWithObject:NSLocalizedString(@"Input Field is not editable.", @"input field is not editable.")];
+ }
+
}
} else {
NSString *errorMessage = [err localizedDescription];
@@ -722,21 +748,6 @@
}
-- (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