diff options
-rw-r--r-- | Interfaces/English.lproj/BundleEditor.xib | 36 | ||||
-rw-r--r-- | Source/SPBundleCommandTextView.h | 9 | ||||
-rw-r--r-- | Source/SPBundleCommandTextView.m | 150 | ||||
-rw-r--r-- | Source/SPBundleEditorController.m | 13 | ||||
-rw-r--r-- | Source/SPCopyTable.m | 9 | ||||
-rw-r--r-- | Source/SPStringAdditions.m | 9 | ||||
-rw-r--r-- | Source/SPTextView.m | 9 | ||||
-rw-r--r-- | Source/SPTextViewAdditions.m | 9 |
8 files changed, 204 insertions, 40 deletions
diff --git a/Interfaces/English.lproj/BundleEditor.xib b/Interfaces/English.lproj/BundleEditor.xib index fc95329a..5bbbb3c9 100644 --- a/Interfaces/English.lproj/BundleEditor.xib +++ b/Interfaces/English.lproj/BundleEditor.xib @@ -468,7 +468,7 @@ <int key="NSTCFlags">1</int> </object> <object class="NSTextViewSharedData" key="NSSharedData"> - <int key="NSFlags">11555</int> + <int key="NSFlags">11299</int> <int key="NSTextCheckingTypes">0</int> <nil key="NSMarkedAttributes"/> <object class="NSColor" key="NSBackgroundColor" id="856229010"> @@ -1760,6 +1760,14 @@ </object> <int key="connectionID">929</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">commandScrollView</string> + <reference key="source" ref="965862131"/> + <reference key="destination" ref="179792134"/> + </object> + <int key="connectionID">931</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -1826,6 +1834,7 @@ <reference ref="78837987"/> </object> <reference key="parent" ref="358491109"/> + <string key="objectName">Bundle Table View</string> </object> <object class="IBObjectRecord"> <int key="objectID">729</int> @@ -1982,6 +1991,7 @@ <reference ref="552615839"/> </object> <reference key="parent" ref="358491109"/> + <string key="objectName">Bundle Content View</string> </object> <object class="IBObjectRecord"> <int key="objectID">774</int> @@ -1991,6 +2001,7 @@ <reference ref="299353121"/> </object> <reference key="parent" ref="338542681"/> + <string key="objectName">Pop Up Button (Output)</string> </object> <object class="IBObjectRecord"> <int key="objectID">775</int> @@ -2045,6 +2056,7 @@ <reference ref="1025501303"/> </object> <reference key="parent" ref="338542681"/> + <string key="objectName">Text Field (Menu Label)</string> </object> <object class="IBObjectRecord"> <int key="objectID">696</int> @@ -2096,6 +2108,7 @@ <reference ref="4363123"/> </object> <reference key="parent" ref="338542681"/> + <string key="objectName">Pop Up Button (Input Fallback)</string> </object> <object class="IBObjectRecord"> <int key="objectID">781</int> @@ -2122,6 +2135,7 @@ <reference ref="748268806"/> </object> <reference key="parent" ref="338542681"/> + <string key="objectName">Text Field (Menu Category)</string> </object> <object class="IBObjectRecord"> <int key="objectID">702</int> @@ -2164,6 +2178,7 @@ <reference ref="43525095"/> </object> <reference key="parent" ref="338542681"/> + <string key="objectName">Text Field (Tooltip)</string> </object> <object class="IBObjectRecord"> <int key="objectID">802</int> @@ -2206,6 +2221,7 @@ <reference ref="131002945"/> </object> <reference key="parent" ref="338542681"/> + <string key="objectName">Pop Up Button (Input)</string> </object> <object class="IBObjectRecord"> <int key="objectID">769</int> @@ -2301,6 +2317,7 @@ <reference ref="965862131"/> </object> <reference key="parent" ref="338542681"/> + <string key="objectName">Bordered Scroll View (Command Text View)</string> </object> <object class="IBObjectRecord"> <int key="objectID">821</int> @@ -2510,9 +2527,9 @@ <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{251, 39}, {655, 444}}</string> + <string>{{515, 73}, {655, 444}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{251, 39}, {655, 444}}</string> + <string>{{515, 73}, {655, 444}}</string> <boolean value="NO"/> <boolean value="YES"/> <string>{726, 444}</string> @@ -2767,7 +2784,7 @@ </object> </object> <nil key="sourceID"/> - <int key="maxID">929</int> + <int key="maxID">931</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -2904,6 +2921,17 @@ <object class="IBPartialClassDescription"> <string key="className">SPBundleCommandTextView</string> <string key="superclassName">NSTextView</string> + <object class="NSMutableDictionary" key="outlets"> + <string key="NS.key.0">commandScrollView</string> + <string key="NS.object.0">NSScrollView</string> + </object> + <object class="NSMutableDictionary" key="toOneOutletInfosByName"> + <string key="NS.key.0">commandScrollView</string> + <object class="IBToOneOutletInfo" key="NS.object.0"> + <string key="name">commandScrollView</string> + <string key="candidateClassName">NSScrollView</string> + </object> + </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBDocumentRelativeSource</string> <string key="minorKey">../../Source/SPBundleCommandTextView.h</string> diff --git a/Source/SPBundleCommandTextView.h b/Source/SPBundleCommandTextView.h index e39ec1dd..fb9cef62 100644 --- a/Source/SPBundleCommandTextView.h +++ b/Source/SPBundleCommandTextView.h @@ -22,13 +22,22 @@ // // More info at <http://code.google.com/p/sequel-pro/> +#import "NoodleLineNumberView.h" + @interface SPBundleCommandTextView : NSTextView { + + IBOutlet NSScrollView *commandScrollView; + + NSUserDefaults *prefs; + BOOL textWasChanged; + NoodleLineNumberView *lineNumberView; } - (NSUInteger)characterIndexOfPoint:(NSPoint)aPoint; - (void)insertFileContentOfFile:(NSString *)aPath; - (void)saveChangedFontInUserDefaults; +- (void) setTabStops; @end diff --git a/Source/SPBundleCommandTextView.m b/Source/SPBundleCommandTextView.m index a840101a..72618dbc 100644 --- a/Source/SPBundleCommandTextView.m +++ b/Source/SPBundleCommandTextView.m @@ -37,6 +37,66 @@ return self; } +- (void)dealloc +{ + + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [prefs removeObserver:self forKeyPath:SPCustomQueryEditorTabStopWidth]; + [prefs release]; + [lineNumberView release]; +} + +- (void) awakeFromNib +{ + + prefs = [[NSUserDefaults standardUserDefaults] retain]; + + [prefs addObserver:self forKeyPath:SPCustomQueryEditorTabStopWidth options:NSKeyValueObservingOptionNew context:NULL]; + + if([[NSUserDefaults standardUserDefaults] dataForKey:@"BundleEditorFont"]) { + NSFont *nf = [NSUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] dataForKey:@"BundleEditorFont"]]; + [self setFont:nf]; + } + + lineNumberView = [[NoodleLineNumberView alloc] initWithScrollView:commandScrollView]; + [commandScrollView setVerticalRulerView:lineNumberView]; + [commandScrollView setHasHorizontalRuler:NO]; + [commandScrollView setHasVerticalRuler:YES]; + [commandScrollView setRulersVisible:YES]; + + // Re-define tab stops for a better editing + [self setTabStops]; + +} + +- (void)drawRect:(NSRect)rect +{ + // Draw background only for screen display but not while printing + if([NSGraphicsContext currentContextDrawingToScreen]) { + + // Draw textview's background since due to the snippet highlighting we're responsible for it. + [[NSColor whiteColor] setFill]; + NSRectFill(rect); + + if (![self selectedRange].length && [[self string] length]) { + NSRange r = [[self string] lineRangeForRange:NSMakeRange([self selectedRange].location, 0)]; + NSUInteger rectCount; + [[self textStorage] ensureAttributesAreFixedInRange:r]; + NSRectArray queryRects = [[self layoutManager] rectArrayForCharacterRange: r + withinSelectedCharacterRange: r + inTextContainer: [self textContainer] + rectCount: &rectCount ]; + [[NSColor colorWithCalibratedRed:0.95f green:0.95f blue:0.95f alpha:1.0f] setFill]; + NSRectFillListUsingOperation(queryRects, rectCount, NSCompositeSourceOver); + } + } + + [super drawRect:rect]; + +} + +#pragma mark - + - (IBAction)undo:(id)sender { textWasChanged = NO; @@ -75,24 +135,53 @@ [super cut:sender]; } -/** - * Validate undo and redo menu items - */ -- (BOOL)validateMenuItem:(NSMenuItem *)menuItem +- (void) setTabStops { - - if ([menuItem action] == @selector(undo:)) { - return ([[self undoManager] canUndo]); + NSFont *tvFont = [self font]; + NSInteger i; + NSTextTab *aTab; + NSMutableArray *myArrayOfTabs; + NSMutableParagraphStyle *paragraphStyle; + + BOOL oldEditableStatus = [self isEditable]; + [self setEditable:YES]; + + NSInteger tabStopWidth = [prefs integerForKey:SPCustomQueryEditorTabStopWidth]; + if(tabStopWidth < 1) tabStopWidth = 1; + + float tabWidth = NSSizeToCGSize([[NSString stringWithString:@" "] sizeWithAttributes:[NSDictionary dictionaryWithObject:tvFont forKey:NSFontAttributeName]]).width; + tabWidth = (float)tabStopWidth * tabWidth; + + NSInteger numberOfTabs = 256/tabStopWidth; + myArrayOfTabs = [NSMutableArray arrayWithCapacity:numberOfTabs]; + aTab = [[NSTextTab alloc] initWithType:NSLeftTabStopType location:tabWidth]; + [myArrayOfTabs addObject:aTab]; + [aTab release]; + for(i=1; i<numberOfTabs; i++) { + aTab = [[NSTextTab alloc] initWithType:NSLeftTabStopType location:tabWidth + ((float)i * tabWidth)]; + [myArrayOfTabs addObject:aTab]; + [aTab release]; } - if ([menuItem action] == @selector(redo:)) { - return ([[self undoManager] canRedo]); + paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; + [paragraphStyle setTabStops:myArrayOfTabs]; + // Soft wrapped lines are indented slightly + [paragraphStyle setHeadIndent:4.0]; + + NSMutableDictionary *textAttributes = [[[NSMutableDictionary alloc] initWithCapacity:1] autorelease]; + [textAttributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName]; + + NSRange range = NSMakeRange(0, [[self textStorage] length]); + if ([self shouldChangeTextInRange:range replacementString:nil]) { + [[self textStorage] setAttributes:textAttributes range: range]; + [self didChangeText]; } - return YES; -} + [self setTypingAttributes:textAttributes]; + [self setDefaultParagraphStyle:paragraphStyle]; + [self setFont:tvFont]; -- (void)textDidChange:(NSNotification *)aNotification -{ - textWasChanged = YES; + [self setEditable:oldEditableStatus]; + + [paragraphStyle release]; } - (void)keyDown:(NSEvent *)theEvent @@ -162,6 +251,8 @@ } +#pragma mark - + /* * Insert the content of a dragged file path or if ⌘ is pressed * while dragging insert the file path @@ -244,6 +335,9 @@ [self insertFileContentOfFile:[sheet helpAnchor]]; } + +#pragma mark - + /* * Convert a NSPoint, usually the mouse location, to * a character index of the text view. @@ -342,11 +436,37 @@ NSLog(@"%@ ‘%@’.", NSLocalizedString(@"Couldn't read the file content of", @"Couldn't read the file content of"), aPath); } +#pragma mark - + +/** + * Validate undo and redo menu items + */ +- (BOOL)validateMenuItem:(NSMenuItem *)menuItem +{ + + if ([menuItem action] == @selector(undo:)) { + return ([[self undoManager] canUndo]); + } + if ([menuItem action] == @selector(redo:)) { + return ([[self undoManager] canRedo]); + } + return YES; +} + +#pragma mark - + +- (void)textDidChange:(NSNotification *)aNotification +{ + textWasChanged = YES; +} + +#pragma mark - + // Store the font in the prefs for selected delegates only - (void)saveChangedFontInUserDefaults { if([[[[self delegate] class] description] isEqualToString:@"SPBundleEditorController"]) - [[NSUserDefaults standardUserDefaults] setObject:[NSArchiver archivedDataWithRootObject:[self font]] forKey:@"FieldEditorSheetFont"]; + [prefs setObject:[NSArchiver archivedDataWithRootObject:[self font]] forKey:@"BundleEditorFont"]; } // Action receiver for a font change in the font panel diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m index 829cff3e..8587082b 100644 --- a/Source/SPBundleEditorController.m +++ b/Source/SPBundleEditorController.m @@ -205,11 +205,6 @@ [keyEquivalentField setCanCaptureGlobalHotKeys:YES]; - if([[NSUserDefaults standardUserDefaults] dataForKey:@"BundleEditorFont"]) { - NSFont *nf = [NSUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] dataForKey:@"BundleEditorFont"]]; - [commandTextView setFont:nf]; - } - } #pragma mark - @@ -982,6 +977,14 @@ #pragma mark NSTextView delegates /** + * Update command text view for highlighting the current edited line + */ +- (void)textViewDidChangeSelection:(NSNotification *)aNotification +{ + [commandTextView setNeedsDisplay:YES]; +} + +/** * Traps any editing in editTextView to allow undo grouping only if the text buffer was really changed. * Inform the run loop delayed for larger undo groups. */ diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m index 48aa62f7..1bfc2277 100644 --- a/Source/SPCopyTable.m +++ b/Source/SPCopyTable.m @@ -840,8 +840,9 @@ NSInteger MENU_EDIT_COPY_AS_SQL = 2003; NSString *inputAction = @""; NSString *inputFallBackAction = @""; NSError *err = nil; + NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, [NSString stringWithNewUUID]]; - [[NSFileManager defaultManager] removeItemAtPath:SPBundleTaskInputFilePath error:nil]; + [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; if([cmdData objectForKey:SPBundleFileInputSourceKey]) inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString]; @@ -850,7 +851,7 @@ NSInteger MENU_EDIT_COPY_AS_SQL = 2003; NSMutableDictionary *env = [NSMutableDictionary dictionary]; [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:@"SP_BUNDLE_PATH"]; - [env setObject:SPBundleTaskInputFilePath forKey:@"SP_BUNDLE_INPUT_FILE"]; + [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"]; @@ -877,7 +878,7 @@ NSInteger MENU_EDIT_COPY_AS_SQL = 2003; } if(input == nil) input = @""; - [input writeToFile:SPBundleTaskInputFilePath + [input writeToFile:bundleInputFilePath atomically:YES encoding:NSUTF8StringEncoding error:&inputFileError]; @@ -892,7 +893,7 @@ NSInteger MENU_EDIT_COPY_AS_SQL = 2003; NSString *output = [cmd runBashCommandWithEnvironment:env atCurrentDirectoryPath:nil error:&err]; - [[NSFileManager defaultManager] removeItemAtPath:SPBundleTaskInputFilePath error:nil]; + [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; if(err == nil && output && [cmdData objectForKey:SPBundleFileOutputActionKey]) { if([[cmdData objectForKey:SPBundleFileOutputActionKey] length] diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index 816dc362..09f37866 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -421,7 +421,8 @@ NSMutableArray *scriptHeaderArguments = [NSMutableArray array]; NSString *scriptPath = @""; - NSString *stdoutFilePath = @"/tmp/SP_BUNDLE_OUTPUT_FILE"; + NSString *stdoutFilePath = [NSString stringWithFormat:@"/tmp/SP_BUNDLE_OUTPUT_FILE_%@", [NSString stringWithNewUUID]]; + NSString *scriptFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskScriptCommandFilePath, [NSString stringWithNewUUID]]; [[NSFileManager defaultManager] removeItemAtPath:SPBundleTaskScriptCommandFilePath error:nil]; [[NSFileManager defaultManager] removeItemAtPath:stdoutFilePath error:nil]; @@ -443,10 +444,10 @@ if([scriptPath hasPrefix:@"/"] && [[NSFileManager defaultManager] fileExistsAtPath:scriptPath isDirectory:&isDir] && !isDir) { NSString *script = [self substringWithRange:NSMakeRange(NSMaxRange(firstLineRange), [self length] - NSMaxRange(firstLineRange))]; NSError *writeError = nil; - [script writeToFile:SPBundleTaskScriptCommandFilePath atomically:YES encoding:NSUTF8StringEncoding error:writeError]; + [script writeToFile:scriptFilePath atomically:YES encoding:NSUTF8StringEncoding error:writeError]; if(writeError == nil) { redirectForScript = YES; - [scriptHeaderArguments addObject:SPBundleTaskScriptCommandFilePath]; + [scriptHeaderArguments addObject:scriptFilePath]; } else { NSBeep(); NSLog(@"Couldn't write script file."); @@ -532,7 +533,7 @@ } if(redirectForScript) - [[NSFileManager defaultManager] removeItemAtPath:SPBundleTaskScriptCommandFilePath error:nil]; + [[NSFileManager defaultManager] removeItemAtPath:scriptFilePath error:nil]; // If return from bash re-activate Sequel Pro [NSApp activateIgnoringOtherApps:YES]; diff --git a/Source/SPTextView.m b/Source/SPTextView.m index 0af0b2ff..b7e39a39 100644 --- a/Source/SPTextView.m +++ b/Source/SPTextView.m @@ -3453,10 +3453,11 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) NSString *inputAction = @""; NSString *inputFallBackAction = @""; NSError *err = nil; + NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, [NSString stringWithNewUUID]]; NSRange currentWordRange, currentQueryRange, currentSelectionRange, currentLineRange; - [[NSFileManager defaultManager] removeItemAtPath:SPBundleTaskInputFilePath error:nil]; + [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; if([cmdData objectForKey:SPBundleFileInputSourceKey]) inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString]; @@ -3494,7 +3495,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) NSMutableDictionary *env = [NSMutableDictionary dictionary]; [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:@"SP_BUNDLE_PATH"]; - [env setObject:SPBundleTaskInputFilePath forKey:@"SP_BUNDLE_INPUT_FILE"]; + [env setObject:bundleInputFilePath forKey:@"SP_BUNDLE_INPUT_FILE"]; if(currentSelectionRange.length) [env setObject:[[self string] substringWithRange:currentSelectionRange] forKey:@"SP_SELECTED_TEXT"]; @@ -3510,7 +3511,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) NSError *inputFileError = nil; NSString *input = [NSString stringWithString:[[self string] substringWithRange:replaceRange]]; - [input writeToFile:SPBundleTaskInputFilePath + [input writeToFile:bundleInputFilePath atomically:YES encoding:NSUTF8StringEncoding error:&inputFileError]; @@ -3525,7 +3526,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) NSString *output = [cmd runBashCommandWithEnvironment:env atCurrentDirectoryPath:nil error:&err]; - [[NSFileManager defaultManager] removeItemAtPath:SPBundleTaskInputFilePath error:nil]; + [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; if(err == nil && output && [cmdData objectForKey:SPBundleFileOutputActionKey]) { if([[cmdData objectForKey:SPBundleFileOutputActionKey] length] diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index fdf2318c..ae07d289 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -525,10 +525,11 @@ NSString *inputAction = @""; NSString *inputFallBackAction = @""; NSError *err = nil; + NSString *bundleInputFilePath = [NSString stringWithFormat:@"%@_%@", SPBundleTaskInputFilePath, [NSString stringWithNewUUID]]; NSRange currentWordRange, currentSelectionRange, currentLineRange; - [[NSFileManager defaultManager] removeItemAtPath:SPBundleTaskInputFilePath error:nil]; + [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; if([cmdData objectForKey:SPBundleFileInputSourceKey]) inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString]; @@ -559,7 +560,7 @@ NSMutableDictionary *env = [NSMutableDictionary dictionary]; [env setObject:[infoPath stringByDeletingLastPathComponent] forKey:@"SP_BUNDLE_PATH"]; - [env setObject:SPBundleTaskInputFilePath forKey:@"SP_BUNDLE_INPUT_FILE"]; + [env setObject:bundleInputFilePath forKey:@"SP_BUNDLE_INPUT_FILE"]; if(currentSelectionRange.length) [env setObject:[[self string] substringWithRange:currentSelectionRange] forKey:@"SP_SELECTED_TEXT"]; @@ -572,7 +573,7 @@ NSError *inputFileError = nil; NSString *input = [NSString stringWithString:[[self string] substringWithRange:replaceRange]]; - [input writeToFile:SPBundleTaskInputFilePath + [input writeToFile:bundleInputFilePath atomically:YES encoding:NSUTF8StringEncoding error:&inputFileError]; @@ -587,7 +588,7 @@ NSString *output = [cmd runBashCommandWithEnvironment:env atCurrentDirectoryPath:nil error:&err]; - [[NSFileManager defaultManager] removeItemAtPath:SPBundleTaskInputFilePath error:nil]; + [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; if(err == nil && output && [cmdData objectForKey:SPBundleFileOutputActionKey]) { if([[cmdData objectForKey:SPBundleFileOutputActionKey] length] |